diff --git a/reminder/bot.py b/reminder/bot.py index f9d9f25..18d2c70 100644 --- a/reminder/bot.py +++ b/reminder/bot.py @@ -42,7 +42,6 @@ def get_config_class(cls) -> Type[BaseProxyConfig]: return Config async def start(self) -> None: - await super().start() self.on_external_config_update() self.db = ReminderDatabase(self.database) self.reminder_loop_task = asyncio.ensure_future(self.reminder_loop(), loop=self.loop) @@ -54,7 +53,6 @@ def on_external_config_update(self) -> None: self.base_aliases = tuple(bc) if isinstance(bc, list) else (bc,) async def stop(self) -> None: - await super().stop() self.reminder_loop_task.cancel() async def reminder_loop(self) -> None: diff --git a/reminder/locale_util.py b/reminder/locale_util.py index 604878b..46e9041 100644 --- a/reminder/locale_util.py +++ b/reminder/locale_util.py @@ -62,11 +62,19 @@ def match(self, val: str) -> Optional[MatcherReturn]: pass +def int_or_float(val: str) -> Union[int, float]: + if "," in val: + return float(val.replace(",", ".")) + elif "." in val: + return float(val) + return int(val) + + class RegexMatcher(Matcher): regex: Pattern value_type: Type - def __init__(self, pattern: str, value_type: Type = int) -> None: + def __init__(self, pattern: str, value_type: Type = int_or_float) -> None: self.regex = re.compile(pattern, re.IGNORECASE) self.value_type = value_type diff --git a/reminder/locales.py b/reminder/locales.py index b12632d..8a5e1ac 100644 --- a/reminder/locales.py +++ b/reminder/locales.py @@ -21,16 +21,17 @@ locales: Locales = {} td_sep_en = r"(?:[\s,]{1,3}(?:and\s)?)?" +number = r"[+-]?\d+(?:[.,]\d+)?" locales["en_iso"] = Locale( name="English (ISO)", timedelta=RegexMatcher(r"(?:(?:in|after)\s)?" - rf"(?:(?P[-+]?\d+)\s?y(?:r|ears?)?{td_sep_en})?" - rf"(?:(?P[-+]?\d+)\s?mo(?:nths?)?{td_sep_en})?" - rf"(?:(?P[-+]?\d+)\s?w(?:k|eeks?)?{td_sep_en})?" - rf"(?:(?P[-+]?\d+)\s?d(?:ays?)?{td_sep_en})?" - rf"(?:(?P[-+]?\d+)\s?h(?:(?:r|our)?s?){td_sep_en})?" - rf"(?:(?P[-+]?\d+)\s?m(?:in(?:ute)?s?)?{td_sep_en})?" - r"(?:(?P[-+]?\d+)\s?s(?:ec(?:ond)?s?)?)?" + rf"(?:(?P{number})\s?y(?:r|ear)?s?{td_sep_en})?" + rf"(?:(?P{number})\s?mo(?:nth)?s?{td_sep_en})?" + rf"(?:(?P{number})\s?w(?:k|eek)?s?{td_sep_en})?" + rf"(?:(?P{number})\s?d(?:ays?)?{td_sep_en})?" + rf"(?:(?P{number})\s?h(?:(?:r|our)?s?){td_sep_en})?" + rf"(?:(?P{number})\s?m(?:in(?:ute)?s?)?{td_sep_en})?" + rf"(?:(?P{number})\s?s(?:ec(?:ond)?s?)?)?" r"(?:\s|$)"), date=RegexMatcher(r"(?P\d{4})-(?P\d{2})-(?P\d{2})\s"), weekday=WeekdayMatcher(pattern=r"(?:today" @@ -72,13 +73,13 @@ td_sep_fi = r"(?:[\s,]{1,3}(?:ja\s)?)?" locales["fi_fi"] = Locale( name="Finnish", - timedelta=RegexMatcher(rf"(?:(?P[-+]?\d+)\s?v(?:uo(?:tta|den))?{td_sep_fi})?" - rf"(?:(?P[-+]?\d+)\s?k(?:k|uukau(?:si|tta|den))?{td_sep_fi})?" - rf"(?:(?P[-+]?\d+)\s?v(?:k|iikk?o[an]?){td_sep_fi})?" - rf"(?:(?P[-+]?\d+)\s?p(?:v|äivä[än]?){td_sep_fi})?" - rf"(?:(?P[-+]?\d+)\s?t(?:un(?:nin?|tia))?{td_sep_fi})?" - rf"(?:(?P[-+]?\d+)\s?m(?:in(?:uut(?:in?|tia))?)?{td_sep_fi})?" - r"(?:(?P[-+]?\d+)\s?s(?:ek(?:un(?:nin?|tia))?)?)?" + timedelta=RegexMatcher(rf"(?:(?P{number})\s?v(?:uo(?:tta|den))?{td_sep_fi})?" + rf"(?:(?P{number})\s?k(?:k|uukau(?:si|tta|den))?{td_sep_fi})?" + rf"(?:(?P{number})\s?v(?:k|iikk?o[an]?){td_sep_fi})?" + rf"(?:(?P{number})\s?p(?:v|äivä[än]?){td_sep_fi})?" + rf"(?:(?P{number})\s?t(?:un(?:nin?|tia))?{td_sep_fi})?" + rf"(?:(?P{number})\s?m(?:in(?:uut(?:in?|tia))?)?{td_sep_fi})?" + rf"(?:(?P{number})\s?s(?:ek(?:un(?:nin?|tia))?)?)?" r"(?:\s(?:kuluttua|päästä?))?" r"(?:\s|$)"), date=ShortYearMatcher(r"(?P\d{1,2})\.(?P\d{1,2})\.(?P\d{2}(?:\d{2})?)\s"), @@ -108,13 +109,13 @@ locales["de_de"] = Locale( name="German", timedelta=RegexMatcher(rf"(?:in\s)?" - rf"(?:(?P[-+]?\d+)\s?jahr(?:en)?{td_sep_de})?" - rf"(?:(?P[-+]?\d+)\s?monat(?:en)?{td_sep_de})?" - rf"(?:(?P[-+]?\d+)\s?wochen?{td_sep_de})?" - rf"(?:(?P[-+]?\d+)\s?tag(?:en)?{td_sep_de})?" - rf"(?:(?P[-+]?\d+)\s?stunden?{td_sep_de})?" - rf"(?:(?P[-+]?\d+)\s?minuten?{td_sep_de})?" - r"(?:(?P[-+]?\d+)\s?sekunden?)?"), + rf"(?:(?P{number})\s?jahr(?:en)?{td_sep_de})?" + rf"(?:(?P{number})\s?monat(?:en)?{td_sep_de})?" + rf"(?:(?P{number})\s?wochen?{td_sep_de})?" + rf"(?:(?P{number})\s?tag(?:en)?{td_sep_de})?" + rf"(?:(?P{number})\s?stunden?{td_sep_de})?" + rf"(?:(?P{number})\s?minuten?{td_sep_de})?" + rf"(?:(?P{number})\s?sekunden?)?"), date=ShortYearMatcher( r"(?P\d{1,2})\.(?P\d{1,2})\.(?P\d{2}(?:\d{2})?)(?:\s|$)"), weekday=WeekdayMatcher(pattern=r"(?:heute"