mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Moved seconds command to Misc from Scheduler.
This commit is contained in:
parent
d9e4cef025
commit
f1a68ff16f
@ -55,39 +55,6 @@ def configure(onStart, afterConnect, advanced):
|
||||
|
||||
|
||||
class Scheduler(callbacks.Privmsg):
|
||||
pass
|
||||
|
||||
def seconds(self, irc, msg, args):
|
||||
"""[<days>d] [<hours>h] [<minutes>m] [<seconds>s]
|
||||
|
||||
Returns the number of seconds in the number of <days>, <hours>,
|
||||
<minutes>, and <seconds> 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)
|
||||
|
31
src/Misc.py
31
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):
|
||||
"""[<days>d] [<hours>h] [<minutes>m] [<seconds>s]
|
||||
|
||||
Returns the number of seconds in the number of <days>, <hours>,
|
||||
<minutes>, and <seconds> 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):
|
||||
"""<nick|channel> <text>
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user