From 5accb8c94077f5b1fab8f2f433ace07769cb07cd Mon Sep 17 00:00:00 2001 From: TheCataliasTNT2k <44349750+TheCataliasTNT2k@users.noreply.github.com> Date: Sun, 28 Apr 2024 23:09:19 +0200 Subject: [PATCH] Updates framework::Framework to match https://github.com/serenity-rs/serenity/pull/2854 --- src/framework/builder.rs | 2 +- src/framework/mod.rs | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) 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 bf959656be52..bb6dac4fc96c 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`].