diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-02-13 23:57:02 +0100 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-02-13 23:57:02 +0100 |
commit | 52964aed06c879ac31987e4c487de9c66292e0c2 (patch) | |
tree | 9dbda022933d8b93e66f2ce5c51e25ba1b0b208e | |
parent | :bug: export MongooseCache (diff) | |
download | server-52964aed06c879ac31987e4c487de9c66292e0c2.tar.xz |
:art: Channel + Member + Message + Role in separate collection
-rw-r--r-- | dist/models/Channel.d.ts | 17 | ||||
-rw-r--r-- | dist/models/Channel.js | 7 | ||||
-rw-r--r-- | dist/models/Channel.js.map | 2 | ||||
-rw-r--r-- | dist/models/Member.d.ts | 1 | ||||
-rw-r--r-- | dist/models/Member.js | 1 | ||||
-rw-r--r-- | dist/models/Member.js.map | 2 | ||||
-rw-r--r-- | dist/models/Message.d.ts | 1 | ||||
-rw-r--r-- | dist/models/Message.js | 1 | ||||
-rw-r--r-- | dist/models/Message.js.map | 2 | ||||
-rw-r--r-- | dist/models/Role.d.ts | 1 | ||||
-rw-r--r-- | dist/models/Role.js | 1 | ||||
-rw-r--r-- | dist/models/Role.js.map | 2 | ||||
-rw-r--r-- | dist/util/Permissions.d.ts | 16 | ||||
-rw-r--r-- | dist/util/Permissions.js | 32 | ||||
-rw-r--r-- | dist/util/Permissions.js.map | 2 | ||||
-rw-r--r-- | src/models/Channel.ts | 19 | ||||
-rw-r--r-- | src/models/Member.ts | 2 | ||||
-rw-r--r-- | src/models/Message.ts | 2 | ||||
-rw-r--r-- | src/models/Role.ts | 2 | ||||
-rw-r--r-- | src/util/Permissions.ts | 47 |
20 files changed, 142 insertions, 18 deletions
diff --git a/dist/models/Channel.d.ts b/dist/models/Channel.d.ts index 6caf7238..289f77c6 100644 --- a/dist/models/Channel.d.ts +++ b/dist/models/Channel.d.ts @@ -19,12 +19,17 @@ export interface GuildChannel extends Channel { guild_id: bigint; position: number; parent_id?: bigint; - permission_overwrites: { - allow: bigint; - deny: bigint; - id: bigint; - type: number; - }[]; + permission_overwrites: ChannelPermissionOverwrite[]; +} +export interface ChannelPermissionOverwrite { + allow: bigint; + deny: bigint; + id: bigint; + type: ChannelPermissionOverwriteType; +} +export declare enum ChannelPermissionOverwriteType { + role = 0, + member = 1 } export interface VoiceChannel extends GuildChannel { } diff --git a/dist/models/Channel.js b/dist/models/Channel.js index d4b50395..7be246d7 100644 --- a/dist/models/Channel.js +++ b/dist/models/Channel.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.ChannelType = exports.ChannelModel = exports.ChannelSchema = void 0; +exports.ChannelType = exports.ChannelPermissionOverwriteType = exports.ChannelModel = exports.ChannelSchema = void 0; const mongoose_1 = require("mongoose"); exports.ChannelSchema = new mongoose_1.Schema({ id: mongoose_1.Types.Long, @@ -27,6 +27,11 @@ exports.ChannelSchema = new mongoose_1.Schema({ ], }); exports.ChannelModel = mongoose_1.model("Channel", exports.ChannelSchema, "channels"); +var ChannelPermissionOverwriteType; +(function (ChannelPermissionOverwriteType) { + ChannelPermissionOverwriteType[ChannelPermissionOverwriteType["role"] = 0] = "role"; + ChannelPermissionOverwriteType[ChannelPermissionOverwriteType["member"] = 1] = "member"; +})(ChannelPermissionOverwriteType = exports.ChannelPermissionOverwriteType || (exports.ChannelPermissionOverwriteType = {})); var ChannelType; (function (ChannelType) { ChannelType[ChannelType["GUILD_TEXT"] = 0] = "GUILD_TEXT"; diff --git a/dist/models/Channel.js.map b/dist/models/Channel.js.map index 768272eb..cba13d65 100644 --- a/dist/models/Channel.js.map +++ b/dist/models/Channel.js.map @@ -1 +1 @@ -{"version":3,"file":"Channel.js","sourceRoot":"","sources":["../../src/models/Channel.ts"],"names":[],"mappings":";;;AAAA,uCAA0D;AAM7C,QAAA,aAAa,GAAG,IAAI,iBAAM,CAAC;IACvC,EAAE,EAAE,gBAAK,CAAC,IAAI;IACd,UAAU,EAAE,EAAE,IAAI,EAAE,iBAAM,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE;IACvD,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACtC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACtC,QAAQ,EAAE,gBAAK,CAAC,IAAI;IACpB,QAAQ,EAAE,gBAAK,CAAC,IAAI;IACpB,SAAS,EAAE,gBAAK,CAAC,IAAI;IACrB,UAAU,EAAE,CAAC,gBAAK,CAAC,IAAI,CAAC;IACxB,QAAQ,EAAE,MAAM;IAChB,eAAe,EAAE,gBAAK,CAAC,IAAI;IAC3B,kBAAkB,EAAE,IAAI;IACxB,IAAI,EAAE,OAAO;IACb,mBAAmB,EAAE,MAAM;IAC3B,KAAK,EAAE,MAAM;IACb,qBAAqB,EAAE;QACtB;YACC,KAAK,EAAE,gBAAK,CAAC,IAAI;YACjB,IAAI,EAAE,gBAAK,CAAC,IAAI;YAChB,EAAE,EAAE,gBAAK,CAAC,IAAI;YACd,IAAI,EAAE,MAAM;SACZ;KACD;CACD,CAAC,CAAC;AAEU,QAAA,YAAY,GAAG,gBAAK,CAAkB,SAAS,EAAE,qBAAa,EAAE,UAAU,CAAC,CAAC;AAuCzF,IAAY,WAQX;AARD,WAAY,WAAW;IACtB,yDAAc,CAAA;IACd,yCAAM,CAAA;IACN,2DAAe,CAAA;IACf,qDAAY,CAAA;IACZ,iEAAkB,CAAA;IAClB,yDAAc,CAAA;IACd,2DAAe,CAAA;AAChB,CAAC,EARW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAQtB"} \ No newline at end of file +{"version":3,"file":"Channel.js","sourceRoot":"","sources":["../../src/models/Channel.ts"],"names":[],"mappings":";;;AAAA,uCAA0D;AAM7C,QAAA,aAAa,GAAG,IAAI,iBAAM,CAAC;IACvC,EAAE,EAAE,gBAAK,CAAC,IAAI;IACd,UAAU,EAAE,EAAE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d.ts index e55fdb91..e4fc1fa7 100644 --- a/dist/models/Member.d.ts +++ b/dist/models/Member.d.ts @@ -3,6 +3,7 @@ import { PublicUser } from "./User"; import { Schema, Document } from "mongoose"; export interface Member extends Document { id: bigint; + guild_id: bigint; nick?: string; roles: bigint[]; joined_at: number; diff --git a/dist/models/Member.js b/dist/models/Member.js index b4aebf0a..fcce8c6a 100644 --- a/dist/models/Member.js +++ b/dist/models/Member.js @@ -8,6 +8,7 @@ const MuteConfig = { }; exports.MemberSchema = new mongoose_1.Schema({ id: mongoose_1.Types.Long, + guild_id: mongoose_1.Types.Long, nick: String, roles: [mongoose_1.Types.Long], joined_at: Number, diff --git a/dist/models/Member.js.map b/dist/models/Member.js.map index 4e9996c3..788f06fc 100644 --- a/dist/models/Member.js.map +++ b/dist/models/Member.js.map @@ -1 +1 @@ -{"version":3,"file":"Member.js","sourceRoot":"","sources":["../../src/models/Member.ts"],"names":[],"mappings":";;;AACA,uCAA0D;AAoC1D,MAAM,UAAU,GAAG;IAClB,QAAQ,EAAE,MAAM;IAChB,oBAAoB,EAAE,MAAM;CAC5B,CAAC;AAEW,QAAA,YAAY,GAAG,IAAI,iBAAM,CAAC;IACtC,EAAE,EAAE,gBAAK,CAAC,IAAI;IACd,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,CAAC,gBAAK,CAAC,IAAI,CAAC;IACnB,SAAS,EAAE,MAAM;IACjB,aAAa,EAAE,MAAM;IACrB,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,OAAO;IACb,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,gBAAK,CAAC,IAAI;IACvB,QAAQ,EAAE;QACT,iBAAiB,EAAE;YAClB;gBACC,UAAU,EAAE,gBAAK,CAAC,IAAI;gBACtB,qBAAqB,EAAE,MAAM;gBAC7B,WAAW,EAAE,UAAU;gBACvB,KAAK,EAAE,OAAO;aACd;SACD;QACD,qBAAqB,EAAE,MAAM;QAC7B,WAAW,EAAE,OAAO;QACpB,WAAW,EAAE,UAAU;QACvB,KAAK,EAAE,OAAO;QACd,iBAAiB,EAAE,OAAO;QAC1B,cAAc,EAAE,OAAO;QACvB,OAAO,EAAE,MAAM;KACf;CACD,CAAC,CAAC;AAEU,QAAA,WAAW,GAAG,gBAAK,CAAS,QAAQ,EAAE,oBAAY,EAAE,SAAS,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"Member.js","sourceRoot":"","sources":["../../src/models/Member.ts"],"names":[],"mappings":";;;AACA,uCAA0D;AAqC1D,MAAM,UAAU,GAAG;IAClB,QAAQ,EAAE,MAAM;IAChB,oBAAoB,EAAE,MAAM;CAC5B,CAAC;AAEW,QAAA,YAAY,GAAG,IAAI,iBAAM,CAAC;IACtC,EAAE,EAAE,gBAAK,CAAC,IAAI;IACd,QAAQ,EAAE,gBAAK,CAAC,IAAI;IACpB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,CAAC,gBAAK,CAAC,IAAI,CAAC;IACnB,SAAS,EAAE,MAAM;IACjB,aAAa,EAAE,MAAM;IACrB,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,OAAO;IACb,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,gBAAK,CAAC,IAAI;IACvB,QAAQ,EAAE;QACT,iBAAiB,EAAE;YAClB;gBACC,UAAU,EAAE,gBAAK,CAAC,IAAI;gBACtB,qBAAqB,EAAE,MAAM;gBAC7B,WAAW,EAAE,UAAU;gBACvB,KAAK,EAAE,OAAO;aACd;SACD;QACD,qBAAqB,EAAE,MAAM;QAC7B,WAAW,EAAE,OAAO;QACpB,WAAW,EAAE,UAAU;QACvB,KAAK,EAAE,OAAO;QACd,iBAAiB,EAAE,OAAO;QAC1B,cAAc,EAAE,OAAO;QACvB,OAAO,EAAE,MAAM;KACf;CACD,CAAC,CAAC;AAEU,QAAA,WAAW,GAAG,gBAAK,CAAS,QAAQ,EAAE,oBAAY,EAAE,SAAS,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/models/Message.d.ts b/dist/models/Message.d.ts index 9ff70b2c..57bb0d6a 100644 --- a/dist/models/Message.d.ts +++ b/dist/models/Message.d.ts @@ -3,6 +3,7 @@ import { Schema, Document } from "mongoose"; import { ChannelType } from "./Channel"; export interface Message extends Document { id: bigint; + channel_id: bigint; author_id?: bigint; webhook_id?: bigint; application_id: bigint; diff --git a/dist/models/Message.js b/dist/models/Message.js index 40808f96..f5c27223 100644 --- a/dist/models/Message.js +++ b/dist/models/Message.js @@ -81,6 +81,7 @@ const Embed = { }; exports.MessageSchema = new mongoose_1.Schema({ id: mongoose_1.Types.Long, + channel_id: mongoose_1.Types.Long, author_id: mongoose_1.Types.Long, webhook_id: mongoose_1.Types.Long, application_id: mongoose_1.Types.Long, diff --git a/dist/models/Message.js.map b/dist/models/Message.js.map index 6c165ffb..4e20ace6 100644 --- a/dist/models/Message.js.map +++ b/dist/models/Message.js.map @@ -1 +1 @@ -{"version":3,"file":"Message.js","sourceRoot":"","sources":["../../src/models/Message.ts"],"names":[],"mappings":";;;AAAA,uCAA0D;AAC1D,uCAAwC;AAuCxC,IAAY,WAkBX;AAlBD,WAAY,WAAW;IACtB,mDAAW,CAAA;IACX,+DAAiB,CAAA;IACjB,qEAAoB,CAAA;IACpB,6CAAQ,CAAA;IACR,2EAAuB,CAAA;IACvB,2EAAuB,CAAA;IACvB,iFAA0B,CAAA;IAC1B,uEAAqB,CAAA;IACrB,mGAAmC,CAAA;IACnC,iHAA0C,CAAA;IAC1C,kHAA2C,CAAA;IAC3C,kHAA2C,CAAA;IAC3C,0EAAuB,CAAA;IACvB,8FAAiC,CAAA;IACjC,4FAAgC,CAAA;IAChC,gDAAU,CAAA;IACV,4EAAwB,CAAA;AACzB,CAAC,EAlBW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAkBtB;AAsED,MAAM,UAAU,GAAG;IAClB,EAAE,EAAE,gBAAK,CAAC,IAAI;IACd,QAAQ,EAAE,MAAM;IAChB,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,MAAM;IACX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EAAE,MAAM;IACjB,gBAAgB,EAAE,MAAM;IACxB,GAAG,EAAE,OAAO;IACZ,gBAAgB,EAAE,OAAO;IACzB,QAAQ,EAAE,CAAC,gBAAK,CAAC,IAAI,CAAC;IACtB,aAAa,EAAE,CAAC,gBAAK,CAAC,IAAI,CAAC;IAC3B,gBAAgB,EAAE;QACjB;YACC,EAAE,EAAE,gBAAK,CAAC,IAAI;YACd,QAAQ,EAAE,gBAAK,CAAC,IAAI;YACpB,IAAI,EAAE,qBAAW;YACjB,IAAI,EAAE,MAAM;SACZ;KACD;IACD,WAAW,EAAE,CAAC,UAAU,CAAC;IACzB,MAAM,EAAE,CAAC,KAAK,CAAC;IACf,SAAS,EAAE,CAAC,QAAQ,CAAC;IACrB,KAAK,EAAE,iBAAM,CAAC,KAAK,CAAC,KAAK;IACzB,MAAM,EAAE,OAAO;IACf,IAAI,EAAE,WAAW;IACjB,QAAQ,EAAE;QACT,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,MAAM;KAChB;IACD,KAAK,EAAE,gBAAK,CAAC,IAAI;IACjB,QAAQ,EAAE,EAAE;IACZ,iBAAiB,EAAE;QAClB,UAAU,EAAE,gBAAK,CAAC,IAAI;QACtB,UAAU,EAAE,gBAAK,CAAC,IAAI;QACtB,QAAQ,EAAE,gBAAK,CAAC,IAAI;KACpB;CACD,CAAC,CAAC;AAEU,QAAA,YAAY,GAAG,gBAAK,CAAU,SAAS,EAAE,qBAAa,EAAE,UAAU,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"Message.js","sourceRoot":"","sources":["../../src/models/Message.ts"],"names":[],"mappings":";;;AAAA,uCAA0D;AAC1D,uCAAwC;AAwCxC,IAAY,WAkBX;AAlBD,WAAY,WAAW;IACtB,mDAAW,CAAA;IACX,+DAAiB,CAAA;IACjB,qEAAoB,CAAA;IACpB,6CAAQ,CAAA;IACR,2EAAuB,CAAA;IACvB,2EAAuB,CAAA;IACvB,iFAA0B,CAAA;IAC1B,uEAAqB,CA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,CAAC,IAAI;KACpB;CACD,CAAC,CAAC;AAEU,QAAA,YAAY,GAAG,gBAAK,CAAU,SAAS,EAAE,qBAAa,EAAE,UAAU,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/models/Role.d.ts b/dist/models/Role.d.ts index a65b0e13..bdb10557 100644 --- a/dist/models/Role.d.ts +++ b/dist/models/Role.d.ts @@ -2,6 +2,7 @@ import { Schema, Document } from "mongoose"; export interface Role extends Document { id: bigint; + guild_id: bigint; color: number; hoist: boolean; managed: boolean; diff --git a/dist/models/Role.js b/dist/models/Role.js index 9a0d0932..41b385fc 100644 --- a/dist/models/Role.js +++ b/dist/models/Role.js @@ -4,6 +4,7 @@ exports.RoleModel = exports.RoleSchema = void 0; const mongoose_1 = require("mongoose"); exports.RoleSchema = new mongoose_1.Schema({ id: mongoose_1.Types.Long, + guild_id: mongoose_1.Types.Long, color: Number, hoist: Boolean, managed: Boolean, diff --git a/dist/models/Role.js.map b/dist/models/Role.js.map index 34adaaa5..08a55b2c 100644 --- a/dist/models/Role.js.map +++ b/dist/models/Role.js.map @@ -1 +1 @@ -{"version":3,"file":"Role.js","sourceRoot":"","sources":["../../src/models/Role.ts"],"names":[],"mappings":";;;AAAA,uCAA0D;AAgB7C,QAAA,UAAU,GAAG,IAAI,iBAAM,CAAC;IACpC,EAAE,EAAE,gBAAK,CAAC,IAAI;IACd,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,OAAO;IACpB,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,gBAAK,CAAC,IAAI;IACvB,QAAQ,EAAE,MAAM;IAChB,IAAI,EAAE;QACL,MAAM,EAAE,gBAAK,CAAC,IAAI;KAClB;CACD,CAAC,CAAC;AAEU,QAAA,SAAS,GAAG,gBAAK,CAAO,MAAM,EAAE,kBAAU,EAAE,OAAO,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"Role.js","sourceRoot":"","sources":["../../src/models/Role.ts"],"names":[],"mappings":";;;AAAA,uCAA0D;AAiB7C,QAAA,UAAU,GAAG,IAAI,iBAAM,CAAC;IACpC,EAAE,EAAE,gBAAK,CAAC,IAAI;IACd,QAAQ,EAAE,gBAAK,CAAC,IAAI;IACpB,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,OAAO;IACpB,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,gBAAK,CAAC,IAAI;IACvB,QAAQ,EAAE,MAAM;IAChB,IAAI,EAAE;QACL,MAAM,EAAE,gBAAK,CAAC,IAAI;KAClB;CACD,CAAC,CAAC;AAEU,QAAA,SAAS,GAAG,gBAAK,CAAO,MAAM,EAAE,kBAAU,EAAE,OAAO,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/util/Permissions.d.ts b/dist/util/Permissions.d.ts index a022038a..80d94803 100644 --- a/dist/util/Permissions.d.ts +++ b/dist/util/Permissions.d.ts @@ -1,3 +1,5 @@ +import { ChannelPermissionOverwrite } from "../models/Channel"; +import { Role } from "../models/Role"; import { BitField } from "./BitField"; export declare type PermissionResolvable = string | number | Permissions | PermissionResolvable[]; export declare class Permissions extends BitField { @@ -39,4 +41,18 @@ export declare class Permissions extends BitField { * Checks whether the bitfield has a permission, or multiple permissions. */ has(permission: PermissionResolvable, checkAdmin?: boolean): boolean; + static channelPermission(overwrites: ChannelPermissionOverwrite[], init?: bigint): bigint; + static rolePermission(roles: Role[]): bigint; + static finalPermission({ user, guild, channel, }: { + user: { + id: bigint; + roles: bigint[]; + }; + guild: { + roles: Role[]; + }; + channel?: { + overwrites: ChannelPermissionOverwrite[]; + }; + }): bigint; } diff --git a/dist/util/Permissions.js b/dist/util/Permissions.js index b594ff89..0686e273 100644 --- a/dist/util/Permissions.js +++ b/dist/util/Permissions.js @@ -14,6 +14,38 @@ class Permissions extends BitField_1.BitField { has(permission, checkAdmin = true) { return (checkAdmin && super.has(Permissions.FLAGS.ADMINISTRATOR)) || super.has(permission); } + static channelPermission(overwrites, init) { + // channelOverwrites.filter((x) => x.type === 1 && x.id !== user.id); + return overwrites.reduce((permission, overwrite) => { + // apply disallowed permission + // * permission: current calculated permission (e.g. 010) + // * deny contains all denied permissions (e.g. 011) + // * allow contains all explicitly allowed permisions (e.g. 100) + return (permission & ~overwrite.deny) | overwrite.allow; + // ~ operator inverts deny (e.g. 011 -> 100) + // & operator only allows 1 for both ~deny and permission (e.g. 010 & 100 -> 000) + // | operators adds both together (e.g. 000 + 100 -> 100) + }, 0n ?? init); + } + static rolePermission(roles) { + // adds all permissions of all roles together (Bit OR) + return roles.reduce((permission, role) => permission | role.permissions, 0n); + } + static finalPermission({ user, guild, channel, }) { + let roles = guild.roles.filter((x) => user.roles.includes(x.id)); + let permission = Permissions.rolePermission(roles); + if (channel?.overwrites) { + let overwrites = channel.overwrites.filter((x) => { + if (x.type === 0 && user.roles.includes(x.id)) + return true; + if (x.type === 1 && x.id == user.id) + return true; + return false; + }); + permission = Permissions.channelPermission(overwrites, permission); + } + return permission; + } } exports.Permissions = Permissions; Permissions.FLAGS = { diff --git a/dist/util/Permissions.js.map b/dist/util/Permissions.js.map index b392596f..6b548f8c 100644 --- a/dist/util/Permissions.js.map +++ b/dist/util/Permissions.js.map @@ -1 +1 @@ -{"version":3,"file":"Permissions.js","sourceRoot":"","sources":["../../src/util/Permissions.ts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,8DAA8D;;;AAE9D,yCAAsC;AAItC,MAAa,WAAY,SAAQ,mBAAQ;IAmCxC,GAAG,CAAC,UAAgC,EAAE,UAAU,GAAG,IAAI;QACtD,OAAO,CAAC,UAAU,IAAI,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC5F,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,UAAgC,EAAE,UAAU,GAAG,IAAI;QAC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;IACxB,gBAAgB,EAAE,EAAE,IAAI,EAAE;IAC1B,MAAM,EAAE,EAAE,IAAI,EAAE;IAChB,YAAY,EAAE,EAAE,IAAI,GAAG;IACvB,aAAa,EAAE,EAAE,IAAI,GAAG;IACxB,iBAAiB,EAAE,EAAE,IAAI,GAAG;IAC5B,eAAe,EAAE,EAAE,IAAI,GAAG;IAC1B,WAAW,EAAE,EAAE,IAAI,GAAG;IACtB,YAAY,EAAE,EAAE,IAAI,GAAG;IACvB,oBAAoB,EAAE,EAAE,IAAI,GAAG;IAC/B,gBAAgB,EAAE,EAAE,IAAI,GAAG;IAC3B,mBAAmB,EAAE,EAAE,IAAI,GAAG;IAC9B,mBAAmB,EAAE,EAAE,IAAI,GAAG;IAC9B,OAAO,EAAE,EAAE,IAAI,GAAG;IAClB,KAAK,EAAE,EAAE,IAAI,GAAG;IAChB,YAAY,EAAE,EAAE,IAAI,GAAG;IACvB,cAAc,EAAE,EAAE,IAAI,GAAG;IACzB,YAAY,EAAE,EAAE,IAAI,GAAG;IACvB,OAAO,EAAE,EAAE,IAAI,GAAG;IAClB,eAAe,EAAE,EAAE,IAAI,GAAG;IAC1B,gBAAgB,EAAE,EAAE,IAAI,GAAG;IAC3B,YAAY,EAAE,EAAE,IAAI,GAAG;IACvB,eAAe,EAAE,EAAE,IAAI,GAAG;IAC1B,aAAa,EAAE,EAAE,IAAI,GAAG;CACxB,CAAC"} \ No newline at end of file diff --git a/src/models/Channel.ts b/src/models/Channel.ts index 36f5e83d..3c63f80f 100644 --- a/src/models/Channel.ts +++ b/src/models/Channel.ts @@ -47,12 +47,19 @@ export interface GuildChannel extends Channel { guild_id: bigint; position: number; parent_id?: bigint; - permission_overwrites: { - allow: bigint; - deny: bigint; - id: bigint; - type: number; - }[]; + permission_overwrites: ChannelPermissionOverwrite[]; +} + +export interface ChannelPermissionOverwrite { + allow: bigint; + deny: bigint; + id: bigint; + type: ChannelPermissionOverwriteType; +} + +export enum ChannelPermissionOverwriteType { + role = 0, + member = 1, } export interface VoiceChannel extends GuildChannel {} diff --git a/src/models/Member.ts b/src/models/Member.ts index d9f34ac8..dd26782f 100644 --- a/src/models/Member.ts +++ b/src/models/Member.ts @@ -3,6 +3,7 @@ import { Schema, model, Types, Document } from "mongoose"; export interface Member extends Document { id: bigint; + guild_id: bigint; nick?: string; roles: bigint[]; joined_at: number; @@ -42,6 +43,7 @@ const MuteConfig = { export const MemberSchema = new Schema({ id: Types.Long, + guild_id: Types.Long, nick: String, roles: [Types.Long], joined_at: Number, diff --git a/src/models/Message.ts b/src/models/Message.ts index 22569d8f..9b3602c4 100644 --- a/src/models/Message.ts +++ b/src/models/Message.ts @@ -3,6 +3,7 @@ import { ChannelType } from "./Channel"; export interface Message extends Document { id: bigint; + channel_id: bigint; author_id?: bigint; webhook_id?: bigint; application_id: bigint; @@ -188,6 +189,7 @@ const Embed = { export const MessageSchema = new Schema({ id: Types.Long, + channel_id: Types.Long, author_id: Types.Long, webhook_id: Types.Long, application_id: Types.Long, diff --git a/src/models/Role.ts b/src/models/Role.ts index d35bd57c..b6cba2f8 100644 --- a/src/models/Role.ts +++ b/src/models/Role.ts @@ -2,6 +2,7 @@ import { Schema, model, Types, Document } from "mongoose"; export interface Role extends Document { id: bigint; + guild_id: bigint; color: number; hoist: boolean; managed: boolean; @@ -16,6 +17,7 @@ export interface Role extends Document { export const RoleSchema = new Schema({ id: Types.Long, + guild_id: Types.Long, color: Number, hoist: Boolean, managed: Boolean, diff --git a/src/util/Permissions.ts b/src/util/Permissions.ts index c3dcdb53..89e1d1d3 100644 --- a/src/util/Permissions.ts +++ b/src/util/Permissions.ts @@ -1,6 +1,8 @@ // https://github.com/discordjs/discord.js/blob/master/src/util/Permissions.js // Apache License Version 2.0 Copyright 2015 - 2021 Amish Shah +import { ChannelPermissionOverwrite } from "../models/Channel"; +import { Role } from "../models/Role"; import { BitField } from "./BitField"; export type PermissionResolvable = string | number | Permissions | PermissionResolvable[]; @@ -50,4 +52,49 @@ export class Permissions extends BitField { has(permission: PermissionResolvable, checkAdmin = true) { return (checkAdmin && super.has(Permissions.FLAGS.ADMINISTRATOR)) || super.has(permission); } + + static channelPermission(overwrites: ChannelPermissionOverwrite[], init?: bigint) { + // channelOverwrites.filter((x) => x.type === 1 && x.id !== user.id); + return overwrites.reduce((permission, overwrite) => { + // apply disallowed permission + // * permission: current calculated permission (e.g. 010) + // * deny contains all denied permissions (e.g. 011) + // * allow contains all explicitly allowed permisions (e.g. 100) + return (permission & ~overwrite.deny) | overwrite.allow; + // ~ operator inverts deny (e.g. 011 -> 100) + // & operator only allows 1 for both ~deny and permission (e.g. 010 & 100 -> 000) + // | operators adds both together (e.g. 000 + 100 -> 100) + }, 0n ?? init); + } + + static rolePermission(roles: Role[]) { + // adds all permissions of all roles together (Bit OR) + return roles.reduce((permission, role) => permission | role.permissions, 0n); + } + + static finalPermission({ + user, + guild, + channel, + }: { + user: { id: bigint; roles: bigint[] }; + guild: { roles: Role[] }; + channel?: { + overwrites: ChannelPermissionOverwrite[]; + }; + }) { + let roles = guild.roles.filter((x) => user.roles.includes(x.id)); + let permission = Permissions.rolePermission(roles); + + if (channel?.overwrites) { + let overwrites = channel.overwrites.filter((x) => { + if (x.type === 0 && user.roles.includes(x.id)) return true; + if (x.type === 1 && x.id == user.id) return true; + return false; + }); + permission = Permissions.channelPermission(overwrites, permission); + } + + return permission; + } } |