From 24aa35dc033024e2648e256d57506b6f186f80f0 Mon Sep 17 00:00:00 2001 From: mudkipdev Date: Sun, 7 May 2023 21:12:34 -0600 Subject: [PATCH] permission changes (breaking changes!!) --- example.config.toml | 4 ++-- scnewsbot/extensions/templates.py | 8 +++++++- scnewsbot/utils.py | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/example.config.toml b/example.config.toml index 1d8842d..54b5382 100644 --- a/example.config.toml +++ b/example.config.toml @@ -8,14 +8,14 @@ extensions = [ "extensions.templates" ] -[permissions] +[permissions.announcements] # This works in a whitelist mode. The invoker of the command must be in an allowed guild and # must have an allowed role. If neither of those are true, allowed_users is checked last. allowed_guilds = [] allowed_roles = [] allowed_users = [] -[permissions.debug] +[permissions.announcements.debug] # This works in addition to the regular permissions, but only if debug mode is enabled. allowed_guilds = [] allowed_roles = [] diff --git a/scnewsbot/extensions/templates.py b/scnewsbot/extensions/templates.py index e98aa23..57f34a8 100644 --- a/scnewsbot/extensions/templates.py +++ b/scnewsbot/extensions/templates.py @@ -1,6 +1,7 @@ from discord.ext import commands import discord from extensions.announcements import Announcement +from utils import can_publish_announcements TEMPLATES: dict[str, Announcement] = { "isc": Announcement(title="Inside Star Citizen | [topic] - [subtopic]"), @@ -58,11 +59,13 @@ class TemplatesCog(commands.Cog, name="Templates"): async def templates(self, ctx: commands.Context) -> None: await ctx.send_help(ctx.command) + @commands.check(can_publish_announcements) @templates.command(name="list") 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: templates = {name.lower(): value for name, value in self.templates.items()} @@ -78,6 +81,7 @@ class TemplatesCog(commands.Cog, name="Templates"): embed.remove_author() await ctx.reply(embed=embed) + @commands.check(can_publish_announcements) @commands.command(brief='A shortcut to the "templates view" command.') async def template(self, ctx: commands.Context, *, template_name: str) -> None: await ctx.invoke( @@ -85,6 +89,7 @@ class TemplatesCog(commands.Cog, name="Templates"): template_name=template_name, ) + @commands.check(can_publish_announcements) @commands.command(name="previews", brief="Shows all the possible ping previews.") async def ping_previews(self, ctx: commands.Context) -> None: await ctx.reply( @@ -94,6 +99,7 @@ class TemplatesCog(commands.Cog, name="Templates"): allowed_mentions=discord.AllowedMentions.none(), ) + @commands.check(can_publish_announcements) @commands.command(brief="Shows all the channel IDs for announcements.") async def channels(self, ctx: commands.Context) -> None: await ctx.reply( diff --git a/scnewsbot/utils.py b/scnewsbot/utils.py index aee7fb1..b559a3f 100644 --- a/scnewsbot/utils.py +++ b/scnewsbot/utils.py @@ -34,9 +34,9 @@ class Config: return self._get_allowed_objects("allowed_users") def _get_allowed_objects(self, object_name, /) -> list: - allowed_objects = self.config["permissions"].get(object_name, []) + allowed_objects = self.config["permissions"]["announcements"].get(object_name, []) if self.debug: - allowed_objects += self.config["permissions"]["debug"].get(object_name, []) + allowed_objects += self.config["permissions"]["announcements"]["debug"].get(object_name, []) return allowed_objects