-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel.py
66 lines (49 loc) · 1.43 KB
/
channel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from collections import deque
from util.nick import nickeq, nicklower
class User:
def __init__(self, nick, mode=None):
self.nick = nicklower(nick)
self.mode = set(mode) if mode else set()
self.messages = deque(maxlen=256)
def __repr__(self):
return "User('{0}')".format(self.nick)
class NickDict(dict):
def __setitem__(self, nick, value):
dict.__setitem__(self, nicklower(nick), value)
def __getitem__(self, nick):
return dict.__getitem__(self, nicklower(nick))
def __contains__(self, nick):
return dict.__contains__(self, nicklower(nick))
def pop(self, nick):
return dict.pop(self, nicklower(nick))
def __getattr__(self, attr):
if attr in self:
return self[attr]
else:
raise KeyError(attr)
def __setattr__(self, attr, val):
self[attr] = val
class Channel:
def __init__(self, name):
self.name = name
self.users = NickDict()
self.topic = None
self.mode = set()
def __repr__(self):
return "Channel('{1}')".format(self.name)
def __contains__(self, nick):
return nick in self.users
class ChannelList(dict):
def __setitem__(self, chan, val):
dict.__setitem__(self, chan.lower(), val)
def __getitem__(self, chan):
return dict.__getitem__(self, chan.lower())
def __contains__(self, chan):
return dict.__contains__(self, chan.lower())
def __getattr__(self, attr):
if attr in self:
return self[attr]
else:
raise KeyError(attr)
def __setattr__(self, attr, val):
self[attr] = val