Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
almeidx committed Nov 3, 2021
1 parent ad009bf commit 47a8452
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions backend/src/plugins/Automod/triggers/matchMentions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Role, User } from "discord.js";
import * as t from "io-ts";
import { tNullable } from "../../../utils";
import { getTextMatchPartialSummary } from "../functions/getTextMatchPartialSummary";
Expand All @@ -8,6 +7,13 @@ interface MatchResultType {
reason: "everyone" | "repliedUser" | "users" | "roles";
}

const summaryType: Record<MatchResultType["reason"], string> = {
everyone: "everyone",
repliedUser: "replied user",
users: "user",
roles: "role",
};

export const MatchMentionsTrigger = automodTrigger<MatchResultType>()({
configType: t.type({
everyone: tNullable(t.boolean),
Expand All @@ -24,9 +30,7 @@ export const MatchMentionsTrigger = automodTrigger<MatchResultType>()({
},

async match({ pluginData, context, triggerConfig }) {
if (!context.message) {
return;
}
if (!context.message) return;

const channel = pluginData.client.channels.resolve(context.message.channel_id);
if (!channel || !channel?.isText()) return;
Expand Down Expand Up @@ -82,20 +86,6 @@ export const MatchMentionsTrigger = automodTrigger<MatchResultType>()({

renderMatchInformation({ pluginData, contexts, matchResult }) {
const partialSummary = getTextMatchPartialSummary(pluginData, "message", contexts[0]);

if (matchResult.extra.reason === "everyone") {
return `Matched everyone mention in ${partialSummary}`;
}
if (matchResult.extra.reason === "repliedUser") {
return `Matched reply mention in ${partialSummary}`;
}
if (matchResult.extra.reason === "users") {
return `Matched user mention in ${partialSummary}`;
}
if (matchResult.extra.reason === "roles") {
return `Matched role mention in ${partialSummary}`;
}

return `Matched mention in ${partialSummary}`;
return `Matched ${summaryType[matchResult.extra.reason]} mention in ${partialSummary}`;
},
});

0 comments on commit 47a8452

Please sign in to comment.