change badges.py to use utils.datetime_utcnow() - less code dupe
This commit is contained in:
parent
2c19bdb949
commit
d91cd02d34
1 changed files with 3 additions and 6 deletions
|
@ -9,12 +9,9 @@ DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
|
||||||
DATE_FORMAT = "%Y-%m-%d"
|
DATE_FORMAT = "%Y-%m-%d"
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
def _now(self):
|
|
||||||
return datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)
|
|
||||||
|
|
||||||
def _parse_date(self, dt: str):
|
def _parse_date(self, dt: str):
|
||||||
if dt.lower() == "today":
|
if dt.lower() == "today":
|
||||||
return self._now()
|
return utils.datetime_utcnow()
|
||||||
else:
|
else:
|
||||||
match = RE_HUMAN_FORMAT.match(dt)
|
match = RE_HUMAN_FORMAT.match(dt)
|
||||||
if not match:
|
if not match:
|
||||||
|
@ -57,7 +54,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
badge_lower = badge.lower()
|
badge_lower = badge.lower()
|
||||||
badges = self._get_badges(event["user"])
|
badges = self._get_badges(event["user"])
|
||||||
|
|
||||||
now = self._round_up_day(self._now())
|
now = self._round_up_day(utils.datetime_utcnow())
|
||||||
|
|
||||||
found_badge = self._find_badge(badges, badge)
|
found_badge = self._find_badge(badges, badge)
|
||||||
|
|
||||||
|
@ -79,7 +76,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
if event["args"]:
|
if event["args"]:
|
||||||
user = event["server"].get_user(event["args_split"][0])
|
user = event["server"].get_user(event["args_split"][0])
|
||||||
|
|
||||||
now = self._round_up_day(self._now())
|
now = self._round_up_day(utils.datetime_utcnow())
|
||||||
badges = []
|
badges = []
|
||||||
for badge, date in self._get_badges(user).items():
|
for badge, date in self._get_badges(user).items():
|
||||||
days_since = self._days_since(now, utils.iso8601_parse(date))
|
days_since = self._days_since(now, utils.iso8601_parse(date))
|
||||||
|
|
Loading…
Reference in a new issue