From de01aa55650adefeef4b98bbc694fc4171ecf7b3 Mon Sep 17 00:00:00 2001 From: Tulir Asokan <tulir@maunium.net> Date: Sat, 24 Oct 2020 15:20:48 +0300 Subject: [PATCH] Rename default timezone config field --- base-config.yaml | 7 ++++--- reminder/bot.py | 6 ++++-- reminder/db.py | 3 ++- reminder/util.py | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/base-config.yaml b/base-config.yaml index a42dbdc..ab9095f 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 6025cbe..a678237 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 65be035..2cce8e3 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 4fba198..a87b96e 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): -- GitLab