aboutsummaryrefslogtreecommitdiff
path: root/src/commands/mod.rs
blob: 6596a32c4e03598f087f4a8082caac8fe950ebac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use serenity::{
    framework::StandardFramework,
    model::id::ChannelId,
};

use crate::Result;

#[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;

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 _ = self::playback::_play(ctx, msg, &url);
        })
}

#[cfg(feature = "diesel")]
mod meme;

#[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)
        )
}

#[cfg(not(feature = "diesel"))]
fn register_db(f: StandardFramework) -> StandardFramework {
    f
}

pub(crate) fn send<A: AsRef<str>>(channel: ChannelId, text: A, tts: bool) -> Result<()> {
    channel.send_message(|m| m.content(text.as_ref()).tts(tts))?;
    Ok(())
}