50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
from discord import DMChannel
|
|
from discord.ext import commands
|
|
from discord_slash import SlashContext
|
|
|
|
from jarvis.db.types import Setting
|
|
from jarvis.utils import build_embed
|
|
from jarvis.utils.field import Field
|
|
|
|
|
|
class ModlogCommandCog(commands.Cog):
|
|
def __init__(self, bot):
|
|
self.bot = bot
|
|
|
|
@commands.Cog.listener()
|
|
async def on_slash_command(self, ctx: SlashContext):
|
|
if not isinstance(ctx.channel, DMChannel) and ctx.name not in ["pw"]:
|
|
modlog = Setting.get(guild=ctx.guild.id, setting="modlog")
|
|
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.name,
|
|
icon_url=ctx.author.avatar_url,
|
|
)
|
|
embed.set_footer(
|
|
text=f"{ctx.author.name}#{ctx.author.discriminator}"
|
|
+ f" | {ctx.author.id}"
|
|
)
|
|
await channel.send(embed=embed)
|