automod: update match summaries for match_* triggers
This commit is contained in:
parent
06997b59b0
commit
b73c8668e3
6 changed files with 53 additions and 38 deletions
|
@ -0,0 +1,32 @@
|
||||||
|
import { MatchableTextType } from "./matchMultipleTextTypesOnMessage";
|
||||||
|
import { AutomodContext, AutomodPluginType } from "../types";
|
||||||
|
import { messageSummary, verboseChannelMention } from "../../../utils";
|
||||||
|
import { PluginData } from "knub";
|
||||||
|
import { User } from "eris";
|
||||||
|
|
||||||
|
export function getTextMatchPartialSummary(
|
||||||
|
pluginData: PluginData<AutomodPluginType>,
|
||||||
|
type: MatchableTextType,
|
||||||
|
context: AutomodContext,
|
||||||
|
) {
|
||||||
|
if (type === "message") {
|
||||||
|
const channel = pluginData.guild.channels.get(context.message.channel_id);
|
||||||
|
const channelMention = channel ? verboseChannelMention(channel) : `\`#${context.message.channel_id}\``;
|
||||||
|
|
||||||
|
return `message in ${channelMention}:\n${messageSummary(context.message)}`;
|
||||||
|
} else if (type === "embed") {
|
||||||
|
const channel = pluginData.guild.channels.get(context.message.channel_id);
|
||||||
|
const channelMention = channel ? verboseChannelMention(channel) : `\`#${context.message.channel_id}\``;
|
||||||
|
|
||||||
|
return `message embed in ${channelMention}:\n${messageSummary(context.message)}`;
|
||||||
|
} else if (type === "username") {
|
||||||
|
return `username: ${context.user.username}`;
|
||||||
|
} else if (type === "nickname") {
|
||||||
|
return `nickname: ${context.member.nick}`;
|
||||||
|
} else if (type === "visiblename") {
|
||||||
|
const visibleName = context.member?.nick || context.user.username;
|
||||||
|
return `visible name: ${visibleName}`;
|
||||||
|
} else if (type === "customstatus") {
|
||||||
|
return `custom status: ${context.member.game.state}`;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,12 @@
|
||||||
import * as t from "io-ts";
|
import * as t from "io-ts";
|
||||||
import { automodTrigger } from "../helpers";
|
import { automodTrigger } from "../helpers";
|
||||||
import { asSingleLine, disableCodeBlocks, disableInlineCode, verboseChannelMention } from "../../../utils";
|
import {
|
||||||
|
asSingleLine,
|
||||||
|
disableCodeBlocks,
|
||||||
|
disableInlineCode,
|
||||||
|
messageSummary,
|
||||||
|
verboseChannelMention,
|
||||||
|
} from "../../../utils";
|
||||||
|
|
||||||
interface MatchResultType {
|
interface MatchResultType {
|
||||||
matchedType: string;
|
matchedType: string;
|
||||||
|
@ -64,10 +70,7 @@ export const MatchAttachmentTypeTrigger = automodTrigger<MatchResultType>()({
|
||||||
Matched attachment type \`${disableInlineCode(matchResult.extra.matchedType)}\`
|
Matched attachment type \`${disableInlineCode(matchResult.extra.matchedType)}\`
|
||||||
(${matchResult.extra.mode === "blacklist" ? "(blacklisted)" : "(not in whitelist)"})
|
(${matchResult.extra.mode === "blacklist" ? "(blacklisted)" : "(not in whitelist)"})
|
||||||
in message (\`${contexts[0].message.id}\`) in ${prettyChannel}:
|
in message (\`${contexts[0].message.id}\`) in ${prettyChannel}:
|
||||||
`) +
|
`) + messageSummary(contexts[0].message)
|
||||||
"\n```" +
|
|
||||||
disableCodeBlocks(contexts[0].message.data.content) +
|
|
||||||
"```"
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { GuildInvite } from "eris";
|
||||||
import { automodTrigger } from "../helpers";
|
import { automodTrigger } from "../helpers";
|
||||||
import {
|
import {
|
||||||
disableCodeBlocks,
|
disableCodeBlocks,
|
||||||
|
disableInlineCode,
|
||||||
getInviteCodesInString,
|
getInviteCodesInString,
|
||||||
isGuildInvite,
|
isGuildInvite,
|
||||||
resolveInvite,
|
resolveInvite,
|
||||||
|
@ -10,6 +11,7 @@ import {
|
||||||
verboseChannelMention,
|
verboseChannelMention,
|
||||||
} from "../../../utils";
|
} from "../../../utils";
|
||||||
import { MatchableTextType, matchMultipleTextTypesOnMessage } from "../functions/matchMultipleTextTypesOnMessage";
|
import { MatchableTextType, matchMultipleTextTypesOnMessage } from "../functions/matchMultipleTextTypesOnMessage";
|
||||||
|
import { getTextMatchPartialSummary } from "../functions/getTextMatchPartialSummary";
|
||||||
|
|
||||||
interface MatchResultType {
|
interface MatchResultType {
|
||||||
type: MatchableTextType;
|
type: MatchableTextType;
|
||||||
|
@ -79,9 +81,6 @@ export const MatchInvitesTrigger = automodTrigger<MatchResultType>()({
|
||||||
},
|
},
|
||||||
|
|
||||||
renderMatchInformation({ pluginData, contexts, matchResult }) {
|
renderMatchInformation({ pluginData, contexts, matchResult }) {
|
||||||
const channel = pluginData.guild.channels.get(contexts[0].message.channel_id);
|
|
||||||
const prettyChannel = verboseChannelMention(channel);
|
|
||||||
|
|
||||||
let matchedText;
|
let matchedText;
|
||||||
|
|
||||||
if (matchResult.extra.invite) {
|
if (matchResult.extra.invite) {
|
||||||
|
@ -91,11 +90,7 @@ export const MatchInvitesTrigger = automodTrigger<MatchResultType>()({
|
||||||
matchedText = `invite code \`${matchResult.extra.code}\``;
|
matchedText = `invite code \`${matchResult.extra.code}\``;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
const partialSummary = getTextMatchPartialSummary(pluginData, matchResult.extra.type, contexts[0]);
|
||||||
`${matchedText} in message (\`${contexts[0].message.id}\`) in ${prettyChannel}:\n` +
|
return `Matched ${matchedText} in ${partialSummary}`;
|
||||||
"```" +
|
|
||||||
disableCodeBlocks(contexts[0].message.data.content) +
|
|
||||||
"```"
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,6 +11,7 @@ import {
|
||||||
} from "../../../utils";
|
} from "../../../utils";
|
||||||
import { MatchableTextType, matchMultipleTextTypesOnMessage } from "../functions/matchMultipleTextTypesOnMessage";
|
import { MatchableTextType, matchMultipleTextTypesOnMessage } from "../functions/matchMultipleTextTypesOnMessage";
|
||||||
import { TSafeRegex } from "../../../validatorUtils";
|
import { TSafeRegex } from "../../../validatorUtils";
|
||||||
|
import { getTextMatchPartialSummary } from "../functions/getTextMatchPartialSummary";
|
||||||
|
|
||||||
interface MatchResultType {
|
interface MatchResultType {
|
||||||
type: MatchableTextType;
|
type: MatchableTextType;
|
||||||
|
@ -131,17 +132,7 @@ export const MatchLinksTrigger = automodTrigger<MatchResultType>()({
|
||||||
},
|
},
|
||||||
|
|
||||||
renderMatchInformation({ pluginData, contexts, matchResult }) {
|
renderMatchInformation({ pluginData, contexts, matchResult }) {
|
||||||
const channel = pluginData.guild.channels.get(contexts[0].message.channel_id);
|
const partialSummary = getTextMatchPartialSummary(pluginData, matchResult.extra.type, contexts[0]);
|
||||||
const prettyChannel = verboseChannelMention(channel);
|
return `Matched link \`${disableInlineCode(matchResult.extra.link)}\` in ${partialSummary}`;
|
||||||
|
|
||||||
return (
|
|
||||||
asSingleLine(`
|
|
||||||
Matched link \`${disableInlineCode(matchResult.extra.link)}\`
|
|
||||||
in message (\`${contexts[0].message.id}\`) in ${prettyChannel}:
|
|
||||||
`) +
|
|
||||||
"\n```" +
|
|
||||||
disableCodeBlocks(contexts[0].message.data.content) +
|
|
||||||
"```"
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { automodTrigger } from "../helpers";
|
||||||
import { disableInlineCode, verboseChannelMention } from "../../../utils";
|
import { disableInlineCode, verboseChannelMention } from "../../../utils";
|
||||||
import { MatchableTextType, matchMultipleTextTypesOnMessage } from "../functions/matchMultipleTextTypesOnMessage";
|
import { MatchableTextType, matchMultipleTextTypesOnMessage } from "../functions/matchMultipleTextTypesOnMessage";
|
||||||
import { TSafeRegex } from "../../../validatorUtils";
|
import { TSafeRegex } from "../../../validatorUtils";
|
||||||
|
import { getTextMatchPartialSummary } from "../functions/getTextMatchPartialSummary";
|
||||||
|
|
||||||
interface MatchResultType {
|
interface MatchResultType {
|
||||||
pattern: string;
|
pattern: string;
|
||||||
|
@ -62,11 +63,7 @@ export const MatchRegexTrigger = automodTrigger<MatchResultType>()({
|
||||||
},
|
},
|
||||||
|
|
||||||
renderMatchInformation({ pluginData, contexts, matchResult }) {
|
renderMatchInformation({ pluginData, contexts, matchResult }) {
|
||||||
const channel = pluginData.guild.channels.get(contexts[0].message.channel_id);
|
const partialSummary = getTextMatchPartialSummary(pluginData, matchResult.extra.type, contexts[0]);
|
||||||
const prettyChannel = verboseChannelMention(channel);
|
return `Matched regex \`${disableInlineCode(matchResult.extra.pattern)}\` in ${partialSummary}`;
|
||||||
|
|
||||||
return `Matched regex \`${disableInlineCode(matchResult.extra.pattern)}\` in message (\`${
|
|
||||||
contexts[0].message.id
|
|
||||||
}\`) in ${prettyChannel}:`;
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,6 +4,7 @@ import escapeStringRegexp from "escape-string-regexp";
|
||||||
import { automodTrigger } from "../helpers";
|
import { automodTrigger } from "../helpers";
|
||||||
import { disableInlineCode, verboseChannelMention } from "../../../utils";
|
import { disableInlineCode, verboseChannelMention } from "../../../utils";
|
||||||
import { MatchableTextType, matchMultipleTextTypesOnMessage } from "../functions/matchMultipleTextTypesOnMessage";
|
import { MatchableTextType, matchMultipleTextTypesOnMessage } from "../functions/matchMultipleTextTypesOnMessage";
|
||||||
|
import { getTextMatchPartialSummary } from "../functions/getTextMatchPartialSummary";
|
||||||
|
|
||||||
interface MatchResultType {
|
interface MatchResultType {
|
||||||
word: string;
|
word: string;
|
||||||
|
@ -80,11 +81,7 @@ export const MatchWordsTrigger = automodTrigger<MatchResultType>()({
|
||||||
},
|
},
|
||||||
|
|
||||||
renderMatchInformation({ pluginData, contexts, matchResult }) {
|
renderMatchInformation({ pluginData, contexts, matchResult }) {
|
||||||
const channel = pluginData.guild.channels.get(contexts[0].message.channel_id);
|
const partialSummary = getTextMatchPartialSummary(pluginData, matchResult.extra.type, contexts[0]);
|
||||||
const prettyChannel = verboseChannelMention(channel);
|
return `Matched word \`${disableInlineCode(matchResult.extra.word)}\` in ${partialSummary}`;
|
||||||
|
|
||||||
return `Matched word \`${disableInlineCode(matchResult.extra.word)}\` in message (\`${
|
|
||||||
contexts[0].message.id
|
|
||||||
}\`) in ${prettyChannel}:`;
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue