Skip to content

Commit

Permalink
Add events logs
Browse files Browse the repository at this point in the history
Add logs when a command is: enabled, disabled, edited, paused and unpaused
  • Loading branch information
rukasudev committed Aug 13, 2024
1 parent ad13a89 commit f817ab0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/views/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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):
Expand Down
30 changes: 30 additions & 0 deletions app/views/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import discord

from app import logger
from app.components.buttons import (
DisableButton,
EditButton,
Expand All @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit f817ab0

Please sign in to comment.