3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

automod: fix match_attachment_type no longer matching on messages with no text content

This commit is contained in:
Dragory 2020-05-28 04:01:07 +03:00
parent 1fcf57cf13
commit 48c9721945
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
2 changed files with 24 additions and 19 deletions

View file

@ -125,12 +125,6 @@ const defaultMatchAttachmentTypeTrigger: Partial<TMatchAttachmentTypeTrigger> =
blacklist_enabled: false,
filetype_whitelist: [],
whitelist_enabled: false,
match_messages: true,
match_embeds: true,
match_visible_names: false,
match_usernames: false,
match_nicknames: false,
match_custom_status: false,
};
const defaultTextSpamTrigger: Partial<t.TypeOf<typeof BaseTextSpamTrigger>> = {
@ -541,17 +535,26 @@ export class AutomodPlugin extends ZeppelinPlugin<TConfigSchema, ICustomOverride
return null;
}
protected evaluateMatchAttachmentTypeTrigger(trigger: TMatchAttachmentTypeTrigger, msg: SavedMessage): null | string {
protected evaluateMatchAttachmentTypeTrigger(
trigger: TMatchAttachmentTypeTrigger,
msg: SavedMessage,
): null | { str: string; matchedValue: string } {
if (!msg.data.attachments) return null;
const attachments: any[] = msg.data.attachments;
for (const attachment of attachments) {
const attachment_type = attachment.filename.split(`.`).pop();
if (trigger.blacklist_enabled && trigger.filetype_blacklist.includes(attachment_type)) {
return `${attachment_type} - blacklisted`;
return {
str: attachment.filename,
matchedValue: `${attachment_type} - blacklisted`,
};
}
if (trigger.whitelist_enabled && !trigger.filetype_whitelist.includes(attachment_type)) {
return `${attachment_type} - not whitelisted`;
return {
str: attachment.filename,
matchedValue: `${attachment_type} - blacklisted`,
};
}
}
@ -733,10 +736,18 @@ export class AutomodPlugin extends ZeppelinPlugin<TConfigSchema, ICustomOverride
}
if (trigger.match_attachment_type) {
const match = await this.matchMultipleTextTypesOnMessage(trigger.match_attachment_type, msg, str => {
return this.evaluateMatchAttachmentTypeTrigger(trigger.match_attachment_type, msg);
});
if (match) return { ...match, trigger: "match_attachment_type" } as TextTriggerMatchResult;
const match = this.evaluateMatchAttachmentTypeTrigger(trigger.match_attachment_type, msg);
// TODO: Add "attachment" type
if (match) {
const messageInfo: MessageInfo = { channelId: msg.channel_id, messageId: msg.id, userId: msg.user_id };
return {
type: "message",
userId: msg.user_id,
messageInfo,
...match,
trigger: "match_attachment_type",
};
}
}
if (trigger.message_spam) {

View file

@ -189,12 +189,6 @@ export const MatchAttachmentTypeTrigger = t.type({
blacklist_enabled: t.boolean,
filetype_whitelist: t.array(t.string),
whitelist_enabled: t.boolean,
match_messages: t.boolean,
match_embeds: t.boolean,
match_visible_names: t.boolean,
match_usernames: t.boolean,
match_nicknames: t.boolean,
match_custom_status: t.boolean,
});
export type TMatchAttachmentTypeTrigger = t.TypeOf<typeof MatchAttachmentTypeTrigger>;