mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-02 23:54:07 +01:00
Add attribute IrcMsg.time.
This commit is contained in:
parent
33e8966e4b
commit
11c10bb3f1
@ -114,7 +114,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')
|
||||
'server_tags', 'time')
|
||||
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'
|
||||
@ -148,6 +148,7 @@ class IrcMsg(object):
|
||||
else:
|
||||
self.args = s.split()
|
||||
self.command = self.args.pop(0)
|
||||
self.time = time.time()
|
||||
except (IndexError, ValueError):
|
||||
raise MalformedIrcMsg(repr(originalString))
|
||||
else:
|
||||
@ -171,11 +172,14 @@ class IrcMsg(object):
|
||||
else:
|
||||
self.reply_env = None
|
||||
self.tags = msg.tags.copy()
|
||||
self.server_tags = msg.server_tags
|
||||
self.time = msg.time
|
||||
else:
|
||||
self.prefix = prefix
|
||||
self.command = command
|
||||
assert all(ircutils.isValidArgument, args), args
|
||||
self.args = args
|
||||
self.time = None
|
||||
self.args = tuple(self.args)
|
||||
if isUserHostmask(self.prefix):
|
||||
(self.nick,self.user,self.host)=ircutils.splitHostmask(self.prefix)
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
from supybot.test import *
|
||||
|
||||
import time
|
||||
import copy
|
||||
import pickle
|
||||
|
||||
@ -94,6 +95,11 @@ class IrcMsgTestCase(SupyTestCase):
|
||||
ircmsgs.IrcMsg,
|
||||
args=('foo', 'bar'),
|
||||
prefix='foo!bar@baz')
|
||||
m = ircmsgs.IrcMsg(prefix='foo!bar@baz', args=('foo', 'bar'),
|
||||
command='CMD')
|
||||
self.assertIs(m.time, None)
|
||||
m.time = 24
|
||||
self.assertEqual(ircmsgs.IrcMsg(msg=m).time, 24)
|
||||
|
||||
def testPickleCopy(self):
|
||||
for msg in msgs:
|
||||
@ -141,6 +147,12 @@ class IrcMsgTestCase(SupyTestCase):
|
||||
self.assertEqual(m.args, ('me', 'Hello'))
|
||||
self.assertEqual(str(m), s + '\n')
|
||||
|
||||
def testTime(self):
|
||||
before = time.time()
|
||||
msg = ircmsgs.IrcMsg('PRIVMSG #foo :foo')
|
||||
after = time.time()
|
||||
self.assertTrue(before <= msg.time <= after)
|
||||
|
||||
class FunctionsTestCase(SupyTestCase):
|
||||
def testIsAction(self):
|
||||
L = [':jemfinch!~jfincher@ts26-2.homenet.ohio-state.edu PRIVMSG'
|
||||
|
Loading…
Reference in New Issue
Block a user