soundboard working pretty nicely

This commit is contained in:
jellywx 2021-06-25 18:45:59 +01:00
parent b4b8d16bcc
commit 87301e4212
5 changed files with 193 additions and 16 deletions

View File

@ -68,7 +68,7 @@ pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream {
_ => {
match_options!(name, values, options, span => [
aliases;
usage;
group;
required_permissions;
allow_slash
]);
@ -79,7 +79,7 @@ pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream {
let Options {
aliases,
description,
usage,
group,
examples,
required_permissions,
allow_slash,
@ -108,7 +108,10 @@ pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream {
let arg_idents = cmd_args
.iter()
.map(|arg| n.with_suffix(arg.name.as_str()).with_suffix(ARG))
.map(|arg| {
n.with_suffix(arg.name.replace(" ", "_").replace("-", "_").as_str())
.with_suffix(ARG)
})
.collect::<Vec<Ident>>();
let mut tokens = cmd_args
@ -146,7 +149,7 @@ pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream {
fun: #name,
names: &[#_name, #(#aliases),*],
desc: #description,
usage: #usage,
group: #group,
examples: &[#(#examples),*],
required_permissions: #required_permissions,
allow_slash: #allow_slash,

View File

@ -290,7 +290,7 @@ impl Default for Arg {
pub(crate) struct Options {
pub aliases: Vec<String>,
pub description: String,
pub usage: AsOption<String>,
pub group: AsOption<String>,
pub examples: Vec<String>,
pub required_permissions: PermissionLevel,
pub allow_slash: bool,

View File

@ -108,11 +108,9 @@ impl CreateGenericResponse {
pub fn embed<F: FnOnce(&mut CreateEmbed) -> &mut CreateEmbed>(mut self, f: F) -> Self {
let mut embed = CreateEmbed::default();
f(&mut embed);
self.embed = Some(embed);
self
}
@ -121,11 +119,9 @@ impl CreateGenericResponse {
f: F,
) -> Self {
let mut components = CreateComponents::default();
f(&mut components);
self.components = Some(components);
self
}
}
@ -344,12 +340,15 @@ impl Arg {
pub struct Command {
pub fun: CommandFn,
pub names: &'static [&'static str],
pub desc: &'static str,
pub usage: Option<&'static str>,
pub examples: &'static [&'static str],
pub required_permissions: PermissionLevel,
pub group: Option<&'static str>,
pub allow_slash: bool,
pub required_permissions: PermissionLevel,
pub args: &'static [&'static Arg],
}

View File

@ -48,6 +48,7 @@ use dashmap::DashMap;
use std::{collections::HashMap, convert::TryFrom, env, sync::Arc, time::Duration};
use serenity::model::prelude::InteractionResponseType;
use tokio::sync::{MutexGuard, RwLock};
struct MySQL;
@ -1137,12 +1138,170 @@ async fn list_sounds(
#[command("soundboard")]
#[aliases("board")]
#[description("Get a menu of sounds in this server with buttons to play them")]
#[description("Get a menu of sounds with buttons to play them")]
#[arg(
name = "1",
description = "Query for sound button 1",
kind = "String",
required = false
)]
#[arg(
name = "2",
description = "Query for sound button 2",
kind = "String",
required = false
)]
#[arg(
name = "3",
description = "Query for sound button 3",
kind = "String",
required = false
)]
#[arg(
name = "4",
description = "Query for sound button 4",
kind = "String",
required = false
)]
#[arg(
name = "5",
description = "Query for sound button 5",
kind = "String",
required = false
)]
#[arg(
name = "6",
description = "Query for sound button 6",
kind = "String",
required = false
)]
#[arg(
name = "7",
description = "Query for sound button 7",
kind = "String",
required = false
)]
#[arg(
name = "8",
description = "Query for sound button 8",
kind = "String",
required = false
)]
#[arg(
name = "9",
description = "Query for sound button 9",
kind = "String",
required = false
)]
#[arg(
name = "10",
description = "Query for sound button 10",
kind = "String",
required = false
)]
#[arg(
name = "11",
description = "Query for sound button 11",
kind = "String",
required = false
)]
#[arg(
name = "12",
description = "Query for sound button 12",
kind = "String",
required = false
)]
#[arg(
name = "13",
description = "Query for sound button 13",
kind = "String",
required = false
)]
#[arg(
name = "14",
description = "Query for sound button 14",
kind = "String",
required = false
)]
#[arg(
name = "15",
description = "Query for sound button 15",
kind = "String",
required = false
)]
#[arg(
name = "16",
description = "Query for sound button 16",
kind = "String",
required = false
)]
#[arg(
name = "17",
description = "Query for sound button 17",
kind = "String",
required = false
)]
#[arg(
name = "18",
description = "Query for sound button 18",
kind = "String",
required = false
)]
#[arg(
name = "19",
description = "Query for sound button 19",
kind = "String",
required = false
)]
#[arg(
name = "20",
description = "Query for sound button 20",
kind = "String",
required = false
)]
#[arg(
name = "21",
description = "Query for sound button 21",
kind = "String",
required = false
)]
#[arg(
name = "22",
description = "Query for sound button 22",
kind = "String",
required = false
)]
#[arg(
name = "23",
description = "Query for sound button 23",
kind = "String",
required = false
)]
#[arg(
name = "24",
description = "Query for sound button 24",
kind = "String",
required = false
)]
#[arg(
name = "25",
description = "Query for sound button 25",
kind = "String",
required = false
)]
async fn soundboard(
ctx: &Context,
invoke: &(dyn CommandInvoke + Sync + Send),
_args: Args,
args: Args,
) -> CommandResult {
if let Some(interaction) = invoke.interaction() {
let _ = interaction
.create_interaction_response(&ctx, |r| {
r.kind(InteractionResponseType::DeferredChannelMessageWithSource)
})
.await;
}
let pool = ctx
.data
.read()
@ -1151,13 +1310,28 @@ async fn soundboard(
.cloned()
.expect("Could not get SQLPool from data");
let sounds = Sound::get_guild_sounds(invoke.guild_id().unwrap(), pool).await?;
let mut sounds = vec![];
for n in 1..25 {
let search = Sound::search_for_sound(
args.named(&n.to_string()).unwrap_or(&"".to_string()),
invoke.guild_id().unwrap(),
invoke.author_id(),
pool.clone(),
true,
)
.await?;
if let Some(sound) = search.first() {
sounds.push(sound.clone());
}
}
invoke
.respond(
.followup(
ctx.http.clone(),
CreateGenericResponse::new()
.content("Select a sound from below:")
.content("**Play a sound:**")
.components(|c| {
for row in sounds.as_slice().chunks(5) {
let mut action_row: CreateActionRow = Default::default();

View File

@ -111,6 +111,7 @@ WHERE
}
}
#[derive(Clone)]
pub struct Sound {
pub name: String,
pub id: u32,