Skip to content

Commit

Permalink
Merge pull request #41 from 0xEmma/command-log
Browse files Browse the repository at this point in the history
Command Logging
  • Loading branch information
dimoschi authored May 30, 2023
2 parents 799ddfe + f089f3f commit ed95d57
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .test.env
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ SENTRY_DSN=

# Channels
CHANNEL_SR_MOD=1127695218900993410
CHANNEL_BOT_LOGS=1012769518828339331
CHANNEL_VERIFY_LOGS=1012769518828339331
CHANNEL_BOT_COMMANDS=1276953350848588101
CHANNEL_SPOILER=2769521890099371011
CHANNEL_BOT_LOGS=1105517088266788925

# Roles
ROLE_BIZCTF2022=7629466241011276950
Expand Down
5 changes: 5 additions & 0 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ async def on_application_command(self, ctx: ApplicationContext) -> None:
"""A global handler cog."""
logger.debug(f"Command '{ctx.command}' received.")
received_commands.labels(ctx.command.name).inc()
embed = Embed(title="Command Log")
embed.add_field(name="Command", value=ctx.command, inline=True)
embed.add_field(name="Caller", value=ctx.author.name, inline=True)
embed.add_field(name="Channel", value=ctx.channel.name, inline=True)
await ctx.guild.get_channel(settings.channels.BOT_LOGS).send(embed=embed)

async def on_application_command_error(self, ctx: ApplicationContext, error: DiscordException) -> None:
"""A global error handler cog."""
Expand Down
6 changes: 3 additions & 3 deletions src/cmds/core/identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def identify(self, ctx: ApplicationContext, account_identifier: str) -> In
f"Related HTB UID: {most_recent_rec.htb_user_id}"
)
embed = discord.Embed(title="Identification error", description=error_desc, color=0xFF2429)
await self.bot.get_channel(settings.channels.BOT_LOGS).send(embed=embed)
await self.bot.get_channel(settings.channels.VERIFY_LOGS).send(embed=embed)

return await ctx.respond(
"Identification error: please contact an online Moderator or Administrator for help.", ephemeral=True
Expand All @@ -98,7 +98,7 @@ async def identify(self, ctx: ApplicationContext, account_identifier: str) -> In
f"but is tied to another Discord account.\n"
f"Originally linked to Discord UID {orig_discord_ids}.")
embed = discord.Embed(title="Identification error", description=error_desc, color=0xFF2429)
await self.bot.get_channel(settings.channels.BOT_LOGS).send(embed=embed)
await self.bot.get_channel(settings.channels.VERIFY_LOGS).send(embed=embed)

return await ctx.respond(
"Identification error: please contact an online Moderator or Administrator for help.", ephemeral=True
Expand All @@ -122,7 +122,7 @@ async def identify(self, ctx: ApplicationContext, account_identifier: str) -> In
f"Original HTB UIDs: {', '.join([str(i) for i in user_htb_ids])}, new HTB UID: "
f"{json_htb_user_id}.")
embed = discord.Embed(title="Identification error", description=error_desc, color=0xFF2429)
await self.bot.get_channel(settings.channels.BOT_LOGS).send(embed=embed)
await self.bot.get_channel(settings.channels.VERIFY_LOGS).send(embed=embed)

return await ctx.respond(
"Identification error: please contact an online Moderator or Administrator for help.", ephemeral=True
Expand Down
6 changes: 3 additions & 3 deletions src/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class Channels(BaseSettings):

DEVLOG: int = 0
SR_MOD: int
BOT_LOGS: int
VERIFY_LOGS: int
BOT_COMMANDS: int
SPOILER: int

@validator("DEVLOG", "SR_MOD", "BOT_LOGS", "BOT_COMMANDS", "SPOILER")
BOT_LOGS: int
@validator("DEVLOG", "SR_MOD", "VERIFY_LOGS", "BOT_COMMANDS", "SPOILER", "BOT_LOGS")
def check_ids_format(cls, v: list[int]) -> list[int]:
"""Validate discord ids format."""
if not v:
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async def process_identification(
description=f"User {member.mention} ({member.id}) was platform banned HTB and thus also here.",
color=0xFF2429, )

await guild.get_channel(settings.channels.BOT_LOGS).send(embed=embed)
await guild.get_channel(settings.channels.VERIFY_LOGS).send(embed=embed)
return None

to_remove = []
Expand Down

0 comments on commit ed95d57

Please sign in to comment.