replaced allow_slash with a method to disallow text commands for soundboard. made string argument selector stricter

This commit is contained in:
2021-06-25 23:13:11 +01:00
parent 14ef6385a0
commit a38e4c808e
9 changed files with 164 additions and 47 deletions

View File

@ -7,6 +7,7 @@ use crate::{
THEME_COLOR,
};
use crate::framework::CommandKind;
use std::{collections::HashMap, sync::Arc};
#[command]
@ -62,6 +63,28 @@ pub async fn help(
)
};
let args = if command.args.is_empty() {
"**Arguments**
• *This command has no arguments*"
.to_string()
} else {
format!(
"**Arguments**
{}",
command
.args
.iter()
.map(|a| format!(
" • `{}` {} - {}",
a.name,
if a.required { "" } else { "[optional]" },
a.description
))
.collect::<Vec<String>>()
.join("\n")
)
};
invoke
.respond(
ctx.http.clone(),
@ -69,15 +92,28 @@ pub async fn help(
e.title(format!("{} Help", command_name))
.color(THEME_COLOR)
.description(format!(
"**Aliases**
"**Available In**
`Slash Commands` {}
` Text Commands` {}
**Aliases**
{}
**Overview**
{}
**Arguments**
{}
{}",
if command.kind != CommandKind::Text {
""
} else {
""
},
if command.kind != CommandKind::Slash {
""
} else {
""
},
command
.names
.iter()
@ -85,17 +121,7 @@ pub async fn help(
.collect::<Vec<String>>()
.join(" "),
command.desc,
command
.args
.iter()
.map(|a| format!(
" • `{}` {} - {}",
a.name,
if a.required { "" } else { "[optional]" },
a.description
))
.collect::<Vec<String>>()
.join("\n"),
args,
examples
))
}),

View File

@ -186,6 +186,7 @@ pub async fn upload_new_sound(
kind = "String",
required = true
)]
#[example("`/delete beep` - delete the sound with the name \"beep\"")]
pub async fn delete_sound(
ctx: &Context,
invoke: &(dyn CommandInvoke + Sync + Send),
@ -278,6 +279,8 @@ pub async fn delete_sound(
description = "Sound name or ID to change the privacy setting of",
required = true
)]
#[example("`/public 12` - change sound with ID 12 to private")]
#[example("`/public 12` - change sound with ID 12 back to public")]
pub async fn change_public(
ctx: &Context,
invoke: &(dyn CommandInvoke + Sync + Send),

View File

@ -184,14 +184,14 @@ __Available ambience sounds:__
}
#[command("soundboard")]
#[aliases("board")]
#[group("Play")]
#[kind(Slash)]
#[description("Get a menu of sounds with buttons to play them")]
#[arg(
name = "1",
description = "Query for sound button 1",
kind = "String",
required = false
required = true
)]
#[arg(
name = "2",

View File

@ -40,6 +40,8 @@ fn format_search_results(search_results: Vec<Sound>) -> CreateGenericResponse {
kind = "Boolean",
required = false
)]
#[example("`/list` - list sounds uploaded to the server you're in")]
#[example("`/list [me: True]` - list sounds you have uploaded across all servers")]
pub async fn list_sounds(
ctx: &Context,
invoke: &(dyn CommandInvoke + Sync + Send),

View File

@ -20,6 +20,9 @@ use crate::{
kind = "Integer",
required = false
)]
#[example("`/volume` - check the volume on the current server")]
#[example("`/volume 100` - reset the volume on the current server")]
#[example("`/volume 10` - set the volume on the current server to 10%")]
pub async fn change_volume(
ctx: &Context,
invoke: &(dyn CommandInvoke + Sync + Send),
@ -66,7 +69,7 @@ pub async fn change_volume(
#[command("prefix")]
#[required_permissions(Restricted)]
#[allow_slash(false)]
#[kind(Text)]
#[group("Settings")]
#[description("Change the prefix of the bot for using non-slash commands")]
#[arg(
@ -97,7 +100,7 @@ pub async fn change_prefix(
}
if let Some(prefix) = args.named("prefix") {
if prefix.len() <= 5 {
if prefix.len() <= 5 && !prefix.is_empty() {
let reply = format!("Prefix changed to `{}`", prefix);
{
@ -142,7 +145,7 @@ pub async fn change_prefix(
#[command("roles")]
#[required_permissions(Restricted)]
#[allow_slash(false)]
#[kind(Text)]
#[group("Settings")]
#[description("Change the roles allowed to use the bot")]
pub async fn set_allowed_roles(
@ -240,6 +243,8 @@ INSERT INTO roles (guild_id, role)
description = "Name or ID of sound to set as your greet sound",
required = false
)]
#[example("`/greet` - remove your join sound")]
#[example("`/greet 1523` - set your join sound to sound with ID 1523")]
pub async fn set_greet_sound(
ctx: &Context,
invoke: &(dyn CommandInvoke + Sync + Send),
@ -312,6 +317,8 @@ pub async fn set_greet_sound(
#[group("Settings")]
#[description("Configure whether users should be able to use join sounds")]
#[required_permissions(Restricted)]
#[example("`/allow_greet` - disable greet sounds in the server")]
#[example("`/allow_greet` - re-enable greet sounds in the server")]
pub async fn allow_greet_sounds(
ctx: &Context,
invoke: &(dyn CommandInvoke + Sync + Send),