summaryrefslogtreecommitdiff
path: root/escape.py
blob: 399717acbdf800fa7a56325b268b4e1143ca26bc (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
#!/usr/bin/python3


import miniirc, sys, ast

assert miniirc.ver >= (1, 4, 0), "This bot requires miniirc >= v1.4.0."

# Variables
nick = "escape-witch"
ident = nick
realname = "i break your terminal haha"
identity = None
# identity = '<username> <password>'
debug = False
channels = ["#librespeech", "#botwar"]
prefix = "`"

ip = "irc.libera.chat"
port = 6697

# Welcome!
print("Welcome to {}!".format(nick), file=sys.stderr)
irc = miniirc.IRC(
    ip,
    port,
    nick,
    channels,
    ident=ident,
    realname=realname,
    ns_identity=identity,
    debug=debug,
    auto_connect=False,
)

# Handle normal messages
# This could probably be better than a large if/else statement.
@irc.Handler("PRIVMSG", colon=False)
def handle_privmsg(irc, hostmask, args):
    channel = args[0]
    text = args[-1].split(" ")
    cmd = text[0].lower()
    if not channel.startswith("#"): return
    if cmd.startswith(prefix):
        # Prefixed commands
        cmd = cmd[len(prefix) :]
        if cmd == "eval":
            try:
                irc.msg(channel, str(ast.literal_eval(' '.join(text[1:]))))
            except ValueError:
                irc.send("KICK", channel, hostmask[0], "sussy baka")
            except SyntaxError:
                irc.send("KICK", channel, hostmask[0], "do I look like I enjoy invalid syntax")
            except Exception as e:
                irc.msg(channel, f"{hostmask[0]}: {type(e).__name__}: {str(e)}")


# Connect
if __name__ == "__main__":
    irc.connect()