diff options
| author | 2019-06-28 23:16:05 +0100 | |
|---|---|---|
| committer | 2019-06-28 23:16:05 +0100 | |
| commit | ae9d099a41b703ce875cf8746a94b6995bbaedfb (patch) | |
| tree | c389ae3b967c43055a1c671b8cebf04db4e8f8b6 /modules/birthday.py | |
| parent | message arg for HTTPWrongContentTypeException/HTTPParsingException (diff) | |
Refactor set/channelset/serverset/botset in to 'utils.Setting' objects
Diffstat (limited to 'modules/birthday.py')
| -rw-r--r-- | modules/birthday.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/modules/birthday.py b/modules/birthday.py index 46a1dde6..563c7a73 100644 --- a/modules/birthday.py +++ b/modules/birthday.py @@ -1,7 +1,7 @@ #--depends-on commands #--depends-on config -import datetime +import datetime, typing from src import ModuleManager, utils DATE_YEAR_FORMAT = "%Y-%m-%d" @@ -30,20 +30,22 @@ def _format(years, dt): return _format_year(dt) else: return _format_noyear(dt) -def _check(s): - parsed = _parse(s) - if parsed: - years, parsed = parsed - return _format(years, parsed) - return None + +class BirthdaySetting(utils.Setting): + def parse(self, value: str) -> typing.Any: + parsed = _parse(value) + if parsed: + years, parsed = parsed + return _format(years, parsed) + return None def _apostrophe(nickname): if nickname[-1].lower() == "s": return "%s'" % nickname return "%s's" % nickname -@utils.export("set", {"setting": "birthday", "help": "Set your birthday", - "validate": _check, "example": "1995-09-15"}) +@utils.export("set", BirthdaySetting("birthday", "Set your birthday", + example="1995-09-15")) class Module(ModuleManager.BaseModule): @utils.hook("received.command.birthday") def birthday(self, event): |
