From 745b7d5690e4d3726be28be5249f593ae0c09947 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 26 Oct 2025 17:50:49 +0100 Subject: [PATCH] refactor(commands/rank): now using the new log system --- src/commands/rank/buyer.ts | 23 +++++++---------------- src/commands/rank/owner.ts | 23 +++++++---------------- src/commands/rank/whitelist.ts | 27 +++++++++------------------ 3 files changed, 23 insertions(+), 50 deletions(-) diff --git a/src/commands/rank/buyer.ts b/src/commands/rank/buyer.ts index 238079f..a0d9288 100644 --- a/src/commands/rank/buyer.ts +++ b/src/commands/rank/buyer.ts @@ -3,6 +3,7 @@ import { EmbedBuilder, MessageFlags } from 'discord.js'; import { prisma } from '@lib/prisma'; import { Guild as GuildPrisma } from '@prisma/client'; import emoji from '../../../assets/emoji.json' assert { type: 'json' }; +import { log } from '@lib/log'; export default { data: new SlashCommandBuilder() @@ -44,9 +45,7 @@ export default { }); } catch (err) { - console.error( - `\t⚠️ | Cannot get the database connection!\n\t\t(${err as Error}).`, - ); + log.error(err, 'Cannot get the database connection'); await interaction.reply({ content: `${emoji.answer.error} | Cannot connect to the database`, flags: MessageFlags.Ephemeral, @@ -62,9 +61,7 @@ export default { }); } catch (err) { - console.error( - `\t⚠️ | Cannot get the database connection!\n\t\t(${err as Error}).`, - ); + log.error(err, 'Cannot get the database connection'); await interaction.reply({ content: `${emoji.answer.error} | Cannot connect to the database`, flags: MessageFlags.Ephemeral, @@ -115,9 +112,7 @@ export default { }); } catch (err) { - console.error( - `⚠️ | Error when adding ${target.username} to the buyer list\n\t${err as Error}`, - ); + log.error(err, `Error when adding ${target.username} to the buyer list`); await interaction.reply({ content: `${emoji.answer.error} | Error when adding ${target.username} to the owner list`, flags: MessageFlags.Ephemeral, @@ -178,9 +173,7 @@ export default { }); } catch (err) { - console.error( - `⚠️ | Error when removing ${target.username} to the buyer list\n\t${err as Error}`, - ); + log.error(err, `Error when removing ${target.username} from the buyer list`); return; } await interaction.reply({ @@ -221,7 +214,7 @@ export default { return `- ${user.username} (\`${user.id}\`)\n`; } catch (err) { - console.warn(`⚠️ | ${buyer.id} : ${err as Error}`); + log.warn(err, `Fetching user ${buyer.id}`); return null; } }), @@ -240,9 +233,7 @@ export default { }); } catch (err) { - console.error( - `⚠️ | error when fetching infromation from the database: ${err as Error}`, - ); + log.error(err, 'Error when fetching information from the database'); await interaction.reply({ content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`, flags: MessageFlags.Ephemeral, diff --git a/src/commands/rank/owner.ts b/src/commands/rank/owner.ts index b4f05f2..929120e 100644 --- a/src/commands/rank/owner.ts +++ b/src/commands/rank/owner.ts @@ -3,6 +3,7 @@ import { CommandInteraction, EmbedBuilder, MessageFlags } from 'discord.js'; import { prisma } from '@lib/prisma'; import { Guild as GuildPrisma, User as UserPrima } from '@prisma/client'; import emoji from '../../../assets/emoji.json' assert { type: 'json' }; +import { log } from '@lib/log'; export default { data: new SlashCommandBuilder() @@ -44,9 +45,7 @@ export default { }); } catch (err) { - console.error( - `\t⚠️ | Cannot get the database connection!\n\t\t(${err as Error}).`, - ); + log.error(err, 'Cannot get the database connection!'); await interaction.reply({ content: `${emoji.answer.error} | Cannot connect to the database`, flags: MessageFlags.Ephemeral, @@ -62,9 +61,7 @@ export default { }); } catch (err) { - console.error( - `\t⚠️ | Cannot get the database connection!\n\t\t(${err as Error}).`, - ); + log.error(err, 'Cannot get the database connection!'); await interaction.reply({ content: `${emoji.answer.error} | Cannot connect to the database`, flags: MessageFlags.Ephemeral, @@ -108,9 +105,7 @@ export default { }); } catch (err) { - console.error( - `⚠️ | Error when adding ${target.username} to the owner list\n\t${err as Error}`, - ); + log.error(err, `Error when adding ${target.username} to the owner list`); await interaction.reply({ content: `${emoji.answer.error} | Error when adding ${target.username} to the owner list`, flags: MessageFlags.Ephemeral, @@ -164,9 +159,7 @@ export default { }); } catch (err) { - console.error( - `⚠️ | Error when removing ${target.username} to the owner list\n\t${err as Error}`, - ); + log.error(err, `Error when removing ${target.username} to the owner list`); await interaction.reply({ content: `${emoji.answer.error} | Cannot removing the user from the owner list`, flags: MessageFlags.Ephemeral, @@ -211,7 +204,7 @@ export default { return `- ${user.username} (\`${user.id}\`)\n`; } catch (err) { - console.warn(`⚠️ | ${owner.id} : ${err as Error}`); + log.warn(err, `Unable to fetch ${owner.id} user`); return null; } }), @@ -230,9 +223,7 @@ export default { }); } catch (err) { - console.error( - `⚠️ | error when fetching infromation from the database: ${err as Error}`, - ); + log.error(err, 'Error when fetching infromation from the database'); await interaction.reply({ content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`, flags: MessageFlags.Ephemeral, diff --git a/src/commands/rank/whitelist.ts b/src/commands/rank/whitelist.ts index 5282c73..c7e50ae 100644 --- a/src/commands/rank/whitelist.ts +++ b/src/commands/rank/whitelist.ts @@ -1,9 +1,10 @@ -import { CommandInteraction, EmbedBuilder, MessageFlags } from 'discord.js'; +import { CommandInteraction, EmbedBuilder, MessageFlags, User } from 'discord.js'; import { SlashCommandBuilder } from '@discordjs/builders'; import { prisma } from '@lib/prisma'; import emoji from '../../../assets/emoji.json' assert { type: 'json' }; import { User as UserPrisma } from '@prisma/client'; import { Guild as GuildPrisma } from '@prisma/client'; +import { log } from '@lib/log'; export default { data: new SlashCommandBuilder() @@ -45,9 +46,7 @@ export default { }); } catch (err) { - console.error( - `\t⚠️ | Whitelist => Cannot get the database connection!\n\t\t(${err as Error}).`, - ); + log.error(err, 'Cannot get the database connection!'); await interaction.reply({ content: `${emoji.answer.error} | Cannot connect to the database`, flags: MessageFlags.Ephemeral, @@ -63,9 +62,7 @@ export default { }); } catch (err) { - console.error( - `\t⚠️ | Cannot get the database connection!\n\t\t(${err as Error}).`, - ); + log.error(err, 'Cannot get the database connection!'); await interaction.reply({ content: `${emoji.answer.error} | Cannot connect to the database`, flags: MessageFlags.Ephemeral, @@ -113,9 +110,7 @@ export default { }); } catch (err) { - console.error( - `⚠️ | Error when adding ${target.username} to the whitelist\n\t${err as Error}`, - ); + log.error(err, `Error when adding ${target.username} to the whitelist`); await interaction.reply({ content: `${emoji.answer.error} | Error when adding ${target.username} to the whitelist`, flags: MessageFlags.Ephemeral, @@ -173,9 +168,7 @@ export default { }); } catch (err) { - console.error( - `⚠️ | Error when removing ${target.username} to the username\n\t${err as Error}`, - ); + log.error(err, `Error when removing ${target.username} to the username`); await interaction.reply({ content: `${emoji.answer.error} | Cannot remove ${target.username} from the whitelist`, flags: MessageFlags.Ephemeral, @@ -214,13 +207,13 @@ export default { } const WlUsers = await Promise.all( - guild.WlUsers.map(async (whitelist) => { + guild.WlUsers.map(async (whitelist: User) => { try { const user = await interaction.client.users.fetch(whitelist.id); return `- ${user.username} (\`${user.id}\`)\n`; } catch (err) { - console.warn(`⚠️ | ${whitelist.id} : ${err as Error}`); + log.warn(err, `Unable to fetch ${whitelist.id}`); return null; } }), @@ -239,9 +232,7 @@ export default { }); } catch (err) { - console.error( - `⚠️ | Whitelist => error when fetching infromation from the database: ${err as Error}`, - ); + log.error(err, 'error when fetching infromation from the database'); await interaction.reply({ content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`, flags: MessageFlags.Ephemeral,