Fix to autovoice on $[un]panic.
[halbot.git] / panic.py
blob4d16b64f5402852fc01df66a593ccf6296679d97
1 from connection import hal
2 from globals import commands, private, nick
3 from basic_commands import reply
4 import perms
6 def panic(who, where, args):
7 "$panic: Engages panic mode in the channel. Hal will set mode +mi, clear all voices, and disable autovoice. The inverse is $unpanic."
8 if where == private:
9 reply(who, where, "Command not available in private, send it in a channel.")
10 return
11 hal.connection.mode(where, "+mi")
12 hal.connection.privmsg("ChanServ", "ACCESS %s ADD %s 100" % (where, nick))
13 hal.connection.privmsg("ChanServ", "CLEAR %s VOICES" % where)
14 hal.connection.privmsg("ChanServ", "ACCESS %s ADD %s 50" % (where, nick))
15 hal.connection.privmsg("ChanServ", "LEVELS %s SET AUTOVOICE 30" % where)
16 commands['panic'] = (perms.op, panic)
18 def unpanic(who, where, args):
19 "$unpanic: Disables $panic mode in the channel. Hall will set mode -i, voice everyone, and re-engage autovoice. Note that he leaves +m, since everyone is autovoiced anyway."
20 if where == private:
21 reply(who, where, "Command not available in private, send it in a channel.")
22 return
23 hal.connection.mode(where, "-i")
24 hal.connection.privmsg("ChanServ", "LEVELS %s SET AUTOVOICE 0" % where)
25 if where in hal.channels:
26 buffer = []
27 buffer_size = 6
28 for user in hal.channels[where].userdict:
29 if len(buffer) < buffer_size:
30 buffer.append(user)
31 else:
32 hal.connection.mode(where, "+%s %s" % (("v" * buffer_size),
33 " ".join(buffer)))
34 buffer = [user]
35 if buffer:
36 hal.connection.mode(where, "+%s %s" % (("v" * len(buffer)),
37 " ".join(buffer)))
38 commands['unpanic'] = (perms.op, unpanic)