Skip to content

Commit

Permalink
Updates framework::Framework to match serenity-rs/serenity#2854
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCataliasTNT2k committed Apr 28, 2024
1 parent 57abf8f commit 5accb8c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/framework/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ impl<U, E> FrameworkBuilder<U, E> {
options.initialize_owners = self.initialize_owners;

// Create framework with specified settings
crate::Framework::new(options)
crate::Framework::new(options, true)
}
}
19 changes: 18 additions & 1 deletion src/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ pub struct Framework<U, E> {

/// Handle to the background task in order to `abort()` it on `Drop`
edit_tracker_purge_task: Option<tokio::task::JoinHandle<()>>,

/// 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<U, E> Framework<U, E> {
Expand All @@ -48,7 +55,7 @@ impl<U, E> Framework<U, E> {
}

/// Setup a new [`Framework`].
pub fn new(options: crate::FrameworkOptions<U, E>) -> Self
pub fn new(options: crate::FrameworkOptions<U, E>, dispatch_automatically: bool) -> Self
where
U: Send + Sync + 'static + 'static,
E: Send + 'static,
Expand All @@ -58,6 +65,7 @@ impl<U, E> Framework<U, E> {
edit_tracker_purge_task: None,
shard_manager: None,
options,
dispatch_automatically,
}
}

Expand Down Expand Up @@ -110,6 +118,15 @@ impl<U: Send + Sync + 'static, E: Send + Sync> 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`].
Expand Down

0 comments on commit 5accb8c

Please sign in to comment.