Skip to content

Commit add1c55

Browse files
authored
Merge pull request CloudBotIRC#111 from linuxdaemon/gonzobot+admin-cleanup
Handful of cleanup for admin_channel.py
2 parents 2a3c92f + fd1622e commit add1c55

2 files changed

Lines changed: 74 additions & 35 deletions

File tree

plugins/admin_channel.py

Lines changed: 66 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,126 @@
11
from cloudbot import hook
22

33

4+
def check_for_chan_mode(char, conn):
5+
serv_info = conn.memory["server_info"]
6+
modes = serv_info.get("channel_modes", "")
7+
return bool(char in modes)
8+
9+
410
def mode_cmd(mode, text, text_inp, chan, conn, notice, nick, admin_log):
511
""" generic mode setting function """
12+
if not check_for_chan_mode(mode[1], conn):
13+
return False
14+
615
split = text_inp.split(" ")
716
if split[0].startswith("#"):
817
channel = split[0]
918
target = split[1]
10-
notice("Attempting to {} {} in {}...".format(text, target, channel))
11-
admin_log("{} used {} to set {} on {} in {}.".format(nick, text, mode, target, channel))
12-
conn.send("MODE {} {} {}".format(channel, mode, target))
1319
else:
1420
channel = chan
1521
target = split[0]
16-
notice("Attempting to {} {} in {}...".format(text, target, channel))
17-
admin_log("{} used {} to set {} on {} in {}.".format(nick, text, mode, target, channel))
18-
conn.send("MODE {} {} {}".format(channel, mode, target))
22+
23+
notice("Attempting to {} {} in {}...".format(text, target, channel))
24+
admin_log("{} used {} to set {} on {} in {}.".format(nick, text, mode, target, channel))
25+
conn.send("MODE {} {} {}".format(channel, mode, target))
26+
27+
return True
1928

2029

2130
def mode_cmd_no_target(mode, text, text_inp, chan, conn, notice, nick, admin_log):
2231
""" generic mode setting function without a target"""
32+
if not check_for_chan_mode(mode[1], conn):
33+
return False
34+
2335
split = text_inp.split(" ")
2436
if split[0].startswith("#"):
2537
channel = split[0]
26-
notice("Attempting to {} {}...".format(text, channel))
27-
admin_log("{} used {} to set {} in {}.".format(nick, text, mode, channel))
28-
conn.send("MODE {} {}".format(channel, mode))
2938
else:
3039
channel = chan
31-
notice("Attempting to {} {}...".format(text, channel))
32-
admin_log("{} used {} to set {} in {}.".format(nick, text, mode, channel))
33-
conn.send("MODE {} {}".format(channel, mode))
40+
41+
notice("Attempting to {} {}...".format(text, channel))
42+
admin_log("{} used {} to set {} in {}.".format(nick, text, mode, channel))
43+
conn.send("MODE {} {}".format(channel, mode))
44+
return True
45+
46+
47+
def do_extban(char, text, text_inp, chan, conn, notice, nick, admin_log, adding=True):
48+
serv_info = conn.memory["server_info"]
49+
if char not in serv_info.get("extbans", ""):
50+
return False
51+
52+
extban_pfx = serv_info["extban_prefix"]
53+
54+
split = text_inp.split(" ")
55+
if split[0].startswith("#"):
56+
channel = split[0]
57+
target = split[1]
58+
text_inp = "{} {}{}:{}".format(channel, extban_pfx, char, target)
59+
else:
60+
target = split[0]
61+
text_inp = "{}{}:{}".format(extban_pfx, char, target)
62+
63+
mode_cmd("+b" if adding else "-b", text, text_inp, chan, conn, notice, nick, admin_log)
64+
return True
3465

3566

36-
@hook.command(permissions=["op_ban", "op"])
67+
@hook.command(permissions=["op_ban", "op", "chanop"])
3768
def ban(text, conn, chan, notice, nick, admin_log):
3869
"""[channel] <user> - bans <user> in [channel], or in the caller's channel if no channel is specified"""
3970
mode_cmd("+b", "ban", text, chan, conn, notice, nick, admin_log)
4071

