refactor(commands/adminstration): now using the new log system
This commit is contained in:
parent
491feedfaf
commit
5db4a7939d
4 changed files with 13 additions and 23 deletions
|
|
@ -8,6 +8,7 @@ import {
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
|
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
|
||||||
import { prisma } from '@lib/prisma';
|
import { prisma } from '@lib/prisma';
|
||||||
|
import { log } from '@lib/log';
|
||||||
import { User as UserPrisma } from '@prisma/client';
|
import { User as UserPrisma } from '@prisma/client';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
@ -30,13 +31,7 @@ export default {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (err: unknown) {
|
catch (err: unknown) {
|
||||||
if (err instanceof Error) {
|
log.error(err, 'Cannot get user data');
|
||||||
console.error(`❌ ${err.name}: ${err.message}`);
|
|
||||||
console.error(err.stack);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.error('❌ Unknown error:', err);
|
|
||||||
}
|
|
||||||
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,
|
||||||
|
|
@ -81,10 +76,7 @@ export default {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (err: unknown) {
|
catch (err: unknown) {
|
||||||
const errorMessage = err instanceof Error ? err.message : String(err);
|
log.error(err, 'Cannot delete category or its channels');
|
||||||
console.error(
|
|
||||||
`Cannot delete category or its channels:\n\t${errorMessage}`,
|
|
||||||
);
|
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: `${emoji.answer.error} | Failed to delete the category or its channels.`,
|
content: `${emoji.answer.error} | Failed to delete the category or its channels.`,
|
||||||
flags: MessageFlags.Ephemeral,
|
flags: MessageFlags.Ephemeral,
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import {
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
|
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
|
||||||
import { Guild, User } from '@prisma/client';
|
import { Guild, User } from '@prisma/client';
|
||||||
|
import { log } from '@lib/log';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
|
|
@ -62,10 +63,7 @@ export default {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (err: unknown) {
|
catch (err: unknown) {
|
||||||
const errorMessage = err instanceof Error ? err.message : String(err);
|
log.error(err, 'Cannot get the database connection');
|
||||||
console.error(
|
|
||||||
`\t⚠️ | Cannot get the database connection!\n\t\t(${errorMessage}).`,
|
|
||||||
);
|
|
||||||
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,
|
||||||
|
|
@ -367,15 +365,11 @@ export default {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (err: unknown) {
|
catch (err: unknown) {
|
||||||
const errorMessage =
|
|
||||||
err instanceof Error ? err.message : (err as string);
|
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: `${emoji.answer.error} | Cannot suppress the category's channels`,
|
content: `${emoji.answer.error} | Cannot suppress the category's channels`,
|
||||||
flags: MessageFlags.Ephemeral,
|
flags: MessageFlags.Ephemeral,
|
||||||
});
|
});
|
||||||
console.error(
|
log.error(err, 'Cannot suppress the category\'s channels');
|
||||||
`Cannot suppress the category's channel:\n\t${errorMessage}`,
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await prisma.guild.update({
|
await prisma.guild.update({
|
||||||
|
|
@ -396,7 +390,7 @@ export default {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
console.error(`no choice on logs command ${choice}`);
|
log.error(new Error(`no choice on logs command ${choice}`), 'Invalid logs command choice');
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: `${emoji.answer.error} | Invalid choice`,
|
content: `${emoji.answer.error} | Invalid choice`,
|
||||||
flags: MessageFlags.Ephemeral,
|
flags: MessageFlags.Ephemeral,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
import { ButtonBuilder, ActionRowBuilder, SlashCommandBuilder } from '@discordjs/builders';
|
import {
|
||||||
|
ButtonBuilder,
|
||||||
|
ActionRowBuilder,
|
||||||
|
SlashCommandBuilder,
|
||||||
|
} from '@discordjs/builders';
|
||||||
import {
|
import {
|
||||||
StringSelectMenuBuilder,
|
StringSelectMenuBuilder,
|
||||||
ButtonStyle,
|
ButtonStyle,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue