mod core;
#[doc(inline)]
pub use core::AppConfig;
mod bot;
#[doc(inline)]
pub use bot::BotConfig;
mod friend;
#[doc(inline)]
pub use friend::FriendConfig;
mod group;
#[doc(inline)]
pub use group::GroupConfig;
mod types;
#[doc(inline)]
pub use types::*;
mod common;
mod config;
mod logger;
mod registry;
pub use registry::ConfigRegistry;
pub trait Config: Send + Sync {
fn name(&self) -> &str;
fn path(&self) -> std::path::PathBuf {
puniyu_path::config_dir()
}
fn to_value(&self) -> toml::Value;
}
impl PartialEq for dyn Config {
fn eq(&self, other: &Self) -> bool {
self.name() == other.name() && self.path() == other.path()
}
}
pub(crate) fn serialize_to_value<T: serde::Serialize>(config: &T) -> toml::Value {
toml::Value::try_from(config).expect("Failed to serialize config to toml::Value")
}
#[inline]
pub fn app_config() -> AppConfig {
AppConfig::get()
}
#[inline]
pub fn bot_config() -> BotConfig {
BotConfig::get()
}
#[inline]
pub fn friend_config() -> FriendConfig {
FriendConfig::get()
}
#[inline]
pub fn group_config() -> GroupConfig {
GroupConfig::get()
}
pub fn init() {
macro_rules! register_config {
($ty:ty) => {{
let _ = ConfigRegistry::register(<$ty>::default());
}};
}
register_config!(AppConfig);
register_config!(BotConfig);
register_config!(GroupConfig);
register_config!(FriendConfig);
config::start_config_watcher();
}