Skip to content

Commit

Permalink
Fix breakage caused by CacheHttp -> Http
Browse files Browse the repository at this point in the history
* Use Http instead of CacheHttp

* Fix examples compiling

* Update MSRV lockfile

---------

Co-authored-by: GnomedDev <[email protected]>
  • Loading branch information
NotNorom and GnomedDev authored May 3, 2024
1 parent a72b980 commit 06fb5c4
Show file tree
Hide file tree
Showing 10 changed files with 711 additions and 697 deletions.
645 changes: 290 additions & 355 deletions .github/Cargo-msrv.lock

Large diffs are not rendered by default.

580 changes: 249 additions & 331 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/event_handler/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async fn event_handler(
let old_mentions = data.poise_mentions.fetch_add(1, Ordering::SeqCst);
new_message
.reply(
ctx,
&ctx.http,
format!("Poise has been mentioned {} times", old_mentions + 1),
)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion examples/feature_showcase/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub async fn delete(
#[description = "Message to be deleted"] msg: serenity::Message,
reason: Option<String>,
) -> Result<(), Error> {
msg.delete(ctx, reason.as_deref()).await?;
msg.delete(ctx.http(), reason.as_deref()).await?;
Ok(())
}

Expand Down
158 changes: 158 additions & 0 deletions examples/feature_showcase/code_block_parameter.expanded.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
mod code_block_parameter {
use crate::{Context, Error};
#[allow(clippy::str_to_string)]
pub fn code() -> ::poise::Command<
<Context<'static> as poise::_GetGenerics>::U,
<Context<'static> as poise::_GetGenerics>::E,
> {
pub async fn inner(
ctx: Context<'_>,
args: poise::KeyValueArgs,
code: poise::CodeBlock,
) -> Result<(), Error> {
ctx.say({
let res = ::alloc::fmt::format(
format_args!("Key value args: {0:?}\nCode: {1}", args, code),
);
res
})
.await?;
Ok(())
}
::poise::Command {
prefix_action: Some(|ctx| Box::pin(async move {
let (poise_param_0, poise_param_1, ..) = async {
use ::poise::PopArgument as _;
let ctx = ctx.serenity_context;
let msg = ctx.msg;
let args = ctx.args;
let attachment_index = 0;
let mut error: (
Box<dyn std::error::Error + Send + Sync>,
Option<String>,
) = (
Box::new(::poise::TooManyArguments {
__non_exhaustive: (),
}) as _,
None,
);
match {
use ::poise::PopArgumentHack as _;
(&std::marker::PhantomData::<poise::KeyValueArgs>)
.pop_from(&args, attachment_index, ctx, msg)
}
.await
{
Ok((args, attachment_index, token)) => {
match {
use ::poise::PopArgumentHack as _;
(&std::marker::PhantomData::<poise::CodeBlock>)
.pop_from(&args, attachment_index, ctx, msg)
}
.await
{
Ok((args, attachment_index, token)) => {
if args.is_empty() {
return Ok((token, token));
}
}
Err(e) => error = e,
};
}
Err(e) => error = e,
};
Err(error)
}
.await
.map_err(|(error, input)| poise::FrameworkError::new_argument_parse(
ctx.into(),
input,
error,
))?;
if !ctx.framework.options.manual_cooldowns {
ctx.command
.cooldowns
.lock()
.unwrap()
.start_cooldown(ctx.cooldown_context());
}
inner(ctx.into(), poise_param_0, poise_param_1)
.await
.map_err(|error| poise::FrameworkError::new_command(
ctx.into(),
error,
))
})),
slash_action: None,
context_menu_action: None,
subcommands: ::alloc::vec::Vec::new(),
subcommand_required: false,
name: "code".to_string(),
name_localizations: std::collections::HashMap::new(),
qualified_name: String::from("code"),
identifying_name: String::from("code"),
source_code_name: String::from("code"),
category: None,
description: None,
description_localizations: std::collections::HashMap::new(),
help_text: None,
hide_in_help: false,
cooldowns: std::sync::Mutex::new(::poise::Cooldowns::new()),
cooldown_config: std::sync::RwLock::new(::poise::CooldownConfig {
global: None,
user: None,
guild: None,
channel: None,
member: None,
__non_exhaustive: (),
}),
reuse_response: false,
default_member_permissions: poise::serenity_prelude::Permissions::empty(),
required_permissions: poise::serenity_prelude::Permissions::empty(),
required_bot_permissions: poise::serenity_prelude::Permissions::empty(),
owners_only: false,
guild_only: false,
dm_only: false,
nsfw_only: false,
checks: ::alloc::vec::Vec::new(),
on_error: None,
parameters: <[_]>::into_vec(
#[rustc_box]
::alloc::boxed::Box::new([
::poise::CommandParameter {
name: "args".to_string(),
name_localizations: std::collections::HashMap::new(),
description: None,
description_localizations: std::collections::HashMap::new(),
required: true,
channel_types: None,
type_setter: None,
choices: ::alloc::vec::Vec::new(),
autocomplete_callback: None,
__non_exhaustive: (),
},
::poise::CommandParameter {
name: "code".to_string(),
name_localizations: std::collections::HashMap::new(),
description: None,
description_localizations: std::collections::HashMap::new(),
required: true,
channel_types: None,
type_setter: None,
choices: ::alloc::vec::Vec::new(),
autocomplete_callback: None,
__non_exhaustive: (),
},
]),
),
custom_data: Box::new(()),
aliases: ::alloc::vec::Vec::new(),
invoke_on_edit: false,
track_deletion: false,
broadcast_typing: false,
context_menu_name: None,
ephemeral: false,
__non_exhaustive: (),
}
}
}
6 changes: 3 additions & 3 deletions examples/help_generation/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ async fn food_react(
let reaction = FOOD[rand::thread_rng().gen_range(0..FOOD.len())];
let reaction = serenity::ReactionType::Unicode(FixedString::from_str_trunc(reaction));

msg.react(ctx, reaction).await?;
msg.react(ctx.http(), reaction).await?;
ctx.say("Reacted!").await?;
Ok(())
}
Expand All @@ -262,7 +262,7 @@ async fn fruit_react(
let reaction = FRUIT[rand::thread_rng().gen_range(0..FRUIT.len())];
let reaction = serenity::ReactionType::Unicode(FixedString::from_str_trunc(reaction));

msg.react(ctx, reaction).await?;
msg.react(ctx.http(), reaction).await?;
ctx.say("Reacted!").await?;
Ok(())
}
Expand All @@ -281,7 +281,7 @@ async fn vegetable_react(
let reaction = VEGETABLES[rand::thread_rng().gen_range(0..VEGETABLES.len())];
let reaction = serenity::ReactionType::Unicode(FixedString::from_str_trunc(reaction));

msg.react(ctx, reaction).await?;
msg.react(ctx.http(), reaction).await?;
ctx.say("Reacted!").await?;
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions examples/manual_dispatch/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ struct Handler {
}
#[serenity::async_trait]
impl serenity::EventHandler for Handler {
async fn message(&self, serenity_context: &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,
serenity_context: &serenity_context,
options: &self.options,
shard_manager: &shard_manager,
};
Expand All @@ -35,7 +35,7 @@ impl serenity::EventHandler for Handler {

let res = poise::dispatch_message(
framework_data,
new_message,
&new_message,
trigger,
&invocation_data,
&mut parent_commands,
Expand Down
5 changes: 4 additions & 1 deletion src/dispatch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ pub async fn dispatch_event<U: Send + Sync + 'static, E>(
.unwrap()
.process_message_delete(*deleted_message_id);
if let Some(bot_response) = bot_response {
if let Err(e) = bot_response.delete(framework.serenity_context, None).await {
if let Err(e) = bot_response
.delete(&framework.serenity_context.http, None)
.await
{
tracing::warn!("failed to delete bot response: {}", e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/reply/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl ReplyHandle<'_> {
ctx: crate::Context<'_, U, E>,
) -> Result<(), serenity::Error> {
match &self.0 {
ReplyHandleInner::Prefix(msg) => msg.delete(ctx.serenity_context(), None).await?,
ReplyHandleInner::Prefix(msg) => msg.delete(ctx.http(), None).await?,
ReplyHandleInner::Application {
http: _,
interaction,
Expand Down
2 changes: 1 addition & 1 deletion src/reply/send_reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub async fn send_prefix_reply<'a, U: Send + Sync + 'static, E>(
let new_response = ctx
.msg
.channel_id
.send_message(ctx.serenity_context(), builder.to_prefix(ctx.msg.into()))
.send_message(ctx.http(), builder.to_prefix(ctx.msg.into()))
.await?;
// We don't check ctx.command.reuse_response because we need to store bot responses for
// track_deletion too
Expand Down

0 comments on commit 06fb5c4

Please sign in to comment.