You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
853 B
28 lines
853 B
4 years ago
|
from datetime import datetime
|
||
|
from typing import TYPE_CHECKING
|
||
|
|
||
4 years ago
|
from apscheduler.triggers.cron import CronTrigger
|
||
4 years ago
|
from discord.ext.commands import BadArgument, Converter
|
||
|
from dateutil import parser
|
||
|
|
||
4 years ago
|
from fifo.timezones import assemble_timezones
|
||
4 years ago
|
|
||
|
if TYPE_CHECKING:
|
||
|
DatetimeConverter = datetime
|
||
4 years ago
|
CronConverter = str
|
||
4 years ago
|
else:
|
||
|
class DatetimeConverter(Converter):
|
||
|
async def convert(self, ctx, argument) -> datetime:
|
||
4 years ago
|
dt = parser.parse(argument, fuzzy=True, tzinfos=assemble_timezones())
|
||
4 years ago
|
if dt is not None:
|
||
|
return dt
|
||
|
raise BadArgument()
|
||
4 years ago
|
|
||
|
class CronConverter(Converter):
|
||
|
async def convert(self, ctx, argument) -> str:
|
||
|
try:
|
||
|
CronTrigger.from_crontab(argument)
|
||
|
except ValueError:
|
||
|
raise BadArgument()
|
||
|
|
||
|
return argument
|