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 ))
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
3445
3546
3647def do_extban (char , text , text_inp , chan , conn , notice , nick , admin_log , adding = True ):
@@ -68,9 +79,8 @@ def unban(text, conn, chan, notice, nick, admin_log):
6879@hook .command (permissions = ["op_quiet" , "op" ])
6980def quiet (text , conn , chan , notice , nick , admin_log ):
7081 """[channel] <user> - quiets <user> in [channel], or in the caller's channel if no channel is specified"""
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 )
82+ if mode_cmd ("+q" , "quiet" , text , chan , conn , notice , nick , admin_log ):
83+ return
7484
7585 if not do_extban ('m' , "quiet" , text , chan , conn , notice , nick , admin_log , True ):
7686 notice ("Unable to set +q or a mute extban on this network." )
@@ -79,9 +89,8 @@ def quiet(text, conn, chan, notice, nick, admin_log):
7989@hook .command (permissions = ["op_quiet" , "op" ])
8090def unquiet (text , conn , chan , notice , nick , admin_log ):
8191 """[channel] <user> - unquiets <user> in [channel], or in the caller's channel if no channel is specified"""
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 )
92+ if mode_cmd ("-q" , "unquiet" , text , chan , conn , notice , nick , admin_log ):
93+ return
8594
8695 if not do_extban ('m' , "unquiet" , text , chan , conn , notice , nick , admin_log , False ):
8796 notice ("Unable to unset +q or a mute extban on this network." )
0 commit comments