diff --git a/Cargo.lock b/Cargo.lock index 80685701d0fb..e34df5c71b09 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -193,9 +193,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.32" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41daef31d7a747c5c847246f36de49ced6f7403b4cdabc807a97b5cc184cda7a" +checksum = "9f13690e35a5e4ace198e7beea2895d29f3a9cc55015fcebe6336bd2010af9eb" dependencies = [ "android-tzdata", "iana-time-zone", @@ -1104,9 +1104,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b7fa1134405e2ec9353fd416b17f8dacd46c473d7d3fd1cf202706a14eb792a" +checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" dependencies = [ "aho-corasick", "memchr", @@ -1299,18 +1299,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.195" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.195" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" dependencies = [ "proc-macro2", "quote", @@ -1319,9 +1319,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.111" +version = "1.0.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" +checksum = "4d1bd37ce2324cf3bf85e5a25f96eb4baf0d5aa6eba43e7ae8958870c4ec48ed" dependencies = [ "itoa", "ryu", @@ -1343,7 +1343,7 @@ dependencies = [ [[package]] name = "serenity" version = "0.12.0" -source = "git+https://github.com/serenity-rs/serenity?branch=next#4e05d38796e50b10a6a201d2fa03a71f759ac766" +source = "git+https://github.com/serenity-rs/serenity?branch=next#e79e5d0e02b2c40c478179ad006fcbdb53e2fed8" dependencies = [ "arrayvec", "async-trait", diff --git a/examples/feature_showcase/collector.rs b/examples/feature_showcase/collector.rs index b0bb14a0be6b..09594b063a44 100644 --- a/examples/feature_showcase/collector.rs +++ b/examples/feature_showcase/collector.rs @@ -38,7 +38,7 @@ pub async fn boop(ctx: Context<'_>) -> Result<(), Error> { ) .await?; - mci.create_response(ctx, serenity::CreateInteractionResponse::Acknowledge) + mci.create_response(ctx.http(), serenity::CreateInteractionResponse::Acknowledge) .await?; } diff --git a/examples/manual_dispatch/main.rs b/examples/manual_dispatch/main.rs index 5ed24d481ab6..a351ce642678 100644 --- a/examples/manual_dispatch/main.rs +++ b/examples/manual_dispatch/main.rs @@ -20,17 +20,30 @@ struct Handler { } #[serenity::async_trait] impl serenity::EventHandler for Handler { - async fn message(&self, ctx: serenity::Context, new_message: serenity::Message) { + async fn message(&self, serenity_context: &serenity::Context, new_message: &serenity::Message) { // FrameworkContext contains all data that poise::Framework usually manages let shard_manager = (*self.shard_manager.lock().unwrap()).clone().unwrap(); let framework_data = poise::FrameworkContext { - serenity_context: &ctx, + serenity_context, options: &self.options, shard_manager: &shard_manager, }; - let event = serenity::FullEvent::Message { new_message }; - poise::dispatch_event(framework_data, event).await; + let invocation_data = tokio::sync::Mutex::new(Box::new(()) as _); + let trigger = poise::MessageDispatchTrigger::MessageCreate; + let mut parent_commands = Vec::new(); + + let res = poise::dispatch_message( + framework_data, + new_message, + trigger, + &invocation_data, + &mut parent_commands, + ); + + if let Err(err) = res.await { + err.handle(&self.options).await; + } } // For slash commands or edit tracking to work, forward interaction_create and message_update diff --git a/src/builtins/paginate.rs b/src/builtins/paginate.rs index 904f35eea26d..ff2933fb4687 100644 --- a/src/builtins/paginate.rs +++ b/src/builtins/paginate.rs @@ -83,7 +83,7 @@ pub async fn paginate( // Update the message with the new page contents press .create_response( - ctx.serenity_context(), + ctx.http(), serenity::CreateInteractionResponse::UpdateMessage( serenity::CreateInteractionResponseMessage::new() .embed(serenity::CreateEmbed::new().description(pages[current_page])), diff --git a/src/dispatch/mod.rs b/src/dispatch/mod.rs index ea4cd71cdf6b..7e44a463d552 100644 --- a/src/dispatch/mod.rs +++ b/src/dispatch/mod.rs @@ -66,9 +66,9 @@ impl<'a, U: Send + Sync + 'static, E> FrameworkContext<'a, U, E> { /// Central event handling function of this library pub async fn dispatch_event( framework: crate::FrameworkContext<'_, U, E>, - event: serenity::FullEvent, + event: &serenity::FullEvent, ) { - match &event { + match event { serenity::FullEvent::Message { new_message } => { let invocation_data = tokio::sync::Mutex::new(Box::new(()) as _); let mut parent_commands = Vec::new(); @@ -172,10 +172,10 @@ pub async fn dispatch_event( // Do this after the framework's Ready handling, so that get_user_data() doesnt // potentially block infinitely - if let Err(error) = (framework.options.event_handler)(framework, &event).await { + if let Err(error) = (framework.options.event_handler)(framework, event).await { let error = crate::FrameworkError::EventHandler { error, - event: &event, + event, framework, }; (framework.options.on_error)(error).await; diff --git a/src/dispatch/slash.rs b/src/dispatch/slash.rs index 2a1fc0759aa0..762b852c8509 100644 --- a/src/dispatch/slash.rs +++ b/src/dispatch/slash.rs @@ -236,7 +236,7 @@ async fn run_autocomplete( if let Err(e) = ctx .interaction .create_response( - &ctx.framework.serenity_context, + ctx.http(), serenity::CreateInteractionResponse::Autocomplete(autocomplete_response), ) .await diff --git a/src/framework/mod.rs b/src/framework/mod.rs index 721f6dfdf9d4..bf959656be52 100644 --- a/src/framework/mod.rs +++ b/src/framework/mod.rs @@ -107,7 +107,7 @@ impl serenity::Framework for Framework } } - async fn dispatch(&self, ctx: serenity::Context, event: serenity::FullEvent) { + async fn dispatch(&self, ctx: &serenity::Context, event: &serenity::FullEvent) { raw_dispatch_event(self, ctx, event).await } } @@ -116,12 +116,12 @@ impl serenity::Framework for Framework /// Otherwise, it forwards the event to [`crate::dispatch_event`] async fn raw_dispatch_event( framework: &Framework, - ctx: serenity::Context, - event: serenity::FullEvent, + serenity_context: &serenity::Context, + event: &serenity::FullEvent, ) where U: Send + Sync + 'static, { - if let serenity::FullEvent::Ready { data_about_bot } = &event { + if let serenity::FullEvent::Ready { data_about_bot } = event { let _: Result<_, _> = framework.bot_id.set(data_about_bot.user.id); } @@ -133,7 +133,7 @@ async fn raw_dispatch_event( let framework = crate::FrameworkContext { #[cfg(not(feature = "cache"))] bot_id, - serenity_context: &ctx, + serenity_context, options: &framework.options, shard_manager: framework.shard_manager(), }; diff --git a/src/modal.rs b/src/modal.rs index 2e8085c220bb..43378cdfc8c5 100644 --- a/src/modal.rs +++ b/src/modal.rs @@ -65,7 +65,7 @@ async fn execute_modal_generic< // Send acknowledgement so that the pop-up is closed response - .create_response(ctx, serenity::CreateInteractionResponse::Acknowledge) + .create_response(&ctx.http, serenity::CreateInteractionResponse::Acknowledge) .await?; Ok(Some(M::parse(response.data))) @@ -94,7 +94,7 @@ pub async fn execute_modal( let interaction = ctx.interaction; let response = execute_modal_generic( ctx.serenity_context(), - |resp| interaction.create_response(ctx, resp), + |resp| interaction.create_response(ctx.http(), resp), interaction.id.to_string(), defaults, timeout, @@ -125,7 +125,7 @@ pub async fn execute_modal_on_component_interaction( ) -> Result, serenity::Error> { execute_modal_generic( ctx, - |resp| interaction.create_response(ctx, resp), + |resp| interaction.create_response(&ctx.http, resp), interaction.id.to_string(), defaults, timeout, diff --git a/src/reply/send_reply.rs b/src/reply/send_reply.rs index 3d2c08ec4e0c..b127f908938d 100644 --- a/src/reply/send_reply.rs +++ b/src/reply/send_reply.rs @@ -76,9 +76,7 @@ where let builder = builder .to_slash_followup_response(serenity::CreateInteractionResponseFollowup::new()); - ctx.interaction - .create_followup(ctx.serenity_context(), builder) - .await? + ctx.interaction.create_followup(ctx.http(), builder).await? })) } else { let builder = @@ -86,7 +84,7 @@ where ctx.interaction .create_response( - ctx.serenity_context(), + ctx.http(), serenity::CreateInteractionResponse::Message(builder), ) .await?; diff --git a/src/structs/slash.rs b/src/structs/slash.rs index 6523a45e60eb..faa4556528ae 100644 --- a/src/structs/slash.rs +++ b/src/structs/slash.rs @@ -68,9 +68,8 @@ impl ApplicationContext<'_, U, E> { serenity::CreateInteractionResponseMessage::new().ephemeral(ephemeral), ); - self.interaction - .create_response(self.framework.serenity_context, response) - .await?; + let http = &self.framework.serenity_context.http; + self.interaction.create_response(http, response).await?; self.has_sent_initial_response .store(true, std::sync::atomic::Ordering::SeqCst);