mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 11:42:52 +01:00
Add a 'channel' attribute to IrcMsg objects.
It's nicer to use 'irc.channel' instead of 'irc.args[0]', and .channel provides the actual channel name (stripped of the statusmsg prefix), so it can be used by plugins when they want to use the actual channel name.
This commit is contained in:
parent
d4cac026d4
commit
7a7cdb9f05
@ -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)
|
||||
|
||||
|
@ -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'
|
||||
|
@ -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'))
|
||||
|
Loading…
Reference in New Issue
Block a user