60 lines
2.6 KiB
TypeScript
60 lines
2.6 KiB
TypeScript
// External Imports
|
|
import { Command, CommandBuilder, CommandClient, CommandInteraction, Constants, SlashCommand } from 'athena-prime';
|
|
|
|
// Internal Imports
|
|
import { Database } from '../../shared/Database';
|
|
import { CreateDefaultEmbed, SetSeverity } from '../../utils';
|
|
|
|
// ---------------
|
|
|
|
@SlashCommand(
|
|
new CommandBuilder('ban', 'Ban a user, optionally cleanup 1 day worth of messages.')
|
|
.setIntegrationTypes(Constants.ApplicationIntegrationType.GuildInstall)
|
|
.setContexts(Constants.InteractionContextType.Guild)
|
|
.setCommandType(Constants.ApplicationCommandType.ChatInput)
|
|
.setMemberPermission(Constants.PermissionFlagsBits.BanMembers)
|
|
.addUserOption('user', 'The user to ban.', true)
|
|
.addStringOption({ name: 'duration', description: '(optional): The duration of the ban. Formatted as 7d12h30m30s.', required: false })
|
|
.addStringOption({ name: 'reason', description: '(optional): The reason for banning the user.', required: false })
|
|
.addBooleanOption('clean', "(optional): Clean the user's messages upwards of a day.", false)
|
|
.addBooleanOption('purge', "(optional): Purge the user's messages from the database.", false)
|
|
)
|
|
class BanCommand extends Command<CommandClient> {
|
|
cooldown = 5;
|
|
userPermissions = [Constants.PermissionFlagsBits.BanMembers];
|
|
|
|
async handleCommand(context: CommandClient<any, any>, interaction: CommandInteraction, data: any) {
|
|
if (!interaction.inGuild()) return;
|
|
await interaction.defer();
|
|
|
|
const user = interaction.getRequiredMember('user');
|
|
const duration = interaction.getString('duration');
|
|
const reason = interaction.getString('reason') || 'No reason specified.';
|
|
const clean = interaction.getBoolean('clean') || false;
|
|
const purge = interaction.getBoolean('purge') || false;
|
|
|
|
// Nix -> Tarrgon: Could you pretty please hook up the database for this 🥺
|
|
|
|
await context.banGuildMember(interaction.guild.id, user.id, clean ? 1 : undefined, reason);
|
|
if (purge) await Database.purgeMessagesFrom(user.id);
|
|
|
|
interaction.createMessage({
|
|
embeds: [{
|
|
...CreateDefaultEmbed(context),
|
|
...SetSeverity('success'),
|
|
|
|
description: 'Executed ban action.',
|
|
|
|
fields: [
|
|
{ name: 'User', value: `${user.username} (${user.mention})`, inline: false },
|
|
{ name: 'Duration', value: `${duration || 'Permanent'}`, inline: false },
|
|
{ name: 'Reason', value: `${user.username} (${user.mention})`, inline: false },
|
|
{ name: 'Clean', value: `${clean ? 'Yes' : 'No'}`, inline: true },
|
|
{ name: 'Purge', value: `${purge ? 'Yes' : 'No'}`, inline: true },
|
|
]
|
|
}]
|
|
});
|
|
}
|
|
}
|
|
|
|
export default new BanCommand('ban'); |