mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-10 12:42:44 +01:00
🐛 fix role can't set permission
This commit is contained in:
parent
286b4a69fd
commit
dd611d0e7c
@ -3,6 +3,7 @@
|
|||||||
import { Channel, ChannelPermissionOverwrite, Guild, Member, Role } from "../entities";
|
import { Channel, ChannelPermissionOverwrite, Guild, Member, Role } from "../entities";
|
||||||
import { BitField } from "./BitField";
|
import { BitField } from "./BitField";
|
||||||
import "missing-native-js-functions";
|
import "missing-native-js-functions";
|
||||||
|
import { BitFieldResolvable } from ".";
|
||||||
// TODO: check role hierarchy permission
|
// TODO: check role hierarchy permission
|
||||||
|
|
||||||
var HTTPError: any;
|
var HTTPError: any;
|
||||||
@ -17,11 +18,19 @@ export type PermissionResolvable = bigint | number | Permissions | PermissionRes
|
|||||||
|
|
||||||
type PermissionString = keyof typeof Permissions.FLAGS;
|
type PermissionString = keyof typeof Permissions.FLAGS;
|
||||||
|
|
||||||
const CUSTOM_PERMISSION_OFFSET = BigInt(1) << BigInt(48); // 16 free custom permission bits, and 11 for discord to add new ones
|
// BigInt doesn't have a bit limit (https://stackoverflow.com/questions/53335545/whats-the-biggest-bigint-value-in-js-as-per-spec)
|
||||||
|
const CUSTOM_PERMISSION_OFFSET = BigInt(1) << BigInt(64); // 27 permission bits left for discord to add new ones
|
||||||
|
|
||||||
export class Permissions extends BitField {
|
export class Permissions extends BitField {
|
||||||
cache: PermissionCache = {};
|
cache: PermissionCache = {};
|
||||||
|
|
||||||
|
constructor(bits: BitFieldResolvable = 0) {
|
||||||
|
super(bits);
|
||||||
|
if (this.bitfield & Permissions.FLAGS.ADMINISTRATOR) {
|
||||||
|
this.bitfield = ALL_PERMISSIONS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static FLAGS = {
|
static FLAGS = {
|
||||||
CREATE_INSTANT_INVITE: BigInt(1) << BigInt(0),
|
CREATE_INSTANT_INVITE: BigInt(1) << BigInt(0),
|
||||||
KICK_MEMBERS: BigInt(1) << BigInt(1),
|
KICK_MEMBERS: BigInt(1) << BigInt(1),
|
||||||
@ -92,7 +101,7 @@ export class Permissions extends BitField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
overwriteChannel(overwrites: ChannelPermissionOverwrite[]) {
|
overwriteChannel(overwrites: ChannelPermissionOverwrite[]) {
|
||||||
if (!overwrites) return this
|
if (!overwrites) return this;
|
||||||
if (!this.cache) throw new Error("permission chache not available");
|
if (!this.cache) throw new Error("permission chache not available");
|
||||||
overwrites = overwrites.filter((x) => {
|
overwrites = overwrites.filter((x) => {
|
||||||
if (x.type === 0 && this.cache.roles?.some((r) => r.id === x.id)) return true;
|
if (x.type === 0 && this.cache.roles?.some((r) => r.id === x.id)) return true;
|
||||||
@ -175,6 +184,8 @@ export class Permissions extends BitField {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ALL_PERMISSIONS = Object.values(Permissions.FLAGS).reduce((total, val) => total | val, BigInt(0));
|
||||||
|
|
||||||
export type PermissionCache = {
|
export type PermissionCache = {
|
||||||
channel?: Channel | undefined;
|
channel?: Channel | undefined;
|
||||||
member?: Member | undefined;
|
member?: Member | undefined;
|
||||||
|
Loading…
Reference in New Issue
Block a user