From c28b37b0e99cd3996293185c483633af602c1e97 Mon Sep 17 00:00:00 2001 From: mightypanders Date: Tue, 18 Apr 2023 23:44:14 +0200 Subject: [PATCH] add function to filter the role changes from member update --- server/helper/roleFilter.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 server/helper/roleFilter.ts diff --git a/server/helper/roleFilter.ts b/server/helper/roleFilter.ts new file mode 100644 index 0000000..3c64323 --- /dev/null +++ b/server/helper/roleFilter.ts @@ -0,0 +1,16 @@ +import { GuildMember } from "discord.js" +import { ChangedRoles } from "../interfaces" +import { logger } from "../logger" + +export function filterRolesFromMemberUpdate(oldMember: GuildMember, newMember: GuildMember): ChangedRoles { + + const oldRoles = oldMember.roles.cache + const newRoles = newMember.roles.cache + + const removedRoles = oldRoles.filter(x => newRoles.find(y => y.id === x.id) == undefined) + const addedRoles = newRoles.filter(x => oldRoles.find(y => y.id === x.id) == undefined) + logger.info(`Member ${oldMember.id} RemovedRoles: ${removedRoles.map(x => x.name)}`, { guildId: oldMember.guild.id }) + logger.info(`Member ${oldMember.id} AddedRoles: ${addedRoles.map(x => x.name)}`, { guildId: oldMember.guild.id }) + + return { addedRoles, removedRoles } +}