Add message purging
This commit is contained in:
@@ -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.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -173,7 +173,7 @@ export class Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async purgeMessagesFrom(id: string) {
|
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
|
//#endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user