From 93381d7da00d84454967b05a78607a887c84e805 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Thu, 3 Feb 2022 06:34:14 -0700 Subject: [PATCH] Migrate owner, closes #99 --- jarvis/cogs/owner.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/jarvis/cogs/owner.py b/jarvis/cogs/owner.py index a19dcd9..0e55bde 100644 --- a/jarvis/cogs/owner.py +++ b/jarvis/cogs/owner.py @@ -1,31 +1,26 @@ """J.A.R.V.I.S. Owner Cog.""" -from discord import User -from discord.ext import commands +from dis_snek import MessageContext, Scale, Snake, message_command +from dis_snek.models.discord.user import User +from dis_snek.models.snek.checks import is_owner from jarvis.config import reload_config from jarvis.db.models import Config -class OwnerCog(commands.Cog): +class OwnerCog(Scale): """ J.A.R.V.I.S. management cog. Used by admins to control core J.A.R.V.I.S. systems """ - def __init__(self, bot: commands.Cog): + def __init__(self, bot: Snake): self.bot = bot self.admins = Config.objects(key="admins").first() - @commands.group(name="admin", hidden=True, pass_context=True) - @commands.is_owner() - async def _admin(self, ctx: commands.Context) -> None: - if ctx.invoked_subcommand is None: - await ctx.send("Usage: `admin `\n" + "Subcommands: `add`, `remove`") - - @_admin.command(name="add", hidden=True) - @commands.is_owner() - async def _add(self, ctx: commands.Context, user: User) -> None: + @message_command(name="addadmin") + @is_owner() + async def _add(self, ctx: MessageContext, user: User) -> None: if user.id in self.admins.value: await ctx.send(f"{user.mention} is already an admin.") return @@ -34,9 +29,9 @@ class OwnerCog(commands.Cog): reload_config() await ctx.send(f"{user.mention} is now an admin. Use this power carefully.") - @_admin.command(name="remove", hidden=True) - @commands.is_owner() - async def _remove(self, ctx: commands.Context, user: User) -> None: + @message_command(name="deladmin") + @is_owner() + async def _remove(self, ctx: MessageContext, user: User) -> None: if user.id not in self.admins.value: await ctx.send(f"{user.mention} is not an admin.") return @@ -46,6 +41,6 @@ class OwnerCog(commands.Cog): await ctx.send(f"{user.mention} is no longer an admin.") -def setup(bot: commands.Bot) -> None: +def setup(bot: Snake) -> None: """Add OwnerCog to J.A.R.V.I.S.""" bot.add_cog(OwnerCog(bot))