Skip to content

Commit

Permalink
Fix breakage caused by AsRef and simd-json removal
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Jan 24, 2024
1 parent 376547c commit 2240841
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 66 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ jobs:
# don't test examples because they need collector feature
command: cargo test --no-default-features --features serenity/rustls_backend --lib --tests

# - name: all features + simdjson
# command: cargo test --all-features --features serenity/simdjson --lib --tests --examples
# rustflags: -C target-cpu=haswell # needed for simdjson
- name: all features - simdjson
command: cargo test --all-features --lib --tests --examples

- name: native TLS
command: cargo test --all-features --features serenity/native_tls_backend --lib --tests --examples

Expand Down
29 changes: 14 additions & 15 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/advanced_cooldowns/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn dynamic_cooldowns(ctx: Context<'_>) -> Result<(), Error> {
#[poise::command(prefix_command, owners_only)]
async fn register_commands(ctx: Context<'_>) -> Result<(), Error> {
let commands = &ctx.framework().options().commands;
poise::builtins::register_globally(ctx, commands).await?;
poise::builtins::register_globally(ctx.http(), commands).await?;

ctx.say("Successfully registered slash commands!").await?;
Ok(())
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 @@ -38,7 +38,7 @@ async fn on_error(error: poise::FrameworkError<'_, Data, Error>) {
#[poise::command(prefix_command, owners_only)]
async fn register_commands(ctx: Context<'_>) -> Result<(), Error> {
let commands = &ctx.framework().options().commands;
poise::builtins::register_globally(ctx, commands).await?;
poise::builtins::register_globally(ctx.http(), commands).await?;

ctx.say("Successfully registered slash commands!").await?;
Ok(())
Expand Down
3 changes: 2 additions & 1 deletion examples/feature_showcase/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ pub async fn boop(ctx: Context<'_>) -> Result<(), Error> {
ctx.send(reply).await?;

let mut boop_count = 0;
while let Some(mci) = serenity::ComponentInteractionCollector::new(ctx)
let shard_messenger = &ctx.serenity_context().shard;
while let Some(mci) = serenity::ComponentInteractionCollector::new(shard_messenger.clone())
.author_id(ctx.author().id)
.channel_id(ctx.channel_id())
.timeout(std::time::Duration::from_secs(120))
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 @@ -29,7 +29,7 @@ pub type Data = ();
#[poise::command(prefix_command, owners_only)]
async fn register_commands(ctx: Context<'_>) -> Result<(), Error> {
let commands = &ctx.framework().options().commands;
poise::builtins::register_globally(ctx, commands).await?;
poise::builtins::register_globally(ctx.http(), commands).await?;

ctx.say("Successfully registered slash commands!").await?;
Ok(())
Expand Down
13 changes: 10 additions & 3 deletions examples/feature_showcase/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,20 @@ pub async fn component_modal(ctx: crate::Context<'_>) -> Result<(), Error> {

ctx.send(reply).await?;

while let Some(mci) = serenity::ComponentInteractionCollector::new(ctx.serenity_context())
let serenity_context = ctx.serenity_context();
let shard_messenger = &serenity_context.shard;
while let Some(mci) = serenity::ComponentInteractionCollector::new(shard_messenger.clone())
.timeout(std::time::Duration::from_secs(120))
.filter(move |mci| mci.data.custom_id == "open_modal")
.await
{
let data =
poise::execute_modal_on_component_interaction::<MyModal>(ctx, mci, None, None).await?;
let data = poise::execute_modal_on_component_interaction::<MyModal>(
serenity_context,
mci,
None,
None,
)
.await?;
println!("Got data: {:?}", data);
}
Ok(())
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 @@ -322,7 +322,7 @@ You can edit your `?help` message to the bot and the bot will edit its response.
#[poise::command(prefix_command, owners_only)]
async fn register_commands(ctx: Context<'_>) -> Result<(), Error> {
let commands = &ctx.framework().options().commands;
poise::builtins::register_globally(ctx, commands).await?;
poise::builtins::register_globally(ctx.http(), commands).await?;

ctx.say("Successfully registered slash commands!").await?;
Ok(())
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 @@ -50,7 +50,7 @@ pub async fn invocation_data_test(
#[poise::command(prefix_command, owners_only)]
async fn register_commands(ctx: Context<'_>) -> Result<(), Error> {
let commands = &ctx.framework().options().commands;
poise::builtins::register_globally(ctx, commands).await?;
poise::builtins::register_globally(ctx.http(), commands).await?;

ctx.say("Successfully registered slash commands!").await?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstart/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async fn age(
#[poise::command(prefix_command, owners_only)]
async fn register_commands(ctx: Context<'_>) -> Result<(), Error> {
let commands = &ctx.framework().options().commands;
poise::builtins::register_globally(ctx, commands).await?;
poise::builtins::register_globally(ctx.http(), commands).await?;

ctx.say("Successfully registered slash commands!").await?;
Ok(())
Expand Down
16 changes: 9 additions & 7 deletions src/builtins/paginate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ pub async fn paginate<U: Send + Sync + 'static, E>(

// Loop through incoming interactions with the navigation buttons
let mut current_page = 0;
while let Some(press) = serenity::collector::ComponentInteractionCollector::new(ctx)
// We defined our button IDs to start with `ctx_id`. If they don't, some other command's
// button was pressed
.filter(move |press| press.data.custom_id.starts_with(&ctx_id.to_string()))
// Timeout when no navigation button has been pressed for 24 hours
.timeout(std::time::Duration::from_secs(3600 * 24))
.await
let shard_messenger = &ctx.serenity_context().shard;
while let Some(press) =
serenity::collector::ComponentInteractionCollector::new(shard_messenger.clone())
// We defined our button IDs to start with `ctx_id`. If they don't, some other command's
// button was pressed
.filter(move |press| press.data.custom_id.starts_with(&ctx_id.to_string()))
// Timeout when no navigation button has been pressed for 24 hours
.timeout(std::time::Duration::from_secs(3600 * 24))
.await
{
// Depending on which button was pressed, go to next or previous page
if press.data.custom_id.as_str() == next_button_id {
Expand Down
18 changes: 9 additions & 9 deletions src/builtins/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn create_application_commands<U, E>(
/// Thin wrapper around [`create_application_commands`] that funnels the returned builder into
/// [`serenity::Command::set_global_commands`].
pub async fn register_globally<U, E>(
http: impl AsRef<serenity::Http>,
http: &serenity::Http,
commands: &[crate::Command<U, E>],
) -> Result<(), serenity::Error> {
let builder = create_application_commands(commands);
Expand All @@ -63,7 +63,7 @@ pub async fn register_globally<U, E>(
/// Thin wrapper around [`create_application_commands`] that funnels the returned builder into
/// [`serenity::GuildId::set_commands`].
pub async fn register_in_guild<U, E>(
http: impl AsRef<serenity::Http>,
http: &serenity::Http,
commands: &[crate::Command<U, E>],
guild_id: serenity::GuildId,
) -> Result<(), serenity::Error> {
Expand Down Expand Up @@ -101,7 +101,7 @@ pub async fn register_application_commands<U: Send + Sync + 'static, E>(
if global {
ctx.say(format!("Registering {num_commands} commands...",))
.await?;
serenity::Command::set_global_commands(ctx, &commands_builder).await?;
serenity::Command::set_global_commands(ctx.http(), &commands_builder).await?;
} else {
let guild_id = match ctx.guild_id() {
Some(x) => x,
Expand All @@ -113,7 +113,7 @@ pub async fn register_application_commands<U: Send + Sync + 'static, E>(

ctx.say(format!("Registering {num_commands} commands..."))
.await?;
guild_id.set_commands(ctx, &commands_builder).await?;
guild_id.set_commands(ctx.http(), &commands_builder).await?;
}

ctx.say("Done!").await?;
Expand Down Expand Up @@ -188,7 +188,7 @@ pub async fn register_application_commands_buttons<U: Send + Sync + 'static, E>(
let interaction = reply
.message()
.await?
.await_component_interaction(ctx)
.await_component_interaction(ctx.serenity_context().shard.clone())
.author_id(ctx.author().id)
.await;

Expand Down Expand Up @@ -228,10 +228,10 @@ pub async fn register_application_commands_buttons<U: Send + Sync + 'static, E>(
":gear: Registering {num_commands} global commands...",
))
.await?;
serenity::Command::set_global_commands(ctx, &create_commands).await?;
serenity::Command::set_global_commands(ctx.http(), &create_commands).await?;
} else {
ctx.say(":gear: Unregistering global commands...").await?;
serenity::Command::set_global_commands(ctx, &[]).await?;
serenity::Command::set_global_commands(ctx.http(), &[]).await?;
}
} else {
let guild_id = match ctx.guild_id() {
Expand All @@ -246,10 +246,10 @@ pub async fn register_application_commands_buttons<U: Send + Sync + 'static, E>(
":gear: Registering {num_commands} guild commands...",
))
.await?;
guild_id.set_commands(ctx, &create_commands).await?;
guild_id.set_commands(ctx.http(), &create_commands).await?;
} else {
ctx.say(":gear: Unregistering guild commands...").await?;
guild_id.set_commands(ctx, &[]).await?;
guild_id.set_commands(ctx.http(), &[]).await?;
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/choice_parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ impl<T: ChoiceParameter> crate::SlashArgument for T {
_: &serenity::CommandInteraction,
value: &serenity::ResolvedValue<'_>,
) -> ::std::result::Result<Self, crate::SlashArgError> {
#[allow(unused_imports)]
use ::serenity::json::*; // Required for simd-json :|

let choice_key = match value {
serenity::ResolvedValue::Integer(int) => *int as u64,
_ => {
Expand Down
3 changes: 0 additions & 3 deletions src/dispatch/slash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ async fn run_autocomplete<U: Send + Sync + 'static, E>(
_ => return Ok(()),
};

#[allow(unused_imports)]
use ::serenity::json::*; // as_str() access via trait for simd-json

// Generate an autocomplete response
let autocomplete_response = match autocomplete_callback(ctx, partial_input).await {
Ok(x) => x,
Expand Down
8 changes: 4 additions & 4 deletions src/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn execute_modal_generic<
create_interaction_response(M::create(defaults, modal_custom_id.clone())).await?;

// Wait for user to submit
let response = serenity::collector::ModalInteractionCollector::new(&ctx.shard)
let response = serenity::collector::ModalInteractionCollector::new(ctx.shard.clone())
.filter(move |d| d.data.custom_id.as_str() == modal_custom_id)
.timeout(timeout.unwrap_or(std::time::Duration::from_secs(3600)))
.await;
Expand Down Expand Up @@ -118,14 +118,14 @@ pub async fn execute_modal<U: Send + Sync + 'static, E, M: Modal>(
/// If you need more specialized behavior, you can copy paste the implementation of this function
/// and adjust to your needs. The code of this function is just a starting point.
pub async fn execute_modal_on_component_interaction<M: Modal>(
ctx: impl AsRef<serenity::Context>,
ctx: &serenity::Context,
interaction: serenity::ComponentInteraction,
defaults: Option<M>,
timeout: Option<std::time::Duration>,
) -> Result<Option<M>, serenity::Error> {
execute_modal_generic(
ctx.as_ref(),
|resp| interaction.create_response(ctx.as_ref(), resp),
ctx,
|resp| interaction.create_response(ctx, resp),
interaction.id.to_string(),
defaults,
timeout,
Expand Down
4 changes: 2 additions & 2 deletions src/reply/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ impl ReplyHandle<'_> {
followup,
} => match followup {
Some(followup) => {
interaction.delete_followup(ctx, followup.id).await?;
interaction.delete_followup(ctx.http(), followup.id).await?;
}
None => {
interaction.delete_response(ctx).await?;
interaction.delete_response(ctx.http()).await?;
}
},
ReplyHandleInner::Autocomplete => panic!("delete is a no-op in autocomplete context"),
Expand Down
2 changes: 0 additions & 2 deletions src/slash_argument/slash_macro.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Infrastructure to parse received slash command arguments into Rust types.
#[allow(unused_imports)] // import is required if serenity simdjson feature is enabled
use crate::serenity::json::*;
#[allow(unused_imports)] // required for introdoc-links in doc comments
use crate::serenity_prelude as serenity;

Expand Down
2 changes: 0 additions & 2 deletions src/slash_argument/slash_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use super::SlashArgError;
use std::convert::TryInto as _;
use std::marker::PhantomData;

#[allow(unused_imports)] // import is required if serenity simdjson feature is enabled
use crate::serenity::json::*;
use crate::serenity_prelude as serenity;

/// Implement this trait on types that you want to use as a slash command parameter.
Expand Down
4 changes: 1 addition & 3 deletions src/structs/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ context_methods! {
#[cfg(feature = "cache")]
(guild self)
(pub fn guild(self) -> Option<serenity::GuildRef<'a>>) {
self.guild_id()?.to_guild_cached(self.serenity_context())
self.guild_id()?.to_guild_cached(self.cache())
}

// Doesn't fit in with the rest of the functions here but it's convenient
Expand Down Expand Up @@ -399,8 +399,6 @@ context_methods! {
}
string += &ctx.command.name;
for arg in ctx.args {
#[allow(unused_imports)] // required for simd-json
use ::serenity::json::*;
use std::fmt::Write as _;

string += " ";
Expand Down

0 comments on commit 2240841

Please sign in to comment.