diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-03-03 21:24:34 +0100 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-03-03 21:24:34 +0100 |
commit | d85701a5b7fde84fa482de49c0f06a9ec90e1815 (patch) | |
tree | ec5b97c9098ad89ef146641589f5ded4dce902f3 /src/util | |
parent | :construction: custom permissions (diff) | |
download | server-d85701a5b7fde84fa482de49c0f06a9ec90e1815.tar.xz |
:art: getPermission cache
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/Permissions.ts | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/util/Permissions.ts b/src/util/Permissions.ts index 6d14e9a3..96a1a27c 100644 --- a/src/util/Permissions.ts +++ b/src/util/Permissions.ts @@ -1,10 +1,11 @@ // https://github.com/discordjs/discord.js/blob/master/src/util/Permissions.js // Apache License Version 2.0 Copyright 2015 - 2021 Amish Shah -import { MemberModel } from "../models/Member"; +import { MemberDocument, MemberModel } from "../models/Member"; import { ChannelDocument, ChannelModel } from "../models/Channel"; import { ChannelPermissionOverwrite } from "../models/Channel"; import { Role, RoleModel } from "../models/Role"; import { BitField } from "./BitField"; +import { GuildDocument } from "../models/Guild"; export type PermissionResolvable = bigint | number | Permissions | PermissionResolvable[] | PermissionString; @@ -142,12 +143,18 @@ export class Permissions extends BitField { } } -export async function getPermission(user_id: bigint, guild_id: bigint, channel_id?: bigint) { - var member = await MemberModel.findOne({ guild_id, id: user_id }, "roles").exec(); +export async function getPermission( + user_id: bigint, + guild_id: bigint, + channel_id?: bigint, + cache?: { channel: ChannelDocument | null; member: MemberDocument | null } +) { + var { channel, member } = cache || {}; + + member = await MemberModel.findOne({ guild_id, id: user_id }, "roles").exec(); if (!member) throw new Error("Member not found"); var roles = await RoleModel.find({ guild_id, id: { $in: member.roles } }).exec(); - let channel: ChannelDocument | null = null; if (channel_id) { channel = await ChannelModel.findOne({ id: channel_id }, "permission_overwrites").exec(); } |