From c7b2aacb371c5973a8cc1bd87c6006f8d7405cee Mon Sep 17 00:00:00 2001 From: wlinator Date: Sun, 2 Jul 2023 11:33:25 -0400 Subject: [PATCH] Logs on_application_command_completion --- main.py | 62 ++++++++++++++++++++++++++++++++++++++---------- modules/basic.py | 4 ---- 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/main.py b/main.py index cc0d59b..5d81d73 100644 --- a/main.py +++ b/main.py @@ -9,6 +9,7 @@ SPECIAL_BALANCE_NAME= import logging import os +import platform import re from datetime import datetime @@ -98,19 +99,21 @@ def setup_logger(): logger.addHandler(info_file_handler) logger.propagate = False + logging.captureWarnings(True) + return logger +racu_logs = setup_logger() + + @sbbot.event async def on_ready(): - # wait until the bot is ready - # then sync the sqlite3 database - # db.tables.sync_database() - # Item.insert_items() - - # reload all cogs to sync db parameters - # load_cogs(reload=True) - racu_logs.info("RACU IS BOOTED/READY") + racu_logs.info(f"Logged in as {sbbot.user.name}") + racu_logs.info(f"discord.py API version: {discord.__version__}") + racu_logs.info(f"Python version: {platform.python_version()}") + racu_logs.info(f"Running on: {platform.system()} {platform.release()} ({os.name})") + racu_logs.info("-----------------------------------------") """ https://docs.pycord.dev/en/stable/api/events.html#discord.on_ready @@ -124,11 +127,16 @@ async def on_message(message): if message.author.bot: return - xp_handler = XPHandler() - await xp_handler.process_xp(message) + try: + xp_handler = XPHandler() + await xp_handler.process_xp(message) - reaction_handler = ReactionHandler(reactions) - await reaction_handler.handle_message(message) + reaction_handler = ReactionHandler(reactions) + await reaction_handler.handle_message(message) + + except Exception as error: + racu_logs.error(f"on_message (check debug log): {error}", exc_info=False) + racu_logs.debug(f"on_message (w/ stacktrace): {error}", exc_info=True) @sbbot.event @@ -159,7 +167,35 @@ async def on_member_join(member): await guild.get_channel(welcome_channel_id).send(embed=embed, content=member.mention) -racu_logs = setup_logger() +@sbbot.event +async def on_application_command_completion(ctx) -> None: + """ + This code is executed when a slash_command has been successfully executed. + :param ctx: + :return: + """ + full_command_name = ctx.command.qualified_name + split = full_command_name.split(" ") + executed_command = str(split[0]) + + if ctx.guild is not None: + racu_logs.info( + f"Executed {executed_command} command in {ctx.guild.name} (ID: {ctx.guild.id}) " + f"by {ctx.author} (ID: {ctx.author.id})" + ) + else: + racu_logs.info( + f"Executed {executed_command} command by {ctx.author} (ID: {ctx.author.id}) in DMs." + ) + + +# async def on_application_command_error(ctx, error) -> None: +# racu_logs.error(f"on_command_error (check debug log): {error}", exc_info=False) +# racu_logs.debug(f"on_command_error (w/ stacktrace): {error}", exc_info=True) + +# async def on_error(event: str, *args, **kwargs) -> None: +# racu_logs.error(f"on_command_error (check debug log): {event}") + # load all json strings = json_loader.load_strings() diff --git a/modules/basic.py b/modules/basic.py index 0b49fe7..ea98c4a 100644 --- a/modules/basic.py +++ b/modules/basic.py @@ -23,7 +23,6 @@ class BasicCog(commands.Cog): async def ping(self, ctx): ping = round(self.bot.latency * 1000, 2) await ctx.respond(f"SB latency: {ping} ms") - racu_logs.info(f"{ctx.author.name} used the ping command. | ping: {ping} ms") @commands.slash_command( name="restart", @@ -33,7 +32,6 @@ class BasicCog(commands.Cog): @commands.check(universal.owner_check) async def restart(self, ctx): await ctx.respond(content="Restarting..", ephemeral=True) - racu_logs.info(f"{ctx.author.name} used the restart command.") try: racu_logs.info(subprocess.check_output(["/bin/bash", "racu_update.sh"])) @@ -47,8 +45,6 @@ class BasicCog(commands.Cog): ) @commands.dm_only() async def intro(self, ctx): - racu_logs.info(f"{ctx.author.name} used the intro command.") - guild_id = 719227135151046699 channel_id = 973619250507972618 muted_role_id = 754895743151505489