From 122fc79d01e874be207fb3784f17ee9e7ba168d9 Mon Sep 17 00:00:00 2001 From: mudkipdev Date: Sun, 7 May 2023 21:25:44 -0600 Subject: [PATCH] add warning for legacy config --- scnewsbot/__main__.py | 9 +++++++++ scnewsbot/extensions/templates.py | 2 +- scnewsbot/utils.py | 8 ++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/scnewsbot/__main__.py b/scnewsbot/__main__.py index afe718a..2f21c39 100644 --- a/scnewsbot/__main__.py +++ b/scnewsbot/__main__.py @@ -9,12 +9,21 @@ class InvalidTokenException(Exception): pass +class InvalidConfigException(Exception): + pass + + def main() -> None: DISCORD_TOKEN = os.getenv("DISCORD_TOKEN") if not DISCORD_TOKEN: raise InvalidTokenException("A Discord token was not set.") with open("config.toml", "rb") as config_file: + if "[permissions]" in config_file.read(): + raise InvalidConfigException( + "The format for permissions has changed; please check the new example config." + ) + config = Config(tomllib.load(config_file)) bot = Bot(config) diff --git a/scnewsbot/extensions/templates.py b/scnewsbot/extensions/templates.py index 57f34a8..3743d0f 100644 --- a/scnewsbot/extensions/templates.py +++ b/scnewsbot/extensions/templates.py @@ -64,7 +64,7 @@ class TemplatesCog(commands.Cog, name="Templates"): async def _list(self, ctx: commands.Context) -> None: templates = "\n".join([f"- {template}" for template in self.templates]) await ctx.reply(f"Here are all of the available templates: ```\n{templates}```") - + @commands.check(can_publish_announcements) @templates.command() async def view(self, ctx: commands.Context, *, template_name: str) -> None: diff --git a/scnewsbot/utils.py b/scnewsbot/utils.py index b559a3f..e4f4db9 100644 --- a/scnewsbot/utils.py +++ b/scnewsbot/utils.py @@ -34,9 +34,13 @@ class Config: return self._get_allowed_objects("allowed_users") def _get_allowed_objects(self, object_name, /) -> list: - allowed_objects = self.config["permissions"]["announcements"].get(object_name, []) + allowed_objects = self.config["permissions"]["announcements"].get( + object_name, [] + ) if self.debug: - allowed_objects += self.config["permissions"]["announcements"]["debug"].get(object_name, []) + allowed_objects += self.config["permissions"]["announcements"]["debug"].get( + object_name, [] + ) return allowed_objects