mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-10-03 01:48:52 +02:00
Time: add 'ddate' (#1310)
* Time: add 'ddate', fix contributors, add Time.local as a package_dir in setup.py * Time: add in license information for ddate.py * Time: change 'ddate' command to where it will error out gracefully if 'ddate.base' isn't available * Time: add tests, remove Time.local from package_dir
This commit is contained in:
parent
bee98f6711
commit
2ba7bc5c16
@ -42,8 +42,9 @@ __author__ = supybot.authors.jemfinch
|
|||||||
|
|
||||||
# This is a dictionary mapping supybot.Author instances to lists of
|
# This is a dictionary mapping supybot.Author instances to lists of
|
||||||
# contributions.
|
# contributions.
|
||||||
__contributors__ = {'tztime': supybot.Author('Valentin Lorentz', 'ProgVal',
|
__contributors__ = {supybot.authors.progval: ['tztime'],
|
||||||
'progval@gmail.com')}
|
supybot.Author('Ken Spencer', 'kspencer',
|
||||||
|
'iota@electrocode.net'): ['ddate']}
|
||||||
|
|
||||||
|
|
||||||
from . import config
|
from . import config
|
||||||
|
0
plugins/Time/local/__init__.py
Normal file
0
plugins/Time/local/__init__.py
Normal file
@ -27,17 +27,24 @@
|
|||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
###
|
###
|
||||||
|
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
TIME = time # For later use.
|
TIME = time # For later use.
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import supybot.conf as conf
|
import supybot.conf as conf
|
||||||
|
import supybot.log as log
|
||||||
import supybot.utils as utils
|
import supybot.utils as utils
|
||||||
from supybot.commands import *
|
from supybot.commands import *
|
||||||
import supybot.callbacks as callbacks
|
import supybot.callbacks as callbacks
|
||||||
from supybot.i18n import PluginInternationalization, internationalizeDocstring
|
from supybot.i18n import PluginInternationalization, internationalizeDocstring
|
||||||
_ = PluginInternationalization('Time')
|
_ = PluginInternationalization('Time')
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ddate.base import DDate as _ddate
|
||||||
|
except ImportError:
|
||||||
|
log.info("'ddate' not available, disabling command.")
|
||||||
|
_ddate = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from dateutil import parser
|
from dateutil import parser
|
||||||
@ -206,7 +213,22 @@ class Time(callbacks.Plugin):
|
|||||||
irc.reply(datetime.now(timezone).strftime(format))
|
irc.reply(datetime.now(timezone).strftime(format))
|
||||||
tztime = wrap(tztime, ['text'])
|
tztime = wrap(tztime, ['text'])
|
||||||
|
|
||||||
|
def ddate(self, irc, msg, args, year=None, month=None, day=None):
|
||||||
|
"""[<year> <month> <day>]
|
||||||
|
Returns a the Discordian date today, or an optional different date."""
|
||||||
|
if _ddate is not None:
|
||||||
|
if year is not None and month is not None and day is not None:
|
||||||
|
try:
|
||||||
|
irc.reply(_ddate(datetime(year=year, month=month, day=day)))
|
||||||
|
except ValueError as e:
|
||||||
|
irc.error("%s", e)
|
||||||
|
else:
|
||||||
|
irc.reply(_ddate())
|
||||||
|
else:
|
||||||
|
irc.error(_("The 'ddate' module is not installed."
|
||||||
|
" Use '%s -m pip install --user ddate'"
|
||||||
|
" See <https://pypi.python.org/pypi/ddate/> for more information.") % sys.executable)
|
||||||
|
ddate = wrap(ddate, [optional('positiveint'), optional('positiveint'), optional('positiveint')])
|
||||||
Class = Time
|
Class = Time
|
||||||
|
|
||||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
@ -43,6 +43,13 @@ except ImportError:
|
|||||||
else:
|
else:
|
||||||
has_dateutil = True
|
has_dateutil = True
|
||||||
|
|
||||||
|
try:
|
||||||
|
import ddate.base
|
||||||
|
except ImportError:
|
||||||
|
has_ddate = False
|
||||||
|
else:
|
||||||
|
has_ddate = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from unittest import skipIf
|
from unittest import skipIf
|
||||||
except ImportError: # Python 2.6
|
except ImportError: # Python 2.6
|
||||||
@ -92,6 +99,13 @@ class TimeTestCase(PluginTestCase):
|
|||||||
def testNoNestedErrors(self):
|
def testNoNestedErrors(self):
|
||||||
self.assertNotError('echo [seconds 4m]')
|
self.assertNotError('echo [seconds 4m]')
|
||||||
|
|
||||||
|
@skipIf(not has_ddate, 'ddate is missing')
|
||||||
|
def testDDate(self):
|
||||||
|
self.assertNotError('ddate')
|
||||||
|
self.assertHelp('ddate 0 0 0') # because nonsense was put in
|
||||||
|
self.assertHelp('ddate -1 1 1') # because nonsense was put in
|
||||||
|
self.assertHelp('ddate -1 -1 -1') # because nonsense was put in
|
||||||
|
# plugin.py:223 would catch these otherwise
|
||||||
|
self.assertResponse('ddate 1 1 1', 'Sweetmorn, the 1st day of Chaos in the YOLD 1167') # make sure the laws of physics and time aren't out of wack
|
||||||
|
|
||||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user