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 746b5c4
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/advanced_cooldowns/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/basic_structure/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _)
Expand Down
2 changes: 1 addition & 1 deletion examples/event_handler/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _)
Expand Down
2 changes: 1 addition & 1 deletion examples/feature_showcase/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/help_generation/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/invocation_data/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstart/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
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 746b5c4

Please sign in to comment.