diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-05-14 22:36:03 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-05-14 22:36:03 +0200 |
commit | 9fb7bf9491e8d88ee1244624d3dedd5cce018474 (patch) | |
tree | ba751cb38194e4f971586b88fb65014b300c1101 /src/util/Permissions.ts | |
parent | :bug: fix Database toObject (diff) | |
parent | 1.1.6 (diff) | |
download | server-9fb7bf9491e8d88ee1244624d3dedd5cce018474.tar.xz |
:bug: add MessageType enum
Diffstat (limited to 'src/util/Permissions.ts')
-rw-r--r-- | src/util/Permissions.ts | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/util/Permissions.ts b/src/util/Permissions.ts index 6b29248c..ab195813 100644 --- a/src/util/Permissions.ts +++ b/src/util/Permissions.ts @@ -6,6 +6,7 @@ import { ChannelPermissionOverwrite } from "../models/Channel"; import { Role, RoleModel } from "../models/Role"; import { BitField } from "./BitField"; import { GuildDocument, GuildModel } from "../models/Guild"; +// TODO: check role hierarchy permission var HTTPError: any; @@ -186,7 +187,7 @@ export class Permissions extends BitField { } export async function getPermission( - user_id: string, + user_id?: string, guild_id?: string, channel_id?: string, cache?: { channel?: ChannelDocument | null; member?: MemberDocument | null; guild?: GuildDocument | null } @@ -194,6 +195,8 @@ export async function getPermission( var { channel, member, guild } = cache || {}; var roles; + if (!user_id) throw new HTTPError("User not found"); + if (channel_id && !channel) { channel = await ChannelModel.findOne( { id: channel_id }, @@ -205,11 +208,11 @@ export async function getPermission( if (guild_id) { if (!guild) guild = await GuildModel.findOne({ id: guild_id }, { owner_id: true }).exec(); - if (!guild) throw new Error("Guild not found"); + if (!guild) throw new HTTPError("Guild not found"); if (guild.owner_id === user_id) return new Permissions(Permissions.FLAGS.ADMINISTRATOR); if (!member) member = await MemberModel.findOne({ guild_id, id: user_id }, "roles").exec(); - if (!member) throw new Error("Member not found"); + if (!member) throw new HTTPError("Member not found"); roles = await RoleModel.find({ guild_id, id: { $in: member.roles } }).exec(); } |