Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree-wide: end of summer cleanup #214

Merged
merged 22 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
commands: assign all commands automatically
  • Loading branch information
getchoo committed Jul 28, 2024
commit 8ec7a0d4f51e3b8564d934c4805f6f26b0d7949a
10 changes: 5 additions & 5 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ async fn setup(ctx: &serenity::Context) -> Result<Data> {
}
trace!("Storage backend connected!");

poise::builtins::register_globally(ctx, &commands::to_vec_global()).await?;
poise::builtins::register_globally(ctx, &commands::global()).await?;
info!("Registered global commands!");

// register "extra" commands in guilds that allow it
let guilds = storage.get_opted_guilds().await?;

for guild in guilds {
poise::builtins::register_in_guild(ctx, &commands::to_vec_optional(), guild).await?;
poise::builtins::register_in_guild(ctx, &commands::optional(), guild).await?;

info!("Registered guild commands to {}", guild);
}
} else {
warn!("No storage backend was specified. Features requiring storage will be disabled");
warn!("No storage backend was specified. Features requiring storage cannot be used");
warn!("Registering optional commands globally since there's no storage backend");
poise::builtins::register_globally(ctx, &commands::to_vec()).await?;
poise::builtins::register_globally(ctx, &commands::all()).await?;
}

let http_client = <http::Client as http::Ext>::default();
Expand All @@ -66,7 +66,7 @@ pub async fn get() -> Result<serenity::Client> {
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;

let options = FrameworkOptions {
commands: commands::to_vec(),
commands: commands::all(),
on_error: |error| Box::pin(handlers::error::handle(error)),

command_check: Some(|ctx| {
Expand Down
23 changes: 6 additions & 17 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,13 @@ macro_rules! cmd {
};
}

pub fn to_vec() -> Vec<Command> {
vec![
cmd!(general, ask),
cmd!(general, bing),
cmd!(general, config),
cmd!(general, convert),
cmd!(general, emoji),
cmd!(general, pfp),
cmd!(general, random),
cmd!(general, version),
cmd!(moderation, clear_messages),
cmd!(optional, copypasta),
cmd!(optional, teawiespam),
cmd!(optional, uwurandom),
]
pub fn all() -> Vec<Command> {
let mut all_commands = global();
all_commands.append(&mut optional());
all_commands
}

pub fn to_vec_global() -> Vec<Command> {
pub fn global() -> Vec<Command> {
vec![
cmd!(general, ask),
cmd!(general, bing),
Expand All @@ -48,7 +37,7 @@ pub fn to_vec_global() -> Vec<Command> {
]
}

pub fn to_vec_optional() -> Vec<Command> {
pub fn optional() -> Vec<Command> {
vec![
cmd!(optional, copypasta),
cmd!(optional, teawiespam),
Expand Down