Update to serenity 12
This commit is contained in:
1 parent
cd5651c7f6
commit
e632f55b4e
14 files changed
+1669
-1116
No files matched your search
+33
-59
@@ -1,10 +1,8 @@
|
||||
use poise::{
|
||||
serenity_prelude,
|
||||
serenity_prelude::{
|
||||
application::component::ButtonStyle,
|
||||
constants::MESSAGE_CODE_LIMIT,
|
||||
interaction::{message_component::MessageComponentInteraction, InteractionResponseType},
|
||||
CreateActionRow, CreateEmbed, GuildId, UserId,
|
||||
constants::MESSAGE_CODE_LIMIT, ButtonStyle, ComponentInteraction, CreateActionRow,
|
||||
CreateButton, CreateEmbed, EditInteractionResponse, GuildId, UserId,
|
||||
},
|
||||
CreateReply,
|
||||
};
|
||||
@@ -16,8 +14,8 @@ use crate::{
|
||||
Context, Data, Error,
|
||||
};
|
||||
|
||||
fn format_search_results<'a>(search_results: Vec<Sound>) -> CreateReply<'a> {
|
||||
let mut builder = CreateReply::default();
|
||||
fn format_search_results(search_results: Vec<Sound>) -> CreateReply {
|
||||
let builder = CreateReply::default();
|
||||
|
||||
let mut current_character_count = 0;
|
||||
let title = "Public sounds matching filter:";
|
||||
@@ -32,9 +30,7 @@ fn format_search_results<'a>(search_results: Vec<Sound>) -> CreateReply<'a> {
|
||||
current_character_count <= MESSAGE_CODE_LIMIT - title.len()
|
||||
});
|
||||
|
||||
builder.embed(|e| e.title(title).fields(field_iter));
|
||||
|
||||
builder
|
||||
builder.embed(CreateEmbed::default().title(title).fields(field_iter))
|
||||
}
|
||||
|
||||
/// Show uploaded sounds
|
||||
@@ -124,10 +120,8 @@ impl SoundPager {
|
||||
}
|
||||
|
||||
fn create_action_row(&self, max_page: u64) -> CreateActionRow {
|
||||
let mut row = CreateActionRow::default();
|
||||
|
||||
row.create_button(|b| {
|
||||
b.custom_id(
|
||||
let row = CreateActionRow::Buttons(vec![
|
||||
CreateButton::new(
|
||||
serde_json::to_string(&SoundPager {
|
||||
nonce: 0,
|
||||
page: 0,
|
||||
@@ -137,10 +131,8 @@ impl SoundPager {
|
||||
)
|
||||
.style(ButtonStyle::Primary)
|
||||
.label("⏪")
|
||||
.disabled(self.page == 0)
|
||||
})
|
||||
.create_button(|b| {
|
||||
b.custom_id(
|
||||
.disabled(self.page == 0),
|
||||
CreateButton::new(
|
||||
serde_json::to_string(&SoundPager {
|
||||
nonce: 1,
|
||||
page: self.page.saturating_sub(1),
|
||||
@@ -150,16 +142,12 @@ impl SoundPager {
|
||||
)
|
||||
.style(ButtonStyle::Secondary)
|
||||
.label("◀️")
|
||||
.disabled(self.page == 0)
|
||||
})
|
||||
.create_button(|b| {
|
||||
b.custom_id("pid")
|
||||
.disabled(self.page == 0),
|
||||
CreateButton::new("pid")
|
||||
.style(ButtonStyle::Success)
|
||||
.label(format!("Page {}", self.page + 1))
|
||||
.disabled(true)
|
||||
})
|
||||
.create_button(|b| {
|
||||
b.custom_id(
|
||||
.disabled(true),
|
||||
CreateButton::new(
|
||||
serde_json::to_string(&SoundPager {
|
||||
nonce: 2,
|
||||
page: self.page.saturating_add(1),
|
||||
@@ -169,10 +157,8 @@ impl SoundPager {
|
||||
)
|
||||
.style(ButtonStyle::Secondary)
|
||||
.label("▶️")
|
||||
.disabled(self.page == max_page)
|
||||
})
|
||||
.create_button(|b| {
|
||||
b.custom_id(
|
||||
.disabled(self.page == max_page),
|
||||
CreateButton::new(
|
||||
serde_json::to_string(&SoundPager {
|
||||
nonce: 3,
|
||||
page: max_page,
|
||||
@@ -182,16 +168,14 @@ impl SoundPager {
|
||||
)
|
||||
.style(ButtonStyle::Primary)
|
||||
.label("⏩")
|
||||
.disabled(self.page == max_page)
|
||||
});
|
||||
.disabled(self.page == max_page),
|
||||
]);
|
||||
|
||||
row
|
||||
}
|
||||
|
||||
fn embed(&self, sounds: &[Sound], count: u64) -> CreateEmbed {
|
||||
let mut embed = CreateEmbed::default();
|
||||
|
||||
embed
|
||||
CreateEmbed::default()
|
||||
.color(THEME_COLOR)
|
||||
.title(self.context.title())
|
||||
.description(format!("**{}** sounds:", count))
|
||||
@@ -205,15 +189,13 @@ impl SoundPager {
|
||||
),
|
||||
true,
|
||||
)
|
||||
}));
|
||||
|
||||
embed
|
||||
}))
|
||||
}
|
||||
|
||||
pub async fn handle_interaction(
|
||||
ctx: &serenity_prelude::Context,
|
||||
data: &Data,
|
||||
interaction: &MessageComponentInteraction,
|
||||
interaction: &ComponentInteraction,
|
||||
) -> Result<(), Error> {
|
||||
let user_id = interaction.user.id;
|
||||
let guild_id = interaction.guild_id.unwrap();
|
||||
@@ -227,14 +209,12 @@ impl SoundPager {
|
||||
};
|
||||
|
||||
interaction
|
||||
.create_interaction_response(&ctx, |r| {
|
||||
r.kind(InteractionResponseType::UpdateMessage)
|
||||
.interaction_response_data(|d| {
|
||||
d.ephemeral(true)
|
||||
.add_embed(pager.embed(&sounds, count))
|
||||
.components(|c| c.add_action_row(pager.create_action_row(count / 25)))
|
||||
})
|
||||
})
|
||||
.edit_response(
|
||||
&ctx,
|
||||
EditInteractionResponse::default()
|
||||
.add_embed(pager.embed(&sounds, count))
|
||||
.components(vec![pager.create_action_row(count / 25)]),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
@@ -254,14 +234,12 @@ impl SoundPager {
|
||||
}
|
||||
};
|
||||
|
||||
ctx.send(|r| {
|
||||
r.ephemeral(true)
|
||||
.embed(|e| {
|
||||
*e = self.embed(&sounds, count);
|
||||
e
|
||||
})
|
||||
.components(|c| c.add_action_row(self.create_action_row(count / 25)))
|
||||
})
|
||||
ctx.send(
|
||||
CreateReply::default()
|
||||
.ephemeral(true)
|
||||
.embed(self.embed(&sounds, count))
|
||||
.components(vec![self.create_action_row(count / 25)]),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
@@ -284,11 +262,7 @@ pub async fn search_sounds(
|
||||
.search_for_sound(&query, ctx.guild_id().unwrap(), ctx.author().id, false)
|
||||
.await?;
|
||||
|
||||
ctx.send(|m| {
|
||||
*m = format_search_results(search_results);
|
||||
m
|
||||
})
|
||||
.await?;
|
||||
ctx.send(format_search_results(search_results)).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user