rebuilt files

This commit is contained in:
Amish Shah
2015-11-22 15:01:42 +00:00
parent cf33df18cf
commit 68b60c5464
27 changed files with 1023 additions and 1746 deletions

File diff suppressed because it is too large Load Diff

View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,7 @@
"use strict"; "use strict"
/* global Buffer */ /* global Buffer */
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");
var User = require("../../Structures/User.js"), var User = require("../../Structures/User.js"),
@@ -16,32 +15,17 @@ var User = require("../../Structures/User.js"),
Invite = require("../../Structures/Invite.js"), Invite = require("../../Structures/Invite.js"),
Games = require("../../../ref/gameMap.js"); Games = require("../../../ref/gameMap.js");
var Resolver = (function () { class Resolver {
function Resolver(internal) { constructor(internal) {
_classCallCheck(this, Resolver);
this.internal = internal; this.internal = internal;
} }
Resolver.prototype.resolveGameID = function resolveGameID(resource) { resolveGameID(resource) {
if (!isNaN(resource) && parseInt(resource) % 1 === 0) { if (!isNaN(resource) && parseInt(resource) % 1 === 0) {
return resource; return resource;
} else if (typeof resource == "string" || resource instanceof String) { } else if (typeof resource == "string" || resource instanceof String) {
for (var _iterator = Games, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { for (var game of Games) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var game = _ref;
if (game.name.toUpperCase() === resource.toUpperCase()) { if (game.name.toUpperCase() === resource.toUpperCase()) {
return game.id; return game.id;
} }
@@ -49,17 +33,17 @@ var Resolver = (function () {
} }
return null; return null;
}; }
Resolver.prototype.resolveToBase64 = function resolveToBase64(resource) { resolveToBase64(resource) {
if (resource instanceof Buffer) { if (resource instanceof Buffer) {
resource = resource.toString("base64"); resource = resource.toString("base64");
resource = "data:image/jpg;base64," + resource; resource = "data:image/jpg;base64," + resource;
} }
return resource; return resource;
}; }
Resolver.prototype.resolveInviteID = function resolveInviteID(resource) { resolveInviteID(resource) {
if (resource instanceof Invite) { if (resource instanceof Invite) {
return resource.id; return resource.id;
} else if (typeof resource == "string" || resource instanceof String) { } else if (typeof resource == "string" || resource instanceof String) {
@@ -72,9 +56,9 @@ var Resolver = (function () {
} }
} }
return null; return null;
}; }
Resolver.prototype.resolveServer = function resolveServer(resource) { resolveServer(resource) {
if (resource instanceof Server) { if (resource instanceof Server) {
return resource; return resource;
} else if (resource instanceof ServerChannel) { } else if (resource instanceof ServerChannel) {
@@ -87,39 +71,26 @@ var Resolver = (function () {
} }
} }
return null; return null;
}; }
Resolver.prototype.resolveFile = function resolveFile(resource) { resolveFile(resource) {
if (typeof resource === "string" || resource instanceof String) { if (typeof resource === "string" || resource instanceof String) {
return fs.createReadStream(resource); return fs.createReadStream(resource);
} else { } else {
return resource; return resource;
} }
}; }
Resolver.prototype.resolveMentions = function resolveMentions(resource) { resolveMentions(resource) {
// resource is a string // resource is a string
var _mentions = []; var _mentions = [];
for (var _iterator2 = resource.match(/<@[^>]*>/g) || [], _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { for (var mention of resource.match(/<@[^>]*>/g) || []) {
var _ref2;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref2 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref2 = _i2.value;
}
var mention = _ref2;
_mentions.push(mention.substring(2, mention.length - 1)); _mentions.push(mention.substring(2, mention.length - 1));
} }
return _mentions; return _mentions;
}; }
Resolver.prototype.resolveString = function resolveString(resource) { resolveString(resource) {
// accepts Array, Channel, Server, User, Message, String and anything // accepts Array, Channel, Server, User, Message, String and anything
// toString()-able // toString()-able
@@ -130,9 +101,9 @@ var Resolver = (function () {
} }
return final.toString(); return final.toString();
}; }
Resolver.prototype.resolveUser = function resolveUser(resource) { resolveUser(resource) {
/* /*
accepts a Message, Channel, Server, String ID, User, PMChannel accepts a Message, Channel, Server, String ID, User, PMChannel
*/ */
@@ -155,9 +126,9 @@ var Resolver = (function () {
} }
return found; return found;
}; }
Resolver.prototype.resolveMessage = function resolveMessage(resource) { resolveMessage(resource) {
// accepts a Message, PMChannel & TextChannel // accepts a Message, PMChannel & TextChannel
var found = null; var found = null;
@@ -168,23 +139,23 @@ var Resolver = (function () {
} }
return found; return found;
}; }
Resolver.prototype.resolveVoiceChannel = function resolveVoiceChannel(resource) { resolveVoiceChannel(resource) {
// resolveChannel will also work but this is more apt // resolveChannel will also work but this is more apt
if (resource instanceof VoiceChannel) { if (resource instanceof VoiceChannel) {
return resource; return resource;
} }
return null; return null;
}; }
Resolver.prototype.resolveChannel = function resolveChannel(resource) { resolveChannel(resource) {
/* /*
accepts a Message, Channel, Server, String ID, User accepts a Message, Channel, Server, String ID, User
*/ */
var self = this; var self = this;
return new Promise(function (resolve, reject) { return new Promise((resolve, reject) => {
var found = null; var found = null;
if (resource instanceof Message) { if (resource instanceof Message) {
found = resource.channel; found = resource.channel;
@@ -197,20 +168,7 @@ var Resolver = (function () {
} else if (resource instanceof User) { } else if (resource instanceof User) {
// see if a PM exists // see if a PM exists
var chatFound = false; var chatFound = false;
for (var _iterator3 = self.internal.private_channels, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { for (var pmchat of self.internal.private_channels) {
var _ref3;
if (_isArray3) {
if (_i3 >= _iterator3.length) break;
_ref3 = _iterator3[_i3++];
} else {
_i3 = _iterator3.next();
if (_i3.done) break;
_ref3 = _i3.value;
}
var pmchat = _ref3;
if (pmchat.recipient.equals(resource)) { if (pmchat.recipient.equals(resource)) {
chatFound = pmchat; chatFound = pmchat;
break; break;
@@ -221,19 +179,12 @@ var Resolver = (function () {
found = chatFound; found = chatFound;
} else { } else {
// PM does not exist :\ // PM does not exist :\
self.internal.startPM(resource).then(function (pmchannel) { self.internal.startPM(resource).then(pmchannel => resolve(pmchannel)).catch(e => reject(e));
return resolve(pmchannel);
})["catch"](function (e) {
return reject(e);
});
return; return;
} }
} }
if (found) resolve(found);else reject(new Error("Didn't found anything")); if (found) resolve(found);else reject(new Error("Didn't found anything"));
}); });
}; }
}
return Resolver;
})();
module.exports = Resolver; module.exports = Resolver;

View File

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

View File

@@ -1,39 +1,26 @@
"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 _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");
var Cache = require("../Util/Cache.js"); var Cache = require("../Util/Cache.js");
var PermissionOverwrite = require("./PermissionOverwrite.js"); var PermissionOverwrite = require("./PermissionOverwrite.js");
var reg = require("../Util/ArgumentRegulariser.js").reg; var reg = require("../Util/ArgumentRegulariser.js").reg;
var Channel = (function (_Equality) { class Channel extends Equality {
_inherits(Channel, _Equality);
function Channel(data, client) { constructor(data, client) {
_classCallCheck(this, Channel); super();
_Equality.call(this);
this.id = data.id; this.id = data.id;
this.client = client; this.client = client;
} }
Channel.prototype["delete"] = function _delete() { get isPrivate() {
return !!this.server;
}
delete() {
return this.client.deleteChannel.apply(this.client, reg(this, arguments)); return this.client.deleteChannel.apply(this.client, reg(this, arguments));
}; }
_createClass(Channel, [{ }
key: "isPrivate",
get: function get() {
return !!this.server;
}
}]);
return Channel;
})(Equality);
module.exports = Channel; module.exports = Channel;

View File

@@ -1,22 +1,15 @@
"use strict"; "use strict";
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;
var ChannelPermissions = (function () { class ChannelPermissions {
function ChannelPermissions(permissions) { constructor(permissions) {
_classCallCheck(this, ChannelPermissions);
this.permissions = permissions; this.permissions = permissions;
} }
ChannelPermissions.prototype.serialise = function serialise(explicit) { serialise(explicit) {
var _this = this;
var hp = function hp(perm) { var hp = perm => this.hasPermission(perm, explicit);
return _this.hasPermission(perm, explicit);
};
return { return {
// general // general
@@ -43,16 +36,14 @@ var ChannelPermissions = (function () {
voiceMoveMembers: hp(Permissions.voiceMoveMembers), voiceMoveMembers: hp(Permissions.voiceMoveMembers),
voiceUseVAD: hp(Permissions.voiceUseVAD) voiceUseVAD: hp(Permissions.voiceUseVAD)
}; };
}; }
ChannelPermissions.prototype.serialize = function serialize() { serialize() {
// ;n; // ;n;
return this.serialise(); return this.serialise();
}; }
ChannelPermissions.prototype.hasPermission = 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") { if (perm instanceof String || typeof perm === "string") {
perm = Permissions[perm]; perm = Permissions[perm];
} }
@@ -67,9 +58,7 @@ var ChannelPermissions = (function () {
} }
} }
return !!(this.permissions & perm); return !!(this.permissions & perm);
}; }
}
return ChannelPermissions;
})();
module.exports = ChannelPermissions; module.exports = ChannelPermissions;

View File

@@ -1,32 +1,26 @@
"use strict"; "use strict";
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");
var ServerChannel = require("./ServerChannel.js"); var ServerChannel = require("./ServerChannel.js");
var Invite = (function () { class Invite {
function Invite(data, chan, client) { constructor(data, chan, client) {
_classCallCheck(this, Invite); this.maxAge = data.max_age;
this.code = data.code;
this.server = chan.server;
this.channel = chan;
this.revoked = data.revoked;
this.createdAt = Date.parse(data.created_at);
this.temporary = data.temporary;
this.uses = data.uses;
this.maxUses = data.uses;
this.inviter = client.internal.users.get("id", data.inviter.id);
this.xkcd = data.xkcdpass;
}
this.maxAge = data.max_age; toString() {
this.code = data.code; return `https://discord.gg/${ this.code }`;
this.server = chan.server; }
this.channel = chan; }
this.revoked = data.revoked;
this.createdAt = Date.parse(data.created_at);
this.temporary = data.temporary;
this.uses = data.uses;
this.maxUses = data.uses;
this.inviter = client.internal.users.get("id", data.inviter.id);
this.xkcd = data.xkcdpass;
}
Invite.prototype.toString = function toString() {
return "https://discord.gg/" + this.code;
};
return Invite;
})();
module.exports = Invite; module.exports = Invite;

View File

@@ -1,25 +1,13 @@
"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 _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");
var User = require("./User.js"); var User = require("./User.js");
var reg = require("../Util/ArgumentRegulariser.js").reg; var reg = require("../Util/ArgumentRegulariser.js").reg;
var Equality = require("../Util/Equality"); var Equality = require("../Util/Equality");
var Message = (function (_Equality) { class Message extends Equality {
_inherits(Message, _Equality); constructor(data, channel, client) {
super();
function Message(data, channel, client) {
var _this = this;
_classCallCheck(this, Message);
_Equality.call(this);
this.channel = channel; this.channel = channel;
this.client = client; this.client = client;
this.nonce = data.nonce; this.nonce = data.nonce;
@@ -37,51 +25,46 @@ var Message = (function (_Equality) {
this.content = data.content; this.content = data.content;
this.mentions = new Cache(); this.mentions = new Cache();
data.mentions.forEach(function (mention) { data.mentions.forEach(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
// users from messages from logs who may have left the server and were // users from messages from logs who may have left the server and were
// 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)));
}); });
} }
Message.prototype.isMentioned = function isMentioned(user) { isMentioned(user) {
user = this.client.internal.resolver.resolveUser(user); user = this.client.internal.resolver.resolveUser(user);
if (user) { if (user) {
return this.mentions.has("id", user.id); return this.mentions.has("id", user.id);
} else { } else {
return false; return false;
} }
}; }
Message.prototype.toString = function toString() { toString() {
return this.content; return this.content;
}; }
Message.prototype["delete"] = function _delete() { delete() {
return this.client.deleteMessage.apply(this.client, reg(this, arguments)); return this.client.deleteMessage.apply(this.client, reg(this, arguments));
}; }
Message.prototype.update = function update() { update() {
return this.client.updateMessage.apply(this.client, reg(this, arguments)); return this.client.updateMessage.apply(this.client, reg(this, arguments));
}; }
Message.prototype.reply = function reply() { reply() {
return this.client.reply.apply(this.client, reg(this, arguments)); return this.client.reply.apply(this.client, reg(this, arguments));
}; }
Message.prototype.replyTTS = function replyTTS() { replyTTS() {
return this.client.replyTTS.apply(this.client, reg(this, arguments)); return this.client.replyTTS.apply(this.client, reg(this, arguments));
}; }
_createClass(Message, [{ get sender() {
key: "sender", return this.author;
get: function get() { }
return this.author; }
}
}]);
return Message;
})(Equality);
module.exports = Message; module.exports = Message;

View File

@@ -1,24 +1,14 @@
"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 _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");
var User = require("./User.js"); var User = require("./User.js");
var Equality = require("../Util/Equality.js"); var Equality = require("../Util/Equality.js");
var Cache = require("../Util/Cache.js"); var Cache = require("../Util/Cache.js");
var reg = require("../Util/ArgumentRegulariser.js").reg; var reg = require("../Util/ArgumentRegulariser.js").reg;
var PMChannel = (function (_Channel) { class PMChannel extends Channel {
_inherits(PMChannel, _Channel); constructor(data, client) {
super(data, client);
function PMChannel(data, client) {
_classCallCheck(this, PMChannel);
_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;
@@ -27,27 +17,21 @@ var PMChannel = (function (_Channel) {
} }
/* warning! may return null */ /* warning! may return null */
get lastMessage() {
return this.messages.get("id", this.lastMessageID);
}
PMChannel.prototype.toString = function toString() { toString() {
return this.recipient.toString(); return this.recipient.toString();
}; }
PMChannel.prototype.sendMessage = function sendMessage() { sendMessage() {
return this.client.sendMessage.apply(this.client, reg(this, arguments)); return this.client.sendMessage.apply(this.client, reg(this, arguments));
}; }
PMChannel.prototype.sendTTSMessage = function sendTTSMessage() { sendTTSMessage() {
return this.client.sendTTSMessage.apply(this.client, reg(this, arguments)); return this.client.sendTTSMessage.apply(this.client, reg(this, arguments));
}; }
}
_createClass(PMChannel, [{
key: "lastMessage",
get: function get() {
return this.messages.get("id", this.lastMessageID);
}
}]);
return PMChannel;
})(Channel);
module.exports = PMChannel; module.exports = PMChannel;

View File

@@ -1,15 +1,10 @@
"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"); } }
var Permissions = require("../Constants.js").Permissions; var Permissions = require("../Constants.js").Permissions;
var PermissionOverwrite = (function () { class PermissionOverwrite {
function PermissionOverwrite(data) {
_classCallCheck(this, PermissionOverwrite);
constructor(data) {
this.id = data.id; this.id = data.id;
this.type = data.type; // member or role this.type = data.type; // member or role
this.deny = data.deny; this.deny = data.deny;
@@ -17,70 +12,59 @@ var PermissionOverwrite = (function () {
} }
// returns an array of allowed permissions // returns an array of allowed permissions
get allowed() {
var allowed = [];
for (var permName in Permissions) {
if (permName === "manageRoles" || permName === "manageChannels") {
// these permissions do not exist in overwrites.
continue;
}
PermissionOverwrite.prototype.setAllowed = function setAllowed(allowedArray) { if (!!(this.allow & Permissions[permName])) {
var _this = this; allowed.push(permName);
}
}
return allowed;
}
allowedArray.forEach(function (permission) { // returns an array of denied permissions
get denied() {
var denied = [];
for (var permName in Permissions) {
if (permName === "manageRoles" || permName === "manageChannels") {
// these permissions do not exist in overwrites.
continue;
}
if (!!(this.deny & Permissions[permName])) {
denied.push(permName);
}
}
return denied;
}
setAllowed(allowedArray) {
allowedArray.forEach(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) {
_this.allow |= 1 << permission; this.allow |= 1 << permission;
} }
}); });
}; }
PermissionOverwrite.prototype.setDenied = function setDenied(deniedArray) { setDenied(deniedArray) {
var _this2 = this; deniedArray.forEach(permission => {
deniedArray.forEach(function (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) {
_this2.deny |= 1 << permission; this.deny |= 1 << permission;
} }
}); });
}; }
_createClass(PermissionOverwrite, [{ }
key: "allowed",
get: function get() {
var allowed = [];
for (var permName in Permissions) {
if (permName === "manageRoles" || permName === "manageChannels") {
// these permissions do not exist in overwrites.
continue;
}
if (!!(this.allow & Permissions[permName])) {
allowed.push(permName);
}
}
return allowed;
}
// returns an array of denied permissions
}, {
key: "denied",
get: function get() {
var denied = [];
for (var permName in Permissions) {
if (permName === "manageRoles" || permName === "manageChannels") {
// these permissions do not exist in overwrites.
continue;
}
if (!!(this.deny & Permissions[permName])) {
denied.push(permName);
}
}
return denied;
}
}]);
return PermissionOverwrite;
})();
module.exports = PermissionOverwrite; module.exports = PermissionOverwrite;

View File

@@ -1,7 +1,5 @@
"use strict"; "use strict";
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;
/* /*
@@ -16,14 +14,10 @@ example data
color: 0 } color: 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) { 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);
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.position = data.position || -1;
this.permissions = data.permissions || (data.name === "@everyone" ? DefaultRole : 0); this.permissions = data.permissions || (data.name === "@everyone" ? DefaultRole : 0);
this.name = data.name || "@everyone"; this.name = data.name || "@everyone";
@@ -35,12 +29,9 @@ var Role = (function () {
this.client = client; this.client = client;
} }
Role.prototype.serialise = function serialise(explicit) { serialise(explicit) {
var _this = this;
var hp = function hp(perm) { var hp = perm => this.hasPermission(perm, explicit);
return _this.hasPermission(perm, explicit);
};
return { return {
// general // general
@@ -67,16 +58,14 @@ var Role = (function () {
voiceMoveMembers: hp(Permissions.voiceMoveMembers), voiceMoveMembers: hp(Permissions.voiceMoveMembers),
voiceUseVAD: hp(Permissions.voiceUseVAD) voiceUseVAD: hp(Permissions.voiceUseVAD)
}; };
}; }
Role.prototype.serialize = function serialize() { serialize() {
// ;n; // ;n;
return this.serialise(); return this.serialise();
}; }
Role.prototype.hasPermission = 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") { if (perm instanceof String || typeof perm === "string") {
perm = Permissions[perm]; perm = Permissions[perm];
} }
@@ -95,9 +84,9 @@ var Role = (function () {
// !!(36953089 & (1 << 21)) = voice speak allowed // !!(36953089 & (1 << 21)) = voice speak allowed
return !!(this.permissions & perm); return !!(this.permissions & perm);
}; }
Role.prototype.setPermission = function setPermission(permission, value) { setPermission(permission, value) {
if (permission instanceof String || typeof permission === "string") { if (permission instanceof String || typeof permission === "string") {
permission = Permissions[permission]; permission = Permissions[permission];
} }
@@ -109,31 +98,27 @@ var Role = (function () {
this.permissions &= ~permission; this.permissions &= ~permission;
} }
} }
}; }
Role.prototype.setPermissions = function setPermissions(obj) { setPermissions(obj) {
var _this2 = this; obj.forEach((value, permission) => {
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
_this2.setPermission(permission, value); this.setPermission(permission, value);
} }
}); });
}; }
Role.prototype.colorAsHex = function colorAsHex() { colorAsHex() {
var val = this.color.toString(); var val = this.color.toString();
while (val.length < 6) { while (val.length < 6) {
val = "0" + val; val = "0" + val;
} }
return "#" + val; return "#" + val;
}; }
}
return Role;
})();
module.exports = Role; module.exports = Role;

View File

@@ -1,11 +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 _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");
var Endpoints = require("../Constants.js").Endpoints; var Endpoints = require("../Constants.js").Endpoints;
var Cache = require("../Util/Cache.js"); var Cache = require("../Util/Cache.js");
@@ -16,15 +10,10 @@ var Role = require("./Role.js");
var strictKeys = ["region", "ownerID", "name", "id", "icon", "afkTimeout", "afkChannelID"]; var strictKeys = ["region", "ownerID", "name", "id", "icon", "afkTimeout", "afkChannelID"];
var Server = (function (_Equality) { class Server extends Equality {
_inherits(Server, _Equality); constructor(data, client) {
function Server(data, client) { super();
var _this = this;
_classCallCheck(this, Server);
_Equality.call(this);
var self = this; var self = this;
this.client = client; this.client = client;
@@ -43,48 +32,33 @@ var Server = (function (_Equality) {
var self = this; var self = this;
data.roles.forEach(function (dataRole) { data.roles.forEach(dataRole => {
_this.roles.add(new Role(dataRole, _this, client)); this.roles.add(new Role(dataRole, this, client));
}); });
data.members.forEach(function (dataUser) { data.members.forEach(dataUser => {
_this.memberMap[dataUser.user.id] = { this.memberMap[dataUser.user.id] = {
roles: dataUser.roles.map(function (pid) { roles: dataUser.roles.map(pid => self.roles.get("id", pid)),
return self.roles.get("id", pid);
}),
mute: dataUser.mute, mute: dataUser.mute,
deaf: dataUser.deaf, deaf: dataUser.deaf,
joinedAt: Date.parse(dataUser.joined_at) joinedAt: Date.parse(dataUser.joined_at)
}; };
var user = client.internal.users.add(new User(dataUser.user, client)); var user = client.internal.users.add(new User(dataUser.user, client));
_this.members.add(user); this.members.add(user);
}); });
data.channels.forEach(function (dataChannel) { data.channels.forEach(dataChannel => {
if (dataChannel.type === "text") { if (dataChannel.type === "text") {
var channel = client.internal.channels.add(new TextChannel(dataChannel, client, _this)); var channel = client.internal.channels.add(new TextChannel(dataChannel, client, this));
_this.channels.add(channel); this.channels.add(channel);
} else { } else {
var channel = client.internal.channels.add(new VoiceChannel(dataChannel, client, _this)); var channel = client.internal.channels.add(new VoiceChannel(dataChannel, client, this));
_this.channels.add(channel); this.channels.add(channel);
} }
}); });
if (data.presences) { if (data.presences) {
for (var _iterator = data.presences, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { for (var presence of data.presences) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var presence = _ref;
var user = client.internal.users.get("id", presence.user.id); var user = client.internal.users.get("id", presence.user.id);
if (user) { if (user) {
user.status = presence.status; user.status = presence.status;
@@ -94,39 +68,46 @@ var Server = (function (_Equality) {
} }
} }
Server.prototype.rolesOfUser = function rolesOfUser(user) { rolesOfUser(user) {
user = this.client.internal.resolver.resolveUser(user); user = this.client.internal.resolver.resolveUser(user);
if (user) { if (user) {
return this.memberMap[user.id] ? this.memberMap[user.id].roles : []; return this.memberMap[user.id] ? this.memberMap[user.id].roles : [];
} else { } else {
return null; return null;
} }
}; }
Server.prototype.rolesOf = function rolesOf(user) { rolesOf(user) {
return this.rolesOfUser(user); return this.rolesOfUser(user);
}; }
Server.prototype.toString = function toString() { get iconURL() {
if (!this.icon) {
return null;
} else {
return Endpoints.SERVER_ICON(this.id, this.icon);
}
}
get afkChannel() {
return this.channels.get("id", this.afkChannelID);
}
get defaultChannel() {
return this.channels.get("id", this.id);
}
get owner() {
return this.members.get("id", this.ownerID);
}
toString() {
return this.name; return this.name;
}; }
Server.prototype.equalsStrict = function equalsStrict(obj) { equalsStrict(obj) {
if (obj instanceof Server) { if (obj instanceof Server) {
for (var _iterator2 = strictKeys, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { for (var key of strictKeys) {
var _ref2;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref2 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref2 = _i2.value;
}
var key = _ref2;
if (obj[key] !== this[key]) { if (obj[key] !== this[key]) {
return false; return false;
} }
@@ -135,35 +116,8 @@ var Server = (function (_Equality) {
return false; return false;
} }
return true; return true;
}; }
_createClass(Server, [{ }
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; module.exports = Server;

View File

@@ -1,35 +1,25 @@
"use strict"; "use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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");
var Cache = require("../Util/Cache.js"); var Cache = require("../Util/Cache.js");
var PermissionOverwrite = require("./PermissionOverwrite.js"); var PermissionOverwrite = require("./PermissionOverwrite.js");
var ChannelPermissions = require("./ChannelPermissions.js"); var ChannelPermissions = require("./ChannelPermissions.js");
var reg = require("../Util/ArgumentRegulariser.js").reg; var reg = require("../Util/ArgumentRegulariser.js").reg;
var ServerChannel = (function (_Channel) { class ServerChannel extends Channel {
_inherits(ServerChannel, _Channel); constructor(data, client, server) {
super(data, client);
function ServerChannel(data, client, server) {
var _this = this;
_classCallCheck(this, ServerChannel);
_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(permission => {
_this.permissionOverwrites.add(new PermissionOverwrite(permission)); this.permissionOverwrites.add(new PermissionOverwrite(permission));
}); });
} }
ServerChannel.prototype.permissionsOf = function permissionsOf(user) { permissionsOf(user) {
user = this.client.internal.resolver.resolveUser(user); user = this.client.internal.resolver.resolveUser(user);
if (user) { if (user) {
if (this.server.owner.equals(user)) { if (this.server.owner.equals(user)) {
@@ -38,13 +28,11 @@ var ServerChannel = (function (_Channel) {
var everyoneRole = this.server.roles.get("name", "@everyone"); var everyoneRole = this.server.roles.get("name", "@everyone");
var userRoles = [everyoneRole].concat(this.server.rolesOf(user) || []); var userRoles = [everyoneRole].concat(this.server.rolesOf(user) || []);
var userRolesID = userRoles.map(function (v) { var userRolesID = userRoles.map(v => v.id);
return v.id;
});
var roleOverwrites = [], var roleOverwrites = [],
memberOverwrites = []; memberOverwrites = [];
this.permissionOverwrites.forEach(function (overwrite) { this.permissionOverwrites.forEach(overwrite => {
if (overwrite.type === "member" && overwrite.id === user.id) { if (overwrite.type === "member" && overwrite.id === user.id) {
memberOverwrites.push(overwrite); memberOverwrites.push(overwrite);
} else if (overwrite.type === "role" && overwrite.id in userRolesID) { } else if (overwrite.type === "role" && overwrite.id in userRolesID) {
@@ -54,37 +42,11 @@ var ServerChannel = (function (_Channel) {
var permissions = 0; var permissions = 0;
for (var _iterator = userRoles, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { for (var serverRole of userRoles) {
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; permissions |= serverRole.permissions;
} }
for (var _iterator2 = roleOverwrites.concat(memberOverwrites), _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { for (var overwrite of roleOverwrites.concat(memberOverwrites)) {
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.deny;
permissions = permissions | overwrite.allow; permissions = permissions | overwrite.allow;
} }
@@ -93,25 +55,23 @@ var ServerChannel = (function (_Channel) {
} else { } else {
return null; return null;
} }
}; }
ServerChannel.prototype.permsOf = function permsOf(user) { permsOf(user) {
return this.permissionsOf(user); return this.permissionsOf(user);
}; }
ServerChannel.prototype.mention = function mention() { mention() {
return "<#" + this.id + ">"; return `<#${ this.id }>`;
}; }
ServerChannel.prototype.toString = function toString() { toString() {
return this.mention(); return this.mention();
}; }
ServerChannel.prototype.setName = function setName() { setName() {
return this.client.setChannelName.apply(this.client, reg(this, arguments)); return this.client.setChannelName.apply(this.client, reg(this, arguments));
}; }
}
return ServerChannel;
})(Channel);
module.exports = ServerChannel; module.exports = ServerChannel;

View File

@@ -1,22 +1,12 @@
"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 _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");
var Cache = require("../Util/Cache.js"); var Cache = require("../Util/Cache.js");
var reg = require("../Util/ArgumentRegulariser.js").reg; var reg = require("../Util/ArgumentRegulariser.js").reg;
var TextChannel = (function (_ServerChannel) { class TextChannel extends ServerChannel {
_inherits(TextChannel, _ServerChannel); constructor(data, client, server) {
super(data, client, server);
function TextChannel(data, client, server) {
_classCallCheck(this, TextChannel);
_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;
@@ -24,35 +14,29 @@ var TextChannel = (function (_ServerChannel) {
} }
/* warning! may return null */ /* warning! may return null */
get lastMessage() {
return this.messages.get("id", this.lastMessageID);
}
TextChannel.prototype.setTopic = function setTopic() { setTopic() {
return this.client.setTopic.apply(this.client, reg(this, arguments)); return this.client.setTopic.apply(this.client, reg(this, arguments));
}; }
TextChannel.prototype.setNameAndTopic = function setNameAndTopic() { setNameAndTopic() {
return this.client.setChannelNameAndTopic.apply(this.client, reg(this, arguments)); return this.client.setChannelNameAndTopic.apply(this.client, reg(this, arguments));
}; }
TextChannel.prototype.update = function update() { update() {
return this.client.updateChannel.apply(this.client, reg(this, arguments)); return this.client.updateChannel.apply(this.client, reg(this, arguments));
}; }
TextChannel.prototype.sendMessage = function sendMessage() { sendMessage() {
return this.client.sendMessage.apply(this.client, reg(this, arguments)); return this.client.sendMessage.apply(this.client, reg(this, arguments));
}; }
TextChannel.prototype.sendTTSMessage = function sendTTSMessage() { sendTTSMessage() {
return this.client.sendTTSMessage.apply(this.client, reg(this, arguments)); return this.client.sendTTSMessage.apply(this.client, reg(this, arguments));
}; }
}
_createClass(TextChannel, [{
key: "lastMessage",
get: function get() {
return this.messages.get("id", this.lastMessageID);
}
}]);
return TextChannel;
})(ServerChannel);
module.exports = TextChannel; module.exports = TextChannel;

