aboutsummaryrefslogtreecommitdiffstats
path: root/salvador/commands.py
blob: 833a9533a44b22551a9012eb9deee2e8c548d86e (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
"""
Sopel plugin: salvador admin commands

Owner-only commands for managing the bot at runtime.

  !join #channel         - join a channel
  !part [#channel]       - leave a channel (defaults to current)
  !chans                 - list channels the bot is in
  !help                  - show usage
"""

from sopel import plugin


def _is_owner(bot, trigger):
    return trigger.nick == bot.settings.core.owner


@plugin.command("join")
def cmd_join(bot, trigger):
    if not _is_owner(bot, trigger):
        return
    channel = (trigger.group(2) or "").strip()
    if not channel.startswith("#"):
        bot.say("usage: !join #channel")
        return
    bot.join(channel)


@plugin.command("part")
def cmd_part(bot, trigger):
    if not _is_owner(bot, trigger):
        return
    channel = (trigger.group(2) or "").strip()
    if not channel:
        channel = trigger.sender
    bot.part(channel)


@plugin.command("chans")
def cmd_chans(bot, trigger):
    if not _is_owner(bot, trigger):
        return
    chans = sorted(str(c) for c in bot.channels)
    if chans:
        bot.say("in: " + " ".join(chans))
    else:
        bot.say("not in any channels")


@plugin.command("help")
def cmd_help(bot, trigger):
    lines = [
        "!draw [<lines>] <url>  - render image as mIRC colour art (lines: 4-12, default 6)",
    ]
    if _is_owner(bot, trigger):
        lines += [
            "!join #channel         - join a channel (owner)",
            "!part [#channel]       - leave a channel (owner)",
            "!chans                 - list channels the bot is in (owner)",
        ]
    lines.append("!help                  - this message")
    for line in lines:
        bot.say(line, trigger.nick)