3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-21 16:55:03 +00:00

fix(automod/triggers): optimize and fix MIME type

This commit is contained in:
Hiroyuki 2021-08-14 14:25:23 -04:00
parent 64df1909e7
commit 8c92c98777
No known key found for this signature in database
GPG key ID: 843DF434003F6710

View file

@ -1,7 +1,7 @@
import { automodTrigger } from "../helpers"; import { automodTrigger } from "../helpers";
import * as t from "io-ts"; import * as t from "io-ts";
import { asSingleLine, messageSummary, verboseChannelMention } from "src/utils"; import { asSingleLine, messageSummary, verboseChannelMention } from "../../../utils";
import { Snowflake, TextChannel, Util } from "discord.js"; import { GuildChannel, Util } from "discord.js";
interface MatchResultType { interface MatchResultType {
matchedType: string; matchedType: string;
@ -33,7 +33,7 @@ export const MatchMimeTypeTrigger = automodTrigger<MatchResultType>()({
const { contentType } = attachment; const { contentType } = attachment;
const blacklist = trigger.blacklist_enabled const blacklist = trigger.blacklist_enabled
? (trigger.mime_type_blacklist || []).map(_t => _t.toLowerCase()) ? (trigger.mime_type_blacklist ?? []).map(_t => _t.toLowerCase())
: null; : null;
if (contentType && blacklist?.includes(contentType)) { if (contentType && blacklist?.includes(contentType)) {
@ -46,13 +46,13 @@ export const MatchMimeTypeTrigger = automodTrigger<MatchResultType>()({
} }
const whitelist = trigger.whitelist_enabled const whitelist = trigger.whitelist_enabled
? (trigger.mime_type_whitelist || []).map(_t => _t.toLowerCase()) ? (trigger.mime_type_whitelist ?? []).map(_t => _t.toLowerCase())
: null; : null;
if (whitelist && (!contentType || !whitelist.includes(contentType))) { if (whitelist && (!contentType || !whitelist.includes(contentType))) {
return { return {
extra: { extra: {
matchedType: contentType || "unknown", matchedType: contentType || "<unknown>",
mode: "whitelist", mode: "whitelist",
}, },
}; };
@ -64,8 +64,8 @@ export const MatchMimeTypeTrigger = automodTrigger<MatchResultType>()({
renderMatchInformation({ pluginData, contexts, matchResult }) { renderMatchInformation({ pluginData, contexts, matchResult }) {
const { message } = contexts[0]; const { message } = contexts[0];
const channel = pluginData.guild.channels.cache.get(message!.channel_id as Snowflake) as TextChannel; const channel = pluginData.guild.channels.resolve(message!.channel_id);
const prettyChannel = verboseChannelMention(channel); const prettyChannel = verboseChannelMention(channel as GuildChannel);
const { matchedType, mode } = matchResult.extra; const { matchedType, mode } = matchResult.extra;
return ( return (