From 1e20a5a7a04afe9e35e5164e431c52c12886c45c Mon Sep 17 00:00:00 2001 From: syntaxbullet Date: Wed, 14 Jan 2026 17:58:28 +0100 Subject: [PATCH] refactor: migrate bot handlers to centralized logger --- bot/lib/handlers/AutocompleteHandler.ts | 3 ++- bot/lib/handlers/CommandHandler.ts | 7 ++++--- bot/lib/handlers/ComponentInteractionHandler.ts | 7 ++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/bot/lib/handlers/AutocompleteHandler.ts b/bot/lib/handlers/AutocompleteHandler.ts index 61b5132..d5a0498 100644 --- a/bot/lib/handlers/AutocompleteHandler.ts +++ b/bot/lib/handlers/AutocompleteHandler.ts @@ -1,5 +1,6 @@ import { AutocompleteInteraction } from "discord.js"; import { AuroraClient } from "@/lib/BotClient"; +import { logger } from "@shared/lib/logger"; /** @@ -16,7 +17,7 @@ export class AutocompleteHandler { try { await command.autocomplete(interaction); } catch (error) { - console.error(`Error handling autocomplete for ${interaction.commandName}:`, error); + logger.error("bot", `Error handling autocomplete for ${interaction.commandName}`, error); } } } diff --git a/bot/lib/handlers/CommandHandler.ts b/bot/lib/handlers/CommandHandler.ts index 3fc8647..eeb4b08 100644 --- a/bot/lib/handlers/CommandHandler.ts +++ b/bot/lib/handlers/CommandHandler.ts @@ -2,6 +2,7 @@ import { ChatInputCommandInteraction, MessageFlags } from "discord.js"; import { AuroraClient } from "@/lib/BotClient"; import { userService } from "@shared/modules/user/user.service"; import { createErrorEmbed } from "@lib/embeds"; +import { logger } from "@shared/lib/logger"; /** @@ -13,7 +14,7 @@ export class CommandHandler { const command = AuroraClient.commands.get(interaction.commandName); if (!command) { - console.error(`No command matching ${interaction.commandName} was found.`); + logger.error("bot", `No command matching ${interaction.commandName} was found.`); return; } @@ -28,14 +29,14 @@ export class CommandHandler { try { await userService.getOrCreateUser(interaction.user.id, interaction.user.username); } catch (error) { - console.error("Failed to ensure user exists:", error); + logger.error("bot", "Failed to ensure user exists", error); } try { await command.execute(interaction); AuroraClient.lastCommandTimestamp = Date.now(); } catch (error) { - console.error(String(error)); + logger.error("bot", `Error executing command ${interaction.commandName}`, error); const errorEmbed = createErrorEmbed('There was an error while executing this command!'); if (interaction.replied || interaction.deferred) { diff --git a/bot/lib/handlers/ComponentInteractionHandler.ts b/bot/lib/handlers/ComponentInteractionHandler.ts index ac4a7eb..f99d127 100644 --- a/bot/lib/handlers/ComponentInteractionHandler.ts +++ b/bot/lib/handlers/ComponentInteractionHandler.ts @@ -2,6 +2,7 @@ import { ButtonInteraction, StringSelectMenuInteraction, ModalSubmitInteraction, import { UserError } from "@shared/lib/errors"; import { createErrorEmbed } from "@lib/embeds"; +import { logger } from "@shared/lib/logger"; type ComponentInteraction = ButtonInteraction | StringSelectMenuInteraction | ModalSubmitInteraction; @@ -28,7 +29,7 @@ export class ComponentInteractionHandler { return; } } else { - console.error(`Handler method ${route.method} not found in module`); + logger.error("bot", `Handler method ${route.method} not found in module`); } } } @@ -52,7 +53,7 @@ export class ComponentInteractionHandler { // Log system errors (non-user errors) for debugging if (!isUserError) { - console.error(`Error in ${handlerName}:`, error); + logger.error("bot", `Error in ${handlerName}`, error); } const errorEmbed = createErrorEmbed(errorMessage); @@ -72,7 +73,7 @@ export class ComponentInteractionHandler { } } catch (replyError) { // If we can't send a reply, log it - console.error(`Failed to send error response in ${handlerName}:`, replyError); + logger.error("bot", `Failed to send error response in ${handlerName}`, replyError); } } }