3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

!source: don't show source of messages you don't have access to; allow mods to use the command by default

This commit is contained in:
Dragory 2020-08-05 23:57:09 +03:00
parent 14af94e7a3
commit 60aff76ebe
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
6 changed files with 137 additions and 12 deletions

View file

@ -0,0 +1,10 @@
import { Constants, GuildChannel } from "eris";
import { hasPermissions } from "./hasPermissions";
export function canReadChannel(channel: GuildChannel, memberId: string) {
const channelPermissions = channel.permissionsOf(memberId);
return hasPermissions(channelPermissions, [
Constants.Permissions.readMessages,
Constants.Permissions.readMessageHistory,
]);
}

View file

@ -0,0 +1,17 @@
import { Constants, Permission } from "eris";
export function hasPermissions(channelPermissions: Permission, permissions: number | number[]) {
if (Boolean(channelPermissions.allow & Constants.Permissions.administrator)) {
return true;
}
if (!Array.isArray(permissions)) {
permissions = [permissions];
}
for (const permission of permissions) {
if (!(channelPermissions.allow & permission)) return false;
}
return true;
}