import { RoleType , RoleTypeKey } from './../common/types' ; import { GuildMember , Role , Collection } from 'discord.js' ; export class RoleService { hasPermission ( member , minRoleToRun ) { const roles = member . roles ; const highestRole = this . _getHighestRole ( roles . cache ) ; return highestRole >= minRoleToRun ; } private _getHighestRole ( roles ) { let highestRole = 0 ; roles . forEach ( ( role ) => { if ( role . name in RoleType ) { if ( role . name === 'Suspended' ) { return RoleType . Suspended ; } highestRole = Math . max ( highestRole , RoleType [ < RoleTypeKey > role . name ] ) ; } } ) ; return highestRole ; } }