feat(commmands/custom): Update the set command's permission check to use the isOwner function
This commit is contained in:
parent
dde23bf13a
commit
9e6a4a0993
1 changed files with 16 additions and 28 deletions
|
|
@ -7,7 +7,6 @@ import {
|
||||||
CommandInteraction,
|
CommandInteraction,
|
||||||
} 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 { User as UserPrisma } from '@prisma/client';
|
|
||||||
import { log } from '@lib/log.js';
|
import { log } from '@lib/log.js';
|
||||||
import { color as colorLib } from '@lib/color';
|
import { color as colorLib } from '@lib/color';
|
||||||
import { isBuyer, isOwner } from '@lib/perm.js';
|
import { isBuyer, isOwner } from '@lib/perm.js';
|
||||||
|
|
@ -113,39 +112,28 @@ export default {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
async execute(interaction: CommandInteraction) {
|
async execute(interaction: CommandInteraction) {
|
||||||
let userData: UserPrisma | null;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
const subcommand: string = interaction.options.getSubcommand();
|
const subcommand: string = interaction.options.getSubcommand();
|
||||||
switch (subcommand) {
|
switch (subcommand) {
|
||||||
case 'color': {
|
case 'color': {
|
||||||
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,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const newColor: string = interaction.options.getString('color');
|
let newColor: string = interaction.options.getString('color');
|
||||||
if (!/^#[0-9A-Fa-f]{6}$/.test(newColor)) {
|
if (!/^[0-9A-Fa-f]{6}$/.test(newColor)) {
|
||||||
await interaction.reply({
|
if (!/^#[0-9A-Fa-f]{6}$/.test(newColor)) {
|
||||||
content: `${emoji.answer.no} | You have to give a color with the syntax: \`#000000\`.`,
|
await interaction.reply({
|
||||||
flags: MessageFlags.Ephemeral,
|
content: `${emoji.answer.no} | You have to give a color with the syntax: \`(#)000000\`.`,
|
||||||
});
|
flags: MessageFlags.Ephemeral,
|
||||||
return;
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newColor = newColor.replace('#', '');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await prisma.guild.upsert({
|
await prisma.guild.upsert({
|
||||||
where: {
|
where: {
|
||||||
|
|
@ -166,7 +154,7 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case 'footer': {
|
case 'footer': {
|
||||||
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,
|
||||||
|
|
@ -200,7 +188,7 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case 'pp': {
|
case 'pp': {
|
||||||
if (!userData.isBuyer) {
|
if (!await isBuyer(interaction.user.id)) {
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: `${emoji.answer.no} | This command is only for buyer`,
|
content: `${emoji.answer.no} | This command is only for buyer`,
|
||||||
flags: MessageFlags.Ephemeral,
|
flags: MessageFlags.Ephemeral,
|
||||||
|
|
@ -225,7 +213,7 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case 'status': {
|
case 'status': {
|
||||||
if (!userData.isBuyer) {
|
if (!await isBuyer(interaction.user.id)) {
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: `${emoji.answer.no} | This command is only for buyer`,
|
content: `${emoji.answer.no} | This command is only for buyer`,
|
||||||
flags: MessageFlags.Ephemeral,
|
flags: MessageFlags.Ephemeral,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue