diff --git a/plugins/Time/plugin.py b/plugins/Time/plugin.py index a0d8fcdd2..94b2fa62a 100644 --- a/plugins/Time/plugin.py +++ b/plugins/Time/plugin.py @@ -72,10 +72,13 @@ try: except ImportError: tzlocal = None + +_SECONDS_SPLIT_RE = re.compile('(?<=[a-z]) ?') + class Time(callbacks.Plugin): """This plugin allows you to use different time-related functions.""" @internationalizeDocstring - def seconds(self, irc, msg, args): + def seconds(self, irc, msg, args, text): """[y] [w] [d] [h] [m] [s] Returns the number of seconds in the number of , , @@ -84,11 +87,13 @@ class Time(callbacks.Plugin): Useful for scheduling events at a given number of seconds in the future. """ - if not args: - raise callbacks.ArgumentError seconds = 0 - for arg in args: - if not arg or arg[-1] not in 'ywdhms': + if not text: + raise callbacks.ArgumentError + for arg in _SECONDS_SPLIT_RE.split(text): + if not arg: + continue + if arg[-1] not in 'ywdhms': raise callbacks.ArgumentError (s, kind) = arg[:-1], arg[-1] try: @@ -108,6 +113,7 @@ class Time(callbacks.Plugin): elif kind == 's': seconds += i irc.reply(str(seconds)) + seconds = wrap(seconds, ['text']) @internationalizeDocstring def at(self, irc, msg, args, s=None): diff --git a/plugins/Time/test.py b/plugins/Time/test.py index 96233edb7..57b2a486a 100644 --- a/plugins/Time/test.py +++ b/plugins/Time/test.py @@ -77,16 +77,22 @@ class TimeTestCase(PluginTestCase): self.assertResponse('seconds 10s', '10') self.assertResponse('seconds 1m', '60') self.assertResponse('seconds 1m 1s', '61') + self.assertResponse('seconds 1m1s', '61') self.assertResponse('seconds 1h', '3600') self.assertResponse('seconds 1h 1s', '3601') + self.assertResponse('seconds 1h1s', '3601') self.assertResponse('seconds 1d', '86400') self.assertResponse('seconds 1d 1s', '86401') + self.assertResponse('seconds 1d1s', '86401') self.assertResponse('seconds 2s', '2') self.assertResponse('seconds 2m', '120') self.assertResponse('seconds 2d 2h 2m 2s', '180122') + self.assertResponse('seconds 2d2h2m2s', '180122') self.assertResponse('seconds 1s', '1') self.assertResponse('seconds 1y 1s', '31536001') + self.assertResponse('seconds 1y1s', '31536001') self.assertResponse('seconds 1w 1s', '604801') + self.assertResponse('seconds 1w1s', '604801') def testNoErrors(self): self.assertNotError('ctime')