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
|
@ -0,0 +1,34 @@
|
|||
import { eventListener } from "knub";
|
||||
import { AutomodContext, AutomodPluginType } from "../types";
|
||||
import { RecentActionType } from "../constants";
|
||||
import { runAutomod } from "../functions/runAutomod";
|
||||
import isEqual from "lodash.isequal";
|
||||
import diff from "lodash.difference";
|
||||
|
||||
export const RunAutomodOnMemberUpdate = eventListener<AutomodPluginType>()(
|
||||
"guildMemberUpdate",
|
||||
({ pluginData, args: { member, oldMember } }) => {
|
||||
if (!oldMember) return;
|
||||
|
||||
if (isEqual(oldMember.roles, member.roles)) return;
|
||||
|
||||
const addedRoles = diff(member.roles, oldMember.roles);
|
||||
const removedRoles = diff(oldMember.roles, member.roles);
|
||||
|
||||
if (addedRoles.length || removedRoles.length) {
|
||||
const context: AutomodContext = {
|
||||
timestamp: Date.now(),
|
||||
user: member.user,
|
||||
member,
|
||||
rolesChanged: {
|
||||
added: addedRoles,
|
||||
removed: removedRoles,
|
||||
},
|
||||
};
|
||||
|
||||
pluginData.state.queue.add(() => {
|
||||
runAutomod(pluginData, context);
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue