3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-16 06:11:49 +00:00

automod: add guild info to matched invites

This commit is contained in:
Dragory 2020-05-28 03:28:25 +03:00
parent 9b263957a3
commit 1fcf57cf13
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -428,9 +428,9 @@ export class AutomodPlugin extends ZeppelinPlugin<TConfigSchema, ICustomOverride
} }
/** /**
* @return Matched invite code * @return Info about matched invite
*/ */
protected async evaluateMatchInvitesTrigger(trigger: TMatchInvitesTrigger, str: string): Promise<null | string> { protected async evaluateMatchInvitesTrigger(trigger: TMatchInvitesTrigger, str: string): Promise<null | any> {
const inviteCodes = getInviteCodesInString(str); const inviteCodes = getInviteCodesInString(str);
if (inviteCodes.length === 0) return null; if (inviteCodes.length === 0) return null;
@ -438,22 +438,22 @@ export class AutomodPlugin extends ZeppelinPlugin<TConfigSchema, ICustomOverride
for (const code of uniqueInviteCodes) { for (const code of uniqueInviteCodes) {
if (trigger.include_invite_codes && trigger.include_invite_codes.includes(code)) { if (trigger.include_invite_codes && trigger.include_invite_codes.includes(code)) {
return code; return { code };
} }
if (trigger.exclude_invite_codes && !trigger.exclude_invite_codes.includes(code)) { if (trigger.exclude_invite_codes && !trigger.exclude_invite_codes.includes(code)) {
return code; return { code };
} }
} }
for (const inviteCode of uniqueInviteCodes) { for (const inviteCode of uniqueInviteCodes) {
const invite = await this.resolveInvite(inviteCode); const invite = await this.resolveInvite(inviteCode);
if (!invite) return inviteCode; if (!invite) return { code: inviteCode };
if (trigger.include_guilds && trigger.include_guilds.includes(invite.guild.id)) { if (trigger.include_guilds && trigger.include_guilds.includes(invite.guild.id)) {
return inviteCode; return { code: inviteCode, invite };
} }
if (trigger.exclude_guilds && !trigger.exclude_guilds.includes(invite.guild.id)) { if (trigger.exclude_guilds && !trigger.exclude_guilds.includes(invite.guild.id)) {
return inviteCode; return { code: inviteCode, invite };
} }
} }
@ -1499,7 +1499,10 @@ export class AutomodPlugin extends ZeppelinPlugin<TConfigSchema, ICustomOverride
} else if (matchResult.trigger === "match_regex") { } else if (matchResult.trigger === "match_regex") {
return `regex \`${disableInlineCode(matchResult.matchedValue)}\``; return `regex \`${disableInlineCode(matchResult.matchedValue)}\``;
} else if (matchResult.trigger === "match_invites") { } else if (matchResult.trigger === "match_invites") {
return `invite code \`${disableInlineCode(matchResult.matchedValue)}\``; if (matchResult.matchedValue.invite) {
return `invite code \`${matchResult.matchedValue.code}\` (**${matchResult.matchedValue.invite.guild.name}**, \`${matchResult.matchedValue.invite.guild.id}\`)`;
}
return `invite code \`${disableInlineCode(matchResult.matchedValue.code)}\``;
} else if (matchResult.trigger === "match_links") { } else if (matchResult.trigger === "match_links") {
return `link \`${disableInlineCode(matchResult.matchedValue)}\``; return `link \`${disableInlineCode(matchResult.matchedValue)}\``;
} else if (matchResult.trigger === "match_attachment_type") { } else if (matchResult.trigger === "match_attachment_type") {