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
|
#!/usr/bin/python3
import miniirc
import sys
from miniirc import *
assert miniirc.ver >= (1, 4, 0), "This bot requires miniirc >= v1.4.0."
nick = "Guard"
ident = nick
realname = "Simple Channel Services Bot: https://git.andrewyu.org/ircbots"
identity = "LibreBot redacted"
debug = True
channels = {
"##gnuhackers": {
"flags": {
("Andrew", "user/AndrewYu"): [
"ban",
"kick",
"op",
"autoop",
"invite",
"masskick",
"voice",
"set",
"spam",
]
}
},
"#librespeech": {
"flags": {
("~leah", "libreboot/developer/leah"): [
"ban",
"kick",
"op",
"autoop",
"invite",
"masskick",
"voice",
"set",
"spam",
],
("Andrew", "user/AndrewYu"): [
"ban",
"kick",
"op",
"autoop",
"invite",
"masskick",
"voice",
"set",
"spam",
],
}
},
}
cnames = channels.keys()
def flags(channel, hostmask):
return channels[channel]["flags"][(hostmask[1], hostmask[2])]
prefix = "/"
ip = "irc.libera.chat"
port = 6697
# Welcome!
print("Welcome to {}!".format(nick), file=sys.stderr)
irc = IRC(
ip,
port,
nick,
cnames,
ident=ident,
realname=realname,
ns_identity=identity,
debug=debug,
auto_connect=False,
)
@irc.Handler("JOIN", colon=False)
def handle_join(irc, hostmask, args):
channel = args[0]
@irc.Handler("PRIVMSG", colon=False)
def handle_privmsg(irc, hostmask, args):
channel = args[0]
text = args[-1].split(" ")
cmd = text[0].lower()
cmdargs = text[1:]
if cmd.startswith(prefix):
cmd = cmd[len(prefix) :]
if len(flags(channel, hostmask)) < 1:
irc.msg(
channel,
f"{hostmask[0]}: You are not authorized to use {irc.nick}.",
)
if cmd == "help":
irc.msg(
channel,
"I am {}, a simple channel services implementation. This is not a replacement for ChanServ yet.".format(
irc.nick
),
)
elif cmd == "ban":
if "!" in cmdargs[0] and "@" in cmdargs[0]:
irc.send("MODE", channel, "+b", cmdargs[0])
irc.send("KICK", channel, hostmask[0], cmdargs[2:])
else:
irc.msg(channel, f"{hostmask[0]}: Invalid command.")
if __name__ == "__main__":
irc.connect()
|