View File

@@ -1,21 +1,11 @@
"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 _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");
var Endpoints = require("../Constants.js").Endpoints; var Endpoints = require("../Constants.js").Endpoints;
var User = (function (_Equality) { class User extends Equality {
_inherits(User, _Equality); constructor(data, client) {
super();
function User(data, client) {
_classCallCheck(this, User);
_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;
@@ -29,30 +19,25 @@ var User = (function (_Equality) {
}; };
} }
User.prototype.mention = function mention() { get avatarURL() {
return "<@" + this.id + ">"; if (!this.avatar) {
}; return null;
} else {
User.prototype.toString = function toString() { return Endpoints.AVATAR(this.id, this.avatar);
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, [{
key: "avatarURL",
get: function get() {
if (!this.avatar) {
return null;
} else {
return Endpoints.AVATAR(this.id, this.avatar);
}
} }
}]); }
return User; mention() {
})(Equality); 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;
}
}
module.exports = User; module.exports = User;

View File

@@ -1,21 +1,11 @@
"use strict"; "use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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");
var VoiceChannel = (function (_ServerChannel) { class VoiceChannel extends ServerChannel {
_inherits(VoiceChannel, _ServerChannel); constructor(data, client, server) {
super(data, client, server);
function VoiceChannel(data, client, server) {
_classCallCheck(this, VoiceChannel);
_ServerChannel.call(this, data, client, server);
} }
}
return VoiceChannel;
})(ServerChannel);
module.exports = VoiceChannel; module.exports = VoiceChannel;

View File

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

View File

@@ -1,61 +1,40 @@
"use strict"; "use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } class Cache extends Array {
constructor(discrim, limit) {
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; } super();
var Cache = (function (_Array) {
_inherits(Cache, _Array);
function Cache(discrim, limit) {
_classCallCheck(this, Cache);
_Array.call(this);
this.discrim = discrim || "id"; this.discrim = discrim || "id";
} }
Cache.prototype.get = function get(key, value) { get(key, value) {
var found = null; var found = null;
this.forEach(function (val, index, array) { this.forEach((val, index, array) => {
if (val.hasOwnProperty(key) && val[key] == value) { if (val.hasOwnProperty(key) && val[key] == value) {
found = val; found = val;
return; return;
} }
}); });
return found; return found;
}; }
Cache.prototype.has = function has(key, value) { has(key, value) {
return !!this.get(key, value); return !!this.get(key, value);
}; }
Cache.prototype.getAll = function getAll(key, value) { getAll(key, value) {
var found = new Cache(this.discrim); var found = new Cache(this.discrim);
this.forEach(function (val, index, array) { this.forEach((val, index, array) => {
if (val.hasOwnProperty(key) && val[key] == value) { if (val.hasOwnProperty(key) && val[key] == value) {
found.push(val); found.push(val);
return; return;
} }
}); });
return found; return found;
}; }
Cache.prototype.add = function add(data) { add(data) {
var exit = false; var exit = false;
for (var _iterator = this, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { for (var item of this) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var item = _ref;
if (item[this.discrim] === data[this.discrim]) { if (item[this.discrim] === data[this.discrim]) {
exit = item; exit = item;
break; break;
@@ -70,9 +49,9 @@ var Cache = (function (_Array) {
this.push(data); this.push(data);
return data; return data;
} }
}; }
Cache.prototype.update = function update(old, data) { update(old, data) {
var item = this.get(this.discrim, old[this.discrim]); var item = this.get(this.discrim, old[this.discrim]);
if (item) { if (item) {
var index = this.indexOf(item); var index = this.indexOf(item);
@@ -81,13 +60,13 @@ var Cache = (function (_Array) {
} else { } else {
return false; return false;
} }
}; }
Cache.prototype.random = function random() { random() {
return this[Math.floor(Math.random() * this.length)]; return this[Math.floor(Math.random() * this.length)];
}; }
Cache.prototype.remove = function remove(data) { remove(data) {
var index = this.indexOf(data); var index = this.indexOf(data);
if (~index) { if (~index) {
this.splice(index, 1); this.splice(index, 1);
@@ -98,9 +77,7 @@ var Cache = (function (_Array) {
} }
} }
return false; return false;
}; }
}
return Cache;
})(Array);
module.exports = Cache; module.exports = Cache;

View File

@@ -9,37 +9,24 @@
Instead, use objectThatExtendsEquality.equals() Instead, use objectThatExtendsEquality.equals()
*/ */
"use strict"; class Equality {
constructor() {}
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; }; })(); get eqDiscriminator() {
return "id";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Equality = (function () {
function Equality() {
_classCallCheck(this, Equality);
} }
Equality.prototype.equals = function equals(object) { equals(object) {
if (object && object[this.eqDiscriminator] == this[this.eqDiscriminator]) { if (object && object[this.eqDiscriminator] == this[this.eqDiscriminator]) {
return true; return true;
} }
return false; return false;
}; }
Equality.prototype.equalsStrict = function equalsStrict(object) { equalsStrict(object) {
// override per class type // override per class type
return; return;
}; }
}
_createClass(Equality, [{
key: "eqDiscriminator",
get: function get() {
return "id";
}
}]);
return Equality;
})();
module.exports = Equality; module.exports = Equality;

View File

@@ -1,7 +1,5 @@
"use strict"; "use strict";
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");
var opus; var opus;
@@ -12,41 +10,26 @@ try {
} }
var VoicePacket = require("./VoicePacket.js"); var VoicePacket = require("./VoicePacket.js");
var AudioEncoder = (function () { class AudioEncoder {
function AudioEncoder() { constructor() {
_classCallCheck(this, AudioEncoder);
if (opus) { if (opus) {
this.opus = new opus.OpusEncoder(48000, 1); this.opus = new opus.OpusEncoder(48000, 1);
} }
this.choice = false; this.choice = false;
} }
AudioEncoder.prototype.opusBuffer = function opusBuffer(buffer) { opusBuffer(buffer) {
return this.opus.encode(buffer, 1920); return this.opus.encode(buffer, 1920);
}; }
AudioEncoder.prototype.getCommand = function getCommand(force) { getCommand(force) {
if (this.choice && force) return choice; if (this.choice && force) return choice;
var choices = ["avconv", "ffmpeg"]; var choices = ["avconv", "ffmpeg"];
for (var _iterator = choices, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { for (var choice of choices) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var choice = _ref;
var p = cpoc.spawnSync(choice); var p = cpoc.spawnSync(choice);
if (!p.error) { if (!p.error) {
this.choice = choice; this.choice = choice;
@@ -55,13 +38,11 @@ var AudioEncoder = (function () {
} }
return "help"; return "help";
}; }
AudioEncoder.prototype.encodeStream = 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; var self = this;
return new Promise(function (resolve, reject) { return new Promise((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. 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", "-"]); "-af", "volume=1", "pipe:1", "-i", "-"]);
@@ -90,13 +71,11 @@ var AudioEncoder = (function () {
reject("close"); reject("close");
}); });
}); });
}; }
AudioEncoder.prototype.encodeFile = 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; var self = this;
return new Promise(function (resolve, reject) { return new Promise((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. 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]); "-af", "volume=1", "pipe:1", "-i", file]);
@@ -121,9 +100,7 @@ var AudioEncoder = (function () {
reject("close"); reject("close");
}); });
}); });
}; }
}
return AudioEncoder;
})();
module.exports = AudioEncoder; module.exports = AudioEncoder;

View File

@@ -1,22 +1,12 @@
"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 _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");
var StreamIntent = (function (_EventEmitter) { class StreamIntent extends EventEmitter {
_inherits(StreamIntent, _EventEmitter); constructor() {
super();
function StreamIntent() {
_classCallCheck(this, StreamIntent);
_EventEmitter.call(this);
} }
}
return StreamIntent;
})(EventEmitter);
module.exports = StreamIntent; module.exports = StreamIntent;

View File

@@ -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,10 +7,7 @@
been possible! been possible!
*/ */
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } ;
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");
var dns = require("dns"); var dns = require("dns");
var udp = require("dgram"); var udp = require("dgram");
@@ -20,13 +17,9 @@ var VoicePacket = require("./VoicePacket.js");
var StreamIntent = require("./StreamIntent.js"); var StreamIntent = require("./StreamIntent.js");
var EventEmitter = require("events"); var EventEmitter = require("events");
var VoiceConnection = (function (_EventEmitter) { class VoiceConnection extends EventEmitter {
_inherits(VoiceConnection, _EventEmitter); constructor(channel, client, session, token, server, endpoint) {
super();
function VoiceConnection(channel, client, session, token, server, endpoint) {
_classCallCheck(this, VoiceConnection);
_EventEmitter.call(this);
this.id = channel.id; this.id = channel.id;
this.voiceChannel = channel; this.voiceChannel = channel;
this.client = client; this.client = client;
@@ -47,7 +40,7 @@ var VoiceConnection = (function (_EventEmitter) {
this.init(); this.init();
} }
VoiceConnection.prototype.destroy = function destroy() { destroy() {
this.stopPlaying(); this.stopPlaying();
if (this.KAI) clearInterval(this.KAI); if (this.KAI) clearInterval(this.KAI);
this.vWS.close(); this.vWS.close();
@@ -61,18 +54,18 @@ var VoiceConnection = (function (_EventEmitter) {
self_deaf: false self_deaf: false
} }
}); });
}; }
VoiceConnection.prototype.stopPlaying = function stopPlaying() { stopPlaying() {
this.playing = false; this.playing = false;
this.playingIntent = null; this.playingIntent = null;
if (this.instream) { if (this.instream) {
this.instream.end(); this.instream.end();
this.instream.destroy(); this.instream.destroy();
} }
}; }
VoiceConnection.prototype.playStream = function playStream(stream) { playStream(stream) {
var self = this; var self = this;
@@ -123,7 +116,7 @@ var VoiceConnection = (function (_EventEmitter) {
sequence + 10 < 65535 ? sequence += 1 : sequence = 0; sequence + 10 < 65535 ? sequence += 1 : sequence = 0;
time + 9600 < 4294967295 ? time += 960 : time = 0; time + 9600 < 4294967295 ? time += 960 : time = 0;
self.sendBuffer(buffer, sequence, time, function (e) {}); self.sendBuffer(buffer, sequence, time, e => {});
var nextTime = startTime + count * length; var nextTime = startTime + count * length;
@@ -141,9 +134,9 @@ var VoiceConnection = (function (_EventEmitter) {
send(); send();
return retStream; return retStream;
}; }
VoiceConnection.prototype.setSpeaking = function setSpeaking(value) { setSpeaking(value) {
this.playing = value; this.playing = value;
if (this.vWS.readyState === WebSocket.OPEN) this.vWS.send(JSON.stringify({ if (this.vWS.readyState === WebSocket.OPEN) this.vWS.send(JSON.stringify({
op: 5, op: 5,
@@ -152,11 +145,9 @@ var VoiceConnection = (function (_EventEmitter) {
delay: 0 delay: 0
} }
})); }));
}; }
VoiceConnection.prototype.sendPacket = function sendPacket(packet) {
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1];
sendPacket(packet, callback = function (err) {}) {
var self = this; var self = this;
self.playing = true; self.playing = true;
try { try {
@@ -166,9 +157,9 @@ var VoiceConnection = (function (_EventEmitter) {
callback(e); callback(e);
return false; return false;
} }
}; }
VoiceConnection.prototype.sendBuffer = function sendBuffer(rawbuffer, sequence, timestamp, callback) { sendBuffer(rawbuffer, sequence, timestamp, callback) {
var self = this; var self = this;
self.playing = true; self.playing = true;
try { try {
@@ -186,68 +177,54 @@ var VoiceConnection = (function (_EventEmitter) {
self.emit("error", e); self.emit("error", e);
return false; return false;
} }
}; }
VoiceConnection.prototype.test = function test() { test() {
this.playFile("C:/users/amish/desktop/audio.mp3").then(function (stream) { this.playFile("C:/users/amish/desktop/audio.mp3").then(stream => {
stream.on("time", function (time) { stream.on("time", time => {
console.log("Time", 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];
playFile(stream, callback = function (err, str) {}) {
var self = this; var self = this;
return new Promise(function (resolve, reject) { return new Promise((resolve, reject) => {
_this.encoder.encodeFile(stream)["catch"](error).then(function (data) { this.encoder.encodeFile(stream).catch(error).then(data => {
self.streamProc = data.proc; self.streamProc = data.proc;
var intent = self.playStream(data.stream); var intent = self.playStream(data.stream);
resolve(intent); resolve(intent);
callback(null, intent); callback(null, intent);
}); });
function error() { function error(e = true) {
var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
reject(e); reject(e);
callback(e); callback(e);
} }
}); });
}; }
VoiceConnection.prototype.playRawStream = function playRawStream(stream) {
var _this2 = this;
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, str) {} : arguments[1];
playRawStream(stream, callback = function (err, str) {}) {
var self = this; var self = this;
return new Promise(function (resolve, reject) { return new Promise((resolve, reject) => {
_this2.encoder.encodeStream(stream)["catch"](error).then(function (data) { this.encoder.encodeStream(stream).catch(error).then(data => {
self.streamProc = data.proc; self.streamProc = data.proc;
self.instream = data.instream; self.instream = data.instream;
var intent = self.playStream(data.stream); var intent = self.playStream(data.stream);
resolve(intent); resolve(intent);
callback(null, intent); callback(null, intent);
}); });
function error() { function error(e = true) {
var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
reject(e); reject(e);
callback(e); callback(e);
} }
}); });
}; }
VoiceConnection.prototype.init = function init() {
var _this3 = this;
init() {
var self = this; var self = this;
dns.lookup(this.endpoint, function (err, address, family) { dns.lookup(this.endpoint, (err, address, family) => {
self.endpoint = address; self.endpoint = address;
var vWS = self.vWS = new WebSocket("wss://" + _this3.endpoint, null, { rejectUnauthorized: false }); var vWS = self.vWS = new WebSocket("wss://" + this.endpoint, null, { rejectUnauthorized: false });
var udpClient = self.udp = udp.createSocket("udp4"); var udpClient = self.udp = udp.createSocket("udp4");
var firstPacket = true; var firstPacket = true;
@@ -280,7 +257,7 @@ var VoiceConnection = (function (_EventEmitter) {
} }
}); });
vWS.on("open", function () { vWS.on("open", () => {
vWS.send(JSON.stringify({ vWS.send(JSON.stringify({
op: 0, op: 0,
d: { d: {
@@ -294,13 +271,13 @@ var VoiceConnection = (function (_EventEmitter) {
var KAI; var KAI;
vWS.on("message", function (msg) { vWS.on("message", msg => {
var data = JSON.parse(msg); var data = JSON.parse(msg);
switch (data.op) { switch (data.op) {
case 2: case 2:
self.vWSData = data.d; self.vWSData = data.d;
KAI = setInterval(function () { KAI = setInterval(() => {
if (vWS && vWS.readyState === WebSocket.OPEN) vWS.send(JSON.stringify({ if (vWS && vWS.readyState === WebSocket.OPEN) vWS.send(JSON.stringify({
op: 3, op: 3,
d: null d: null
@@ -310,7 +287,7 @@ var VoiceConnection = (function (_EventEmitter) {
var udpPacket = new Buffer(70); var udpPacket = new Buffer(70);
udpPacket.writeUIntBE(data.d.ssrc, 0, 4); udpPacket.writeUIntBE(data.d.ssrc, 0, 4);
udpClient.send(udpPacket, 0, udpPacket.length, data.d.port, self.endpoint, function (err) { udpClient.send(udpPacket, 0, udpPacket.length, data.d.port, self.endpoint, err => {
if (err) self.emit("error", err); if (err) self.emit("error", err);
}); });
break; break;
@@ -324,9 +301,7 @@ var VoiceConnection = (function (_EventEmitter) {
} }
}); });
}); });
}; }
}
return VoiceConnection;
})(EventEmitter);
module.exports = VoiceConnection; module.exports = VoiceConnection;

View File

@@ -1,26 +1,25 @@
"use strict"; "use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } class VoicePacket {
constructor(data, sequence, time, ssrc) {
var VoicePacket = function VoicePacket(data, sequence, time, ssrc) { var audioBuffer = data,
_classCallCheck(this, VoicePacket); returnBuffer = new Buffer(audioBuffer.length + 12);
var audioBuffer = data, returnBuffer.fill(0);
returnBuffer = new Buffer(audioBuffer.length + 12); returnBuffer[0] = 0x80;
returnBuffer[1] = 0x78;
returnBuffer.fill(0); returnBuffer.writeUIntBE(sequence, 2, 2);
returnBuffer[0] = 0x80; returnBuffer.writeUIntBE(time, 4, 4);
returnBuffer[1] = 0x78; returnBuffer.writeUIntBE(ssrc, 8, 4);
returnBuffer.writeUIntBE(sequence, 2, 2); for (var i = 0; i < audioBuffer.length; i++) {
returnBuffer.writeUIntBE(time, 4, 4); returnBuffer[i + 12] = audioBuffer[i];
returnBuffer.writeUIntBE(ssrc, 8, 4); }
for (var i = 0; i < audioBuffer.length; i++) { return returnBuffer;
returnBuffer[i + 12] = audioBuffer[i]; }
} }
return returnBuffer;
};
module.exports = VoicePacket; module.exports = VoicePacket;

View File

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