mirror of
https://github.com/ahmadk953/poixpixel-discord-bot.git
synced 2025-05-11 11:13: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
|
@ -14,12 +14,15 @@ const command: Command = {
|
|||
.setDescription('(Admin Only) Display the current configuration')
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||
execute: async (interaction) => {
|
||||
if (!interaction.isChatInputCommand() || !interaction.guild) return;
|
||||
|
||||
await interaction.deferReply({ flags: ['Ephemeral'] });
|
||||
|
||||
if (
|
||||
!interaction.memberPermissions?.has(PermissionFlagsBits.Administrator)
|
||||
) {
|
||||
await interaction.reply({
|
||||
await interaction.editReply({
|
||||
content: 'You do not have permission to use this command.',
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
@ -180,10 +183,9 @@ const command: Command = {
|
|||
? [createPaginationButtons(pages.length, currentPage)]
|
||||
: [];
|
||||
|
||||
const reply = await interaction.reply({
|
||||
const reply = await interaction.editReply({
|
||||
embeds: [pages[currentPage]],
|
||||
components,
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
|
||||
if (pages.length <= 1) return;
|
||||
|
|
|
@ -26,9 +26,11 @@ const command: OptionsCommand = {
|
|||
),
|
||||
|
||||
execute: async (interaction) => {
|
||||
try {
|
||||
await interaction.deferReply();
|
||||
if (!interaction.isChatInputCommand() || !interaction.guild) return;
|
||||
|
||||
await interaction.deferReply();
|
||||
|
||||
try {
|
||||
const client = interaction.client as ExtendedClient;
|
||||
const commandName = interaction.options.getString('command');
|
||||
|
||||
|
@ -178,7 +180,7 @@ async function handleSpecificCommand(
|
|||
const cmd = client.commands.get(commandName);
|
||||
|
||||
if (!cmd) {
|
||||
return interaction.reply({
|
||||
return interaction.editReply({
|
||||
content: `Command \`${commandName}\` not found.`,
|
||||
ephemeral: true,
|
||||
});
|
||||
|
@ -227,7 +229,7 @@ async function handleSpecificCommand(
|
|||
inline: false,
|
||||
});
|
||||
|
||||
return interaction.reply({ embeds: [embed] });
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,10 @@ const command: Command = {
|
|||
.setName('members')
|
||||
.setDescription('Lists all non-bot members of the server'),
|
||||
execute: async (interaction) => {
|
||||
if (!interaction.isChatInputCommand() || !interaction.guild) return;
|
||||
|
||||
await interaction.deferReply();
|
||||
|
||||
let members = await getAllMembers();
|
||||
members = members.sort((a, b) =>
|
||||
(a.discordUsername ?? '').localeCompare(b.discordUsername ?? ''),
|
||||
|
@ -63,7 +67,7 @@ const command: Command = {
|
|||
const components =
|
||||
pages.length > 1 ? [getButtonActionRow(), getSelectMenuRow()] : [];
|
||||
|
||||
await interaction.reply({
|
||||
await interaction.editReply({
|
||||
embeds: [pages[currentPage]],
|
||||
components,
|
||||
});
|
||||
|
|
|
@ -8,7 +8,7 @@ const command: Command = {
|
|||
.setDescription('Check the latency from you to the bot'),
|
||||
execute: async (interaction) => {
|
||||
await interaction.reply(
|
||||
`Pong! Latency: ${Date.now() - interaction.createdTimestamp}ms`,
|
||||
`🏓 Pong! Latency: ${Date.now() - interaction.createdTimestamp}ms`,
|
||||
);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -8,21 +8,22 @@ const command: Command = {
|
|||
.setName('recalculatelevels')
|
||||
.setDescription('(Admin Only) Recalculate all user levels'),
|
||||
execute: async (interaction) => {
|
||||
if (!interaction.isChatInputCommand() || !interaction.guild) return;
|
||||
|
||||
await interaction.deferReply({ flags: ['Ephemeral'] });
|
||||
await interaction.editReply('Recalculating levels...');
|
||||
|
||||
if (
|
||||
!interaction.memberPermissions?.has(
|
||||
PermissionsBitField.Flags.Administrator,
|
||||
)
|
||||
) {
|
||||
await interaction.reply({
|
||||
await interaction.editReply({
|
||||
content: 'You do not have permission to use this command.',
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await interaction.deferReply();
|
||||
await interaction.editReply('Recalculating levels...');
|
||||
|
||||
try {
|
||||
await recalculateUserLevels();
|
||||
await interaction.editReply('Levels recalculated successfully!');
|
||||
|
|
|
@ -36,7 +36,9 @@ const command: SubcommandCommand = {
|
|||
),
|
||||
|
||||
execute: async (interaction) => {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
if (!interaction.isChatInputCommand() || !interaction.guild) return;
|
||||
|
||||
await interaction.deferReply({ flags: ['Ephemeral'] });
|
||||
|
||||
const config = loadConfig();
|
||||
const managerRoleId = config.roles.staffRoles.find(
|
||||
|
@ -52,18 +54,15 @@ const command: SubcommandCommand = {
|
|||
PermissionsBitField.Flags.Administrator,
|
||||
)
|
||||
) {
|
||||
await interaction.reply({
|
||||
await interaction.editReply({
|
||||
content:
|
||||
'You do not have permission to use this command. This command is restricted to users with the Manager role.',
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const subcommand = interaction.options.getSubcommand();
|
||||
|
||||
await interaction.deferReply({ flags: ['Ephemeral'] });
|
||||
|
||||
try {
|
||||
if (subcommand === 'database') {
|
||||
await handleDatabaseReconnect(interaction);
|
||||
|
|
|
@ -18,6 +18,10 @@ const command: Command = {
|
|||
.setName('restart')
|
||||
.setDescription('(Manager Only) Restart the bot'),
|
||||
execute: async (interaction) => {
|
||||
if (!interaction.isChatInputCommand() || !interaction.guild) return;
|
||||
|
||||
await interaction.deferReply({ flags: ['Ephemeral'] });
|
||||
|
||||
const config = loadConfig();
|
||||
const managerRoleId = config.roles.staffRoles.find(
|
||||
(role) => role.name === 'Manager',
|
||||
|
@ -32,17 +36,15 @@ const command: Command = {
|
|||
PermissionsBitField.Flags.Administrator,
|
||||
)
|
||||
) {
|
||||
await interaction.reply({
|
||||
await interaction.editReply({
|
||||
content:
|
||||
'You do not have permission to restart the bot. This command is restricted to users with the Manager role.',
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await interaction.reply({
|
||||
await interaction.editReply({
|
||||
content: 'Restarting the bot... This may take a few moments.',
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
|
||||
const dbConnected = await ensureDatabaseConnection();
|
||||
|
|
|
@ -7,8 +7,10 @@ const command: Command = {
|
|||
.setName('server')
|
||||
.setDescription('Provides information about the server.'),
|
||||
execute: async (interaction) => {
|
||||
if (!interaction.isChatInputCommand() || !interaction.guild) return;
|
||||
|
||||
await interaction.reply(
|
||||
`The server **${interaction!.guild!.name}** has **${interaction!.guild!.memberCount}** members and was created on **${interaction!.guild!.createdAt}**. It is **${new Date().getFullYear() - interaction!.guild!.createdAt.getFullYear()!}** years old.`,
|
||||
`The server **${interaction.guild.name}** has **${interaction.guild.memberCount}** members and was created on **${interaction.guild.createdAt}**. It is **${new Date().getFullYear() - interaction.guild.createdAt.getFullYear()}** years old.`,
|
||||
);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -19,13 +19,17 @@ const command: OptionsCommand = {
|
|||
.setRequired(true),
|
||||
),
|
||||
execute: async (interaction) => {
|
||||
if (!interaction.isChatInputCommand() || !interaction.guild) return;
|
||||
|
||||
await interaction.deferReply();
|
||||
|
||||
const userOption = interaction.options.get(
|
||||
'user',
|
||||
) as unknown as GuildMember;
|
||||
const user = userOption.user;
|
||||
|
||||
if (!userOption || !user) {
|
||||
await interaction.reply('User not found');
|
||||
await interaction.editReply('User not found');
|
||||
return;
|
||||
}
|
||||
if (
|
||||
|
@ -33,7 +37,7 @@ const command: OptionsCommand = {
|
|||
PermissionsBitField.Flags.ModerateMembers,
|
||||
)
|
||||
) {
|
||||
await interaction.reply(
|
||||
await interaction.editReply(
|
||||
'You do not have permission to view member information.',
|
||||
);
|
||||
return;
|
||||
|
@ -140,7 +144,7 @@ const command: OptionsCommand = {
|
|||
iconURL: interaction.user.displayAvatarURL(),
|
||||
});
|
||||
|
||||
await interaction.reply({ embeds: [embed] });
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -71,12 +71,16 @@ const command: SubcommandCommand = {
|
|||
),
|
||||
),
|
||||
execute: async (interaction) => {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
if (!interaction.isChatInputCommand() || !interaction.guild) return;
|
||||
|
||||
const commandUser = interaction.guild?.members.cache.get(
|
||||
const commandUser = interaction.guild.members.cache.get(
|
||||
interaction.user.id,
|
||||
);
|
||||
|
||||
await interaction.deferReply({
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
|
||||
const config = loadConfig();
|
||||
const managerRoleId = config.roles.staffRoles.find(
|
||||
(role) => role.name === 'Manager',
|
||||
|
@ -87,18 +91,12 @@ const command: SubcommandCommand = {
|
|||
!managerRoleId ||
|
||||
commandUser.roles.highest.comparePositionTo(managerRoleId) < 0
|
||||
) {
|
||||
await interaction.reply({
|
||||
await interaction.editReply({
|
||||
content: 'You do not have permission to use this command',
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await interaction.deferReply({
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
await interaction.editReply('Processing...');
|
||||
|
||||
const subcommand = interaction.options.getSubcommand();
|
||||
const user = interaction.options.getUser('user', true);
|
||||
const amount = interaction.options.getInteger('amount', false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue