youmubot/youmubot-core/src/lib.rs
Natsu Kagami a146883620
Some checks failed
Build and Test / Format check (push) Has been cancelled
Build and Test / Lint (push) Has been cancelled
Build and Test / Test (push) Has been cancelled
Build and Test / Build (push) Has been cancelled
core: Remove soft ban (#64)
Since Discord implemented silence, soft bans are not really used.
2025-03-29 17:06:20 +01:00

70 lines
1.7 KiB
Rust

use std::collections::HashSet;
use serenity::{
framework::standard::{
help_commands, macros::help, Args, CommandGroup, CommandResult, HelpOptions,
},
model::{channel::Message, id::UserId},
};
pub use admin::ADMIN_GROUP;
pub use community::COMMUNITY_GROUP;
pub use fun::FUN_GROUP;
use youmubot_prelude::*;
pub mod admin;
pub mod community;
mod db;
pub mod fun;
#[derive(Debug, Clone)]
pub struct CoreEnv {
pub(crate) prelude: Env,
pub(crate) ignore: admin::ignore::IgnoredUsers,
}
impl CoreEnv {
async fn new(prelude: Env) -> Result<Self> {
let ignore = admin::ignore::IgnoredUsers::from_db(&prelude).await?;
Ok(Self { prelude, ignore })
}
}
/// Gets an [CoreEnv] from the current environment.
pub trait HasCoreEnv: Send + Sync {
fn core_env(&self) -> &CoreEnv;
}
impl<T: AsRef<CoreEnv> + Send + Sync> HasCoreEnv for T {
fn core_env(&self) -> &CoreEnv {
self.as_ref()
}
}
/// Sets up all databases in the client.
pub async fn setup(path: &std::path::Path, data: &mut TypeMap, prelude: Env) -> Result<CoreEnv> {
db::load_role_list(
&mut *data,
&path.join("roles_v2.yaml"),
&path.join("roles.yaml"),
)?;
// Start reaction handlers
data.insert::<community::ReactionWatchers>(community::ReactionWatchers::new(&*data)?);
CoreEnv::new(prelude).await
}
// A help command
#[help]
pub async fn help(
context: &Context,
msg: &Message,
args: Args,
help_options: &'static HelpOptions,
groups: &[&'static CommandGroup],
owners: HashSet<UserId>,
) -> CommandResult {
help_commands::with_embeds(context, msg, args, help_options, groups, owners).await?;
Ok(())
}