diff --git a/src/cmds/message-filter/index.ts b/src/cmds/message-filter/index.ts index d7f4cf4..3bebd14 100644 --- a/src/cmds/message-filter/index.ts +++ b/src/cmds/message-filter/index.ts @@ -14,6 +14,10 @@ const collections = guilds.view( ); const exemptions = guilds.view>('messageFilter.exemptions', raw => raw.map(deserializeExemption)); +function isEnabled(guildId: Snowflake) { + return guilds.get(guildId, 'messageFilter.enabled', v => v, true); +} + function buildEmbed (message: string, color?: ColorResolvable): EmbedBuilder { const embed = new EmbedBuilder() .setTitle('Message Filter') @@ -57,6 +61,10 @@ async function filter (client: Client, message: Message | PartialMessage): Promi return; } + if (!isEnabled(message.guildId)) { + return; + } + const filterCollection = collections.get(message.guildId); if (filterCollection === null || filterCollection.forbidden.length === 0) { return; @@ -297,6 +305,26 @@ export default { command: new ComplexCommand( 'message-filter', { + async state (client: Client, interaction: ChatInputCommandInteraction<'cached'>) { + const currentState = isEnabled(interaction.guildId); + + if (currentState) { + await interaction.reply({ embeds: [buildEmbed('Message filtering is currently enabled for this server!')] }); + } else { + await interaction.reply({ embeds: [buildEmbed('Message filtering is currently disabled for this server!')] }); + } + }, + async toggle (client: Client, interaction: ChatInputCommandInteraction<'cached'>) { + const currentState = isEnabled(interaction.guildId); + const newState = !currentState; + guilds.set(interaction.guildId, 'messageFilter.enabled', newState); + + if (newState) { + await interaction.reply({ embeds: [buildEmbed('Message filtering is now enabled for this server!')] }); + } else { + await interaction.reply({ embeds: [buildEmbed('Message filtering is now disabled for this server!')] }); + } + }, forbidden: buildFilterManagement('forbidden'), allowed: buildFilterManagement('allowed'), exemptions: { diff --git a/src/deploy.ts b/src/deploy.ts index 704c9a8..059ca70 100644 --- a/src/deploy.ts +++ b/src/deploy.ts @@ -204,6 +204,16 @@ const cmds: ApplicationCommandDataResolvable[] = [ defaultMemberPermissions: PermissionFlagsBits.ManageMessages, description: 'Manage message filters for this server', options: [ + { + type: ApplicationCommandOptionType.Subcommand, + name: 'state', + description: 'Check the state of message filtering for current server', + }, + { + type: ApplicationCommandOptionType.Subcommand, + name: 'toggle', + description: 'En- or disable message filtering for current server', + }, { type: ApplicationCommandOptionType.SubcommandGroup, name: 'forbidden',