4172

42-
@hook.command(permissions=["op_ban", "op"])
73+
@hook.command(permissions=["op_ban", "op", "chanop"])
4374
def unban(text, conn, chan, notice, nick, admin_log):
4475
"""[channel] <user> - unbans <user> in [channel], or in the caller's channel if no channel is specified"""
4576
mode_cmd("-b", "unban", text, chan, conn, notice, nick, admin_log)
4677

4778

48-
@hook.command(permissions=["op_quiet", "op"])
79+
@hook.command(permissions=["op_quiet", "op", "chanop"])
4980
def quiet(text, conn, chan, notice, nick, admin_log):
5081
"""[channel] <user> - quiets <user> in [channel], or in the caller's channel if no channel is specified"""
51-
if conn.name == "snoonet":
52-
out = "mode {} +b m:{}".format(chan, text)
53-
conn.send(out)
82+
if mode_cmd("+q", "quiet", text, chan, conn, notice, nick, admin_log):
5483
return
55-
mode_cmd("+q", "quiet", text, chan, conn, notice, nick, admin_log)
5684

85+
if not do_extban('m', "quiet", text, chan, conn, notice, nick, admin_log, True):
86+
notice("Unable to set +q or a mute extban on this network.")
5787

58-
@hook.command(permissions=["op_quiet", "op"])
88+
89+
@hook.command(permissions=["op_quiet", "op", "chanop"])
5990
def unquiet(text, conn, chan, notice, nick, admin_log):
6091
"""[channel] <user> - unquiets <user> in [channel], or in the caller's channel if no channel is specified"""
61-
if conn.name == "snoonet":
62-
out = "mode {} -b m:{}".format(chan, text)
63-
conn.send(out)
92+
if mode_cmd("-q", "unquiet", text, chan, conn, notice, nick, admin_log):
6493
return
65-
mode_cmd("-q", "unquiet", text, chan, conn, notice, nick, admin_log)
94+
95+
if not do_extban('m', "unquiet", text, chan, conn, notice, nick, admin_log, False):
96+
notice("Unable to unset +q or a mute extban on this network.")
6697

6798

68-
@hook.command(permissions=["op_voice", "op"])
99+
@hook.command(permissions=["op_voice", "op", "chanop"])
69100
def voice(text, conn, chan, notice, nick, admin_log):
70101
"""[channel] <user> - voices <user> in [channel], or in the caller's channel if no channel is specified"""
71102
mode_cmd("+v", "voice", text, chan, conn, notice, nick, admin_log)
72103

73104

74-
@hook.command(permissions=["op_voice", "op"])
105+
@hook.command(permissions=["op_voice", "op", "chanop"])
75106
def devoice(text, conn, chan, notice, nick, admin_log):
76107
"""[channel] <user> - devoices <user> in [channel], or in the caller's channel if no channel is specified"""
77108
mode_cmd("-v", "devoice", text, chan, conn, notice, nick, admin_log)
78109

79110

80-
@hook.command(permissions=["op_op", "op"])
111+
@hook.command(permissions=["op_op", "op", "chanop"])
81112
def op(text, conn, chan, notice, nick, admin_log):
82113
"""[channel] <user> - ops <user> in [channel], or in the caller's channel if no channel is specified"""
83114
mode_cmd("+o", "op", text, chan, conn, notice, nick, admin_log)
84115

85116

86-
@hook.command(permissions=["op_op", "op"])
117+
@hook.command(permissions=["op_op", "op", "chanop"])
87118
def deop(text, conn, chan, notice, nick, admin_log):
88119
"""[channel] <user> - deops <user> in [channel], or in the caller's channel if no channel is specified"""
89120
mode_cmd("-o", "deop", text, chan, conn, notice, nick, admin_log)
90121

91122

