diff --git a/package.json b/package.json index 1020e82d1..7cc4fd3f3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bastion", - "version": "10.11.0", + "version": "10.11.1", "description": "Get an enhanced Discord experience!", "type": "module", "homepage": "https://bastion.traction.one", diff --git a/src/commands/config/filter/invites.ts b/src/commands/config/filter/invites.ts index 8ff0a8623..8349d08f2 100644 --- a/src/commands/config/filter/invites.ts +++ b/src/commands/config/filter/invites.ts @@ -2,7 +2,7 @@ * @author TRACTION (iamtraction) * @copyright 2023 */ -import { AutoModerationActionType, AutoModerationRuleEventType, AutoModerationRuleTriggerType, ChatInputCommandInteraction, PermissionFlagsBits } from "discord.js"; +import { AutoModerationActionOptions, AutoModerationActionType, AutoModerationRuleEventType, AutoModerationRuleTriggerType, ChatInputCommandInteraction, PermissionFlagsBits } from "discord.js"; import { Command, Logger } from "@bastion/tesseract"; import GuildModel from "../../../models/Guild.js"; @@ -35,6 +35,30 @@ class FilterInvitesCommand extends Command { return await interaction.editReply(`I've ${ newInviteFilterRule.enabled ? "enabled" : "disabled" } the **${ newInviteFilterRule.name }** AutoMod rule.`); } + const actions: AutoModerationActionOptions[] = [ + { + type: AutoModerationActionType.BlockMessage, + metadata: { + customMessage: "You are not allowed to send invites in this channel.", + }, + }, + { + type: AutoModerationActionType.Timeout, + metadata: { + durationSeconds: 60, + }, + }, + ]; + + if (interaction.guild.channels.cache.has(guildDocument.moderationLogChannel)) { + actions.push({ + type: AutoModerationActionType.SendAlertMessage, + metadata: { + channel: guildDocument.moderationLogChannel, + }, + }); + } + // create invite filter rule const newInviteFilterRule = await interaction.guild.autoModerationRules.create({ enabled: true, @@ -46,26 +70,7 @@ class FilterInvitesCommand extends Command { "(?:https?://)?(?:www\\.)?(?:discord\\.gg|discord(?:app)?\\.com/invite)/[a-z0-9-.]+", ], }, - actions: [ - { - type: AutoModerationActionType.BlockMessage, - metadata: { - customMessage: "You are not allowed to send invites in this channel.", - }, - }, - { - type: AutoModerationActionType.SendAlertMessage, - metadata: { - channel: guildDocument.moderationLogChannel, - }, - }, - { - type: AutoModerationActionType.Timeout, - metadata: { - durationSeconds: 60, - }, - }, - ], + actions, reason: "Configure Invite Filter", }); diff --git a/src/commands/config/filter/links.ts b/src/commands/config/filter/links.ts index f0421e403..de12810d0 100644 --- a/src/commands/config/filter/links.ts +++ b/src/commands/config/filter/links.ts @@ -2,7 +2,7 @@ * @author TRACTION (iamtraction) * @copyright 2023 */ -import { AutoModerationActionType, AutoModerationRuleEventType, AutoModerationRuleTriggerType, ChatInputCommandInteraction, PermissionFlagsBits } from "discord.js"; +import { AutoModerationActionOptions, AutoModerationActionType, AutoModerationRuleEventType, AutoModerationRuleTriggerType, ChatInputCommandInteraction, PermissionFlagsBits } from "discord.js"; import { Command, Logger } from "@bastion/tesseract"; import GuildModel from "../../../models/Guild.js"; @@ -35,6 +35,30 @@ class FilterLinksCommand extends Command { return await interaction.editReply(`I've ${ newLinkFilterRule.enabled ? "enabled" : "disabled" } the **${ newLinkFilterRule.name }** AutoMod rule.`); } + const actions: AutoModerationActionOptions[] = [ + { + type: AutoModerationActionType.BlockMessage, + metadata: { + customMessage: "You are not allowed to send links in this channel.", + }, + }, + { + type: AutoModerationActionType.Timeout, + metadata: { + durationSeconds: 60, + }, + }, + ]; + + if (interaction.guild.channels.cache.has(guildDocument.moderationLogChannel)) { + actions.push({ + type: AutoModerationActionType.SendAlertMessage, + metadata: { + channel: guildDocument.moderationLogChannel, + }, + }); + } + // create link filter rule const newLinkFilterRule = await interaction.guild.autoModerationRules.create({ enabled: true, @@ -46,26 +70,7 @@ class FilterLinksCommand extends Command { "https?://(?:[-;:&=+$,\\w]+@)?[A-Za-z0-9.-]+", ], }, - actions: [ - { - type: AutoModerationActionType.BlockMessage, - metadata: { - customMessage: "You are not allowed to send links in this channel.", - }, - }, - { - type: AutoModerationActionType.SendAlertMessage, - metadata: { - channel: guildDocument.moderationLogChannel, - }, - }, - { - type: AutoModerationActionType.Timeout, - metadata: { - durationSeconds: 60, - }, - }, - ], + actions, reason: "Configure Link Filter", }); diff --git a/src/utils/regex.ts b/src/utils/regex.ts index 1ea3c386f..614c1ed73 100644 --- a/src/utils/regex.ts +++ b/src/utils/regex.ts @@ -2,7 +2,7 @@ * @author TRACTION (iamtraction) * @copyright 2022 */ -export const SERVER_INVITE = /(https:\/\/)?(www\.)?(discord\.gg|discordapp\.com\/invite|discord\.com\/invite)\/([a-z0-9-.]+)?/i; +export const SERVER_INVITE = /(?:https?:\/\/)?(?:www\.)?(?:discord\.gg|discord(?:app)?\.com\/invite)\/([a-z0-9-.]+)/i; export const URI = /((([A-Za-z]{3,9}:(?:\/\/))(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w\-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\\w]*))?)/i; export const WEBHOOK_URL = /(?:https:\/\/)(?:www\.)?(?:discordapp|discord)\.com\/api\/webhooks\/([0-9]+)\/([a-z0-9_-]+)/i;