Skip to content
Snippets Groups Projects
Commit de01aa55 authored by Tulir Asokan's avatar Tulir Asokan
Browse files

Rename default timezone config field

parent 5bace921
No related branches found
No related tags found
No related merge requests found
# 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'
......@@ -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:
......
......@@ -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:
......
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment