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:
parent
14af94e7a3
commit
60aff76ebe
6 changed files with 137 additions and 12 deletions
10
backend/src/utils/canReadChannel.ts
Normal file
10
backend/src/utils/canReadChannel.ts
Normal 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,
|
||||
]);
|
||||
}
|
17
backend/src/utils/hasPermissions.ts
Normal file
17
backend/src/utils/hasPermissions.ts
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue