|
1
|
|
|
from util import strip_nick |
|
2
|
|
|
from event import Event |
|
3
|
|
|
try: |
|
4
|
|
|
from basemodule import BaseModule |
|
5
|
|
|
except ImportError: |
|
6
|
|
|
from modules.basemodule import BaseModule |
|
7
|
|
|
class Nicklist(BaseModule): |
|
8
|
|
|
def post_init(self): |
|
9
|
|
|
nicklisting_self_join = Event("__.nicklisting_self_join__") |
|
10
|
|
|
nicklisting_other_join = Event("__.nicklisting_other_join__") |
|
11
|
|
|
nicklisting_quit = Event("__.nicklisting_quit__") |
|
12
|
|
|
nicklisting_part = Event("__.nicklisting_part__") |
|
13
|
|
|
|
|
14
|
|
|
nicklisting_command = Event("__.nicklist__") |
|
15
|
|
|
nicklisting_command.define(msg_definition="^\.nicklist") |
|
16
|
|
|
|
|
17
|
|
|
nicklisting_self_join.define(message_id=353) |
|
18
|
|
|
nicklisting_other_join.define(definition="JOIN") |
|
19
|
|
|
nicklisting_quit.define(definition="QUIT") |
|
20
|
|
|
nicklisting_part.define(definition="PART") |
|
21
|
|
|
|
|
22
|
|
|
nicklisting_command.subscribe(self) |
|
23
|
|
|
nicklisting_self_join.subscribe(self) |
|
24
|
|
|
nicklisting_other_join.subscribe(self) |
|
25
|
|
|
nicklisting_quit.subscribe(self) |
|
26
|
|
|
nicklisting_part.subscribe(self) |
|
27
|
|
|
|
|
28
|
|
|
# register ourself to our new custom event(s) |
|
29
|
|
|
self.bot.register_event(nicklisting_self_join, self) |
|
30
|
|
|
self.bot.register_event(nicklisting_other_join, self) |
|
31
|
|
|
self.bot.register_event(nicklisting_quit, self) |
|
32
|
|
|
self.bot.register_event(nicklisting_command,self) |
|
33
|
|
|
self.bot.register_event(nicklisting_part,self) |
|
34
|
|
|
|
|
35
|
|
|
self.bot.mem_store['nicklist'] = dict() |
|
36
|
|
|
|
|
37
|
|
|
def handle(self, event): |
|
38
|
|
|
if event.message_id == 353: |
|
39
|
|
|
self.bot.mem_store['nicklist'][event.channel] = event.line.split(":")[2].split() |
|
40
|
|
|
|
|
41
|
|
|
if event.msg.startswith(".nicklist"): |
|
42
|
|
|
print self.bot.mem_store['nicklist'][event.channel] |
|
43
|
|
|
|
|
44
|
|
|
if event._type == "__.nicklisting_other_join__": |
|
45
|
|
|
try: |
|
46
|
|
|
self.bot.mem_store['nicklist'][event.channel].append(strip_nick(event.user)) |
|
47
|
|
|
except KeyError: |
|
48
|
|
|
self.bot.mem_store['nicklist'][event.channel] = list() |
|
49
|
|
|
|
|
50
|
|
|
if event._type == "__.nicklisting_part__": |
|
51
|
|
|
try: |
|
52
|
|
|
self.bot.mem_store['nicklist'][event.channel].remove(strip_nick(event.user)) |
|
53
|
|
|
except ValueError: |
|
54
|
|
|
pass |
|
55
|
|
|
|
|
56
|
|
|
if event._type == "__.nicklisting_quit__": |
|
57
|
|
|
try: |
|
58
|
|
|
for name, chan in self.bot.mem_store['nicklist'].iteritems(): |
|
59
|
|
|
chan.remove(strip_nick(event.user)) |
|
60
|
|
|
except ValueError: |
|
61
|
|
|
pass |
|
62
|
|
|
|