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 | |
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')
-rw-r--r-- | src/util/Constants.ts | 25 | ||||
-rw-r--r-- | src/util/Permissions.ts | 9 | ||||
-rw-r--r-- | src/util/String.ts | 4 |
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(); } |