diff --git a/plugins/Scheduler.py b/plugins/Scheduler.py index e40f64da3..1335f3582 100644 --- a/plugins/Scheduler.py +++ b/plugins/Scheduler.py @@ -55,39 +55,6 @@ def configure(onStart, afterConnect, advanced): class Scheduler(callbacks.Privmsg): - pass - - def seconds(self, irc, msg, args): - """[d] [h] [m] [s] - - Returns the number of seconds in the number of , , - , and given. An example usage is - "seconds 2h 30m", which would return 9000, which is 3600*2 + 30*60. - 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 'dhms': - raise callbacks.ArgumentError - (s, kind) = arg[:-1], arg[-1] - try: - i = int(s) - except ValueError: - irc.error(msg, 'Invalid argument: %s' % arg) - return - if kind == 'd': - seconds += i*86400 - elif kind == 'h': - seconds += i*3600 - elif kind == 'm': - seconds += i*60 - elif kind == 's': - seconds += i - irc.reply(msg, str(seconds)) - def _makeCommandFunction(self, irc, msg, command): """Makes a function suitable for scheduling from command.""" tokens = callbacks.tokenize(command) diff --git a/src/Misc.py b/src/Misc.py index 14899171b..e7f77cf46 100755 --- a/src/Misc.py +++ b/src/Misc.py @@ -389,6 +389,37 @@ class Misc(callbacks.Privmsg): irc.error(msg, 'I couldn\'t find a message matching that criteria in ' 'my history of %s messages.' % len(irc.state.history)) + def seconds(self, irc, msg, args): + """[d] [h] [m] [s] + + Returns the number of seconds in the number of , , + , and given. An example usage is + "seconds 2h 30m", which would return 9000, which is 3600*2 + 30*60. + 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 'dhms': + raise callbacks.ArgumentError + (s, kind) = arg[:-1], arg[-1] + try: + i = int(s) + except ValueError: + irc.error(msg, 'Invalid argument: %s' % arg) + return + if kind == 'd': + seconds += i*86400 + elif kind == 'h': + seconds += i*3600 + elif kind == 'm': + seconds += i*60 + elif kind == 's': + seconds += i + irc.reply(msg, str(seconds)) + def tell(self, irc, msg, args): """ diff --git a/test/test_Misc.py b/test/test_Misc.py index 8cdaac310..589c4fd87 100644 --- a/test/test_Misc.py +++ b/test/test_Misc.py @@ -188,6 +188,20 @@ class MiscTestCase(ChannelPluginTestCase, PluginDocumentation): def testRevisionIsCaseInsensitive(self): self.assertNotError('revision misc') + def testSeconds(self): + self.assertResponse('seconds 1s', '1') + self.assertResponse('seconds 10s', '10') + self.assertResponse('seconds 1m', '60') + self.assertResponse('seconds 1m 1s', '61') + self.assertResponse('seconds 1h', '3600') + self.assertResponse('seconds 1h 1s', '3601') + self.assertResponse('seconds 1d', '86400') + self.assertResponse('seconds 1d 1s', '86401') + self.assertResponse('seconds 2s', '2') + self.assertResponse('seconds 2m', '120') + self.assertResponse('seconds 2d 2h 2m 2s', '180122') + self.assertResponse('seconds 1s', '1') + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: diff --git a/test/test_Scheduler.py b/test/test_Scheduler.py index 1e209d54c..54365ae7a 100644 --- a/test/test_Scheduler.py +++ b/test/test_Scheduler.py @@ -33,20 +33,6 @@ from testsupport import * class MiscTestCase(ChannelPluginTestCase, PluginDocumentation): plugins = ('Scheduler', 'Utilities') - def testSeconds(self): - self.assertResponse('seconds 1s', '1') - self.assertResponse('seconds 10s', '10') - self.assertResponse('seconds 1m', '60') - self.assertResponse('seconds 1m 1s', '61') - self.assertResponse('seconds 1h', '3600') - self.assertResponse('seconds 1h 1s', '3601') - self.assertResponse('seconds 1d', '86400') - self.assertResponse('seconds 1d 1s', '86401') - self.assertResponse('seconds 2s', '2') - self.assertResponse('seconds 2m', '120') - self.assertResponse('seconds 2d 2h 2m 2s', '180122') - self.assertResponse('seconds 1s', '1') - def testAddRemove(self): self.assertNotError('scheduler add [seconds 5s] echo foo bar baz') self.assertNoResponse(' ', 4)