Skip to content

Commit

Permalink
Migrate permissions to BigInt
Browse files Browse the repository at this point in the history
  • Loading branch information
abalabahaha committed Apr 3, 2021
1 parent 886cb30 commit 3649cd7
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 80 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ plugins:
- "sort-class-members"
extends: "eslint:recommended"
globals:
BigInt: true
window: true
parserOptions:
ecmaVersion: 2018
ecmaVersion: 2020
rules:
array-bracket-spacing:
- 2
Expand Down
74 changes: 37 additions & 37 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1082,41 +1082,41 @@ declare namespace Eris {
GUILD_INVITE_REMINDER: 22;
};
Permissions: {
createInstantInvite: 1;
kickMembers: 2;
banMembers: 4;
administrator: 8;
manageChannels: 16;
manageGuild: 32;
addReactions: 64;
viewAuditLogs: 128;
voicePrioritySpeaker: 256;
stream: 512;
readMessages: 1024;
sendMessages: 2048;
sendTTSMessages: 4096;
manageMessages: 8192;
embedLinks: 16384;
attachFiles: 32768;
readMessageHistory: 65536;
mentionEveryone: 131072;
externalEmojis: 262144;
viewGuildInsights: 524288;
voiceConnect: 1048576;
voiceSpeak: 2097152;
voiceMuteMembers: 4194304;
voiceDeafenMembers: 8388608;
voiceMoveMembers: 16777216;
voiceUseVAD: 33554432;
changeNickname: 67108864;
manageNicknames: 134217728;
manageRoles: 268435456;
manageWebhooks: 546870912;
manageEmojis: 1973741824;
all: 2147483647;
allGuild: 2080899263;
allText: 805829714;
allVoice: 871367441;
createInstantInvite: 1n;
kickMembers: 2n;
banMembers: 4n;
administrator: 8n;
manageChannels: 16n;
manageGuild: 32n;
addReactions: 64n;
viewAuditLogs: 128n;
voicePrioritySpeaker: 256n;
stream: 512n;
readMessages: 1024n;
sendMessages: 2048n;
sendTTSMessages: 4096n;
manageMessages: 8192n;
embedLinks: 16384n;
attachFiles: 32768n;
readMessageHistory: 65536n;
mentionEveryone: 131072n;
externalEmojis: 262144n;
viewGuildInsights: 524288n;
voiceConnect: 1048576n;
voiceSpeak: 2097152n;
voiceMuteMembers: 4194304n;
voiceDeafenMembers: 8388608n;
voiceMoveMembers: 16777216n;
voiceUseVAD: 33554432n;
changeNickname: 67108864n;
manageNicknames: 134217728n;
manageRoles: 268435456n;
manageWebhooks: 536870912n;
manageEmojis: 1073741824n;
all: 2147483647n;
allGuild: 2080899263n;
allText: 805829713n;
allVoice: 871367441n;
};
REST_VERSION: 7;
StickerFormats: {
Expand Down Expand Up @@ -2151,8 +2151,8 @@ declare namespace Eris {
}

export class Permission extends Base {
allow: number;
deny: number;
allow: BigInt;
deny: BigInt;
json: Record<keyof Constants["Permissions"], boolean>;
constructor(allow: number | string, deny: number | string);
has(permission: keyof Constants["Permissions"]): boolean;
Expand Down
70 changes: 35 additions & 35 deletions lib/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,41 @@ module.exports.GATEWAY_VERSION = 6;
module.exports.REST_VERSION = 7;

module.exports.Permissions = {
createInstantInvite: 1,
kickMembers: 1 << 1,
banMembers: 1 << 2,
administrator: 1 << 3,
manageChannels: 1 << 4,
manageGuild: 1 << 5,
addReactions: 1 << 6,
viewAuditLogs: 1 << 7,
voicePrioritySpeaker: 1 << 8,
stream: 1 << 9,
readMessages: 1 << 10,
sendMessages: 1 << 11,
sendTTSMessages: 1 << 12,
manageMessages: 1 << 13,
embedLinks: 1 << 14,
attachFiles: 1 << 15,
readMessageHistory: 1 << 16,
mentionEveryone: 1 << 17,
externalEmojis: 1 << 18,
viewGuildInsights: 1 << 19,
voiceConnect: 1 << 20,
voiceSpeak: 1 << 21,
voiceMuteMembers: 1 << 22,
voiceDeafenMembers: 1 << 23,
voiceMoveMembers: 1 << 24,
voiceUseVAD: 1 << 25,
changeNickname: 1 << 26,
manageNicknames: 1 << 27,
manageRoles: 1 << 28,
manageWebhooks: 1 << 29,
manageEmojis: 1 << 30,
all: 0b1111111111111111111111111111111,
allGuild: 0b1111100000010000000000010111111,
allText: 0b0110000000001111111110001010001,
allVoice: 0b0110011111100000000001100010001
createInstantInvite: 1n,
kickMembers: 1n << 1n,
banMembers: 1n << 2n,
administrator: 1n << 3n,
manageChannels: 1n << 4n,
manageGuild: 1n << 5n,
addReactions: 1n << 6n,
viewAuditLogs: 1n << 7n,
voicePrioritySpeaker: 1n << 8n,
stream: 1n << 9n,
readMessages: 1n << 10n,
sendMessages: 1n << 11n,
sendTTSMessages: 1n << 12n,
manageMessages: 1n << 13n,
embedLinks: 1n << 14n,
attachFiles: 1n << 15n,
readMessageHistory: 1n << 16n,
mentionEveryone: 1n << 17n,
externalEmojis: 1n << 18n,
viewGuildInsights: 1n << 19n,
voiceConnect: 1n << 20n,
voiceSpeak: 1n << 21n,
voiceMuteMembers: 1n << 22n,
voiceDeafenMembers: 1n << 23n,
voiceMoveMembers: 1n << 24n,
voiceUseVAD: 1n << 25n,
changeNickname: 1n << 26n,
manageNicknames: 1n << 27n,
manageRoles: 1n << 28n,
manageWebhooks: 1n << 29n,
manageEmojis: 1n << 30n,
all: 0b1111111111111111111111111111111n,
allGuild: 0b1111100000010000000000010111111n,
allText: 0b0110000000001111111110001010001n,
allVoice: 0b0110011111100000000001100010001n
};

module.exports.VoiceOPCodes = {
Expand Down
4 changes: 2 additions & 2 deletions lib/structures/GuildChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ class GuildChannel extends Channel {
if(overwrite) {
permission = (permission & ~overwrite.deny) | overwrite.allow;
}
let deny = 0;
let allow = 0;
let deny = 0n;
let allow = 0n;
for(const roleID of member.roles) {
if((overwrite = this.permissionOverwrites.get(roleID))) {
deny |= overwrite.deny;
Expand Down
8 changes: 4 additions & 4 deletions lib/structures/Permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const {Permissions} = require("../Constants");

/**
* Represents a calculated permissions number
* @prop {Number} allow The allowed permissions number
* @prop {Number} deny The denied permissions number
* @prop {BigInt} allow The allowed permissions number
* @prop {BigInt} deny The denied permissions number
* @prop {Object} json A JSON representation of the permissions number.
* If a permission key isn't there, it is not set by this permission.
* If a permission key is false, it is denied by the permission.
Expand All @@ -23,8 +23,8 @@ const {Permissions} = require("../Constants");
class Permission extends Base {
constructor(allow, deny = 0) {
super();
this.allow = Number(allow);
this.deny = Number(deny);
this.allow = BigInt(allow);
this.deny = BigInt(deny);
}

get json() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"typings": "./index.d.ts",
"engines": {
"node": ">=8.0.0"
"node": ">=10.4.0"
},
"scripts": {
"lint:js": "eslint -c .eslintrc.yml lib examples *.js",
Expand Down

0 comments on commit 3649cd7

Please sign in to comment.