From 05cf74015176d2428c7e17e9ec0a74590ddd64a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9munaire?= Date: Fri, 20 Jul 2012 03:24:51 +0200 Subject: [PATCH] New method send_msg_verified that checks the user is on the message destination channel --- message.py | 2 +- server.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/message.py b/message.py index 3940fbd..19b7094 100644 --- a/message.py +++ b/message.py @@ -86,7 +86,7 @@ class Message: def send_msg (self, channel, msg, cmd = "PRIVMSG", endl = "\r\n"): if CREDITS[self.realname].speak(): - self.srv.send_msg (channel, msg, cmd, endl) + self.srv.send_msg_verified (self.sender, channel, msg, cmd, endl) def send_global (self, msg, cmd = "PRIVMSG", endl = "\r\n"): if CREDITS[self.realname].speak(): diff --git a/server.py b/server.py index 468edd0..808cd73 100644 --- a/server.py +++ b/server.py @@ -98,16 +98,20 @@ class Server(threading.Thread): if self.accepted_channel(channel): self.send_msg_final(channel, msg, cmd, endl) + def send_msg_verified (self, sender, channel, msg, cmd = "PRIVMSG", endl = "\r\n"): + if self.accepted_channel(channel, sender): + self.send_msg_final(channel, msg, cmd, endl) + def send_global (self, msg, cmd = "PRIVMSG", endl = "\r\n"): for channel in self.channels.keys(): self.send_msg (channel, msg, cmd, endl) - def accepted_channel(self, chan): + def accepted_channel(self, chan, sender = None): if self.listen_nick: - return chan in self.channels or chan == self.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 + return chan in self.channels and (sender is None or sender in self.channels[chan].people) def disconnect(self): if self.connected: