core: Use IRCv3.2 extension server-time to fill IrcMsg.time, if available.

This commit is contained in:
Valentin Lorentz 2015-08-22 20:11:46 +02:00
parent 11c10bb3f1
commit b338a23708
3 changed files with 13 additions and 2 deletions

View File

@ -955,7 +955,7 @@ class Irc(IrcCommandDispatcher, log.Firewalled):
REQUEST_CAPABILITIES = set(['account-notify', 'extended-join',
'multi-prefix', 'metadata-notify', 'account-tag',
'userhost-in-names', 'invite-notify'])
'userhost-in-names', 'invite-notify', 'server-time'])
def _queueConnectMessages(self):
if self.zombie:

View File

@ -38,6 +38,7 @@ object (which, as you'll read later, is quite...full-featured :))
import re
import sys
import time
import datetime
import functools
from . import conf, ircutils, utils
@ -148,7 +149,13 @@ class IrcMsg(object):
else:
self.args = s.split()
self.command = self.args.pop(0)
self.time = time.time()
if 'time' in self.server_tags:
s = self.server_tags['time']
date = datetime.datetime.strptime(s, '%Y-%m-%dT%H:%M:%S.%fZ')
print(repr(date))
self.time = date.timestamp()
else:
self.time = time.time()
except (IndexError, ValueError):
raise MalformedIrcMsg(repr(originalString))
else:

View File

@ -153,6 +153,10 @@ class IrcMsgTestCase(SupyTestCase):
after = time.time()
self.assertTrue(before <= msg.time <= after)
msg = ircmsgs.IrcMsg('@time=2011-10-19T16:40:51.620Z '
':Angel!angel@example.org PRIVMSG Wiz :Hello')
self.assertEqual(msg.time, 1319035251.62)
class FunctionsTestCase(SupyTestCase):
def testIsAction(self):
L = [':jemfinch!~jfincher@ts26-2.homenet.ohio-state.edu PRIVMSG'