From 59e925c8e5f9a123004e623d96ac97976d2f8a75 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Thu, 8 Jul 2021 09:04:13 -0600 Subject: [PATCH] Add modlog for on_slash_command, closes #34 --- jarvis/__init__.py | 2 +- jarvis/cogs/modlog.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/jarvis/__init__.py b/jarvis/__init__.py index 933ca49..c98d658 100644 --- a/jarvis/__init__.py +++ b/jarvis/__init__.py @@ -221,7 +221,7 @@ async def unwarn(): if warn["time"] + timedelta(hours=warn["duration"]) < datetime.now(): updates.append( pymongo.UpdateOne( - {{"_id": warn["_id"]}, {"$set": {"active": False}}} + {"_id": warn["_id"]}, {"$set": {"active": False}} ) ) if updates: diff --git a/jarvis/cogs/modlog.py b/jarvis/cogs/modlog.py index 7991652..2776687 100644 --- a/jarvis/cogs/modlog.py +++ b/jarvis/cogs/modlog.py @@ -3,8 +3,10 @@ from datetime import datetime, timedelta import discord import pymongo +from discord import DMChannel from discord.ext import commands from discord.utils import find +from discord_slash import SlashContext import jarvis from jarvis.config import get_config @@ -413,6 +415,36 @@ class ModlogCog(commands.Cog): ) await channel.send(embed=embed) + @commands.Cog.listener() + async def on_slash_command(self, ctx: SlashContext): + if not isinstance(ctx.channel, DMChannel): + modlog = self.db.jarvis.settings.find_one( + {"guild": ctx.guild.id, "setting": "modlog"} + ) + if modlog: + channel = ctx.guild.get_channel(modlog["value"]) + fields = [ + Field("Command", ctx.name), + Field("Args", ctx.args, 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) + def setup(bot): bot.add_cog(ModlogCog(bot))