feat(commmands/rank): Update the whitelist command's permission check to use the isOwner function

This commit is contained in:
Raphael 2025-11-15 00:32:55 +01:00 committed by Raphaël
parent 31a29d2884
commit c016fbbb9f

View file

@ -2,9 +2,9 @@ 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 { Guild as GuildPrisma } from '@prisma/client'; import { Guild as GuildPrisma } from '@prisma/client';
import { log } from '@lib/log'; import { log } from '@lib/log';
import { isOwner } from '@lib/perm.js';
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
@ -37,22 +37,6 @@ export default {
), ),
async execute(interaction: CommandInteraction) { async execute(interaction: CommandInteraction) {
const subcommand = interaction.options.getSubcommand(); const subcommand = interaction.options.getSubcommand();
let userData: UserPrisma;
try {
userData = await prisma.user.findUnique({
where: {
id: interaction.user.id,
},
});
}
catch (err) {
log.error(err, 'Cannot get the database connection!');
await interaction.reply({
content: `${emoji.answer.error} | Cannot connect to the database`,
flags: MessageFlags.Ephemeral,
});
return;
}
let guildData: GuildPrisma; let guildData: GuildPrisma;
try { try {
guildData = await prisma.guild.findUnique({ guildData = await prisma.guild.findUnique({
@ -72,7 +56,7 @@ export default {
const target: GuildMember = interaction.options.getUser('target'); const target: GuildMember = interaction.options.getUser('target');
switch (subcommand) { switch (subcommand) {
case 'add': case 'add':
if (!userData.isOwner) { if (!await isOwner(interaction.user.id)) {
await interaction.reply({ await interaction.reply({
content: `${emoji.answer.no} | This command is only for owner`, content: `${emoji.answer.no} | This command is only for owner`,
flags: MessageFlags.Ephemeral, flags: MessageFlags.Ephemeral,
@ -123,7 +107,7 @@ export default {
}); });
return; return;
case 'delete': case 'delete':
if (!userData.isOwner) { if (!await isOwner(interaction.user.id)) {
await interaction.reply({ await interaction.reply({
content: `${emoji.answer.no} | This command is only for owner`, content: `${emoji.answer.no} | This command is only for owner`,
flags: MessageFlags.Ephemeral, flags: MessageFlags.Ephemeral,
@ -181,7 +165,7 @@ export default {
}); });
return; return;
case 'list': case 'list':
if (!userData.isOwner) { if (!await isOwner(interaction.user.id)) {
await interaction.reply({ await interaction.reply({
content: `${emoji.answer.no} | This command is only for owner`, content: `${emoji.answer.no} | This command is only for owner`,
flags: MessageFlags.Ephemeral, flags: MessageFlags.Ephemeral,