Rework on_command, ref #108
This commit is contained in:
parent
adf770d624
commit
0a9b8a3adc
1 changed files with 11 additions and 21 deletions
|
@ -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",
|
||||
|
|
Loading…
Add table
Reference in a new issue