mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-10 12:42:44 +01:00
🎨 Channel + Member + Message + Role in separate collection
This commit is contained in:
parent
4125b7810d
commit
52964aed06
11
dist/models/Channel.d.ts
vendored
11
dist/models/Channel.d.ts
vendored
@ -19,12 +19,17 @@ export interface GuildChannel extends Channel {
|
|||||||
guild_id: bigint;
|
guild_id: bigint;
|
||||||
position: number;
|
position: number;
|
||||||
parent_id?: bigint;
|
parent_id?: bigint;
|
||||||
permission_overwrites: {
|
permission_overwrites: ChannelPermissionOverwrite[];
|
||||||
|
}
|
||||||
|
export interface ChannelPermissionOverwrite {
|
||||||
allow: bigint;
|
allow: bigint;
|
||||||
deny: bigint;
|
deny: bigint;
|
||||||
id: bigint;
|
id: bigint;
|
||||||
type: number;
|
type: ChannelPermissionOverwriteType;
|
||||||
}[];
|
}
|
||||||
|
export declare enum ChannelPermissionOverwriteType {
|
||||||
|
role = 0,
|
||||||
|
member = 1
|
||||||
}
|
}
|
||||||
export interface VoiceChannel extends GuildChannel {
|
export interface VoiceChannel extends GuildChannel {
|
||||||
}
|
}
|
||||||
|
7
dist/models/Channel.js
vendored
7
dist/models/Channel.js
vendored
@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
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");
|
const mongoose_1 = require("mongoose");
|
||||||
exports.ChannelSchema = new mongoose_1.Schema({
|
exports.ChannelSchema = new mongoose_1.Schema({
|
||||||
id: mongoose_1.Types.Long,
|
id: mongoose_1.Types.Long,
|
||||||
@ -27,6 +27,11 @@ exports.ChannelSchema = new mongoose_1.Schema({
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
exports.ChannelModel = mongoose_1.model("Channel", exports.ChannelSchema, "channels");
|
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;
|
var ChannelType;
|
||||||
(function (ChannelType) {
|
(function (ChannelType) {
|
||||||
ChannelType[ChannelType["GUILD_TEXT"] = 0] = "GUILD_TEXT";
|
ChannelType[ChannelType["GUILD_TEXT"] = 0] = "GUILD_TEXT";
|
||||||
|
2
dist/models/Channel.js.map
vendored
2
dist/models/Channel.js.map
vendored
@ -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,kBAA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AAkB,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;AA4BzF,IAAY,8BAGX;AAHD,WAAY,8BAA8B;IACzC,mFAAQ,CAAA;IACR,uFAAU,CAAA;AACX,CAAC,EAHW,8BAA8B,GAA9B,sCAA8B,KAA9B,sCAA8B,QAGzC;AAeD,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"}
|
1
dist/models/Member.d.ts
vendored
1
dist/models/Member.d.ts
vendored
@ -3,6 +3,7 @@ import { PublicUser } from "./User";
|
|||||||
import { Schema, Document } from "mongoose";
|
import { Schema, Document } from "mongoose";
|
||||||
export interface Member extends Document {
|
export interface Member extends Document {
|
||||||
id: bigint;
|
id: bigint;
|
||||||
|
guild_id: bigint;
|
||||||
nick?: string;
|
nick?: string;
|
||||||
roles: bigint[];
|
roles: bigint[];
|
||||||
joined_at: number;
|
joined_at: number;
|
||||||
|
1
dist/models/Member.js
vendored
1
dist/models/Member.js
vendored
@ -8,6 +8,7 @@ const MuteConfig = {
|
|||||||
};
|
};
|
||||||
exports.MemberSchema = new mongoose_1.Schema({
|
exports.MemberSchema = new mongoose_1.Schema({
|
||||||
id: mongoose_1.Types.Long,
|
id: mongoose_1.Types.Long,
|
||||||
|
guild_id: mongoose_1.Types.Long,
|
||||||
nick: String,
|
nick: String,
|
||||||
roles: [mongoose_1.Types.Long],
|
roles: [mongoose_1.Types.Long],
|
||||||
joined_at: Number,
|
joined_at: Number,
|
||||||
|
2
dist/models/Member.js.map
vendored
2
dist/models/Member.js.map
vendored
@ -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"}
|
{"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"}
|
1
dist/models/Message.d.ts
vendored
1
dist/models/Message.d.ts
vendored
@ -3,6 +3,7 @@ import { Schema, Document } from "mongoose";
|
|||||||
import { ChannelType } from "./Channel";
|
import { ChannelType } from "./Channel";
|
||||||
export interface Message extends Document {
|
export interface Message extends Document {
|
||||||
id: bigint;
|
id: bigint;
|
||||||
|
channel_id: bigint;
|
||||||
author_id?: bigint;
|
author_id?: bigint;
|
||||||
webhook_id?: bigint;
|
webhook_id?: bigint;
|
||||||
application_id: bigint;
|
application_id: bigint;
|
||||||
|
1
dist/models/Message.js
vendored
1
dist/models/Message.js
vendored
@ -81,6 +81,7 @@ const Embed = {
|
|||||||
};
|
};
|
||||||
exports.MessageSchema = new mongoose_1.Schema({
|
exports.MessageSchema = new mongoose_1.Schema({
|
||||||
id: mongoose_1.Types.Long,
|
id: mongoose_1.Types.Long,
|
||||||
|
channel_id: mongoose_1.Types.Long,
|
||||||
author_id: mongoose_1.Types.Long,
|
author_id: mongoose_1.Types.Long,
|
||||||
webhook_id: mongoose_1.Types.Long,
|
webhook_id: mongoose_1.Types.Long,
|
||||||
application_id: mongoose_1.Types.Long,
|
application_id: mongoose_1.Types.Long,
|
||||||
|
2
dist/models/Message.js.map
vendored
2
dist/models/Message.js.map
vendored
@ -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,SAAS,EAAE,MAAM;IACjB,MAAM,EAAE,MAAM;IACd,KAAK,EAAE,MAAM;CACb,CAAC;AAEF,MAAM,UAAU,G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CAAC,CAAC"}
|
1
dist/models/Role.d.ts
vendored
1
dist/models/Role.d.ts
vendored
@ -2,6 +2,7 @@
|
|||||||
import { Schema, Document } from "mongoose";
|
import { Schema, Document } from "mongoose";
|
||||||
export interface Role extends Document {
|
export interface Role extends Document {
|
||||||
id: bigint;
|
id: bigint;
|
||||||
|
guild_id: bigint;
|
||||||
color: number;
|
color: number;
|
||||||
hoist: boolean;
|
hoist: boolean;
|
||||||
managed: boolean;
|
managed: boolean;
|
||||||
|
1
dist/models/Role.js
vendored
1
dist/models/Role.js
vendored
@ -4,6 +4,7 @@ exports.RoleModel = exports.RoleSchema = void 0;
|
|||||||
const mongoose_1 = require("mongoose");
|
const mongoose_1 = require("mongoose");
|
||||||
exports.RoleSchema = new mongoose_1.Schema({
|
exports.RoleSchema = new mongoose_1.Schema({
|
||||||
id: mongoose_1.Types.Long,
|
id: mongoose_1.Types.Long,
|
||||||
|
guild_id: mongoose_1.Types.Long,
|
||||||
color: Number,
|
color: Number,
|
||||||
hoist: Boolean,
|
hoist: Boolean,
|
||||||
managed: Boolean,
|
managed: Boolean,
|
||||||
|
2
dist/models/Role.js.map
vendored
2
dist/models/Role.js.map
vendored
@ -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"}
|
{"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"}
|
16
dist/util/Permissions.d.ts
vendored
16
dist/util/Permissions.d.ts
vendored
@ -1,3 +1,5 @@
|
|||||||
|
import { ChannelPermissionOverwrite } from "../models/Channel";
|
||||||
|
import { Role } from "../models/Role";
|
||||||
import { BitField } from "./BitField";
|
import { BitField } from "./BitField";
|
||||||
export declare type PermissionResolvable = string | number | Permissions | PermissionResolvable[];
|
export declare type PermissionResolvable = string | number | Permissions | PermissionResolvable[];
|
||||||
export declare class Permissions extends BitField {
|
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.
|
* Checks whether the bitfield has a permission, or multiple permissions.
|
||||||
*/
|
*/
|
||||||
has(permission: PermissionResolvable, checkAdmin?: boolean): boolean;
|
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;
|
||||||
}
|
}
|
||||||
|
32
dist/util/Permissions.js
vendored
32
dist/util/Permissions.js
vendored
@ -14,6 +14,38 @@ class Permissions extends BitField_1.BitField {
|
|||||||
has(permission, checkAdmin = true) {
|
has(permission, checkAdmin = true) {
|
||||||
return (checkAdmin && super.has(Permissions.FLAGS.ADMINISTRATOR)) || super.has(permission);
|
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;
|
exports.Permissions = Permissions;
|
||||||
Permissions.FLAGS = {
|
Permissions.FLAGS = {
|
||||||
|
2
dist/util/Permissions.js.map
vendored
2
dist/util/Permissions.js.map
vendored
@ -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;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;;AA5CF,kCA6CC;AA5CO,iBAAK,GAAG;IACd,qBAAqB,EAAE,EAAE,IAAI,EAAE;IAC/B,YAAY,EAAE,EAAE,IAAI,EAAE;IACtB,WAAW,EAAE,EAAE,IAAI,EAAE;IACrB,aAAa,EAAE,EAAE,IAAI,EAAE;IACvB,eAAe,EAAE,EAAE,IAAI,EAAE;IACzB,YAAY,EAAE,EAAE,IAAI,EAAE;IACtB,aAAa,EAAE,EAAE,IAAI,EAAE;IAC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C9B,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"}
|
@ -47,12 +47,19 @@ export interface GuildChannel extends Channel {
|
|||||||
guild_id: bigint;
|
guild_id: bigint;
|
||||||
position: number;
|
position: number;
|
||||||
parent_id?: bigint;
|
parent_id?: bigint;
|
||||||
permission_overwrites: {
|
permission_overwrites: ChannelPermissionOverwrite[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ChannelPermissionOverwrite {
|
||||||
allow: bigint;
|
allow: bigint;
|
||||||
deny: bigint;
|
deny: bigint;
|
||||||
id: bigint;
|
id: bigint;
|
||||||
type: number;
|
type: ChannelPermissionOverwriteType;
|
||||||
}[];
|
}
|
||||||
|
|
||||||
|
export enum ChannelPermissionOverwriteType {
|
||||||
|
role = 0,
|
||||||
|
member = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface VoiceChannel extends GuildChannel {}
|
export interface VoiceChannel extends GuildChannel {}
|
||||||
|
@ -3,6 +3,7 @@ import { Schema, model, Types, Document } from "mongoose";
|
|||||||
|
|
||||||
export interface Member extends Document {
|
export interface Member extends Document {
|
||||||
id: bigint;
|
id: bigint;
|
||||||
|
guild_id: bigint;
|
||||||
nick?: string;
|
nick?: string;
|
||||||
roles: bigint[];
|
roles: bigint[];
|
||||||
joined_at: number;
|
joined_at: number;
|
||||||
@ -42,6 +43,7 @@ const MuteConfig = {
|
|||||||
|
|
||||||
export const MemberSchema = new Schema({
|
export const MemberSchema = new Schema({
|
||||||
id: Types.Long,
|
id: Types.Long,
|
||||||
|
guild_id: Types.Long,
|
||||||
nick: String,
|
nick: String,
|
||||||
roles: [Types.Long],
|
roles: [Types.Long],
|
||||||
joined_at: Number,
|
joined_at: Number,
|
||||||
|
@ -3,6 +3,7 @@ import { ChannelType } from "./Channel";
|
|||||||
|
|
||||||
export interface Message extends Document {
|
export interface Message extends Document {
|
||||||
id: bigint;
|
id: bigint;
|
||||||
|
channel_id: bigint;
|
||||||
author_id?: bigint;
|
author_id?: bigint;
|
||||||
webhook_id?: bigint;
|
webhook_id?: bigint;
|
||||||
application_id: bigint;
|
application_id: bigint;
|
||||||
@ -188,6 +189,7 @@ const Embed = {
|
|||||||
|
|
||||||
export const MessageSchema = new Schema({
|
export const MessageSchema = new Schema({
|
||||||
id: Types.Long,
|
id: Types.Long,
|
||||||
|
channel_id: Types.Long,
|
||||||
author_id: Types.Long,
|
author_id: Types.Long,
|
||||||
webhook_id: Types.Long,
|
webhook_id: Types.Long,
|
||||||
application_id: Types.Long,
|
application_id: Types.Long,
|
||||||
|
@ -2,6 +2,7 @@ import { Schema, model, Types, Document } from "mongoose";
|
|||||||
|
|
||||||
export interface Role extends Document {
|
export interface Role extends Document {
|
||||||
id: bigint;
|
id: bigint;
|
||||||
|
guild_id: bigint;
|
||||||
color: number;
|
color: number;
|
||||||
hoist: boolean;
|
hoist: boolean;
|
||||||
managed: boolean;
|
managed: boolean;
|
||||||
@ -16,6 +17,7 @@ export interface Role extends Document {
|
|||||||
|
|
||||||
export const RoleSchema = new Schema({
|
export const RoleSchema = new Schema({
|
||||||
id: Types.Long,
|
id: Types.Long,
|
||||||
|
guild_id: Types.Long,
|
||||||
color: Number,
|
color: Number,
|
||||||
hoist: Boolean,
|
hoist: Boolean,
|
||||||
managed: Boolean,
|
managed: Boolean,
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
// https://github.com/discordjs/discord.js/blob/master/src/util/Permissions.js
|
// https://github.com/discordjs/discord.js/blob/master/src/util/Permissions.js
|
||||||
// Apache License Version 2.0 Copyright 2015 - 2021 Amish Shah
|
// Apache License Version 2.0 Copyright 2015 - 2021 Amish Shah
|
||||||
|
|
||||||
|
import { ChannelPermissionOverwrite } from "../models/Channel";
|
||||||
|
import { Role } from "../models/Role";
|
||||||
import { BitField } from "./BitField";
|
import { BitField } from "./BitField";
|
||||||
|
|
||||||
export type PermissionResolvable = string | number | Permissions | PermissionResolvable[];
|
export type PermissionResolvable = string | number | Permissions | PermissionResolvable[];
|
||||||
@ -50,4 +52,49 @@ export class Permissions extends BitField {
|
|||||||
has(permission: PermissionResolvable, checkAdmin = true) {
|
has(permission: PermissionResolvable, checkAdmin = true) {
|
||||||
return (checkAdmin && super.has(Permissions.FLAGS.ADMINISTRATOR)) || super.has(permission);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user