restructured a lot. everything updated to poise.

This commit is contained in:
jude committed 2022-01-26 20:33:51 +00:00
1 parent bb54c0d2c0
commit b350007dae
15 files changed
+775 -757

No files matched your search

+113 -43
View File
@@ -2,32 +2,58 @@ use poise::serenity::{
builder::CreateActionRow, model::interactions::message_component::ButtonStyle,
};
use crate::{play_from_query, sound::Sound, Context, Error};
use crate::{
cmds::autocomplete_sound, models::sound::SoundCtx, utils::play_from_query, Context, Error,
};
/// Play a sound in your current voice channel
#[poise::command(slash_command)]
pub async fn play(
ctx: Context<'_>,
#[description = "Name or ID of sound to play"] name: String,
#[description = "Name or ID of sound to play"]
#[autocomplete = "autocomplete_sound"]
name: String,
) -> Result<(), Error> {
let guild = ctx.guild().unwrap();
ctx.say(play_from_query(&ctx, guild, ctx.author().id, &name, false).await)
.await?;
ctx.say(
play_from_query(
&ctx.discord(),
&ctx.data(),
guild,
ctx.author().id,
&name,
false,
)
.await,
)
.await?;
Ok(())
}
/// Loop a sound in your current voice channel
#[poise::command(slash_command)]
#[poise::command(slash_command, rename = "loop")]
pub async fn loop_play(
ctx: Context<'_>,
#[description = "Name or ID of sound to loop"] name: String,
#[description = "Name or ID of sound to loop"]
#[autocomplete = "autocomplete_sound"]
name: String,
) -> Result<(), Error> {
let guild = ctx.guild().unwrap();
ctx.say(play_from_query(&ctx, guild, ctx.author().id, &name, true).await)
.await?;
ctx.say(
play_from_query(
&ctx.discord(),
&ctx.data(),
guild,
ctx.author().id,
&name,
true,
)
.await,
)
.await?;
Ok(())
}
@@ -36,36 +62,84 @@ pub async fn loop_play(
#[poise::command(slash_command, rename = "soundboard", category = "Play")]
pub async fn soundboard(
ctx: Context<'_>,
#[description = "Name or ID of sound for button 1"] sound_1: String,
#[description = "Name or ID of sound for button 2"] sound_2: Option<String>,
#[description = "Name or ID of sound for button 3"] sound_3: Option<String>,
#[description = "Name or ID of sound for button 4"] sound_4: Option<String>,
#[description = "Name or ID of sound for button 5"] sound_5: Option<String>,
#[description = "Name or ID of sound for button 6"] sound_6: Option<String>,
#[description = "Name or ID of sound for button 7"] sound_7: Option<String>,
#[description = "Name or ID of sound for button 8"] sound_8: Option<String>,
#[description = "Name or ID of sound for button 9"] sound_9: Option<String>,
#[description = "Name or ID of sound for button 10"] sound_10: Option<String>,
#[description = "Name or ID of sound for button 11"] sound_11: Option<String>,
#[description = "Name or ID of sound for button 12"] sound_12: Option<String>,
#[description = "Name or ID of sound for button 13"] sound_13: Option<String>,
#[description = "Name or ID of sound for button 14"] sound_14: Option<String>,
#[description = "Name or ID of sound for button 15"] sound_15: Option<String>,
#[description = "Name or ID of sound for button 16"] sound_16: Option<String>,
#[description = "Name or ID of sound for button 17"] sound_17: Option<String>,
#[description = "Name or ID of sound for button 18"] sound_18: Option<String>,
#[description = "Name or ID of sound for button 19"] sound_19: Option<String>,
#[description = "Name or ID of sound for button 20"] sound_20: Option<String>,
#[description = "Name or ID of sound for button 21"] sound_21: Option<String>,
#[description = "Name or ID of sound for button 22"] sound_22: Option<String>,
#[description = "Name or ID of sound for button 23"] sound_23: Option<String>,
#[description = "Name or ID of sound for button 24"] sound_24: Option<String>,
#[description = "Name or ID of sound for button 25"] sound_25: Option<String>,
#[description = "Name or ID of sound for button 1"]
#[autocomplete = "autocomplete_sound"]
sound_1: String,
#[description = "Name or ID of sound for button 2"]
#[autocomplete = "autocomplete_sound"]
sound_2: Option<String>,
#[description = "Name or ID of sound for button 3"]
#[autocomplete = "autocomplete_sound"]
sound_3: Option<String>,
#[description = "Name or ID of sound for button 4"]
#[autocomplete = "autocomplete_sound"]
sound_4: Option<String>,
#[description = "Name or ID of sound for button 5"]
#[autocomplete = "autocomplete_sound"]
sound_5: Option<String>,
#[description = "Name or ID of sound for button 6"]
#[autocomplete = "autocomplete_sound"]
sound_6: Option<String>,
#[description = "Name or ID of sound for button 7"]
#[autocomplete = "autocomplete_sound"]
sound_7: Option<String>,
#[description = "Name or ID of sound for button 8"]
#[autocomplete = "autocomplete_sound"]
sound_8: Option<String>,
#[description = "Name or ID of sound for button 9"]
#[autocomplete = "autocomplete_sound"]
sound_9: Option<String>,
#[description = "Name or ID of sound for button 10"]
#[autocomplete = "autocomplete_sound"]
sound_10: Option<String>,
#[description = "Name or ID of sound for button 11"]
#[autocomplete = "autocomplete_sound"]
sound_11: Option<String>,
#[description = "Name or ID of sound for button 12"]
#[autocomplete = "autocomplete_sound"]
sound_12: Option<String>,
#[description = "Name or ID of sound for button 13"]
#[autocomplete = "autocomplete_sound"]
sound_13: Option<String>,
#[description = "Name or ID of sound for button 14"]
#[autocomplete = "autocomplete_sound"]
sound_14: Option<String>,
#[description = "Name or ID of sound for button 15"]
#[autocomplete = "autocomplete_sound"]
sound_15: Option<String>,
#[description = "Name or ID of sound for button 16"]
#[autocomplete = "autocomplete_sound"]
sound_16: Option<String>,
#[description = "Name or ID of sound for button 17"]
#[autocomplete = "autocomplete_sound"]
sound_17: Option<String>,
#[description = "Name or ID of sound for button 18"]
#[autocomplete = "autocomplete_sound"]
sound_18: Option<String>,
#[description = "Name or ID of sound for button 19"]
#[autocomplete = "autocomplete_sound"]
sound_19: Option<String>,
#[description = "Name or ID of sound for button 20"]
#[autocomplete = "autocomplete_sound"]
sound_20: Option<String>,
#[description = "Name or ID of sound for button 21"]
#[autocomplete = "autocomplete_sound"]
sound_21: Option<String>,
#[description = "Name or ID of sound for button 22"]
#[autocomplete = "autocomplete_sound"]
sound_22: Option<String>,
#[description = "Name or ID of sound for button 23"]
#[autocomplete = "autocomplete_sound"]
sound_23: Option<String>,
#[description = "Name or ID of sound for button 24"]
#[autocomplete = "autocomplete_sound"]
sound_24: Option<String>,
#[description = "Name or ID of sound for button 25"]
#[autocomplete = "autocomplete_sound"]
sound_25: Option<String>,
) -> Result<(), Error> {
ctx.defer().await?;
let pool = ctx.data().database.clone();
let query_terms = [
Some(sound_1),
sound_2,
@@ -97,14 +171,10 @@ pub async fn soundboard(
let mut sounds = vec![];
for sound in query_terms.iter().flatten() {
let search = Sound::search_for_sound(
&sound,
ctx.guild_id().unwrap(),
ctx.author().id,
pool.clone(),
true,
)
.await?;
let search = ctx
.data()
.search_for_sound(&sound, ctx.guild_id().unwrap(), ctx.author().id, true)
.await?;
if let Some(sound) = search.first() {
if !sounds.contains(sound) {