mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
automod: add role_added and role_removed triggers
This commit is contained in:
parent
bfa9cf55a7
commit
4c7a51f586
9 changed files with 187 additions and 4 deletions
|
@ -14,6 +14,8 @@ import { MatchLinksTrigger } from "./matchLinks";
|
|||
import { MatchAttachmentTypeTrigger } from "./matchAttachmentType";
|
||||
import { MemberJoinSpamTrigger } from "./memberJoinSpam";
|
||||
import { MemberJoinTrigger } from "./memberJoin";
|
||||
import { RoleAddedTrigger } from "./roleAdded";
|
||||
import { RoleRemovedTrigger } from "./roleRemoved";
|
||||
|
||||
export const availableTriggers: Record<string, AutomodTriggerBlueprint<any, any>> = {
|
||||
match_words: MatchWordsTrigger,
|
||||
|
@ -22,6 +24,8 @@ export const availableTriggers: Record<string, AutomodTriggerBlueprint<any, any>
|
|||
match_links: MatchLinksTrigger,
|
||||
match_attachment_type: MatchAttachmentTypeTrigger,
|
||||
member_join: MemberJoinTrigger,
|
||||
role_added: RoleAddedTrigger,
|
||||
role_removed: RoleRemovedTrigger,
|
||||
|
||||
message_spam: MessageSpamTrigger,
|
||||
mention_spam: MentionSpamTrigger,
|
||||
|
|
42
backend/src/plugins/Automod/triggers/roleAdded.ts
Normal file
42
backend/src/plugins/Automod/triggers/roleAdded.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import * as t from "io-ts";
|
||||
import { automodTrigger } from "../helpers";
|
||||
import { consumeIgnoredRoleChange } from "../functions/ignoredRoleChanges";
|
||||
|
||||
interface RoleAddedMatchResult {
|
||||
matchedRoleId: string;
|
||||
}
|
||||
|
||||
export const RoleAddedTrigger = automodTrigger<RoleAddedMatchResult>()({
|
||||
configType: t.union([t.string, t.array(t.string)]),
|
||||
|
||||
defaultConfig: null,
|
||||
|
||||
async match({ triggerConfig, context, pluginData }) {
|
||||
if (!context.member || !context.rolesChanged || context.rolesChanged.added.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const triggerRoles = Array.isArray(triggerConfig) ? triggerConfig : [triggerConfig];
|
||||
for (const roleId of triggerRoles) {
|
||||
if (context.rolesChanged.added.includes(roleId)) {
|
||||
if (consumeIgnoredRoleChange(pluginData, context.member.id, roleId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return {
|
||||
extra: {
|
||||
matchedRoleId: roleId,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
renderMatchInformation({ matchResult, pluginData, contexts }) {
|
||||
const role = pluginData.guild.roles.get(matchResult.extra.matchedRoleId);
|
||||
const roleName = role?.name || "Unknown";
|
||||
const member = contexts[0].member!;
|
||||
const memberName = `**${member.user.username}#${member.user.discriminator}** (\`${member.id}\`)`;
|
||||
return `Role ${roleName} (\`${matchResult.extra.matchedRoleId}\`) was added to ${memberName}`;
|
||||
},
|
||||
});
|
42
backend/src/plugins/Automod/triggers/roleRemoved.ts
Normal file
42
backend/src/plugins/Automod/triggers/roleRemoved.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import * as t from "io-ts";
|
||||
import { automodTrigger } from "../helpers";
|
||||
import { consumeIgnoredRoleChange } from "../functions/ignoredRoleChanges";
|
||||
|
||||
interface RoleAddedMatchResult {
|
||||
matchedRoleId: string;
|
||||
}
|
||||
|
||||
export const RoleRemovedTrigger = automodTrigger<RoleAddedMatchResult>()({
|
||||
configType: t.union([t.string, t.array(t.string)]),
|
||||
|
||||
defaultConfig: null,
|
||||
|
||||
async match({ triggerConfig, context, pluginData }) {
|
||||
if (!context.member || !context.rolesChanged || context.rolesChanged.removed.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const triggerRoles = Array.isArray(triggerConfig) ? triggerConfig : [triggerConfig];
|
||||
for (const roleId of triggerRoles) {
|
||||
if (consumeIgnoredRoleChange(pluginData, context.member.id, roleId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (context.rolesChanged.removed.includes(roleId)) {
|
||||
return {
|
||||
extra: {
|
||||
matchedRoleId: roleId,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
renderMatchInformation({ matchResult, pluginData, contexts }) {
|
||||
const role = pluginData.guild.roles.get(matchResult.extra.matchedRoleId);
|
||||
const roleName = role?.name || "Unknown";
|
||||
const member = contexts[0].member!;
|
||||
const memberName = `**${member.user.username}#${member.user.discriminator}** (\`${member.id}\`)`;
|
||||
return `Role ${roleName} (\`${matchResult.extra.matchedRoleId}\`) was removed from ${memberName}`;
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue