diff options
| author | Nathan Perry <np@nathanperry.dev> | 2019-11-17 21:31:28 -0500 |
|---|---|---|
| committer | Nathan Perry <np@nathanperry.dev> | 2019-11-17 21:31:28 -0500 |
| commit | 2a38c282dd57c2051a568549d62c80d6036e8920 (patch) | |
| tree | ec25f84dda5cdb100ae093b0a690ef349636b4dc /src/commands/mod.rs | |
| parent | 479bb8d584b138054acc6567b72cb3076832e79c (diff) | |
most restructuring done
Diffstat (limited to 'src/commands/mod.rs')
| -rw-r--r-- | src/commands/mod.rs | 230 |
1 files changed, 87 insertions, 143 deletions
diff --git a/src/commands/mod.rs b/src/commands/mod.rs index f4ff9cb..619335c 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,163 +1,107 @@ use serenity::{ framework::StandardFramework, - model::id::{ChannelId, MessageId}, }; -use crate::Result; +use crate::{ + util::CtxExt, +}; +#[cfg(feature = "games")] +use crate::game::*; +pub use self::{ + playback::*, + sound_levels::*, +}; #[cfg(feature = "diesel")] pub use self::meme::*; -pub use self::playback::*; -pub use self::sound_levels::*; pub(crate) mod playback; pub(crate) mod sound_levels; pub(crate) mod roll; +group!("playback", { + options: { + only_in: "guild", + }, + commands: [ + skip, + pause, + resume, + list, + die, + mute, + unmute, + play, + volume, + ], +}); + +group!("general", { + options: { + only_in: "guild", + }, + commands: [ + roll, + ], +}); + pub fn register_commands(f: StandardFramework) -> StandardFramework { - let f: StandardFramework = register_db(f); - f - .command("skip", |c| c - .desc("skip the rest of the current request") - .guild_only(true) - .exec(skip)) - .command("pause", |c| c - .desc("pause playback (currently broken)") - .guild_only(true) - .exec(pause)) - .command("resume", |c| c - .desc("resume playing (currently broken)") - .guild_only(true) - .exec(resume)) - .command("list", |c| c - .known_as("queue") - .desc("list playing and queued requests") - .guild_only(true) - .exec(list)) - .command("die", |c| c - .batch_known_as(vec!["sudoku", "stop"]) - .desc("stop playing and empty the queue") - .guild_only(true) - .exec(die)) - .command("mute", |c| c - .desc("mute thulani (playback continues)") - .guild_only(true) - .exec(mute)) - .command("unmute", |c| c - .desc("unmute thulani") - .guild_only(true) - .exec(unmute)) - .command("play", |c| c - .desc("queue a request") - .guild_only(true) - .exec(play)) - .command("volume", |c| c - .desc("set playback volume") - .guild_only(true) - .exec(volume)) - .command("roll", |c| c - .known_as("calc") - .desc("simulate rolling dice") - .guild_only(true) - .exec(roll::roll)) - .unrecognised_command(|ctx, msg, unrec| { - let url = match msg.content.split_whitespace().skip(1).next() { - Some(x) if x.starts_with("http") => x, - _ => { - info!("bad command formatting: '{}'", unrec); - let _ = send(msg.channel_id, "format your commands right. fuck you.", msg.tts); - return; - } - }; + let result = f + .group(&PLAYBACK_GROUP) + .group(&GENERAL_GROUP); - let _ = self::playback::_play(ctx, msg, &url); - }) -} + #[cfg(feature = "diesel")] + let result = result.group(&MEMES_GROUP); -#[cfg(feature = "diesel")] -mod meme; + #[cfg(feature = "games")] + let result = result.group(&GAME_GROUP); -#[cfg(feature = "diesel")] -fn register_db(f: StandardFramework) -> StandardFramework { - f - .command("meme", |c| c - .guild_only(true) - .help_available(false) - .cmd(meme)) - .command("audiomeme", |c| c - .guild_only(true) - .help_available(false) - .cmd(audio_meme) - ) - .command("silentmeme", |c| c - .guild_only(true) - .help_available(false) - .cmd(silent_meme) - ) - .command("addmeme", |c| c - .guild_only(true) - .desc("first argument is title, everything after is text. one attached image is included if present.") - .cmd(addmeme) - ) - .command("addaudiomeme", |c| c - .guild_only(true) - .desc("title, audio link, text, with optional image") - .cmd(addaudiomeme) - ) - .command("delmeme", |c| c - .guild_only(true) - .desc("delete a meme by name (exact match only)") - .cmd(delmeme) - ) - .command("wat", |c| c - .known_as("what") - .known_as("last") - .known_as("lastmeme") - .guild_only(true) - .desc("check info for last meme") - .cmd(wat) - ) - .command("stats", |c| c - .guild_only(true) - .desc("get meme stats") - .cmd(stats) - ) - .command("history", |c| c - .known_as("hist") - .guild_only(true) - .desc("history of recent messages") - .cmd(history) - ) - .command("rarememe", |c| c - .known_as("rare_meme") - .guild_only(true) - .desc("deliver an underutilized meme") - .cmd(rare_meme) - ) - .command("memers", |c| c - .guild_only(true) - .desc("list stats for all server memers") - .cmd(memers) - ) - .command("query", |c| c - .guild_only(true) - .desc("find a lot of matching memes") - .cmd(query) - ) -} + result.unrecognised_command(|ctx, msg, unrec| { + let url = match msg.content.split_whitespace().skip(1).next() { + Some(x) if x.starts_with("http") => x, + _ => { + info!("bad command formatting: '{}'", unrec); + let _ = ctx.send(msg.channel_id, "format your commands right. fuck you.", msg.tts); + return; + } + }; -#[cfg(not(feature = "diesel"))] -fn register_db(f: StandardFramework) -> StandardFramework { - f + let _ = self::playback::_play(ctx, msg, &url); + }) } -#[inline] -pub(crate) fn send<A: AsRef<str>>(channel: ChannelId, text: A, tts: bool) -> Result<()> { - send_result(channel, text, tts).map(|_| ()) -} +#[cfg(feature = "games")] +group!("game", { + options: { + only_in: "guild", + }, + commands: [ + installedgame, + ownedgame, + updategaem, + ], +}); -#[inline] -pub(crate) fn send_result<A: AsRef<str>>(channel: ChannelId, text: A, tts: bool) -> Result<MessageId> { - let result = channel.send_message(|m| m.content(text.as_ref()).tts(tts))?; - Ok(result.id) -} +#[cfg(feature = "diesel")] +mod meme; + +#[cfg(feature = "diesel")] +group!("memes", { + options: { + only_in: "guild", + }, + commands: [ + meme, + audio_meme, + silent_Meme, + addmeme, + addaudiomeme, + delmeme, + wat, + stats, + history, + rare_meme, + memers, + query, + ], +}); |
