From 0e17952bb01d35901ef2b270a7d173e56615b1db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sven=20M=C3=A4der?= <maeder@phys.ethz.ch> Date: Tue, 5 Mar 2024 12:26:33 +0100 Subject: [PATCH] Refactor class names --- ethzlunch/__init__.py | 2 +- ethzlunch/bot.py | 11 ++++++----- ethzlunch/db.py | 6 +++--- ethzlunch/reminder.py | 4 ++-- maubot.yaml | 4 ++-- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/ethzlunch/__init__.py b/ethzlunch/__init__.py index 7b67996..a58b8c4 100644 --- a/ethzlunch/__init__.py +++ b/ethzlunch/__init__.py @@ -1 +1 @@ -from .bot import ReminderBot +from .bot import ETHzLunchBot diff --git a/ethzlunch/bot.py b/ethzlunch/bot.py index 9652983..4fe720d 100644 --- a/ethzlunch/bot.py +++ b/ethzlunch/bot.py @@ -25,7 +25,7 @@ from mautrix.util.async_db import UpgradeTable from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper from .migrations import upgrade_table -from .db import ReminderDatabase +from .db import ETHzLunchDatabase from .util import validate_locale, validate_timezone, CommandSyntaxError from .reminder import Reminder from .ethz import (parse_facilities, parse_menus, filter_facilities, markdown_facilities, @@ -49,14 +49,14 @@ class Config(BaseProxyConfig): helper.copy("default_facilities") -class ReminderBot(Plugin): +class ETHzLunchBot(Plugin): base_command: Tuple[str, ...] hunger_command: Tuple[str, ...] default_timezone: pytz.timezone admin_power_level: int scheduler: AsyncIOScheduler reminders: Dict[EventID, Reminder] - db: ReminderDatabase + db: ETHzLunchDatabase url_facilities: str url_menus: str @@ -71,7 +71,7 @@ class ReminderBot(Plugin): async def start(self) -> None: self.scheduler = AsyncIOScheduler() self.scheduler.start() - self.db = ReminderDatabase(self.database) + self.db = ETHzLunchDatabase(self.database) self.on_external_config_update() self.reminders = await self.db.load_all(self) @@ -245,7 +245,8 @@ class ReminderBot(Plugin): f"Available price categories: `int`, `ext`, `stud`\n" f"Disable prices in menus: `off`") - @lunch.subcommand("remind", help="Create reminder (time: `hh:mm`, days default: `mon-fri`)") + @lunch.subcommand("remind", aliases=["reminder"], + help="Create reminder (time: `hh:mm`, days default: `mon-fri`)") @command.argument("time", matches="[0-9]{1,2}:[0-9]{2}") @command.argument("days", required=False) @command.argument("canteens", required=False, pass_raw=True) diff --git a/ethzlunch/db.py b/ethzlunch/db.py index fdf58ec..f10baed 100644 --- a/ethzlunch/db.py +++ b/ethzlunch/db.py @@ -29,7 +29,7 @@ from mautrix.types import UserID, EventID, RoomID if TYPE_CHECKING: - from .bot import ReminderBot + from .bot import ETHzLunchBot from .reminder import Reminder @@ -37,7 +37,7 @@ from .reminder import Reminder logger = logging.getLogger(__name__) -class ReminderDatabase: +class ETHzLunchDatabase: cache: DefaultDict[UserID, UserInfo] db: Database defaults: UserInfo @@ -125,7 +125,7 @@ class ReminderDatabase: reminder.is_agenda, reminder.creator) - async def load_all(self, bot: ReminderBot) -> Dict[EventID, Reminder]: + async def load_all(self, bot: ETHzLunchBot) -> Dict[EventID, Reminder]: """ Load all reminders in the database and return them as a dict for the main bot Args: bot: it feels dirty to do it this way, but it seems to work and make code cleaner diff --git a/ethzlunch/reminder.py b/ethzlunch/reminder.py index 1b1cb97..af4e2ea 100644 --- a/ethzlunch/reminder.py +++ b/ethzlunch/reminder.py @@ -18,7 +18,7 @@ except ImportError: USE_CRON_DESCRIPTOR = False if TYPE_CHECKING: - from .bot import ReminderBot + from .bot import ETHzLunchBot logger = logging.getLogger(__name__) @@ -26,7 +26,7 @@ logger = logging.getLogger(__name__) class Reminder(object): def __init__( self, - bot: ReminderBot, + bot: ETHzLunchBot, room_id: RoomID, message: str, event_id: Optional[EventID] = None, diff --git a/maubot.yaml b/maubot.yaml index d80bb2e..e537c2a 100644 --- a/maubot.yaml +++ b/maubot.yaml @@ -3,8 +3,8 @@ id: ch.ethz.phys.lunch version: 0.0.2 license: AGPL-3.0-or-later modules: -- reminder -main_class: ReminderBot +- ethzlunch +main_class: ETHzLunchBot extra_files: - base-config.yaml dependencies: -- GitLab