-
-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commands(config): add new filter command
Signed-off-by: TRACTION <19631364+iamtraction@users.noreply.github.com>
- Loading branch information
1 parent
58872ff
commit 118b5bd
Showing
2 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/*! | ||
* @author TRACTION (iamtraction) | ||
* @copyright 2023 | ||
*/ | ||
import { AutoModerationActionType, AutoModerationRuleEventType, AutoModerationRuleTriggerType, ChatInputCommandInteraction, PermissionFlagsBits } from "discord.js"; | ||
import { Command, Logger } from "@bastion/tesseract"; | ||
|
||
import GuildModel from "../../../models/Guild.js"; | ||
|
||
class FilterInvitesCommand extends Command { | ||
constructor() { | ||
super({ | ||
name: "invites", | ||
description: "Configure Invite Filter AutoMod rule in the server.", | ||
userPermissions: [ PermissionFlagsBits.ManageGuild ], | ||
clientPermissions: [ PermissionFlagsBits.ManageGuild ], | ||
}); | ||
} | ||
|
||
public async exec(interaction: ChatInputCommandInteraction<"cached">): Promise<unknown> { | ||
await interaction.deferReply(); | ||
|
||
// get guild document | ||
const guildDocument = await GuildModel.findById(interaction.guildId); | ||
|
||
// get the invite filter rule if it exists | ||
const inviteFilterRule = guildDocument.inviteFilterRule && await interaction.guild.autoModerationRules.fetch({ | ||
autoModerationRule: guildDocument.inviteFilterRule, | ||
cache: false, | ||
}).catch(Logger.ignore); | ||
|
||
// toggle invite filter rule if it exists | ||
if (inviteFilterRule) { | ||
const newInviteFilterRule = await inviteFilterRule.setEnabled(!inviteFilterRule.enabled, `${ inviteFilterRule.enabled ? "Disable" : "Enable" } Invite Filter`); | ||
return await interaction.editReply(`I've ${ newInviteFilterRule.enabled ? "enabled" : "disabled" } the **${ newInviteFilterRule.name }** AutoMod rule.`); | ||
} | ||
|
||
// create invite filter rule | ||
const newInviteFilterRule = await interaction.guild.autoModerationRules.create({ | ||
enabled: true, | ||
name: "Block Invites", | ||
eventType: AutoModerationRuleEventType.MessageSend, | ||
triggerType: AutoModerationRuleTriggerType.Keyword, | ||
triggerMetadata: { | ||
regexPatterns: [ | ||
"(?: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, | ||
}, | ||
}, | ||
], | ||
reason: "Configure Invite Filter", | ||
}); | ||
|
||
// update invite filter rule id | ||
guildDocument.inviteFilterRule = newInviteFilterRule.id; | ||
|
||
// save document | ||
await guildDocument.save(); | ||
|
||
return await interaction.editReply("I've configured the invite filter AutoMod rule."); | ||
} | ||
} | ||
|
||
export { FilterInvitesCommand as Command }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/*! | ||
* @author TRACTION (iamtraction) | ||
* @copyright 2023 | ||
*/ | ||
import { AutoModerationActionType, AutoModerationRuleEventType, AutoModerationRuleTriggerType, ChatInputCommandInteraction, PermissionFlagsBits } from "discord.js"; | ||
import { Command, Logger } from "@bastion/tesseract"; | ||
|
||
import GuildModel from "../../../models/Guild.js"; | ||
|
||
class FilterLinksCommand extends Command { | ||
constructor() { | ||
super({ | ||
name: "links", | ||
description: "Configure Link Filter AutoMod rule in the server.", | ||
userPermissions: [ PermissionFlagsBits.ManageGuild ], | ||
clientPermissions: [ PermissionFlagsBits.ManageGuild ], | ||
}); | ||
} | ||
|
||
public async exec(interaction: ChatInputCommandInteraction<"cached">): Promise<unknown> { | ||
await interaction.deferReply(); | ||
|
||
// get guild document | ||
const guildDocument = await GuildModel.findById(interaction.guildId); | ||
|
||
// get the link filter rule if it exists | ||
const linkFilterRule = guildDocument.linkFilterRule && await interaction.guild.autoModerationRules.fetch({ | ||
autoModerationRule: guildDocument.linkFilterRule, | ||
cache: false, | ||
}).catch(Logger.ignore); | ||
|
||
// toggle link filter rule if it exists | ||
if (linkFilterRule) { | ||
const newLinkFilterRule = await linkFilterRule.setEnabled(!linkFilterRule.enabled, `${ linkFilterRule.enabled ? "Disable" : "Enable" } Link Filter`); | ||
return await interaction.editReply(`I've ${ newLinkFilterRule.enabled ? "enabled" : "disabled" } the **${ newLinkFilterRule.name }** AutoMod rule.`); | ||
} | ||
|
||
// create link filter rule | ||
const newLinkFilterRule = await interaction.guild.autoModerationRules.create({ | ||
enabled: true, | ||
name: "Block Links", | ||
eventType: AutoModerationRuleEventType.MessageSend, | ||
triggerType: AutoModerationRuleTriggerType.Keyword, | ||
triggerMetadata: { | ||
regexPatterns: [ | ||
"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, | ||
}, | ||
}, | ||
], | ||
reason: "Configure Link Filter", | ||
}); | ||
|
||
// update link filter rule id | ||
guildDocument.linkFilterRule = newLinkFilterRule.id; | ||
|
||
// save document | ||
await guildDocument.save(); | ||
|
||
return await interaction.editReply("I've configured the link filter AutoMod rule."); | ||
} | ||
} | ||
|
||
export { FilterLinksCommand as Command }; |