import { AnyChannel , DMChannel , GuildChannel , Permissions } from 'discord.js' ; export class PermissionUtils { public static canSend ( channel , embedLinks = false ) { if ( channel instanceof DMChannel ) { return true ; } else if ( channel instanceof GuildChannel ) { let channelPerms = channel . permissionsFor ( channel . client . user ) ; if ( ! channelPerms ) { return false ; } return channelPerms . has ( [ Permissions . FLAGS . VIEW_CHANNEL , Permissions . FLAGS . SEND_MESSAGES , ... ( embedLinks ? [ Permissions . FLAGS . EMBED_LINKS ] : [ ] ) , ] ) ; } else { return false ; } } public static canMention ( channel ) { if ( channel instanceof DMChannel ) { return true ; } else if ( channel instanceof GuildChannel ) { let channelPerms = channel . permissionsFor ( channel . client . user ) ; if ( ! channelPerms ) { return false ; } return channelPerms . has ( [ Permissions . FLAGS . VIEW_CHANNEL , Permissions . FLAGS . MENTION_EVERYONE , ] ) ; } else { return false ; } } public static canReact ( channel , removeOthers = false ) { if ( channel instanceof DMChannel ) { return true ; } else if ( channel instanceof GuildChannel ) { let channelPerms = channel . permissionsFor ( channel . client . user ) ; if ( ! channelPerms ) { return false ; } return channelPerms . has ( [ Permissions . FLAGS . VIEW_CHANNEL , Permissions . FLAGS . ADD_REACTIONS , Permissions . FLAGS . READ_MESSAGE_HISTORY , ... ( removeOthers ? [ Permissions . FLAGS . MANAGE_MESSAGES ] : [ ] ) , ] ) ; } else { return false ; } } public static canPin ( channel , unpinOld = false ) { if ( channel instanceof DMChannel ) { return true ; } else if ( channel instanceof GuildChannel ) { let channelPerms = channel . permissionsFor ( channel . client . user ) ; if ( ! channelPerms ) { return false ; } return channelPerms . has ( [ Permissions . FLAGS . VIEW_CHANNEL , Permissions . FLAGS . MANAGE_MESSAGES , ... ( unpinOld ? [ Permissions . FLAGS . READ_MESSAGE_HISTORY ] : [ ] ) , ] ) ; } else { return false ; } } }