Update to serenity 12

This commit is contained in:
claude Bot committed 2023-12-19 19:37:41 +00:00
1 parent cd5651c7f6
commit e632f55b4e
14 files changed
+1669 -1116

No files matched your search

+91 -83
View File
@@ -1,8 +1,10 @@
use std::time::{SystemTime, UNIX_EPOCH};
use poise::serenity_prelude::{
builder::CreateActionRow, model::application::component::ButtonStyle, GuildChannel,
ReactionType,
use poise::{
serenity_prelude::{
builder::CreateActionRow, ButtonStyle, CreateButton, GuildChannel, ReactionType,
},
CreateReply,
};
#[cfg(feature = "metrics")]
@@ -30,13 +32,13 @@ pub async fn play(
ctx.defer().await?;
let guild = ctx.guild().unwrap();
let guild = ctx.guild().map(|g| g.clone()).unwrap();
ctx.say(
play_from_query(
&ctx.serenity_context(),
&ctx.data(),
guild,
&guild,
ctx.author().id,
channel.map(|c| c.id),
&name,
@@ -64,20 +66,25 @@ pub async fn play_random(
) -> Result<(), Error> {
ctx.defer().await?;
let guild = ctx.guild().unwrap();
let channel_to_join = channel.map(|c| c.id).or_else(|| {
guild
.voice_states
.get(&ctx.author().id)
.and_then(|voice_state| voice_state.channel_id)
});
let (channel_to_join, guild_id) = {
let guild = ctx.guild().unwrap();
(
channel.map(|c| c.id).or_else(|| {
guild
.voice_states
.get(&ctx.author().id)
.and_then(|voice_state| voice_state.channel_id)
}),
guild.id,
)
};
match channel_to_join {
Some(channel) => {
let (call_handler, _) =
join_channel(ctx.serenity_context(), guild.clone(), channel).await;
let call = join_channel(ctx.serenity_context(), guild_id, channel).await?;
let sounds = ctx.data().guild_sounds(guild.id, None).await?;
let sounds = ctx.data().guild_sounds(guild_id, None).await?;
if sounds.len() == 0 {
ctx.say("No sounds in this server!").await?;
return Ok(());
@@ -91,8 +98,8 @@ pub async fn play_random(
// anyway.
match sounds.get(ts.subsec_micros() as usize % sounds.len()) {
Some(sound) => {
let guild_data = ctx.data().guild_data(guild.id).await.unwrap();
let mut lock = call_handler.lock().await;
let guild_data = ctx.data().guild_data(guild_id).await.unwrap();
let mut lock = call.lock().await;
play_audio(
sound,
@@ -209,25 +216,23 @@ pub async fn queue_play(
) -> Result<(), Error> {
ctx.defer().await?;
let guild = ctx.guild().unwrap();
let (channel_to_join, guild_id) = {
let guild = ctx.guild().unwrap();
let channel_to_join = guild
.voice_states
.get(&ctx.author().id)
.and_then(|voice_state| voice_state.channel_id);
(
guild
.voice_states
.get(&ctx.author().id)
.and_then(|voice_state| voice_state.channel_id),
guild.id,
)
};
match channel_to_join {
Some(user_channel) => {
let (call_handler, _) =
join_channel(ctx.serenity_context(), guild.clone(), user_channel).await;
let call = join_channel(ctx.serenity_context(), guild_id, user_channel).await?;
let guild_data = ctx
.data()
.guild_data(ctx.guild_id().unwrap())
.await
.unwrap();
let mut lock = call_handler.lock().await;
let guild_data = ctx.data().guild_data(guild_id).await.unwrap();
let query_terms = [
Some(sound_1),
@@ -270,14 +275,18 @@ pub async fn queue_play(
}
}
queue_audio(
&sounds,
guild_data.read().await.volume,
&mut lock,
&ctx.data().database,
)
.await
.unwrap();
{
let mut lock = call.lock().await;
queue_audio(
&sounds,
guild_data.read().await.volume,
&mut lock,
&ctx.data().database,
)
.await
.unwrap();
}
ctx.say(format!("Queued {} sounds!", sounds.len())).await?;
}
@@ -304,13 +313,13 @@ pub async fn loop_play(
) -> Result<(), Error> {
ctx.defer().await?;
let guild = ctx.guild().unwrap();
let guild = ctx.guild().map(|g| g.clone()).unwrap();
ctx.say(
play_from_query(
&ctx.serenity_context(),
&ctx.data(),
guild,
&guild,
ctx.author().id,
None,
&name,
@@ -434,50 +443,49 @@ pub async fn soundboard(
}
}
ctx.send(|m| {
m.content("**Play a sound:**").components(|c| {
for row in sounds.as_slice().chunks(5) {
let mut action_row: CreateActionRow = Default::default();
for sound in row {
action_row.create_button(|b| {
b.style(ButtonStyle::Primary)
.label(&sound.name)
.custom_id(sound.id)
});
}
c.add_action_row(action_row);
let components = {
let mut c = vec![];
for row in sounds.as_slice().chunks(5) {
let mut action_row = vec![];
for sound in row {
action_row.push(
CreateButton::new(sound.id.to_string())
.style(ButtonStyle::Primary)
.label(&sound.name),
);
}
c.create_action_row(|r| {
r.create_button(|b| {
b.label("Stop")
.emoji(ReactionType::Unicode("⏹".to_string()))
.style(ButtonStyle::Danger)
.custom_id("#stop")
})
.create_button(|b| {
b.label("Mode:")
.style(ButtonStyle::Secondary)
.disabled(true)
.custom_id("#mode")
})
.create_button(|b| {
b.label("Instant")
.emoji(ReactionType::Unicode("▶".to_string()))
.style(ButtonStyle::Secondary)
.disabled(true)
.custom_id("#instant")
})
.create_button(|b| {
b.label("Loop")
.emoji(ReactionType::Unicode("🔁".to_string()))
.style(ButtonStyle::Secondary)
.custom_id("#loop")
})
})
})
})
c.push(CreateActionRow::Buttons(action_row));
}
c.push(CreateActionRow::Buttons(vec![
CreateButton::new("#stop")
.label("Stop")
.emoji(ReactionType::Unicode("⏹".to_string()))
.style(ButtonStyle::Danger),
CreateButton::new("#mode")
.label("Mode:")
.style(ButtonStyle::Secondary)
.disabled(true),
CreateButton::new("#instant")
.label("Instant")
.emoji(ReactionType::Unicode("▶".to_string()))
.style(ButtonStyle::Secondary)
.disabled(true),
CreateButton::new("#loop")
.label("Loop")
.emoji(ReactionType::Unicode("🔁".to_string()))
.style(ButtonStyle::Secondary),
]));
c
};
ctx.send(
CreateReply::default()
.content("**Play a sound:**")
.components(components),
)
.await?;
Ok(())