From 32841b230aa6258fd6c0462988938485239c9842 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Wed, 23 Mar 2022 01:26:24 -0600 Subject: [PATCH] More work on settings, WIP --- jarvis/cogs/settings.py | 47 ++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/jarvis/cogs/settings.py b/jarvis/cogs/settings.py index c197573..de39409 100644 --- a/jarvis/cogs/settings.py +++ b/jarvis/cogs/settings.py @@ -1,9 +1,16 @@ """J.A.R.V.I.S. Settings Management Cog.""" from typing import Any +from dis_snek import InteractionContext, Scale, Snake +from dis_snek.models.discord.channel import GuildText +from dis_snek.models.discord.enums import Permissions +from dis_snek.models.snek.application_commands import ( + OptionTypes, + slash_command, + slash_option, +) from dis_snek.models.snek.command import check from discord import Role, TextChannel -from discord.ext import commands from discord.utils import find from discord_slash import SlashContext, cog_ext from discord_slash.utils.manage_commands import create_option @@ -15,12 +22,9 @@ from jarvis.utils.field import Field from jarvis.utils.permissions import admin_or_permissions -class SettingsCog(commands.Cog): +class SettingsCog(Scale): """J.A.R.V.I.S. Settings Management Cog.""" - def __init__(self, bot: commands.Bot): - self.bot = bot - async def update_settings(self, setting: str, value: Any, guild: int) -> bool: """Update a guild setting.""" existing = await Setting.find_one(q(setting=setting, guild=guild)) @@ -38,24 +42,19 @@ class SettingsCog(commands.Cog): return await existing.delete() return False - @cog_ext.cog_subcommand( - base="settings", - subcommand_group="set", - name="modlog", - description="Set modlog channel", - choices=[ - create_option( - name="channel", - description="Modlog channel", - opt_type=7, - required=True, - ) - ], + @slash_command( + name="settings", + description="Control bot settings", + sub_cmd_name="modlog", + sub_cmd_description="Set ActivityLog channel", ) - @check(admin_or_permissions(manage_guild=True)) - async def _set_modlog(self, ctx: SlashContext, channel: TextChannel) -> None: - if not isinstance(channel, TextChannel): - await ctx.send("Channel must be a TextChannel", ephemeral=True) + @slash_option( + name="channel", description="ModLog Channel", opt_type=OptionTypes.CHANNEL, required=True + ) + @check(admin_or_permissions(Permissions.MANAGE_GUILD)) + async def _set_modlog(self, ctx: InteractionContext(), channel: GuildText) -> None: + if not isinstance(channel, GuildText): + await ctx.send("Channel must be a GuildText", ephemeral=True) return self.update_settings("modlog", channel.id, ctx.guild.id) await ctx.send(f"Settings applied. New modlog channel is {channel.mention}") @@ -74,7 +73,7 @@ class SettingsCog(commands.Cog): ) ], ) - @check(admin_or_permissions(manage_guild=True)) + @check(admin_or_permissions(Permissions.MANAGE_GUILD)) async def _set_activitylog(self, ctx: SlashContext, channel: TextChannel) -> None: if not isinstance(channel, TextChannel): await ctx.send("Channel must be a TextChannel", ephemeral=True) @@ -261,6 +260,6 @@ class SettingsCog(commands.Cog): await ctx.send(f"Guild settings cleared: `{deleted is not None}`") -def setup(bot: commands.Bot) -> None: +def setup(bot: Snake) -> None: """Add SettingsCog to J.A.R.V.I.S.""" SettingsCog(bot)