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