Add message purging

This commit is contained in:
Tarrgon
2026-07-06 21:51:00 -04:00
parent c4a02a23e0
commit f32e2292ea
2 changed files with 49 additions and 1 deletions
+48
View File
@@ -0,0 +1,48 @@
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.');
}
}
}
};
+1 -1
View File
@@ -173,7 +173,7 @@ export class Database {
}
static async purgeMessagesFrom(id: string) {
await Database.db.run('DELETE from messages WHERE ');
await Database.db.run('DELETE from messages WHERE author_id_hash = ?', Encrypter.hash(id));
}
//#endregion