(wip) reworking of the Message class; backported from v4

This commit is contained in:
nemunaire 2014-08-29 16:33:45 +02:00
commit 0a16321259
15 changed files with 185 additions and 178 deletions

View file

@ -120,21 +120,16 @@ class IRCServer(server.Server):
self.channels[chan].treat(msg.cmd, msg)
def evt_channel(self, msg, srv):
if msg.channel is not None:
if msg.channel in self.channels:
self.channels[msg.channel].treat(msg.cmd, msg)
if msg.receivers is not None:
for receiver in msg.receivers:
if receiver in self.channels:
self.channels[receiver].treat(msg.cmd, msg)
def accepted_channel(self, chan, sender=None):
"""Return True if the channel (or the user) is authorized"""
if self.allow_all:
return True
elif self.listen_nick:
return (chan in self.channels and (sender is None or sender in
self.channels[chan].people)
) or chan == self.nick
else:
return chan in self.channels and (sender is None or sender
in self.channels[chan].people)
return (self.allow_all or
(chan in self.channels and (sender is None or sender in self.channels[chan].people)) or
(self.listen_nick and chan == self.nick))
def join(self, chan, password=None, force=False):
"""Join a channel"""
@ -255,7 +250,7 @@ class IRCServer(server.Server):
"""Send a message without checks or format"""
#TODO: add something for post message treatment here
if channel == self.nick:
self.logger.warn("Nemubot talks to himself: %s", msg, stack_info=True)
self.logger.warn("Nemubot talks to himself: %s", line, stack_info=True)
if line is not None and channel is not None:
if self.s is None:
self.logger.warn("Attempt to send message on a non connected server: %s: %s", self.id, line, stack_info=True)

View file

@ -73,22 +73,20 @@ class Server(threading.Thread):
def send_response(self, res, origin):
"""Analyse a Response and send it"""
# TODO: how to send a CTCP message to a different person
if res.ctcp:
self.send_ctcp(res.sender, res.get_message())
if type(res.channel) != list:
res.channel = [ res.channel ]
elif res.channel is not None and res.channel != self.nick:
self.send_msg(res.channel, res.get_message())
for channel in res.channel:
if channel != self.nick:
self.send_msg(channel, res.get_message())
else:
channel = res.sender
self.send_msg_usr(channel, res.get_message(), "NOTICE" if res.is_ctcp else "PRIVMSG")
if not res.alone:
if hasattr(self, "send_bot"):
self.send_bot("NOMORE %s" % res.channel)
self.moremessages[res.channel] = res
elif res.sender is not None:
self.send_msg_usr(res.sender, res.get_message())
if not res.alone:
self.moremessages[res.sender] = res
self.moremessages[channel] = res
def send_ctcp(self, to, msg, cmd="NOTICE", endl="\r\n"):
"""Send a message as CTCP response"""