diff --git a/src/commands/admin/database.ts b/src/commands/admin/database.ts new file mode 100644 index 0000000..9c8f9de --- /dev/null +++ b/src/commands/admin/database.ts @@ -0,0 +1,49 @@ +// 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('database', "Essential database functions. THESE ARE POTENTIALLY DESTRUCTIVE ACTIONS, BE SURE!") + .setIntegrationTypes(Constants.ApplicationIntegrationType.GuildInstall) + .setContexts(Constants.InteractionContextType.Guild) + .setCommandType(Constants.ApplicationCommandType.ChatInput) + .setMemberPermission(Constants.PermissionFlagsBits.Administrator) + + .addSubcommand('purge-user', 'Purge user messages from the database.', builder => + builder.addUserOption('user', 'The user to purge.', true) + ) +) +class DatabaseCommand extends Command { + cooldown = 60; + userPermissions = [Constants.PermissionFlagsBits.Administrator]; + + async handleCommand(context: CommandClient, interaction: CommandInteraction, data: any) { + if (!interaction.inGuild() || !interaction.subcommand) return; + + await interaction.defer(); + + switch (interaction.subcommand.at(0)) { + case 'purge-user': + const user = interaction.getRequiredMember('user'); + await Database.purgeMessagesFrom(user.id); + + await interaction.createMessage({ + embeds: [{ + ...CreateDefaultEmbed(context), + ...SetSeverity('success'), + + description: `Executed user-purge on ${user.mention}.` + }] + }); + + return; + } + } +} + +export default new DatabaseCommand('database'); \ No newline at end of file diff --git a/src/commands/admin/rename-channel.ts b/src/commands/admin/rename-channel.ts index ef92e35..c397421 100644 --- a/src/commands/admin/rename-channel.ts +++ b/src/commands/admin/rename-channel.ts @@ -8,12 +8,12 @@ import { CreateDefaultEmbed, SetSeverity } from '../../utils'; // --------------- @SlashCommand( - new CommandBuilder('rename-channel', 'Rename the general channel.') + new CommandBuilder('rename-general', 'Rename the general channel.') .setIntegrationTypes(Constants.ApplicationIntegrationType.GuildInstall) .setContexts(Constants.InteractionContextType.Guild) .setCommandType(Constants.ApplicationCommandType.ChatInput) .setMemberPermission(Constants.PermissionFlagsBits.ManageChannels) - .addStringOption({ name: 'name', description: 'The new general chat name.', required: true, max_length: 32 }) + .addStringOption({ name: 'name', description: 'The new general chat name.', required: true, max_length: 64 }) ) class RenameGeneralCommand extends Command { cooldown = 360; @@ -21,7 +21,7 @@ class RenameGeneralCommand extends Command { async handleCommand(context: CommandClient, interaction: CommandInteraction, data: any) { if (!interaction.inGuild()) return; - interaction.defer(); + await interaction.defer(); const settings = await Database.GetOrCreateSettings(interaction.guild.id); if (!settings.general_chat_id) { @@ -65,4 +65,4 @@ class RenameGeneralCommand extends Command { } } -export default new RenameGeneralCommand('name-sync'); \ No newline at end of file +export default new RenameGeneralCommand('rename-general'); \ No newline at end of file diff --git a/src/commands/database.ts b/src/commands/database.ts deleted file mode 100644 index ebf8e76..0000000 --- a/src/commands/database.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { ApplicationIntegrationType, ChatInputCommandInteraction, Client, InteractionContextType, MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js'; -import { Database } from '../shared/Database'; -import { getIdFromInput } from '../utils'; - -export default { - name: 'database', - data: new SlashCommandBuilder() - .setName('database') - .setDescription('Database access.') - .setIntegrationTypes(ApplicationIntegrationType.GuildInstall) - .setContexts(InteractionContextType.Guild) - .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild) - .addSubcommandGroup(subcommandGroup => - subcommandGroup - .setName('messages') - .setDescription('Access to messages in the database.') - .addSubcommand(subcommand => - subcommand - .setName('purge') - .setDescription("Purge a user's messages from the database.") - .addStringOption(option => - option - .setName('user') - .setDescription('The discord user id, or mention, of the user.') - .setRequired(true) - ) - ) - ), - handler: async function (client: Client, interaction: ChatInputCommandInteraction) { - await interaction.deferReply({ flags: [MessageFlags.Ephemeral] }); - - const group = interaction.options.getSubcommandGroup(true); - - const subcommand = interaction.options.getSubcommand(true); - - if (group == 'messages') { - if (subcommand == 'purge') { - const discordUserInput = interaction.options.getString('discord-user', true); - - const idToUse = getIdFromInput(discordUserInput); - - await Database.purgeMessagesFrom(idToUse); - - return interaction.editReply('Messages purged.'); - } - } - } -}; \ No newline at end of file