From be5722bb0116d74058babc261b6d07ff02881275 Mon Sep 17 00:00:00 2001 From: Slincnik Date: Sun, 8 Dec 2024 18:11:30 +0300 Subject: [PATCH] refactor: change default console to logger --- handlers/command-handler/functions/registerCommands.js | 9 ++++++--- handlers/command-handler/index.js | 5 +++-- handlers/event-handler/index.js | 10 +++++----- newEvents/ready.js | 4 +++- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/handlers/command-handler/functions/registerCommands.js b/handlers/command-handler/functions/registerCommands.js index e0e50d2e..c7fe5ef9 100644 --- a/handlers/command-handler/functions/registerCommands.js +++ b/handlers/command-handler/functions/registerCommands.js @@ -1,3 +1,4 @@ +import logger from "../../../helpers/logger.js"; import differentCommands from "../utils/differentcommands.js"; export default async function registerCommands(props) { @@ -14,12 +15,14 @@ const registerGlobalCommands = async (client, commands) => { const targetCommand = appCommandsManager.cache.find(cmd => cmd.name === data.name); if (targetCommand && differentCommands(targetCommand, data)) { - await targetCommand.edit(data).catch(() => console.log(`Failed to update command: ${data.name} globally`)); + await targetCommand.edit(data).catch(() => logger.error(`Failed to update command: ${data.name} globally`)); - console.log(`Edited command globally: ${data.name}`); + logger.log(`Edited command globally: ${data.name}`); } else if (!targetCommand) { - await appCommandsManager.create(data).catch(() => console.log(`Failed to register command: ${data.name}`)); + await appCommandsManager.create(data).catch(() => logger.error(`Failed to register command: ${data.name}`)); } }), ); + + logger.log("Registered global commands"); }; diff --git a/handlers/command-handler/index.js b/handlers/command-handler/index.js index 50538603..96ffe039 100644 --- a/handlers/command-handler/index.js +++ b/handlers/command-handler/index.js @@ -1,3 +1,4 @@ +import logger from "../../helpers/logger.js"; import { client } from "../../index.js"; import { getFilePaths } from "../../utils/get-path.js"; import { toFileURL } from "../../utils/resolve-file.js"; @@ -21,12 +22,12 @@ const buildCommands = async () => { const { data, run } = await import(toFileURL(cmdFilePath)); if (!data || !data.name) { - console.warn(`Command ${cmdFilePath} does not have a data object or name`); + logger.warn(`Command ${cmdFilePath} does not have a data object or name`); continue; } if (typeof run !== "function") { - console.warn(`Command ${cmdFilePath} does not have a run function or it is not a function`); + logger.warn(`Command ${cmdFilePath} does not have a run function or it is not a function`); continue; } diff --git a/handlers/event-handler/index.js b/handlers/event-handler/index.js index 4179703d..6200e0a6 100644 --- a/handlers/event-handler/index.js +++ b/handlers/event-handler/index.js @@ -1,3 +1,4 @@ +import logger from "../../helpers/logger.js"; import { client } from "../../index.js"; import { getFilePaths } from "../../utils/get-path.js"; import { toFileURL } from "../../utils/resolve-file.js"; @@ -6,7 +7,6 @@ export const events = []; export const init = async () => { await buildEvents(); - registerEvents(); }; @@ -18,23 +18,23 @@ const buildEvents = async () => { const { data, run } = await import(toFileURL(eventFilePath)); if (!data || !data.name) { - console.warn(`Event ${eventFilePath} does not have a data object or name`); + logger.warn(`Event ${eventFilePath} does not have a data object or name`); continue; } if (typeof run !== "function") { - console.warn(`Event ${eventFilePath} does not have a run function or it is not a function`); + logger.warn(`Event ${eventFilePath} does not have a run function or it is not a function`); continue; } events.push({ data, run }); } } catch (error) { - console.error("Error build events: ", error); + logger.error("Error build events: ", error); } }; -const registerEvents = () => { +const registerEvents = async () => { for (const { data, run } of events) { if (data.once) client.once(data.name, run); else client.on(data.name, run); diff --git a/newEvents/ready.js b/newEvents/ready.js index d796ebd6..0f698b5d 100644 --- a/newEvents/ready.js +++ b/newEvents/ready.js @@ -1,3 +1,5 @@ +import logger from "../helpers/logger.js"; + export const data = { name: "ready", once: true, @@ -8,5 +10,5 @@ export const data = { * @param {import("../base/Client.JaBaClient")} client */ export async function run(client) { - console.log(client.user.tag + " is online!"); + logger.log(client.user.tag + " is online!"); }