permission changes (breaking changes!!)

This commit is contained in:
mudkipdev
2023-05-07 21:12:34 -06:00
parent 75538c57d7
commit 24aa35dc03
3 changed files with 11 additions and 5 deletions

View File

@@ -8,14 +8,14 @@ extensions = [
"extensions.templates" "extensions.templates"
] ]
[permissions] [permissions.announcements]
# This works in a whitelist mode. The invoker of the command must be in an allowed guild and # 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. # must have an allowed role. If neither of those are true, allowed_users is checked last.
allowed_guilds = [] allowed_guilds = []
allowed_roles = [] allowed_roles = []
allowed_users = [] allowed_users = []
[permissions.debug] [permissions.announcements.debug]
# This works in addition to the regular permissions, but only if debug mode is enabled. # This works in addition to the regular permissions, but only if debug mode is enabled.
allowed_guilds = [] allowed_guilds = []
allowed_roles = [] allowed_roles = []

View File

@@ -1,6 +1,7 @@
from discord.ext import commands from discord.ext import commands
import discord import discord
from extensions.announcements import Announcement from extensions.announcements import Announcement
from utils import can_publish_announcements
TEMPLATES: dict[str, Announcement] = { TEMPLATES: dict[str, Announcement] = {
"isc": Announcement(title="Inside Star Citizen | [topic] - [subtopic]"), "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: async def templates(self, ctx: commands.Context) -> None:
await ctx.send_help(ctx.command) await ctx.send_help(ctx.command)
@commands.check(can_publish_announcements)
@templates.command(name="list") @templates.command(name="list")
async def _list(self, ctx: commands.Context) -> None: async def _list(self, ctx: commands.Context) -> None:
templates = "\n".join([f"- {template}" for template in self.templates]) templates = "\n".join([f"- {template}" for template in self.templates])
await ctx.reply(f"Here are all of the available templates: ```\n{templates}```") await ctx.reply(f"Here are all of the available templates: ```\n{templates}```")
@commands.check(can_publish_announcements)
@templates.command() @templates.command()
async def view(self, ctx: commands.Context, *, template_name: str) -> None: async def view(self, ctx: commands.Context, *, template_name: str) -> None:
templates = {name.lower(): value for name, value in self.templates.items()} templates = {name.lower(): value for name, value in self.templates.items()}
@@ -78,6 +81,7 @@ class TemplatesCog(commands.Cog, name="Templates"):
embed.remove_author() embed.remove_author()
await ctx.reply(embed=embed) await ctx.reply(embed=embed)
@commands.check(can_publish_announcements)
@commands.command(brief='A shortcut to the "templates view" command.') @commands.command(brief='A shortcut to the "templates view" command.')
async def template(self, ctx: commands.Context, *, template_name: str) -> None: async def template(self, ctx: commands.Context, *, template_name: str) -> None:
await ctx.invoke( await ctx.invoke(
@@ -85,6 +89,7 @@ class TemplatesCog(commands.Cog, name="Templates"):
template_name=template_name, template_name=template_name,
) )
@commands.check(can_publish_announcements)
@commands.command(name="previews", brief="Shows all the possible ping previews.") @commands.command(name="previews", brief="Shows all the possible ping previews.")
async def ping_previews(self, ctx: commands.Context) -> None: async def ping_previews(self, ctx: commands.Context) -> None:
await ctx.reply( await ctx.reply(
@@ -94,6 +99,7 @@ class TemplatesCog(commands.Cog, name="Templates"):
allowed_mentions=discord.AllowedMentions.none(), allowed_mentions=discord.AllowedMentions.none(),
) )
@commands.check(can_publish_announcements)
@commands.command(brief="Shows all the channel IDs for announcements.") @commands.command(brief="Shows all the channel IDs for announcements.")
async def channels(self, ctx: commands.Context) -> None: async def channels(self, ctx: commands.Context) -> None:
await ctx.reply( await ctx.reply(

View File

@@ -34,9 +34,9 @@ class Config:
return self._get_allowed_objects("allowed_users") return self._get_allowed_objects("allowed_users")
def _get_allowed_objects(self, object_name, /) -> list: 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: 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 return allowed_objects