import { Collection, GuildMember } from "discord.js" import { filterRolesFromMemberUpdate } from "../helper/roleFilter" import { ChangedRoles, PermissionLevel } from "../interfaces" import ar from "date-fns/locale/ar" import { jellyfinHandler } from "../.." export const name = 'guildMemberUpdate' export async function execute(oldMember: GuildMember, newMember: GuildMember) { try { const changedRoles: ChangedRoles = filterRolesFromMemberUpdate(oldMember, newMember) const triggerRoleIds: Collection = getGuildSpecificTriggerRoleId(oldMember.guild.id) triggerRoleIds.forEach((level, key) => { const addedRoleMatches = changedRoles.addedRoles.find(aRole => aRole.id === key) if (addedRoleMatches) { jellyfinHandler.upsertUser(newMember, level) } const removedRoleMatches = changedRoles.removedRoles.find(rRole => rRole.id === key) if (removedRoleMatches) { jellyfinHandler.removeUser(newMember) } }) } catch (error) { console.error(error) } } function getGuildSpecificTriggerRoleId(id: string): Collection { const outVal = new Collection() outVal.set('1096819983889215659', "VIEWER") outVal.set('1097990848613986526', "ADMIN") return outVal }