1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-10 12:42:44 +01:00

🎨 getPermission cache

This commit is contained in:
Flam3rboy 2021-03-03 21:24:34 +01:00
parent 0df97867bb
commit d85701a5b7
7 changed files with 33 additions and 17 deletions

View File

@ -16,7 +16,7 @@ declare class LongSchema extends mongoose.SchemaType {
handleSingle(val: any): any;
handleArray(val: any): any;
checkRequired(val: any): boolean;
cast(val: any, scope?: any, init?: any): any;
cast(val: any, scope?: any, init?: any, type?: string): any;
castForQuery($conditional: string, value: any): any;
}
declare module "mongoose" {

View File

@ -22,26 +22,30 @@ class LongSchema extends mongoose_1.default.SchemaType {
};
}
handleSingle(val) {
return this.cast(val);
return this.cast(val, null, null, "handle");
}
handleArray(val) {
var self = this;
return val.map(function (m) {
return self.cast(m);
return self.cast(m, null, null, "handle");
});
}
checkRequired(val) {
return null != val;
}
cast(val, scope, init) {
cast(val, scope, init, type) {
if (null === val)
return val;
if ("" === val)
return null;
if (typeof val === "bigint")
if (typeof val === "bigint" && type === "query") {
return mongoose_1.default.mongo.Long.fromString(val.toString());
if (val instanceof mongoose_1.default.mongo.Long)
}
if (val instanceof mongoose_1.default.mongo.Long) {
if (type === "handle" || init == false)
return val;
return BigInt(val.toString());
}
if (val instanceof Number || "number" == typeof val)
return BigInt(val);
if (!Array.isArray(val) && val.toString)
@ -60,7 +64,7 @@ class LongSchema extends mongoose_1.default.SchemaType {
return handler.call(this, value);
}
else {
return this.cast($conditional);
return this.cast($conditional, null, null, "query");
}
}
}

View File

@ -1 +1 @@
{"version":3,"file":"MongoBigInt.js","sourceRoot":"","sources":["../../src/util/MongoBigInt.ts"],"names":[],"mappings":";;;;;AAAA,wDAAgC;AAEhC,MAAM,UAAW,SAAQ,kBAAQ,CAAC,UAAU;IAA5C;;QACQ,yBAAoB,GAAG;YAC7B,GAAG,EAAE,IAAI,CAAC,YAAY;YACtB,IAAI,EAAE,IAAI,CAAC,YAAY;YACvB,GAAG,EAAE,IAAI,CAAC,YAAY;Y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;AACxC,kBAAQ,CAAC,KAAK,CAAC,IAAI,GAAG,kBAAQ,CAAC,KAAK,CAAC,IAAI,CAAC"}

View File

@ -1,3 +1,5 @@
import { MemberDocument } from "../models/Member";
import { ChannelDocument } from "../models/Channel";
import { ChannelPermissionOverwrite } from "../models/Channel";
import { Role } from "../models/Role";
import { BitField } from "./BitField";
@ -57,5 +59,8 @@ export declare class Permissions extends BitField {
};
}): bigint;
}
export declare function getPermission(user_id: bigint, guild_id: bigint, channel_id?: bigint): Promise<Permissions>;
export declare function getPermission(user_id: bigint, guild_id: bigint, channel_id?: bigint, cache?: {
channel: ChannelDocument | null;
member: MemberDocument | null;
}): Promise<Permissions>;
export {};

View File

@ -85,12 +85,12 @@ Permissions.FLAGS = {
MANAGE_WEBHOOKS: 1n << 29n,
MANAGE_EMOJIS: 1n << 30n,
};
async function getPermission(user_id, guild_id, channel_id) {
var member = await Member_1.MemberModel.findOne({ guild_id, id: user_id }, "roles").exec();
async function getPermission(user_id, guild_id, channel_id, cache) {
var { channel, member } = cache || {};
member = await Member_1.MemberModel.findOne({ guild_id, id: user_id }, "roles").exec();
if (!member)
throw new Error("Member not found");
var roles = await Role_1.RoleModel.find({ guild_id, id: { $in: member.roles } }).exec();
let channel = null;
if (channel_id) {
channel = await Channel_1.ChannelModel.findOne({ id: channel_id }, "permission_overwrites").exec();
}

View File

@ -1 +1 @@
{"version":3,"file":"Permissions.js","sourceRoot":"","sources":["../../src/util/Permissions.ts"],"names":[],"mappings":";;;AAAA,8EAA8E;AAC9E,8DAA8D;AAC9D,6CAA+C;AAC/C,+CAAkE;AAElE,yCAAiD;AACjD,yCAAsC;AAqCtC,MAAM,wBAAwB,GAAG,EAAE,IAAI,GAAG,CAAC,CAAC,qEAAqE;AAEjH,MAAa,WAAY,SAAQ,mBAAQ;IAqCxC,GAAG,CAAC,UAAgC,EAAE,UAAU,GAAG,IAAI;QACtD,OAAO,CAAC,UAAU,IAAI,KAAK,CAAC,GAAG,CAAC,WAAW,CAA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AAM,oBAAW,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9E,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAEjD,IAAI,KAAK,GAAG,MAAM,gBAAS,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACjF,IAAI,UAAU,EAAE;QACf,OAAO,GAAG,MAAM,sBAAY,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,uBAAuB,CAAC,CAAC,IAAI,EAAE,CAAC;KACzF;IAED,IAAI,UAAU,GAAG,WAAW,CAAC,eAAe,CAAC;QAC5C,IAAI,EAAE;YACL,EAAE,EAAE,OAAO;YACX,KAAK,EAAE,MAAM,CAAC,KAAK;SACnB;QACD,KAAK,EAAE;YACN,KAAK,EAAE,KAAK;SACZ;QACD,OAAO,EAAE;YACR,UAAU,EAAE,OAAO,EAAE,qBAAqB;SAC1C;KACD,CAAC,CAAC;IAEH,OAAO,IAAI,WAAW,CAAC,UAAU,CAAC,CAAC;AACpC,CAAC;AA9BD,sCA8BC"}

View File

@ -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();
}