*quietly adds a file that should have been in the tree since 9839a*
[halbot.git] / panic.py
blob7e1c43a8d28f25e7fb51fbcf96e74839ba262bde
1 import irclib
2 from common import resize
3 from connection import hal, irc
4 import globals
5 from globals import commands, private, nick
6 from basic_commands import reply
7 import perms
8 import whois
10 def panic(who, where, args):
11 "$panic: Engages panic mode in the channel. Hal will set mode +mi, clear all voices, and disable autovoice. The inverse is $unpanic."
12 if where == private:
13 reply(who, where, "Command not available in private, send it in a channel.")
14 return
15 hal.connection.mode(where, "+mi")
16 hal.connection.privmsg("ChanServ", "ACCESS %s ADD %s 100" % (where, nick))
17 hal.connection.privmsg("ChanServ", "CLEAR %s VOICES" % where)
18 hal.connection.privmsg("ChanServ", "ACCESS %s ADD %s 50" % (where, nick))
19 hal.connection.privmsg("ChanServ", "LEVELS %s SET AUTOVOICE 30" % where)
20 commands['panic'] = (perms.op, panic)
22 def unpanic(who, where, args):
23 "$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."
24 if where == private:
25 reply(who, where, "Command not available in private, send it in a channel.")
26 return
27 hal.connection.mode(where, "-i")
28 hal.connection.privmsg("ChanServ", "LEVELS %s SET AUTOVOICE 0" % where)
29 if where in hal.channels:
30 buffer = []
31 buffer_size = 6
32 for user in hal.channels[where].userdict:
33 if len(buffer) < buffer_size:
34 buffer.append(user)
35 else:
36 hal.connection.mode(where, "+%s %s" % (("v" * buffer_size),
37 " ".join(buffer)))
38 buffer = [user]
39 if buffer:
40 hal.connection.mode(where, "+%s %s" % (("v" * len(buffer)),
41 " ".join(buffer)))
42 commands['unpanic'] = (perms.op, unpanic)
44 def kickban(who, where, args):
45 """$kickban <user> <reason>: Kicks and bans a user from the channel. The ban is for *!*@<user's host>."""
46 if where == private:
47 reply(who, where, "Channel-only command.")
48 return
49 user, reason = resize(args.split(" ", 1), 2)
50 whois.userhost_callbacks[user] = (do_kickban, (who, where, reason))
51 hal.connection.userhost([user])
52 commands['kickban'] = (perms.op, kickban)
54 def do_kickban(nm, who, where, reason):
55 hal.connection.mode(where, "+b *!*@%s" % irclib.nm_to_h(nm))
56 hal.connection.kick(where, irclib.nm_to_n(nm), "%s (%s)" % (reason, who))
58 def kill_channel(who, where, args):
59 """$kill-channel <reason>: When sent, and whenever anyone joins the channel after, Hal will run /msg OperServ AKILLCHAN KILL +0 <channel> <reason>, causing all non-oper users on the channel to be kicked off the server and permabanned."""
60 reason = args
61 if where == private:
62 reply(who, where, "Channel-only command.")
63 elif not reason:
64 reply(who, where, "Usage: $kill-channel <reason>")
65 else:
66 globals.kill_channels[where] = reason
67 do_kill_channel(where)
68 reply(who, where, "Done.")
69 commands['kill-channel'] = (perms.ircop, kill_channel)
71 def unkill_channel(who, where, args):
72 if where == private:
73 reply(who, where, "Channel-only command.")
74 else:
75 if where in globals.kill_channels:
76 del globals.kill_channels[where]
77 reply(who, where, "Done.")
78 else:
79 reply(who, where, "Channel was not set to autokill.")
80 commands['unkill-channel'] = (perms.ircop, unkill_channel)
82 def do_kill_channel(channel):
83 reason = globals.kill_channels[channel]
84 hal.connection.privmsg("OperServ", "AKILLCHAN KILL +0 %s %s" % (channel, reason))
86 def got_join(conn, event):
87 channel = event.target()
88 if channel in globals.kill_channels:
89 do_kill_channel(channel)
90 irc.add_global_handler("join", got_join)