$onr, $xkcd
[halbot.git] / whois.py
blob9f9fb6e4a5c55a79904a9aedb3bfa70dedec2690
1 from __future__ import generators
2 from sets import Set
4 import perms
5 from common import multiunion, ircdict_to_set
6 from safety import safe
8 def voice_or_better(channel):
9 from connection import hal
10 if channel in hal.channels:
11 chan = hal.channels[channel]
12 dicts = (chan.voiceddict, chan.hopdict, chan.operdict, chan.admindict,
13 chan.ownerdict)
14 return multiunion(*[ircdict_to_set(d) for d in dicts])
15 else:
16 return Set()
18 def callback(who, info):
19 raise ValueError, "Whois callback never got replaced."
21 class Whois(object):
22 registered = False
23 ircop = False
24 channel_perms = None
25 def __init__(self):
26 self.channel_perms = {}
28 whois_info = {}
30 #@safe
31 def got_whois(conn, event):
32 user = event.arguments()[0]
33 whois_info[user] = Whois()
34 got_whois = safe(got_whois)
36 #@safe
37 def got_registered(conn, event):
38 args = event.arguments()
39 if len(args) == 2 and args[1] == "is a registered nick":
40 user = args[0]
41 whois_info[user].registered = True
42 got_registered = safe(got_registered)
44 #@safe
45 def got_channels(conn, event):
46 args = event.arguments()
47 if len(args) == 2:
48 user = args[0]
49 channels = args[1].split()
50 for c in channels:
51 if c[0] != "#":
52 whois_info[user].channel_perms[c[1:]] = perms.Perms.from_symbol(c[0])
53 else:
54 whois_info[user].channel_perms[c] = perms.present
55 got_channels = safe(got_channels)
57 #@safe
58 def got_servop(conn, event):
59 args = event.arguments()
60 if len(args) == 2:
61 user = args[0]
62 whois_info[user].ircop = True
63 got_servop = safe(got_servop)
65 #@safe
66 def got_whoend(conn, event):
67 who = event.arguments()[0]
68 callback(who, whois_info[who])
69 if False:
70 user = whois_info[who]
71 print "Who info for %s:" % who
72 print "Registered: %s" % user.registered
73 print "IRCop: %s" % user.ircop
74 p = user.channel_perms
75 perms = "".join([("%s: %s, " % (k, p[k])) for k in p])[:-2]
76 print "Channel info: %s" % perms
77 got_whoend = safe(got_whoend)