Skip to content

Commit

Permalink
Fix breakage caused by builder trait removal
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Feb 9, 2024
1 parent 2361a39 commit 70c7b26
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 37 deletions.
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/feature_showcase/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
}

Expand Down
21 changes: 17 additions & 4 deletions examples/manual_dispatch/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/paginate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub async fn paginate<U: Send + Sync + 'static, E>(
// 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])),
Expand Down
8 changes: 4 additions & 4 deletions src/dispatch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<U: Send + Sync + 'static, E>(
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();
Expand Down Expand Up @@ -172,10 +172,10 @@ pub async fn dispatch_event<U: Send + Sync + 'static, E>(

// 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;
Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/slash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ async fn run_autocomplete<U: Send + Sync + 'static, E>(
if let Err(e) = ctx
.interaction
.create_response(
&ctx.framework.serenity_context,
ctx.http(),
serenity::CreateInteractionResponse::Autocomplete(autocomplete_response),
)
.await
Expand Down
10 changes: 5 additions & 5 deletions src/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<U: Send + Sync + 'static, E: Send + Sync> 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
}
}
Expand All @@ -116,12 +116,12 @@ impl<U: Send + Sync + 'static, E: Send + Sync> serenity::Framework for Framework
/// Otherwise, it forwards the event to [`crate::dispatch_event`]
async fn raw_dispatch_event<U, E>(
framework: &Framework<U, E>,
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);
}

Expand All @@ -133,7 +133,7 @@ async fn raw_dispatch_event<U, E>(
let framework = crate::FrameworkContext {
#[cfg(not(feature = "cache"))]
bot_id,
serenity_context: &ctx,
serenity_context,
options: &framework.options,
shard_manager: framework.shard_manager(),
};
Expand Down
6 changes: 3 additions & 3 deletions src/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -94,7 +94,7 @@ pub async fn execute_modal<U: Send + Sync + 'static, E, M: 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,
Expand Down Expand Up @@ -125,7 +125,7 @@ pub async fn execute_modal_on_component_interaction<M: Modal>(
) -> Result<Option<M>, 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,
Expand Down
6 changes: 2 additions & 4 deletions src/reply/send_reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,15 @@ 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 =
builder.to_slash_initial_response(serenity::CreateInteractionResponseMessage::new());

ctx.interaction
.create_response(
ctx.serenity_context(),
ctx.http(),
serenity::CreateInteractionResponse::Message(builder),
)
.await?;
Expand Down
5 changes: 2 additions & 3 deletions src/structs/slash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ impl<U, E> 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);
Expand Down

0 comments on commit 70c7b26

Please sign in to comment.