diff options
Diffstat (limited to 'src/commands/mod.rs')
| -rw-r--r-- | src/commands/mod.rs | 90 |
1 files changed, 49 insertions, 41 deletions
diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 69c9185..ba87adb 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,18 +1,14 @@ -use crate::util; -use log::info; -use serenity::framework::{ - standard::macros::group, - StandardFramework, -}; +use poise::builtins::PrettyHelpConfiguration; -#[cfg(feature = "db")] -pub use self::meme::*; -pub use self::{ - playback::*, - roll::ROLL_COMMAND, - today::TODAY_COMMAND, +use crate::{ + commands::playback::_play, + util, + PoiseContext, }; +#[cfg(feature = "games")] +pub mod game; + #[cfg(feature = "db")] pub(crate) mod meme; pub(crate) mod playback; @@ -20,40 +16,52 @@ pub(crate) mod roll; pub(crate) mod sound_levels; pub(crate) mod today; -mod help; +#[cfg(feature = "db")] +pub use self::meme::*; -#[group] -#[only_in(guild)] -#[commands(roll, today)] -struct General; +pub fn commands() -> Vec<poise::Command<crate::PoiseData, anyhow::Error>> { + let mut commands = vec![ + playback::play(), + playback::pause(), + playback::resume(), + playback::die(), + playback::list(), + sound_levels::mute(), + sound_levels::unmute(), + roll::roll(), + help(), + ]; -pub fn register_commands(f: StandardFramework) -> StandardFramework { - let result = f.group(&PLAYBACK_GROUP).group(&GENERAL_GROUP); + #[cfg(feature = "games")] + commands.extend(game::commands()); #[cfg(feature = "db")] - let result = result.group(&MEMES_GROUP); + commands.extend(meme::commands()); - #[cfg(feature = "games")] - let result = result.group(&crate::game::GAME_GROUP); + commands +} + +#[poise::command(slash_command, prefix_command, aliases("halp"))] +pub async fn help(ctx: PoiseContext<'_>, command: Option<String>) -> anyhow::Result<()> { + poise::builtins::pretty_help( + ctx, + command.as_ref().map(|x| x.as_str()), + PrettyHelpConfiguration { + ..Default::default() + }, + ) + .await?; + + Ok(()) +} + +pub async fn unrecognized(ctx: PoiseContext<'_>, u: url::Url) -> anyhow::Result<()> { + if !u.scheme().starts_with("http") { + util::reply(ctx, "format your commands right. fuck you.").await?; + return Ok(()); + } - result.help(&help::HELP).unrecognised_command(|ctx, msg, unrec| { - Box::pin(async move { - let url = match msg.content.split_whitespace().nth(1) { - Some(x) if x.starts_with("http") => x, - _ => { - info!("bad command formatting: '{}'", unrec); - let _ = util::send( - ctx, - msg.channel_id, - "format your commands right. fuck you.", - msg.tts, - ) - .await; - return; - }, - }; + let _ = _play(ctx, &u).await?; - let _ = _play(ctx, msg, url).await; - }) - }) + Ok(()) } |
