feat(commmands/administration): Update the deletecat command's permission check to use the isOwner function
This commit is contained in:
parent
e1abcd5b24
commit
0c081a7ace
1 changed files with 4 additions and 21 deletions
|
|
@ -3,13 +3,11 @@ import {
|
||||||
MessageFlags,
|
MessageFlags,
|
||||||
ChannelType,
|
ChannelType,
|
||||||
ChatInputCommandInteraction,
|
ChatInputCommandInteraction,
|
||||||
type SlashCommandChannelOption,
|
|
||||||
CategoryChannel,
|
CategoryChannel,
|
||||||
} 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 { log } from '@lib/log';
|
import { log } from '@lib/log';
|
||||||
import { User as UserPrisma } from '@prisma/client';
|
import { isOwner } from '@lib/perm.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
|
|
@ -24,22 +22,7 @@ export default {
|
||||||
),
|
),
|
||||||
|
|
||||||
async execute(interaction: ChatInputCommandInteraction) {
|
async execute(interaction: ChatInputCommandInteraction) {
|
||||||
let userData: UserPrisma | null = null;
|
if (!await isOwner(interaction.user.id)) {
|
||||||
try {
|
|
||||||
userData = await prisma.user.findUnique({
|
|
||||||
where: { id: interaction.user.id },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (err: unknown) {
|
|
||||||
log.error(err, 'Cannot get user data');
|
|
||||||
await interaction.reply({
|
|
||||||
content: `${emoji.answer.error} | Cannot connect to the database`,
|
|
||||||
flags: MessageFlags.Ephemeral,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!userData?.isOwner) {
|
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: `${emoji.answer.no} | This command is only for owners`,
|
content: `${emoji.answer.no} | This command is only for owners`,
|
||||||
flags: MessageFlags.Ephemeral,
|
flags: MessageFlags.Ephemeral,
|
||||||
|
|
@ -47,9 +30,9 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const categoryOption = interaction.options.getChannel('category', true);
|
const categoryOption: CategoryChannel | null = interaction.options.getChannel('category', true);
|
||||||
|
|
||||||
if (categoryOption.type !== ChannelType.GuildCategory) {
|
if (!(categoryOption instanceof CategoryChannel)) {
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: `${emoji.answer.no} | Please choose a valid category.`,
|
content: `${emoji.answer.no} | Please choose a valid category.`,
|
||||||
flags: MessageFlags.Ephemeral,
|
flags: MessageFlags.Ephemeral,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue