Built src again using the correct preset

This commit is contained in:
Amish Shah
2015-11-22 15:12:39 +00:00
parent 68b60c5464
commit b22995f254
27 changed files with 4288 additions and 3142 deletions

5
.babelrc Normal file
View File

@@ -0,0 +1,5 @@
{
"presets": [
"es2015"
]
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,5 @@
"use strict";
exports.IDLE = 0;
exports.LOGGING_IN = 1;
exports.LOGGED_IN = 2;

File diff suppressed because it is too large Load Diff

View File

@@ -2,6 +2,11 @@
/* 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"); } }
var fs = require("fs");
var User = require("../../Structures/User.js"),
@@ -15,35 +20,62 @@ var User = require("../../Structures/User.js"),
Invite = require("../../Structures/Invite.js"),
Games = require("../../../ref/gameMap.js");
class Resolver {
constructor(internal) {
var Resolver = (function () {
function Resolver(internal) {
_classCallCheck(this, Resolver);
this.internal = internal;
}
resolveGameID(resource) {
_createClass(Resolver, [{
key: "resolveGameID",
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;
for (var game of Games) {
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;
}
resolveToBase64(resource) {
}, {
key: "resolveToBase64",
value: function resolveToBase64(resource) {
if (resource instanceof Buffer) {
resource = resource.toString("base64");
resource = "data:image/jpg;base64," + resource;
}
return resource;
}
resolveInviteID(resource) {
}, {
key: "resolveInviteID",
value: function resolveInviteID(resource) {
if (resource instanceof Invite) {
return resource.id;
} else if (typeof resource == "string" || resource instanceof String) {
@@ -57,8 +89,9 @@ class Resolver {
}
return null;
}
resolveServer(resource) {
}, {
key: "resolveServer",
value: function resolveServer(resource) {
if (resource instanceof Server) {
return resource;
} else if (resource instanceof ServerChannel) {
@@ -72,25 +105,50 @@ class Resolver {
}
return null;
}
resolveFile(resource) {
}, {
key: "resolveFile",
value: function resolveFile(resource) {
if (typeof resource === "string" || resource instanceof String) {
return fs.createReadStream(resource);
} else {
return resource;
}
}
resolveMentions(resource) {
}, {
key: "resolveMentions",
value: function resolveMentions(resource) {
// resource is a string
var _mentions = [];
for (var mention of resource.match(/<@[^>]*>/g) || []) {
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = (resource.match(/<@[^>]*>/g) || [])[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var mention = _step2.value;
_mentions.push(mention.substring(2, mention.length - 1));
}
return _mentions;
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
resolveString(resource) {
return _mentions;
}
}, {
key: "resolveString",
value: function resolveString(resource) {
// accepts Array, Channel, Server, User, Message, String and anything
// toString()-able
@@ -102,8 +160,9 @@ class Resolver {
return final.toString();
}
resolveUser(resource) {
}, {
key: "resolveUser",
value: function resolveUser(resource) {
/*
accepts a Message, Channel, Server, String ID, User, PMChannel
*/
@@ -127,8 +186,9 @@ class Resolver {
return found;
}
resolveMessage(resource) {
}, {
key: "resolveMessage",
value: function resolveMessage(resource) {
// accepts a Message, PMChannel & TextChannel
var found = null;
@@ -140,22 +200,24 @@ class Resolver {
return found;
}
resolveVoiceChannel(resource) {
}, {
key: "resolveVoiceChannel",
value: function resolveVoiceChannel(resource) {
// resolveChannel will also work but this is more apt
if (resource instanceof VoiceChannel) {
return resource;
}
return null;
}
resolveChannel(resource) {
}, {
key: "resolveChannel",
value: function resolveChannel(resource) {
/*
accepts a Message, Channel, Server, String ID, User
*/
var self = this;
return new Promise((resolve, reject) => {
return new Promise(function (resolve, reject) {
var found = null;
if (resource instanceof Message) {
found = resource.channel;
@@ -168,23 +230,53 @@ class Resolver {
} else if (resource instanceof User) {
// see if a PM exists
var chatFound = false;
for (var pmchat of self.internal.private_channels) {
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) {
// a PM already exists!
found = chatFound;
} else {
// PM does not exist :\
self.internal.startPM(resource).then(pmchannel => resolve(pmchannel)).catch(e => reject(e));
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;
})();
module.exports = Resolver;

View File

@@ -1,35 +1,75 @@
"use strict";
var API = "https://discordapp.com/api";
var Endpoints = {
// general endpoints
LOGIN: `${ API }/auth/login`,
LOGOUT: `${ API }/auth/logout`,
ME: `${ API }/users/@me`,
GATEWAY: `${ API }/gateway`,
USER_CHANNELS: userID => `${ API }/users/${ userID }/channels`,
AVATAR: (userID, avatar) => `${ API }/users/${ userID }/avatars/${ avatar }.jpg`,
INVITE: id => `${ API }/invite/${ id }`,
LOGIN: API + "/auth/login",
LOGOUT: API + "/auth/logout",
ME: API + "/users/@me",
GATEWAY: API + "/gateway",
USER_CHANNELS: function USER_CHANNELS(userID) {
return API + "/users/" + userID + "/channels";
},
AVATAR: function AVATAR(userID, avatar) {
return API + "/users/" + userID + "/avatars/" + avatar + ".jpg";
},
INVITE: function INVITE(id) {
return API + "/invite/" + id;
},
// servers
SERVERS: `${ API }/guilds`,
SERVER: serverID => `${ Endpoints.SERVERS }/${ serverID }`,
SERVER_ICON: (serverID, hash) => `${ Endpoints.SERVER(serverID) }/icons/${ hash }.jpg`,
SERVER_PRUNE: serverID => `${ Endpoints.SERVER(serverID) }/prune`,
SERVER_EMBED: serverID => `${ Endpoints.SERVER(serverID) }/embed`,
SERVER_INVITES: serverID => `${ Endpoints.SERVER(serverID) }/invites`,
SERVER_ROLES: serverID => `${ Endpoints.SERVER(serverID) }/roles`,
SERVER_BANS: serverID => `${ Endpoints.SERVER(serverID) }/bans`,
SERVER_INTEGRATIONS: serverID => `${ Endpoints.SERVER(serverID) }/integrations`,
SERVER_MEMBERS: serverID => `${ Endpoints.SERVER(serverID) }/members`,
SERVER_CHANNELS: serverID => `${ Endpoints.SERVER(serverID) }/channels`,
SERVERS: API + "/guilds",
SERVER: function SERVER(serverID) {
return Endpoints.SERVERS + "/" + serverID;
},
SERVER_ICON: function SERVER_ICON(serverID, hash) {
return Endpoints.SERVER(serverID) + "/icons/" + hash + ".jpg";
},
SERVER_PRUNE: function SERVER_PRUNE(serverID) {
return Endpoints.SERVER(serverID) + "/prune";
},
SERVER_EMBED: function SERVER_EMBED(serverID) {
return Endpoints.SERVER(serverID) + "/embed";
},
SERVER_INVITES: function SERVER_INVITES(serverID) {
return Endpoints.SERVER(serverID) + "/invites";
},
SERVER_ROLES: function SERVER_ROLES(serverID) {
return Endpoints.SERVER(serverID) + "/roles";
},
SERVER_BANS: function SERVER_BANS(serverID) {
return Endpoints.SERVER(serverID) + "/bans";
},
SERVER_INTEGRATIONS: function SERVER_INTEGRATIONS(serverID) {
return Endpoints.SERVER(serverID) + "/integrations";
},
SERVER_MEMBERS: function SERVER_MEMBERS(serverID) {
return Endpoints.SERVER(serverID) + "/members";
},
SERVER_CHANNELS: function SERVER_CHANNELS(serverID) {
return Endpoints.SERVER(serverID) + "/channels";
},
// channels
CHANNELS: `${ API }/channels`,
CHANNEL: channelID => `${ Endpoints.CHANNELS }/${ channelID }`,
CHANNEL_MESSAGES: channelID => `${ Endpoints.CHANNEL(channelID) }/messages`,
CHANNEL_INVITES: channelID => `${ Endpoints.CHANNEL(channelID) }/invites`,
CHANNEL_TYPING: channelID => `${ Endpoints.CHANNEL(channelID) }/typing`,
CHANNEL_PERMISSIONS: channelID => `${ Endpoints.CHANNEL(channelID) }/permissions`,
CHANNEL_MESSAGE: (channelID, messageID) => `${ Endpoints.CHANNEL_MESSAGES(channelID) }/${ messageID }`
CHANNELS: API + "/channels",
CHANNEL: function CHANNEL(channelID) {
return Endpoints.CHANNELS + "/" + channelID;
},
CHANNEL_MESSAGES: function CHANNEL_MESSAGES(channelID) {
return Endpoints.CHANNEL(channelID) + "/messages";
},
CHANNEL_INVITES: function CHANNEL_INVITES(channelID) {
return Endpoints.CHANNEL(channelID) + "/invites";
},
CHANNEL_TYPING: function CHANNEL_TYPING(channelID) {
return Endpoints.CHANNEL(channelID) + "/typing";
},
CHANNEL_PERMISSIONS: function CHANNEL_PERMISSIONS(channelID) {
return Endpoints.CHANNEL(channelID) + "/permissions";
},
CHANNEL_MESSAGE: function CHANNEL_MESSAGE(channelID, messageID) {
return Endpoints.CHANNEL_MESSAGES(channelID) + "/" + messageID;
}
};
var Permissions = {

View File

@@ -1,26 +1,44 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Equality = require("../Util/Equality.js");
var Cache = require("../Util/Cache.js");
var PermissionOverwrite = require("./PermissionOverwrite.js");
var reg = require("../Util/ArgumentRegulariser.js").reg;
class Channel extends Equality {
var Channel = (function (_Equality) {
_inherits(Channel, _Equality);
constructor(data, client) {
super();
this.id = data.id;
this.client = client;
function Channel(data, client) {
_classCallCheck(this, Channel);
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Channel).call(this));
_this.id = data.id;
_this.client = client;
return _this;
}
get isPrivate() {
return !!this.server;
}
delete() {
_createClass(Channel, [{
key: "delete",
value: function _delete() {
return this.client.deleteChannel.apply(this.client, reg(this, arguments));
}
}, {
key: "isPrivate",
get: function get() {
return !!this.server;
}
}]);
}
return Channel;
})(Equality);
module.exports = Channel;

View File

@@ -1,15 +1,26 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Permissions = require("../Constants.js").Permissions;
class ChannelPermissions {
constructor(permissions) {
var ChannelPermissions = (function () {
function ChannelPermissions(permissions) {
_classCallCheck(this, ChannelPermissions);
this.permissions = permissions;
}
serialise(explicit) {
_createClass(ChannelPermissions, [{
key: "serialise",
value: function serialise(explicit) {
var _this = this;
var hp = perm => this.hasPermission(perm, explicit);
var hp = function hp(perm) {
return _this.hasPermission(perm, explicit);
};
return {
// general
@@ -37,13 +48,17 @@ class ChannelPermissions {
voiceUseVAD: hp(Permissions.voiceUseVAD)
};
}
serialize() {
}, {
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];
hasPermission(perm, explicit = false) {
if (perm instanceof String || typeof perm === "string") {
perm = Permissions[perm];
}
@@ -59,6 +74,9 @@ class ChannelPermissions {
}
return !!(this.permissions & perm);
}
}
}]);
return ChannelPermissions;
})();
module.exports = ChannelPermissions;

View File

@@ -1,10 +1,16 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Server = require("./Server.js");
var ServerChannel = require("./ServerChannel.js");
class Invite {
constructor(data, chan, client) {
var Invite = (function () {
function Invite(data, chan, client) {
_classCallCheck(this, Invite);
this.maxAge = data.max_age;
this.code = data.code;
this.server = chan.server;
@@ -18,9 +24,14 @@ class Invite {
this.xkcd = data.xkcdpass;
}
toString() {
return `https://discord.gg/${ this.code }`;
_createClass(Invite, [{
key: "toString",
value: function toString() {
return "https://discord.gg/" + this.code;
}
}
}]);
return Invite;
})();
module.exports = Invite;

View File

@@ -1,39 +1,55 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Cache = require("../Util/Cache.js");
var User = require("./User.js");
var reg = require("../Util/ArgumentRegulariser.js").reg;
var Equality = require("../Util/Equality");
class Message extends Equality {
constructor(data, channel, client) {
super();
this.channel = channel;
this.client = client;
this.nonce = data.nonce;
this.attachments = data.attachments;
this.tts = data.tts;
this.embeds = data.embeds;
this.timestamp = Date.parse(data.timestamp);
this.everyoneMentioned = data.mention_everyone;
this.id = data.id;
var Message = (function (_Equality) {
_inherits(Message, _Equality);
if (data.edited_timestamp) this.editedTimestamp = Date.parse(data.edited_timestamp);
function Message(data, channel, client) {
_classCallCheck(this, Message);
if (data.author instanceof User) this.author = data.author;else this.author = client.internal.users.add(new User(data.author, client));
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Message).call(this));
this.content = data.content;
this.mentions = new Cache();
_this.channel = channel;
_this.client = client;
_this.nonce = data.nonce;
_this.attachments = data.attachments;
_this.tts = data.tts;
_this.embeds = data.embeds;
_this.timestamp = Date.parse(data.timestamp);
_this.everyoneMentioned = data.mention_everyone;
_this.id = data.id;
data.mentions.forEach(mention => {
if (data.edited_timestamp) _this.editedTimestamp = Date.parse(data.edited_timestamp);
if (data.author instanceof User) _this.author = data.author;else _this.author = client.internal.users.add(new User(data.author, client));
_this.content = data.content;
_this.mentions = new Cache();
data.mentions.forEach(function (mention) {
// this is .add and not .get because it allows the bot to cache
// users from messages from logs who may have left the server and were
// not previously cached.
if (mention instanceof User) this.mentions.push(mention);else this.mentions.add(client.internal.users.add(new User(mention, client)));
if (mention instanceof User) _this.mentions.push(mention);else _this.mentions.add(client.internal.users.add(new User(mention, client)));
});
return _this;
}
isMentioned(user) {
_createClass(Message, [{
key: "isMentioned",
value: function isMentioned(user) {
user = this.client.internal.resolver.resolveUser(user);
if (user) {
return this.mentions.has("id", user.id);
@@ -41,30 +57,39 @@ class Message extends Equality {
return false;
}
}
toString() {
}, {
key: "toString",
value: function toString() {
return this.content;
}
delete() {
}, {
key: "delete",
value: function _delete() {
return this.client.deleteMessage.apply(this.client, reg(this, arguments));
}
update() {
}, {
key: "update",
value: function update() {
return this.client.updateMessage.apply(this.client, reg(this, arguments));
}
reply() {
}, {
key: "reply",
value: function reply() {
return this.client.reply.apply(this.client, reg(this, arguments));
}
replyTTS() {
}, {
key: "replyTTS",
value: function replyTTS() {
return this.client.replyTTS.apply(this.client, reg(this, arguments));
}
get sender() {
}, {
key: "sender",
get: function get() {
return this.author;
}
}
}]);
return Message;
})(Equality);
module.exports = Message;

View File

@@ -1,37 +1,59 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Channel = require("./Channel.js");
var User = require("./User.js");
var Equality = require("../Util/Equality.js");
var Cache = require("../Util/Cache.js");
var reg = require("../Util/ArgumentRegulariser.js").reg;
class PMChannel extends Channel {
constructor(data, client) {
super(data, client);
var PMChannel = (function (_Channel) {
_inherits(PMChannel, _Channel);
this.type = data.type || "text";
this.lastMessageId = data.last_message_id;
this.messages = new Cache("id", 1000);
this.recipient = this.client.internal.users.add(new User(data.recipient, this.client));
function PMChannel(data, client) {
_classCallCheck(this, PMChannel);
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(PMChannel).call(this, data, client));
_this.type = data.type || "text";
_this.lastMessageId = data.last_message_id;
_this.messages = new Cache("id", 1000);
_this.recipient = _this.client.internal.users.add(new User(data.recipient, _this.client));
return _this;
}
/* warning! may return null */
get lastMessage() {
return this.messages.get("id", this.lastMessageID);
}
toString() {
_createClass(PMChannel, [{
key: "toString",
value: function toString() {
return this.recipient.toString();
}
sendMessage() {
}, {
key: "sendMessage",
value: function sendMessage() {
return this.client.sendMessage.apply(this.client, reg(this, arguments));
}
sendTTSMessage() {
}, {
key: "sendTTSMessage",
value: function sendTTSMessage() {
return this.client.sendTTSMessage.apply(this.client, reg(this, arguments));
}
}
}, {
key: "lastMessage",
get: function get() {
return this.messages.get("id", this.lastMessageID);
}
}]);
return PMChannel;
})(Channel);
module.exports = PMChannel;

View File

@@ -1,10 +1,15 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Permissions = require("../Constants.js").Permissions;
class PermissionOverwrite {
var PermissionOverwrite = (function () {
function PermissionOverwrite(data) {
_classCallCheck(this, PermissionOverwrite);
constructor(data) {
this.id = data.id;
this.type = data.type; // member or role
this.deny = data.deny;
@@ -12,7 +17,38 @@ class PermissionOverwrite {
}
// returns an array of allowed permissions
get allowed() {
_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",
get: function get() {
var allowed = [];
for (var permName in Permissions) {
if (permName === "manageRoles" || permName === "manageChannels") {
@@ -28,7 +64,10 @@ class PermissionOverwrite {
}
// returns an array of denied permissions
get denied() {
}, {
key: "denied",
get: function get() {
var denied = [];
for (var permName in Permissions) {
if (permName === "manageRoles" || permName === "manageChannels") {
@@ -42,29 +81,9 @@ class PermissionOverwrite {
}
return denied;
}
}]);
setAllowed(allowedArray) {
allowedArray.forEach(permission => {
if (permission instanceof String || typeof permission === "string") {
permission = Permissions[permission];
}
if (permission) {
this.allow |= 1 << permission;
}
});
}
setDenied(deniedArray) {
deniedArray.forEach(permission => {
if (permission instanceof String || typeof permission === "string") {
permission = Permissions[permission];
}
if (permission) {
this.deny |= 1 << permission;
}
});
}
}
return PermissionOverwrite;
})();
module.exports = PermissionOverwrite;

View File

@@ -1,5 +1,9 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Permissions = require("../Constants.js").Permissions;
/*
@@ -14,10 +18,14 @@ example data
color: 0 }
*/
const DefaultRole = [Permissions.createInstantInvite, Permissions.readMessages, Permissions.readMessageHistory, Permissions.sendMessages, Permissions.sendTTSMessages, Permissions.embedLinks, Permissions.attachFiles, Permissions.readMessageHistory, Permissions.mentionEveryone, Permissions.voiceConnect, Permissions.voiceSpeak, Permissions.voiceUseVAD].reduce((previous, current) => previous | current, 0);
var DefaultRole = [Permissions.createInstantInvite, Permissions.readMessages, Permissions.readMessageHistory, Permissions.sendMessages, Permissions.sendTTSMessages, Permissions.embedLinks, Permissions.attachFiles, Permissions.readMessageHistory, Permissions.mentionEveryone, Permissions.voiceConnect, Permissions.voiceSpeak, Permissions.voiceUseVAD].reduce(function (previous, current) {
return previous | current;
}, 0);
var Role = (function () {
function Role(data, server, client) {
_classCallCheck(this, Role);
class Role {
constructor(data, server, client) {
this.position = data.position || -1;
this.permissions = data.permissions || (data.name === "@everyone" ? DefaultRole : 0);
this.name = data.name || "@everyone";
@@ -29,9 +37,14 @@ class Role {
this.client = client;
}
serialise(explicit) {
_createClass(Role, [{
key: "serialise",
value: function serialise(explicit) {
var _this = this;
var hp = perm => this.hasPermission(perm, explicit);
var hp = function hp(perm) {
return _this.hasPermission(perm, explicit);
};
return {
// general
@@ -59,13 +72,17 @@ class Role {
voiceUseVAD: hp(Permissions.voiceUseVAD)
};
}
serialize() {
}, {
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];
hasPermission(perm, explicit = false) {
if (perm instanceof String || typeof perm === "string") {
perm = Permissions[perm];
}
@@ -85,8 +102,9 @@ class Role {
return !!(this.permissions & perm);
}
setPermission(permission, value) {
}, {
key: "setPermission",
value: function setPermission(permission, value) {
if (permission instanceof String || typeof permission === "string") {
permission = Permissions[permission];
}
@@ -99,26 +117,33 @@ class Role {
}
}
}
}, {
key: "setPermissions",
value: function setPermissions(obj) {
var _this2 = this;
setPermissions(obj) {
obj.forEach((value, permission) => {
obj.forEach(function (value, permission) {
if (permission instanceof String || typeof permission === "string") {
permission = Permissions[permission];
}
if (permission) {
// valid permission
this.setPermission(permission, value);
_this2.setPermission(permission, value);
}
});
}
colorAsHex() {
}, {
key: "colorAsHex",
value: function colorAsHex() {
var val = this.color.toString();
while (val.length < 6) {
val = "0" + val;
}
return "#" + val;
}
}
}]);
return Role;
})();
module.exports = Role;

View File

@@ -1,5 +1,13 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Equality = require("../Util/Equality.js");
var Endpoints = require("../Constants.js").Endpoints;
var Cache = require("../Util/Cache.js");
@@ -10,65 +18,94 @@ var Role = require("./Role.js");
var strictKeys = ["region", "ownerID", "name", "id", "icon", "afkTimeout", "afkChannelID"];
class Server extends Equality {
constructor(data, client) {
var Server = (function (_Equality) {
_inherits(Server, _Equality);
super();
function Server(data, client) {
_classCallCheck(this, Server);
var self = this;
this.client = client;
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Server).call(this));
this.region = data.region;
this.ownerID = data.owner_id;
this.name = data.name;
this.id = data.id;
this.members = new Cache();
this.channels = new Cache();
this.roles = new Cache();
this.icon = data.icon;
this.afkTimeout = data.afkTimeout;
this.afkChannelID = data.afk_channel_id;
this.memberMap = {};
var self = _this;
_this.client = client;
var self = this;
_this.region = data.region;
_this.ownerID = data.owner_id;
_this.name = data.name;
_this.id = data.id;
_this.members = new Cache();
_this.channels = new Cache();
_this.roles = new Cache();
_this.icon = data.icon;
_this.afkTimeout = data.afkTimeout;
_this.afkChannelID = data.afk_channel_id;
_this.memberMap = {};
data.roles.forEach(dataRole => {
this.roles.add(new Role(dataRole, this, client));
var self = _this;
data.roles.forEach(function (dataRole) {
_this.roles.add(new Role(dataRole, _this, client));
});
data.members.forEach(dataUser => {
this.memberMap[dataUser.user.id] = {
roles: dataUser.roles.map(pid => self.roles.get("id", pid)),
data.members.forEach(function (dataUser) {
_this.memberMap[dataUser.user.id] = {
roles: dataUser.roles.map(function (pid) {
return self.roles.get("id", pid);
}),
mute: dataUser.mute,
deaf: dataUser.deaf,
joinedAt: Date.parse(dataUser.joined_at)
};
var user = client.internal.users.add(new User(dataUser.user, client));
this.members.add(user);
_this.members.add(user);
});
data.channels.forEach(dataChannel => {
data.channels.forEach(function (dataChannel) {
if (dataChannel.type === "text") {
var channel = client.internal.channels.add(new TextChannel(dataChannel, client, this));
this.channels.add(channel);
var channel = client.internal.channels.add(new TextChannel(dataChannel, client, _this));
_this.channels.add(channel);
} else {
var channel = client.internal.channels.add(new VoiceChannel(dataChannel, client, this));
this.channels.add(channel);
var channel = client.internal.channels.add(new VoiceChannel(dataChannel, client, _this));
_this.channels.add(channel);
}
});
if (data.presences) {
for (var presence of data.presences) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = data.presences[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var presence = _step.value;
var user = client.internal.users.get("id", presence.user.id);
if (user) {
user.status = presence.status;
user.gameID = presence.game_id;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
return _this;
}
rolesOfUser(user) {
_createClass(Server, [{
key: "rolesOfUser",
value: function rolesOfUser(user) {
user = this.client.internal.resolver.resolveUser(user);
if (user) {
return this.memberMap[user.id] ? this.memberMap[user.id].roles : [];
@@ -76,48 +113,78 @@ class Server extends Equality {
return null;
}
}
rolesOf(user) {
}, {
key: "rolesOf",
value: function rolesOf(user) {
return this.rolesOfUser(user);
}
get iconURL() {
if (!this.icon) {
return null;
} else {
return Endpoints.SERVER_ICON(this.id, this.icon);
}
}
get afkChannel() {
return this.channels.get("id", this.afkChannelID);
}
get defaultChannel() {
return this.channels.get("id", this.id);
}
get owner() {
return this.members.get("id", this.ownerID);
}
toString() {
}, {
key: "toString",
value: function toString() {
return this.name;
}
equalsStrict(obj) {
}, {
key: "equalsStrict",
value: function equalsStrict(obj) {
if (obj instanceof Server) {
for (var key of strictKeys) {
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = strictKeys[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var key = _step2.value;
if (obj[key] !== this[key]) {
return false;
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
} else {
return false;
}
return true;
}
}, {
key: "iconURL",
get: function get() {
if (!this.icon) {
return null;
} else {
return Endpoints.SERVER_ICON(this.id, this.icon);
}
}
}, {
key: "afkChannel",
get: function get() {
return this.channels.get("id", this.afkChannelID);
}
}, {
key: "defaultChannel",
get: function get() {
return this.channels.get("id", this.id);
}
}, {
key: "owner",
get: function get() {
return this.members.get("id", this.ownerID);
}
}]);
}
return Server;
})(Equality);
module.exports = Server;

View File

@@ -1,25 +1,41 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Channel = require("./Channel.js");
var Cache = require("../Util/Cache.js");
var PermissionOverwrite = require("./PermissionOverwrite.js");
var ChannelPermissions = require("./ChannelPermissions.js");
var reg = require("../Util/ArgumentRegulariser.js").reg;
class ServerChannel extends Channel {
constructor(data, client, server) {
super(data, client);
this.name = data.name;
this.type = data.type;
this.position = data.position;
this.permissionOverwrites = new Cache();
this.server = server;
data.permission_overwrites.forEach(permission => {
this.permissionOverwrites.add(new PermissionOverwrite(permission));
var ServerChannel = (function (_Channel) {
_inherits(ServerChannel, _Channel);
function ServerChannel(data, client, server) {
_classCallCheck(this, ServerChannel);
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(ServerChannel).call(this, data, client));
_this.name = data.name;
_this.type = data.type;
_this.position = data.position;
_this.permissionOverwrites = new Cache();
_this.server = server;
data.permission_overwrites.forEach(function (permission) {
_this.permissionOverwrites.add(new PermissionOverwrite(permission));
});
return _this;
}
permissionsOf(user) {
_createClass(ServerChannel, [{
key: "permissionsOf",
value: function permissionsOf(user) {
user = this.client.internal.resolver.resolveUser(user);
if (user) {
if (this.server.owner.equals(user)) {
@@ -28,11 +44,13 @@ class ServerChannel extends Channel {
var everyoneRole = this.server.roles.get("name", "@everyone");
var userRoles = [everyoneRole].concat(this.server.rolesOf(user) || []);
var userRolesID = userRoles.map(v => v.id);
var userRolesID = userRoles.map(function (v) {
return v.id;
});
var roleOverwrites = [],
memberOverwrites = [];
this.permissionOverwrites.forEach(overwrite => {
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) {
@@ -42,36 +60,85 @@ class ServerChannel extends Channel {
var permissions = 0;
for (var serverRole of userRoles) {
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;
for (var overwrite of roleOverwrites.concat(memberOverwrites)) {
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;
}
}
permsOf(user) {
}, {
key: "permsOf",
value: function permsOf(user) {
return this.permissionsOf(user);
}
mention() {
return `<#${ this.id }>`;
}, {
key: "mention",
value: function mention() {
return "<#" + this.id + ">";
}
toString() {
}, {
key: "toString",
value: function toString() {
return this.mention();
}
setName() {
}, {
key: "setName",
value: function setName() {
return this.client.setChannelName.apply(this.client, reg(this, arguments));
}
}
}]);
return ServerChannel;
})(Channel);
module.exports = ServerChannel;

View File

@@ -1,42 +1,66 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ServerChannel = require("./ServerChannel.js");
var Cache = require("../Util/Cache.js");
var reg = require("../Util/ArgumentRegulariser.js").reg;
class TextChannel extends ServerChannel {
constructor(data, client, server) {
super(data, client, server);
var TextChannel = (function (_ServerChannel) {
_inherits(TextChannel, _ServerChannel);
this.topic = data.topic;
this.lastMessageID = data.last_message_id;
this.messages = new Cache("id", client.options.maximumMessages);
function TextChannel(data, client, server) {
_classCallCheck(this, TextChannel);
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(TextChannel).call(this, data, client, server));
_this.topic = data.topic;
_this.lastMessageID = data.last_message_id;
_this.messages = new Cache("id", client.options.maximumMessages);
return _this;
}
/* warning! may return null */
get lastMessage() {
return this.messages.get("id", this.lastMessageID);
}
setTopic() {
_createClass(TextChannel, [{
key: "setTopic",
value: function setTopic() {
return this.client.setTopic.apply(this.client, reg(this, arguments));
}
setNameAndTopic() {
}, {
key: "setNameAndTopic",
value: function setNameAndTopic() {
return this.client.setChannelNameAndTopic.apply(this.client, reg(this, arguments));
}
update() {
}, {
key: "update",
value: function update() {
return this.client.updateChannel.apply(this.client, reg(this, arguments));
}
sendMessage() {
}, {
key: "sendMessage",
value: function sendMessage() {
return this.client.sendMessage.apply(this.client, reg(this, arguments));
}
sendTTSMessage() {
}, {
key: "sendTTSMessage",
value: function sendTTSMessage() {
return this.client.sendTTSMessage.apply(this.client, reg(this, arguments));
}
}
}, {
key: "lastMessage",
get: function get() {
return this.messages.get("id", this.lastMessageID);
}
}]);
return TextChannel;
})(ServerChannel);
module.exports = TextChannel;

View File

@@ -1,43 +1,65 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Equality = require("../Util/Equality.js");
var Endpoints = require("../Constants.js").Endpoints;
class User extends Equality {
constructor(data, client) {
super();
this.client = client;
this.username = data.username;
this.discriminator = data.discriminator;
this.id = data.id;
this.avatar = data.avatar;
this.status = data.status || "offline";
this.gameID = data.game_id || null;
this.typing = {
var User = (function (_Equality) {
_inherits(User, _Equality);
function User(data, client) {
_classCallCheck(this, User);
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(User).call(this));
_this.client = client;
_this.username = data.username;
_this.discriminator = data.discriminator;
_this.id = data.id;
_this.avatar = data.avatar;
_this.status = data.status || "offline";
_this.gameID = data.game_id || null;
_this.typing = {
since: null,
channel: null
};
return _this;
}
get avatarURL() {
_createClass(User, [{
key: "mention",
value: function mention() {
return "<@" + this.id + ">";
}
}, {
key: "toString",
value: function toString() {
return this.mention();
}
}, {
key: "equalsStrict",
value: function equalsStrict(obj) {
if (obj instanceof User) return this.id === obj.id && this.username === obj.username && this.discriminator === obj.discriminator && this.avatar === obj.avatar && this.status === obj.status && this.gameID === obj.gameID;else return false;
}
}, {
key: "avatarURL",
get: function get() {
if (!this.avatar) {
return null;
} else {
return Endpoints.AVATAR(this.id, this.avatar);
}
}
}]);
mention() {
return `<@${ this.id }>`;
}
toString() {
return this.mention();
}
equalsStrict(obj) {
if (obj instanceof User) return this.id === obj.id && this.username === obj.username && this.discriminator === obj.discriminator && this.avatar === obj.avatar && this.status === obj.status && this.gameID === obj.gameID;else return false;
}
}
return User;
})(Equality);
module.exports = User;

View File

@@ -1,11 +1,23 @@
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ServerChannel = require("./ServerChannel.js");
class VoiceChannel extends ServerChannel {
constructor(data, client, server) {
super(data, client, server);
var VoiceChannel = (function (_ServerChannel) {
_inherits(VoiceChannel, _ServerChannel);
function VoiceChannel(data, client, server) {
_classCallCheck(this, VoiceChannel);
return _possibleConstructorReturn(this, Object.getPrototypeOf(VoiceChannel).call(this, data, client, server));
}
}
return VoiceChannel;
})(ServerChannel);
module.exports = VoiceChannel;

View File

@@ -1,3 +1,5 @@
"use strict";
exports.reg = function (c, a) {
return [c].concat(Array.prototype.slice.call(a));
};

View File

@@ -1,14 +1,30 @@
"use strict";
class Cache extends Array {
constructor(discrim, limit) {
super();
this.discrim = discrim || "id";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Cache = (function (_Array) {
_inherits(Cache, _Array);
function Cache(discrim, limit) {
_classCallCheck(this, Cache);
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Cache).call(this));
_this.discrim = discrim || "id";
return _this;
}
get(key, value) {
_createClass(Cache, [{
key: "get",
value: function get(key, value) {
var found = null;
this.forEach((val, index, array) => {
this.forEach(function (val, index, array) {
if (val.hasOwnProperty(key) && val[key] == value) {
found = val;
return;
@@ -16,14 +32,16 @@ class Cache extends Array {
});
return found;
}
has(key, value) {
}, {
key: "has",
value: function has(key, value) {
return !!this.get(key, value);
}
getAll(key, value) {
}, {
key: "getAll",
value: function getAll(key, value) {
var found = new Cache(this.discrim);
this.forEach((val, index, array) => {
this.forEach(function (val, index, array) {
if (val.hasOwnProperty(key) && val[key] == value) {
found.push(val);
return;
@@ -31,15 +49,38 @@ class Cache extends Array {
});
return found;
}
add(data) {
}, {
key: "add",
value: function add(data) {
var exit = false;
for (var item of this) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = this[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var item = _step.value;
if (item[this.discrim] === data[this.discrim]) {
exit = item;
break;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
if (exit) {
return exit;
} else {
@@ -50,8 +91,9 @@ class Cache extends Array {
return data;
}
}
update(old, data) {
}, {
key: "update",
value: function update(old, data) {
var item = this.get(this.discrim, old[this.discrim]);
if (item) {
var index = this.indexOf(item);
@@ -61,12 +103,14 @@ class Cache extends Array {
return false;
}
}
random() {
}, {
key: "random",
value: function random() {
return this[Math.floor(Math.random() * this.length)];
}
remove(data) {
}, {
key: "remove",
value: function remove(data) {
var index = this.indexOf(data);
if (~index) {
this.splice(index, 1);
@@ -78,6 +122,9 @@ class Cache extends Array {
}
return false;
}
}
}]);
return Cache;
})(Array);
module.exports = Cache;

View File

@@ -1,3 +1,9 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*
The Equality Class is just used to show
that a Class has an ID that can be used to
@@ -9,24 +15,34 @@
Instead, use objectThatExtendsEquality.equals()
*/
class Equality {
constructor() {}
get eqDiscriminator() {
return "id";
var Equality = (function () {
function Equality() {
_classCallCheck(this, Equality);
}
equals(object) {
_createClass(Equality, [{
key: "equals",
value: function equals(object) {
if (object && object[this.eqDiscriminator] == this[this.eqDiscriminator]) {
return true;
}
return false;
}
equalsStrict(object) {
}, {
key: "equalsStrict",
value: function equalsStrict(object) {
// override per class type
return;
}
}
}, {
key: "eqDiscriminator",
get: function get() {
return "id";
}
}]);
return Equality;
})();
module.exports = Equality;

View File

@@ -1,5 +1,9 @@
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var cpoc = require("child_process");
var opus;
@@ -10,39 +14,68 @@ try {
}
var VoicePacket = require("./VoicePacket.js");
class AudioEncoder {
constructor() {
var AudioEncoder = (function () {
function AudioEncoder() {
_classCallCheck(this, AudioEncoder);
if (opus) {
this.opus = new opus.OpusEncoder(48000, 1);
}
this.choice = false;
}
opusBuffer(buffer) {
_createClass(AudioEncoder, [{
key: "opusBuffer",
value: function opusBuffer(buffer) {
return this.opus.encode(buffer, 1920);
}
getCommand(force) {
}, {
key: "getCommand",
value: function getCommand(force) {
if (this.choice && force) return choice;
var choices = ["avconv", "ffmpeg"];
for (var choice of choices) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = choices[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var choice = _step.value;
var p = cpoc.spawnSync(choice);
if (!p.error) {
this.choice = choice;
return choice;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return "help";
}
}, {
key: "encodeStream",
value: function encodeStream(stream) {
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, buffer) {} : arguments[1];
encodeStream(stream, callback = function (err, buffer) {}) {
var self = this;
return new Promise((resolve, reject) => {
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", "-"]);
@@ -72,10 +105,13 @@ class AudioEncoder {
});
});
}
}, {
key: "encodeFile",
value: function encodeFile(file) {
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, buffer) {} : arguments[1];
encodeFile(file, callback = function (err, buffer) {}) {
var self = this;
return new Promise((resolve, reject) => {
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]);
@@ -101,6 +137,9 @@ class AudioEncoder {
});
});
}
}
}]);
return AudioEncoder;
})();
module.exports = AudioEncoder;

View File

@@ -1,12 +1,25 @@
"use strict"
// 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 _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var EventEmitter = require("events");
class StreamIntent extends EventEmitter {
constructor() {
super();
var StreamIntent = (function (_EventEmitter) {
_inherits(StreamIntent, _EventEmitter);
function StreamIntent() {
_classCallCheck(this, StreamIntent);
return _possibleConstructorReturn(this, Object.getPrototypeOf(StreamIntent).call(this));
}
}
return StreamIntent;
})(EventEmitter);
module.exports = StreamIntent;

View File

@@ -8,6 +8,15 @@
*/
;
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var WebSocket = require("ws");
var dns = require("dns");
var udp = require("dgram");
@@ -17,30 +26,38 @@ var VoicePacket = require("./VoicePacket.js");
var StreamIntent = require("./StreamIntent.js");
var EventEmitter = require("events");
class VoiceConnection extends EventEmitter {
constructor(channel, client, session, token, server, endpoint) {
super();
this.id = channel.id;
this.voiceChannel = channel;
this.client = client;
this.session = session;
this.token = token;
this.server = server;
this.endpoint = endpoint.replace(":80", "");
this.vWS = null; // vWS means voice websocket
this.ready = false;
this.vWSData = {};
this.encoder = new AudioEncoder();
this.udp = null;
this.playingIntent = null;
this.playing = false;
this.streamTime = 0;
this.streamProc = null;
this.KAI = null;
this.init();
var VoiceConnection = (function (_EventEmitter) {
_inherits(VoiceConnection, _EventEmitter);
function VoiceConnection(channel, client, session, token, server, endpoint) {
_classCallCheck(this, VoiceConnection);
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(VoiceConnection).call(this));
_this.id = channel.id;
_this.voiceChannel = channel;
_this.client = client;
_this.session = session;
_this.token = token;
_this.server = server;
_this.endpoint = endpoint.replace(":80", "");
_this.vWS = null; // vWS means voice websocket
_this.ready = false;
_this.vWSData = {};
_this.encoder = new AudioEncoder();
_this.udp = null;
_this.playingIntent = null;
_this.playing = false;
_this.streamTime = 0;
_this.streamProc = null;
_this.KAI = null;
_this.init();
return _this;
}
destroy() {
_createClass(VoiceConnection, [{
key: "destroy",
value: function destroy() {
this.stopPlaying();
if (this.KAI) clearInterval(this.KAI);
this.vWS.close();
@@ -55,8 +72,9 @@ class VoiceConnection extends EventEmitter {
}
});
}
stopPlaying() {
}, {
key: "stopPlaying",
value: function stopPlaying() {
this.playing = false;
this.playingIntent = null;
if (this.instream) {
@@ -64,8 +82,9 @@ class VoiceConnection extends EventEmitter {
this.instream.destroy();
}
}
playStream(stream) {
}, {
key: "playStream",
value: function playStream(stream) {
var self = this;
@@ -116,13 +135,14 @@ class VoiceConnection extends EventEmitter {
sequence + 10 < 65535 ? sequence += 1 : sequence = 0;
time + 9600 < 4294967295 ? time += 960 : time = 0;
self.sendBuffer(buffer, sequence, time, e => {});
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);
@@ -135,8 +155,9 @@ class VoiceConnection extends EventEmitter {
return retStream;
}
setSpeaking(value) {
}, {
key: "setSpeaking",
value: function setSpeaking(value) {
this.playing = value;
if (this.vWS.readyState === WebSocket.OPEN) this.vWS.send(JSON.stringify({
op: 5,
@@ -146,8 +167,11 @@ class VoiceConnection extends EventEmitter {
}
}));
}
}, {
key: "sendPacket",
value: function sendPacket(packet) {
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1];
sendPacket(packet, callback = function (err) {}) {
var self = this;
self.playing = true;
try {
@@ -158,8 +182,9 @@ class VoiceConnection extends EventEmitter {
return false;
}
}
sendBuffer(rawbuffer, sequence, timestamp, callback) {
}, {
key: "sendBuffer",
value: function sendBuffer(rawbuffer, sequence, timestamp, callback) {
var self = this;
self.playing = true;
try {
@@ -178,53 +203,71 @@ class VoiceConnection extends EventEmitter {
return false;
}
}
test() {
this.playFile("C:/users/amish/desktop/audio.mp3").then(stream => {
stream.on("time", time => {
}, {
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];
playFile(stream, callback = function (err, str) {}) {
var self = this;
return new Promise((resolve, reject) => {
this.encoder.encodeFile(stream).catch(error).then(data => {
return new Promise(function (resolve, reject) {
_this2.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(e = true) {
function error() {
var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
reject(e);
callback(e);
}
});
}
}, {
key: "playRawStream",
value: function playRawStream(stream) {
var _this3 = this;
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, str) {} : arguments[1];
playRawStream(stream, callback = function (err, str) {}) {
var self = this;
return new Promise((resolve, reject) => {
this.encoder.encodeStream(stream).catch(error).then(data => {
return new Promise(function (resolve, reject) {
_this3.encoder.encodeStream(stream).catch(error).then(function (data) {
self.streamProc = data.proc;
self.instream = data.instream;
var intent = self.playStream(data.stream);
resolve(intent);
callback(null, intent);
});
function error(e = true) {
function error() {
var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
reject(e);
callback(e);
}
});
}
}, {
key: "init",
value: function init() {
var _this4 = this;
init() {
var self = this;
dns.lookup(this.endpoint, (err, address, family) => {
dns.lookup(this.endpoint, function (err, address, family) {
self.endpoint = address;
var vWS = self.vWS = new WebSocket("wss://" + this.endpoint, null, { rejectUnauthorized: false });
var vWS = self.vWS = new WebSocket("wss://" + _this4.endpoint, null, { rejectUnauthorized: false });
var udpClient = self.udp = udp.createSocket("udp4");
var firstPacket = true;
@@ -257,7 +300,7 @@ class VoiceConnection extends EventEmitter {
}
});
vWS.on("open", () => {
vWS.on("open", function () {
vWS.send(JSON.stringify({
op: 0,
d: {
@@ -271,13 +314,13 @@ class VoiceConnection extends EventEmitter {
var KAI;
vWS.on("message", msg => {
vWS.on("message", function (msg) {
var data = JSON.parse(msg);
switch (data.op) {
case 2:
self.vWSData = data.d;
KAI = setInterval(() => {
KAI = setInterval(function () {
if (vWS && vWS.readyState === WebSocket.OPEN) vWS.send(JSON.stringify({
op: 3,
d: null
@@ -287,7 +330,7 @@ class VoiceConnection extends EventEmitter {
var udpPacket = new Buffer(70);
udpPacket.writeUIntBE(data.d.ssrc, 0, 4);
udpClient.send(udpPacket, 0, udpPacket.length, data.d.port, self.endpoint, err => {
udpClient.send(udpPacket, 0, udpPacket.length, data.d.port, self.endpoint, function (err) {
if (err) self.emit("error", err);
});
break;
@@ -302,6 +345,9 @@ class VoiceConnection extends EventEmitter {
});
});
}
}
}]);
return VoiceConnection;
})(EventEmitter);
module.exports = VoiceConnection;

View File

@@ -1,7 +1,9 @@
"use strict";
class VoicePacket {
constructor(data, sequence, time, ssrc) {
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var VoicePacket = function VoicePacket(data, sequence, time, ssrc) {
_classCallCheck(this, VoicePacket);
var audioBuffer = data,
returnBuffer = new Buffer(audioBuffer.length + 12);
@@ -19,7 +21,6 @@ class VoicePacket {
}
return returnBuffer;
}
}
};
module.exports = VoicePacket;

View File

@@ -1,3 +1,5 @@
"use strict";
module.exports = {
Client: require("./Client/Client"),
Channel: require("./Structures/Channel"),

View File

@@ -125,6 +125,7 @@ class VoiceConnection extends EventEmitter {
self.streamTime = count * length;
setTimeout(send, length + (nextTime - Date.now()));
if (!self.playing)
self.setSpeaking(true);