mirror of
https://github.com/ahmadk953/poixpixel-discord-bot.git
synced 2025-05-14 12:43:05 +00:00
chore: improve safety of commands
This commit is contained in:
parent
83bbf7b098
commit
7c2a99daf5
28 changed files with 329 additions and 235 deletions
|
@ -148,8 +148,9 @@ const command = {
|
|||
),
|
||||
|
||||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
await interaction.deferReply();
|
||||
if (!interaction.isChatInputCommand() || !interaction.guild) return;
|
||||
|
||||
await interaction.deferReply();
|
||||
const subcommand = interaction.options.getSubcommand();
|
||||
|
||||
switch (subcommand) {
|
||||
|
|
|
@ -33,8 +33,9 @@ const command: SubcommandCommand = {
|
|||
),
|
||||
|
||||
execute: async (interaction) => {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
if (!interaction.isChatInputCommand() || !interaction.guild) return;
|
||||
|
||||
await interaction.deferReply();
|
||||
const subcommand = interaction.options.getSubcommand();
|
||||
|
||||
if (subcommand === 'status') {
|
||||
|
@ -82,33 +83,30 @@ const command: SubcommandCommand = {
|
|||
});
|
||||
}
|
||||
|
||||
await interaction.reply({ embeds: [embed] });
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
} else if (subcommand === 'setcount') {
|
||||
if (
|
||||
!interaction.memberPermissions?.has(
|
||||
PermissionsBitField.Flags.Administrator,
|
||||
)
|
||||
) {
|
||||
await interaction.reply({
|
||||
await interaction.editReply({
|
||||
content: 'You need administrator permissions to use this command.',
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const count = interaction.options.getInteger('count');
|
||||
if (count === null) {
|
||||
await interaction.reply({
|
||||
await interaction.editReply({
|
||||
content: 'Invalid count specified.',
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await setCount(count);
|
||||
await interaction.reply({
|
||||
await interaction.editReply({
|
||||
content: `Count has been set to **${count}**. The next number should be **${count + 1}**.`,
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
|
@ -74,12 +74,11 @@ const command: SubcommandCommand = {
|
|||
),
|
||||
|
||||
execute: async (interaction) => {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
if (!interaction.isChatInputCommand() || !interaction.guild) return;
|
||||
|
||||
await interaction.deferReply({
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
await interaction.editReply('Processing...');
|
||||
|
||||
const config = loadConfig();
|
||||
const subcommand = interaction.options.getSubcommand();
|
||||
|
@ -100,7 +99,7 @@ const command: SubcommandCommand = {
|
|||
});
|
||||
|
||||
if (!isAdmin) {
|
||||
const approvalChannel = interaction.guild?.channels.cache.get(
|
||||
const approvalChannel = interaction.guild.channels.cache.get(
|
||||
config.channels.factApproval,
|
||||
);
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import {
|
|||
builder,
|
||||
} from '@/util/giveaways/giveawayManager.js';
|
||||
import { createPaginationButtons } from '@/util/helpers.js';
|
||||
import { loadConfig } from '@/util/configLoader';
|
||||
|
||||
const command: SubcommandCommand = {
|
||||
data: new SlashCommandBuilder()
|
||||
|
@ -53,16 +54,30 @@ const command: SubcommandCommand = {
|
|||
),
|
||||
|
||||
execute: async (interaction) => {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
if (!interaction.isChatInputCommand() || !interaction.guild) return;
|
||||
|
||||
const config = loadConfig();
|
||||
const communityManagerRoleId = config.roles.staffRoles.find(
|
||||
(role) => role.name === 'Community Manager',
|
||||
)?.roleId;
|
||||
|
||||
if (!communityManagerRoleId) {
|
||||
await interaction.reply({
|
||||
content:
|
||||
'Community Manager role not found in the configuration. Please contact a server admin.',
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!interaction.memberPermissions?.has(
|
||||
PermissionsBitField.Flags.ModerateMembers,
|
||||
)
|
||||
!interaction.guild.members.cache
|
||||
.find((member) => member.id === interaction.user.id)
|
||||
?.roles.cache.has(communityManagerRoleId)
|
||||
) {
|
||||
await interaction.reply({
|
||||
content: 'You do not have permission to manage giveaways.',
|
||||
ephemeral: true,
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
@ -152,7 +167,7 @@ async function handleListGiveaways(interaction: ChatInputCommandInteraction) {
|
|||
if (i.user.id !== interaction.user.id) {
|
||||
await i.reply({
|
||||
content: 'You cannot use these buttons.',
|
||||
ephemeral: true,
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -22,13 +22,12 @@ const command: OptionsCommand = {
|
|||
.setRequired(false),
|
||||
),
|
||||
execute: async (interaction) => {
|
||||
if (!interaction.guild) return;
|
||||
if (!interaction.isChatInputCommand() || !interaction.guild) return;
|
||||
|
||||
await interaction.deferReply();
|
||||
|
||||
try {
|
||||
const usersPerPage =
|
||||
(interaction.options.get('limit')?.value as number) || 10;
|
||||
const usersPerPage = interaction.options.getInteger('limit') || 10;
|
||||
|
||||
const allUsers = await getLevelLeaderboard(100);
|
||||
|
||||
|
|
|
@ -15,18 +15,16 @@ const command: OptionsCommand = {
|
|||
.setRequired(false),
|
||||
),
|
||||
execute: async (interaction) => {
|
||||
const member = await interaction.guild?.members.fetch(
|
||||
(interaction.options.get('user')?.value as string) || interaction.user.id,
|
||||
);
|
||||
|
||||
if (!member) {
|
||||
await interaction.reply('User not found in this server.');
|
||||
return;
|
||||
}
|
||||
if (!interaction.isChatInputCommand() || !interaction.guild) return;
|
||||
|
||||
await interaction.deferReply();
|
||||
|
||||
try {
|
||||
const member = await interaction.guild.members.fetch(
|
||||
(interaction.options.get('user')?.value as string) ||
|
||||
interaction.user.id,
|
||||
);
|
||||
|
||||
const userData = await getUserLevel(member.id);
|
||||
const rankCard = await generateRankCard(member, userData);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue