Introduce Response class and a new way to send message to user

Remove old send_* in Message class
!more is now a built-in command
This commit is contained in:
Némunaire 2012-08-30 15:29:11 +02:00
parent c3c0b216d4
commit 5e52c4dbbb
4 changed files with 204 additions and 104 deletions

View file

@ -46,6 +46,8 @@ class Server(threading.Thread):
chan = channel.Channel(chn, self)
self.channels[chan.name] = chan
self.moremessages = dict()
threading.Thread.__init__(self)
def isDCC(self, to=None):
@ -72,13 +74,6 @@ class Server(threading.Thread):
else:
return None
@property
def partner(self):
if self.node.hasAttribute("partner"):
return self.node["partner"]
else:
return None
@property
def ip(self):
"""Convert common IP representation to little-endian integer representation"""
@ -112,6 +107,21 @@ class Server(threading.Thread):
def id(self):
return self.host + ":" + str(self.port)
def send_pong(self, cnt):
self.s.send(("PONG %s\r\n" % cnt).encode ())
def send_response(self, res):
if res.channel is not None:
self.send_msg(res.channel, res.get_message())
if not res.alone:
self.moremessages[res.channel] = res
elif res.nick is not None:
self.send_msg_usr(res.nick, res.get_message())
if not res.alone:
self.moremessages[res.nick] = res
def send_ctcp(self, to, msg, cmd = "NOTICE", endl = "\r\n"):
"""Send a message as CTCP response"""
if msg is not None and to is not None:
@ -143,10 +153,6 @@ class Server(threading.Thread):
else:
self.s.send (("%s %s :%s%s" % (cmd, channel, line[0:442]+"...", endl)).encode ())
def send_msg_prtn(self, msg):
"""Send a message to partner bot"""
self.send_msg_final(self.partner, msg)
def send_msg_usr(self, user, msg):
"""Send a message to a user instead of a channel"""
if user is not None and user[0] != "#":