From 72d9bbe15220c21909dec8e30fb80729a24cec72 Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Tue, 6 Aug 2024 10:45:06 -0400 Subject: first pass convert to poise --- src/commands/mod.rs | 94 +++++++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 43 deletions(-) (limited to 'src/commands/mod.rs') 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> { + 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); - - 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, msg, url).await; - }) - }) + commands +} + +#[poise::command(slash_command, prefix_command, aliases("halp"))] +pub async fn help(ctx: PoiseContext<'_>, command: Option) -> 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(()); + } + + let _ = _play(ctx, &u).await?; + + Ok(()) } -- cgit v1.3.1