48 lines
1.9 KiB
Python
48 lines
1.9 KiB
Python
"""J.A.R.V.I.S. ModlogCommandCog."""
|
|
from discord import DMChannel
|
|
from discord.ext import commands
|
|
from discord_slash import SlashContext
|
|
|
|
from jarvis.db.models import Setting
|
|
from jarvis.utils import build_embed
|
|
from jarvis.utils.field import Field
|
|
|
|
|
|
class ModlogCommandCog(commands.Cog):
|
|
"""J.A.R.V.I.S. ModlogCommandCog."""
|
|
|
|
def __init__(self, bot: commands.Bot):
|
|
self.bot = bot
|
|
|
|
@commands.Cog.listener()
|
|
async def on_slash_command(self, ctx: SlashContext) -> 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)
|
|
fields = [
|
|
Field("Command", ctx.name),
|
|
]
|
|
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",
|
|
fields=fields,
|
|
color="#fc9e3f",
|
|
)
|
|
embed.set_author(name=ctx.author.username, icon_url=ctx.author.display_avatar.url)
|
|
embed.set_footer(
|
|
text=f"{ctx.author.username}#{ctx.author.discriminator} | {ctx.author.id}"
|
|
)
|
|
await channel.send(embed=embed)
|