mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Added full evaluation of SERVERwide permissions
This commit is contained in:
@@ -1,9 +1,34 @@
|
||||
"use strict";
|
||||
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var ChannelPermissions = function ChannelPermissions(data) {
|
||||
_classCallCheck(this, ChannelPermissions);
|
||||
};
|
||||
var ChannelPermissions = (function () {
|
||||
function ChannelPermissions(data) {
|
||||
_classCallCheck(this, ChannelPermissions);
|
||||
|
||||
function getBit(x) {
|
||||
return (this.packed >>> x & 1) === 1;
|
||||
}
|
||||
|
||||
this.type = data.type; //either member or role
|
||||
|
||||
this.id = data.id;
|
||||
|
||||
this.deny = data.deny;
|
||||
|
||||
this.allow = data.allow;
|
||||
}
|
||||
|
||||
_createClass(ChannelPermissions, [{
|
||||
key: "getBit",
|
||||
value: function getBit(x) {
|
||||
return (this.packed >>> x & 1) === 1;
|
||||
}
|
||||
}]);
|
||||
|
||||
return ChannelPermissions;
|
||||
})();
|
||||
|
||||
module.exports = ChannelPermissions;
|
||||
@@ -9,6 +9,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var User = require("./user.js");
|
||||
var ServerPermissions = require("./ServerPermissions.js");
|
||||
|
||||
var Member = (function (_User) {
|
||||
_inherits(Member, _User);
|
||||
@@ -25,8 +26,9 @@ var Member = (function (_User) {
|
||||
key: "roles",
|
||||
get: function get() {
|
||||
|
||||
var ufRoles = [];
|
||||
var ufRoles = [this.server.getRole(this.server.id)];
|
||||
|
||||
console.log(this.rawRoles);
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
@@ -54,6 +56,43 @@ var Member = (function (_User) {
|
||||
|
||||
return ufRoles;
|
||||
}
|
||||
}, {
|
||||
key: "evalPerms",
|
||||
get: function get() {
|
||||
|
||||
var basePerms = this.roles,
|
||||
//cache roles as it can be slightly expensive
|
||||
basePerm = basePerms[0].packed;
|
||||
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator2 = basePerms[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
||||
var perm = _step2.value;
|
||||
|
||||
basePerm = basePerm | perm.packed;
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError2 = true;
|
||||
_iteratorError2 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion2 && _iterator2["return"]) {
|
||||
_iterator2["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError2) {
|
||||
throw _iteratorError2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ServerPermissions({
|
||||
permissions: basePerm
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return Member;
|
||||
|
||||
@@ -26,7 +26,7 @@ var Channel = (function () {
|
||||
for (var _iterator = data.permission_overwrites[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var role = _step.value;
|
||||
|
||||
this.roles.push(new ChannelPermissions());
|
||||
this.roles.push(new ChannelPermissions(role));
|
||||
}
|
||||
|
||||
//this.isPrivate = isPrivate; //not sure about the implementation of this...
|
||||
|
||||
Reference in New Issue
Block a user