refactor(commands/rank): now using the new log system

This commit is contained in:
Raphael 2025-10-26 17:50:49 +01:00 committed by Raphaël
parent bdfa9e1c9b
commit 745b7d5690
3 changed files with 23 additions and 50 deletions

View file

@ -3,6 +3,7 @@ import { EmbedBuilder, MessageFlags } from 'discord.js';
import { prisma } from '@lib/prisma'; import { prisma } from '@lib/prisma';
import { Guild as GuildPrisma } from '@prisma/client'; import { Guild as GuildPrisma } from '@prisma/client';
import emoji from '../../../assets/emoji.json' assert { type: 'json' }; import emoji from '../../../assets/emoji.json' assert { type: 'json' };
import { log } from '@lib/log';
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
@ -44,9 +45,7 @@ export default {
}); });
} }
catch (err) { catch (err) {
console.error( log.error(err, 'Cannot get the database connection');
`\t⚠ | Cannot get the database connection!\n\t\t(${err as Error}).`,
);
await interaction.reply({ await interaction.reply({
content: `${emoji.answer.error} | Cannot connect to the database`, content: `${emoji.answer.error} | Cannot connect to the database`,
flags: MessageFlags.Ephemeral, flags: MessageFlags.Ephemeral,
@ -62,9 +61,7 @@ export default {
}); });
} }
catch (err) { catch (err) {
console.error( log.error(err, 'Cannot get the database connection');
`\t⚠ | Cannot get the database connection!\n\t\t(${err as Error}).`,
);
await interaction.reply({ await interaction.reply({
content: `${emoji.answer.error} | Cannot connect to the database`, content: `${emoji.answer.error} | Cannot connect to the database`,
flags: MessageFlags.Ephemeral, flags: MessageFlags.Ephemeral,
@ -115,9 +112,7 @@ export default {
}); });
} }
catch (err) { catch (err) {
console.error( log.error(err, `Error when adding ${target.username} to the buyer list`);
`⚠️ | Error when adding ${target.username} to the buyer list\n\t${err as Error}`,
);
await interaction.reply({ await interaction.reply({
content: `${emoji.answer.error} | Error when adding ${target.username} to the owner list`, content: `${emoji.answer.error} | Error when adding ${target.username} to the owner list`,
flags: MessageFlags.Ephemeral, flags: MessageFlags.Ephemeral,
@ -178,9 +173,7 @@ export default {
}); });
} }
catch (err) { catch (err) {
console.error( log.error(err, `Error when removing ${target.username} from the buyer list`);
`⚠️ | Error when removing ${target.username} to the buyer list\n\t${err as Error}`,
);
return; return;
} }
await interaction.reply({ await interaction.reply({
@ -221,7 +214,7 @@ export default {
return `- ${user.username} (\`${user.id}\`)\n`; return `- ${user.username} (\`${user.id}\`)\n`;
} }
catch (err) { catch (err) {
console.warn(`⚠️ | ${buyer.id} : ${err as Error}`); log.warn(err, `Fetching user ${buyer.id}`);
return null; return null;
} }
}), }),
@ -240,9 +233,7 @@ export default {
}); });
} }
catch (err) { catch (err) {
console.error( log.error(err, 'Error when fetching information from the database');
`⚠️ | error when fetching infromation from the database: ${err as Error}`,
);
await interaction.reply({ await interaction.reply({
content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`, content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`,
flags: MessageFlags.Ephemeral, flags: MessageFlags.Ephemeral,

View file

@ -3,6 +3,7 @@ import { CommandInteraction, EmbedBuilder, MessageFlags } from 'discord.js';
import { prisma } from '@lib/prisma'; import { prisma } from '@lib/prisma';
import { Guild as GuildPrisma, User as UserPrima } from '@prisma/client'; import { Guild as GuildPrisma, User as UserPrima } from '@prisma/client';
import emoji from '../../../assets/emoji.json' assert { type: 'json' }; import emoji from '../../../assets/emoji.json' assert { type: 'json' };
import { log } from '@lib/log';
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
@ -44,9 +45,7 @@ export default {
}); });
} }
catch (err) { catch (err) {
console.error( log.error(err, 'Cannot get the database connection!');
`\t⚠ | Cannot get the database connection!\n\t\t(${err as Error}).`,
);
await interaction.reply({ await interaction.reply({
content: `${emoji.answer.error} | Cannot connect to the database`, content: `${emoji.answer.error} | Cannot connect to the database`,
flags: MessageFlags.Ephemeral, flags: MessageFlags.Ephemeral,
@ -62,9 +61,7 @@ export default {
}); });
} }
catch (err) { catch (err) {
console.error( log.error(err, 'Cannot get the database connection!');
`\t⚠ | Cannot get the database connection!\n\t\t(${err as Error}).`,
);
await interaction.reply({ await interaction.reply({
content: `${emoji.answer.error} | Cannot connect to the database`, content: `${emoji.answer.error} | Cannot connect to the database`,
flags: MessageFlags.Ephemeral, flags: MessageFlags.Ephemeral,
@ -108,9 +105,7 @@ export default {
}); });
} }
catch (err) { catch (err) {
console.error( log.error(err, `Error when adding ${target.username} to the owner list`);
`⚠️ | Error when adding ${target.username} to the owner list\n\t${err as Error}`,
);
await interaction.reply({ await interaction.reply({
content: `${emoji.answer.error} | Error when adding ${target.username} to the owner list`, content: `${emoji.answer.error} | Error when adding ${target.username} to the owner list`,
flags: MessageFlags.Ephemeral, flags: MessageFlags.Ephemeral,
@ -164,9 +159,7 @@ export default {
}); });
} }
catch (err) { catch (err) {
console.error( log.error(err, `Error when removing ${target.username} to the owner list`);
`⚠️ | Error when removing ${target.username} to the owner list\n\t${err as Error}`,
);
await interaction.reply({ await interaction.reply({
content: `${emoji.answer.error} | Cannot removing the user from the owner list`, content: `${emoji.answer.error} | Cannot removing the user from the owner list`,
flags: MessageFlags.Ephemeral, flags: MessageFlags.Ephemeral,
@ -211,7 +204,7 @@ export default {
return `- ${user.username} (\`${user.id}\`)\n`; return `- ${user.username} (\`${user.id}\`)\n`;
} }
catch (err) { catch (err) {
console.warn(`⚠️ | ${owner.id} : ${err as Error}`); log.warn(err, `Unable to fetch ${owner.id} user`);
return null; return null;
} }
}), }),
@ -230,9 +223,7 @@ export default {
}); });
} }
catch (err) { catch (err) {
console.error( log.error(err, 'Error when fetching infromation from the database');
`⚠️ | error when fetching infromation from the database: ${err as Error}`,
);
await interaction.reply({ await interaction.reply({
content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`, content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`,
flags: MessageFlags.Ephemeral, flags: MessageFlags.Ephemeral,

View file

@ -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 { SlashCommandBuilder } from '@discordjs/builders';
import { prisma } from '@lib/prisma'; import { prisma } from '@lib/prisma';
import emoji from '../../../assets/emoji.json' assert { type: 'json' }; import emoji from '../../../assets/emoji.json' assert { type: 'json' };
import { User as UserPrisma } from '@prisma/client'; import { User as UserPrisma } from '@prisma/client';
import { Guild as GuildPrisma } from '@prisma/client'; import { Guild as GuildPrisma } from '@prisma/client';
import { log } from '@lib/log';
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
@ -45,9 +46,7 @@ export default {
}); });
} }
catch (err) { catch (err) {
console.error( log.error(err, 'Cannot get the database connection!');
`\t⚠ | Whitelist => Cannot get the database connection!\n\t\t(${err as Error}).`,
);
await interaction.reply({ await interaction.reply({
content: `${emoji.answer.error} | Cannot connect to the database`, content: `${emoji.answer.error} | Cannot connect to the database`,
flags: MessageFlags.Ephemeral, flags: MessageFlags.Ephemeral,
@ -63,9 +62,7 @@ export default {
}); });
} }
catch (err) { catch (err) {
console.error( log.error(err, 'Cannot get the database connection!');
`\t⚠ | Cannot get the database connection!\n\t\t(${err as Error}).`,
);
await interaction.reply({ await interaction.reply({
content: `${emoji.answer.error} | Cannot connect to the database`, content: `${emoji.answer.error} | Cannot connect to the database`,
flags: MessageFlags.Ephemeral, flags: MessageFlags.Ephemeral,
@ -113,9 +110,7 @@ export default {
}); });
} }
catch (err) { catch (err) {
console.error( log.error(err, `Error when adding ${target.username} to the whitelist`);
`⚠️ | Error when adding ${target.username} to the whitelist\n\t${err as Error}`,
);
await interaction.reply({ await interaction.reply({
content: `${emoji.answer.error} | Error when adding ${target.username} to the whitelist`, content: `${emoji.answer.error} | Error when adding ${target.username} to the whitelist`,
flags: MessageFlags.Ephemeral, flags: MessageFlags.Ephemeral,
@ -173,9 +168,7 @@ export default {
}); });
} }
catch (err) { catch (err) {
console.error( log.error(err, `Error when removing ${target.username} to the username`);
`⚠️ | Error when removing ${target.username} to the username\n\t${err as Error}`,
);
await interaction.reply({ await interaction.reply({
content: `${emoji.answer.error} | Cannot remove ${target.username} from the whitelist`, content: `${emoji.answer.error} | Cannot remove ${target.username} from the whitelist`,
flags: MessageFlags.Ephemeral, flags: MessageFlags.Ephemeral,
@ -214,13 +207,13 @@ export default {
} }
const WlUsers = await Promise.all( const WlUsers = await Promise.all(
guild.WlUsers.map(async (whitelist) => { guild.WlUsers.map(async (whitelist: User) => {
try { try {
const user = await interaction.client.users.fetch(whitelist.id); const user = await interaction.client.users.fetch(whitelist.id);
return `- ${user.username} (\`${user.id}\`)\n`; return `- ${user.username} (\`${user.id}\`)\n`;
} }
catch (err) { catch (err) {
console.warn(`⚠️ | ${whitelist.id} : ${err as Error}`); log.warn(err, `Unable to fetch ${whitelist.id}`);
return null; return null;
} }
}), }),
@ -239,9 +232,7 @@ export default {
}); });
} }
catch (err) { catch (err) {
console.error( log.error(err, 'error when fetching infromation from the database');
`⚠️ | Whitelist => error when fetching infromation from the database: ${err as Error}`,
);
await interaction.reply({ await interaction.reply({
content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`, content: `${emoji.answer.error} | Cannot fetch the infromation of the database.`,
flags: MessageFlags.Ephemeral, flags: MessageFlags.Ephemeral,