11from 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+
410def 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
2130def 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 ))
3440
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
3545
36- @hook .command (permissions = ["op_ban" , "op" ])
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
65+
66+
67+ @hook .command (permissions = ["op_ban" , "op" , "chanop" ])
3768def 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" ])
4374def 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" ])
4980def 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 )
84+
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." )
5687
5788
58- @hook .command (permissions = ["op_quiet" , "op" ])
89+ @hook .command (permissions = ["op_quiet" , "op" , "chanop" ])
5990def 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 )
6694
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." )
6797
68- @hook .command (permissions = ["op_voice" , "op" ])
98+
99+ @hook .command (permissions = ["op_voice" , "op" , "chanop" ])
69100def 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" ])
75106def 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" ])
81112def 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" ])
87118def 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" ])
93124def 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" ])
108139def 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 (" " )
@@ -114,7 +145,7 @@ def kick(text, chan, conn, notice, nick, admin_log):
114145 target = split [1 ]
115146 if len (split ) > 2 :
116147 reason = " " .join (split [2 :])
117- out = "KICK {} {}: {}" .format (channel , target , reason )
148+ out = "KICK {} {} : {}" .format (channel , target , reason )
118149 else :
119150 out = "KICK {} {}" .format (channel , target )
120151 else :
@@ -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" ])
135166def 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 )
149180def 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 )
155186def 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 )
161192def 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 )
167198def 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 )
0 commit comments