mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 01:53:30 +01:00
Built src again using the correct preset
This commit is contained in:
@@ -1,26 +1,44 @@
|
||||
"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"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
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 Equality = require("../Util/Equality.js");
|
||||
var Cache = require("../Util/Cache.js");
|
||||
var PermissionOverwrite = require("./PermissionOverwrite.js");
|
||||
var reg = require("../Util/ArgumentRegulariser.js").reg;
|
||||
|
||||
class Channel extends Equality {
|
||||
var Channel = (function (_Equality) {
|
||||
_inherits(Channel, _Equality);
|
||||
|
||||
constructor(data, client) {
|
||||
super();
|
||||
this.id = data.id;
|
||||
this.client = client;
|
||||
function Channel(data, client) {
|
||||
_classCallCheck(this, Channel);
|
||||
|
||||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Channel).call(this));
|
||||
|
||||
_this.id = data.id;
|
||||
_this.client = client;
|
||||
return _this;
|
||||
}
|
||||
|
||||
get isPrivate() {
|
||||
return !!this.server;
|
||||
}
|
||||
_createClass(Channel, [{
|
||||
key: "delete",
|
||||
value: function _delete() {
|
||||
return this.client.deleteChannel.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}, {
|
||||
key: "isPrivate",
|
||||
get: function get() {
|
||||
return !!this.server;
|
||||
}
|
||||
}]);
|
||||
|
||||
delete() {
|
||||
return this.client.deleteChannel.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
}
|
||||
return Channel;
|
||||
})(Equality);
|
||||
|
||||
module.exports = Channel;
|
||||
@@ -1,64 +1,82 @@
|
||||
"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 Permissions = require("../Constants.js").Permissions;
|
||||
|
||||
class ChannelPermissions {
|
||||
constructor(permissions) {
|
||||
var ChannelPermissions = (function () {
|
||||
function ChannelPermissions(permissions) {
|
||||
_classCallCheck(this, ChannelPermissions);
|
||||
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
serialise(explicit) {
|
||||
_createClass(ChannelPermissions, [{
|
||||
key: "serialise",
|
||||
value: function serialise(explicit) {
|
||||
var _this = this;
|
||||
|
||||
var hp = perm => this.hasPermission(perm, explicit);
|
||||
var hp = function hp(perm) {
|
||||
return _this.hasPermission(perm, explicit);
|
||||
};
|
||||
|
||||
return {
|
||||
// general
|
||||
createInstantInvite: hp(Permissions.createInstantInvite),
|
||||
kickMembers: hp(Permissions.kickMembers),
|
||||
banMembers: hp(Permissions.banMembers),
|
||||
managePermissions: hp(Permissions.managePermissions),
|
||||
manageChannel: hp(Permissions.manageChannel),
|
||||
manageServer: hp(Permissions.manageServer),
|
||||
// text
|
||||
readMessages: hp(Permissions.readMessages),
|
||||
sendMessages: hp(Permissions.sendMessages),
|
||||
sendTTSMessages: hp(Permissions.sendTTSMessages),
|
||||
manageMessages: hp(Permissions.manageMessages),
|
||||
embedLinks: hp(Permissions.embedLinks),
|
||||
attachFiles: hp(Permissions.attachFiles),
|
||||
readMessageHistory: hp(Permissions.readMessageHistory),
|
||||
mentionEveryone: hp(Permissions.mentionEveryone),
|
||||
// voice
|
||||
voiceConnect: hp(Permissions.voiceConnect),
|
||||
voiceSpeak: hp(Permissions.voiceSpeak),
|
||||
voiceMuteMembers: hp(Permissions.voiceMuteMembers),
|
||||
voiceDeafenMembers: hp(Permissions.voiceDeafenMembers),
|
||||
voiceMoveMembers: hp(Permissions.voiceMoveMembers),
|
||||
voiceUseVAD: hp(Permissions.voiceUseVAD)
|
||||
};
|
||||
}
|
||||
|
||||
serialize() {
|
||||
// ;n;
|
||||
return this.serialise();
|
||||
}
|
||||
|
||||
hasPermission(perm, explicit = false) {
|
||||
if (perm instanceof String || typeof perm === "string") {
|
||||
perm = Permissions[perm];
|
||||
return {
|
||||
// general
|
||||
createInstantInvite: hp(Permissions.createInstantInvite),
|
||||
kickMembers: hp(Permissions.kickMembers),
|
||||
banMembers: hp(Permissions.banMembers),
|
||||
managePermissions: hp(Permissions.managePermissions),
|
||||
manageChannel: hp(Permissions.manageChannel),
|
||||
manageServer: hp(Permissions.manageServer),
|
||||
// text
|
||||
readMessages: hp(Permissions.readMessages),
|
||||
sendMessages: hp(Permissions.sendMessages),
|
||||
sendTTSMessages: hp(Permissions.sendTTSMessages),
|
||||
manageMessages: hp(Permissions.manageMessages),
|
||||
embedLinks: hp(Permissions.embedLinks),
|
||||
attachFiles: hp(Permissions.attachFiles),
|
||||
readMessageHistory: hp(Permissions.readMessageHistory),
|
||||
mentionEveryone: hp(Permissions.mentionEveryone),
|
||||
// voice
|
||||
voiceConnect: hp(Permissions.voiceConnect),
|
||||
voiceSpeak: hp(Permissions.voiceSpeak),
|
||||
voiceMuteMembers: hp(Permissions.voiceMuteMembers),
|
||||
voiceDeafenMembers: hp(Permissions.voiceDeafenMembers),
|
||||
voiceMoveMembers: hp(Permissions.voiceMoveMembers),
|
||||
voiceUseVAD: hp(Permissions.voiceUseVAD)
|
||||
};
|
||||
}
|
||||
if (!perm) {
|
||||
return false;
|
||||
}, {
|
||||
key: "serialize",
|
||||
value: function serialize() {
|
||||
// ;n;
|
||||
return this.serialise();
|
||||
}
|
||||
if (!explicit) {
|
||||
// implicit permissions allowed
|
||||
if (!!(this.permissions & Permissions.manageRoles)) {
|
||||
// manageRoles allowed, they have all permissions
|
||||
return true;
|
||||
}, {
|
||||
key: "hasPermission",
|
||||
value: function hasPermission(perm) {
|
||||
var explicit = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
|
||||
|
||||
if (perm instanceof String || typeof perm === "string") {
|
||||
perm = Permissions[perm];
|
||||
}
|
||||
if (!perm) {
|
||||
return false;
|
||||
}
|
||||
if (!explicit) {
|
||||
// implicit permissions allowed
|
||||
if (!!(this.permissions & Permissions.manageRoles)) {
|
||||
// manageRoles allowed, they have all permissions
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return !!(this.permissions & perm);
|
||||
}
|
||||
return !!(this.permissions & perm);
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
||||
return ChannelPermissions;
|
||||
})();
|
||||
|
||||
module.exports = ChannelPermissions;
|
||||
@@ -1,10 +1,16 @@
|
||||
"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 Server = require("./Server.js");
|
||||
var ServerChannel = require("./ServerChannel.js");
|
||||
|
||||
class Invite {
|
||||
constructor(data, chan, client) {
|
||||
var Invite = (function () {
|
||||
function Invite(data, chan, client) {
|
||||
_classCallCheck(this, Invite);
|
||||
|
||||
this.maxAge = data.max_age;
|
||||
this.code = data.code;
|
||||
this.server = chan.server;
|
||||
@@ -18,9 +24,14 @@ class Invite {
|
||||
this.xkcd = data.xkcdpass;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `https://discord.gg/${ this.code }`;
|
||||
}
|
||||
}
|
||||
_createClass(Invite, [{
|
||||
key: "toString",
|
||||
value: function toString() {
|
||||
return "https://discord.gg/" + this.code;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Invite;
|
||||
})();
|
||||
|
||||
module.exports = Invite;
|
||||
@@ -1,70 +1,95 @@
|
||||
"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"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
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 Cache = require("../Util/Cache.js");
|
||||
var User = require("./User.js");
|
||||
var reg = require("../Util/ArgumentRegulariser.js").reg;
|
||||
var Equality = require("../Util/Equality");
|
||||
|
||||
class Message extends Equality {
|
||||
constructor(data, channel, client) {
|
||||
super();
|
||||
this.channel = channel;
|
||||
this.client = client;
|
||||
this.nonce = data.nonce;
|
||||
this.attachments = data.attachments;
|
||||
this.tts = data.tts;
|
||||
this.embeds = data.embeds;
|
||||
this.timestamp = Date.parse(data.timestamp);
|
||||
this.everyoneMentioned = data.mention_everyone;
|
||||
this.id = data.id;
|
||||
var Message = (function (_Equality) {
|
||||
_inherits(Message, _Equality);
|
||||
|
||||
if (data.edited_timestamp) this.editedTimestamp = Date.parse(data.edited_timestamp);
|
||||
function Message(data, channel, client) {
|
||||
_classCallCheck(this, Message);
|
||||
|
||||
if (data.author instanceof User) this.author = data.author;else this.author = client.internal.users.add(new User(data.author, client));
|
||||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Message).call(this));
|
||||
|
||||
this.content = data.content;
|
||||
this.mentions = new Cache();
|
||||
_this.channel = channel;
|
||||
_this.client = client;
|
||||
_this.nonce = data.nonce;
|
||||
_this.attachments = data.attachments;
|
||||
_this.tts = data.tts;
|
||||
_this.embeds = data.embeds;
|
||||
_this.timestamp = Date.parse(data.timestamp);
|
||||
_this.everyoneMentioned = data.mention_everyone;
|
||||
_this.id = data.id;
|
||||
|
||||
data.mentions.forEach(mention => {
|
||||
if (data.edited_timestamp) _this.editedTimestamp = Date.parse(data.edited_timestamp);
|
||||
|
||||
if (data.author instanceof User) _this.author = data.author;else _this.author = client.internal.users.add(new User(data.author, client));
|
||||
|
||||
_this.content = data.content;
|
||||
_this.mentions = new Cache();
|
||||
|
||||
data.mentions.forEach(function (mention) {
|
||||
// this is .add and not .get because it allows the bot to cache
|
||||
// users from messages from logs who may have left the server and were
|
||||
// not previously cached.
|
||||
if (mention instanceof User) this.mentions.push(mention);else this.mentions.add(client.internal.users.add(new User(mention, client)));
|
||||
if (mention instanceof User) _this.mentions.push(mention);else _this.mentions.add(client.internal.users.add(new User(mention, client)));
|
||||
});
|
||||
return _this;
|
||||
}
|
||||
|
||||
isMentioned(user) {
|
||||
user = this.client.internal.resolver.resolveUser(user);
|
||||
if (user) {
|
||||
return this.mentions.has("id", user.id);
|
||||
} else {
|
||||
return false;
|
||||
_createClass(Message, [{
|
||||
key: "isMentioned",
|
||||
value: function isMentioned(user) {
|
||||
user = this.client.internal.resolver.resolveUser(user);
|
||||
if (user) {
|
||||
return this.mentions.has("id", user.id);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "toString",
|
||||
value: function toString() {
|
||||
return this.content;
|
||||
}
|
||||
}, {
|
||||
key: "delete",
|
||||
value: function _delete() {
|
||||
return this.client.deleteMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}, {
|
||||
key: "update",
|
||||
value: function update() {
|
||||
return this.client.updateMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}, {
|
||||
key: "reply",
|
||||
value: function reply() {
|
||||
return this.client.reply.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}, {
|
||||
key: "replyTTS",
|
||||
value: function replyTTS() {
|
||||
return this.client.replyTTS.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}, {
|
||||
key: "sender",
|
||||
get: function get() {
|
||||
return this.author;
|
||||
}
|
||||
}]);
|
||||
|
||||
toString() {
|
||||
return this.content;
|
||||
}
|
||||
|
||||
delete() {
|
||||
return this.client.deleteMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
update() {
|
||||
return this.client.updateMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
reply() {
|
||||
return this.client.reply.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
replyTTS() {
|
||||
return this.client.replyTTS.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
get sender() {
|
||||
return this.author;
|
||||
}
|
||||
}
|
||||
return Message;
|
||||
})(Equality);
|
||||
|
||||
module.exports = Message;
|
||||
@@ -1,37 +1,59 @@
|
||||
"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"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
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 Channel = require("./Channel.js");
|
||||
var User = require("./User.js");
|
||||
var Equality = require("../Util/Equality.js");
|
||||
var Cache = require("../Util/Cache.js");
|
||||
var reg = require("../Util/ArgumentRegulariser.js").reg;
|
||||
|
||||
class PMChannel extends Channel {
|
||||
constructor(data, client) {
|
||||
super(data, client);
|
||||
var PMChannel = (function (_Channel) {
|
||||
_inherits(PMChannel, _Channel);
|
||||
|
||||
this.type = data.type || "text";
|
||||
this.lastMessageId = data.last_message_id;
|
||||
this.messages = new Cache("id", 1000);
|
||||
this.recipient = this.client.internal.users.add(new User(data.recipient, this.client));
|
||||
function PMChannel(data, client) {
|
||||
_classCallCheck(this, PMChannel);
|
||||
|
||||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(PMChannel).call(this, data, client));
|
||||
|
||||
_this.type = data.type || "text";
|
||||
_this.lastMessageId = data.last_message_id;
|
||||
_this.messages = new Cache("id", 1000);
|
||||
_this.recipient = _this.client.internal.users.add(new User(data.recipient, _this.client));
|
||||
return _this;
|
||||
}
|
||||
|
||||
/* warning! may return null */
|
||||
get lastMessage() {
|
||||
return this.messages.get("id", this.lastMessageID);
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.recipient.toString();
|
||||
}
|
||||
_createClass(PMChannel, [{
|
||||
key: "toString",
|
||||
value: function toString() {
|
||||
return this.recipient.toString();
|
||||
}
|
||||
}, {
|
||||
key: "sendMessage",
|
||||
value: function sendMessage() {
|
||||
return this.client.sendMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}, {
|
||||
key: "sendTTSMessage",
|
||||
value: function sendTTSMessage() {
|
||||
return this.client.sendTTSMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}, {
|
||||
key: "lastMessage",
|
||||
get: function get() {
|
||||
return this.messages.get("id", this.lastMessageID);
|
||||
}
|
||||
}]);
|
||||
|
||||
sendMessage() {
|
||||
return this.client.sendMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
sendTTSMessage() {
|
||||
return this.client.sendTTSMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}
|
||||
return PMChannel;
|
||||
})(Channel);
|
||||
|
||||
module.exports = PMChannel;
|
||||
@@ -1,10 +1,15 @@
|
||||
"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 Permissions = require("../Constants.js").Permissions;
|
||||
|
||||
class PermissionOverwrite {
|
||||
var PermissionOverwrite = (function () {
|
||||
function PermissionOverwrite(data) {
|
||||
_classCallCheck(this, PermissionOverwrite);
|
||||
|
||||
constructor(data) {
|
||||
this.id = data.id;
|
||||
this.type = data.type; // member or role
|
||||
this.deny = data.deny;
|
||||
@@ -12,59 +17,73 @@ class PermissionOverwrite {
|
||||
}
|
||||
|
||||
// returns an array of allowed permissions
|
||||
get allowed() {
|
||||
var allowed = [];
|
||||
for (var permName in Permissions) {
|
||||
if (permName === "manageRoles" || permName === "manageChannels") {
|
||||
// these permissions do not exist in overwrites.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!!(this.allow & Permissions[permName])) {
|
||||
allowed.push(permName);
|
||||
}
|
||||
_createClass(PermissionOverwrite, [{
|
||||
key: "setAllowed",
|
||||
value: function setAllowed(allowedArray) {
|
||||
var _this = this;
|
||||
|
||||
allowedArray.forEach(function (permission) {
|
||||
if (permission instanceof String || typeof permission === "string") {
|
||||
permission = Permissions[permission];
|
||||
}
|
||||
if (permission) {
|
||||
_this.allow |= 1 << permission;
|
||||
}
|
||||
});
|
||||
}
|
||||
return allowed;
|
||||
}
|
||||
}, {
|
||||
key: "setDenied",
|
||||
value: function setDenied(deniedArray) {
|
||||
var _this2 = this;
|
||||
|
||||
// returns an array of denied permissions
|
||||
get denied() {
|
||||
var denied = [];
|
||||
for (var permName in Permissions) {
|
||||
if (permName === "manageRoles" || permName === "manageChannels") {
|
||||
// these permissions do not exist in overwrites.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!!(this.deny & Permissions[permName])) {
|
||||
denied.push(permName);
|
||||
}
|
||||
deniedArray.forEach(function (permission) {
|
||||
if (permission instanceof String || typeof permission === "string") {
|
||||
permission = Permissions[permission];
|
||||
}
|
||||
if (permission) {
|
||||
_this2.deny |= 1 << permission;
|
||||
}
|
||||
});
|
||||
}
|
||||
return denied;
|
||||
}
|
||||
}, {
|
||||
key: "allowed",
|
||||
get: function get() {
|
||||
var allowed = [];
|
||||
for (var permName in Permissions) {
|
||||
if (permName === "manageRoles" || permName === "manageChannels") {
|
||||
// these permissions do not exist in overwrites.
|
||||
continue;
|
||||
}
|
||||
|
||||
setAllowed(allowedArray) {
|
||||
allowedArray.forEach(permission => {
|
||||
if (permission instanceof String || typeof permission === "string") {
|
||||
permission = Permissions[permission];
|
||||
if (!!(this.allow & Permissions[permName])) {
|
||||
allowed.push(permName);
|
||||
}
|
||||
}
|
||||
if (permission) {
|
||||
this.allow |= 1 << permission;
|
||||
}
|
||||
});
|
||||
}
|
||||
return allowed;
|
||||
}
|
||||
|
||||
setDenied(deniedArray) {
|
||||
deniedArray.forEach(permission => {
|
||||
if (permission instanceof String || typeof permission === "string") {
|
||||
permission = Permissions[permission];
|
||||
}
|
||||
if (permission) {
|
||||
this.deny |= 1 << permission;
|
||||
}
|
||||
});
|
||||
}
|
||||
// returns an array of denied permissions
|
||||
|
||||
}
|
||||
}, {
|
||||
key: "denied",
|
||||
get: function get() {
|
||||
var denied = [];
|
||||
for (var permName in Permissions) {
|
||||
if (permName === "manageRoles" || permName === "manageChannels") {
|
||||
// these permissions do not exist in overwrites.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!!(this.deny & Permissions[permName])) {
|
||||
denied.push(permName);
|
||||
}
|
||||
}
|
||||
return denied;
|
||||
}
|
||||
}]);
|
||||
|
||||
return PermissionOverwrite;
|
||||
})();
|
||||
|
||||
module.exports = PermissionOverwrite;
|
||||
@@ -1,5 +1,9 @@
|
||||
"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 Permissions = require("../Constants.js").Permissions;
|
||||
/*
|
||||
|
||||
@@ -14,10 +18,14 @@ example data
|
||||
color: 0 }
|
||||
*/
|
||||
|
||||
const DefaultRole = [Permissions.createInstantInvite, Permissions.readMessages, Permissions.readMessageHistory, Permissions.sendMessages, Permissions.sendTTSMessages, Permissions.embedLinks, Permissions.attachFiles, Permissions.readMessageHistory, Permissions.mentionEveryone, Permissions.voiceConnect, Permissions.voiceSpeak, Permissions.voiceUseVAD].reduce((previous, current) => previous | current, 0);
|
||||
var DefaultRole = [Permissions.createInstantInvite, Permissions.readMessages, Permissions.readMessageHistory, Permissions.sendMessages, Permissions.sendTTSMessages, Permissions.embedLinks, Permissions.attachFiles, Permissions.readMessageHistory, Permissions.mentionEveryone, Permissions.voiceConnect, Permissions.voiceSpeak, Permissions.voiceUseVAD].reduce(function (previous, current) {
|
||||
return previous | current;
|
||||
}, 0);
|
||||
|
||||
var Role = (function () {
|
||||
function Role(data, server, client) {
|
||||
_classCallCheck(this, Role);
|
||||
|
||||
class Role {
|
||||
constructor(data, server, client) {
|
||||
this.position = data.position || -1;
|
||||
this.permissions = data.permissions || (data.name === "@everyone" ? DefaultRole : 0);
|
||||
this.name = data.name || "@everyone";
|
||||
@@ -29,96 +37,113 @@ class Role {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
serialise(explicit) {
|
||||
_createClass(Role, [{
|
||||
key: "serialise",
|
||||
value: function serialise(explicit) {
|
||||
var _this = this;
|
||||
|
||||
var hp = perm => this.hasPermission(perm, explicit);
|
||||
var hp = function hp(perm) {
|
||||
return _this.hasPermission(perm, explicit);
|
||||
};
|
||||
|
||||
return {
|
||||
// general
|
||||
createInstantInvite: hp(Permissions.createInstantInvite),
|
||||
kickMembers: hp(Permissions.kickMembers),
|
||||
banMembers: hp(Permissions.banMembers),
|
||||
manageRoles: hp(Permissions.manageRoles),
|
||||
manageChannels: hp(Permissions.manageChannels),
|
||||
manageServer: hp(Permissions.manageServer),
|
||||
// text
|
||||
readMessages: hp(Permissions.readMessages),
|
||||
sendMessages: hp(Permissions.sendMessages),
|
||||
sendTTSMessages: hp(Permissions.sendTTSMessages),
|
||||
manageMessages: hp(Permissions.manageMessages),
|
||||
embedLinks: hp(Permissions.embedLinks),
|
||||
attachFiles: hp(Permissions.attachFiles),
|
||||
readMessageHistory: hp(Permissions.readMessageHistory),
|
||||
mentionEveryone: hp(Permissions.mentionEveryone),
|
||||
// voice
|
||||
voiceConnect: hp(Permissions.voiceConnect),
|
||||
voiceSpeak: hp(Permissions.voiceSpeak),
|
||||
voiceMuteMembers: hp(Permissions.voiceMuteMembers),
|
||||
voiceDeafenMembers: hp(Permissions.voiceDeafenMembers),
|
||||
voiceMoveMembers: hp(Permissions.voiceMoveMembers),
|
||||
voiceUseVAD: hp(Permissions.voiceUseVAD)
|
||||
};
|
||||
}
|
||||
|
||||
serialize() {
|
||||
// ;n;
|
||||
return this.serialise();
|
||||
}
|
||||
|
||||
hasPermission(perm, explicit = false) {
|
||||
if (perm instanceof String || typeof perm === "string") {
|
||||
perm = Permissions[perm];
|
||||
return {
|
||||
// general
|
||||
createInstantInvite: hp(Permissions.createInstantInvite),
|
||||
kickMembers: hp(Permissions.kickMembers),
|
||||
banMembers: hp(Permissions.banMembers),
|
||||
manageRoles: hp(Permissions.manageRoles),
|
||||
manageChannels: hp(Permissions.manageChannels),
|
||||
manageServer: hp(Permissions.manageServer),
|
||||
// text
|
||||
readMessages: hp(Permissions.readMessages),
|
||||
sendMessages: hp(Permissions.sendMessages),
|
||||
sendTTSMessages: hp(Permissions.sendTTSMessages),
|
||||
manageMessages: hp(Permissions.manageMessages),
|
||||
embedLinks: hp(Permissions.embedLinks),
|
||||
attachFiles: hp(Permissions.attachFiles),
|
||||
readMessageHistory: hp(Permissions.readMessageHistory),
|
||||
mentionEveryone: hp(Permissions.mentionEveryone),
|
||||
// voice
|
||||
voiceConnect: hp(Permissions.voiceConnect),
|
||||
voiceSpeak: hp(Permissions.voiceSpeak),
|
||||
voiceMuteMembers: hp(Permissions.voiceMuteMembers),
|
||||
voiceDeafenMembers: hp(Permissions.voiceDeafenMembers),
|
||||
voiceMoveMembers: hp(Permissions.voiceMoveMembers),
|
||||
voiceUseVAD: hp(Permissions.voiceUseVAD)
|
||||
};
|
||||
}
|
||||
if (!perm) {
|
||||
return false;
|
||||
}, {
|
||||
key: "serialize",
|
||||
value: function serialize() {
|
||||
// ;n;
|
||||
return this.serialise();
|
||||
}
|
||||
if (!explicit) {
|
||||
// implicit permissions allowed
|
||||
if (!!(this.permissions & Permissions.manageRoles)) {
|
||||
// manageRoles allowed, they have all permissions
|
||||
return true;
|
||||
}, {
|
||||
key: "hasPermission",
|
||||
value: function hasPermission(perm) {
|
||||
var explicit = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
|
||||
|
||||
if (perm instanceof String || typeof perm === "string") {
|
||||
perm = Permissions[perm];
|
||||
}
|
||||
}
|
||||
// e.g.
|
||||
// !!(36953089 & Permissions.manageRoles) = not allowed to manage roles
|
||||
// !!(36953089 & (1 << 21)) = voice speak allowed
|
||||
|
||||
return !!(this.permissions & perm);
|
||||
}
|
||||
|
||||
setPermission(permission, value) {
|
||||
if (permission instanceof String || typeof permission === "string") {
|
||||
permission = Permissions[permission];
|
||||
}
|
||||
if (permission) {
|
||||
// valid permission
|
||||
if (value) {
|
||||
this.permissions |= permission;
|
||||
} else {
|
||||
this.permissions &= ~permission;
|
||||
if (!perm) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!explicit) {
|
||||
// implicit permissions allowed
|
||||
if (!!(this.permissions & Permissions.manageRoles)) {
|
||||
// manageRoles allowed, they have all permissions
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// e.g.
|
||||
// !!(36953089 & Permissions.manageRoles) = not allowed to manage roles
|
||||
// !!(36953089 & (1 << 21)) = voice speak allowed
|
||||
|
||||
setPermissions(obj) {
|
||||
obj.forEach((value, permission) => {
|
||||
return !!(this.permissions & perm);
|
||||
}
|
||||
}, {
|
||||
key: "setPermission",
|
||||
value: function setPermission(permission, value) {
|
||||
if (permission instanceof String || typeof permission === "string") {
|
||||
permission = Permissions[permission];
|
||||
}
|
||||
if (permission) {
|
||||
// valid permission
|
||||
this.setPermission(permission, value);
|
||||
if (value) {
|
||||
this.permissions |= permission;
|
||||
} else {
|
||||
this.permissions &= ~permission;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
colorAsHex() {
|
||||
var val = this.color.toString();
|
||||
while (val.length < 6) {
|
||||
val = "0" + val;
|
||||
}
|
||||
return "#" + val;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "setPermissions",
|
||||
value: function setPermissions(obj) {
|
||||
var _this2 = this;
|
||||
|
||||
obj.forEach(function (value, permission) {
|
||||
if (permission instanceof String || typeof permission === "string") {
|
||||
permission = Permissions[permission];
|
||||
}
|
||||
if (permission) {
|
||||
// valid permission
|
||||
_this2.setPermission(permission, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "colorAsHex",
|
||||
value: function colorAsHex() {
|
||||
var val = this.color.toString();
|
||||
while (val.length < 6) {
|
||||
val = "0" + val;
|
||||
}
|
||||
return "#" + val;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Role;
|
||||
})();
|
||||
|
||||
module.exports = Role;
|
||||
@@ -1,5 +1,13 @@
|
||||
"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"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
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 Equality = require("../Util/Equality.js");
|
||||
var Endpoints = require("../Constants.js").Endpoints;
|
||||
var Cache = require("../Util/Cache.js");
|
||||
@@ -10,114 +18,173 @@ var Role = require("./Role.js");
|
||||
|
||||
var strictKeys = ["region", "ownerID", "name", "id", "icon", "afkTimeout", "afkChannelID"];
|
||||
|
||||
class Server extends Equality {
|
||||
constructor(data, client) {
|
||||
var Server = (function (_Equality) {
|
||||
_inherits(Server, _Equality);
|
||||
|
||||
super();
|
||||
function Server(data, client) {
|
||||
_classCallCheck(this, Server);
|
||||
|
||||
var self = this;
|
||||
this.client = client;
|
||||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Server).call(this));
|
||||
|
||||
this.region = data.region;
|
||||
this.ownerID = data.owner_id;
|
||||
this.name = data.name;
|
||||
this.id = data.id;
|
||||
this.members = new Cache();
|
||||
this.channels = new Cache();
|
||||
this.roles = new Cache();
|
||||
this.icon = data.icon;
|
||||
this.afkTimeout = data.afkTimeout;
|
||||
this.afkChannelID = data.afk_channel_id;
|
||||
this.memberMap = {};
|
||||
var self = _this;
|
||||
_this.client = client;
|
||||
|
||||
var self = this;
|
||||
_this.region = data.region;
|
||||
_this.ownerID = data.owner_id;
|
||||
_this.name = data.name;
|
||||
_this.id = data.id;
|
||||
_this.members = new Cache();
|
||||
_this.channels = new Cache();
|
||||
_this.roles = new Cache();
|
||||
_this.icon = data.icon;
|
||||
_this.afkTimeout = data.afkTimeout;
|
||||
_this.afkChannelID = data.afk_channel_id;
|
||||
_this.memberMap = {};
|
||||
|
||||
data.roles.forEach(dataRole => {
|
||||
this.roles.add(new Role(dataRole, this, client));
|
||||
var self = _this;
|
||||
|
||||
data.roles.forEach(function (dataRole) {
|
||||
_this.roles.add(new Role(dataRole, _this, client));
|
||||
});
|
||||
|
||||
data.members.forEach(dataUser => {
|
||||
this.memberMap[dataUser.user.id] = {
|
||||
roles: dataUser.roles.map(pid => self.roles.get("id", pid)),
|
||||
data.members.forEach(function (dataUser) {
|
||||
_this.memberMap[dataUser.user.id] = {
|
||||
roles: dataUser.roles.map(function (pid) {
|
||||
return self.roles.get("id", pid);
|
||||
}),
|
||||
mute: dataUser.mute,
|
||||
deaf: dataUser.deaf,
|
||||
joinedAt: Date.parse(dataUser.joined_at)
|
||||
};
|
||||
var user = client.internal.users.add(new User(dataUser.user, client));
|
||||
this.members.add(user);
|
||||
_this.members.add(user);
|
||||
});
|
||||
|
||||
data.channels.forEach(dataChannel => {
|
||||
data.channels.forEach(function (dataChannel) {
|
||||
if (dataChannel.type === "text") {
|
||||
var channel = client.internal.channels.add(new TextChannel(dataChannel, client, this));
|
||||
this.channels.add(channel);
|
||||
var channel = client.internal.channels.add(new TextChannel(dataChannel, client, _this));
|
||||
_this.channels.add(channel);
|
||||
} else {
|
||||
var channel = client.internal.channels.add(new VoiceChannel(dataChannel, client, this));
|
||||
this.channels.add(channel);
|
||||
var channel = client.internal.channels.add(new VoiceChannel(dataChannel, client, _this));
|
||||
_this.channels.add(channel);
|
||||
}
|
||||
});
|
||||
|
||||
if (data.presences) {
|
||||
for (var presence of data.presences) {
|
||||
var user = client.internal.users.get("id", presence.user.id);
|
||||
if (user) {
|
||||
user.status = presence.status;
|
||||
user.gameID = presence.game_id;
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = data.presences[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var presence = _step.value;
|
||||
|
||||
var user = client.internal.users.get("id", presence.user.id);
|
||||
if (user) {
|
||||
user.status = presence.status;
|
||||
user.gameID = presence.game_id;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return _this;
|
||||
}
|
||||
|
||||
rolesOfUser(user) {
|
||||
user = this.client.internal.resolver.resolveUser(user);
|
||||
if (user) {
|
||||
return this.memberMap[user.id] ? this.memberMap[user.id].roles : [];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
rolesOf(user) {
|
||||
return this.rolesOfUser(user);
|
||||
}
|
||||
|
||||
get iconURL() {
|
||||
if (!this.icon) {
|
||||
return null;
|
||||
} else {
|
||||
return Endpoints.SERVER_ICON(this.id, this.icon);
|
||||
}
|
||||
}
|
||||
|
||||
get afkChannel() {
|
||||
return this.channels.get("id", this.afkChannelID);
|
||||
}
|
||||
|
||||
get defaultChannel() {
|
||||
return this.channels.get("id", this.id);
|
||||
}
|
||||
|
||||
get owner() {
|
||||
return this.members.get("id", this.ownerID);
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
equalsStrict(obj) {
|
||||
if (obj instanceof Server) {
|
||||
for (var key of strictKeys) {
|
||||
if (obj[key] !== this[key]) {
|
||||
return false;
|
||||
}
|
||||
_createClass(Server, [{
|
||||
key: "rolesOfUser",
|
||||
value: function rolesOfUser(user) {
|
||||
user = this.client.internal.resolver.resolveUser(user);
|
||||
if (user) {
|
||||
return this.memberMap[user.id] ? this.memberMap[user.id].roles : [];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}, {
|
||||
key: "rolesOf",
|
||||
value: function rolesOf(user) {
|
||||
return this.rolesOfUser(user);
|
||||
}
|
||||
}, {
|
||||
key: "toString",
|
||||
value: function toString() {
|
||||
return this.name;
|
||||
}
|
||||
}, {
|
||||
key: "equalsStrict",
|
||||
value: function equalsStrict(obj) {
|
||||
if (obj instanceof Server) {
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
|
||||
}
|
||||
try {
|
||||
for (var _iterator2 = strictKeys[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
||||
var key = _step2.value;
|
||||
|
||||
if (obj[key] !== this[key]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError2 = true;
|
||||
_iteratorError2 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
||||
_iterator2.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError2) {
|
||||
throw _iteratorError2;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}, {
|
||||
key: "iconURL",
|
||||
get: function get() {
|
||||
if (!this.icon) {
|
||||
return null;
|
||||
} else {
|
||||
return Endpoints.SERVER_ICON(this.id, this.icon);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "afkChannel",
|
||||
get: function get() {
|
||||
return this.channels.get("id", this.afkChannelID);
|
||||
}
|
||||
}, {
|
||||
key: "defaultChannel",
|
||||
get: function get() {
|
||||
return this.channels.get("id", this.id);
|
||||
}
|
||||
}, {
|
||||
key: "owner",
|
||||
get: function get() {
|
||||
return this.members.get("id", this.ownerID);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Server;
|
||||
})(Equality);
|
||||
|
||||
module.exports = Server;
|
||||
@@ -1,77 +1,144 @@
|
||||
"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"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
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 Channel = require("./Channel.js");
|
||||
var Cache = require("../Util/Cache.js");
|
||||
var PermissionOverwrite = require("./PermissionOverwrite.js");
|
||||
var ChannelPermissions = require("./ChannelPermissions.js");
|
||||
var reg = require("../Util/ArgumentRegulariser.js").reg;
|
||||
|
||||
class ServerChannel extends Channel {
|
||||
constructor(data, client, server) {
|
||||
super(data, client);
|
||||
this.name = data.name;
|
||||
this.type = data.type;
|
||||
this.position = data.position;
|
||||
this.permissionOverwrites = new Cache();
|
||||
this.server = server;
|
||||
data.permission_overwrites.forEach(permission => {
|
||||
this.permissionOverwrites.add(new PermissionOverwrite(permission));
|
||||
var ServerChannel = (function (_Channel) {
|
||||
_inherits(ServerChannel, _Channel);
|
||||
|
||||
function ServerChannel(data, client, server) {
|
||||
_classCallCheck(this, ServerChannel);
|
||||
|
||||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(ServerChannel).call(this, data, client));
|
||||
|
||||
_this.name = data.name;
|
||||
_this.type = data.type;
|
||||
_this.position = data.position;
|
||||
_this.permissionOverwrites = new Cache();
|
||||
_this.server = server;
|
||||
data.permission_overwrites.forEach(function (permission) {
|
||||
_this.permissionOverwrites.add(new PermissionOverwrite(permission));
|
||||
});
|
||||
return _this;
|
||||
}
|
||||
|
||||
permissionsOf(user) {
|
||||
user = this.client.internal.resolver.resolveUser(user);
|
||||
if (user) {
|
||||
if (this.server.owner.equals(user)) {
|
||||
return new ChannelPermissions(4294967295);
|
||||
}
|
||||
var everyoneRole = this.server.roles.get("name", "@everyone");
|
||||
|
||||
var userRoles = [everyoneRole].concat(this.server.rolesOf(user) || []);
|
||||
var userRolesID = userRoles.map(v => v.id);
|
||||
var roleOverwrites = [],
|
||||
memberOverwrites = [];
|
||||
|
||||
this.permissionOverwrites.forEach(overwrite => {
|
||||
if (overwrite.type === "member" && overwrite.id === user.id) {
|
||||
memberOverwrites.push(overwrite);
|
||||
} else if (overwrite.type === "role" && overwrite.id in userRolesID) {
|
||||
roleOverwrites.push(overwrite);
|
||||
_createClass(ServerChannel, [{
|
||||
key: "permissionsOf",
|
||||
value: function permissionsOf(user) {
|
||||
user = this.client.internal.resolver.resolveUser(user);
|
||||
if (user) {
|
||||
if (this.server.owner.equals(user)) {
|
||||
return new ChannelPermissions(4294967295);
|
||||
}
|
||||
});
|
||||
var everyoneRole = this.server.roles.get("name", "@everyone");
|
||||
|
||||
var permissions = 0;
|
||||
var userRoles = [everyoneRole].concat(this.server.rolesOf(user) || []);
|
||||
var userRolesID = userRoles.map(function (v) {
|
||||
return v.id;
|
||||
});
|
||||
var roleOverwrites = [],
|
||||
memberOverwrites = [];
|
||||
|
||||
for (var serverRole of userRoles) {
|
||||
permissions |= serverRole.permissions;
|
||||
this.permissionOverwrites.forEach(function (overwrite) {
|
||||
if (overwrite.type === "member" && overwrite.id === user.id) {
|
||||
memberOverwrites.push(overwrite);
|
||||
} else if (overwrite.type === "role" && overwrite.id in userRolesID) {
|
||||
roleOverwrites.push(overwrite);
|
||||
}
|
||||
});
|
||||
|
||||
var permissions = 0;
|
||||
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = userRoles[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var serverRole = _step.value;
|
||||
|
||||
permissions |= serverRole.permissions;
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator2 = roleOverwrites.concat(memberOverwrites)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
||||
var overwrite = _step2.value;
|
||||
|
||||
permissions = permissions & ~overwrite.deny;
|
||||
permissions = permissions | overwrite.allow;
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError2 = true;
|
||||
_iteratorError2 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
||||
_iterator2.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError2) {
|
||||
throw _iteratorError2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ChannelPermissions(permissions);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (var overwrite of roleOverwrites.concat(memberOverwrites)) {
|
||||
permissions = permissions & ~overwrite.deny;
|
||||
permissions = permissions | overwrite.allow;
|
||||
}
|
||||
|
||||
return new ChannelPermissions(permissions);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "permsOf",
|
||||
value: function permsOf(user) {
|
||||
return this.permissionsOf(user);
|
||||
}
|
||||
}, {
|
||||
key: "mention",
|
||||
value: function mention() {
|
||||
return "<#" + this.id + ">";
|
||||
}
|
||||
}, {
|
||||
key: "toString",
|
||||
value: function toString() {
|
||||
return this.mention();
|
||||
}
|
||||
}, {
|
||||
key: "setName",
|
||||
value: function setName() {
|
||||
return this.client.setChannelName.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}]);
|
||||
|
||||
permsOf(user) {
|
||||
return this.permissionsOf(user);
|
||||
}
|
||||
|
||||
mention() {
|
||||
return `<#${ this.id }>`;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.mention();
|
||||
}
|
||||
|
||||
setName() {
|
||||
return this.client.setChannelName.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}
|
||||
return ServerChannel;
|
||||
})(Channel);
|
||||
|
||||
module.exports = ServerChannel;
|
||||
@@ -1,42 +1,66 @@
|
||||
"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"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
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 ServerChannel = require("./ServerChannel.js");
|
||||
var Cache = require("../Util/Cache.js");
|
||||
var reg = require("../Util/ArgumentRegulariser.js").reg;
|
||||
|
||||
class TextChannel extends ServerChannel {
|
||||
constructor(data, client, server) {
|
||||
super(data, client, server);
|
||||
var TextChannel = (function (_ServerChannel) {
|
||||
_inherits(TextChannel, _ServerChannel);
|
||||
|
||||
this.topic = data.topic;
|
||||
this.lastMessageID = data.last_message_id;
|
||||
this.messages = new Cache("id", client.options.maximumMessages);
|
||||
function TextChannel(data, client, server) {
|
||||
_classCallCheck(this, TextChannel);
|
||||
|
||||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(TextChannel).call(this, data, client, server));
|
||||
|
||||
_this.topic = data.topic;
|
||||
_this.lastMessageID = data.last_message_id;
|
||||
_this.messages = new Cache("id", client.options.maximumMessages);
|
||||
return _this;
|
||||
}
|
||||
|
||||
/* warning! may return null */
|
||||
get lastMessage() {
|
||||
return this.messages.get("id", this.lastMessageID);
|
||||
}
|
||||
|
||||
setTopic() {
|
||||
return this.client.setTopic.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
_createClass(TextChannel, [{
|
||||
key: "setTopic",
|
||||
value: function setTopic() {
|
||||
return this.client.setTopic.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}, {
|
||||
key: "setNameAndTopic",
|
||||
value: function setNameAndTopic() {
|
||||
return this.client.setChannelNameAndTopic.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}, {
|
||||
key: "update",
|
||||
value: function update() {
|
||||
return this.client.updateChannel.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}, {
|
||||
key: "sendMessage",
|
||||
value: function sendMessage() {
|
||||
return this.client.sendMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}, {
|
||||
key: "sendTTSMessage",
|
||||
value: function sendTTSMessage() {
|
||||
return this.client.sendTTSMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}, {
|
||||
key: "lastMessage",
|
||||
get: function get() {
|
||||
return this.messages.get("id", this.lastMessageID);
|
||||
}
|
||||
}]);
|
||||
|
||||
setNameAndTopic() {
|
||||
return this.client.setChannelNameAndTopic.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
update() {
|
||||
return this.client.updateChannel.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
sendMessage() {
|
||||
return this.client.sendMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
|
||||
sendTTSMessage() {
|
||||
return this.client.sendTTSMessage.apply(this.client, reg(this, arguments));
|
||||
}
|
||||
}
|
||||
return TextChannel;
|
||||
})(ServerChannel);
|
||||
|
||||
module.exports = TextChannel;
|
||||
@@ -1,43 +1,65 @@
|
||||
"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"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
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 Equality = require("../Util/Equality.js");
|
||||
var Endpoints = require("../Constants.js").Endpoints;
|
||||
|
||||
class User extends Equality {
|
||||
constructor(data, client) {
|
||||
super();
|
||||
this.client = client;
|
||||
this.username = data.username;
|
||||
this.discriminator = data.discriminator;
|
||||
this.id = data.id;
|
||||
this.avatar = data.avatar;
|
||||
this.status = data.status || "offline";
|
||||
this.gameID = data.game_id || null;
|
||||
this.typing = {
|
||||
var User = (function (_Equality) {
|
||||
_inherits(User, _Equality);
|
||||
|
||||
function User(data, client) {
|
||||
_classCallCheck(this, User);
|
||||
|
||||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(User).call(this));
|
||||
|
||||
_this.client = client;
|
||||
_this.username = data.username;
|
||||
_this.discriminator = data.discriminator;
|
||||
_this.id = data.id;
|
||||
_this.avatar = data.avatar;
|
||||
_this.status = data.status || "offline";
|
||||
_this.gameID = data.game_id || null;
|
||||
_this.typing = {
|
||||
since: null,
|
||||
channel: null
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
|
||||
get avatarURL() {
|
||||
if (!this.avatar) {
|
||||
return null;
|
||||
} else {
|
||||
return Endpoints.AVATAR(this.id, this.avatar);
|
||||
_createClass(User, [{
|
||||
key: "mention",
|
||||
value: function mention() {
|
||||
return "<@" + this.id + ">";
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "toString",
|
||||
value: function toString() {
|
||||
return this.mention();
|
||||
}
|
||||
}, {
|
||||
key: "equalsStrict",
|
||||
value: function equalsStrict(obj) {
|
||||
if (obj instanceof User) return this.id === obj.id && this.username === obj.username && this.discriminator === obj.discriminator && this.avatar === obj.avatar && this.status === obj.status && this.gameID === obj.gameID;else return false;
|
||||
}
|
||||
}, {
|
||||
key: "avatarURL",
|
||||
get: function get() {
|
||||
if (!this.avatar) {
|
||||
return null;
|
||||
} else {
|
||||
return Endpoints.AVATAR(this.id, this.avatar);
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
||||
mention() {
|
||||
return `<@${ this.id }>`;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.mention();
|
||||
}
|
||||
|
||||
equalsStrict(obj) {
|
||||
if (obj instanceof User) return this.id === obj.id && this.username === obj.username && this.discriminator === obj.discriminator && this.avatar === obj.avatar && this.status === obj.status && this.gameID === obj.gameID;else return false;
|
||||
}
|
||||
}
|
||||
return User;
|
||||
})(Equality);
|
||||
|
||||
module.exports = User;
|
||||
@@ -1,11 +1,23 @@
|
||||
"use strict";
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
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 ServerChannel = require("./ServerChannel.js");
|
||||
|
||||
class VoiceChannel extends ServerChannel {
|
||||
constructor(data, client, server) {
|
||||
super(data, client, server);
|
||||
var VoiceChannel = (function (_ServerChannel) {
|
||||
_inherits(VoiceChannel, _ServerChannel);
|
||||
|
||||
function VoiceChannel(data, client, server) {
|
||||
_classCallCheck(this, VoiceChannel);
|
||||
|
||||
return _possibleConstructorReturn(this, Object.getPrototypeOf(VoiceChannel).call(this, data, client, server));
|
||||
}
|
||||
}
|
||||
|
||||
return VoiceChannel;
|
||||
})(ServerChannel);
|
||||
|
||||
module.exports = VoiceChannel;
|
||||
Reference in New Issue
Block a user