diff options
Diffstat (limited to 'src/util/Permissions.ts')
-rw-r--r-- | src/util/Permissions.ts | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/util/Permissions.ts b/src/util/Permissions.ts index 4bad70d3..fb7e0b88 100644 --- a/src/util/Permissions.ts +++ b/src/util/Permissions.ts @@ -147,21 +147,21 @@ export async function getPermission( user_id: string, guild_id: string, channel_id?: string, - cache?: { channel?: ChannelDocument | null; member?: MemberDocument | null } + cache?: { channel?: ChannelDocument | null; member?: MemberDocument | null; guild?: GuildDocument | null } ) { - var { channel, member } = cache || {}; + var { channel, member, guild } = cache || {}; - const guild = await GuildModel.findOne({ id: guild_id }, { owner_id: true }).exec(); + if (!guild) guild = await GuildModel.findOne({ id: guild_id }, { owner_id: true }).exec(); if (!guild) throw new Error("Guild not found"); if (guild.owner_id === user_id) return new Permissions(Permissions.FLAGS.ADMINISTRATOR); - member = await MemberModel.findOne({ guild_id, id: user_id }, "roles").exec(); + if (!member) 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 } }) .lean() .exec(); - if (channel_id) { + if (channel_id && !channel) { channel = await ChannelModel.findOne({ id: channel_id }, "permission_overwrites").exec(); } |