summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/util/Constants.ts25
-rw-r--r--src/util/Permissions.ts9
-rw-r--r--src/util/String.ts4
3 files changed, 33 insertions, 5 deletions
diff --git a/src/util/Constants.ts b/src/util/Constants.ts
index 808d234b..bda53174 100644
--- a/src/util/Constants.ts
+++ b/src/util/Constants.ts
@@ -1,3 +1,28 @@
 import { VerifyOptions } from "jsonwebtoken";
 
 export const JWTOptions: VerifyOptions = { algorithms: ["HS256"] };
+
+export enum MessageType {
+	DEFAULT,
+	RECIPIENT_ADD,
+	RECIPIENT_REMOVE,
+	CALL,
+	CHANNEL_NAME_CHANGE,
+	CHANNEL_ICON_CHANGE,
+	CHANNEL_PINNED_MESSAGE,
+	GUILD_MEMBER_JOIN,
+	USER_PREMIUM_GUILD_SUBSCRIPTION,
+	USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1,
+	USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2,
+	USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3,
+	CHANNEL_FOLLOW_ADD,
+	GUILD_DISCOVERY_DISQUALIFIED,
+	GUILD_DISCOVERY_REQUALIFIED,
+	GUILD_DISCOVERY_GRACE_PERIOD_INITIAL_WARNING,
+	GUILD_DISCOVERY_GRACE_PERIOD_FINAL_WARNING,
+	THREAD_CREATED,
+	REPLY,
+	APPLICATION_COMMAND,
+	THREAD_STARTER_MESSAGE,
+	GUILD_INVITE_REMINDER,
+}
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();
 	}
diff --git a/src/util/String.ts b/src/util/String.ts
index bac7905f..55f11e8d 100644
--- a/src/util/String.ts
+++ b/src/util/String.ts
@@ -1,7 +1,7 @@
-import { DOUBLE_WHITE_SPACE, SPECIAL_CHAR } from "./Regex";
+import { SPECIAL_CHAR } from "./Regex";
 
 export function trimSpecial(str?: string): string {
 	// @ts-ignore
 	if (!str) return;
-	return str.replace(SPECIAL_CHAR, "").replace(DOUBLE_WHITE_SPACE, " ").trim();
+	return str.replace(SPECIAL_CHAR, "").trim();
 }