From 0a9b8a3adcaf66549c95989bf1c82a2600dbddd2 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Sun, 6 Feb 2022 01:28:20 -0700 Subject: [PATCH] Rework on_command, ref #108 --- jarvis/cogs/modlog/command.py | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/jarvis/cogs/modlog/command.py b/jarvis/cogs/modlog/command.py index 75d54b5..f846f4c 100644 --- a/jarvis/cogs/modlog/command.py +++ b/jarvis/cogs/modlog/command.py @@ -1,40 +1,30 @@ """J.A.R.V.I.S. ModlogCommandCog.""" -from discord import DMChannel -from discord.ext import commands -from discord_slash import SlashContext +from dis_snek import InteractionContext, Snake, listen +from dis_snek.models.discord.channel import DMChannel +from dis_snek.models.discord.embed import EmbedField from jarvis.db.models import Setting from jarvis.utils import build_embed -from jarvis.utils.field import Field -class ModlogCommandCog(commands.Cog): +class ModlogCommandCog(object): """J.A.R.V.I.S. ModlogCommandCog.""" - def __init__(self, bot: commands.Bot): + def __init__(self, bot: Snake): self.bot = bot + self.bot.add_listener(self.on_command) - @commands.Cog.listener() - async def on_slash_command(self, ctx: SlashContext) -> None: + @listen() + async def on_command(self, ctx: InteractionContext) -> None: """Process on_slash_command events.""" if not isinstance(ctx.channel, DMChannel) and ctx.name not in ["pw"]: modlog = Setting.objects(guild=ctx.guild.id, setting="modlog").first() if modlog: - channel = ctx.guild.get_channel(modlog.value) + channel = await ctx.guild.get_channel(modlog.value) + args = " ".join(f"{k}:v" for k, v in ctx.kwargs.items()) fields = [ - Field("Command", ctx.name), + EmbedField(name="Command", value=f"{ctx.invoked_name} {args}", inline=False), ] - if ctx.kwargs: - kwargs_string = " ".join(f"{k}: {str(ctx.kwargs[k])}" for k in ctx.kwargs) - fields.append( - Field( - "Keyword Args", - kwargs_string, - False, - ) - ) - if ctx.subcommand_name: - fields.insert(1, Field("Subcommand", ctx.subcommand_name)) embed = build_embed( title="Command Invoked", description=f"{ctx.author.mention} invoked a command",