Sammy
5b98c9bf2f
We can add multiple eventhandlers per eventname. To avoid confusion and large files and to improve concise file names the event files were renamed
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { Collection, GuildMember } from "discord.js"
|
|
import { filterRolesFromMemberUpdate, getGuildSpecificTriggerRoleId } from "../helper/roleFilter"
|
|
import { ChangedRoles, PermissionLevel } from "../interfaces"
|
|
import { jellyfinHandler } from "../.."
|
|
import { v4 as uuid } from "uuid"
|
|
|
|
export const name = 'guildMemberUpdate'
|
|
export async function execute(oldMember: GuildMember, newMember: GuildMember) {
|
|
try {
|
|
const requestId = uuid()
|
|
const changedRoles: ChangedRoles = filterRolesFromMemberUpdate(oldMember, newMember)
|
|
const triggerRoleIds: Collection<string, PermissionLevel> = getGuildSpecificTriggerRoleId()
|
|
|
|
triggerRoleIds.forEach((level, key) => {
|
|
const addedRoleMatches = changedRoles.addedRoles.find(aRole => aRole.id === key)
|
|
if (addedRoleMatches) {
|
|
jellyfinHandler.upsertUser(newMember, level, requestId)
|
|
}
|
|
const removedRoleMatches = changedRoles.removedRoles.find(rRole => rRole.id === key)
|
|
if (removedRoleMatches) {
|
|
jellyfinHandler.removeUser(newMember, level, requestId)
|
|
}
|
|
})
|
|
} catch (error) {
|
|
console.error(error)
|
|
}
|
|
}
|
|
|
|
|
|
|