92-
@hook.command(permissions=["op_topic", "op"])
123+
@hook.command(permissions=["op_topic", "op", "chanop"])
93124
def topic(text, conn, chan, nick, admin_log):
94125
"""[channel] <topic> - changes the topic to <topic> in [channel], or in the caller's channel
95126
if no channel is specified"""
@@ -104,7 +135,7 @@ def topic(text, conn, chan, nick, admin_log):
104135
conn.send("TOPIC {} :{}".format(chan, msg))
105136

106137

107-
@hook.command(permissions=["op_kick", "op"])
138+
@hook.command(permissions=["op_kick", "op", "chanop"])
108139
def kick(text, chan, conn, notice, nick, admin_log):
109140
"""[channel] <user> - kicks <user> from [channel], or from the caller's channel if no channel is specified"""
110141
split = text.split(" ")
@@ -131,7 +162,7 @@ def kick(text, chan, conn, notice, nick, admin_log):
131162
conn.send(out)
132163

133164

134-
@hook.command(permissions=["op_rem", "op"])
165+
@hook.command(permissions=["op_rem", "op", "chanop"])
135166
def remove(text, chan, conn, nick, admin_log):
136167
"""<user> - force removes <user> from the caller's channel."""
137168
split = text.split(" ")
@@ -145,25 +176,25 @@ def remove(text, chan, conn, nick, admin_log):
145176
conn.send(out)
146177

147178

148-
@hook.command(permissions=["op_mute", "op"], autohelp=False)
179+
@hook.command(permissions=["op_mute", "op", "chanop"], autohelp=False)
149180
def mute(text, conn, chan, notice, nick, admin_log):
150181
"""[channel] - mutes [channel], or in the caller's channel if no channel is specified"""
151182
mode_cmd_no_target("+m", "mute", text, chan, conn, notice, nick, admin_log)
152183

153184

154-
@hook.command(permissions=["op_mute", "op"], autohelp=False)
185+
@hook.command(permissions=["op_mute", "op", "chanop"], autohelp=False)
155186
def unmute(text, conn, chan, notice, nick, admin_log):
156187
"""[channel] - unmutes [channel], or in the caller's channel if no channel is specified"""
157188
mode_cmd_no_target("-m", "unmute", text, chan, conn, notice, nick, admin_log)
158189

159190

160-
@hook.command(permissions=["op_lock", "op"], autohelp=False)
191+
@hook.command(permissions=["op_lock", "op", "chanop"], autohelp=False)
161192
def lock(text, conn, chan, notice, nick, admin_log):
162193
"""[channel] - locks [channel], or in the caller's channel if no channel is specified"""
163194
mode_cmd_no_target("+i", "lock", text, chan, conn, notice, nick, admin_log)
164195

165196

166-
@hook.command(permissions=["op_lock", "op"], autohelp=False)
197+
@hook.command(permissions=["op_lock", "op", "chanop"], autohelp=False)
167198
def unlock(text, conn, chan, notice, nick, admin_log):
168199
"""[channel] - unlocks [channel], or in the caller's channel if no channel is specified"""
169200
mode_cmd_no_target("-i", "unlock", text, chan, conn, notice, nick, admin_log)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ def handle_chan_modes(value, serv_info):
5858
modelist[mode] = ChanMode(mode, types[i])
5959

6060

61+
def handle_extbans(value, serv_info):
62+
pfx, extbans = value.split(',', 1)
63+
serv_info["extbans"] = extbans
64+
serv_info["extban_prefix"] = pfx
65+
66+
6167
@hook.irc_raw('005', singlethread=True)
6268
def on_isupport(conn, irc_paramlist):
6369
serv_info = conn.memory["server_info"]
@@ -71,3 +77,5 @@ def on_isupport(conn, irc_paramlist):
7177
handle_prefixes(value, serv_info)
7278
elif name == "CHANMODES":
7379
handle_chan_modes(value, serv_info)
80+
elif name == "EXTBAN":
81+
handle_extbans(value, serv_info)

0 commit comments

Comments
 (0)