Servers now manage server-wide permissions

Servers now create ServerPermissions objects for roles
This commit is contained in:
hydrabolt
2015-10-03 19:44:08 +01:00
parent 6967f5e649
commit b264b61718
5 changed files with 159 additions and 57 deletions

View File

@@ -1,12 +1,18 @@
class ServerPermissions {
constructor(packedPermissions) {
constructor(data) {
var self = this;
function getBit(x) {
return ((this.packed >>> x) & 1) === 1;
return ((self.packed >>> x) & 1) === 1;
}
this.packed = packedPermissions;
this.packed = data.permissions;
this.name = data.name;
this.id = data.id;
this.createInstantInvite = getBit(0);
this.banMembers = getBit(1);
@@ -35,4 +41,6 @@ class ServerPermissions {
getBit(x) {
return ((this.packed >>> x) & 1) === 1;
}
}
}
module.exports = ServerPermissions;

View File

@@ -1,3 +1,5 @@
var ServerPermissions = require("./ServerPermissions.js");
class Server {
constructor(data, client) {
this.client = client;
@@ -12,6 +14,10 @@ class Server {
this.afkChannelId = data.afk_channel_id;
this.roles = [];
for(var permissionGroup of data.roles){
this.roles.push( new ServerPermissions(permissionGroup) );
}
if(!data.members){
data.members = [ client.user ];
@@ -30,6 +36,10 @@ class Server {
}
}
get permissionGroups(){
return this.roles;
}
get iconURL() {
if (!this.icon)