mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Fixed compiled version
Downgraded babel until a working solution found
This commit is contained in:
1472
lib/Client/Client.js
1472
lib/Client/Client.js
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,6 @@
|
|||||||
"use strict"
|
"use strict";
|
||||||
/* global Buffer */
|
/* global Buffer */
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
@@ -27,254 +23,215 @@ var Resolver = (function () {
|
|||||||
this.internal = internal;
|
this.internal = internal;
|
||||||
}
|
}
|
||||||
|
|
||||||
_createClass(Resolver, [{
|
Resolver.prototype.resolveGameID = function resolveGameID(resource) {
|
||||||
key: "resolveGameID",
|
if (!isNaN(resource) && parseInt(resource) % 1 === 0) {
|
||||||
value: function resolveGameID(resource) {
|
|
||||||
if (!isNaN(resource) && parseInt(resource) % 1 === 0) {
|
|
||||||
return resource;
|
|
||||||
} else if (typeof resource == "string" || resource instanceof String) {
|
|
||||||
var _iteratorNormalCompletion = true;
|
|
||||||
var _didIteratorError = false;
|
|
||||||
var _iteratorError = undefined;
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
for (var _iterator = Games[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
||||||
var game = _step.value;
|
|
||||||
|
|
||||||
if (game.name.toUpperCase() === resource.toUpperCase()) {
|
|
||||||
return game.id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
_didIteratorError = true;
|
|
||||||
_iteratorError = err;
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
|
||||||
_iterator.return();
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (_didIteratorError) {
|
|
||||||
throw _iteratorError;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: "resolveToBase64",
|
|
||||||
value: function resolveToBase64(resource) {
|
|
||||||
if (resource instanceof Buffer) {
|
|
||||||
resource = resource.toString("base64");
|
|
||||||
resource = "data:image/jpg;base64," + resource;
|
|
||||||
}
|
|
||||||
return resource;
|
return resource;
|
||||||
}
|
} else if (typeof resource == "string" || resource instanceof String) {
|
||||||
}, {
|
|
||||||
key: "resolveInviteID",
|
|
||||||
value: function resolveInviteID(resource) {
|
|
||||||
if (resource instanceof Invite) {
|
|
||||||
return resource.id;
|
|
||||||
} else if (typeof resource == "string" || resource instanceof String) {
|
|
||||||
|
|
||||||
if (resource.indexOf("http") === 0) {
|
for (var _iterator = Games, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||||
var split = resource.split("/");
|
var _ref;
|
||||||
return split.pop();
|
|
||||||
|
if (_isArray) {
|
||||||
|
if (_i >= _iterator.length) break;
|
||||||
|
_ref = _iterator[_i++];
|
||||||
} else {
|
} else {
|
||||||
return resource;
|
_i = _iterator.next();
|
||||||
|
if (_i.done) break;
|
||||||
|
_ref = _i.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var game = _ref;
|
||||||
|
|
||||||
|
if (game.name.toUpperCase() === resource.toUpperCase()) {
|
||||||
|
return game.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}, {
|
|
||||||
key: "resolveServer",
|
return null;
|
||||||
value: function resolveServer(resource) {
|
};
|
||||||
if (resource instanceof Server) {
|
|
||||||
return resource;
|
Resolver.prototype.resolveToBase64 = function resolveToBase64(resource) {
|
||||||
} else if (resource instanceof ServerChannel) {
|
if (resource instanceof Buffer) {
|
||||||
return resource.server;
|
resource = resource.toString("base64");
|
||||||
} else if (resource instanceof String || typeof resource === "string") {
|
resource = "data:image/jpg;base64," + resource;
|
||||||
return this.internal.servers.get("id", resource);
|
|
||||||
} else if (resource instanceof Message) {
|
|
||||||
if (resource.channel instanceof TextChannel) {
|
|
||||||
return resource.server;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}, {
|
return resource;
|
||||||
key: "resolveFile",
|
};
|
||||||
value: function resolveFile(resource) {
|
|
||||||
if (typeof resource === "string" || resource instanceof String) {
|
Resolver.prototype.resolveInviteID = function resolveInviteID(resource) {
|
||||||
return fs.createReadStream(resource);
|
if (resource instanceof Invite) {
|
||||||
|
return resource.id;
|
||||||
|
} else if (typeof resource == "string" || resource instanceof String) {
|
||||||
|
|
||||||
|
if (resource.indexOf("http") === 0) {
|
||||||
|
var split = resource.split("/");
|
||||||
|
return split.pop();
|
||||||
} else {
|
} else {
|
||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, {
|
return null;
|
||||||
key: "resolveMentions",
|
};
|
||||||
value: function resolveMentions(resource) {
|
|
||||||
// resource is a string
|
|
||||||
var _mentions = [];
|
|
||||||
var _iteratorNormalCompletion2 = true;
|
|
||||||
var _didIteratorError2 = false;
|
|
||||||
var _iteratorError2 = undefined;
|
|
||||||
|
|
||||||
try {
|
Resolver.prototype.resolveServer = function resolveServer(resource) {
|
||||||
for (var _iterator2 = (resource.match(/<@[^>]*>/g) || [])[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
if (resource instanceof Server) {
|
||||||
var mention = _step2.value;
|
return resource;
|
||||||
|
} else if (resource instanceof ServerChannel) {
|
||||||
|
return resource.server;
|
||||||
|
} else if (resource instanceof String || typeof resource === "string") {
|
||||||
|
return this.internal.servers.get("id", resource);
|
||||||
|
} else if (resource instanceof Message) {
|
||||||
|
if (resource.channel instanceof TextChannel) {
|
||||||
|
return resource.server;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
_mentions.push(mention.substring(2, mention.length - 1));
|
Resolver.prototype.resolveFile = function resolveFile(resource) {
|
||||||
}
|
if (typeof resource === "string" || resource instanceof String) {
|
||||||
} catch (err) {
|
return fs.createReadStream(resource);
|
||||||
_didIteratorError2 = true;
|
} else {
|
||||||
_iteratorError2 = err;
|
return resource;
|
||||||
} finally {
|
}
|
||||||
try {
|
};
|
||||||
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
|
||||||
_iterator2.return();
|
Resolver.prototype.resolveMentions = function resolveMentions(resource) {
|
||||||
}
|
// resource is a string
|
||||||
} finally {
|
var _mentions = [];
|
||||||
if (_didIteratorError2) {
|
for (var _iterator2 = resource.match(/<@[^>]*>/g) || [], _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||||
throw _iteratorError2;
|
var _ref2;
|
||||||
}
|
|
||||||
}
|
if (_isArray2) {
|
||||||
|
if (_i2 >= _iterator2.length) break;
|
||||||
|
_ref2 = _iterator2[_i2++];
|
||||||
|
} else {
|
||||||
|
_i2 = _iterator2.next();
|
||||||
|
if (_i2.done) break;
|
||||||
|
_ref2 = _i2.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _mentions;
|
var mention = _ref2;
|
||||||
|
|
||||||
|
_mentions.push(mention.substring(2, mention.length - 1));
|
||||||
}
|
}
|
||||||
}, {
|
return _mentions;
|
||||||
key: "resolveString",
|
};
|
||||||
value: function resolveString(resource) {
|
|
||||||
|
|
||||||
// accepts Array, Channel, Server, User, Message, String and anything
|
Resolver.prototype.resolveString = function resolveString(resource) {
|
||||||
// toString()-able
|
|
||||||
|
|
||||||
var final = resource;
|
// accepts Array, Channel, Server, User, Message, String and anything
|
||||||
if (resource instanceof Array) {
|
// toString()-able
|
||||||
final = resource.join("\n");
|
|
||||||
|
var final = resource;
|
||||||
|
if (resource instanceof Array) {
|
||||||
|
final = resource.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return final.toString();
|
||||||
|
};
|
||||||
|
|
||||||
|
Resolver.prototype.resolveUser = function resolveUser(resource) {
|
||||||
|
/*
|
||||||
|
accepts a Message, Channel, Server, String ID, User, PMChannel
|
||||||
|
*/
|
||||||
|
var found = null;
|
||||||
|
if (resource instanceof User) {
|
||||||
|
found = resource;
|
||||||
|
} else if (resource instanceof Message) {
|
||||||
|
found = resource.author;
|
||||||
|
} else if (resource instanceof TextChannel) {
|
||||||
|
var lmsg = resource.lastMessage;
|
||||||
|
if (lmsg) {
|
||||||
|
found = lmsg.author;
|
||||||
}
|
}
|
||||||
|
} else if (resource instanceof Server) {
|
||||||
return final.toString();
|
found = resource.owner;
|
||||||
|
} else if (resource instanceof PMChannel) {
|
||||||
|
found = resource.recipient;
|
||||||
|
} else if (resource instanceof String || typeof resource === "string") {
|
||||||
|
found = this.client.internal.users.get("id", resource);
|
||||||
}
|
}
|
||||||
}, {
|
|
||||||
key: "resolveUser",
|
return found;
|
||||||
value: function resolveUser(resource) {
|
};
|
||||||
/*
|
|
||||||
accepts a Message, Channel, Server, String ID, User, PMChannel
|
Resolver.prototype.resolveMessage = function resolveMessage(resource) {
|
||||||
|
// accepts a Message, PMChannel & TextChannel
|
||||||
|
var found = null;
|
||||||
|
|
||||||
|
if (resource instanceof TextChannel || resource instanceof PMChannel) {
|
||||||
|
found = resource.lastMessage;
|
||||||
|
} else if (resource instanceof Message) {
|
||||||
|
found = resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
return found;
|
||||||
|
};
|
||||||
|
|
||||||
|
Resolver.prototype.resolveVoiceChannel = function resolveVoiceChannel(resource) {
|
||||||
|
// resolveChannel will also work but this is more apt
|
||||||
|
if (resource instanceof VoiceChannel) {
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
Resolver.prototype.resolveChannel = function resolveChannel(resource) {
|
||||||
|
/*
|
||||||
|
accepts a Message, Channel, Server, String ID, User
|
||||||
*/
|
*/
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
var found = null;
|
var found = null;
|
||||||
if (resource instanceof User) {
|
if (resource instanceof Message) {
|
||||||
|
found = resource.channel;
|
||||||
|
} else if (resource instanceof Channel) {
|
||||||
found = resource;
|
found = resource;
|
||||||
} else if (resource instanceof Message) {
|
|
||||||
found = resource.author;
|
|
||||||
} else if (resource instanceof TextChannel) {
|
|
||||||
var lmsg = resource.lastMessage;
|
|
||||||
if (lmsg) {
|
|
||||||
found = lmsg.author;
|
|
||||||
}
|
|
||||||
} else if (resource instanceof Server) {
|
} else if (resource instanceof Server) {
|
||||||
found = resource.owner;
|
found = resource.channels.get("id", resource.id);
|
||||||
} else if (resource instanceof PMChannel) {
|
|
||||||
found = resource.recipient;
|
|
||||||
} else if (resource instanceof String || typeof resource === "string") {
|
} else if (resource instanceof String || typeof resource === "string") {
|
||||||
found = this.client.internal.users.get("id", resource);
|
found = self.internal.channels.get("id", resource);
|
||||||
}
|
} else if (resource instanceof User) {
|
||||||
|
// see if a PM exists
|
||||||
|
var chatFound = false;
|
||||||
|
for (var _iterator3 = self.internal.private_channels, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
||||||
|
var _ref3;
|
||||||
|
|
||||||
return found;
|
if (_isArray3) {
|
||||||
}
|
if (_i3 >= _iterator3.length) break;
|
||||||
}, {
|
_ref3 = _iterator3[_i3++];
|
||||||
key: "resolveMessage",
|
} else {
|
||||||
value: function resolveMessage(resource) {
|
_i3 = _iterator3.next();
|
||||||
// accepts a Message, PMChannel & TextChannel
|
if (_i3.done) break;
|
||||||
var found = null;
|
_ref3 = _i3.value;
|
||||||
|
|
||||||
if (resource instanceof TextChannel || resource instanceof PMChannel) {
|
|
||||||
found = resource.lastMessage;
|
|
||||||
} else if (resource instanceof Message) {
|
|
||||||
found = resource;
|
|
||||||
}
|
|
||||||
|
|
||||||
return found;
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: "resolveVoiceChannel",
|
|
||||||
value: function resolveVoiceChannel(resource) {
|
|
||||||
// resolveChannel will also work but this is more apt
|
|
||||||
if (resource instanceof VoiceChannel) {
|
|
||||||
return resource;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: "resolveChannel",
|
|
||||||
value: function resolveChannel(resource) {
|
|
||||||
/*
|
|
||||||
accepts a Message, Channel, Server, String ID, User
|
|
||||||
*/
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
return new Promise(function (resolve, reject) {
|
|
||||||
var found = null;
|
|
||||||
if (resource instanceof Message) {
|
|
||||||
found = resource.channel;
|
|
||||||
} else if (resource instanceof Channel) {
|
|
||||||
found = resource;
|
|
||||||
} else if (resource instanceof Server) {
|
|
||||||
found = resource.channels.get("id", resource.id);
|
|
||||||
} else if (resource instanceof String || typeof resource === "string") {
|
|
||||||
found = self.internal.channels.get("id", resource);
|
|
||||||
} else if (resource instanceof User) {
|
|
||||||
// see if a PM exists
|
|
||||||
var chatFound = false;
|
|
||||||
var _iteratorNormalCompletion3 = true;
|
|
||||||
var _didIteratorError3 = false;
|
|
||||||
var _iteratorError3 = undefined;
|
|
||||||
|
|
||||||
try {
|
|
||||||
for (var _iterator3 = self.internal.private_channels[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
||||||
var pmchat = _step3.value;
|
|
||||||
|
|
||||||
if (pmchat.recipient.equals(resource)) {
|
|
||||||
chatFound = pmchat;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
_didIteratorError3 = true;
|
|
||||||
_iteratorError3 = err;
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
|
||||||
_iterator3.return();
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (_didIteratorError3) {
|
|
||||||
throw _iteratorError3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chatFound) {
|
var pmchat = _ref3;
|
||||||
// a PM already exists!
|
|
||||||
found = chatFound;
|
if (pmchat.recipient.equals(resource)) {
|
||||||
} else {
|
chatFound = pmchat;
|
||||||
// PM does not exist :\
|
break;
|
||||||
self.internal.startPM(resource).then(function (pmchannel) {
|
|
||||||
return resolve(pmchannel);
|
|
||||||
}).catch(function (e) {
|
|
||||||
return reject(e);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (found) resolve(found);else reject(new Error("Didn't found anything"));
|
if (chatFound) {
|
||||||
});
|
// a PM already exists!
|
||||||
}
|
found = chatFound;
|
||||||
}]);
|
} else {
|
||||||
|
// PM does not exist :\
|
||||||
|
self.internal.startPM(resource).then(function (pmchannel) {
|
||||||
|
return resolve(pmchannel);
|
||||||
|
})["catch"](function (e) {
|
||||||
|
return reject(e);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found) resolve(found);else reject(new Error("Didn't found anything"));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return Resolver;
|
return Resolver;
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ var _createClass = (function () { function defineProperties(target, props) { for
|
|||||||
|
|
||||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
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; }
|
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 Equality = require("../Util/Equality.js");
|
||||||
@@ -19,19 +17,16 @@ var Channel = (function (_Equality) {
|
|||||||
function Channel(data, client) {
|
function Channel(data, client) {
|
||||||
_classCallCheck(this, Channel);
|
_classCallCheck(this, Channel);
|
||||||
|
|
||||||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Channel).call(this));
|
_Equality.call(this);
|
||||||
|
this.id = data.id;
|
||||||
_this.id = data.id;
|
this.client = client;
|
||||||
_this.client = client;
|
|
||||||
return _this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Channel.prototype["delete"] = function _delete() {
|
||||||
|
return this.client.deleteChannel.apply(this.client, reg(this, arguments));
|
||||||
|
};
|
||||||
|
|
||||||
_createClass(Channel, [{
|
_createClass(Channel, [{
|
||||||
key: "delete",
|
|
||||||
value: function _delete() {
|
|
||||||
return this.client.deleteChannel.apply(this.client, reg(this, arguments));
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: "isPrivate",
|
key: "isPrivate",
|
||||||
get: function get() {
|
get: function get() {
|
||||||
return !!this.server;
|
return !!this.server;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
"use strict";
|
"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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
var Permissions = require("../Constants.js").Permissions;
|
var Permissions = require("../Constants.js").Permissions;
|
||||||
@@ -13,68 +11,63 @@ var ChannelPermissions = (function () {
|
|||||||
this.permissions = permissions;
|
this.permissions = permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
_createClass(ChannelPermissions, [{
|
ChannelPermissions.prototype.serialise = function serialise(explicit) {
|
||||||
key: "serialise",
|
var _this = this;
|
||||||
value: function serialise(explicit) {
|
|
||||||
var _this = this;
|
|
||||||
|
|
||||||
var hp = function hp(perm) {
|
var hp = function hp(perm) {
|
||||||
return _this.hasPermission(perm, explicit);
|
return _this.hasPermission(perm, explicit);
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// general
|
// general
|
||||||
createInstantInvite: hp(Permissions.createInstantInvite),
|
createInstantInvite: hp(Permissions.createInstantInvite),
|
||||||
kickMembers: hp(Permissions.kickMembers),
|
kickMembers: hp(Permissions.kickMembers),
|
||||||
banMembers: hp(Permissions.banMembers),
|
banMembers: hp(Permissions.banMembers),
|
||||||
managePermissions: hp(Permissions.managePermissions),
|
managePermissions: hp(Permissions.managePermissions),
|
||||||
manageChannel: hp(Permissions.manageChannel),
|
manageChannel: hp(Permissions.manageChannel),
|
||||||
manageServer: hp(Permissions.manageServer),
|
manageServer: hp(Permissions.manageServer),
|
||||||
// text
|
// text
|
||||||
readMessages: hp(Permissions.readMessages),
|
readMessages: hp(Permissions.readMessages),
|
||||||
sendMessages: hp(Permissions.sendMessages),
|
sendMessages: hp(Permissions.sendMessages),
|
||||||
sendTTSMessages: hp(Permissions.sendTTSMessages),
|
sendTTSMessages: hp(Permissions.sendTTSMessages),
|
||||||
manageMessages: hp(Permissions.manageMessages),
|
manageMessages: hp(Permissions.manageMessages),
|
||||||
embedLinks: hp(Permissions.embedLinks),
|
embedLinks: hp(Permissions.embedLinks),
|
||||||
attachFiles: hp(Permissions.attachFiles),
|
attachFiles: hp(Permissions.attachFiles),
|
||||||
readMessageHistory: hp(Permissions.readMessageHistory),
|
readMessageHistory: hp(Permissions.readMessageHistory),
|
||||||
mentionEveryone: hp(Permissions.mentionEveryone),
|
mentionEveryone: hp(Permissions.mentionEveryone),
|
||||||
// voice
|
// voice
|
||||||
voiceConnect: hp(Permissions.voiceConnect),
|
voiceConnect: hp(Permissions.voiceConnect),
|
||||||
voiceSpeak: hp(Permissions.voiceSpeak),
|
voiceSpeak: hp(Permissions.voiceSpeak),
|
||||||
voiceMuteMembers: hp(Permissions.voiceMuteMembers),
|
voiceMuteMembers: hp(Permissions.voiceMuteMembers),
|
||||||
voiceDeafenMembers: hp(Permissions.voiceDeafenMembers),
|
voiceDeafenMembers: hp(Permissions.voiceDeafenMembers),
|
||||||
voiceMoveMembers: hp(Permissions.voiceMoveMembers),
|
voiceMoveMembers: hp(Permissions.voiceMoveMembers),
|
||||||
voiceUseVAD: hp(Permissions.voiceUseVAD)
|
voiceUseVAD: hp(Permissions.voiceUseVAD)
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
}, {
|
|
||||||
key: "serialize",
|
|
||||||
value: function serialize() {
|
|
||||||
// ;n;
|
|
||||||
return this.serialise();
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: "hasPermission",
|
|
||||||
value: function hasPermission(perm) {
|
|
||||||
var explicit = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
|
|
||||||
|
|
||||||
if (perm instanceof String || typeof perm === "string") {
|
ChannelPermissions.prototype.serialize = function serialize() {
|
||||||
perm = Permissions[perm];
|
// ;n;
|
||||||
}
|
return this.serialise();
|
||||||
if (!perm) {
|
};
|
||||||
return false;
|
|
||||||
}
|
ChannelPermissions.prototype.hasPermission = function hasPermission(perm) {
|
||||||
if (!explicit) {
|
var explicit = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
|
||||||
// implicit permissions allowed
|
|
||||||
if (!!(this.permissions & Permissions.manageRoles)) {
|
if (perm instanceof String || typeof perm === "string") {
|
||||||
// manageRoles allowed, they have all permissions
|
perm = Permissions[perm];
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return !!(this.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 ChannelPermissions;
|
return ChannelPermissions;
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
"use strict";
|
"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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
var Server = require("./Server.js");
|
var Server = require("./Server.js");
|
||||||
@@ -24,12 +22,9 @@ var Invite = (function () {
|
|||||||
this.xkcd = data.xkcdpass;
|
this.xkcd = data.xkcdpass;
|
||||||
}
|
}
|
||||||
|
|
||||||
_createClass(Invite, [{
|
Invite.prototype.toString = function toString() {
|
||||||
key: "toString",
|
return "https://discord.gg/" + this.code;
|
||||||
value: function toString() {
|
};
|
||||||
return "https://discord.gg/" + this.code;
|
|
||||||
}
|
|
||||||
}]);
|
|
||||||
|
|
||||||
return Invite;
|
return Invite;
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ var _createClass = (function () { function defineProperties(target, props) { for
|
|||||||
|
|
||||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
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; }
|
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 Cache = require("../Util/Cache.js");
|
||||||
@@ -17,26 +15,27 @@ var Message = (function (_Equality) {
|
|||||||
_inherits(Message, _Equality);
|
_inherits(Message, _Equality);
|
||||||
|
|
||||||
function Message(data, channel, client) {
|
function Message(data, channel, client) {
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
_classCallCheck(this, Message);
|
_classCallCheck(this, Message);
|
||||||
|
|
||||||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Message).call(this));
|
_Equality.call(this);
|
||||||
|
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;
|
||||||
|
|
||||||
_this.channel = channel;
|
if (data.edited_timestamp) this.editedTimestamp = Date.parse(data.edited_timestamp);
|
||||||
_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;
|
|
||||||
|
|
||||||
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));
|
||||||
|
|
||||||
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();
|
||||||
_this.content = data.content;
|
|
||||||
_this.mentions = new Cache();
|
|
||||||
|
|
||||||
data.mentions.forEach(function (mention) {
|
data.mentions.forEach(function (mention) {
|
||||||
// this is .add and not .get because it allows the bot to cache
|
// this is .add and not .get because it allows the bot to cache
|
||||||
@@ -44,45 +43,38 @@ var Message = (function (_Equality) {
|
|||||||
// not previously cached.
|
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Message.prototype.isMentioned = function isMentioned(user) {
|
||||||
|
user = this.client.internal.resolver.resolveUser(user);
|
||||||
|
if (user) {
|
||||||
|
return this.mentions.has("id", user.id);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Message.prototype.toString = function toString() {
|
||||||
|
return this.content;
|
||||||
|
};
|
||||||
|
|
||||||
|
Message.prototype["delete"] = function _delete() {
|
||||||
|
return this.client.deleteMessage.apply(this.client, reg(this, arguments));
|
||||||
|
};
|
||||||
|
|
||||||
|
Message.prototype.update = function update() {
|
||||||
|
return this.client.updateMessage.apply(this.client, reg(this, arguments));
|
||||||
|
};
|
||||||
|
|
||||||
|
Message.prototype.reply = function reply() {
|
||||||
|
return this.client.reply.apply(this.client, reg(this, arguments));
|
||||||
|
};
|
||||||
|
|
||||||
|
Message.prototype.replyTTS = function replyTTS() {
|
||||||
|
return this.client.replyTTS.apply(this.client, reg(this, arguments));
|
||||||
|
};
|
||||||
|
|
||||||
_createClass(Message, [{
|
_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",
|
key: "sender",
|
||||||
get: function get() {
|
get: function get() {
|
||||||
return this.author;
|
return this.author;
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ var _createClass = (function () { function defineProperties(target, props) { for
|
|||||||
|
|
||||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
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; }
|
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 Channel = require("./Channel.js");
|
||||||
@@ -20,33 +18,29 @@ var PMChannel = (function (_Channel) {
|
|||||||
function PMChannel(data, client) {
|
function PMChannel(data, client) {
|
||||||
_classCallCheck(this, PMChannel);
|
_classCallCheck(this, PMChannel);
|
||||||
|
|
||||||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(PMChannel).call(this, data, client));
|
_Channel.call(this, data, client);
|
||||||
|
|
||||||
_this.type = data.type || "text";
|
this.type = data.type || "text";
|
||||||
_this.lastMessageId = data.last_message_id;
|
this.lastMessageId = data.last_message_id;
|
||||||
_this.messages = new Cache("id", 1000);
|
this.messages = new Cache("id", 1000);
|
||||||
_this.recipient = _this.client.internal.users.add(new User(data.recipient, _this.client));
|
this.recipient = this.client.internal.users.add(new User(data.recipient, this.client));
|
||||||
return _this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* warning! may return null */
|
/* warning! may return null */
|
||||||
|
|
||||||
|
PMChannel.prototype.toString = function toString() {
|
||||||
|
return this.recipient.toString();
|
||||||
|
};
|
||||||
|
|
||||||
|
PMChannel.prototype.sendMessage = function sendMessage() {
|
||||||
|
return this.client.sendMessage.apply(this.client, reg(this, arguments));
|
||||||
|
};
|
||||||
|
|
||||||
|
PMChannel.prototype.sendTTSMessage = function sendTTSMessage() {
|
||||||
|
return this.client.sendTTSMessage.apply(this.client, reg(this, arguments));
|
||||||
|
};
|
||||||
|
|
||||||
_createClass(PMChannel, [{
|
_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",
|
key: "lastMessage",
|
||||||
get: function get() {
|
get: function get() {
|
||||||
return this.messages.get("id", this.lastMessageID);
|
return this.messages.get("id", this.lastMessageID);
|
||||||
|
|||||||
@@ -18,35 +18,33 @@ var PermissionOverwrite = (function () {
|
|||||||
|
|
||||||
// returns an array of allowed permissions
|
// returns an array of allowed permissions
|
||||||
|
|
||||||
|
PermissionOverwrite.prototype.setAllowed = 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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
PermissionOverwrite.prototype.setDenied = function setDenied(deniedArray) {
|
||||||
|
var _this2 = this;
|
||||||
|
|
||||||
|
deniedArray.forEach(function (permission) {
|
||||||
|
if (permission instanceof String || typeof permission === "string") {
|
||||||
|
permission = Permissions[permission];
|
||||||
|
}
|
||||||
|
if (permission) {
|
||||||
|
_this2.deny |= 1 << permission;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
_createClass(PermissionOverwrite, [{
|
_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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: "setDenied",
|
|
||||||
value: function setDenied(deniedArray) {
|
|
||||||
var _this2 = this;
|
|
||||||
|
|
||||||
deniedArray.forEach(function (permission) {
|
|
||||||
if (permission instanceof String || typeof permission === "string") {
|
|
||||||
permission = Permissions[permission];
|
|
||||||
}
|
|
||||||
if (permission) {
|
|
||||||
_this2.deny |= 1 << permission;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: "allowed",
|
key: "allowed",
|
||||||
get: function get() {
|
get: function get() {
|
||||||
var allowed = [];
|
var allowed = [];
|
||||||
@@ -64,7 +62,6 @@ var PermissionOverwrite = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// returns an array of denied permissions
|
// returns an array of denied permissions
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
key: "denied",
|
key: "denied",
|
||||||
get: function get() {
|
get: function get() {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
"use strict";
|
"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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
var Permissions = require("../Constants.js").Permissions;
|
var Permissions = require("../Constants.js").Permissions;
|
||||||
@@ -37,111 +35,103 @@ var Role = (function () {
|
|||||||
this.client = client;
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
_createClass(Role, [{
|
Role.prototype.serialise = function serialise(explicit) {
|
||||||
key: "serialise",
|
var _this = this;
|
||||||
value: function serialise(explicit) {
|
|
||||||
var _this = this;
|
|
||||||
|
|
||||||
var hp = function hp(perm) {
|
var hp = function hp(perm) {
|
||||||
return _this.hasPermission(perm, explicit);
|
return _this.hasPermission(perm, explicit);
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// general
|
// general
|
||||||
createInstantInvite: hp(Permissions.createInstantInvite),
|
createInstantInvite: hp(Permissions.createInstantInvite),
|
||||||
kickMembers: hp(Permissions.kickMembers),
|
kickMembers: hp(Permissions.kickMembers),
|
||||||
banMembers: hp(Permissions.banMembers),
|
banMembers: hp(Permissions.banMembers),
|
||||||
manageRoles: hp(Permissions.manageRoles),
|
manageRoles: hp(Permissions.manageRoles),
|
||||||
manageChannels: hp(Permissions.manageChannels),
|
manageChannels: hp(Permissions.manageChannels),
|
||||||
manageServer: hp(Permissions.manageServer),
|
manageServer: hp(Permissions.manageServer),
|
||||||
// text
|
// text
|
||||||
readMessages: hp(Permissions.readMessages),
|
readMessages: hp(Permissions.readMessages),
|
||||||
sendMessages: hp(Permissions.sendMessages),
|
sendMessages: hp(Permissions.sendMessages),
|
||||||
sendTTSMessages: hp(Permissions.sendTTSMessages),
|
sendTTSMessages: hp(Permissions.sendTTSMessages),
|
||||||
manageMessages: hp(Permissions.manageMessages),
|
manageMessages: hp(Permissions.manageMessages),
|
||||||
embedLinks: hp(Permissions.embedLinks),
|
embedLinks: hp(Permissions.embedLinks),
|
||||||
attachFiles: hp(Permissions.attachFiles),
|
attachFiles: hp(Permissions.attachFiles),
|
||||||
readMessageHistory: hp(Permissions.readMessageHistory),
|
readMessageHistory: hp(Permissions.readMessageHistory),
|
||||||
mentionEveryone: hp(Permissions.mentionEveryone),
|
mentionEveryone: hp(Permissions.mentionEveryone),
|
||||||
// voice
|
// voice
|
||||||
voiceConnect: hp(Permissions.voiceConnect),
|
voiceConnect: hp(Permissions.voiceConnect),
|
||||||
voiceSpeak: hp(Permissions.voiceSpeak),
|
voiceSpeak: hp(Permissions.voiceSpeak),
|
||||||
voiceMuteMembers: hp(Permissions.voiceMuteMembers),
|
voiceMuteMembers: hp(Permissions.voiceMuteMembers),
|
||||||
voiceDeafenMembers: hp(Permissions.voiceDeafenMembers),
|
voiceDeafenMembers: hp(Permissions.voiceDeafenMembers),
|
||||||
voiceMoveMembers: hp(Permissions.voiceMoveMembers),
|
voiceMoveMembers: hp(Permissions.voiceMoveMembers),
|
||||||
voiceUseVAD: hp(Permissions.voiceUseVAD)
|
voiceUseVAD: hp(Permissions.voiceUseVAD)
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
Role.prototype.serialize = function serialize() {
|
||||||
|
// ;n;
|
||||||
|
return this.serialise();
|
||||||
|
};
|
||||||
|
|
||||||
|
Role.prototype.hasPermission = 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) {
|
||||||
key: "serialize",
|
return false;
|
||||||
value: function serialize() {
|
|
||||||
// ;n;
|
|
||||||
return this.serialise();
|
|
||||||
}
|
}
|
||||||
}, {
|
if (!explicit) {
|
||||||
key: "hasPermission",
|
// implicit permissions allowed
|
||||||
value: function hasPermission(perm) {
|
if (!!(this.permissions & Permissions.manageRoles)) {
|
||||||
var explicit = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
|
// manageRoles allowed, they have all permissions
|
||||||
|
return true;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// e.g.
|
|
||||||
// !!(36953089 & Permissions.manageRoles) = not allowed to manage roles
|
|
||||||
// !!(36953089 & (1 << 21)) = voice speak allowed
|
|
||||||
|
|
||||||
return !!(this.permissions & perm);
|
|
||||||
}
|
}
|
||||||
}, {
|
// e.g.
|
||||||
key: "setPermission",
|
// !!(36953089 & Permissions.manageRoles) = not allowed to manage roles
|
||||||
value: function setPermission(permission, value) {
|
// !!(36953089 & (1 << 21)) = voice speak allowed
|
||||||
|
|
||||||
|
return !!(this.permissions & perm);
|
||||||
|
};
|
||||||
|
|
||||||
|
Role.prototype.setPermission = function 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Role.prototype.setPermissions = function setPermissions(obj) {
|
||||||
|
var _this2 = this;
|
||||||
|
|
||||||
|
obj.forEach(function (value, permission) {
|
||||||
if (permission instanceof String || typeof permission === "string") {
|
if (permission instanceof String || typeof permission === "string") {
|
||||||
permission = Permissions[permission];
|
permission = Permissions[permission];
|
||||||
}
|
}
|
||||||
if (permission) {
|
if (permission) {
|
||||||
// valid permission
|
// valid permission
|
||||||
if (value) {
|
_this2.setPermission(permission, value);
|
||||||
this.permissions |= permission;
|
|
||||||
} else {
|
|
||||||
this.permissions &= ~permission;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}, {
|
};
|
||||||
key: "setPermissions",
|
|
||||||
value: function setPermissions(obj) {
|
|
||||||
var _this2 = this;
|
|
||||||
|
|
||||||
obj.forEach(function (value, permission) {
|
Role.prototype.colorAsHex = function colorAsHex() {
|
||||||
if (permission instanceof String || typeof permission === "string") {
|
var val = this.color.toString();
|
||||||
permission = Permissions[permission];
|
while (val.length < 6) {
|
||||||
}
|
val = "0" + val;
|
||||||
if (permission) {
|
|
||||||
// valid permission
|
|
||||||
_this2.setPermission(permission, value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}, {
|
return "#" + val;
|
||||||
key: "colorAsHex",
|
};
|
||||||
value: function colorAsHex() {
|
|
||||||
var val = this.color.toString();
|
|
||||||
while (val.length < 6) {
|
|
||||||
val = "0" + val;
|
|
||||||
}
|
|
||||||
return "#" + val;
|
|
||||||
}
|
|
||||||
}]);
|
|
||||||
|
|
||||||
return Role;
|
return Role;
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ var _createClass = (function () { function defineProperties(target, props) { for
|
|||||||
|
|
||||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
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; }
|
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 Equality = require("../Util/Equality.js");
|
||||||
@@ -22,26 +20,28 @@ var Server = (function (_Equality) {
|
|||||||
_inherits(Server, _Equality);
|
_inherits(Server, _Equality);
|
||||||
|
|
||||||
function Server(data, client) {
|
function Server(data, client) {
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
_classCallCheck(this, Server);
|
_classCallCheck(this, Server);
|
||||||
|
|
||||||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Server).call(this));
|
_Equality.call(this);
|
||||||
|
|
||||||
var self = _this;
|
var self = this;
|
||||||
_this.client = client;
|
this.client = client;
|
||||||
|
|
||||||
_this.region = data.region;
|
this.region = data.region;
|
||||||
_this.ownerID = data.owner_id;
|
this.ownerID = data.owner_id;
|
||||||
_this.name = data.name;
|
this.name = data.name;
|
||||||
_this.id = data.id;
|
this.id = data.id;
|
||||||
_this.members = new Cache();
|
this.members = new Cache();
|
||||||
_this.channels = new Cache();
|
this.channels = new Cache();
|
||||||
_this.roles = new Cache();
|
this.roles = new Cache();
|
||||||
_this.icon = data.icon;
|
this.icon = data.icon;
|
||||||
_this.afkTimeout = data.afkTimeout;
|
this.afkTimeout = data.afkTimeout;
|
||||||
_this.afkChannelID = data.afk_channel_id;
|
this.afkChannelID = data.afk_channel_id;
|
||||||
_this.memberMap = {};
|
this.memberMap = {};
|
||||||
|
|
||||||
var self = _this;
|
var self = this;
|
||||||
|
|
||||||
data.roles.forEach(function (dataRole) {
|
data.roles.forEach(function (dataRole) {
|
||||||
_this.roles.add(new Role(dataRole, _this, client));
|
_this.roles.add(new Role(dataRole, _this, client));
|
||||||
@@ -71,94 +71,73 @@ var Server = (function (_Equality) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (data.presences) {
|
if (data.presences) {
|
||||||
var _iteratorNormalCompletion = true;
|
for (var _iterator = data.presences, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||||
var _didIteratorError = false;
|
var _ref;
|
||||||
var _iteratorError = undefined;
|
|
||||||
|
|
||||||
try {
|
if (_isArray) {
|
||||||
for (var _iterator = data.presences[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
if (_i >= _iterator.length) break;
|
||||||
var presence = _step.value;
|
_ref = _iterator[_i++];
|
||||||
|
} else {
|
||||||
var user = client.internal.users.get("id", presence.user.id);
|
_i = _iterator.next();
|
||||||
if (user) {
|
if (_i.done) break;
|
||||||
user.status = presence.status;
|
_ref = _i.value;
|
||||||
user.gameID = presence.game_id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
|
||||||
_didIteratorError = true;
|
var presence = _ref;
|
||||||
_iteratorError = err;
|
|
||||||
} finally {
|
var user = client.internal.users.get("id", presence.user.id);
|
||||||
try {
|
if (user) {
|
||||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
user.status = presence.status;
|
||||||
_iterator.return();
|
user.gameID = presence.game_id;
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (_didIteratorError) {
|
|
||||||
throw _iteratorError;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return _this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_createClass(Server, [{
|
Server.prototype.rolesOfUser = function rolesOfUser(user) {
|
||||||
key: "rolesOfUser",
|
user = this.client.internal.resolver.resolveUser(user);
|
||||||
value: function rolesOfUser(user) {
|
if (user) {
|
||||||
user = this.client.internal.resolver.resolveUser(user);
|
return this.memberMap[user.id] ? this.memberMap[user.id].roles : [];
|
||||||
if (user) {
|
} else {
|
||||||
return this.memberMap[user.id] ? this.memberMap[user.id].roles : [];
|
return null;
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, {
|
};
|
||||||
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 {
|
Server.prototype.rolesOf = function rolesOf(user) {
|
||||||
for (var _iterator2 = strictKeys[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
return this.rolesOfUser(user);
|
||||||
var key = _step2.value;
|
};
|
||||||
|
|
||||||
if (obj[key] !== this[key]) {
|
Server.prototype.toString = function toString() {
|
||||||
return false;
|
return this.name;
|
||||||
}
|
};
|
||||||
}
|
|
||||||
} catch (err) {
|
Server.prototype.equalsStrict = function equalsStrict(obj) {
|
||||||
_didIteratorError2 = true;
|
if (obj instanceof Server) {
|
||||||
_iteratorError2 = err;
|
for (var _iterator2 = strictKeys, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||||
} finally {
|
var _ref2;
|
||||||
try {
|
|
||||||
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
if (_isArray2) {
|
||||||
_iterator2.return();
|
if (_i2 >= _iterator2.length) break;
|
||||||
}
|
_ref2 = _iterator2[_i2++];
|
||||||
} finally {
|
} else {
|
||||||
if (_didIteratorError2) {
|
_i2 = _iterator2.next();
|
||||||
throw _iteratorError2;
|
if (_i2.done) break;
|
||||||
}
|
_ref2 = _i2.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var key = _ref2;
|
||||||
|
|
||||||
|
if (obj[key] !== this[key]) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}, {
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
_createClass(Server, [{
|
||||||
key: "iconURL",
|
key: "iconURL",
|
||||||
get: function get() {
|
get: function get() {
|
||||||
if (!this.icon) {
|
if (!this.icon) {
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
"use strict";
|
"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 _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; }
|
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 Channel = require("./Channel.js");
|
||||||
@@ -18,125 +14,102 @@ var ServerChannel = (function (_Channel) {
|
|||||||
_inherits(ServerChannel, _Channel);
|
_inherits(ServerChannel, _Channel);
|
||||||
|
|
||||||
function ServerChannel(data, client, server) {
|
function ServerChannel(data, client, server) {
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
_classCallCheck(this, ServerChannel);
|
_classCallCheck(this, ServerChannel);
|
||||||
|
|
||||||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(ServerChannel).call(this, data, client));
|
_Channel.call(this, data, client);
|
||||||
|
this.name = data.name;
|
||||||
_this.name = data.name;
|
this.type = data.type;
|
||||||
_this.type = data.type;
|
this.position = data.position;
|
||||||
_this.position = data.position;
|
this.permissionOverwrites = new Cache();
|
||||||
_this.permissionOverwrites = new Cache();
|
this.server = server;
|
||||||
_this.server = server;
|
|
||||||
data.permission_overwrites.forEach(function (permission) {
|
data.permission_overwrites.forEach(function (permission) {
|
||||||
_this.permissionOverwrites.add(new PermissionOverwrite(permission));
|
_this.permissionOverwrites.add(new PermissionOverwrite(permission));
|
||||||
});
|
});
|
||||||
return _this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_createClass(ServerChannel, [{
|
ServerChannel.prototype.permissionsOf = function permissionsOf(user) {
|
||||||
key: "permissionsOf",
|
user = this.client.internal.resolver.resolveUser(user);
|
||||||
value: function permissionsOf(user) {
|
if (user) {
|
||||||
user = this.client.internal.resolver.resolveUser(user);
|
if (this.server.owner.equals(user)) {
|
||||||
if (user) {
|
return new ChannelPermissions(4294967295);
|
||||||
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(function (v) {
|
|
||||||
return v.id;
|
|
||||||
});
|
|
||||||
var roleOverwrites = [],
|
|
||||||
memberOverwrites = [];
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
var everyoneRole = this.server.roles.get("name", "@everyone");
|
||||||
|
|
||||||
|
var userRoles = [everyoneRole].concat(this.server.rolesOf(user) || []);
|
||||||
|
var userRolesID = userRoles.map(function (v) {
|
||||||
|
return v.id;
|
||||||
|
});
|
||||||
|
var roleOverwrites = [],
|
||||||
|
memberOverwrites = [];
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
for (var _iterator = userRoles, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||||
|
var _ref;
|
||||||
|
|
||||||
|
if (_isArray) {
|
||||||
|
if (_i >= _iterator.length) break;
|
||||||
|
_ref = _iterator[_i++];
|
||||||
|
} else {
|
||||||
|
_i = _iterator.next();
|
||||||
|
if (_i.done) break;
|
||||||
|
_ref = _i.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var serverRole = _ref;
|
||||||
|
|
||||||
|
permissions |= serverRole.permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var _iterator2 = roleOverwrites.concat(memberOverwrites), _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||||
|
var _ref2;
|
||||||
|
|
||||||
|
if (_isArray2) {
|
||||||
|
if (_i2 >= _iterator2.length) break;
|
||||||
|
_ref2 = _iterator2[_i2++];
|
||||||
|
} else {
|
||||||
|
_i2 = _iterator2.next();
|
||||||
|
if (_i2.done) break;
|
||||||
|
_ref2 = _i2.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var overwrite = _ref2;
|
||||||
|
|
||||||
|
permissions = permissions & ~overwrite.deny;
|
||||||
|
permissions = permissions | overwrite.allow;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ChannelPermissions(permissions);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}, {
|
};
|
||||||
key: "permsOf",
|
|
||||||
value: function permsOf(user) {
|
ServerChannel.prototype.permsOf = function permsOf(user) {
|
||||||
return this.permissionsOf(user);
|
return this.permissionsOf(user);
|
||||||
}
|
};
|
||||||
}, {
|
|
||||||
key: "mention",
|
ServerChannel.prototype.mention = function mention() {
|
||||||
value: function mention() {
|
return "<#" + this.id + ">";
|
||||||
return "<#" + this.id + ">";
|
};
|
||||||
}
|
|
||||||
}, {
|
ServerChannel.prototype.toString = function toString() {
|
||||||
key: "toString",
|
return this.mention();
|
||||||
value: function toString() {
|
};
|
||||||
return this.mention();
|
|
||||||
}
|
ServerChannel.prototype.setName = function setName() {
|
||||||
}, {
|
return this.client.setChannelName.apply(this.client, reg(this, arguments));
|
||||||
key: "setName",
|
};
|
||||||
value: function setName() {
|
|
||||||
return this.client.setChannelName.apply(this.client, reg(this, arguments));
|
|
||||||
}
|
|
||||||
}]);
|
|
||||||
|
|
||||||
return ServerChannel;
|
return ServerChannel;
|
||||||
})(Channel);
|
})(Channel);
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ var _createClass = (function () { function defineProperties(target, props) { for
|
|||||||
|
|
||||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
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; }
|
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 ServerChannel = require("./ServerChannel.js");
|
||||||
@@ -18,42 +16,36 @@ var TextChannel = (function (_ServerChannel) {
|
|||||||
function TextChannel(data, client, server) {
|
function TextChannel(data, client, server) {
|
||||||
_classCallCheck(this, TextChannel);
|
_classCallCheck(this, TextChannel);
|
||||||
|
|
||||||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(TextChannel).call(this, data, client, server));
|
_ServerChannel.call(this, data, client, server);
|
||||||
|
|
||||||
_this.topic = data.topic;
|
this.topic = data.topic;
|
||||||
_this.lastMessageID = data.last_message_id;
|
this.lastMessageID = data.last_message_id;
|
||||||
_this.messages = new Cache("id", client.options.maximumMessages);
|
this.messages = new Cache("id", client.options.maximumMessages);
|
||||||
return _this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* warning! may return null */
|
/* warning! may return null */
|
||||||
|
|
||||||
|
TextChannel.prototype.setTopic = function setTopic() {
|
||||||
|
return this.client.setTopic.apply(this.client, reg(this, arguments));
|
||||||
|
};
|
||||||
|
|
||||||
|
TextChannel.prototype.setNameAndTopic = function setNameAndTopic() {
|
||||||
|
return this.client.setChannelNameAndTopic.apply(this.client, reg(this, arguments));
|
||||||
|
};
|
||||||
|
|
||||||
|
TextChannel.prototype.update = function update() {
|
||||||
|
return this.client.updateChannel.apply(this.client, reg(this, arguments));
|
||||||
|
};
|
||||||
|
|
||||||
|
TextChannel.prototype.sendMessage = function sendMessage() {
|
||||||
|
return this.client.sendMessage.apply(this.client, reg(this, arguments));
|
||||||
|
};
|
||||||
|
|
||||||
|
TextChannel.prototype.sendTTSMessage = function sendTTSMessage() {
|
||||||
|
return this.client.sendTTSMessage.apply(this.client, reg(this, arguments));
|
||||||
|
};
|
||||||
|
|
||||||
_createClass(TextChannel, [{
|
_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",
|
key: "lastMessage",
|
||||||
get: function get() {
|
get: function get() {
|
||||||
return this.messages.get("id", this.lastMessageID);
|
return this.messages.get("id", this.lastMessageID);
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ var _createClass = (function () { function defineProperties(target, props) { for
|
|||||||
|
|
||||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
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; }
|
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 Equality = require("../Util/Equality.js");
|
||||||
@@ -17,38 +15,33 @@ var User = (function (_Equality) {
|
|||||||
function User(data, client) {
|
function User(data, client) {
|
||||||
_classCallCheck(this, User);
|
_classCallCheck(this, User);
|
||||||
|
|
||||||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(User).call(this));
|
_Equality.call(this);
|
||||||
|
this.client = client;
|
||||||
_this.client = client;
|
this.username = data.username;
|
||||||
_this.username = data.username;
|
this.discriminator = data.discriminator;
|
||||||
_this.discriminator = data.discriminator;
|
this.id = data.id;
|
||||||
_this.id = data.id;
|
this.avatar = data.avatar;
|
||||||
_this.avatar = data.avatar;
|
this.status = data.status || "offline";
|
||||||
_this.status = data.status || "offline";
|
this.gameID = data.game_id || null;
|
||||||
_this.gameID = data.game_id || null;
|
this.typing = {
|
||||||
_this.typing = {
|
|
||||||
since: null,
|
since: null,
|
||||||
channel: null
|
channel: null
|
||||||
};
|
};
|
||||||
return _this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
User.prototype.mention = function mention() {
|
||||||
|
return "<@" + this.id + ">";
|
||||||
|
};
|
||||||
|
|
||||||
|
User.prototype.toString = function toString() {
|
||||||
|
return this.mention();
|
||||||
|
};
|
||||||
|
|
||||||
|
User.prototype.equalsStrict = 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;
|
||||||
|
};
|
||||||
|
|
||||||
_createClass(User, [{
|
_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",
|
key: "avatarURL",
|
||||||
get: function get() {
|
get: function get() {
|
||||||
if (!this.avatar) {
|
if (!this.avatar) {
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
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; }
|
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 ServerChannel = require("./ServerChannel.js");
|
||||||
@@ -14,7 +12,7 @@ var VoiceChannel = (function (_ServerChannel) {
|
|||||||
function VoiceChannel(data, client, server) {
|
function VoiceChannel(data, client, server) {
|
||||||
_classCallCheck(this, VoiceChannel);
|
_classCallCheck(this, VoiceChannel);
|
||||||
|
|
||||||
return _possibleConstructorReturn(this, Object.getPrototypeOf(VoiceChannel).call(this, data, client, server));
|
_ServerChannel.call(this, data, client, server);
|
||||||
}
|
}
|
||||||
|
|
||||||
return VoiceChannel;
|
return VoiceChannel;
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
"use strict";
|
"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 _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; }
|
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 = (function (_Array) {
|
var Cache = (function (_Array) {
|
||||||
@@ -14,115 +10,95 @@ var Cache = (function (_Array) {
|
|||||||
function Cache(discrim, limit) {
|
function Cache(discrim, limit) {
|
||||||
_classCallCheck(this, Cache);
|
_classCallCheck(this, Cache);
|
||||||
|
|
||||||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Cache).call(this));
|
_Array.call(this);
|
||||||
|
this.discrim = discrim || "id";
|
||||||
_this.discrim = discrim || "id";
|
|
||||||
return _this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_createClass(Cache, [{
|
Cache.prototype.get = function get(key, value) {
|
||||||
key: "get",
|
var found = null;
|
||||||
value: function get(key, value) {
|
this.forEach(function (val, index, array) {
|
||||||
var found = null;
|
if (val.hasOwnProperty(key) && val[key] == value) {
|
||||||
this.forEach(function (val, index, array) {
|
found = val;
|
||||||
if (val.hasOwnProperty(key) && val[key] == value) {
|
return;
|
||||||
found = val;
|
}
|
||||||
return;
|
});
|
||||||
}
|
return found;
|
||||||
});
|
};
|
||||||
return found;
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: "has",
|
|
||||||
value: function has(key, value) {
|
|
||||||
return !!this.get(key, value);
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: "getAll",
|
|
||||||
value: function getAll(key, value) {
|
|
||||||
var found = new Cache(this.discrim);
|
|
||||||
this.forEach(function (val, index, array) {
|
|
||||||
if (val.hasOwnProperty(key) && val[key] == value) {
|
|
||||||
found.push(val);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return found;
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: "add",
|
|
||||||
value: function add(data) {
|
|
||||||
var exit = false;
|
|
||||||
var _iteratorNormalCompletion = true;
|
|
||||||
var _didIteratorError = false;
|
|
||||||
var _iteratorError = undefined;
|
|
||||||
|
|
||||||
try {
|
Cache.prototype.has = function has(key, value) {
|
||||||
for (var _iterator = this[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
return !!this.get(key, value);
|
||||||
var item = _step.value;
|
};
|
||||||
|
|
||||||
if (item[this.discrim] === data[this.discrim]) {
|
Cache.prototype.getAll = function getAll(key, value) {
|
||||||
exit = item;
|
var found = new Cache(this.discrim);
|
||||||
break;
|
this.forEach(function (val, index, array) {
|
||||||
}
|
if (val.hasOwnProperty(key) && val[key] == value) {
|
||||||
}
|
found.push(val);
|
||||||
} catch (err) {
|
return;
|
||||||
_didIteratorError = true;
|
}
|
||||||
_iteratorError = err;
|
});
|
||||||
} finally {
|
return found;
|
||||||
try {
|
};
|
||||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
|
||||||
_iterator.return();
|
Cache.prototype.add = function add(data) {
|
||||||
}
|
var exit = false;
|
||||||
} finally {
|
for (var _iterator = this, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||||
if (_didIteratorError) {
|
var _ref;
|
||||||
throw _iteratorError;
|
|
||||||
}
|
if (_isArray) {
|
||||||
}
|
if (_i >= _iterator.length) break;
|
||||||
|
_ref = _iterator[_i++];
|
||||||
|
} else {
|
||||||
|
_i = _iterator.next();
|
||||||
|
if (_i.done) break;
|
||||||
|
_ref = _i.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exit) {
|
var item = _ref;
|
||||||
return exit;
|
|
||||||
} else {
|
if (item[this.discrim] === data[this.discrim]) {
|
||||||
if (this.limit && this.length >= this.limit) {
|
exit = item;
|
||||||
this.splice(0, 1);
|
break;
|
||||||
}
|
|
||||||
this.push(data);
|
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, {
|
if (exit) {
|
||||||
key: "update",
|
return exit;
|
||||||
value: function update(old, data) {
|
} else {
|
||||||
var item = this.get(this.discrim, old[this.discrim]);
|
if (this.limit && this.length >= this.limit) {
|
||||||
if (item) {
|
this.splice(0, 1);
|
||||||
var index = this.indexOf(item);
|
|
||||||
this[index] = data;
|
|
||||||
return this[index];
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
this.push(data);
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
}, {
|
};
|
||||||
key: "random",
|
|
||||||
value: function random() {
|
Cache.prototype.update = function update(old, data) {
|
||||||
return this[Math.floor(Math.random() * this.length)];
|
var item = this.get(this.discrim, old[this.discrim]);
|
||||||
}
|
if (item) {
|
||||||
}, {
|
var index = this.indexOf(item);
|
||||||
key: "remove",
|
this[index] = data;
|
||||||
value: function remove(data) {
|
return this[index];
|
||||||
var index = this.indexOf(data);
|
} else {
|
||||||
if (~index) {
|
|
||||||
this.splice(index, 1);
|
|
||||||
} else {
|
|
||||||
var item = this.get(this.discrim, data[this.discrim]);
|
|
||||||
if (item) {
|
|
||||||
this.splice(this.indexOf(item), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}]);
|
};
|
||||||
|
|
||||||
|
Cache.prototype.random = function random() {
|
||||||
|
return this[Math.floor(Math.random() * this.length)];
|
||||||
|
};
|
||||||
|
|
||||||
|
Cache.prototype.remove = function remove(data) {
|
||||||
|
var index = this.indexOf(data);
|
||||||
|
if (~index) {
|
||||||
|
this.splice(index, 1);
|
||||||
|
} else {
|
||||||
|
var item = this.get(this.discrim, data[this.discrim]);
|
||||||
|
if (item) {
|
||||||
|
this.splice(this.indexOf(item), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
return Cache;
|
return Cache;
|
||||||
})(Array);
|
})(Array);
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
"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"); } }
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The Equality Class is just used to show
|
The Equality Class is just used to show
|
||||||
that a Class has an ID that can be used to
|
that a Class has an ID that can be used to
|
||||||
@@ -15,27 +9,30 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|||||||
|
|
||||||
Instead, use objectThatExtendsEquality.equals()
|
Instead, use objectThatExtendsEquality.equals()
|
||||||
*/
|
*/
|
||||||
|
"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 Equality = (function () {
|
var Equality = (function () {
|
||||||
function Equality() {
|
function Equality() {
|
||||||
_classCallCheck(this, Equality);
|
_classCallCheck(this, Equality);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Equality.prototype.equals = function equals(object) {
|
||||||
|
if (object && object[this.eqDiscriminator] == this[this.eqDiscriminator]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
Equality.prototype.equalsStrict = function equalsStrict(object) {
|
||||||
|
// override per class type
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
_createClass(Equality, [{
|
_createClass(Equality, [{
|
||||||
key: "equals",
|
|
||||||
value: function equals(object) {
|
|
||||||
if (object && object[this.eqDiscriminator] == this[this.eqDiscriminator]) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: "equalsStrict",
|
|
||||||
value: function equalsStrict(object) {
|
|
||||||
// override per class type
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: "eqDiscriminator",
|
key: "eqDiscriminator",
|
||||||
get: function get() {
|
get: function get() {
|
||||||
return "id";
|
return "id";
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
"use strict";
|
"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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
var cpoc = require("child_process");
|
var cpoc = require("child_process");
|
||||||
@@ -24,120 +22,106 @@ var AudioEncoder = (function () {
|
|||||||
this.choice = false;
|
this.choice = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_createClass(AudioEncoder, [{
|
AudioEncoder.prototype.opusBuffer = function opusBuffer(buffer) {
|
||||||
key: "opusBuffer",
|
|
||||||
value: function opusBuffer(buffer) {
|
|
||||||
|
|
||||||
return this.opus.encode(buffer, 1920);
|
return this.opus.encode(buffer, 1920);
|
||||||
}
|
};
|
||||||
}, {
|
|
||||||
key: "getCommand",
|
|
||||||
value: function getCommand(force) {
|
|
||||||
|
|
||||||
if (this.choice && force) return choice;
|
AudioEncoder.prototype.getCommand = function getCommand(force) {
|
||||||
|
|
||||||
var choices = ["avconv", "ffmpeg"];
|
if (this.choice && force) return choice;
|
||||||
|
|
||||||
var _iteratorNormalCompletion = true;
|
var choices = ["avconv", "ffmpeg"];
|
||||||
var _didIteratorError = false;
|
|
||||||
var _iteratorError = undefined;
|
|
||||||
|
|
||||||
try {
|
for (var _iterator = choices, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||||
for (var _iterator = choices[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
var _ref;
|
||||||
var choice = _step.value;
|
|
||||||
|
|
||||||
var p = cpoc.spawnSync(choice);
|
if (_isArray) {
|
||||||
if (!p.error) {
|
if (_i >= _iterator.length) break;
|
||||||
this.choice = choice;
|
_ref = _iterator[_i++];
|
||||||
return choice;
|
} else {
|
||||||
}
|
_i = _iterator.next();
|
||||||
}
|
if (_i.done) break;
|
||||||
} catch (err) {
|
_ref = _i.value;
|
||||||
_didIteratorError = true;
|
|
||||||
_iteratorError = err;
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
|
||||||
_iterator.return();
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (_didIteratorError) {
|
|
||||||
throw _iteratorError;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return "help";
|
var choice = _ref;
|
||||||
|
|
||||||
|
var p = cpoc.spawnSync(choice);
|
||||||
|
if (!p.error) {
|
||||||
|
this.choice = choice;
|
||||||
|
return choice;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, {
|
|
||||||
key: "encodeStream",
|
|
||||||
value: function encodeStream(stream) {
|
|
||||||
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, buffer) {} : arguments[1];
|
|
||||||
|
|
||||||
var self = this;
|
return "help";
|
||||||
return new Promise(function (resolve, reject) {
|
};
|
||||||
var enc = cpoc.spawn(self.getCommand(), ["-f", "s16le", "-ar", "48000", "-ac", "1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth.
|
|
||||||
"-af", "volume=1", "pipe:1", "-i", "-"]);
|
|
||||||
|
|
||||||
stream.pipe(enc.stdin);
|
AudioEncoder.prototype.encodeStream = function encodeStream(stream) {
|
||||||
|
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, buffer) {} : arguments[1];
|
||||||
|
|
||||||
enc.stdout.once("readable", function () {
|
var self = this;
|
||||||
callback(null, {
|
return new Promise(function (resolve, reject) {
|
||||||
proc: enc,
|
var enc = cpoc.spawn(self.getCommand(), ["-f", "s16le", "-ar", "48000", "-ac", "1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth.
|
||||||
stream: enc.stdout,
|
"-af", "volume=1", "pipe:1", "-i", "-"]);
|
||||||
instream: stream
|
|
||||||
});
|
stream.pipe(enc.stdin);
|
||||||
resolve({
|
|
||||||
proc: enc,
|
enc.stdout.once("readable", function () {
|
||||||
stream: enc.stdout,
|
callback(null, {
|
||||||
instream: stream
|
proc: enc,
|
||||||
});
|
stream: enc.stdout,
|
||||||
|
instream: stream
|
||||||
});
|
});
|
||||||
|
resolve({
|
||||||
enc.stdout.on("end", function () {
|
proc: enc,
|
||||||
callback("end");
|
stream: enc.stdout,
|
||||||
reject("end");
|
instream: stream
|
||||||
});
|
|
||||||
|
|
||||||
enc.stdout.on("close", function () {
|
|
||||||
callback("close");
|
|
||||||
reject("close");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: "encodeFile",
|
|
||||||
value: function encodeFile(file) {
|
|
||||||
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, buffer) {} : arguments[1];
|
|
||||||
|
|
||||||
var self = this;
|
enc.stdout.on("end", function () {
|
||||||
return new Promise(function (resolve, reject) {
|
callback("end");
|
||||||
var enc = cpoc.spawn(self.getCommand(), ["-f", "s16le", "-ar", "48000", "-ac", "1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth.
|
reject("end");
|
||||||
"-af", "volume=1", "pipe:1", "-i", file]);
|
});
|
||||||
|
|
||||||
enc.stdout.once("readable", function () {
|
enc.stdout.on("close", function () {
|
||||||
callback(null, {
|
callback("close");
|
||||||
proc: enc,
|
reject("close");
|
||||||
stream: enc.stdout
|
});
|
||||||
});
|
});
|
||||||
resolve({
|
};
|
||||||
proc: enc,
|
|
||||||
stream: enc.stdout
|
AudioEncoder.prototype.encodeFile = function encodeFile(file) {
|
||||||
});
|
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, buffer) {} : arguments[1];
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
var enc = cpoc.spawn(self.getCommand(), ["-f", "s16le", "-ar", "48000", "-ac", "1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth.
|
||||||
|
"-af", "volume=1", "pipe:1", "-i", file]);
|
||||||
|
|
||||||
|
enc.stdout.once("readable", function () {
|
||||||
|
callback(null, {
|
||||||
|
proc: enc,
|
||||||
|
stream: enc.stdout
|
||||||
});
|
});
|
||||||
|
resolve({
|
||||||
enc.stdout.on("end", function () {
|
proc: enc,
|
||||||
callback("end");
|
stream: enc.stdout
|
||||||
reject("end");
|
|
||||||
});
|
|
||||||
|
|
||||||
enc.stdout.on("close", function () {
|
|
||||||
callback("close");
|
|
||||||
reject("close");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}]);
|
enc.stdout.on("end", function () {
|
||||||
|
callback("end");
|
||||||
|
reject("end");
|
||||||
|
});
|
||||||
|
|
||||||
|
enc.stdout.on("close", function () {
|
||||||
|
callback("close");
|
||||||
|
reject("close");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return AudioEncoder;
|
return AudioEncoder;
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
"use strict"
|
"use strict";
|
||||||
// represents an intent of streaming music
|
// represents an intent of streaming music
|
||||||
;
|
|
||||||
|
|
||||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
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; }
|
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 EventEmitter = require("events");
|
var EventEmitter = require("events");
|
||||||
@@ -16,7 +13,7 @@ var StreamIntent = (function (_EventEmitter) {
|
|||||||
function StreamIntent() {
|
function StreamIntent() {
|
||||||
_classCallCheck(this, StreamIntent);
|
_classCallCheck(this, StreamIntent);
|
||||||
|
|
||||||
return _possibleConstructorReturn(this, Object.getPrototypeOf(StreamIntent).call(this));
|
_EventEmitter.call(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return StreamIntent;
|
return StreamIntent;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
"use strict"
|
"use strict";
|
||||||
/*
|
/*
|
||||||
Major credit to izy521 who is the creator of
|
Major credit to izy521 who is the creator of
|
||||||
https://github.com/izy521/discord.io,
|
https://github.com/izy521/discord.io,
|
||||||
@@ -7,14 +7,8 @@
|
|||||||
been possible!
|
been possible!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
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 _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; }
|
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 WebSocket = require("ws");
|
var WebSocket = require("ws");
|
||||||
@@ -32,320 +26,306 @@ var VoiceConnection = (function (_EventEmitter) {
|
|||||||
function VoiceConnection(channel, client, session, token, server, endpoint) {
|
function VoiceConnection(channel, client, session, token, server, endpoint) {
|
||||||
_classCallCheck(this, VoiceConnection);
|
_classCallCheck(this, VoiceConnection);
|
||||||
|
|
||||||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(VoiceConnection).call(this));
|
_EventEmitter.call(this);
|
||||||
|
this.id = channel.id;
|
||||||
_this.id = channel.id;
|
this.voiceChannel = channel;
|
||||||
_this.voiceChannel = channel;
|
this.client = client;
|
||||||
_this.client = client;
|
this.session = session;
|
||||||
_this.session = session;
|
this.token = token;
|
||||||
_this.token = token;
|
this.server = server;
|
||||||
_this.server = server;
|
this.endpoint = endpoint.replace(":80", "");
|
||||||
_this.endpoint = endpoint.replace(":80", "");
|
this.vWS = null; // vWS means voice websocket
|
||||||
_this.vWS = null; // vWS means voice websocket
|
this.ready = false;
|
||||||
_this.ready = false;
|
this.vWSData = {};
|
||||||
_this.vWSData = {};
|
this.encoder = new AudioEncoder();
|
||||||
_this.encoder = new AudioEncoder();
|
this.udp = null;
|
||||||
_this.udp = null;
|
this.playingIntent = null;
|
||||||
_this.playingIntent = null;
|
this.playing = false;
|
||||||
_this.playing = false;
|
this.streamTime = 0;
|
||||||
_this.streamTime = 0;
|
this.streamProc = null;
|
||||||
_this.streamProc = null;
|
this.KAI = null;
|
||||||
_this.KAI = null;
|
this.init();
|
||||||
_this.init();
|
|
||||||
return _this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_createClass(VoiceConnection, [{
|
VoiceConnection.prototype.destroy = function destroy() {
|
||||||
key: "destroy",
|
this.stopPlaying();
|
||||||
value: function destroy() {
|
if (this.KAI) clearInterval(this.KAI);
|
||||||
this.stopPlaying();
|
this.vWS.close();
|
||||||
if (this.KAI) clearInterval(this.KAI);
|
this.udp.close();
|
||||||
this.vWS.close();
|
this.client.internal.sendWS({
|
||||||
this.udp.close();
|
op: 4,
|
||||||
this.client.internal.sendWS({
|
d: {
|
||||||
op: 4,
|
guild_id: null,
|
||||||
d: {
|
channel_id: null,
|
||||||
guild_id: null,
|
self_mute: true,
|
||||||
channel_id: null,
|
self_deaf: false
|
||||||
self_mute: true,
|
|
||||||
self_deaf: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: "stopPlaying",
|
|
||||||
value: function stopPlaying() {
|
|
||||||
this.playing = false;
|
|
||||||
this.playingIntent = null;
|
|
||||||
if (this.instream) {
|
|
||||||
this.instream.end();
|
|
||||||
this.instream.destroy();
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
VoiceConnection.prototype.stopPlaying = function stopPlaying() {
|
||||||
|
this.playing = false;
|
||||||
|
this.playingIntent = null;
|
||||||
|
if (this.instream) {
|
||||||
|
this.instream.end();
|
||||||
|
this.instream.destroy();
|
||||||
}
|
}
|
||||||
}, {
|
};
|
||||||
key: "playStream",
|
|
||||||
value: function playStream(stream) {
|
|
||||||
|
|
||||||
var self = this;
|
VoiceConnection.prototype.playStream = function playStream(stream) {
|
||||||
|
|
||||||
var startTime = Date.now();
|
var self = this;
|
||||||
var sequence = 0;
|
|
||||||
var time = 0;
|
|
||||||
var count = 0;
|
|
||||||
|
|
||||||
var length = 20;
|
var startTime = Date.now();
|
||||||
|
var sequence = 0;
|
||||||
|
var time = 0;
|
||||||
|
var count = 0;
|
||||||
|
|
||||||
if (self.playingIntent) {
|
var length = 20;
|
||||||
self.stopPlaying();
|
|
||||||
|
if (self.playingIntent) {
|
||||||
|
self.stopPlaying();
|
||||||
|
}
|
||||||
|
self.playing = true;
|
||||||
|
var retStream = new StreamIntent();
|
||||||
|
var onWarning = false;
|
||||||
|
self.playingIntent = retStream;
|
||||||
|
|
||||||
|
function send() {
|
||||||
|
|
||||||
|
if (!self.playingIntent || !self.playing) {
|
||||||
|
self.setSpeaking(false);
|
||||||
|
retStream.emit("end");
|
||||||
|
self;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
self.playing = true;
|
try {
|
||||||
var retStream = new StreamIntent();
|
var buffer = stream.read(1920);
|
||||||
var onWarning = false;
|
if (!buffer) {
|
||||||
self.playingIntent = retStream;
|
setTimeout(send, length * 10); // give chance for some data in 200ms to appear
|
||||||
|
|
||||||
function send() {
|
|
||||||
|
|
||||||
if (!self.playingIntent || !self.playing) {
|
|
||||||
self.setSpeaking(false);
|
|
||||||
retStream.emit("end");
|
|
||||||
self;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
var buffer = stream.read(1920);
|
if (buffer.length !== 1920) {
|
||||||
if (!buffer) {
|
if (onWarning) {
|
||||||
|
retStream.emit("end");
|
||||||
|
stream.destroy();
|
||||||
|
self.setSpeaking(false);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
onWarning = true;
|
||||||
setTimeout(send, length * 10); // give chance for some data in 200ms to appear
|
setTimeout(send, length * 10); // give chance for some data in 200ms to appear
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffer.length !== 1920) {
|
|
||||||
if (onWarning) {
|
|
||||||
retStream.emit("end");
|
|
||||||
stream.destroy();
|
|
||||||
self.setSpeaking(false);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
onWarning = true;
|
|
||||||
setTimeout(send, length * 10); // give chance for some data in 200ms to appear
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
count++;
|
|
||||||
sequence + 10 < 65535 ? sequence += 1 : sequence = 0;
|
|
||||||
time + 9600 < 4294967295 ? time += 960 : time = 0;
|
|
||||||
|
|
||||||
self.sendBuffer(buffer, sequence, time, function (e) {});
|
|
||||||
|
|
||||||
var nextTime = startTime + count * length;
|
|
||||||
|
|
||||||
self.streamTime = count * length;
|
|
||||||
|
|
||||||
setTimeout(send, length + (nextTime - Date.now()));
|
|
||||||
|
|
||||||
if (!self.playing) self.setSpeaking(true);
|
|
||||||
|
|
||||||
retStream.emit("time", self.streamTime);
|
|
||||||
} catch (e) {
|
|
||||||
retStream.emit("error", e);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
self.setSpeaking(true);
|
|
||||||
send();
|
|
||||||
|
|
||||||
return retStream;
|
count++;
|
||||||
}
|
sequence + 10 < 65535 ? sequence += 1 : sequence = 0;
|
||||||
}, {
|
time + 9600 < 4294967295 ? time += 960 : time = 0;
|
||||||
key: "setSpeaking",
|
|
||||||
value: function setSpeaking(value) {
|
|
||||||
this.playing = value;
|
|
||||||
if (this.vWS.readyState === WebSocket.OPEN) this.vWS.send(JSON.stringify({
|
|
||||||
op: 5,
|
|
||||||
d: {
|
|
||||||
speaking: value,
|
|
||||||
delay: 0
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: "sendPacket",
|
|
||||||
value: function sendPacket(packet) {
|
|
||||||
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1];
|
|
||||||
|
|
||||||
var self = this;
|
self.sendBuffer(buffer, sequence, time, function (e) {});
|
||||||
self.playing = true;
|
|
||||||
try {
|
var nextTime = startTime + count * length;
|
||||||
if (self.vWS.readyState === WebSocket.OPEN) self.udp.send(packet, 0, packet.length, self.vWSData.port, self.endpoint, callback);
|
|
||||||
|
self.streamTime = count * length;
|
||||||
|
|
||||||
|
setTimeout(send, length + (nextTime - Date.now()));
|
||||||
|
|
||||||
|
if (!self.playing) self.setSpeaking(true);
|
||||||
|
|
||||||
|
retStream.emit("time", self.streamTime);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
retStream.emit("error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.setSpeaking(true);
|
||||||
|
send();
|
||||||
|
|
||||||
|
return retStream;
|
||||||
|
};
|
||||||
|
|
||||||
|
VoiceConnection.prototype.setSpeaking = function setSpeaking(value) {
|
||||||
|
this.playing = value;
|
||||||
|
if (this.vWS.readyState === WebSocket.OPEN) this.vWS.send(JSON.stringify({
|
||||||
|
op: 5,
|
||||||
|
d: {
|
||||||
|
speaking: value,
|
||||||
|
delay: 0
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
VoiceConnection.prototype.sendPacket = function sendPacket(packet) {
|
||||||
|
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1];
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
self.playing = true;
|
||||||
|
try {
|
||||||
|
if (self.vWS.readyState === WebSocket.OPEN) self.udp.send(packet, 0, packet.length, self.vWSData.port, self.endpoint, callback);
|
||||||
|
} catch (e) {
|
||||||
|
self.playing = false;
|
||||||
|
callback(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
VoiceConnection.prototype.sendBuffer = function sendBuffer(rawbuffer, sequence, timestamp, callback) {
|
||||||
|
var self = this;
|
||||||
|
self.playing = true;
|
||||||
|
try {
|
||||||
|
if (!self.encoder.opus) {
|
||||||
self.playing = false;
|
self.playing = false;
|
||||||
|
self.emit("error", "No Opus!");
|
||||||
|
self.client.emit("debug", "Tried to use node-opus, but opus not available - install it!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var buffer = self.encoder.opusBuffer(rawbuffer);
|
||||||
|
var packet = new VoicePacket(buffer, sequence, timestamp, self.vWSData.ssrc);
|
||||||
|
return self.sendPacket(packet, callback);
|
||||||
|
} catch (e) {
|
||||||
|
self.playing = false;
|
||||||
|
self.emit("error", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
VoiceConnection.prototype.test = function test() {
|
||||||
|
this.playFile("C:/users/amish/desktop/audio.mp3").then(function (stream) {
|
||||||
|
stream.on("time", function (time) {
|
||||||
|
console.log("Time", time);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
VoiceConnection.prototype.playFile = function playFile(stream) {
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
|
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, str) {} : arguments[1];
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
_this.encoder.encodeFile(stream)["catch"](error).then(function (data) {
|
||||||
|
self.streamProc = data.proc;
|
||||||
|
var intent = self.playStream(data.stream);
|
||||||
|
resolve(intent);
|
||||||
|
callback(null, intent);
|
||||||
|
});
|
||||||
|
function error() {
|
||||||
|
var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
|
||||||
|
|
||||||
|
reject(e);
|
||||||
callback(e);
|
callback(e);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}, {
|
};
|
||||||
key: "sendBuffer",
|
|
||||||
value: function sendBuffer(rawbuffer, sequence, timestamp, callback) {
|
VoiceConnection.prototype.playRawStream = function playRawStream(stream) {
|
||||||
var self = this;
|
var _this2 = this;
|
||||||
self.playing = true;
|
|
||||||
try {
|
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, str) {} : arguments[1];
|
||||||
if (!self.encoder.opus) {
|
|
||||||
self.playing = false;
|
var self = this;
|
||||||
self.emit("error", "No Opus!");
|
return new Promise(function (resolve, reject) {
|
||||||
self.client.emit("debug", "Tried to use node-opus, but opus not available - install it!");
|
_this2.encoder.encodeStream(stream)["catch"](error).then(function (data) {
|
||||||
return;
|
self.streamProc = data.proc;
|
||||||
}
|
self.instream = data.instream;
|
||||||
var buffer = self.encoder.opusBuffer(rawbuffer);
|
var intent = self.playStream(data.stream);
|
||||||
var packet = new VoicePacket(buffer, sequence, timestamp, self.vWSData.ssrc);
|
resolve(intent);
|
||||||
return self.sendPacket(packet, callback);
|
callback(null, intent);
|
||||||
} catch (e) {
|
});
|
||||||
self.playing = false;
|
function error() {
|
||||||
self.emit("error", e);
|
var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
|
||||||
return false;
|
|
||||||
|
reject(e);
|
||||||
|
callback(e);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}, {
|
};
|
||||||
key: "test",
|
|
||||||
value: function test() {
|
|
||||||
this.playFile("C:/users/amish/desktop/audio.mp3").then(function (stream) {
|
|
||||||
stream.on("time", function (time) {
|
|
||||||
console.log("Time", time);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: "playFile",
|
|
||||||
value: function playFile(stream) {
|
|
||||||
var _this2 = this;
|
|
||||||
|
|
||||||
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, str) {} : arguments[1];
|
VoiceConnection.prototype.init = function init() {
|
||||||
|
var _this3 = this;
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
return new Promise(function (resolve, reject) {
|
dns.lookup(this.endpoint, function (err, address, family) {
|
||||||
_this2.encoder.encodeFile(stream).catch(error).then(function (data) {
|
self.endpoint = address;
|
||||||
self.streamProc = data.proc;
|
var vWS = self.vWS = new WebSocket("wss://" + _this3.endpoint, null, { rejectUnauthorized: false });
|
||||||
var intent = self.playStream(data.stream);
|
var udpClient = self.udp = udp.createSocket("udp4");
|
||||||
resolve(intent);
|
|
||||||
callback(null, intent);
|
|
||||||
});
|
|
||||||
function error() {
|
|
||||||
var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
|
|
||||||
|
|
||||||
reject(e);
|
var firstPacket = true;
|
||||||
callback(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: "playRawStream",
|
|
||||||
value: function playRawStream(stream) {
|
|
||||||
var _this3 = this;
|
|
||||||
|
|
||||||
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, str) {} : arguments[1];
|
var discordIP = "",
|
||||||
|
discordPort = "";
|
||||||
|
|
||||||
var self = this;
|
udpClient.bind({ exclusive: true });
|
||||||
return new Promise(function (resolve, reject) {
|
udpClient.on('message', function (msg, rinfo) {
|
||||||
_this3.encoder.encodeStream(stream).catch(error).then(function (data) {
|
var buffArr = JSON.parse(JSON.stringify(msg)).data;
|
||||||
self.streamProc = data.proc;
|
if (firstPacket === true) {
|
||||||
self.instream = data.instream;
|
for (var i = 4; i < buffArr.indexOf(0, i); i++) {
|
||||||
var intent = self.playStream(data.stream);
|
discordIP += String.fromCharCode(buffArr[i]);
|
||||||
resolve(intent);
|
}
|
||||||
callback(null, intent);
|
discordPort = msg.readUIntLE(msg.length - 2, 2).toString(10);
|
||||||
});
|
|
||||||
function error() {
|
|
||||||
var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
|
|
||||||
|
|
||||||
reject(e);
|
var wsDiscPayload = {
|
||||||
callback(e);
|
"op": 1,
|
||||||
}
|
"d": {
|
||||||
});
|
"protocol": "udp",
|
||||||
}
|
"data": {
|
||||||
}, {
|
"address": discordIP,
|
||||||
key: "init",
|
"port": Number(discordPort),
|
||||||
value: function init() {
|
"mode": self.vWSData.modes[0] //Plain
|
||||||
var _this4 = this;
|
|
||||||
|
|
||||||
var self = this;
|
|
||||||
dns.lookup(this.endpoint, function (err, address, family) {
|
|
||||||
self.endpoint = address;
|
|
||||||
var vWS = self.vWS = new WebSocket("wss://" + _this4.endpoint, null, { rejectUnauthorized: false });
|
|
||||||
var udpClient = self.udp = udp.createSocket("udp4");
|
|
||||||
|
|
||||||
var firstPacket = true;
|
|
||||||
|
|
||||||
var discordIP = "",
|
|
||||||
discordPort = "";
|
|
||||||
|
|
||||||
udpClient.bind({ exclusive: true });
|
|
||||||
udpClient.on('message', function (msg, rinfo) {
|
|
||||||
var buffArr = JSON.parse(JSON.stringify(msg)).data;
|
|
||||||
if (firstPacket === true) {
|
|
||||||
for (var i = 4; i < buffArr.indexOf(0, i); i++) {
|
|
||||||
discordIP += String.fromCharCode(buffArr[i]);
|
|
||||||
}
|
|
||||||
discordPort = msg.readUIntLE(msg.length - 2, 2).toString(10);
|
|
||||||
|
|
||||||
var wsDiscPayload = {
|
|
||||||
"op": 1,
|
|
||||||
"d": {
|
|
||||||
"protocol": "udp",
|
|
||||||
"data": {
|
|
||||||
"address": discordIP,
|
|
||||||
"port": Number(discordPort),
|
|
||||||
"mode": self.vWSData.modes[0] //Plain
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
vWS.send(JSON.stringify(wsDiscPayload));
|
|
||||||
firstPacket = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
vWS.on("open", function () {
|
|
||||||
vWS.send(JSON.stringify({
|
|
||||||
op: 0,
|
|
||||||
d: {
|
|
||||||
server_id: self.server.id,
|
|
||||||
user_id: self.client.internal.user.id,
|
|
||||||
session_id: self.session,
|
|
||||||
token: self.token
|
|
||||||
}
|
}
|
||||||
}));
|
};
|
||||||
});
|
vWS.send(JSON.stringify(wsDiscPayload));
|
||||||
|
firstPacket = false;
|
||||||
var KAI;
|
}
|
||||||
|
|
||||||
vWS.on("message", function (msg) {
|
|
||||||
var data = JSON.parse(msg);
|
|
||||||
switch (data.op) {
|
|
||||||
case 2:
|
|
||||||
self.vWSData = data.d;
|
|
||||||
|
|
||||||
KAI = setInterval(function () {
|
|
||||||
if (vWS && vWS.readyState === WebSocket.OPEN) vWS.send(JSON.stringify({
|
|
||||||
op: 3,
|
|
||||||
d: null
|
|
||||||
}));
|
|
||||||
}, data.d.heartbeat_interval);
|
|
||||||
self.KAI = KAI;
|
|
||||||
|
|
||||||
var udpPacket = new Buffer(70);
|
|
||||||
udpPacket.writeUIntBE(data.d.ssrc, 0, 4);
|
|
||||||
udpClient.send(udpPacket, 0, udpPacket.length, data.d.port, self.endpoint, function (err) {
|
|
||||||
if (err) self.emit("error", err);
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
|
|
||||||
self.ready = true;
|
|
||||||
self.mode = data.d.mode;
|
|
||||||
self.emit("ready", self);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}]);
|
vWS.on("open", function () {
|
||||||
|
vWS.send(JSON.stringify({
|
||||||
|
op: 0,
|
||||||
|
d: {
|
||||||
|
server_id: self.server.id,
|
||||||
|
user_id: self.client.internal.user.id,
|
||||||
|
session_id: self.session,
|
||||||
|
token: self.token
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
var KAI;
|
||||||
|
|
||||||
|
vWS.on("message", function (msg) {
|
||||||
|
var data = JSON.parse(msg);
|
||||||
|
switch (data.op) {
|
||||||
|
case 2:
|
||||||
|
self.vWSData = data.d;
|
||||||
|
|
||||||
|
KAI = setInterval(function () {
|
||||||
|
if (vWS && vWS.readyState === WebSocket.OPEN) vWS.send(JSON.stringify({
|
||||||
|
op: 3,
|
||||||
|
d: null
|
||||||
|
}));
|
||||||
|
}, data.d.heartbeat_interval);
|
||||||
|
self.KAI = KAI;
|
||||||
|
|
||||||
|
var udpPacket = new Buffer(70);
|
||||||
|
udpPacket.writeUIntBE(data.d.ssrc, 0, 4);
|
||||||
|
udpClient.send(udpPacket, 0, udpPacket.length, data.d.port, self.endpoint, function (err) {
|
||||||
|
if (err) self.emit("error", err);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
|
||||||
|
self.ready = true;
|
||||||
|
self.mode = data.d.mode;
|
||||||
|
self.emit("ready", self);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return VoiceConnection;
|
return VoiceConnection;
|
||||||
})(EventEmitter);
|
})(EventEmitter);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
"babel-preset-es2015": "^6.1.18",
|
"babel-preset-es2015": "^6.1.18",
|
||||||
"babel-preset-es2015-loose": "^6.1.2",
|
"babel-preset-es2015-loose": "^6.1.2",
|
||||||
"grunt": "~0.4.5",
|
"grunt": "~0.4.5",
|
||||||
"grunt-babel": "^5.0.1",
|
"grunt-babel": "<6.0.0",
|
||||||
"grunt-browserify": "^4.0.0",
|
"grunt-browserify": "^4.0.0",
|
||||||
"grunt-contrib-uglify": "^0.9.2",
|
"grunt-contrib-uglify": "^0.9.2",
|
||||||
"load-grunt-tasks": "^3.2.0"
|
"load-grunt-tasks": "^3.2.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user