diff --git a/src/irclib.py b/src/irclib.py index 744e0a5b5..bef88fb7a 100644 --- a/src/irclib.py +++ b/src/irclib.py @@ -881,10 +881,19 @@ class Irc(IrcCommandDispatcher, log.Firewalled): msg.tag('receivedBy', self) msg.tag('receivedOn', self.network) msg.tag('receivedAt', time.time()) - if msg.args and self.isChannel(msg.args[0]): + + # Check if the message is addressed to a channel + if msg.args: channel = msg.args[0] + if not conf.supybot.protocols.irc.strictRfc(): + statusmsg_chars = self.state.supported.get('statusmsg', '') + channel = channel.lstrip(statusmsg_chars) + if not self.isChannel(channel): + channel = None else: channel = None + msg.channel = channel + preInFilter = str(msg).rstrip('\r\n') log.debug('Incoming message (%s): %s', self.network, preInFilter) diff --git a/src/ircmsgs.py b/src/ircmsgs.py index 760e7d7e5..d8af5025f 100644 --- a/src/ircmsgs.py +++ b/src/ircmsgs.py @@ -116,7 +116,7 @@ class IrcMsg(object): # On second thought, let's use methods for tagging. __slots__ = ('args', 'command', 'host', 'nick', 'prefix', 'user', '_hash', '_str', '_repr', '_len', 'tags', 'reply_env', - 'server_tags', 'time') + 'server_tags', 'time', 'channel') def __init__(self, s='', command='', args=(), prefix='', msg=None, reply_env=None): assert not (msg and s), 'IrcMsg.__init__ cannot accept both s and msg' diff --git a/test/test_irclib.py b/test/test_irclib.py index f320b6cd8..d00f754be 100644 --- a/test/test_irclib.py +++ b/test/test_irclib.py @@ -470,6 +470,33 @@ class IrcTestCase(SupyTestCase): self.irc.feedMsg(msg2) self.assertEqual(list(self.irc.state.history), [msg1, msg2]) + def testMsgChannel(self): + self.irc.reset() + + self.irc.state.supported['statusmsg'] = '@' + self.irc.feedMsg(ircmsgs.IrcMsg('PRIVMSG #linux :foo bar baz!')) + self.assertEqual(self.irc.state.history[-1].channel, '#linux') + self.irc.feedMsg(ircmsgs.IrcMsg('PRIVMSG @#linux2 :foo bar baz!')) + self.assertEqual(self.irc.state.history[-1].channel, '#linux2') + self.irc.feedMsg(ircmsgs.IrcMsg('PRIVMSG +#linux3 :foo bar baz!')) + self.assertEqual(self.irc.state.history[-1].channel, None) + + self.irc.state.supported['statusmsg'] = '+@' + self.irc.feedMsg(ircmsgs.IrcMsg('PRIVMSG #linux :foo bar baz!')) + self.assertEqual(self.irc.state.history[-1].channel, '#linux') + self.irc.feedMsg(ircmsgs.IrcMsg('PRIVMSG @#linux2 :foo bar baz!')) + self.assertEqual(self.irc.state.history[-1].channel, '#linux2') + self.irc.feedMsg(ircmsgs.IrcMsg('PRIVMSG +#linux3 :foo bar baz!')) + self.assertEqual(self.irc.state.history[-1].channel, '#linux3') + + del self.irc.state.supported['statusmsg'] + self.irc.feedMsg(ircmsgs.IrcMsg('PRIVMSG #linux :foo bar baz!')) + self.assertEqual(self.irc.state.history[-1].channel, '#linux') + self.irc.feedMsg(ircmsgs.IrcMsg('PRIVMSG @#linux2 :foo bar baz!')) + self.assertEqual(self.irc.state.history[-1].channel, None) + self.irc.feedMsg(ircmsgs.IrcMsg('PRIVMSG +#linux3 :foo bar baz!')) + self.assertEqual(self.irc.state.history[-1].channel, None) + def testQuit(self): self.irc.reset() self.irc.feedMsg(ircmsgs.IrcMsg(':someuser JOIN #foo'))