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 } +}