import { GuildMember , GuildChannel } from 'discord.js' ; import { Bot } from '..' ; import { staffObject } from '../database/schemas' ; export enum { number } export enum permLevels { member = 0 , immune = 1 , mod = 2 , admin = 3 , botMaster = 4 } export param { GuildMember } member returns export async function getPermLevel ( member ) { if ( member == null ) { return permLevels . member ; } if ( Bot . database . getBotMasters ( ) . includes ( member . user . id ) ) { return permLevels . botMaster ; } if ( member . hasPermission ( 'ADMINISTRATOR' ) ) { return permLevels . admin ; } var staffDoc = await Bot . database . findStaffDoc ( member . guild . id ) ; if ( ! staffDoc ) { return permLevels . member ; } var staffObject = staffDoc . toObject ( ) ; if ( staffObject . admins . users . includes ( member . user . id ) ) { return permLevels . admin ; } for ( var i = 0 ; i < staffObject . admins . roles . length ; i ++ ) { if ( member . roles . find ( role => role . id == staffObject . admins . roles [ i ] ) ) { return permLevels . admin ; } } if ( staffObject . mods . users . includes ( member . user . id ) ) { return permLevels . mod ; } for ( var i = 0 ; i < staffObject . mods . roles . length ; i ++ ) { if ( member . roles . find ( role => role . id == staffObject . mods . roles [ i ] ) ) { return permLevels . mod ; } } if ( staffObject . immune . users . includes ( member . user . id ) ) { return permLevels . immune ; } for ( var i = 0 ; i < staffObject . immune . roles . length ; i ++ ) { if ( member . roles . find ( role => role . id == staffObject . immune . roles [ i ] ) ) { return permLevels . immune ; } } return permLevels . member ; }