diff --git a/base-config.yaml b/base-config.yaml index a42dbdcd3abb5c69aa31c5b37475991334089831..ab9095faef3038c601d06f85352da56e938f3bc3 100644 --- a/base-config.yaml +++ b/base-config.yaml @@ -1,8 +1,9 @@ +# Default timezone for users who did not set one. +# This is parsed with pytz, so the usual format is Continent/City, e.g. Europe/Helsinki. +default_timezone: 'UTC' + # Base command without the prefix (!). # If a list is provided, the first is the main name and the rest are aliases. base_command: - remind - reminder - -# Default timezone for users who did not set one -timezone: 'UTC' diff --git a/reminder/bot.py b/reminder/bot.py index 6025cbec4ea9e8f3f5e3f34c91e5aea7c681ad9c..a67823732522e9d107c28555c6c3e1f649fd10cc 100644 --- a/reminder/bot.py +++ b/reminder/bot.py @@ -36,6 +36,7 @@ class ReminderBot(Plugin): reminder_loop_task: asyncio.Future base_command: str base_aliases: Tuple[str, ...] + default_timezone: pytz.timezone @classmethod def get_config_class(cls) -> Type[BaseProxyConfig]: @@ -51,10 +52,11 @@ class ReminderBot(Plugin): bc = self.config["base_command"] self.base_command = bc[0] if isinstance(bc, list) else bc self.base_aliases = tuple(bc) if isinstance(bc, list) else (bc,) + raw_timezone = self.config["default_timezone"] try: - self.default_timezone = pytz.timezone(self.config["timezone"]) + self.default_timezone = pytz.timezone(raw_timezone) except pytz.UnknownTimeZoneError: - self.log.warning(f"Unknown default timezone {self.config['timezone']}") + self.log.warning(f"Unknown default timezone {raw_timezone}") self.default_timezone = pytz.UTC async def stop(self) -> None: diff --git a/reminder/db.py b/reminder/db.py index 65be035879738a963383e8745ee65b13f986ac08..2cce8e39ce9f29f78b7d21f7228ef798a3749be9 100644 --- a/reminder/db.py +++ b/reminder/db.py @@ -70,7 +70,8 @@ class ReminderDatabase: tx.execute(self.timezone.insert().values(user_id=user_id, timezone=tz.zone)) self.tz_cache[user_id] = tz - def get_timezone(self, user_id: UserID, default_tz: Optional[pytz.timezone]) -> Optional[pytz.timezone]: + def get_timezone(self, user_id: UserID, default_tz: Optional[pytz.timezone] = None + ) -> Optional[pytz.timezone]: try: return self.tz_cache[user_id] except KeyError: diff --git a/reminder/util.py b/reminder/util.py index 4fba198dd076c1ba12f414b025284048d539f79e..a87b96e9ff01a6605b31e8b051e2c053912e6d6c 100644 --- a/reminder/util.py +++ b/reminder/util.py @@ -34,8 +34,8 @@ if TYPE_CHECKING: class Config(BaseProxyConfig): def do_update(self, helper: ConfigUpdateHelper) -> None: + helper.copy("default_timezone") helper.copy("base_command") - helper.copy("timezone") class DateArgument(Argument):