Skip to content

Commit e4b866a

Browse files
committed
Add support for extbans in admin_channel.py
1 parent 9455941 commit e4b866a

2 files changed

Lines changed: 40 additions & 10 deletions

File tree

plugins/admin_channel.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ def mode_cmd_no_target(mode, text, text_inp, chan, conn, notice, nick, admin_log
3333
conn.send("MODE {} {}".format(channel, mode))
3434

3535

36+
def do_extban(char, text, text_inp, chan, conn, notice, nick, admin_log, adding=True):
37+
serv_info = conn.memory["server_info"]
38+
if char not in serv_info.get("extbans", ""):
39+
return False
40+
41+
extban_pfx = serv_info["extban_prefix"]
42+
43+
split = text_inp.split(" ")
44+
if split[0].startswith("#"):
45+
channel = split[0]
46+
target = split[1]
47+
text_inp = "{} {}{}:{}".format(channel, extban_pfx, char, target)
48+
else:
49+
target = split[0]
50+
text_inp = "{}{}:{}".format(extban_pfx, char, target)
51+
52+
mode_cmd("+b" if adding else "-b", text, text_inp, chan, conn, notice, nick, admin_log)
53+
return True
54+
55+
3656
@hook.command(permissions=["op_ban", "op"])
3757
def ban(text, conn, chan, notice, nick, admin_log):
3858
"""[channel] <user> - bans <user> in [channel], or in the caller's channel if no channel is specified"""
@@ -48,21 +68,23 @@ def unban(text, conn, chan, notice, nick, admin_log):
4868
@hook.command(permissions=["op_quiet", "op"])
4969
def quiet(text, conn, chan, notice, nick, admin_log):
5070
"""[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)
54-
return
55-
mode_cmd("+q", "quiet", text, chan, conn, notice, nick, admin_log)
71+
serv_info = conn.memory["server_info"]
72+
if 'q' in serv_info.get("channel_modes", ""):
73+
return mode_cmd("+q", "quiet", text, chan, conn, notice, nick, admin_log)
74+
75+
if not do_extban('m', "quiet", text, chan, conn, notice, nick, admin_log, True):
76+
notice("Unable to set +q or a mute extban on this network.")
5677

5778

5879
@hook.command(permissions=["op_quiet", "op"])
5980
def unquiet(text, conn, chan, notice, nick, admin_log):
6081
"""[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)
64-
return
65-
mode_cmd("-q", "unquiet", text, chan, conn, notice, nick, admin_log)
82+
serv_info = conn.memory["server_info"]
83+
if 'q' in serv_info.get("channel_modes", ""):
84+
return mode_cmd("-q", "unquiet", text, chan, conn, notice, nick, admin_log)
85+
86+
if not do_extban('m', "unquiet", text, chan, conn, notice, nick, admin_log, False):
87+
notice("Unable to unset +q or a mute extban on this network.")
6688

6789

6890
@hook.command(permissions=["op_voice", "op"])

plugins/server_info.py

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)