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 { 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,

View file

@ -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,

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 { 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,