summary refs log tree commit diff
path: root/src/util/Permissions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/Permissions.ts')
-rw-r--r--src/util/Permissions.ts9
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();
 	}