-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.py
75 lines (62 loc) · 1.71 KB
/
user.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
66
67
68
69
70
71
72
73
74
75
from irc.util import NickError
from thunderwave import Singleton as ThunderWave
class User(object):
def __init__(self, nick, username, hostname, server):
self.nick = nick
self.username = username
self.hostname = hostname
self.password = ""
self.is_away = False
self.away_reason = None
self.channels = []
self.transactions = []
def set_away(self, is_away, reason=None):
self.is_away = is_away
self.away_reason = reason
def change_nick(self, new_nick):
for chan in self.channels:
try:
chan.broadcast(self, "NICK %s" % new_nick)
except Exception as e:
continue
self.nick = new_nick
def auth(self, password):
self.password = password
return True
def join(self, chan):
self.channels.append(chan)
def part(self, chan):
self.channels.remove(chan)
def connect(self, transaction):
self.transactions.append(transaction)
def disconnect(self, transaction):
self.transactions.remove(transaction)
def is_admin(self):
return False
def is_moderator(self):
return False
# Modes
def set_invisible(self, value):
raise NotImplementedError()
def set_receipt_server_notices(self, value):
raise NotImplementedError()
def set_wallops(self, value):
raise NotImplementedError()
def set_moderator(self, value):
raise NotImplementedError()
# Messages
def send(self, user, message):
pass
def receivePrivMsg(self, user, message, chan=None):
to = None
if chan is None:
to = self.nick
else:
to = chan.name
self.broadcast(user, "PRIVMSG %s :%s" % (to, message))
def broadcast(self, user, data):
for transaction in self.transactions:
transaction.sendall(":%s!%s@%s %s" % (user.nick, user.username, user.hostname, data))
@staticmethod
def check_nick(nick):
return True