Skip to content

Commit

Permalink
commands(filter-links): fix error if mod logs channel doesn't exit
Browse files Browse the repository at this point in the history
Signed-off-by: TRACTION <19631364+iamtraction@users.noreply.github.com>
  • Loading branch information
iamtraction committed Jun 1, 2023
1 parent ad5ca6c commit 2bdba0e
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions src/commands/config/filter/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand All @@ -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",
});

Expand Down

0 comments on commit 2bdba0e

Please sign in to comment.