From f817ab02db71b311aa50829e7798dc8ae35e52bd Mon Sep 17 00:00:00 2001 From: Lucas Daniel Date: Tue, 13 Aug 2024 07:15:01 -0300 Subject: [PATCH] Add events logs Add logs when a command is: enabled, disabled, edited, paused and unpaused --- app/views/form.py | 9 +++++++++ app/views/manager.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/app/views/form.py b/app/views/form.py index 56e0ed0..af8e064 100644 --- a/app/views/form.py +++ b/app/views/form.py @@ -2,11 +2,13 @@ import discord +from app import logger from app.components.buttons import CancelButton, ConfirmButton, EditButton from app.components.embed import parse_form_dict_to_embed from app.components.modals import CustomModal from app.constants import Commands as commandconstants from app.constants import FormConstants as constants +from app.constants import LogTypes as logconstants from app.services.cogs import insert_cog_by_guild, insert_cog_event from app.services.moderations import update_moderations_by_guild from app.services.utils import ( @@ -283,6 +285,13 @@ async def _finish(self, interaction: discord.Interaction): str(interaction.user.id), ) + logger.info( + f"Command {self.command_key} enabled by {interaction.user.id}", + log_type=logconstants.COMMAND_INFO_TYPE, + guild_id=str(interaction.guild.id), + interaction=interaction, + ) + await interaction.followup.send(embed=embed, view=self) def pre_finish_step(self, interaction: discord.Interaction): diff --git a/app/views/manager.py b/app/views/manager.py index f19f7b5..5c42c62 100644 --- a/app/views/manager.py +++ b/app/views/manager.py @@ -2,6 +2,7 @@ import discord +from app import logger from app.components.buttons import ( DisableButton, EditButton, @@ -10,6 +11,7 @@ UnpauseButton, ) from app.constants import Commands as constants +from app.constants import LogTypes as logconstants from app.services.cogs import ( delete_cog_by_guild, find_cog_events_by_guild, @@ -82,6 +84,13 @@ async def update_command(self, interaction: discord.Interaction): view = self.edited_form_view.view view.clear_items() + logger.info( + f"Command {self.command_key} edited by {interaction.user.id}", + log_type=logconstants.COMMAND_INFO_TYPE, + guild_id=str(interaction.guild.id), + interaction=interaction, + ) + await interaction.followup.edit_message(interaction.message.id, view=self) await interaction.followup.send(embed=embed, view=self) @@ -115,6 +124,13 @@ async def unpause_callback(self, interaction: discord.Interaction): str(interaction.user.id), ) + logger.info( + f"Command {self.command_key} unpaused by {interaction.user.id}", + log_type=logconstants.COMMAND_INFO_TYPE, + guild_id=guild_id, + interaction=interaction, + ) + await interaction.response.edit_message(view=self) await interaction.followup.send(embed=embed, view=self) @@ -142,6 +158,13 @@ async def pause_callback(self, interaction: discord.Interaction): str(interaction.user.id), ) + logger.info( + f"Command {self.command_key} paused by {interaction.user.id}", + log_type=logconstants.COMMAND_INFO_TYPE, + guild_id=guild_id, + interaction=interaction, + ) + await interaction.response.edit_message(view=self) await interaction.followup.send(embed=embed, view=self) @@ -177,6 +200,13 @@ async def disable_callback(self, interaction: discord.Interaction): str(interaction.user.id), ) + logger.info( + f"Command {self.command_key} disabled by {interaction.user.id}", + log_type=logconstants.COMMAND_INFO_TYPE, + guild_id=guild_id, + interaction=interaction, + ) + await interaction.followup.edit_message(interaction.message.id, view=self) await interaction.followup.send(embed=embed, view=self)