diff --git a/examples/advanced_cooldowns/main.rs b/examples/advanced_cooldowns/main.rs index 43026e389301..042996445074 100644 --- a/examples/advanced_cooldowns/main.rs +++ b/examples/advanced_cooldowns/main.rs @@ -49,7 +49,7 @@ async fn main() { }; let client = serenity::Client::builder(&token, serenity::GatewayIntents::non_privileged()) - .framework(poise::Framework::new(options)) + .framework(poise::Framework::new(options, true)) .await; client.unwrap().start().await.unwrap(); diff --git a/examples/basic_structure/main.rs b/examples/basic_structure/main.rs index 40b438189218..2203976381ce 100644 --- a/examples/basic_structure/main.rs +++ b/examples/basic_structure/main.rs @@ -112,7 +112,7 @@ async fn main() { serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT; let client = serenity::ClientBuilder::new(&token, intents) - .framework(poise::Framework::new(options)) + .framework(poise::Framework::new(options, true)) .data(Arc::new(Data { votes: Mutex::new(HashMap::new()), }) as _) diff --git a/examples/event_handler/main.rs b/examples/event_handler/main.rs index 6afc50edd8c1..06b1319f1cd5 100644 --- a/examples/event_handler/main.rs +++ b/examples/event_handler/main.rs @@ -29,7 +29,7 @@ async fn main() { }; let client = serenity::ClientBuilder::new(&token, intents) - .framework(poise::Framework::new(options)) + .framework(poise::Framework::new(options, true)) .data(Arc::new(Data { poise_mentions: AtomicU32::new(0), }) as _) diff --git a/examples/feature_showcase/main.rs b/examples/feature_showcase/main.rs index a0afec2b943e..259f93e4a36b 100644 --- a/examples/feature_showcase/main.rs +++ b/examples/feature_showcase/main.rs @@ -118,7 +118,7 @@ async fn main() { serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT; let client = serenity::ClientBuilder::new(&token, intents) - .framework(poise::Framework::new(framework_options)) + .framework(poise::Framework::new(framework_options, true)) .await; client.unwrap().start().await.unwrap() diff --git a/examples/help_generation/main.rs b/examples/help_generation/main.rs index 309bf561781c..2f9fdd69a8ef 100644 --- a/examples/help_generation/main.rs +++ b/examples/help_generation/main.rs @@ -357,7 +357,7 @@ async fn main() { }; let client = serenity::ClientBuilder::new(&token, intents) - .framework(poise::Framework::new(options)) + .framework(poise::Framework::new(options, true)) .await; client.unwrap().start().await.unwrap(); diff --git a/examples/invocation_data/main.rs b/examples/invocation_data/main.rs index 69cb09ec3428..b6a9da62d94b 100644 --- a/examples/invocation_data/main.rs +++ b/examples/invocation_data/main.rs @@ -117,7 +117,7 @@ async fn main() { }; let client = serenity::ClientBuilder::new(&token, intents) - .framework(poise::Framework::new(options)) + .framework(poise::Framework::new(options, true)) .await; client.unwrap().start().await.unwrap(); diff --git a/examples/quickstart/main.rs b/examples/quickstart/main.rs index 5d679de24eb5..48061b7f0f3f 100644 --- a/examples/quickstart/main.rs +++ b/examples/quickstart/main.rs @@ -36,7 +36,7 @@ async fn main() { }; let client = serenity::ClientBuilder::new(&token, intents) - .framework(poise::Framework::new(options)) + .framework(poise::Framework::new(options, true)) .await; client.unwrap().start().await.unwrap(); diff --git a/src/framework/builder.rs b/src/framework/builder.rs index 3431a5b2060e..ef1d998c271a 100644 --- a/src/framework/builder.rs +++ b/src/framework/builder.rs @@ -54,6 +54,6 @@ impl FrameworkBuilder { options.initialize_owners = self.initialize_owners; // Create framework with specified settings - crate::Framework::new(options) + crate::Framework::new(options, true) } } diff --git a/src/framework/mod.rs b/src/framework/mod.rs index 84f7252e11c3..49be12fdaae4 100644 --- a/src/framework/mod.rs +++ b/src/framework/mod.rs @@ -29,6 +29,13 @@ pub struct Framework { /// Handle to the background task in order to `abort()` it on `Drop` edit_tracker_purge_task: Option>, + + /// If [`Framework::dispatch`] should be called + /// automatically (`true`) or manually by the developer (`false`) + /// + /// This allows the developer to make checks and call other functions before commands are + /// handled at all. + dispatch_automatically: bool, } impl Framework { @@ -48,7 +55,7 @@ impl Framework { } /// Setup a new [`Framework`]. - pub fn new(options: crate::FrameworkOptions) -> Self + pub fn new(options: crate::FrameworkOptions, dispatch_automatically: bool) -> Self where U: Send + Sync + 'static + 'static, E: Send + 'static, @@ -58,6 +65,7 @@ impl Framework { edit_tracker_purge_task: None, shard_manager: None, options, + dispatch_automatically, } } @@ -110,6 +118,15 @@ impl serenity::Framework for Framework async fn dispatch(&self, ctx: &serenity::Context, event: &serenity::FullEvent) { raw_dispatch_event(self, ctx, event).await } + + /// If [`Framework::dispatch`] should be called + /// automatically (`true`) or manually by the developer (`false`) + /// + /// This allows the developer to make checks and call other functions before commands are + /// handled at all. + fn dispatch_automatically(&self) -> bool { + self.dispatch_automatically + } } /// If the incoming event is Ready, this method sets up [`Framework::bot_id`].