From df744e7d54094be939095b8e53056302f66a9e7c Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Tue, 1 Sep 2015 17:06:12 +0100 Subject: [PATCH 001/151] 3.1.6, fixing login bug Fixed bug where the client attempts to close the websocket if there is an error whilst it is null --- package.json | 2 +- src/Client.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 40a91a8c9..e91f2c257 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.1.5", + "version": "3.1.6", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { diff --git a/src/Client.js b/src/Client.js index 72298886a..d88aab364 100644 --- a/src/Client.js +++ b/src/Client.js @@ -153,7 +153,9 @@ class Client { if (err) { self.state = 4; //set state to disconnected self.trigger("disconnected"); - self.websocket.close(); + if(self.websocket){ + self.websocket.close(); + } callback(err); reject(err); } else { From 705a77ed57aa1740d7813ec6a36a220d1cce42f6 Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Tue, 1 Sep 2015 21:04:18 +0100 Subject: [PATCH 002/151] Fancy logo --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c0a68bdaa..b83cdabae 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ -# discord.js +

+ + discord.js + +

[![Build Status](https://travis-ci.org/hydrabolt/discord.js.svg)](https://travis-ci.org/hydrabolt/discord.js) From f78c1b8a2f936412d4e1aabceb8963abb0d961e3 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Tue, 1 Sep 2015 22:12:23 +0100 Subject: [PATCH 003/151] Added isPrivate field --- src/message.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/message.js b/src/message.js index a979e87dd..3462ce88c 100644 --- a/src/message.js +++ b/src/message.js @@ -1,3 +1,5 @@ +var PMChannel = require("./PMChannel.js"); + class Message{ constructor(data, channel, mentions, author){ this.tts = data.tts; @@ -27,6 +29,10 @@ class Message{ get sender(){ return this.author; } + + get isPrivate(){ + return this.channel.isPrivate; + } } /*exports.Message.prototype.isPM = function() { From aa1db2403053d0e809ad0de6baa74034fe8cbe68 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Tue, 1 Sep 2015 22:13:09 +0100 Subject: [PATCH 004/151] Added isPrivate to channels --- src/PMChannel.js | 4 ++++ src/channel.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/PMChannel.js b/src/PMChannel.js index 6b069d50b..d82cf7932 100644 --- a/src/PMChannel.js +++ b/src/PMChannel.js @@ -20,6 +20,10 @@ class PMChannel { } return null; } + + get isPrivate(){ + return true; + } } module.exports = PMChannel; \ No newline at end of file diff --git a/src/channel.js b/src/channel.js index d32ab580d..0dc0b957a 100644 --- a/src/channel.js +++ b/src/channel.js @@ -36,6 +36,10 @@ class Channel { toString(){ return "#" + this.name; } + + get isPrivate(){ + return false; + } } module.exports = Channel; \ No newline at end of file From 67edc5f5e633762b94206df1803753f83766b025 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Tue, 1 Sep 2015 22:14:58 +0100 Subject: [PATCH 005/151] 3.2.0, major fixes to allow support for checking isPrivate --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e91f2c257..0bbf81be0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.1.6", + "version": "3.2.0", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From 8d6ece0b3526891a217672a0d8b8d01c3b5a470a Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Tue, 1 Sep 2015 22:30:34 +0100 Subject: [PATCH 006/151] Whoops, compiled the changes this time :P --- lib/Client.js | 4 +++- lib/PMChannel.js | 5 +++++ lib/channel.js | 5 +++++ lib/message.js | 7 +++++++ package.json | 2 +- test/bot.1.js | 7 +++++++ 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index e12f5a0ee..77a34e10c 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -139,7 +139,9 @@ var Client = (function () { if (err) { self.state = 4; //set state to disconnected self.trigger("disconnected"); - self.websocket.close(); + if (self.websocket) { + self.websocket.close(); + } callback(err); reject(err); } else { diff --git a/lib/PMChannel.js b/lib/PMChannel.js index ae44d3d60..7c30a7c34 100644 --- a/lib/PMChannel.js +++ b/lib/PMChannel.js @@ -53,6 +53,11 @@ var PMChannel = (function () { return null; } + }, { + key: "isPrivate", + get: function get() { + return true; + } }]); return PMChannel; diff --git a/lib/channel.js b/lib/channel.js index f94925f0c..dfb4f72d8 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -71,6 +71,11 @@ var Channel = (function () { get: function get() { return this.server.client; } + }, { + key: "isPrivate", + get: function get() { + return false; + } }]); return Channel; diff --git a/lib/message.js b/lib/message.js index 24c54fbb3..3dd4ddcae 100644 --- a/lib/message.js +++ b/lib/message.js @@ -4,6 +4,8 @@ var _createClass = (function () { function defineProperties(target, props) { for function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +var PMChannel = require("./PMChannel.js"); + var Message = (function () { function Message(data, channel, mentions, author) { _classCallCheck(this, Message); @@ -64,6 +66,11 @@ var Message = (function () { get: function get() { return this.author; } + }, { + key: "isPrivate", + get: function get() { + return this.channel.isPrivate; + } }]); return Message; diff --git a/package.json b/package.json index 0bbf81be0..120e83fcc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.2.0", + "version": "3.2.1", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { diff --git a/test/bot.1.js b/test/bot.1.js index 253e50c50..9293b401d 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -27,6 +27,13 @@ mybot.on("message", function (message) { } }); +mybot.on("ready", function(){ + console.log("im ready"); + setInterval(function(){ + console.log(mybot.websocket.state, "state"); + }, 2000); +}) + function dump(msg) { console.log(msg); } From 5ef3adffb4aa795c71c115580404a2788b15a600 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 4 Sep 2015 22:14:08 +0100 Subject: [PATCH 007/151] 3.2.2., updated so works on older node hopefully --- package.json | 2 +- src/Client.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 120e83fcc..a83a52a24 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.2.1", + "version": "3.2.2", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { diff --git a/src/Client.js b/src/Client.js index d88aab364..582c6cb70 100644 --- a/src/Client.js +++ b/src/Client.js @@ -29,7 +29,7 @@ class Client { this.token = token; this.state = 0; this.websocket = null; - this.events = new Map(); + this.events = {}; this.user = null; this.alreadySentData = false; this.serverCreateListener = new Map(); @@ -103,11 +103,11 @@ class Client { } on(event, fn) { - this.events.set(event, fn); + this.events[event] = fn; } - off(event, fn) { - this.events.delete(event); + off(event) { + this.events[event] = null; } keepAlive() { @@ -124,7 +124,7 @@ class Client { for (var arg in arguments) { args.push(arguments[arg]); } - var evt = this.events.get(event); + var evt = this.events[event]; if (evt) { evt.apply(this, args.slice(1)); } From 064bbb169ca8571e4db595e05c4fc845a43f01ab Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 4 Sep 2015 22:14:49 +0100 Subject: [PATCH 008/151] actually build 3.2.2 changes whoops --- lib/Client.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 77a34e10c..313e21686 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -39,7 +39,7 @@ var Client = (function () { this.token = token; this.state = 0; this.websocket = null; - this.events = new Map(); + this.events = {}; this.user = null; this.alreadySentData = false; this.serverCreateListener = new Map(); @@ -82,12 +82,12 @@ var Client = (function () { }, { key: "on", value: function on(event, fn) { - this.events.set(event, fn); + this.events[event] = fn; } }, { key: "off", - value: function off(event, fn) { - this.events["delete"](event); + value: function off(event) { + this.events[event] = null; } }, { key: "keepAlive", @@ -107,7 +107,7 @@ var Client = (function () { for (var arg in arguments) { args.push(arguments[arg]); } - var evt = this.events.get(event); + var evt = this.events[event]; if (evt) { evt.apply(this, args.slice(1)); } From 012c706ab9dee4df5d419b35e20dcb13a6070c6e Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 5 Sep 2015 13:57:15 +0100 Subject: [PATCH 009/151] 3.3.0 - added TTS capability --- lib/Client.js | 32 +++++++++++++++++++++++--------- package.json | 2 +- src/Client.js | 28 +++++++++++++++++++++------- test/bot.1.js | 5 +---- 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 313e21686..85119d53a 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -323,13 +323,19 @@ var Client = (function () { } }, { key: "reply", - value: function reply(destination, message) { - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, msg) {} : arguments[2]; + value: function reply(destination, message, tts) { + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; var self = this; return new Promise(function (response, reject) { + if (typeof tts === "function") { + // tts is a function, which means the developer wants this to be the callback + callback = tts; + tts = false; + } + var user = destination.sender; self.sendMessage(destination, message, callback, user + ", ").then(response)["catch"](reject); }); @@ -638,14 +644,20 @@ var Client = (function () { } }, { key: "sendMessage", - value: function sendMessage(destination, message) { - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, msg) {} : arguments[2]; - var premessage = arguments.length <= 3 || arguments[3] === undefined ? "" : arguments[3]; + value: function sendMessage(destination, message, tts) { + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; + var premessage = arguments.length <= 4 || arguments[4] === undefined ? "" : arguments[4]; var self = this; var prom = new Promise(function (resolve, reject) { + if (typeof tts === "function") { + // tts is a function, which means the developer wants this to be the callback + callback = tts; + tts = false; + } + message = premessage + resolveMessage(message); var mentions = resolveMentions(); self.resolveDestination(destination).then(send)["catch"](error); @@ -666,13 +678,14 @@ var Client = (function () { action: "sendMessage", content: message, mentions: mentions, + tts: !!tts, //incase it's not a boolean then: mgood, error: mbad }); self.checkQueue(destination); } else { - self._sendMessage(destination, message, mentions).then(mgood)["catch"](mbad); + self._sendMessage(destination, message, tts, mentions).then(mgood)["catch"](mbad); } } @@ -1393,14 +1406,15 @@ var Client = (function () { } }, { key: "_sendMessage", - value: function _sendMessage(destination, content, mentions) { + value: function _sendMessage(destination, content, tts, mentions) { var self = this; return new Promise(function (resolve, reject) { request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).send({ content: content, - mentions: mentions + mentions: mentions, + tts: tts }).end(function (err, res) { if (err) { @@ -1520,7 +1534,7 @@ var Client = (function () { switch (queuedEvent.action) { case "sendMessage": var msgToSend = queuedEvent; - self._sendMessage(channelID, msgToSend.content, msgToSend.mentions).then(function (msg) { + self._sendMessage(channelID, msgToSend.content, msgToSend.tts, msgToSend.mentions).then(function (msg) { msgToSend.then(msg); self.queue[channelID].shift(); doNext(); diff --git a/package.json b/package.json index a83a52a24..e1c2cc82f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.2.2", + "version": "3.3.0", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { diff --git a/src/Client.js b/src/Client.js index 582c6cb70..03cb6a577 100644 --- a/src/Client.js +++ b/src/Client.js @@ -361,12 +361,18 @@ class Client { } - reply(destination, message, callback = function (err, msg) { }) { + reply(destination, message, tts, callback = function (err, msg) { }) { var self = this; return new Promise(function (response, reject) { + if(typeof tts === "function"){ + // tts is a function, which means the developer wants this to be the callback + callback = tts; + tts = false; + } + var user = destination.sender; self.sendMessage(destination, message, callback, user + ", ").then(response).catch(reject); @@ -644,12 +650,18 @@ class Client { } - sendMessage(destination, message, callback = function (err, msg) { }, premessage = "") { + sendMessage(destination, message, tts, callback = function (err, msg) { }, premessage = "") { var self = this; var prom = new Promise(function (resolve, reject) { - + + if(typeof tts === "function"){ + // tts is a function, which means the developer wants this to be the callback + callback = tts; + tts = false; + } + message = premessage + resolveMessage(message); var mentions = resolveMentions(); self.resolveDestination(destination).then(send).catch(error); @@ -670,13 +682,14 @@ class Client { action: "sendMessage", content: message, mentions: mentions, + tts : !!tts, //incase it's not a boolean then: mgood, error: mbad }); self.checkQueue(destination); } else { - self._sendMessage(destination, message, mentions).then(mgood).catch(mbad); + self._sendMessage(destination, message, tts, mentions).then(mgood).catch(mbad); } } @@ -1153,7 +1166,7 @@ class Client { }); } - _sendMessage(destination, content, mentions) { + _sendMessage(destination, content, tts, mentions) { var self = this; @@ -1163,7 +1176,8 @@ class Client { .set("authorization", self.token) .send({ content: content, - mentions: mentions + mentions: mentions, + tts : tts }) .end(function (err, res) { @@ -1277,7 +1291,7 @@ class Client { switch (queuedEvent.action) { case "sendMessage": var msgToSend = queuedEvent; - self._sendMessage(channelID, msgToSend.content, msgToSend.mentions) + self._sendMessage(channelID, msgToSend.content, msgToSend.tts, msgToSend.mentions) .then(function (msg) { msgToSend.then(msg); self.queue[channelID].shift(); diff --git a/test/bot.1.js b/test/bot.1.js index 9293b401d..eb99418bf 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -16,7 +16,7 @@ mybot.on("message", function (message) { return; } - var action1 = mybot.sendMessage(message.channel, "this is message " + 1); + var action1 = mybot.sendMessage(message.channel, "this is message " + 1, true); var action2 = mybot.sendMessage(message.channel, "this is message " + 2).then(log); function log() { @@ -29,9 +29,6 @@ mybot.on("message", function (message) { mybot.on("ready", function(){ console.log("im ready"); - setInterval(function(){ - console.log(mybot.websocket.state, "state"); - }, 2000); }) function dump(msg) { From a6e62b22a62e03936d1f01bc2fa061d0e0d34281 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 6 Sep 2015 20:16:16 +0100 Subject: [PATCH 010/151] Updated Web Distrib management --- gruntfile.js | 6 +- test/bot.1.js | 14 +- web-dist/README.md | 10 + web-dist/{discord.js => discord.3.3.0.js} | 732 +++++++++++++++------- web-dist/discord.min.js | 2 - 5 files changed, 513 insertions(+), 251 deletions(-) create mode 100644 web-dist/README.md rename web-dist/{discord.js => discord.3.3.0.js} (85%) delete mode 100644 web-dist/discord.min.js diff --git a/gruntfile.js b/gruntfile.js index 2cf6001aa..126762092 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -3,7 +3,7 @@ module.exports = function (grunt) { require('load-grunt-tasks')(grunt); grunt.initConfig({ - + pkg: grunt.file.readJSON("package.json"), // define source files and their destinations babel: { dist: { @@ -19,7 +19,7 @@ module.exports = function (grunt) { browserify: { dist: { files: { - 'web-dist/discord.js': ["lib/index.js"], + 'web-dist/discord.<%= pkg.version %>.js': ["lib/index.js"], }, options: { browserifyOptions: { @@ -31,7 +31,7 @@ module.exports = function (grunt) { uglify: { min: { files: { - "./web-dist/discord.min.js": "./web-dist/discord.js" + "./web-dist/discord.min.<%= pkg.version %>.js": "./web-dist/discord.js" } } } diff --git a/test/bot.1.js b/test/bot.1.js index eb99418bf..1230b9bb6 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -16,18 +16,12 @@ mybot.on("message", function (message) { return; } - var action1 = mybot.sendMessage(message.channel, "this is message " + 1, true); - var action2 = mybot.sendMessage(message.channel, "this is message " + 2).then(log); - - function log() { - mybot.updateMessage(action1.message, "blurg"); - mybot.sendMessage(message.channel, "This is message 3 million minus the million so basically just 3"); - mybot.deleteMessage(action1.message); - mybot.sendMessage(message.channel, "This is message RJNGEIKGNER").then(log2); - } + // we can go ahead :) + console.log(message.sender.username); + mybot.sendMessage(message.channel, message.sender.username); }); -mybot.on("ready", function(){ +mybot.on("ready", function () { console.log("im ready"); }) diff --git a/web-dist/README.md b/web-dist/README.md new file mode 100644 index 000000000..053576bab --- /dev/null +++ b/web-dist/README.md @@ -0,0 +1,10 @@ +## Web Distributions + +Here you can find the latest web-ready distributions of discord.js. These distributions will allow you to run discord.js +in your browser, which is very useful for making on-the-go bots or clients. For some reason, request times are also much +shorter in browsers, so your bots will reply much faster. + +Web Distributions aren't always fully functional, and sometimes catching errors is a pain. As discord.js's support for +browserifying is still maturing, please don't expect that it will work out of the box just yet. + +Also, if the versions in this folder are out-dated, you can always run `grunt web` to generate the latest library. \ No newline at end of file diff --git a/web-dist/discord.js b/web-dist/discord.3.3.0.js similarity index 85% rename from web-dist/discord.js rename to web-dist/discord.3.3.0.js index 2eb328b51..6753dcf6b 100644 --- a/web-dist/discord.js +++ b/web-dist/discord.3.3.0.js @@ -20,7 +20,7 @@ var WebSocket = require("ws"); var fs = require("fs"); var defaultOptions = { - cache_tokens: false + queue: false }; var Client = (function () { @@ -36,10 +36,11 @@ var Client = (function () { further efforts will be made to connect. */ this.options = options; + this.options.queue = this.options.queue; this.token = token; this.state = 0; this.websocket = null; - this.events = new Map(); + this.events = {}; this.user = null; this.alreadySentData = false; this.serverCreateListener = new Map(); @@ -61,6 +62,8 @@ var Client = (function () { this.serverCache = []; this.pmChannelCache = []; this.readyTime = null; + this.checkingQueue = {}; + this.queue = {}; } _createClass(Client, [{ @@ -80,12 +83,12 @@ var Client = (function () { }, { key: "on", value: function on(event, fn) { - this.events.set(event, fn); + this.events[event] = fn; } }, { key: "off", - value: function off(event, fn) { - this.events["delete"](event); + value: function off(event) { + this.events[event] = null; } }, { key: "keepAlive", @@ -105,7 +108,7 @@ var Client = (function () { for (var arg in arguments) { args.push(arguments[arg]); } - var evt = this.events.get(event); + var evt = this.events[event]; if (evt) { evt.apply(this, args.slice(1)); } @@ -137,7 +140,9 @@ var Client = (function () { if (err) { self.state = 4; //set state to disconnected self.trigger("disconnected"); - self.websocket.close(); + if (self.websocket) { + self.websocket.close(); + } callback(err); reject(err); } else { @@ -319,13 +324,19 @@ var Client = (function () { } }, { key: "reply", - value: function reply(destination, message) { - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, msg) {} : arguments[2]; + value: function reply(destination, message, tts) { + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; var self = this; return new Promise(function (response, reject) { + if (typeof tts === "function") { + // tts is a function, which means the developer wants this to be the callback + callback = tts; + tts = false; + } + var user = destination.sender; self.sendMessage(destination, message, callback, user + ", ").then(response)["catch"](reject); }); @@ -337,7 +348,7 @@ var Client = (function () { var self = this; - return new Promise(function (resolve, reject) { + var prom = new Promise(function (resolve, reject) { if (timeout) { setTimeout(remove, timeout); } else { @@ -345,17 +356,37 @@ var Client = (function () { } function remove() { - request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).end(function (err, res) { - if (err) { - callback(err); - reject(err); - } else { - callback(null); - resolve(); + if (self.options.queue) { + if (!self.queue[message.channel.id]) { + self.queue[message.channel.id] = []; } - }); + self.queue[message.channel.id].push({ + action: "deleteMessage", + message: message, + then: good, + error: bad + }); + + self.checkQueue(message.channel.id); + } else { + self._deleteMessage(message).then(good)["catch"](bad); + } + } + + function good() { + prom.success = true; + callback(null); + resolve(); + } + + function bad(err) { + prom.error = err; + callback(err); + reject(err); } }); + + return prom; } }, { key: "updateMessage", @@ -364,26 +395,41 @@ var Client = (function () { var self = this; - return new Promise(function (resolve, reject) { + var prom = new Promise(function (resolve, reject) { content = content instanceof Array ? content.join("\n") : content; - request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).send({ - content: content, - mentions: [] - }).end(function (err, res) { - if (err) { - callback(err); - reject(err); - } else { - var msg = new Message(res.body, message.channel, message.mentions, message.sender); - callback(null, msg); - resolve(msg); - - message.channel.messages[message.channel.messages.indexOf(message)] = msg; + if (self.options.queue) { + if (!self.queue[message.channel.id]) { + self.queue[message.channel.id] = []; } - }); + self.queue[message.channel.id].push({ + action: "updateMessage", + message: message, + content: content, + then: good, + error: bad + }); + + self.checkQueue(message.channel.id); + } else { + self._updateMessage(message, content).then(good)["catch"](bad); + } + + function good(msg) { + prom.message = msg; + callback(null, msg); + resolve(msg); + } + + function bad(error) { + prom.error = error; + callback(error); + reject(error); + } }); + + return prom; } }, { key: "setUsername", @@ -547,7 +593,7 @@ var Client = (function () { var self = this; - return new Promise(function (resolve, reject) { + var prom = new Promise(function (resolve, reject) { var fstream; @@ -558,40 +604,60 @@ var Client = (function () { fstream = file; } - self.resolveDestination(destination).then(send)["catch"](error); + self.resolveDestination(destination).then(send)["catch"](bad); function send(destination) { - request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).attach("file", fstream, fileName).end(function (err, res) { - - if (err) { - error(err); - } else { - - var chann = self.getChannel("id", destination); - if (chann) { - var msg = chann.addMessage(new Message(res.body, chann, [], self.user)); - callback(null, msg); - resolve(msg); - } + if (self.options.queue) { + //queue send file too + if (!self.queue[destination]) { + self.queue[destination] = []; } - }); + + self.queue[destination].push({ + action: "sendFile", + attachment: fstream, + attachmentName: fileName, + then: good, + error: bad + }); + + self.checkQueue(destination); + } else { + //not queue + self._sendFile(destination, fstream, fileName).then(good)["catch"](bad); + } } - function error(err) { + function good(msg) { + prom.message = msg; + callback(null, msg); + resolve(msg); + } + + function bad(err) { + prom.error = err; callback(err); reject(err); } }); + + return prom; } }, { key: "sendMessage", - value: function sendMessage(destination, message) { - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, msg) {} : arguments[2]; - var premessage = arguments.length <= 3 || arguments[3] === undefined ? "" : arguments[3]; + value: function sendMessage(destination, message, tts) { + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; + var premessage = arguments.length <= 4 || arguments[4] === undefined ? "" : arguments[4]; var self = this; - return new Promise(function (resolve, reject) { + var prom = new Promise(function (resolve, reject) { + + if (typeof tts === "function") { + // tts is a function, which means the developer wants this to be the callback + callback = tts; + tts = false; + } message = premessage + resolveMessage(message); var mentions = resolveMentions(); @@ -603,55 +669,37 @@ var Client = (function () { } function send(destination) { - - request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).send({ - content: message, - mentions: mentions - }).end(function (err, res) { - - if (err) { - callback(err); - reject(err); - } else { - var data = res.body; - - var mentions = []; - - data.mentions = data.mentions || []; //for some reason this was not defined at some point? - - var _iteratorNormalCompletion3 = true; - var _didIteratorError3 = false; - var _iteratorError3 = undefined; - - try { - for (var _iterator3 = data.mentions[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { - var mention = _step3.value; - - mentions.push(self.addUser(mention)); - } - } catch (err) { - _didIteratorError3 = true; - _iteratorError3 = err; - } finally { - try { - if (!_iteratorNormalCompletion3 && _iterator3["return"]) { - _iterator3["return"](); - } - } finally { - if (_didIteratorError3) { - throw _iteratorError3; - } - } - } - - var channel = self.getChannel("id", data.channel_id); - if (channel) { - var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); - callback(null, msg); - resolve(msg); - } + if (self.options.queue) { + //we're QUEUEING messages, so sending them sequentially based on servers. + if (!self.queue[destination]) { + self.queue[destination] = []; } - }); + + self.queue[destination].push({ + action: "sendMessage", + content: message, + mentions: mentions, + tts: !!tts, //incase it's not a boolean + then: mgood, + error: mbad + }); + + self.checkQueue(destination); + } else { + self._sendMessage(destination, message, tts, mentions).then(mgood)["catch"](mbad); + } + } + + function mgood(msg) { + prom.message = msg; + callback(null, msg); + resolve(msg); + } + + function mbad(error) { + prom.error = error; + callback(error); + reject(error); } function resolveMessage() { @@ -664,27 +712,27 @@ var Client = (function () { function resolveMentions() { var _mentions = []; - var _iteratorNormalCompletion4 = true; - var _didIteratorError4 = false; - var _iteratorError4 = undefined; + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; try { - for (var _iterator4 = (message.match(/<@[^>]*>/g) || [])[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { - var mention = _step4.value; + for (var _iterator3 = (message.match(/<@[^>]*>/g) || [])[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var mention = _step3.value; _mentions.push(mention.substring(2, mention.length - 1)); } } catch (err) { - _didIteratorError4 = true; - _iteratorError4 = err; + _didIteratorError3 = true; + _iteratorError3 = err; } finally { try { - if (!_iteratorNormalCompletion4 && _iterator4["return"]) { - _iterator4["return"](); + if (!_iteratorNormalCompletion3 && _iterator3["return"]) { + _iterator3["return"](); } } finally { - if (_didIteratorError4) { - throw _iteratorError4; + if (_didIteratorError3) { + throw _iteratorError3; } } } @@ -692,6 +740,8 @@ var Client = (function () { return _mentions; } }); + + return prom; } //def createws @@ -737,15 +787,40 @@ var Client = (function () { self.user = self.addUser(data.user); + var _iteratorNormalCompletion4 = true; + var _didIteratorError4 = false; + var _iteratorError4 = undefined; + + try { + for (var _iterator4 = data.guilds[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var _server = _step4.value; + + var server = self.addServer(_server); + } + } catch (err) { + _didIteratorError4 = true; + _iteratorError4 = err; + } finally { + try { + if (!_iteratorNormalCompletion4 && _iterator4["return"]) { + _iterator4["return"](); + } + } finally { + if (_didIteratorError4) { + throw _iteratorError4; + } + } + } + var _iteratorNormalCompletion5 = true; var _didIteratorError5 = false; var _iteratorError5 = undefined; try { - for (var _iterator5 = data.guilds[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { - var _server = _step5.value; + for (var _iterator5 = data.private_channels[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { + var _pmc = _step5.value; - var server = self.addServer(_server); + var pmc = self.addPMChannel(_pmc); } } catch (err) { _didIteratorError5 = true; @@ -762,31 +837,6 @@ var Client = (function () { } } - var _iteratorNormalCompletion6 = true; - var _didIteratorError6 = false; - var _iteratorError6 = undefined; - - try { - for (var _iterator6 = data.private_channels[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { - var _pmc = _step6.value; - - var pmc = self.addPMChannel(_pmc); - } - } catch (err) { - _didIteratorError6 = true; - _iteratorError6 = err; - } finally { - try { - if (!_iteratorNormalCompletion6 && _iterator6["return"]) { - _iterator6["return"](); - } - } finally { - if (_didIteratorError6) { - throw _iteratorError6; - } - } - } - self.trigger("ready"); self.readyTime = Date.now(); self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users."); @@ -801,27 +851,27 @@ var Client = (function () { var mentions = []; data.mentions = data.mentions || []; //for some reason this was not defined at some point? - var _iteratorNormalCompletion7 = true; - var _didIteratorError7 = false; - var _iteratorError7 = undefined; + var _iteratorNormalCompletion6 = true; + var _didIteratorError6 = false; + var _iteratorError6 = undefined; try { - for (var _iterator7 = data.mentions[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { - var mention = _step7.value; + for (var _iterator6 = data.mentions[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { + var mention = _step6.value; mentions.push(self.addUser(mention)); } } catch (err) { - _didIteratorError7 = true; - _iteratorError7 = err; + _didIteratorError6 = true; + _iteratorError6 = err; } finally { try { - if (!_iteratorNormalCompletion7 && _iterator7["return"]) { - _iterator7["return"](); + if (!_iteratorNormalCompletion6 && _iterator6["return"]) { + _iterator6["return"](); } } finally { - if (_didIteratorError7) { - throw _iteratorError7; + if (_didIteratorError6) { + throw _iteratorError6; } } } @@ -866,27 +916,27 @@ var Client = (function () { } var mentions = []; - var _iteratorNormalCompletion8 = true; - var _didIteratorError8 = false; - var _iteratorError8 = undefined; + var _iteratorNormalCompletion7 = true; + var _didIteratorError7 = false; + var _iteratorError7 = undefined; try { - for (var _iterator8 = info.mentions[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) { - var mention = _step8.value; + for (var _iterator7 = info.mentions[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { + var mention = _step7.value; mentions.push(self.addUser(mention)); } } catch (err) { - _didIteratorError8 = true; - _iteratorError8 = err; + _didIteratorError7 = true; + _iteratorError7 = err; } finally { try { - if (!_iteratorNormalCompletion8 && _iterator8["return"]) { - _iterator8["return"](); + if (!_iteratorNormalCompletion7 && _iterator7["return"]) { + _iterator7["return"](); } } finally { - if (_didIteratorError8) { - throw _iteratorError8; + if (_didIteratorError7) { + throw _iteratorError7; } } } @@ -1101,27 +1151,27 @@ var Client = (function () { server = new Server(data, this); this.serverCache.push(server); if (data.channels) { - var _iteratorNormalCompletion9 = true; - var _didIteratorError9 = false; - var _iteratorError9 = undefined; + var _iteratorNormalCompletion8 = true; + var _didIteratorError8 = false; + var _iteratorError8 = undefined; try { - for (var _iterator9 = data.channels[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) { - var channel = _step9.value; + for (var _iterator8 = data.channels[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) { + var channel = _step8.value; server.channels.push(this.addChannel(channel, server.id)); } } catch (err) { - _didIteratorError9 = true; - _iteratorError9 = err; + _didIteratorError8 = true; + _iteratorError8 = err; } finally { try { - if (!_iteratorNormalCompletion9 && _iterator9["return"]) { - _iterator9["return"](); + if (!_iteratorNormalCompletion8 && _iterator8["return"]) { + _iterator8["return"](); } } finally { - if (_didIteratorError9) { - throw _iteratorError9; + if (_didIteratorError8) { + throw _iteratorError8; } } } @@ -1135,16 +1185,50 @@ var Client = (function () { }, { key: "getUser", value: function getUser(key, value) { + var _iteratorNormalCompletion9 = true; + var _didIteratorError9 = false; + var _iteratorError9 = undefined; + + try { + for (var _iterator9 = this.userCache[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) { + var user = _step9.value; + + if (user[key] === value) { + return user; + } + } + } catch (err) { + _didIteratorError9 = true; + _iteratorError9 = err; + } finally { + try { + if (!_iteratorNormalCompletion9 && _iterator9["return"]) { + _iterator9["return"](); + } + } finally { + if (_didIteratorError9) { + throw _iteratorError9; + } + } + } + + return null; + } + + //def getChannel + }, { + key: "getChannel", + value: function getChannel(key, value) { var _iteratorNormalCompletion10 = true; var _didIteratorError10 = false; var _iteratorError10 = undefined; try { - for (var _iterator10 = this.userCache[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) { - var user = _step10.value; + for (var _iterator10 = this.channelCache[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) { + var channel = _step10.value; - if (user[key] === value) { - return user; + if (channel[key] === value) { + return channel; } } } catch (err) { @@ -1162,19 +1246,17 @@ var Client = (function () { } } - return null; + return this.getPMChannel(key, value); //might be a PM } - - //def getChannel }, { - key: "getChannel", - value: function getChannel(key, value) { + key: "getPMChannel", + value: function getPMChannel(key, value) { var _iteratorNormalCompletion11 = true; var _didIteratorError11 = false; var _iteratorError11 = undefined; try { - for (var _iterator11 = this.channelCache[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) { + for (var _iterator11 = this.pmChannelCache[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) { var channel = _step11.value; if (channel[key] === value) { @@ -1196,21 +1278,23 @@ var Client = (function () { } } - return this.getPMChannel(key, value); //might be a PM + return null; } + + //def getServer }, { - key: "getPMChannel", - value: function getPMChannel(key, value) { + key: "getServer", + value: function getServer(key, value) { var _iteratorNormalCompletion12 = true; var _didIteratorError12 = false; var _iteratorError12 = undefined; try { - for (var _iterator12 = this.pmChannelCache[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) { - var channel = _step12.value; + for (var _iterator12 = this.serverCache[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) { + var server = _step12.value; - if (channel[key] === value) { - return channel; + if (server[key] === value) { + return server; } } } catch (err) { @@ -1231,40 +1315,6 @@ var Client = (function () { return null; } - //def getServer - }, { - key: "getServer", - value: function getServer(key, value) { - var _iteratorNormalCompletion13 = true; - var _didIteratorError13 = false; - var _iteratorError13 = undefined; - - try { - for (var _iterator13 = this.serverCache[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) { - var server = _step13.value; - - if (server[key] === value) { - return server; - } - } - } catch (err) { - _didIteratorError13 = true; - _iteratorError13 = err; - } finally { - try { - if (!_iteratorNormalCompletion13 && _iterator13["return"]) { - _iterator13["return"](); - } - } finally { - if (_didIteratorError13) { - throw _iteratorError13; - } - } - } - - return null; - } - //def trySendConnData }, { key: "trySendConnData", @@ -1317,13 +1367,13 @@ var Client = (function () { } else if (destination instanceof User) { //check if we have a PM - var _iteratorNormalCompletion14 = true; - var _didIteratorError14 = false; - var _iteratorError14 = undefined; + var _iteratorNormalCompletion13 = true; + var _didIteratorError13 = false; + var _iteratorError13 = undefined; try { - for (var _iterator14 = self.pmChannelCache[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) { - var pmc = _step14.value; + for (var _iterator13 = self.pmChannelCache[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) { + var pmc = _step13.value; if (pmc.user.equals(destination)) { return pmc.id; @@ -1331,6 +1381,62 @@ var Client = (function () { } //we don't, at this point we're late + } catch (err) { + _didIteratorError13 = true; + _iteratorError13 = err; + } finally { + try { + if (!_iteratorNormalCompletion13 && _iterator13["return"]) { + _iterator13["return"](); + } + } finally { + if (_didIteratorError13) { + throw _iteratorError13; + } + } + } + + self.startPM(destination).then(function (pmc) { + resolve(pmc.id); + })["catch"](reject); + } else { + channId = destination; + } + if (channId) resolve(channId); + }); + } + }, { + key: "_sendMessage", + value: function _sendMessage(destination, content, tts, mentions) { + + var self = this; + + return new Promise(function (resolve, reject) { + request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).send({ + content: content, + mentions: mentions, + tts: tts + }).end(function (err, res) { + + if (err) { + reject(err); + } else { + var data = res.body; + + var mentions = []; + + data.mentions = data.mentions || []; //for some reason this was not defined at some point? + + var _iteratorNormalCompletion14 = true; + var _didIteratorError14 = false; + var _iteratorError14 = undefined; + + try { + for (var _iterator14 = data.mentions[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) { + var mention = _step14.value; + + mentions.push(self.addUser(mention)); + } } catch (err) { _didIteratorError14 = true; _iteratorError14 = err; @@ -1346,15 +1452,152 @@ var Client = (function () { } } - self.startPM(destination).then(function (pmc) { - resolve(pmc.id); - })["catch"](reject); - } else { - channId = destination; + var channel = self.getChannel("id", data.channel_id); + if (channel) { + var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); + resolve(msg); + } } - if (channId) resolve(channId); + }); }); } + }, { + key: "_sendFile", + value: function _sendFile(destination, attachment) { + var attachmentName = arguments.length <= 2 || arguments[2] === undefined ? "DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png" : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).attach("file", attachment, attachmentName).end(function (err, res) { + + if (err) { + reject(err); + } else { + + var chann = self.getChannel("id", destination); + if (chann) { + var msg = chann.addMessage(new Message(res.body, chann, [], self.user)); + resolve(msg); + } + } + }); + }); + } + }, { + key: "_updateMessage", + value: function _updateMessage(message, content) { + var self = this; + return new Promise(function (resolve, reject) { + request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).send({ + content: content, + mentions: [] + }).end(function (err, res) { + if (err) { + reject(err); + } else { + var msg = new Message(res.body, message.channel, message.mentions, message.sender); + resolve(msg); + message.channel.messages[message.channel.messages.indexOf(message)] = msg; + } + }); + }); + } + }, { + key: "_deleteMessage", + value: function _deleteMessage(message) { + var self = this; + return new Promise(function (resolve, reject) { + request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + }); + } + }, { + key: "checkQueue", + value: function checkQueue(channelID) { + var _this = this; + + var self = this; + + if (!this.checkingQueue[channelID]) { + (function () { + var doNext = function doNext() { + if (self.queue[channelID].length === 0) { + done(); + return; + } + var queuedEvent = self.queue[channelID][0]; + switch (queuedEvent.action) { + case "sendMessage": + var msgToSend = queuedEvent; + self._sendMessage(channelID, msgToSend.content, msgToSend.tts, msgToSend.mentions).then(function (msg) { + msgToSend.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + msgToSend.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + case "sendFile": + var fileToSend = queuedEvent; + self._sendFile(channelID, fileToSend.attachment, fileToSend.attachmentName).then(function (msg) { + fileToSend.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + fileToSend.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + case "updateMessage": + var msgToUpd = queuedEvent; + self._updateMessage(msgToUpd.message, msgToUpd.content).then(function (msg) { + msgToUpd.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + msgToUpd.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + case "deleteMessage": + var msgToDel = queuedEvent; + self._deleteMessage(msgToDel.message).then(function (msg) { + msgToDel.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + msgToDel.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + default: + done(); + break; + } + }; + + var done = function done() { + self.checkingQueue[channelID] = false; + return; + }; + + //if we aren't already checking this queue. + _this.checkingQueue[channelID] = true; + doNext(); + })(); + } + } }, { key: "uptime", get: function get() { @@ -1509,6 +1752,11 @@ var PMChannel = (function () { return null; } + }, { + key: "isPrivate", + get: function get() { + return true; + } }]); return PMChannel; @@ -1589,6 +1837,11 @@ var Channel = (function () { get: function get() { return this.server.client; } + }, { + key: "isPrivate", + get: function get() { + return false; + } }]); return Channel; @@ -1651,6 +1904,8 @@ var _createClass = (function () { function defineProperties(target, props) { for function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +var PMChannel = require("./PMChannel.js"); + var Message = (function () { function Message(data, channel, mentions, author) { _classCallCheck(this, Message); @@ -1711,13 +1966,18 @@ var Message = (function () { get: function get() { return this.author; } + }, { + key: "isPrivate", + get: function get() { + return this.channel.isPrivate; + } }]); return Message; })(); module.exports = Message; -},{}],8:[function(require,module,exports){ +},{"./PMChannel.js":3}],8:[function(require,module,exports){ "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; }; })(); diff --git a/web-dist/discord.min.js b/web-dist/discord.min.js deleted file mode 100644 index 37ba4d200..000000000 --- a/web-dist/discord.min.js +++ /dev/null @@ -1,2 +0,0 @@ -!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Discord=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g]*>/g)||[])[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;a.push(h.substring(2,h.length-1))}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return a}b=d+l(b);var o=m();e.resolveDestination(a).then(j)["catch"](i)})}},{key:"createws",value:function(a){if(this.websocket)return!1;var b=this;this.websocket=new o(a),this.websocket.onopen=function(){b.trySendConnData()},this.websocket.onclose=function(){b.trigger("disconnected")},this.websocket.onmessage=function(a){var c=!1,d={};try{c=JSON.parse(a.data),d=c.d}catch(e){return void b.trigger("error",e,a)}switch(c.t){case"READY":b.debug("received ready packet"),b.user=b.addUser(d.user);var f=!0,g=!1,i=void 0;try{for(var j,l=d.guilds[Symbol.iterator]();!(f=(j=l.next()).done);f=!0)var m=j.value,n=b.addServer(m)}catch(e){g=!0,i=e}finally{try{!f&&l["return"]&&l["return"]()}finally{if(g)throw i}}var o=!0,p=!1,q=void 0;try{for(var r,s=d.private_channels[Symbol.iterator]();!(o=(r=s.next()).done);o=!0){var t=r.value;b.addPMChannel(t)}}catch(e){p=!0,q=e}finally{try{!o&&s["return"]&&s["return"]()}finally{if(p)throw q}}b.trigger("ready"),b.readyTime=Date.now(),b.debug("cached "+b.serverCache.length+" servers, "+b.channelCache.length+" channels, "+b.pmChannelCache.length+" PMs and "+b.userCache.length+" users."),b.state=3,setInterval(function(){b.keepAlive.apply(b)},d.heartbeat_interval);break;case"MESSAGE_CREATE":b.debug("received message");var u=[];d.mentions=d.mentions||[];var v=!0,w=!1,x=void 0;try{for(var y,z=d.mentions[Symbol.iterator]();!(v=(y=z.next()).done);v=!0){var A=y.value;u.push(b.addUser(A))}}catch(e){w=!0,x=e}finally{try{!v&&z["return"]&&z["return"]()}finally{if(w)throw x}}var B=b.getChannel("id",d.channel_id);if(B){var C=B.addMessage(new k(d,B,u,b.addUser(d.author)));b.trigger("message",C)}break;case"MESSAGE_DELETE":b.debug("message deleted");var B=b.getChannel("id",d.channel_id),D=B.getMessage("id",d.id);D?(b.trigger("messageDelete",B,D),B.messages.splice(B.messages.indexOf(D),1)):b.trigger("messageDelete",B);break;case"MESSAGE_UPDATE":b.debug("message updated");var B=b.getChannel("id",d.channel_id),E=B.getMessage("id",d.id);if(E){var F={};for(var G in E)F[G]=E[G];for(var G in d)F[G]=d[G];var u=[],H=!0,I=!1,J=void 0;try{for(var K,L=F.mentions[Symbol.iterator]();!(H=(K=L.next()).done);H=!0){var A=K.value;u.push(b.addUser(A))}}catch(e){I=!0,J=e}finally{try{!H&&L["return"]&&L["return"]()}finally{if(I)throw J}}var M=new k(F,B,u,E.author);b.trigger("messageUpdate",M,E),B.messages[B.messages.indexOf(E)]=M}break;case"GUILD_DELETE":var n=b.getServer("id",d.id);n&&(b.serverCache.splice(b.serverCache.indexOf(n),1),b.trigger("serverDelete",n));break;case"CHANNEL_DELETE":var B=b.getChannel("id",d.id);if(B){var n=B.server;n&&n.channels.splice(n.channels.indexOf(B),1),b.trigger("channelDelete",B),b.serverCache.splice(b.serverCache.indexOf(B),1)}break;case"GUILD_CREATE":var n=b.getServer("id",d.id);if(n||(n=b.addServer(d)),b.serverCreateListener.get(d.id)){var N=b.serverCreateListener.get(d.id);N[0](n),N[1](null,n),b.serverCreateListener["delete"](d.id)}b.trigger("serverCreate",n);break;case"CHANNEL_CREATE":var B=b.getChannel("id",d.id);if(!B){var O=b.addChannel(d,d.guild_id),P=b.getServer("id",d.guild_id);P&&P.addChannel(O),b.trigger("channelCreate",O)}break;case"GUILD_MEMBER_ADD":var n=b.getServer("id",d.guild_id);if(n){var Q=b.addUser(d.user);~n.members.indexOf(Q)||n.members.push(Q),b.trigger("serverNewMember",Q)}break;case"GUILD_MEMBER_REMOVE":var n=b.getServer("id",d.guild_id);if(n){var Q=b.addUser(d.user);~n.members.indexOf(Q)&&n.members.splice(n.members.indexOf(Q),1),b.trigger("serverRemoveMember",Q)}break;case"USER_UPDATE":if(b.user&&d.id===b.user.id){var R=new h(d);b.trigger("userUpdate",R,b.user),~b.userCache.indexOf(b.user)&&(b.userCache[b.userCache.indexOf(b.user)]=R),b.user=R}break;case"PRESENCE_UPDATE":var S=b.getUser("id",d.user.id);if(S){var T=new h(d.user);T.equalsStrict(S)?b.trigger("presence",{user:S,status:d.status,server:b.getServer("id",d.guild_id),gameId:d.game_id}):(b.trigger("userUpdate",S,T),b.userCache[b.userCache.indexOf(S)]=T)}break;default:b.debug("received unknown packet"),b.trigger("unknown",c)}}}},{key:"addUser",value:function(a){return this.getUser("id",a.id)||this.userCache.push(new h(a)),this.getUser("id",a.id)}},{key:"addChannel",value:function(a,b){return this.getChannel("id",a.id)||this.channelCache.push(new j(a,this.getServer("id",b))),this.getChannel("id",a.id)}},{key:"addPMChannel",value:function(a){return this.getPMChannel("id",a.id)||this.pmChannelCache.push(new m(a,this)),this.getPMChannel("id",a.id)}},{key:"addServer",value:function(a){var b=this.getServer("id",a.id);if(!b&&(b=new i(a,this),this.serverCache.push(b),a.channels)){var c=!0,d=!1,e=void 0;try{for(var f,g=a.channels[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;b.channels.push(this.addChannel(h,b.id))}}catch(j){d=!0,e=j}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}}return b}},{key:"getUser",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.userCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"getChannel",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.channelCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return this.getPMChannel(a,b)}},{key:"getPMChannel",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.pmChannelCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"getServer",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.serverCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"trySendConnData",value:function(){if(this.token&&!this.alreadySentData){this.alreadySentData=!0;var a={op:2,d:{token:this.token,v:2,properties:{$os:"discord.js",$browser:"discord.js",$device:"discord.js",$referrer:"",$referring_domain:""}}};this.websocket.send(JSON.stringify(a))}}},{key:"resolveServerID",value:function(a){return a instanceof i?a.id:!isNaN(a)&&a.length&&17===a.length?a:void 0}},{key:"resolveDestination",value:function(a){var b=!1,c=this;return new Promise(function(d,e){if(a instanceof i)b=a.id;else if(a instanceof j)b=a.id;else if(a instanceof k)b=a.channel.id;else if(a instanceof h){var f=!0,g=!1,l=void 0;try{for(var m,n=c.pmChannelCache[Symbol.iterator]();!(f=(m=n.next()).done);f=!0){var o=m.value;if(o.user.equals(a))return o.id}}catch(p){g=!0,l=p}finally{try{!f&&n["return"]&&n["return"]()}finally{if(g)throw l}}c.startPM(a).then(function(a){d(a.id)})["catch"](e)}else b=a;b&&d(b)})}},{key:"uptime",get:function(){return this.readyTime?Date.now()-this.readyTime:null}},{key:"ready",get:function(){return 3===this.state}},{key:"servers",get:function(){return this.serverCache}},{key:"channels",get:function(){return this.channelCache}},{key:"users",get:function(){return this.userCache}},{key:"PMChannels",get:function(){return this.pmChannelCache}},{key:"messages",get:function(){var a=[],b=!0,c=!1,d=void 0;try{for(var e,f=this.channelCache[Symbol.iterator]();!(b=(e=f.next()).done);b=!0){var g=e.value;a=a.concat(g.messages)}}catch(h){c=!0,d=h}finally{try{!b&&f["return"]&&f["return"]()}finally{if(c)throw d}}return a}}]),a}();b.exports=r},{"./Endpoints.js":2,"./PMChannel.js":3,"./channel.js":4,"./invite.js":6,"./message.js":7,"./server.js":8,"./user.js":9,fs:10,superagent:11,ws:14}],2:[function(a,b,c){"use strict";c.BASE_DOMAIN="discordapp.com",c.BASE="https://"+c.BASE_DOMAIN,c.WEBSOCKET_HUB="wss://"+c.BASE_DOMAIN+"/hub",c.API=c.BASE+"/api",c.AUTH=c.API+"/auth",c.LOGIN=c.AUTH+"/login",c.LOGOUT=c.AUTH+"/logout",c.USERS=c.API+"/users",c.SERVERS=c.API+"/guilds",c.CHANNELS=c.API+"/channels"},{}],3:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c"}},{key:"toString",value:function(){return this.mention()}},{key:"equals",value:function(a){return a.id===this.id}},{key:"equalsStrict",value:function(a){return a.id===this.id&&a.avatar===this.avatar&&a.username===this.username&&a.discriminator===this.discriminator}},{key:"avatarURL",get:function(){return this.avatar?"https://discordapp.com/api/users/"+this.id+"/avatars/"+this.avatar+".jpg":null}}]),a}();b.exports=f},{}],10:[function(a,b,c){},{}],11:[function(a,b,c){function d(){}function e(a){var b={}.toString.call(a);switch(b){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function f(a){return a===Object(a)}function g(a){if(!f(a))return a;var b=[];for(var c in a)null!=a[c]&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")}function h(a){for(var b,c,d={},e=a.split("&"),f=0,g=e.length;g>f;++f)c=e[f],b=c.split("="),d[decodeURIComponent(b[0])]=decodeURIComponent(b[1]);return d}function i(a){var b,c,d,e,f=a.split(/\r?\n/),g={};f.pop();for(var h=0,i=f.length;i>h;++h)c=f[h],b=c.indexOf(":"),d=c.slice(0,b).toLowerCase(),e=r(c.slice(b+1)),g[d]=e;return g}function j(a){return a.split(/ *; */).shift()}function k(a){return p(a.split(/ *; */),function(a,b){var c=b.split(/ *= */),d=c.shift(),e=c.shift();return d&&e&&(a[d]=e),a},{})}function l(a,b){b=b||{},this.req=a,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||"undefined"==typeof this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText,this.setStatusProperties(this.xhr.status),this.header=this.headers=i(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body="HEAD"!=this.req.method?this.parseBody(this.text?this.text:this.xhr.response):null}function m(a,b){var c=this;o.call(this),this._query=this._query||[],this.method=a,this.url=b,this.header={},this._header={},this.on("end",function(){var a=null,b=null;try{b=new l(c)}catch(d){return a=new Error("Parser is unable to parse the response"),a.parse=!0,a.original=d,c.callback(a)}if(c.emit("response",b),a)return c.callback(a,b);if(b.status>=200&&b.status<300)return c.callback(a,b);var e=new Error(b.statusText||"Unsuccessful HTTP response");e.original=a,e.response=b,e.status=b.status,c.callback(e,b)})}function n(a,b){return"function"==typeof b?new m("GET",a).end(b):1==arguments.length?new m("GET",a):new m(a,b)}var o=a("emitter"),p=a("reduce"),q="undefined"==typeof window?this||self:window;n.getXHR=function(){if(!(!q.XMLHttpRequest||q.location&&"file:"==q.location.protocol&&q.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(a){}return!1};var r="".trim?function(a){return a.trim()}:function(a){return a.replace(/(^\s*|\s*$)/g,"")};n.serializeObject=g,n.parseString=h,n.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},n.serialize={"application/x-www-form-urlencoded":g,"application/json":JSON.stringify},n.parse={"application/x-www-form-urlencoded":h,"application/json":JSON.parse},l.prototype.get=function(a){return this.header[a.toLowerCase()]},l.prototype.setHeaderProperties=function(a){var b=this.header["content-type"]||"";this.type=j(b);var c=k(b);for(var d in c)this[d]=c[d]},l.prototype.parseBody=function(a){var b=n.parse[this.type];return b&&a&&(a.length||a instanceof Object)?b(a):null},l.prototype.setStatusProperties=function(a){1223===a&&(a=204);var b=a/100|0;this.status=a,this.statusType=b,this.info=1==b,this.ok=2==b,this.clientError=4==b,this.serverError=5==b,this.error=4==b||5==b?this.toError():!1,this.accepted=202==a,this.noContent=204==a,this.badRequest=400==a,this.unauthorized=401==a,this.notAcceptable=406==a,this.notFound=404==a,this.forbidden=403==a},l.prototype.toError=function(){var a=this.req,b=a.method,c=a.url,d="cannot "+b+" "+c+" ("+this.status+")",e=new Error(d);return e.status=this.status,e.method=b,e.url=c,e},n.Response=l,o(m.prototype),m.prototype.use=function(a){return a(this),this},m.prototype.timeout=function(a){return this._timeout=a,this},m.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},m.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(),this.clearTimeout(),this.emit("abort"),this)},m.prototype.set=function(a,b){if(f(a)){for(var c in a)this.set(c,a[c]);return this}return this._header[a.toLowerCase()]=b,this.header[a]=b,this},m.prototype.unset=function(a){return delete this._header[a.toLowerCase()],delete this.header[a],this},m.prototype.getHeader=function(a){return this._header[a.toLowerCase()]},m.prototype.type=function(a){return this.set("Content-Type",n.types[a]||a),this},m.prototype.accept=function(a){return this.set("Accept",n.types[a]||a),this},m.prototype.auth=function(a,b){var c=btoa(a+":"+b);return this.set("Authorization","Basic "+c),this},m.prototype.query=function(a){return"string"!=typeof a&&(a=g(a)),a&&this._query.push(a),this},m.prototype.field=function(a,b){return this._formData||(this._formData=new q.FormData),this._formData.append(a,b),this},m.prototype.attach=function(a,b,c){return this._formData||(this._formData=new q.FormData),this._formData.append(a,b,c),this},m.prototype.send=function(a){var b=f(a),c=this.getHeader("Content-Type");if(b&&f(this._data))for(var d in a)this._data[d]=a[d];else"string"==typeof a?(c||this.type("form"),c=this.getHeader("Content-Type"),"application/x-www-form-urlencoded"==c?this._data=this._data?this._data+"&"+a:a:this._data=(this._data||"")+a):this._data=a;return!b||e(a)?this:(c||this.type("json"),this)},m.prototype.callback=function(a,b){var c=this._callback;this.clearTimeout(),c(a,b)},m.prototype.crossDomainError=function(){var a=new Error("Origin is not allowed by Access-Control-Allow-Origin");a.crossDomain=!0,this.callback(a)},m.prototype.timeoutError=function(){var a=this._timeout,b=new Error("timeout of "+a+"ms exceeded");b.timeout=a,this.callback(b)},m.prototype.withCredentials=function(){return this._withCredentials=!0,this},m.prototype.end=function(a){var b=this,c=this.xhr=n.getXHR(),f=this._query.join("&"),g=this._timeout,h=this._formData||this._data;this._callback=a||d,c.onreadystatechange=function(){if(4==c.readyState){var a;try{a=c.status}catch(d){a=0}if(0==a){if(b.timedout)return b.timeoutError();if(b.aborted)return;return b.crossDomainError()}b.emit("end")}};var i=function(a){a.total>0&&(a.percent=a.loaded/a.total*100),b.emit("progress",a)};this.hasListeners("progress")&&(c.onprogress=i);try{c.upload&&this.hasListeners("progress")&&(c.upload.onprogress=i)}catch(j){}if(g&&!this._timer&&(this._timer=setTimeout(function(){b.timedout=!0,b.abort()},g)),f&&(f=n.serializeObject(f),this.url+=~this.url.indexOf("?")?"&"+f:"?"+f),c.open(this.method,this.url,!0),this._withCredentials&&(c.withCredentials=!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof h&&!e(h)){var k=this.getHeader("Content-Type"),l=n.serialize[k?k.split(";")[0]:""];l&&(h=l(h))}for(var m in this.header)null!=this.header[m]&&c.setRequestHeader(m,this.header[m]);return this.emit("request",this), -c.send(h),this},m.prototype.then=function(a,b){return this.end(function(c,d){c?b(c):a(d)})},n.Request=m,n.get=function(a,b,c){var d=n("GET",a);return"function"==typeof b&&(c=b,b=null),b&&d.query(b),c&&d.end(c),d},n.head=function(a,b,c){var d=n("HEAD",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.del=function(a,b){var c=n("DELETE",a);return b&&c.end(b),c},n.patch=function(a,b,c){var d=n("PATCH",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.post=function(a,b,c){var d=n("POST",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.put=function(a,b,c){var d=n("PUT",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},b.exports=n},{emitter:12,reduce:13}],12:[function(a,b,c){function d(a){return a?e(a):void 0}function e(a){for(var b in d.prototype)a[b]=d.prototype[b];return a}b.exports=d,d.prototype.on=d.prototype.addEventListener=function(a,b){return this._callbacks=this._callbacks||{},(this._callbacks[a]=this._callbacks[a]||[]).push(b),this},d.prototype.once=function(a,b){function c(){d.off(a,c),b.apply(this,arguments)}var d=this;return this._callbacks=this._callbacks||{},c.fn=b,this.on(a,c),this},d.prototype.off=d.prototype.removeListener=d.prototype.removeAllListeners=d.prototype.removeEventListener=function(a,b){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var c=this._callbacks[a];if(!c)return this;if(1==arguments.length)return delete this._callbacks[a],this;for(var d,e=0;ed;++d)c[d].apply(this,b)}return this},d.prototype.listeners=function(a){return this._callbacks=this._callbacks||{},this._callbacks[a]||[]},d.prototype.hasListeners=function(a){return!!this.listeners(a).length}},{}],13:[function(a,b,c){b.exports=function(a,b,c){for(var d=0,e=a.length,f=3==arguments.length?c:a[d++];e>d;)f=b.call(null,f,a[d],++d,a);return f}},{}],14:[function(a,b,c){function d(a,b,c){var d;return d=b?new f(a,b):new f(a)}var e=function(){return this}(),f=e.WebSocket||e.MozWebSocket;b.exports=f?d:null,f&&(d.prototype=f.prototype)},{}]},{},[5])(5)}); \ No newline at end of file From 833f0478d412015d28a6f8c09acc657d6d594f30 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 6 Sep 2015 20:21:37 +0100 Subject: [PATCH 011/151] Fixed minify script --- gruntfile.js | 2 +- web-dist/discord.min.3.3.0.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 web-dist/discord.min.3.3.0.js diff --git a/gruntfile.js b/gruntfile.js index 126762092..a8972256f 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -31,7 +31,7 @@ module.exports = function (grunt) { uglify: { min: { files: { - "./web-dist/discord.min.<%= pkg.version %>.js": "./web-dist/discord.js" + "./web-dist/discord.min.<%= pkg.version %>.js": "./web-dist/discord.<%= pkg.version %>.js" } } } diff --git a/web-dist/discord.min.3.3.0.js b/web-dist/discord.min.3.3.0.js new file mode 100644 index 000000000..71f1235d5 --- /dev/null +++ b/web-dist/discord.min.3.3.0.js @@ -0,0 +1,2 @@ +!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Discord=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g]*>/g)||[])[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;a.push(h.substring(2,h.length-1))}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return a}"function"==typeof c&&(d=c,c=!1),b=e+n(b);var p=o();f.resolveDestination(a).then(k)["catch"](j)});return g}},{key:"createws",value:function(a){if(this.websocket)return!1;var b=this;this.websocket=new o(a),this.websocket.onopen=function(){b.trySendConnData()},this.websocket.onclose=function(){b.trigger("disconnected")},this.websocket.onmessage=function(a){var c=!1,d={};try{c=JSON.parse(a.data),d=c.d}catch(e){return void b.trigger("error",e,a)}switch(c.t){case"READY":b.debug("received ready packet"),b.user=b.addUser(d.user);var f=!0,g=!1,i=void 0;try{for(var j,l=d.guilds[Symbol.iterator]();!(f=(j=l.next()).done);f=!0)var m=j.value,n=b.addServer(m)}catch(e){g=!0,i=e}finally{try{!f&&l["return"]&&l["return"]()}finally{if(g)throw i}}var o=!0,p=!1,q=void 0;try{for(var r,s=d.private_channels[Symbol.iterator]();!(o=(r=s.next()).done);o=!0){var t=r.value;b.addPMChannel(t)}}catch(e){p=!0,q=e}finally{try{!o&&s["return"]&&s["return"]()}finally{if(p)throw q}}b.trigger("ready"),b.readyTime=Date.now(),b.debug("cached "+b.serverCache.length+" servers, "+b.channelCache.length+" channels, "+b.pmChannelCache.length+" PMs and "+b.userCache.length+" users."),b.state=3,setInterval(function(){b.keepAlive.apply(b)},d.heartbeat_interval);break;case"MESSAGE_CREATE":b.debug("received message");var u=[];d.mentions=d.mentions||[];var v=!0,w=!1,x=void 0;try{for(var y,z=d.mentions[Symbol.iterator]();!(v=(y=z.next()).done);v=!0){var A=y.value;u.push(b.addUser(A))}}catch(e){w=!0,x=e}finally{try{!v&&z["return"]&&z["return"]()}finally{if(w)throw x}}var B=b.getChannel("id",d.channel_id);if(B){var C=B.addMessage(new k(d,B,u,b.addUser(d.author)));b.trigger("message",C)}break;case"MESSAGE_DELETE":b.debug("message deleted");var B=b.getChannel("id",d.channel_id),D=B.getMessage("id",d.id);D?(b.trigger("messageDelete",B,D),B.messages.splice(B.messages.indexOf(D),1)):b.trigger("messageDelete",B);break;case"MESSAGE_UPDATE":b.debug("message updated");var B=b.getChannel("id",d.channel_id),E=B.getMessage("id",d.id);if(E){var F={};for(var G in E)F[G]=E[G];for(var G in d)F[G]=d[G];var u=[],H=!0,I=!1,J=void 0;try{for(var K,L=F.mentions[Symbol.iterator]();!(H=(K=L.next()).done);H=!0){var A=K.value;u.push(b.addUser(A))}}catch(e){I=!0,J=e}finally{try{!H&&L["return"]&&L["return"]()}finally{if(I)throw J}}var M=new k(F,B,u,E.author);b.trigger("messageUpdate",M,E),B.messages[B.messages.indexOf(E)]=M}break;case"GUILD_DELETE":var n=b.getServer("id",d.id);n&&(b.serverCache.splice(b.serverCache.indexOf(n),1),b.trigger("serverDelete",n));break;case"CHANNEL_DELETE":var B=b.getChannel("id",d.id);if(B){var n=B.server;n&&n.channels.splice(n.channels.indexOf(B),1),b.trigger("channelDelete",B),b.serverCache.splice(b.serverCache.indexOf(B),1)}break;case"GUILD_CREATE":var n=b.getServer("id",d.id);if(n||(n=b.addServer(d)),b.serverCreateListener.get(d.id)){var N=b.serverCreateListener.get(d.id);N[0](n),N[1](null,n),b.serverCreateListener["delete"](d.id)}b.trigger("serverCreate",n);break;case"CHANNEL_CREATE":var B=b.getChannel("id",d.id);if(!B){var O=b.addChannel(d,d.guild_id),P=b.getServer("id",d.guild_id);P&&P.addChannel(O),b.trigger("channelCreate",O)}break;case"GUILD_MEMBER_ADD":var n=b.getServer("id",d.guild_id);if(n){var Q=b.addUser(d.user);~n.members.indexOf(Q)||n.members.push(Q),b.trigger("serverNewMember",Q)}break;case"GUILD_MEMBER_REMOVE":var n=b.getServer("id",d.guild_id);if(n){var Q=b.addUser(d.user);~n.members.indexOf(Q)&&n.members.splice(n.members.indexOf(Q),1),b.trigger("serverRemoveMember",Q)}break;case"USER_UPDATE":if(b.user&&d.id===b.user.id){var R=new h(d);b.trigger("userUpdate",R,b.user),~b.userCache.indexOf(b.user)&&(b.userCache[b.userCache.indexOf(b.user)]=R),b.user=R}break;case"PRESENCE_UPDATE":var S=b.getUser("id",d.user.id);if(S){var T=new h(d.user);T.equalsStrict(S)?b.trigger("presence",{user:S,status:d.status,server:b.getServer("id",d.guild_id),gameId:d.game_id}):(b.trigger("userUpdate",S,T),b.userCache[b.userCache.indexOf(S)]=T)}break;default:b.debug("received unknown packet"),b.trigger("unknown",c)}}}},{key:"addUser",value:function(a){return this.getUser("id",a.id)||this.userCache.push(new h(a)),this.getUser("id",a.id)}},{key:"addChannel",value:function(a,b){return this.getChannel("id",a.id)||this.channelCache.push(new j(a,this.getServer("id",b))),this.getChannel("id",a.id)}},{key:"addPMChannel",value:function(a){return this.getPMChannel("id",a.id)||this.pmChannelCache.push(new m(a,this)),this.getPMChannel("id",a.id)}},{key:"addServer",value:function(a){var b=this.getServer("id",a.id);if(!b&&(b=new i(a,this),this.serverCache.push(b),a.channels)){var c=!0,d=!1,e=void 0;try{for(var f,g=a.channels[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;b.channels.push(this.addChannel(h,b.id))}}catch(j){d=!0,e=j}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}}return b}},{key:"getUser",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.userCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"getChannel",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.channelCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return this.getPMChannel(a,b)}},{key:"getPMChannel",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.pmChannelCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"getServer",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.serverCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"trySendConnData",value:function(){if(this.token&&!this.alreadySentData){this.alreadySentData=!0;var a={op:2,d:{token:this.token,v:2,properties:{$os:"discord.js",$browser:"discord.js",$device:"discord.js",$referrer:"",$referring_domain:""}}};this.websocket.send(JSON.stringify(a))}}},{key:"resolveServerID",value:function(a){return a instanceof i?a.id:!isNaN(a)&&a.length&&17===a.length?a:void 0}},{key:"resolveDestination",value:function(a){var b=!1,c=this;return new Promise(function(d,e){if(a instanceof i)b=a.id;else if(a instanceof j)b=a.id;else if(a instanceof k)b=a.channel.id;else if(a instanceof h){var f=!0,g=!1,l=void 0;try{for(var m,n=c.pmChannelCache[Symbol.iterator]();!(f=(m=n.next()).done);f=!0){var o=m.value;if(o.user.equals(a))return o.id}}catch(p){g=!0,l=p}finally{try{!f&&n["return"]&&n["return"]()}finally{if(g)throw l}}c.startPM(a).then(function(a){d(a.id)})["catch"](e)}else b=a;b&&d(b)})}},{key:"_sendMessage",value:function(a,b,c,d){var e=this;return new Promise(function(f,h){n.post(g.CHANNELS+"/"+a+"/messages").set("authorization",e.token).send({content:b,mentions:d,tts:c}).end(function(a,b){if(a)h(a);else{var c=b.body,d=[];c.mentions=c.mentions||[];var g=!0,i=!1,j=void 0;try{for(var l,m=c.mentions[Symbol.iterator]();!(g=(l=m.next()).done);g=!0){var n=l.value;d.push(e.addUser(n))}}catch(a){i=!0,j=a}finally{try{!g&&m["return"]&&m["return"]()}finally{if(i)throw j}}var o=e.getChannel("id",c.channel_id);if(o){var p=o.addMessage(new k(c,o,d,e.addUser(c.author)));f(p)}}})})}},{key:"_sendFile",value:function(a,b){var c=arguments.length<=2||void 0===arguments[2]?"DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png":arguments[2],d=this;return new Promise(function(e,f){n.post(g.CHANNELS+"/"+a+"/messages").set("authorization",d.token).attach("file",b,c).end(function(b,c){if(b)f(b);else{var g=d.getChannel("id",a);if(g){var h=g.addMessage(new k(c.body,g,[],d.user));e(h)}}})})}},{key:"_updateMessage",value:function(a,b){var c=this;return new Promise(function(d,e){n.patch(g.CHANNELS+"/"+a.channel.id+"/messages/"+a.id).set("authorization",c.token).send({content:b,mentions:[]}).end(function(b,c){if(b)e(b);else{var f=new k(c.body,a.channel,a.mentions,a.sender);d(f),a.channel.messages[a.channel.messages.indexOf(a)]=f}})})}},{key:"_deleteMessage",value:function(a){var b=this;return new Promise(function(c,d){n.del(g.CHANNELS+"/"+a.channel.id+"/messages/"+a.id).set("authorization",b.token).end(function(a,b){a?d(a):c()})})}},{key:"checkQueue",value:function(a){var b=this,c=this;this.checkingQueue[a]||!function(){var d=function f(){if(0===c.queue[a].length)return void e();var b=c.queue[a][0];switch(b.action){case"sendMessage":var d=b;c._sendMessage(a,d.content,d.tts,d.mentions).then(function(b){d.then(b),c.queue[a].shift(),f()})["catch"](function(b){d.error(b),c.queue[a].shift(),f()});break;case"sendFile":var g=b;c._sendFile(a,g.attachment,g.attachmentName).then(function(b){g.then(b),c.queue[a].shift(),f()})["catch"](function(b){g.error(b),c.queue[a].shift(),f()});break;case"updateMessage":var h=b;c._updateMessage(h.message,h.content).then(function(b){h.then(b),c.queue[a].shift(),f()})["catch"](function(b){h.error(b),c.queue[a].shift(),f()});break;case"deleteMessage":var i=b;c._deleteMessage(i.message).then(function(b){i.then(b),c.queue[a].shift(),f()})["catch"](function(b){i.error(b),c.queue[a].shift(),f()});break;default:e()}},e=function(){c.checkingQueue[a]=!1};b.checkingQueue[a]=!0,d()}()}},{key:"uptime",get:function(){return this.readyTime?Date.now()-this.readyTime:null}},{key:"ready",get:function(){return 3===this.state}},{key:"servers",get:function(){return this.serverCache}},{key:"channels",get:function(){return this.channelCache}},{key:"users",get:function(){return this.userCache}},{key:"PMChannels",get:function(){return this.pmChannelCache}},{key:"messages",get:function(){var a=[],b=!0,c=!1,d=void 0;try{for(var e,f=this.channelCache[Symbol.iterator]();!(b=(e=f.next()).done);b=!0){var g=e.value;a=a.concat(g.messages)}}catch(h){c=!0,d=h}finally{try{!b&&f["return"]&&f["return"]()}finally{if(c)throw d}}return a}}]),a}();b.exports=r},{"./Endpoints.js":2,"./PMChannel.js":3,"./channel.js":4,"./invite.js":6,"./message.js":7,"./server.js":8,"./user.js":9,fs:10,superagent:11,ws:14}],2:[function(a,b,c){"use strict";c.BASE_DOMAIN="discordapp.com",c.BASE="https://"+c.BASE_DOMAIN,c.WEBSOCKET_HUB="wss://"+c.BASE_DOMAIN+"/hub",c.API=c.BASE+"/api",c.AUTH=c.API+"/auth",c.LOGIN=c.AUTH+"/login",c.LOGOUT=c.AUTH+"/logout",c.USERS=c.API+"/users",c.SERVERS=c.API+"/guilds",c.CHANNELS=c.API+"/channels"},{}],3:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c"}},{key:"toString",value:function(){return this.mention()}},{key:"equals",value:function(a){return a.id===this.id}},{key:"equalsStrict",value:function(a){return a.id===this.id&&a.avatar===this.avatar&&a.username===this.username&&a.discriminator===this.discriminator}},{key:"avatarURL",get:function(){return this.avatar?"https://discordapp.com/api/users/"+this.id+"/avatars/"+this.avatar+".jpg":null}}]),a}();b.exports=f},{}],10:[function(a,b,c){},{}],11:[function(a,b,c){function d(){}function e(a){var b={}.toString.call(a);switch(b){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function f(a){return a===Object(a)}function g(a){if(!f(a))return a;var b=[];for(var c in a)null!=a[c]&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")}function h(a){for(var b,c,d={},e=a.split("&"),f=0,g=e.length;g>f;++f)c=e[f],b=c.split("="),d[decodeURIComponent(b[0])]=decodeURIComponent(b[1]);return d}function i(a){var b,c,d,e,f=a.split(/\r?\n/),g={};f.pop();for(var h=0,i=f.length;i>h;++h)c=f[h],b=c.indexOf(":"),d=c.slice(0,b).toLowerCase(),e=r(c.slice(b+1)),g[d]=e;return g}function j(a){return a.split(/ *; */).shift()}function k(a){return p(a.split(/ *; */),function(a,b){var c=b.split(/ *= */),d=c.shift(),e=c.shift();return d&&e&&(a[d]=e),a},{})}function l(a,b){b=b||{},this.req=a,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||"undefined"==typeof this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText,this.setStatusProperties(this.xhr.status),this.header=this.headers=i(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body="HEAD"!=this.req.method?this.parseBody(this.text?this.text:this.xhr.response):null}function m(a,b){var c=this;o.call(this),this._query=this._query||[],this.method=a,this.url=b,this.header={},this._header={},this.on("end",function(){var a=null,b=null;try{b=new l(c)}catch(d){return a=new Error("Parser is unable to parse the response"),a.parse=!0,a.original=d,c.callback(a)}if(c.emit("response",b),a)return c.callback(a,b);if(b.status>=200&&b.status<300)return c.callback(a,b);var e=new Error(b.statusText||"Unsuccessful HTTP response");e.original=a,e.response=b,e.status=b.status,c.callback(e,b)})}function n(a,b){return"function"==typeof b?new m("GET",a).end(b):1==arguments.length?new m("GET",a):new m(a,b)}var o=a("emitter"),p=a("reduce"),q="undefined"==typeof window?this||self:window;n.getXHR=function(){if(!(!q.XMLHttpRequest||q.location&&"file:"==q.location.protocol&&q.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(a){}return!1};var r="".trim?function(a){return a.trim()}:function(a){return a.replace(/(^\s*|\s*$)/g,"")};n.serializeObject=g,n.parseString=h,n.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},n.serialize={"application/x-www-form-urlencoded":g,"application/json":JSON.stringify},n.parse={"application/x-www-form-urlencoded":h,"application/json":JSON.parse},l.prototype.get=function(a){return this.header[a.toLowerCase()]},l.prototype.setHeaderProperties=function(a){var b=this.header["content-type"]||"";this.type=j(b);var c=k(b);for(var d in c)this[d]=c[d]},l.prototype.parseBody=function(a){var b=n.parse[this.type];return b&&a&&(a.length||a instanceof Object)?b(a):null},l.prototype.setStatusProperties=function(a){1223===a&&(a=204);var b=a/100|0;this.status=a,this.statusType=b,this.info=1==b,this.ok=2==b,this.clientError=4==b,this.serverError=5==b,this.error=4==b||5==b?this.toError():!1,this.accepted=202==a,this.noContent=204==a,this.badRequest=400==a,this.unauthorized=401==a,this.notAcceptable=406==a,this.notFound=404==a,this.forbidden=403==a},l.prototype.toError=function(){var a=this.req,b=a.method,c=a.url,d="cannot "+b+" "+c+" ("+this.status+")",e=new Error(d);return e.status=this.status,e.method=b,e.url=c,e},n.Response=l,o(m.prototype),m.prototype.use=function(a){return a(this),this},m.prototype.timeout=function(a){return this._timeout=a,this},m.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},m.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(), +this.clearTimeout(),this.emit("abort"),this)},m.prototype.set=function(a,b){if(f(a)){for(var c in a)this.set(c,a[c]);return this}return this._header[a.toLowerCase()]=b,this.header[a]=b,this},m.prototype.unset=function(a){return delete this._header[a.toLowerCase()],delete this.header[a],this},m.prototype.getHeader=function(a){return this._header[a.toLowerCase()]},m.prototype.type=function(a){return this.set("Content-Type",n.types[a]||a),this},m.prototype.accept=function(a){return this.set("Accept",n.types[a]||a),this},m.prototype.auth=function(a,b){var c=btoa(a+":"+b);return this.set("Authorization","Basic "+c),this},m.prototype.query=function(a){return"string"!=typeof a&&(a=g(a)),a&&this._query.push(a),this},m.prototype.field=function(a,b){return this._formData||(this._formData=new q.FormData),this._formData.append(a,b),this},m.prototype.attach=function(a,b,c){return this._formData||(this._formData=new q.FormData),this._formData.append(a,b,c),this},m.prototype.send=function(a){var b=f(a),c=this.getHeader("Content-Type");if(b&&f(this._data))for(var d in a)this._data[d]=a[d];else"string"==typeof a?(c||this.type("form"),c=this.getHeader("Content-Type"),"application/x-www-form-urlencoded"==c?this._data=this._data?this._data+"&"+a:a:this._data=(this._data||"")+a):this._data=a;return!b||e(a)?this:(c||this.type("json"),this)},m.prototype.callback=function(a,b){var c=this._callback;this.clearTimeout(),c(a,b)},m.prototype.crossDomainError=function(){var a=new Error("Origin is not allowed by Access-Control-Allow-Origin");a.crossDomain=!0,this.callback(a)},m.prototype.timeoutError=function(){var a=this._timeout,b=new Error("timeout of "+a+"ms exceeded");b.timeout=a,this.callback(b)},m.prototype.withCredentials=function(){return this._withCredentials=!0,this},m.prototype.end=function(a){var b=this,c=this.xhr=n.getXHR(),f=this._query.join("&"),g=this._timeout,h=this._formData||this._data;this._callback=a||d,c.onreadystatechange=function(){if(4==c.readyState){var a;try{a=c.status}catch(d){a=0}if(0==a){if(b.timedout)return b.timeoutError();if(b.aborted)return;return b.crossDomainError()}b.emit("end")}};var i=function(a){a.total>0&&(a.percent=a.loaded/a.total*100),b.emit("progress",a)};this.hasListeners("progress")&&(c.onprogress=i);try{c.upload&&this.hasListeners("progress")&&(c.upload.onprogress=i)}catch(j){}if(g&&!this._timer&&(this._timer=setTimeout(function(){b.timedout=!0,b.abort()},g)),f&&(f=n.serializeObject(f),this.url+=~this.url.indexOf("?")?"&"+f:"?"+f),c.open(this.method,this.url,!0),this._withCredentials&&(c.withCredentials=!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof h&&!e(h)){var k=this.getHeader("Content-Type"),l=n.serialize[k?k.split(";")[0]:""];l&&(h=l(h))}for(var m in this.header)null!=this.header[m]&&c.setRequestHeader(m,this.header[m]);return this.emit("request",this),c.send(h),this},m.prototype.then=function(a,b){return this.end(function(c,d){c?b(c):a(d)})},n.Request=m,n.get=function(a,b,c){var d=n("GET",a);return"function"==typeof b&&(c=b,b=null),b&&d.query(b),c&&d.end(c),d},n.head=function(a,b,c){var d=n("HEAD",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.del=function(a,b){var c=n("DELETE",a);return b&&c.end(b),c},n.patch=function(a,b,c){var d=n("PATCH",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.post=function(a,b,c){var d=n("POST",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.put=function(a,b,c){var d=n("PUT",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},b.exports=n},{emitter:12,reduce:13}],12:[function(a,b,c){function d(a){return a?e(a):void 0}function e(a){for(var b in d.prototype)a[b]=d.prototype[b];return a}b.exports=d,d.prototype.on=d.prototype.addEventListener=function(a,b){return this._callbacks=this._callbacks||{},(this._callbacks[a]=this._callbacks[a]||[]).push(b),this},d.prototype.once=function(a,b){function c(){d.off(a,c),b.apply(this,arguments)}var d=this;return this._callbacks=this._callbacks||{},c.fn=b,this.on(a,c),this},d.prototype.off=d.prototype.removeListener=d.prototype.removeAllListeners=d.prototype.removeEventListener=function(a,b){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var c=this._callbacks[a];if(!c)return this;if(1==arguments.length)return delete this._callbacks[a],this;for(var d,e=0;ed;++d)c[d].apply(this,b)}return this},d.prototype.listeners=function(a){return this._callbacks=this._callbacks||{},this._callbacks[a]||[]},d.prototype.hasListeners=function(a){return!!this.listeners(a).length}},{}],13:[function(a,b,c){b.exports=function(a,b,c){for(var d=0,e=a.length,f=3==arguments.length?c:a[d++];e>d;)f=b.call(null,f,a[d],++d,a);return f}},{}],14:[function(a,b,c){function d(a,b,c){var d;return d=b?new f(a,b):new f(a)}var e=function(){return this}(),f=e.WebSocket||e.MozWebSocket;b.exports=f?d:null,f&&(d.prototype=f.prototype)},{}]},{},[5])(5)}); \ No newline at end of file From 527947dbd3d939bd0685ae006b2254d7c88c41cf Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 12 Sep 2015 15:46:22 +0100 Subject: [PATCH 012/151] 3.3.1 --- {.settings => .vscode}/settings.json | 0 {.settings => .vscode}/tasks.json | 0 lib/Client.js | 6 +- package.json | 2 +- src/Client.js | 6 +- test/bot.1.js | 3 +- web-dist/discord.3.3.1.js | 3590 ++++++++++++++++++++++++++ web-dist/discord.min.3.3.1.js | 2 + 8 files changed, 3602 insertions(+), 7 deletions(-) rename {.settings => .vscode}/settings.json (100%) rename {.settings => .vscode}/tasks.json (100%) create mode 100644 web-dist/discord.3.3.1.js create mode 100644 web-dist/discord.min.3.3.1.js diff --git a/.settings/settings.json b/.vscode/settings.json similarity index 100% rename from .settings/settings.json rename to .vscode/settings.json diff --git a/.settings/tasks.json b/.vscode/tasks.json similarity index 100% rename from .settings/tasks.json rename to .vscode/tasks.json diff --git a/lib/Client.js b/lib/Client.js index 85119d53a..36ac902e0 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1039,7 +1039,7 @@ var Client = (function () { server.members.push(user); } - self.trigger("serverNewMember", user); + self.trigger("serverNewMember", user, server); } break; @@ -1056,7 +1056,7 @@ var Client = (function () { server.members.splice(server.members.indexOf(user), 1); } - self.trigger("serverRemoveMember", user); + self.trigger("serverRemoveMember", user, server); } break; @@ -1396,6 +1396,7 @@ var Client = (function () { } self.startPM(destination).then(function (pmc) { + console.log(pmc); resolve(pmc.id); })["catch"](reject); } else { @@ -1507,6 +1508,7 @@ var Client = (function () { value: function _deleteMessage(message) { var self = this; return new Promise(function (resolve, reject) { + request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).end(function (err, res) { if (err) { reject(err); diff --git a/package.json b/package.json index e1c2cc82f..0eddd6cfa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.3.0", + "version": "3.3.1", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { diff --git a/src/Client.js b/src/Client.js index 03cb6a577..f4c4c1287 100644 --- a/src/Client.js +++ b/src/Client.js @@ -943,7 +943,7 @@ class Client { server.members.push(user); } - self.trigger("serverNewMember", user); + self.trigger("serverNewMember", user, server); } break; @@ -960,7 +960,7 @@ class Client { server.members.splice(server.members.indexOf(user), 1); } - self.trigger("serverRemoveMember", user); + self.trigger("serverRemoveMember", user, server); } break; @@ -1155,6 +1155,7 @@ class Client { //we don't, at this point we're late self.startPM(destination).then(function (pmc) { + console.log(pmc); resolve(pmc.id); }).catch(reject); @@ -1260,6 +1261,7 @@ class Client { _deleteMessage(message){ var self = this; return new Promise(function(resolve, reject){ + request .del(`${Endpoints.CHANNELS}/${message.channel.id}/messages/${message.id}`) .set("authorization", self.token) diff --git a/test/bot.1.js b/test/bot.1.js index 1230b9bb6..f99314baa 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -17,8 +17,7 @@ mybot.on("message", function (message) { } // we can go ahead :) - console.log(message.sender.username); - mybot.sendMessage(message.channel, message.sender.username); + mybot.sendMessage(message.author, message.sender.username); }); mybot.on("ready", function () { diff --git a/web-dist/discord.3.3.1.js b/web-dist/discord.3.3.1.js new file mode 100644 index 000000000..9992d6869 --- /dev/null +++ b/web-dist/discord.3.3.1.js @@ -0,0 +1,3590 @@ +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Discord = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o]*>/g) || [])[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var mention = _step3.value; + + _mentions.push(mention.substring(2, mention.length - 1)); + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3["return"]) { + _iterator3["return"](); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + + return _mentions; + } + }); + + return prom; + } + + //def createws + }, { + key: "createws", + value: function createws(url) { + if (this.websocket) return false; + + var self = this; + + //good to go + this.websocket = new WebSocket(url); + + //open + this.websocket.onopen = function () { + self.trySendConnData(); //try connecting + }; + + //close + this.websocket.onclose = function () { + self.trigger("disconnected"); + }; + + //message + this.websocket.onmessage = function (e) { + + var dat = false, + data = {}; + + try { + dat = JSON.parse(e.data); + data = dat.d; + } catch (err) { + self.trigger("error", err, e); + return; + } + + //valid message + switch (dat.t) { + + case "READY": + self.debug("received ready packet"); + + self.user = self.addUser(data.user); + + var _iteratorNormalCompletion4 = true; + var _didIteratorError4 = false; + var _iteratorError4 = undefined; + + try { + for (var _iterator4 = data.guilds[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var _server = _step4.value; + + var server = self.addServer(_server); + } + } catch (err) { + _didIteratorError4 = true; + _iteratorError4 = err; + } finally { + try { + if (!_iteratorNormalCompletion4 && _iterator4["return"]) { + _iterator4["return"](); + } + } finally { + if (_didIteratorError4) { + throw _iteratorError4; + } + } + } + + var _iteratorNormalCompletion5 = true; + var _didIteratorError5 = false; + var _iteratorError5 = undefined; + + try { + for (var _iterator5 = data.private_channels[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { + var _pmc = _step5.value; + + var pmc = self.addPMChannel(_pmc); + } + } catch (err) { + _didIteratorError5 = true; + _iteratorError5 = err; + } finally { + try { + if (!_iteratorNormalCompletion5 && _iterator5["return"]) { + _iterator5["return"](); + } + } finally { + if (_didIteratorError5) { + throw _iteratorError5; + } + } + } + + self.trigger("ready"); + self.readyTime = Date.now(); + self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users."); + self.state = 3; + setInterval(function () { + self.keepAlive.apply(self); + }, data.heartbeat_interval); + + break; + case "MESSAGE_CREATE": + self.debug("received message"); + + var mentions = []; + data.mentions = data.mentions || []; //for some reason this was not defined at some point? + var _iteratorNormalCompletion6 = true; + var _didIteratorError6 = false; + var _iteratorError6 = undefined; + + try { + for (var _iterator6 = data.mentions[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { + var mention = _step6.value; + + mentions.push(self.addUser(mention)); + } + } catch (err) { + _didIteratorError6 = true; + _iteratorError6 = err; + } finally { + try { + if (!_iteratorNormalCompletion6 && _iterator6["return"]) { + _iterator6["return"](); + } + } finally { + if (_didIteratorError6) { + throw _iteratorError6; + } + } + } + + var channel = self.getChannel("id", data.channel_id); + if (channel) { + var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); + self.trigger("message", msg); + } + + break; + case "MESSAGE_DELETE": + self.debug("message deleted"); + + var channel = self.getChannel("id", data.channel_id); + var message = channel.getMessage("id", data.id); + if (message) { + self.trigger("messageDelete", channel, message); + channel.messages.splice(channel.messages.indexOf(message), 1); + } else { + //don't have the cache of that message ;( + self.trigger("messageDelete", channel); + } + break; + case "MESSAGE_UPDATE": + self.debug("message updated"); + + var channel = self.getChannel("id", data.channel_id); + var formerMessage = channel.getMessage("id", data.id); + + if (formerMessage) { + + //new message might be partial, so we need to fill it with whatever the old message was. + var info = {}; + + for (var key in formerMessage) { + info[key] = formerMessage[key]; + } + + for (var key in data) { + info[key] = data[key]; + } + + var mentions = []; + var _iteratorNormalCompletion7 = true; + var _didIteratorError7 = false; + var _iteratorError7 = undefined; + + try { + for (var _iterator7 = info.mentions[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { + var mention = _step7.value; + + mentions.push(self.addUser(mention)); + } + } catch (err) { + _didIteratorError7 = true; + _iteratorError7 = err; + } finally { + try { + if (!_iteratorNormalCompletion7 && _iterator7["return"]) { + _iterator7["return"](); + } + } finally { + if (_didIteratorError7) { + throw _iteratorError7; + } + } + } + + var newMessage = new Message(info, channel, mentions, formerMessage.author); + + self.trigger("messageUpdate", newMessage, formerMessage); + + channel.messages[channel.messages.indexOf(formerMessage)] = newMessage; + } + + // message isn't in cache, and if it's a partial it could cause + // all hell to break loose... best to just act as if nothing happened + + break; + + case "GUILD_DELETE": + + var server = self.getServer("id", data.id); + + if (server) { + self.serverCache.splice(self.serverCache.indexOf(server), 1); + self.trigger("serverDelete", server); + } + + break; + + case "CHANNEL_DELETE": + + var channel = self.getChannel("id", data.id); + + if (channel) { + + var server = channel.server; + + if (server) { + + server.channels.splice(server.channels.indexOf(channel), 1); + } + + self.trigger("channelDelete", channel); + + self.serverCache.splice(self.serverCache.indexOf(channel), 1); + } + + break; + + case "GUILD_CREATE": + + var server = self.getServer("id", data.id); + + if (!server) { + //if server doesn't already exist because duh + server = self.addServer(data); + } /*else if(server.channels.length === 0){ + + var srv = new Server(data, self); + for(channel of data.channels){ + srv.channels.push(new Channel(channel, data.id)); + } + self.serverCache[self.serverCache.indexOf(server)] = srv; + + }*/ + + if (self.serverCreateListener.get(data.id)) { + var cbs = self.serverCreateListener.get(data.id); + cbs[0](server); //promise then callback + cbs[1](null, server); //legacy callback + self.serverCreateListener["delete"](data.id); + } + + self.trigger("serverCreate", server); + + break; + + case "CHANNEL_CREATE": + + var channel = self.getChannel("id", data.id); + + if (!channel) { + + var chann = self.addChannel(data, data.guild_id); + var srv = self.getServer("id", data.guild_id); + if (srv) { + srv.addChannel(chann); + } + self.trigger("channelCreate", chann); + } + + break; + + case "GUILD_MEMBER_ADD": + + var server = self.getServer("id", data.guild_id); + + if (server) { + + var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. + + if (! ~server.members.indexOf(user)) { + server.members.push(user); + } + + self.trigger("serverNewMember", user, server); + } + + break; + + case "GUILD_MEMBER_REMOVE": + + var server = self.getServer("id", data.guild_id); + + if (server) { + + var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. + + if (~server.members.indexOf(user)) { + server.members.splice(server.members.indexOf(user), 1); + } + + self.trigger("serverRemoveMember", user, server); + } + + break; + + case "USER_UPDATE": + + if (self.user && data.id === self.user.id) { + + var newUser = new User(data); //not actually adding to the cache + + self.trigger("userUpdate", newUser, self.user); + + if (~self.userCache.indexOf(self.user)) { + self.userCache[self.userCache.indexOf(self.user)] = newUser; + } + + self.user = newUser; + } + + break; + + case "PRESENCE_UPDATE": + + var userInCache = self.getUser("id", data.user.id); + + if (userInCache) { + //user exists + var presenceUser = new User(data.user); + if (presenceUser.equalsStrict(userInCache)) { + //they're exactly the same, an actual presence update + self.trigger("presence", { + user: userInCache, + status: data.status, + server: self.getServer("id", data.guild_id), + gameId: data.game_id + }); + } else { + //one of their details changed. + self.trigger("userUpdate", userInCache, presenceUser); + self.userCache[self.userCache.indexOf(userInCache)] = presenceUser; + } + } + + break; + + default: + self.debug("received unknown packet"); + self.trigger("unknown", dat); + break; + + } + }; + } + + //def addUser + }, { + key: "addUser", + value: function addUser(data) { + if (!this.getUser("id", data.id)) { + this.userCache.push(new User(data)); + } + return this.getUser("id", data.id); + } + + //def addChannel + }, { + key: "addChannel", + value: function addChannel(data, serverId) { + if (!this.getChannel("id", data.id)) { + this.channelCache.push(new Channel(data, this.getServer("id", serverId))); + } + return this.getChannel("id", data.id); + } + }, { + key: "addPMChannel", + value: function addPMChannel(data) { + if (!this.getPMChannel("id", data.id)) { + this.pmChannelCache.push(new PMChannel(data, this)); + } + return this.getPMChannel("id", data.id); + } + + //def addServer + }, { + key: "addServer", + value: function addServer(data) { + + var server = this.getServer("id", data.id); + + if (!server) { + server = new Server(data, this); + this.serverCache.push(server); + if (data.channels) { + var _iteratorNormalCompletion8 = true; + var _didIteratorError8 = false; + var _iteratorError8 = undefined; + + try { + for (var _iterator8 = data.channels[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) { + var channel = _step8.value; + + server.channels.push(this.addChannel(channel, server.id)); + } + } catch (err) { + _didIteratorError8 = true; + _iteratorError8 = err; + } finally { + try { + if (!_iteratorNormalCompletion8 && _iterator8["return"]) { + _iterator8["return"](); + } + } finally { + if (_didIteratorError8) { + throw _iteratorError8; + } + } + } + } + } + + return server; + } + + //def getUser + }, { + key: "getUser", + value: function getUser(key, value) { + var _iteratorNormalCompletion9 = true; + var _didIteratorError9 = false; + var _iteratorError9 = undefined; + + try { + for (var _iterator9 = this.userCache[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) { + var user = _step9.value; + + if (user[key] === value) { + return user; + } + } + } catch (err) { + _didIteratorError9 = true; + _iteratorError9 = err; + } finally { + try { + if (!_iteratorNormalCompletion9 && _iterator9["return"]) { + _iterator9["return"](); + } + } finally { + if (_didIteratorError9) { + throw _iteratorError9; + } + } + } + + return null; + } + + //def getChannel + }, { + key: "getChannel", + value: function getChannel(key, value) { + var _iteratorNormalCompletion10 = true; + var _didIteratorError10 = false; + var _iteratorError10 = undefined; + + try { + for (var _iterator10 = this.channelCache[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) { + var channel = _step10.value; + + if (channel[key] === value) { + return channel; + } + } + } catch (err) { + _didIteratorError10 = true; + _iteratorError10 = err; + } finally { + try { + if (!_iteratorNormalCompletion10 && _iterator10["return"]) { + _iterator10["return"](); + } + } finally { + if (_didIteratorError10) { + throw _iteratorError10; + } + } + } + + return this.getPMChannel(key, value); //might be a PM + } + }, { + key: "getPMChannel", + value: function getPMChannel(key, value) { + var _iteratorNormalCompletion11 = true; + var _didIteratorError11 = false; + var _iteratorError11 = undefined; + + try { + for (var _iterator11 = this.pmChannelCache[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) { + var channel = _step11.value; + + if (channel[key] === value) { + return channel; + } + } + } catch (err) { + _didIteratorError11 = true; + _iteratorError11 = err; + } finally { + try { + if (!_iteratorNormalCompletion11 && _iterator11["return"]) { + _iterator11["return"](); + } + } finally { + if (_didIteratorError11) { + throw _iteratorError11; + } + } + } + + return null; + } + + //def getServer + }, { + key: "getServer", + value: function getServer(key, value) { + var _iteratorNormalCompletion12 = true; + var _didIteratorError12 = false; + var _iteratorError12 = undefined; + + try { + for (var _iterator12 = this.serverCache[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) { + var server = _step12.value; + + if (server[key] === value) { + return server; + } + } + } catch (err) { + _didIteratorError12 = true; + _iteratorError12 = err; + } finally { + try { + if (!_iteratorNormalCompletion12 && _iterator12["return"]) { + _iterator12["return"](); + } + } finally { + if (_didIteratorError12) { + throw _iteratorError12; + } + } + } + + return null; + } + + //def trySendConnData + }, { + key: "trySendConnData", + value: function trySendConnData() { + + if (this.token && !this.alreadySentData) { + + this.alreadySentData = true; + + var data = { + op: 2, + d: { + token: this.token, + v: 2, + properties: { + "$os": "discord.js", + "$browser": "discord.js", + "$device": "discord.js", + "$referrer": "", + "$referring_domain": "" + } + } + }; + this.websocket.send(JSON.stringify(data)); + } + } + }, { + key: "resolveServerID", + value: function resolveServerID(resource) { + + if (resource instanceof Server) { + return resource.id; + } else if (!isNaN(resource) && resource.length && resource.length === 17) { + return resource; + } + } + }, { + key: "resolveDestination", + value: function resolveDestination(destination) { + var channId = false; + var self = this; + + return new Promise(function (resolve, reject) { + if (destination instanceof Server) { + channId = destination.id; //general is the same as server id + } else if (destination instanceof Channel) { + channId = destination.id; + } else if (destination instanceof Message) { + channId = destination.channel.id; + } else if (destination instanceof User) { + + //check if we have a PM + var _iteratorNormalCompletion13 = true; + var _didIteratorError13 = false; + var _iteratorError13 = undefined; + + try { + for (var _iterator13 = self.pmChannelCache[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) { + var pmc = _step13.value; + + if (pmc.user.equals(destination)) { + return pmc.id; + } + } + + //we don't, at this point we're late + } catch (err) { + _didIteratorError13 = true; + _iteratorError13 = err; + } finally { + try { + if (!_iteratorNormalCompletion13 && _iterator13["return"]) { + _iterator13["return"](); + } + } finally { + if (_didIteratorError13) { + throw _iteratorError13; + } + } + } + + self.startPM(destination).then(function (pmc) { + resolve(pmc.id); + })["catch"](reject); + } else { + channId = destination; + } + if (channId) resolve(channId); + }); + } + }, { + key: "_sendMessage", + value: function _sendMessage(destination, content, tts, mentions) { + + var self = this; + + return new Promise(function (resolve, reject) { + request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).send({ + content: content, + mentions: mentions, + tts: tts + }).end(function (err, res) { + + if (err) { + reject(err); + } else { + var data = res.body; + + var mentions = []; + + data.mentions = data.mentions || []; //for some reason this was not defined at some point? + + var _iteratorNormalCompletion14 = true; + var _didIteratorError14 = false; + var _iteratorError14 = undefined; + + try { + for (var _iterator14 = data.mentions[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) { + var mention = _step14.value; + + mentions.push(self.addUser(mention)); + } + } catch (err) { + _didIteratorError14 = true; + _iteratorError14 = err; + } finally { + try { + if (!_iteratorNormalCompletion14 && _iterator14["return"]) { + _iterator14["return"](); + } + } finally { + if (_didIteratorError14) { + throw _iteratorError14; + } + } + } + + var channel = self.getChannel("id", data.channel_id); + if (channel) { + var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); + resolve(msg); + } + } + }); + }); + } + }, { + key: "_sendFile", + value: function _sendFile(destination, attachment) { + var attachmentName = arguments.length <= 2 || arguments[2] === undefined ? "DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png" : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).attach("file", attachment, attachmentName).end(function (err, res) { + + if (err) { + reject(err); + } else { + + var chann = self.getChannel("id", destination); + if (chann) { + var msg = chann.addMessage(new Message(res.body, chann, [], self.user)); + resolve(msg); + } + } + }); + }); + } + }, { + key: "_updateMessage", + value: function _updateMessage(message, content) { + var self = this; + return new Promise(function (resolve, reject) { + request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).send({ + content: content, + mentions: [] + }).end(function (err, res) { + if (err) { + reject(err); + } else { + var msg = new Message(res.body, message.channel, message.mentions, message.sender); + resolve(msg); + message.channel.messages[message.channel.messages.indexOf(message)] = msg; + } + }); + }); + } + }, { + key: "_deleteMessage", + value: function _deleteMessage(message) { + var self = this; + return new Promise(function (resolve, reject) { + request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + }); + } + }, { + key: "checkQueue", + value: function checkQueue(channelID) { + var _this = this; + + var self = this; + + if (!this.checkingQueue[channelID]) { + (function () { + var doNext = function doNext() { + if (self.queue[channelID].length === 0) { + done(); + return; + } + var queuedEvent = self.queue[channelID][0]; + switch (queuedEvent.action) { + case "sendMessage": + var msgToSend = queuedEvent; + self._sendMessage(channelID, msgToSend.content, msgToSend.tts, msgToSend.mentions).then(function (msg) { + msgToSend.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + msgToSend.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + case "sendFile": + var fileToSend = queuedEvent; + self._sendFile(channelID, fileToSend.attachment, fileToSend.attachmentName).then(function (msg) { + fileToSend.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + fileToSend.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + case "updateMessage": + var msgToUpd = queuedEvent; + self._updateMessage(msgToUpd.message, msgToUpd.content).then(function (msg) { + msgToUpd.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + msgToUpd.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + case "deleteMessage": + var msgToDel = queuedEvent; + self._deleteMessage(msgToDel.message).then(function (msg) { + msgToDel.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + msgToDel.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + default: + done(); + break; + } + }; + + var done = function done() { + self.checkingQueue[channelID] = false; + return; + }; + + //if we aren't already checking this queue. + _this.checkingQueue[channelID] = true; + doNext(); + })(); + } + } + }, { + key: "uptime", + get: function get() { + + return this.readyTime ? Date.now() - this.readyTime : null; + } + }, { + key: "ready", + get: function get() { + return this.state === 3; + } + }, { + key: "servers", + get: function get() { + return this.serverCache; + } + }, { + key: "channels", + get: function get() { + return this.channelCache; + } + }, { + key: "users", + get: function get() { + return this.userCache; + } + }, { + key: "PMChannels", + get: function get() { + return this.pmChannelCache; + } + }, { + key: "messages", + get: function get() { + + var msgs = []; + var _iteratorNormalCompletion15 = true; + var _didIteratorError15 = false; + var _iteratorError15 = undefined; + + try { + for (var _iterator15 = this.channelCache[Symbol.iterator](), _step15; !(_iteratorNormalCompletion15 = (_step15 = _iterator15.next()).done); _iteratorNormalCompletion15 = true) { + var channel = _step15.value; + + msgs = msgs.concat(channel.messages); + } + } catch (err) { + _didIteratorError15 = true; + _iteratorError15 = err; + } finally { + try { + if (!_iteratorNormalCompletion15 && _iterator15["return"]) { + _iterator15["return"](); + } + } finally { + if (_didIteratorError15) { + throw _iteratorError15; + } + } + } + + return msgs; + } + }]); + + return Client; +})(); + +function getGateway() { + + var self = this; + + return new Promise(function (resolve, reject) { + request.get(Endpoints.API + "/gateway").end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(res.body.url); + } + }); + }); +} + +module.exports = Client; +},{"./Endpoints.js":2,"./PMChannel.js":3,"./channel.js":4,"./invite.js":6,"./message.js":7,"./server.js":8,"./user.js":9,"fs":10,"superagent":11,"ws":14}],2:[function(require,module,exports){ +"use strict"; + +exports.BASE_DOMAIN = "discordapp.com"; +exports.BASE = "https://" + exports.BASE_DOMAIN; +exports.WEBSOCKET_HUB = "wss://" + exports.BASE_DOMAIN + "/hub"; + +exports.API = exports.BASE + "/api"; +exports.AUTH = exports.API + "/auth"; +exports.LOGIN = exports.AUTH + "/login"; +exports.LOGOUT = exports.AUTH + "/logout"; +exports.USERS = exports.API + "/users"; +exports.SERVERS = exports.API + "/guilds"; +exports.CHANNELS = exports.API + "/channels"; +},{}],3:[function(require,module,exports){ +"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 PMChannel = (function () { + function PMChannel(data, client) { + _classCallCheck(this, PMChannel); + + this.user = client.getUser("id", data.recipient.id); + this.id = data.id; + this.messages = []; + } + + _createClass(PMChannel, [{ + key: "addMessage", + value: function addMessage(data) { + if (!this.getMessage("id", data.id)) { + this.messages.push(data); + } + return this.getMessage("id", data.id); + } + }, { + key: "getMessage", + value: function getMessage(key, value) { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var message = _step.value; + + if (message[key] === value) { + return message; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return null; + } + }, { + key: "isPrivate", + get: function get() { + return true; + } + }]); + + return PMChannel; +})(); + +module.exports = PMChannel; +},{}],4:[function(require,module,exports){ +"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 Channel = (function () { + function Channel(data, server) { + _classCallCheck(this, Channel); + + this.server = server; + this.name = data.name; + this.type = data.type; + this.id = data.id; + this.messages = []; + //this.isPrivate = isPrivate; //not sure about the implementation of this... + } + + _createClass(Channel, [{ + key: "equals", + value: function equals(object) { + return object && object.id === this.id; + } + }, { + key: "addMessage", + value: function addMessage(data) { + if (!this.getMessage("id", data.id)) { + this.messages.push(data); + } + return this.getMessage("id", data.id); + } + }, { + key: "getMessage", + value: function getMessage(key, value) { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var message = _step.value; + + if (message[key] === value) { + return message; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return null; + } + }, { + key: "toString", + value: function toString() { + return "#" + this.name; + } + }, { + key: "client", + get: function get() { + return this.server.client; + } + }, { + key: "isPrivate", + get: function get() { + return false; + } + }]); + + return Channel; +})(); + +module.exports = Channel; +},{}],5:[function(require,module,exports){ +"use strict"; + +var request = require("superagent"); +var Endpoints = require("./Endpoints.js"); +var Client = require("./Client.js"); + +var Discord = { + Endpoints: Endpoints, + Client: Client +}; + +module.exports = Discord; +},{"./Client.js":1,"./Endpoints.js":2,"superagent":11}],6:[function(require,module,exports){ +"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 Invite = (function () { + function Invite(data, client) { + _classCallCheck(this, Invite); + + this.max_age = data.max_age; + this.code = data.code; + this.server = client.getServer("id", data.guild.id); + this.revoked = data.revoked; + this.created_at = Date.parse(data.created_at); + this.temporary = data.temporary; + this.uses = data.uses; + this.max_uses = data.uses; + this.inviter = client.addUser(data.inviter); + this.xkcd = data.xkcdpass; + this.channel = client.getChannel("id", data.channel.id); + } + + _createClass(Invite, [{ + key: "URL", + get: function get() { + var code = this.xkcd ? this.xkcdpass : this.code; + return "https://discord.gg/" + code; + } + }]); + + return Invite; +})(); + +module.exports = Invite; +},{}],7:[function(require,module,exports){ +"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 PMChannel = require("./PMChannel.js"); + +var Message = (function () { + function Message(data, channel, mentions, author) { + _classCallCheck(this, Message); + + this.tts = data.tts; + this.timestamp = Date.parse(data.timestamp); + this.nonce = data.nonce; + this.mentions = mentions; + this.everyoneMentioned = data.mention_everyone; + this.id = data.id; + this.embeds = data.embeds; + this.editedTimestamp = data.edited_timestamp; + this.content = data.content.trim(); + this.channel = channel; + this.author = author; + this.attachments = data.attachments; + } + + /*exports.Message.prototype.isPM = function() { + return ( this.channel instanceof PMChannel ); + }*/ + + _createClass(Message, [{ + key: "isMentioned", + value: function isMentioned(user) { + var id = user.id ? user.id : user; + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.mentions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var mention = _step.value; + + if (mention.id === id) { + return true; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return false; + } + }, { + key: "sender", + get: function get() { + return this.author; + } + }, { + key: "isPrivate", + get: function get() { + return this.channel.isPrivate; + } + }]); + + return Message; +})(); + +module.exports = Message; +},{"./PMChannel.js":3}],8:[function(require,module,exports){ +"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 = (function () { + function Server(data, client) { + _classCallCheck(this, Server); + + this.client = client; + this.region = data.region; + this.ownerID = data.owner_id; + this.name = data.name; + this.id = data.id; + this.members = []; + this.channels = []; + this.icon = data.icon; + this.afkTimeout = data.afk_timeout; + this.afkChannelId = data.afk_channel_id; + + if (!data.members) { + data.members = [client.user]; + return; + } + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = data.members[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var member = _step.value; + + // first we cache the user in our Discord Client, + // then we add it to our list. This way when we + // get a user from this server's member list, + // it will be identical (unless an async change occurred) + // to the client's cache. + if (member.user) this.members.push(client.addUser(member.user)); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + } + + _createClass(Server, [{ + key: "getChannel", + + // get/set + value: function getChannel(key, value) { + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = this.channels[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var channel = _step2.value; + + if (channel[key] === value) { + return channel; + } + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2["return"]) { + _iterator2["return"](); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + + return null; + } + }, { + key: "getMember", + value: function getMember(key, value) { + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = this.members[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var member = _step3.value; + + if (member[key] === value) { + return member; + } + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3["return"]) { + _iterator3["return"](); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + + return null; + } + }, { + key: "addChannel", + value: function addChannel(chann) { + if (!this.getChannel("id", chann.id)) { + this.channels.push(chann); + } + return chann; + } + }, { + key: "addMember", + value: function addMember(member) { + if (!this.getMember("id", member.id)) { + this.members.push(member); + } + return member; + } + }, { + key: "toString", + value: function toString() { + return this.name; + } + }, { + key: "iconURL", + get: function get() { + if (!this.icon) return null; + return "https://discordapp.com/api/guilds/" + this.id + "/icons/" + this.icon + ".jpg"; + } + }, { + key: "afkChannel", + get: function get() { + if (!this.afkChannelId) return false; + + return this.getChannel("id", this.afkChannelId); + } + }, { + key: "defaultChannel", + get: function get() { + return this.getChannel("name", "general"); + } + }, { + key: "owner", + get: function get() { + return this.client.getUser("id", this.ownerID); + } + }]); + + return Server; +})(); + +module.exports = Server; +},{}],9:[function(require,module,exports){ +"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 User = (function () { + function User(data) { + _classCallCheck(this, User); + + this.username = data.username; + this.discriminator = data.discriminator; + this.id = data.id; + this.avatar = data.avatar; + } + + // access using user.avatarURL; + + _createClass(User, [{ + key: "mention", + value: function mention() { + return "<@" + this.id + ">"; + } + }, { + key: "toString", + value: function toString() { + /* + if we embed a user in a String - like so: + "Yo " + user + " what's up?" + It would generate something along the lines of: + "Yo @hydrabolt what's up?" + */ + return this.mention(); + } + }, { + key: "equals", + value: function equals(object) { + return object.id === this.id; + } + }, { + key: "equalsStrict", + value: function equalsStrict(object) { + return object.id === this.id && object.avatar === this.avatar && object.username === this.username && object.discriminator === this.discriminator; + } + }, { + key: "avatarURL", + get: function get() { + if (!this.avatar) return null; + return "https://discordapp.com/api/users/" + this.id + "/avatars/" + this.avatar + ".jpg"; + } + }]); + + return User; +})(); + +module.exports = User; +},{}],10:[function(require,module,exports){ + +},{}],11:[function(require,module,exports){ +/** + * Module dependencies. + */ + +var Emitter = require('emitter'); +var reduce = require('reduce'); + +/** + * Root reference for iframes. + */ + +var root = 'undefined' == typeof window + ? (this || self) + : window; + +/** + * Noop. + */ + +function noop(){}; + +/** + * Check if `obj` is a host object, + * we don't want to serialize these :) + * + * TODO: future proof, move to compoent land + * + * @param {Object} obj + * @return {Boolean} + * @api private + */ + +function isHost(obj) { + var str = {}.toString.call(obj); + + switch (str) { + case '[object File]': + case '[object Blob]': + case '[object FormData]': + return true; + default: + return false; + } +} + +/** + * Determine XHR. + */ + +request.getXHR = function () { + if (root.XMLHttpRequest + && (!root.location || 'file:' != root.location.protocol + || !root.ActiveXObject)) { + return new XMLHttpRequest; + } else { + try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {} + } + return false; +}; + +/** + * Removes leading and trailing whitespace, added to support IE. + * + * @param {String} s + * @return {String} + * @api private + */ + +var trim = ''.trim + ? function(s) { return s.trim(); } + : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); }; + +/** + * Check if `obj` is an object. + * + * @param {Object} obj + * @return {Boolean} + * @api private + */ + +function isObject(obj) { + return obj === Object(obj); +} + +/** + * Serialize the given `obj`. + * + * @param {Object} obj + * @return {String} + * @api private + */ + +function serialize(obj) { + if (!isObject(obj)) return obj; + var pairs = []; + for (var key in obj) { + if (null != obj[key]) { + pairs.push(encodeURIComponent(key) + + '=' + encodeURIComponent(obj[key])); + } + } + return pairs.join('&'); +} + +/** + * Expose serialization method. + */ + + request.serializeObject = serialize; + + /** + * Parse the given x-www-form-urlencoded `str`. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function parseString(str) { + var obj = {}; + var pairs = str.split('&'); + var parts; + var pair; + + for (var i = 0, len = pairs.length; i < len; ++i) { + pair = pairs[i]; + parts = pair.split('='); + obj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]); + } + + return obj; +} + +/** + * Expose parser. + */ + +request.parseString = parseString; + +/** + * Default MIME type map. + * + * superagent.types.xml = 'application/xml'; + * + */ + +request.types = { + html: 'text/html', + json: 'application/json', + xml: 'application/xml', + urlencoded: 'application/x-www-form-urlencoded', + 'form': 'application/x-www-form-urlencoded', + 'form-data': 'application/x-www-form-urlencoded' +}; + +/** + * Default serialization map. + * + * superagent.serialize['application/xml'] = function(obj){ + * return 'generated xml here'; + * }; + * + */ + + request.serialize = { + 'application/x-www-form-urlencoded': serialize, + 'application/json': JSON.stringify + }; + + /** + * Default parsers. + * + * superagent.parse['application/xml'] = function(str){ + * return { object parsed from str }; + * }; + * + */ + +request.parse = { + 'application/x-www-form-urlencoded': parseString, + 'application/json': JSON.parse +}; + +/** + * Parse the given header `str` into + * an object containing the mapped fields. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function parseHeader(str) { + var lines = str.split(/\r?\n/); + var fields = {}; + var index; + var line; + var field; + var val; + + lines.pop(); // trailing CRLF + + for (var i = 0, len = lines.length; i < len; ++i) { + line = lines[i]; + index = line.indexOf(':'); + field = line.slice(0, index).toLowerCase(); + val = trim(line.slice(index + 1)); + fields[field] = val; + } + + return fields; +} + +/** + * Return the mime type for the given `str`. + * + * @param {String} str + * @return {String} + * @api private + */ + +function type(str){ + return str.split(/ *; */).shift(); +}; + +/** + * Return header field parameters. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function params(str){ + return reduce(str.split(/ *; */), function(obj, str){ + var parts = str.split(/ *= */) + , key = parts.shift() + , val = parts.shift(); + + if (key && val) obj[key] = val; + return obj; + }, {}); +}; + +/** + * Initialize a new `Response` with the given `xhr`. + * + * - set flags (.ok, .error, etc) + * - parse header + * + * Examples: + * + * Aliasing `superagent` as `request` is nice: + * + * request = superagent; + * + * We can use the promise-like API, or pass callbacks: + * + * request.get('/').end(function(res){}); + * request.get('/', function(res){}); + * + * Sending data can be chained: + * + * request + * .post('/user') + * .send({ name: 'tj' }) + * .end(function(res){}); + * + * Or passed to `.send()`: + * + * request + * .post('/user') + * .send({ name: 'tj' }, function(res){}); + * + * Or passed to `.post()`: + * + * request + * .post('/user', { name: 'tj' }) + * .end(function(res){}); + * + * Or further reduced to a single call for simple cases: + * + * request + * .post('/user', { name: 'tj' }, function(res){}); + * + * @param {XMLHTTPRequest} xhr + * @param {Object} options + * @api private + */ + +function Response(req, options) { + options = options || {}; + this.req = req; + this.xhr = this.req.xhr; + // responseText is accessible only if responseType is '' or 'text' and on older browsers + this.text = ((this.req.method !='HEAD' && (this.xhr.responseType === '' || this.xhr.responseType === 'text')) || typeof this.xhr.responseType === 'undefined') + ? this.xhr.responseText + : null; + this.statusText = this.req.xhr.statusText; + this.setStatusProperties(this.xhr.status); + this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders()); + // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but + // getResponseHeader still works. so we get content-type even if getting + // other headers fails. + this.header['content-type'] = this.xhr.getResponseHeader('content-type'); + this.setHeaderProperties(this.header); + this.body = this.req.method != 'HEAD' + ? this.parseBody(this.text ? this.text : this.xhr.response) + : null; +} + +/** + * Get case-insensitive `field` value. + * + * @param {String} field + * @return {String} + * @api public + */ + +Response.prototype.get = function(field){ + return this.header[field.toLowerCase()]; +}; + +/** + * Set header related properties: + * + * - `.type` the content type without params + * + * A response of "Content-Type: text/plain; charset=utf-8" + * will provide you with a `.type` of "text/plain". + * + * @param {Object} header + * @api private + */ + +Response.prototype.setHeaderProperties = function(header){ + // content-type + var ct = this.header['content-type'] || ''; + this.type = type(ct); + + // params + var obj = params(ct); + for (var key in obj) this[key] = obj[key]; +}; + +/** + * Parse the given body `str`. + * + * Used for auto-parsing of bodies. Parsers + * are defined on the `superagent.parse` object. + * + * @param {String} str + * @return {Mixed} + * @api private + */ + +Response.prototype.parseBody = function(str){ + var parse = request.parse[this.type]; + return parse && str && (str.length || str instanceof Object) + ? parse(str) + : null; +}; + +/** + * Set flags such as `.ok` based on `status`. + * + * For example a 2xx response will give you a `.ok` of __true__ + * whereas 5xx will be __false__ and `.error` will be __true__. The + * `.clientError` and `.serverError` are also available to be more + * specific, and `.statusType` is the class of error ranging from 1..5 + * sometimes useful for mapping respond colors etc. + * + * "sugar" properties are also defined for common cases. Currently providing: + * + * - .noContent + * - .badRequest + * - .unauthorized + * - .notAcceptable + * - .notFound + * + * @param {Number} status + * @api private + */ + +Response.prototype.setStatusProperties = function(status){ + // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request + if (status === 1223) { + status = 204; + } + + var type = status / 100 | 0; + + // status / class + this.status = status; + this.statusType = type; + + // basics + this.info = 1 == type; + this.ok = 2 == type; + this.clientError = 4 == type; + this.serverError = 5 == type; + this.error = (4 == type || 5 == type) + ? this.toError() + : false; + + // sugar + this.accepted = 202 == status; + this.noContent = 204 == status; + this.badRequest = 400 == status; + this.unauthorized = 401 == status; + this.notAcceptable = 406 == status; + this.notFound = 404 == status; + this.forbidden = 403 == status; +}; + +/** + * Return an `Error` representative of this response. + * + * @return {Error} + * @api public + */ + +Response.prototype.toError = function(){ + var req = this.req; + var method = req.method; + var url = req.url; + + var msg = 'cannot ' + method + ' ' + url + ' (' + this.status + ')'; + var err = new Error(msg); + err.status = this.status; + err.method = method; + err.url = url; + + return err; +}; + +/** + * Expose `Response`. + */ + +request.Response = Response; + +/** + * Initialize a new `Request` with the given `method` and `url`. + * + * @param {String} method + * @param {String} url + * @api public + */ + +function Request(method, url) { + var self = this; + Emitter.call(this); + this._query = this._query || []; + this.method = method; + this.url = url; + this.header = {}; + this._header = {}; + this.on('end', function(){ + var err = null; + var res = null; + + try { + res = new Response(self); + } catch(e) { + err = new Error('Parser is unable to parse the response'); + err.parse = true; + err.original = e; + return self.callback(err); + } + + self.emit('response', res); + + if (err) { + return self.callback(err, res); + } + + if (res.status >= 200 && res.status < 300) { + return self.callback(err, res); + } + + var new_err = new Error(res.statusText || 'Unsuccessful HTTP response'); + new_err.original = err; + new_err.response = res; + new_err.status = res.status; + + self.callback(new_err, res); + }); +} + +/** + * Mixin `Emitter`. + */ + +Emitter(Request.prototype); + +/** + * Allow for extension + */ + +Request.prototype.use = function(fn) { + fn(this); + return this; +} + +/** + * Set timeout to `ms`. + * + * @param {Number} ms + * @return {Request} for chaining + * @api public + */ + +Request.prototype.timeout = function(ms){ + this._timeout = ms; + return this; +}; + +/** + * Clear previous timeout. + * + * @return {Request} for chaining + * @api public + */ + +Request.prototype.clearTimeout = function(){ + this._timeout = 0; + clearTimeout(this._timer); + return this; +}; + +/** + * Abort the request, and clear potential timeout. + * + * @return {Request} + * @api public + */ + +Request.prototype.abort = function(){ + if (this.aborted) return; + this.aborted = true; + this.xhr.abort(); + this.clearTimeout(); + this.emit('abort'); + return this; +}; + +/** + * Set header `field` to `val`, or multiple fields with one object. + * + * Examples: + * + * req.get('/') + * .set('Accept', 'application/json') + * .set('X-API-Key', 'foobar') + * .end(callback); + * + * req.get('/') + * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' }) + * .end(callback); + * + * @param {String|Object} field + * @param {String} val + * @return {Request} for chaining + * @api public + */ + +Request.prototype.set = function(field, val){ + if (isObject(field)) { + for (var key in field) { + this.set(key, field[key]); + } + return this; + } + this._header[field.toLowerCase()] = val; + this.header[field] = val; + return this; +}; + +/** + * Remove header `field`. + * + * Example: + * + * req.get('/') + * .unset('User-Agent') + * .end(callback); + * + * @param {String} field + * @return {Request} for chaining + * @api public + */ + +Request.prototype.unset = function(field){ + delete this._header[field.toLowerCase()]; + delete this.header[field]; + return this; +}; + +/** + * Get case-insensitive header `field` value. + * + * @param {String} field + * @return {String} + * @api private + */ + +Request.prototype.getHeader = function(field){ + return this._header[field.toLowerCase()]; +}; + +/** + * Set Content-Type to `type`, mapping values from `request.types`. + * + * Examples: + * + * superagent.types.xml = 'application/xml'; + * + * request.post('/') + * .type('xml') + * .send(xmlstring) + * .end(callback); + * + * request.post('/') + * .type('application/xml') + * .send(xmlstring) + * .end(callback); + * + * @param {String} type + * @return {Request} for chaining + * @api public + */ + +Request.prototype.type = function(type){ + this.set('Content-Type', request.types[type] || type); + return this; +}; + +/** + * Set Accept to `type`, mapping values from `request.types`. + * + * Examples: + * + * superagent.types.json = 'application/json'; + * + * request.get('/agent') + * .accept('json') + * .end(callback); + * + * request.get('/agent') + * .accept('application/json') + * .end(callback); + * + * @param {String} accept + * @return {Request} for chaining + * @api public + */ + +Request.prototype.accept = function(type){ + this.set('Accept', request.types[type] || type); + return this; +}; + +/** + * Set Authorization field value with `user` and `pass`. + * + * @param {String} user + * @param {String} pass + * @return {Request} for chaining + * @api public + */ + +Request.prototype.auth = function(user, pass){ + var str = btoa(user + ':' + pass); + this.set('Authorization', 'Basic ' + str); + return this; +}; + +/** +* Add query-string `val`. +* +* Examples: +* +* request.get('/shoes') +* .query('size=10') +* .query({ color: 'blue' }) +* +* @param {Object|String} val +* @return {Request} for chaining +* @api public +*/ + +Request.prototype.query = function(val){ + if ('string' != typeof val) val = serialize(val); + if (val) this._query.push(val); + return this; +}; + +/** + * Write the field `name` and `val` for "multipart/form-data" + * request bodies. + * + * ``` js + * request.post('/upload') + * .field('foo', 'bar') + * .end(callback); + * ``` + * + * @param {String} name + * @param {String|Blob|File} val + * @return {Request} for chaining + * @api public + */ + +Request.prototype.field = function(name, val){ + if (!this._formData) this._formData = new root.FormData(); + this._formData.append(name, val); + return this; +}; + +/** + * Queue the given `file` as an attachment to the specified `field`, + * with optional `filename`. + * + * ``` js + * request.post('/upload') + * .attach(new Blob(['hey!'], { type: "text/html"})) + * .end(callback); + * ``` + * + * @param {String} field + * @param {Blob|File} file + * @param {String} filename + * @return {Request} for chaining + * @api public + */ + +Request.prototype.attach = function(field, file, filename){ + if (!this._formData) this._formData = new root.FormData(); + this._formData.append(field, file, filename); + return this; +}; + +/** + * Send `data`, defaulting the `.type()` to "json" when + * an object is given. + * + * Examples: + * + * // querystring + * request.get('/search') + * .end(callback) + * + * // multiple data "writes" + * request.get('/search') + * .send({ search: 'query' }) + * .send({ range: '1..5' }) + * .send({ order: 'desc' }) + * .end(callback) + * + * // manual json + * request.post('/user') + * .type('json') + * .send('{"name":"tj"}) + * .end(callback) + * + * // auto json + * request.post('/user') + * .send({ name: 'tj' }) + * .end(callback) + * + * // manual x-www-form-urlencoded + * request.post('/user') + * .type('form') + * .send('name=tj') + * .end(callback) + * + * // auto x-www-form-urlencoded + * request.post('/user') + * .type('form') + * .send({ name: 'tj' }) + * .end(callback) + * + * // defaults to x-www-form-urlencoded + * request.post('/user') + * .send('name=tobi') + * .send('species=ferret') + * .end(callback) + * + * @param {String|Object} data + * @return {Request} for chaining + * @api public + */ + +Request.prototype.send = function(data){ + var obj = isObject(data); + var type = this.getHeader('Content-Type'); + + // merge + if (obj && isObject(this._data)) { + for (var key in data) { + this._data[key] = data[key]; + } + } else if ('string' == typeof data) { + if (!type) this.type('form'); + type = this.getHeader('Content-Type'); + if ('application/x-www-form-urlencoded' == type) { + this._data = this._data + ? this._data + '&' + data + : data; + } else { + this._data = (this._data || '') + data; + } + } else { + this._data = data; + } + + if (!obj || isHost(data)) return this; + if (!type) this.type('json'); + return this; +}; + +/** + * Invoke the callback with `err` and `res` + * and handle arity check. + * + * @param {Error} err + * @param {Response} res + * @api private + */ + +Request.prototype.callback = function(err, res){ + var fn = this._callback; + this.clearTimeout(); + fn(err, res); +}; + +/** + * Invoke callback with x-domain error. + * + * @api private + */ + +Request.prototype.crossDomainError = function(){ + var err = new Error('Origin is not allowed by Access-Control-Allow-Origin'); + err.crossDomain = true; + this.callback(err); +}; + +/** + * Invoke callback with timeout error. + * + * @api private + */ + +Request.prototype.timeoutError = function(){ + var timeout = this._timeout; + var err = new Error('timeout of ' + timeout + 'ms exceeded'); + err.timeout = timeout; + this.callback(err); +}; + +/** + * Enable transmission of cookies with x-domain requests. + * + * Note that for this to work the origin must not be + * using "Access-Control-Allow-Origin" with a wildcard, + * and also must set "Access-Control-Allow-Credentials" + * to "true". + * + * @api public + */ + +Request.prototype.withCredentials = function(){ + this._withCredentials = true; + return this; +}; + +/** + * Initiate request, invoking callback `fn(res)` + * with an instanceof `Response`. + * + * @param {Function} fn + * @return {Request} for chaining + * @api public + */ + +Request.prototype.end = function(fn){ + var self = this; + var xhr = this.xhr = request.getXHR(); + var query = this._query.join('&'); + var timeout = this._timeout; + var data = this._formData || this._data; + + // store callback + this._callback = fn || noop; + + // state change + xhr.onreadystatechange = function(){ + if (4 != xhr.readyState) return; + + // In IE9, reads to any property (e.g. status) off of an aborted XHR will + // result in the error "Could not complete the operation due to error c00c023f" + var status; + try { status = xhr.status } catch(e) { status = 0; } + + if (0 == status) { + if (self.timedout) return self.timeoutError(); + if (self.aborted) return; + return self.crossDomainError(); + } + self.emit('end'); + }; + + // progress + var handleProgress = function(e){ + if (e.total > 0) { + e.percent = e.loaded / e.total * 100; + } + self.emit('progress', e); + }; + if (this.hasListeners('progress')) { + xhr.onprogress = handleProgress; + } + try { + if (xhr.upload && this.hasListeners('progress')) { + xhr.upload.onprogress = handleProgress; + } + } catch(e) { + // Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist. + // Reported here: + // https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context + } + + // timeout + if (timeout && !this._timer) { + this._timer = setTimeout(function(){ + self.timedout = true; + self.abort(); + }, timeout); + } + + // querystring + if (query) { + query = request.serializeObject(query); + this.url += ~this.url.indexOf('?') + ? '&' + query + : '?' + query; + } + + // initiate request + xhr.open(this.method, this.url, true); + + // CORS + if (this._withCredentials) xhr.withCredentials = true; + + // body + if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) { + // serialize stuff + var contentType = this.getHeader('Content-Type'); + var serialize = request.serialize[contentType ? contentType.split(';')[0] : '']; + if (serialize) data = serialize(data); + } + + // set header fields + for (var field in this.header) { + if (null == this.header[field]) continue; + xhr.setRequestHeader(field, this.header[field]); + } + + // send stuff + this.emit('request', this); + xhr.send(data); + return this; +}; + +/** + * Faux promise support + * + * @param {Function} fulfill + * @param {Function} reject + * @return {Request} + */ + +Request.prototype.then = function (fulfill, reject) { + return this.end(function(err, res) { + err ? reject(err) : fulfill(res); + }); +} + +/** + * Expose `Request`. + */ + +request.Request = Request; + +/** + * Issue a request: + * + * Examples: + * + * request('GET', '/users').end(callback) + * request('/users').end(callback) + * request('/users', callback) + * + * @param {String} method + * @param {String|Function} url or callback + * @return {Request} + * @api public + */ + +function request(method, url) { + // callback + if ('function' == typeof url) { + return new Request('GET', method).end(url); + } + + // url first + if (1 == arguments.length) { + return new Request('GET', method); + } + + return new Request(method, url); +} + +/** + * GET `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.get = function(url, data, fn){ + var req = request('GET', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.query(data); + if (fn) req.end(fn); + return req; +}; + +/** + * HEAD `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.head = function(url, data, fn){ + var req = request('HEAD', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * DELETE `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.del = function(url, fn){ + var req = request('DELETE', url); + if (fn) req.end(fn); + return req; +}; + +/** + * PATCH `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed} data + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.patch = function(url, data, fn){ + var req = request('PATCH', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * POST `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed} data + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.post = function(url, data, fn){ + var req = request('POST', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * PUT `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.put = function(url, data, fn){ + var req = request('PUT', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * Expose `request`. + */ + +module.exports = request; + +},{"emitter":12,"reduce":13}],12:[function(require,module,exports){ + +/** + * Expose `Emitter`. + */ + +module.exports = Emitter; + +/** + * Initialize a new `Emitter`. + * + * @api public + */ + +function Emitter(obj) { + if (obj) return mixin(obj); +}; + +/** + * Mixin the emitter properties. + * + * @param {Object} obj + * @return {Object} + * @api private + */ + +function mixin(obj) { + for (var key in Emitter.prototype) { + obj[key] = Emitter.prototype[key]; + } + return obj; +} + +/** + * Listen on the given `event` with `fn`. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.on = +Emitter.prototype.addEventListener = function(event, fn){ + this._callbacks = this._callbacks || {}; + (this._callbacks[event] = this._callbacks[event] || []) + .push(fn); + return this; +}; + +/** + * Adds an `event` listener that will be invoked a single + * time then automatically removed. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.once = function(event, fn){ + var self = this; + this._callbacks = this._callbacks || {}; + + function on() { + self.off(event, on); + fn.apply(this, arguments); + } + + on.fn = fn; + this.on(event, on); + return this; +}; + +/** + * Remove the given callback for `event` or all + * registered callbacks. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.off = +Emitter.prototype.removeListener = +Emitter.prototype.removeAllListeners = +Emitter.prototype.removeEventListener = function(event, fn){ + this._callbacks = this._callbacks || {}; + + // all + if (0 == arguments.length) { + this._callbacks = {}; + return this; + } + + // specific event + var callbacks = this._callbacks[event]; + if (!callbacks) return this; + + // remove all handlers + if (1 == arguments.length) { + delete this._callbacks[event]; + return this; + } + + // remove specific handler + var cb; + for (var i = 0; i < callbacks.length; i++) { + cb = callbacks[i]; + if (cb === fn || cb.fn === fn) { + callbacks.splice(i, 1); + break; + } + } + return this; +}; + +/** + * Emit `event` with the given args. + * + * @param {String} event + * @param {Mixed} ... + * @return {Emitter} + */ + +Emitter.prototype.emit = function(event){ + this._callbacks = this._callbacks || {}; + var args = [].slice.call(arguments, 1) + , callbacks = this._callbacks[event]; + + if (callbacks) { + callbacks = callbacks.slice(0); + for (var i = 0, len = callbacks.length; i < len; ++i) { + callbacks[i].apply(this, args); + } + } + + return this; +}; + +/** + * Return array of callbacks for `event`. + * + * @param {String} event + * @return {Array} + * @api public + */ + +Emitter.prototype.listeners = function(event){ + this._callbacks = this._callbacks || {}; + return this._callbacks[event] || []; +}; + +/** + * Check if this emitter has `event` handlers. + * + * @param {String} event + * @return {Boolean} + * @api public + */ + +Emitter.prototype.hasListeners = function(event){ + return !! this.listeners(event).length; +}; + +},{}],13:[function(require,module,exports){ + +/** + * Reduce `arr` with `fn`. + * + * @param {Array} arr + * @param {Function} fn + * @param {Mixed} initial + * + * TODO: combatible error handling? + */ + +module.exports = function(arr, fn, initial){ + var idx = 0; + var len = arr.length; + var curr = arguments.length == 3 + ? initial + : arr[idx++]; + + while (idx < len) { + curr = fn.call(null, curr, arr[idx], ++idx, arr); + } + + return curr; +}; +},{}],14:[function(require,module,exports){ + +/** + * Module dependencies. + */ + +var global = (function() { return this; })(); + +/** + * WebSocket constructor. + */ + +var WebSocket = global.WebSocket || global.MozWebSocket; + +/** + * Module exports. + */ + +module.exports = WebSocket ? ws : null; + +/** + * WebSocket constructor. + * + * The third `opts` options object gets ignored in web browsers, since it's + * non-standard, and throws a TypeError if passed to the constructor. + * See: https://github.com/einaros/ws/issues/227 + * + * @param {String} uri + * @param {Array} protocols (optional) + * @param {Object) opts (optional) + * @api public + */ + +function ws(uri, protocols, opts) { + var instance; + if (protocols) { + instance = new WebSocket(uri, protocols); + } else { + instance = new WebSocket(uri); + } + return instance; +} + +if (WebSocket) ws.prototype = WebSocket.prototype; + +},{}]},{},[5])(5) +}); \ No newline at end of file diff --git a/web-dist/discord.min.3.3.1.js b/web-dist/discord.min.3.3.1.js new file mode 100644 index 000000000..2079f39b6 --- /dev/null +++ b/web-dist/discord.min.3.3.1.js @@ -0,0 +1,2 @@ +!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Discord=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g]*>/g)||[])[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;a.push(h.substring(2,h.length-1))}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return a}"function"==typeof c&&(d=c,c=!1),b=e+n(b);var p=o();f.resolveDestination(a).then(k)["catch"](j)});return g}},{key:"createws",value:function(a){if(this.websocket)return!1;var b=this;this.websocket=new o(a),this.websocket.onopen=function(){b.trySendConnData()},this.websocket.onclose=function(){b.trigger("disconnected")},this.websocket.onmessage=function(a){var c=!1,d={};try{c=JSON.parse(a.data),d=c.d}catch(e){return void b.trigger("error",e,a)}switch(c.t){case"READY":b.debug("received ready packet"),b.user=b.addUser(d.user);var f=!0,g=!1,i=void 0;try{for(var j,l=d.guilds[Symbol.iterator]();!(f=(j=l.next()).done);f=!0)var m=j.value,n=b.addServer(m)}catch(e){g=!0,i=e}finally{try{!f&&l["return"]&&l["return"]()}finally{if(g)throw i}}var o=!0,p=!1,q=void 0;try{for(var r,s=d.private_channels[Symbol.iterator]();!(o=(r=s.next()).done);o=!0){var t=r.value;b.addPMChannel(t)}}catch(e){p=!0,q=e}finally{try{!o&&s["return"]&&s["return"]()}finally{if(p)throw q}}b.trigger("ready"),b.readyTime=Date.now(),b.debug("cached "+b.serverCache.length+" servers, "+b.channelCache.length+" channels, "+b.pmChannelCache.length+" PMs and "+b.userCache.length+" users."),b.state=3,setInterval(function(){b.keepAlive.apply(b)},d.heartbeat_interval);break;case"MESSAGE_CREATE":b.debug("received message");var u=[];d.mentions=d.mentions||[];var v=!0,w=!1,x=void 0;try{for(var y,z=d.mentions[Symbol.iterator]();!(v=(y=z.next()).done);v=!0){var A=y.value;u.push(b.addUser(A))}}catch(e){w=!0,x=e}finally{try{!v&&z["return"]&&z["return"]()}finally{if(w)throw x}}var B=b.getChannel("id",d.channel_id);if(B){var C=B.addMessage(new k(d,B,u,b.addUser(d.author)));b.trigger("message",C)}break;case"MESSAGE_DELETE":b.debug("message deleted");var B=b.getChannel("id",d.channel_id),D=B.getMessage("id",d.id);D?(b.trigger("messageDelete",B,D),B.messages.splice(B.messages.indexOf(D),1)):b.trigger("messageDelete",B);break;case"MESSAGE_UPDATE":b.debug("message updated");var B=b.getChannel("id",d.channel_id),E=B.getMessage("id",d.id);if(E){var F={};for(var G in E)F[G]=E[G];for(var G in d)F[G]=d[G];var u=[],H=!0,I=!1,J=void 0;try{for(var K,L=F.mentions[Symbol.iterator]();!(H=(K=L.next()).done);H=!0){var A=K.value;u.push(b.addUser(A))}}catch(e){I=!0,J=e}finally{try{!H&&L["return"]&&L["return"]()}finally{if(I)throw J}}var M=new k(F,B,u,E.author);b.trigger("messageUpdate",M,E),B.messages[B.messages.indexOf(E)]=M}break;case"GUILD_DELETE":var n=b.getServer("id",d.id);n&&(b.serverCache.splice(b.serverCache.indexOf(n),1),b.trigger("serverDelete",n));break;case"CHANNEL_DELETE":var B=b.getChannel("id",d.id);if(B){var n=B.server;n&&n.channels.splice(n.channels.indexOf(B),1),b.trigger("channelDelete",B),b.serverCache.splice(b.serverCache.indexOf(B),1)}break;case"GUILD_CREATE":var n=b.getServer("id",d.id);if(n||(n=b.addServer(d)),b.serverCreateListener.get(d.id)){var N=b.serverCreateListener.get(d.id);N[0](n),N[1](null,n),b.serverCreateListener["delete"](d.id)}b.trigger("serverCreate",n);break;case"CHANNEL_CREATE":var B=b.getChannel("id",d.id);if(!B){var O=b.addChannel(d,d.guild_id),P=b.getServer("id",d.guild_id);P&&P.addChannel(O),b.trigger("channelCreate",O)}break;case"GUILD_MEMBER_ADD":var n=b.getServer("id",d.guild_id);if(n){var Q=b.addUser(d.user);~n.members.indexOf(Q)||n.members.push(Q),b.trigger("serverNewMember",Q,n)}break;case"GUILD_MEMBER_REMOVE":var n=b.getServer("id",d.guild_id);if(n){var Q=b.addUser(d.user);~n.members.indexOf(Q)&&n.members.splice(n.members.indexOf(Q),1),b.trigger("serverRemoveMember",Q,n)}break;case"USER_UPDATE":if(b.user&&d.id===b.user.id){var R=new h(d);b.trigger("userUpdate",R,b.user),~b.userCache.indexOf(b.user)&&(b.userCache[b.userCache.indexOf(b.user)]=R),b.user=R}break;case"PRESENCE_UPDATE":var S=b.getUser("id",d.user.id);if(S){var T=new h(d.user);T.equalsStrict(S)?b.trigger("presence",{user:S,status:d.status,server:b.getServer("id",d.guild_id),gameId:d.game_id}):(b.trigger("userUpdate",S,T),b.userCache[b.userCache.indexOf(S)]=T)}break;default:b.debug("received unknown packet"),b.trigger("unknown",c)}}}},{key:"addUser",value:function(a){return this.getUser("id",a.id)||this.userCache.push(new h(a)),this.getUser("id",a.id)}},{key:"addChannel",value:function(a,b){return this.getChannel("id",a.id)||this.channelCache.push(new j(a,this.getServer("id",b))),this.getChannel("id",a.id)}},{key:"addPMChannel",value:function(a){return this.getPMChannel("id",a.id)||this.pmChannelCache.push(new m(a,this)),this.getPMChannel("id",a.id)}},{key:"addServer",value:function(a){var b=this.getServer("id",a.id);if(!b&&(b=new i(a,this),this.serverCache.push(b),a.channels)){var c=!0,d=!1,e=void 0;try{for(var f,g=a.channels[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;b.channels.push(this.addChannel(h,b.id))}}catch(j){d=!0,e=j}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}}return b}},{key:"getUser",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.userCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"getChannel",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.channelCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return this.getPMChannel(a,b)}},{key:"getPMChannel",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.pmChannelCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"getServer",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.serverCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"trySendConnData",value:function(){if(this.token&&!this.alreadySentData){this.alreadySentData=!0;var a={op:2,d:{token:this.token,v:2,properties:{$os:"discord.js",$browser:"discord.js",$device:"discord.js",$referrer:"",$referring_domain:""}}};this.websocket.send(JSON.stringify(a))}}},{key:"resolveServerID",value:function(a){return a instanceof i?a.id:!isNaN(a)&&a.length&&17===a.length?a:void 0}},{key:"resolveDestination",value:function(a){var b=!1,c=this;return new Promise(function(d,e){if(a instanceof i)b=a.id;else if(a instanceof j)b=a.id;else if(a instanceof k)b=a.channel.id;else if(a instanceof h){var f=!0,g=!1,l=void 0;try{for(var m,n=c.pmChannelCache[Symbol.iterator]();!(f=(m=n.next()).done);f=!0){var o=m.value;if(o.user.equals(a))return o.id}}catch(p){g=!0,l=p}finally{try{!f&&n["return"]&&n["return"]()}finally{if(g)throw l}}c.startPM(a).then(function(a){d(a.id)})["catch"](e)}else b=a;b&&d(b)})}},{key:"_sendMessage",value:function(a,b,c,d){var e=this;return new Promise(function(f,h){n.post(g.CHANNELS+"/"+a+"/messages").set("authorization",e.token).send({content:b,mentions:d,tts:c}).end(function(a,b){if(a)h(a);else{var c=b.body,d=[];c.mentions=c.mentions||[];var g=!0,i=!1,j=void 0;try{for(var l,m=c.mentions[Symbol.iterator]();!(g=(l=m.next()).done);g=!0){var n=l.value;d.push(e.addUser(n))}}catch(a){i=!0,j=a}finally{try{!g&&m["return"]&&m["return"]()}finally{if(i)throw j}}var o=e.getChannel("id",c.channel_id);if(o){var p=o.addMessage(new k(c,o,d,e.addUser(c.author)));f(p)}}})})}},{key:"_sendFile",value:function(a,b){var c=arguments.length<=2||void 0===arguments[2]?"DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png":arguments[2],d=this;return new Promise(function(e,f){n.post(g.CHANNELS+"/"+a+"/messages").set("authorization",d.token).attach("file",b,c).end(function(b,c){if(b)f(b);else{var g=d.getChannel("id",a);if(g){var h=g.addMessage(new k(c.body,g,[],d.user));e(h)}}})})}},{key:"_updateMessage",value:function(a,b){var c=this;return new Promise(function(d,e){n.patch(g.CHANNELS+"/"+a.channel.id+"/messages/"+a.id).set("authorization",c.token).send({content:b,mentions:[]}).end(function(b,c){if(b)e(b);else{var f=new k(c.body,a.channel,a.mentions,a.sender);d(f),a.channel.messages[a.channel.messages.indexOf(a)]=f}})})}},{key:"_deleteMessage",value:function(a){var b=this;return new Promise(function(c,d){n.del(g.CHANNELS+"/"+a.channel.id+"/messages/"+a.id).set("authorization",b.token).end(function(a,b){a?d(a):c()})})}},{key:"checkQueue",value:function(a){var b=this,c=this;this.checkingQueue[a]||!function(){var d=function f(){if(0===c.queue[a].length)return void e();var b=c.queue[a][0];switch(b.action){case"sendMessage":var d=b;c._sendMessage(a,d.content,d.tts,d.mentions).then(function(b){d.then(b),c.queue[a].shift(),f()})["catch"](function(b){d.error(b),c.queue[a].shift(),f()});break;case"sendFile":var g=b;c._sendFile(a,g.attachment,g.attachmentName).then(function(b){g.then(b),c.queue[a].shift(),f()})["catch"](function(b){g.error(b),c.queue[a].shift(),f()});break;case"updateMessage":var h=b;c._updateMessage(h.message,h.content).then(function(b){h.then(b),c.queue[a].shift(),f()})["catch"](function(b){h.error(b),c.queue[a].shift(),f()});break;case"deleteMessage":var i=b;c._deleteMessage(i.message).then(function(b){i.then(b),c.queue[a].shift(),f()})["catch"](function(b){i.error(b),c.queue[a].shift(),f()});break;default:e()}},e=function(){c.checkingQueue[a]=!1};b.checkingQueue[a]=!0,d()}()}},{key:"uptime",get:function(){return this.readyTime?Date.now()-this.readyTime:null}},{key:"ready",get:function(){return 3===this.state}},{key:"servers",get:function(){return this.serverCache}},{key:"channels",get:function(){return this.channelCache}},{key:"users",get:function(){return this.userCache}},{key:"PMChannels",get:function(){return this.pmChannelCache}},{key:"messages",get:function(){var a=[],b=!0,c=!1,d=void 0;try{for(var e,f=this.channelCache[Symbol.iterator]();!(b=(e=f.next()).done);b=!0){var g=e.value;a=a.concat(g.messages)}}catch(h){c=!0,d=h}finally{try{!b&&f["return"]&&f["return"]()}finally{if(c)throw d}}return a}}]),a}();b.exports=r},{"./Endpoints.js":2,"./PMChannel.js":3,"./channel.js":4,"./invite.js":6,"./message.js":7,"./server.js":8,"./user.js":9,fs:10,superagent:11,ws:14}],2:[function(a,b,c){"use strict";c.BASE_DOMAIN="discordapp.com",c.BASE="https://"+c.BASE_DOMAIN,c.WEBSOCKET_HUB="wss://"+c.BASE_DOMAIN+"/hub",c.API=c.BASE+"/api",c.AUTH=c.API+"/auth",c.LOGIN=c.AUTH+"/login",c.LOGOUT=c.AUTH+"/logout",c.USERS=c.API+"/users",c.SERVERS=c.API+"/guilds",c.CHANNELS=c.API+"/channels"},{}],3:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c"}},{key:"toString",value:function(){return this.mention()}},{key:"equals",value:function(a){return a.id===this.id}},{key:"equalsStrict",value:function(a){return a.id===this.id&&a.avatar===this.avatar&&a.username===this.username&&a.discriminator===this.discriminator}},{key:"avatarURL",get:function(){return this.avatar?"https://discordapp.com/api/users/"+this.id+"/avatars/"+this.avatar+".jpg":null}}]),a}();b.exports=f},{}],10:[function(a,b,c){},{}],11:[function(a,b,c){function d(){}function e(a){var b={}.toString.call(a);switch(b){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function f(a){return a===Object(a)}function g(a){if(!f(a))return a;var b=[];for(var c in a)null!=a[c]&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")}function h(a){for(var b,c,d={},e=a.split("&"),f=0,g=e.length;g>f;++f)c=e[f],b=c.split("="),d[decodeURIComponent(b[0])]=decodeURIComponent(b[1]);return d}function i(a){var b,c,d,e,f=a.split(/\r?\n/),g={};f.pop();for(var h=0,i=f.length;i>h;++h)c=f[h],b=c.indexOf(":"),d=c.slice(0,b).toLowerCase(),e=r(c.slice(b+1)),g[d]=e;return g}function j(a){return a.split(/ *; */).shift()}function k(a){return p(a.split(/ *; */),function(a,b){var c=b.split(/ *= */),d=c.shift(),e=c.shift();return d&&e&&(a[d]=e),a},{})}function l(a,b){b=b||{},this.req=a,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||"undefined"==typeof this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText,this.setStatusProperties(this.xhr.status),this.header=this.headers=i(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body="HEAD"!=this.req.method?this.parseBody(this.text?this.text:this.xhr.response):null}function m(a,b){var c=this;o.call(this),this._query=this._query||[],this.method=a,this.url=b,this.header={},this._header={},this.on("end",function(){var a=null,b=null;try{b=new l(c)}catch(d){return a=new Error("Parser is unable to parse the response"),a.parse=!0,a.original=d,c.callback(a)}if(c.emit("response",b),a)return c.callback(a,b);if(b.status>=200&&b.status<300)return c.callback(a,b);var e=new Error(b.statusText||"Unsuccessful HTTP response");e.original=a,e.response=b,e.status=b.status,c.callback(e,b)})}function n(a,b){return"function"==typeof b?new m("GET",a).end(b):1==arguments.length?new m("GET",a):new m(a,b)}var o=a("emitter"),p=a("reduce"),q="undefined"==typeof window?this||self:window;n.getXHR=function(){if(!(!q.XMLHttpRequest||q.location&&"file:"==q.location.protocol&&q.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(a){}return!1};var r="".trim?function(a){return a.trim()}:function(a){return a.replace(/(^\s*|\s*$)/g,"")};n.serializeObject=g,n.parseString=h,n.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},n.serialize={"application/x-www-form-urlencoded":g,"application/json":JSON.stringify},n.parse={"application/x-www-form-urlencoded":h,"application/json":JSON.parse},l.prototype.get=function(a){return this.header[a.toLowerCase()]},l.prototype.setHeaderProperties=function(a){var b=this.header["content-type"]||"";this.type=j(b);var c=k(b);for(var d in c)this[d]=c[d]},l.prototype.parseBody=function(a){var b=n.parse[this.type];return b&&a&&(a.length||a instanceof Object)?b(a):null},l.prototype.setStatusProperties=function(a){1223===a&&(a=204);var b=a/100|0;this.status=a,this.statusType=b,this.info=1==b,this.ok=2==b,this.clientError=4==b,this.serverError=5==b,this.error=4==b||5==b?this.toError():!1,this.accepted=202==a,this.noContent=204==a,this.badRequest=400==a,this.unauthorized=401==a,this.notAcceptable=406==a,this.notFound=404==a,this.forbidden=403==a},l.prototype.toError=function(){var a=this.req,b=a.method,c=a.url,d="cannot "+b+" "+c+" ("+this.status+")",e=new Error(d);return e.status=this.status,e.method=b,e.url=c,e},n.Response=l,o(m.prototype),m.prototype.use=function(a){return a(this),this},m.prototype.timeout=function(a){return this._timeout=a,this},m.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},m.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(), +this.clearTimeout(),this.emit("abort"),this)},m.prototype.set=function(a,b){if(f(a)){for(var c in a)this.set(c,a[c]);return this}return this._header[a.toLowerCase()]=b,this.header[a]=b,this},m.prototype.unset=function(a){return delete this._header[a.toLowerCase()],delete this.header[a],this},m.prototype.getHeader=function(a){return this._header[a.toLowerCase()]},m.prototype.type=function(a){return this.set("Content-Type",n.types[a]||a),this},m.prototype.accept=function(a){return this.set("Accept",n.types[a]||a),this},m.prototype.auth=function(a,b){var c=btoa(a+":"+b);return this.set("Authorization","Basic "+c),this},m.prototype.query=function(a){return"string"!=typeof a&&(a=g(a)),a&&this._query.push(a),this},m.prototype.field=function(a,b){return this._formData||(this._formData=new q.FormData),this._formData.append(a,b),this},m.prototype.attach=function(a,b,c){return this._formData||(this._formData=new q.FormData),this._formData.append(a,b,c),this},m.prototype.send=function(a){var b=f(a),c=this.getHeader("Content-Type");if(b&&f(this._data))for(var d in a)this._data[d]=a[d];else"string"==typeof a?(c||this.type("form"),c=this.getHeader("Content-Type"),"application/x-www-form-urlencoded"==c?this._data=this._data?this._data+"&"+a:a:this._data=(this._data||"")+a):this._data=a;return!b||e(a)?this:(c||this.type("json"),this)},m.prototype.callback=function(a,b){var c=this._callback;this.clearTimeout(),c(a,b)},m.prototype.crossDomainError=function(){var a=new Error("Origin is not allowed by Access-Control-Allow-Origin");a.crossDomain=!0,this.callback(a)},m.prototype.timeoutError=function(){var a=this._timeout,b=new Error("timeout of "+a+"ms exceeded");b.timeout=a,this.callback(b)},m.prototype.withCredentials=function(){return this._withCredentials=!0,this},m.prototype.end=function(a){var b=this,c=this.xhr=n.getXHR(),f=this._query.join("&"),g=this._timeout,h=this._formData||this._data;this._callback=a||d,c.onreadystatechange=function(){if(4==c.readyState){var a;try{a=c.status}catch(d){a=0}if(0==a){if(b.timedout)return b.timeoutError();if(b.aborted)return;return b.crossDomainError()}b.emit("end")}};var i=function(a){a.total>0&&(a.percent=a.loaded/a.total*100),b.emit("progress",a)};this.hasListeners("progress")&&(c.onprogress=i);try{c.upload&&this.hasListeners("progress")&&(c.upload.onprogress=i)}catch(j){}if(g&&!this._timer&&(this._timer=setTimeout(function(){b.timedout=!0,b.abort()},g)),f&&(f=n.serializeObject(f),this.url+=~this.url.indexOf("?")?"&"+f:"?"+f),c.open(this.method,this.url,!0),this._withCredentials&&(c.withCredentials=!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof h&&!e(h)){var k=this.getHeader("Content-Type"),l=n.serialize[k?k.split(";")[0]:""];l&&(h=l(h))}for(var m in this.header)null!=this.header[m]&&c.setRequestHeader(m,this.header[m]);return this.emit("request",this),c.send(h),this},m.prototype.then=function(a,b){return this.end(function(c,d){c?b(c):a(d)})},n.Request=m,n.get=function(a,b,c){var d=n("GET",a);return"function"==typeof b&&(c=b,b=null),b&&d.query(b),c&&d.end(c),d},n.head=function(a,b,c){var d=n("HEAD",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.del=function(a,b){var c=n("DELETE",a);return b&&c.end(b),c},n.patch=function(a,b,c){var d=n("PATCH",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.post=function(a,b,c){var d=n("POST",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.put=function(a,b,c){var d=n("PUT",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},b.exports=n},{emitter:12,reduce:13}],12:[function(a,b,c){function d(a){return a?e(a):void 0}function e(a){for(var b in d.prototype)a[b]=d.prototype[b];return a}b.exports=d,d.prototype.on=d.prototype.addEventListener=function(a,b){return this._callbacks=this._callbacks||{},(this._callbacks[a]=this._callbacks[a]||[]).push(b),this},d.prototype.once=function(a,b){function c(){d.off(a,c),b.apply(this,arguments)}var d=this;return this._callbacks=this._callbacks||{},c.fn=b,this.on(a,c),this},d.prototype.off=d.prototype.removeListener=d.prototype.removeAllListeners=d.prototype.removeEventListener=function(a,b){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var c=this._callbacks[a];if(!c)return this;if(1==arguments.length)return delete this._callbacks[a],this;for(var d,e=0;ed;++d)c[d].apply(this,b)}return this},d.prototype.listeners=function(a){return this._callbacks=this._callbacks||{},this._callbacks[a]||[]},d.prototype.hasListeners=function(a){return!!this.listeners(a).length}},{}],13:[function(a,b,c){b.exports=function(a,b,c){for(var d=0,e=a.length,f=3==arguments.length?c:a[d++];e>d;)f=b.call(null,f,a[d],++d,a);return f}},{}],14:[function(a,b,c){function d(a,b,c){var d;return d=b?new f(a,b):new f(a)}var e=function(){return this}(),f=e.WebSocket||e.MozWebSocket;b.exports=f?d:null,f&&(d.prototype=f.prototype)},{}]},{},[5])(5)}); \ No newline at end of file From 8b88fd1ea59507b9912e33c2f1ff7f08e36e5b9a Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 12 Sep 2015 15:49:56 +0100 Subject: [PATCH 013/151] 3.3.2, fixed PMs. --- lib/Client.js | 3 +- package.json | 2 +- src/Client.js | 3 +- web-dist/discord.3.3.2.js | 3593 +++++++++++++++++++++++++++++++++ web-dist/discord.min.3.3.2.js | 2 + 5 files changed, 3600 insertions(+), 3 deletions(-) create mode 100644 web-dist/discord.3.3.2.js create mode 100644 web-dist/discord.min.3.3.2.js diff --git a/lib/Client.js b/lib/Client.js index 36ac902e0..80b9a925f 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1375,7 +1375,8 @@ var Client = (function () { var pmc = _step13.value; if (pmc.user.equals(destination)) { - return pmc.id; + resolve(pmc.id); + return; } } diff --git a/package.json b/package.json index 0eddd6cfa..4af3dbde8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.3.1", + "version": "3.3.2", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { diff --git a/src/Client.js b/src/Client.js index f4c4c1287..6421121e6 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1149,7 +1149,8 @@ class Client { //check if we have a PM for (var pmc of self.pmChannelCache) { if (pmc.user.equals(destination)) { - return pmc.id; + resolve(pmc.id); + return; } } diff --git a/web-dist/discord.3.3.2.js b/web-dist/discord.3.3.2.js new file mode 100644 index 000000000..ee7512e4b --- /dev/null +++ b/web-dist/discord.3.3.2.js @@ -0,0 +1,3593 @@ +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Discord = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o]*>/g) || [])[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var mention = _step3.value; + + _mentions.push(mention.substring(2, mention.length - 1)); + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3["return"]) { + _iterator3["return"](); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + + return _mentions; + } + }); + + return prom; + } + + //def createws + }, { + key: "createws", + value: function createws(url) { + if (this.websocket) return false; + + var self = this; + + //good to go + this.websocket = new WebSocket(url); + + //open + this.websocket.onopen = function () { + self.trySendConnData(); //try connecting + }; + + //close + this.websocket.onclose = function () { + self.trigger("disconnected"); + }; + + //message + this.websocket.onmessage = function (e) { + + var dat = false, + data = {}; + + try { + dat = JSON.parse(e.data); + data = dat.d; + } catch (err) { + self.trigger("error", err, e); + return; + } + + //valid message + switch (dat.t) { + + case "READY": + self.debug("received ready packet"); + + self.user = self.addUser(data.user); + + var _iteratorNormalCompletion4 = true; + var _didIteratorError4 = false; + var _iteratorError4 = undefined; + + try { + for (var _iterator4 = data.guilds[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var _server = _step4.value; + + var server = self.addServer(_server); + } + } catch (err) { + _didIteratorError4 = true; + _iteratorError4 = err; + } finally { + try { + if (!_iteratorNormalCompletion4 && _iterator4["return"]) { + _iterator4["return"](); + } + } finally { + if (_didIteratorError4) { + throw _iteratorError4; + } + } + } + + var _iteratorNormalCompletion5 = true; + var _didIteratorError5 = false; + var _iteratorError5 = undefined; + + try { + for (var _iterator5 = data.private_channels[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { + var _pmc = _step5.value; + + var pmc = self.addPMChannel(_pmc); + } + } catch (err) { + _didIteratorError5 = true; + _iteratorError5 = err; + } finally { + try { + if (!_iteratorNormalCompletion5 && _iterator5["return"]) { + _iterator5["return"](); + } + } finally { + if (_didIteratorError5) { + throw _iteratorError5; + } + } + } + + self.trigger("ready"); + self.readyTime = Date.now(); + self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users."); + self.state = 3; + setInterval(function () { + self.keepAlive.apply(self); + }, data.heartbeat_interval); + + break; + case "MESSAGE_CREATE": + self.debug("received message"); + + var mentions = []; + data.mentions = data.mentions || []; //for some reason this was not defined at some point? + var _iteratorNormalCompletion6 = true; + var _didIteratorError6 = false; + var _iteratorError6 = undefined; + + try { + for (var _iterator6 = data.mentions[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { + var mention = _step6.value; + + mentions.push(self.addUser(mention)); + } + } catch (err) { + _didIteratorError6 = true; + _iteratorError6 = err; + } finally { + try { + if (!_iteratorNormalCompletion6 && _iterator6["return"]) { + _iterator6["return"](); + } + } finally { + if (_didIteratorError6) { + throw _iteratorError6; + } + } + } + + var channel = self.getChannel("id", data.channel_id); + if (channel) { + var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); + self.trigger("message", msg); + } + + break; + case "MESSAGE_DELETE": + self.debug("message deleted"); + + var channel = self.getChannel("id", data.channel_id); + var message = channel.getMessage("id", data.id); + if (message) { + self.trigger("messageDelete", channel, message); + channel.messages.splice(channel.messages.indexOf(message), 1); + } else { + //don't have the cache of that message ;( + self.trigger("messageDelete", channel); + } + break; + case "MESSAGE_UPDATE": + self.debug("message updated"); + + var channel = self.getChannel("id", data.channel_id); + var formerMessage = channel.getMessage("id", data.id); + + if (formerMessage) { + + //new message might be partial, so we need to fill it with whatever the old message was. + var info = {}; + + for (var key in formerMessage) { + info[key] = formerMessage[key]; + } + + for (var key in data) { + info[key] = data[key]; + } + + var mentions = []; + var _iteratorNormalCompletion7 = true; + var _didIteratorError7 = false; + var _iteratorError7 = undefined; + + try { + for (var _iterator7 = info.mentions[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { + var mention = _step7.value; + + mentions.push(self.addUser(mention)); + } + } catch (err) { + _didIteratorError7 = true; + _iteratorError7 = err; + } finally { + try { + if (!_iteratorNormalCompletion7 && _iterator7["return"]) { + _iterator7["return"](); + } + } finally { + if (_didIteratorError7) { + throw _iteratorError7; + } + } + } + + var newMessage = new Message(info, channel, mentions, formerMessage.author); + + self.trigger("messageUpdate", newMessage, formerMessage); + + channel.messages[channel.messages.indexOf(formerMessage)] = newMessage; + } + + // message isn't in cache, and if it's a partial it could cause + // all hell to break loose... best to just act as if nothing happened + + break; + + case "GUILD_DELETE": + + var server = self.getServer("id", data.id); + + if (server) { + self.serverCache.splice(self.serverCache.indexOf(server), 1); + self.trigger("serverDelete", server); + } + + break; + + case "CHANNEL_DELETE": + + var channel = self.getChannel("id", data.id); + + if (channel) { + + var server = channel.server; + + if (server) { + + server.channels.splice(server.channels.indexOf(channel), 1); + } + + self.trigger("channelDelete", channel); + + self.serverCache.splice(self.serverCache.indexOf(channel), 1); + } + + break; + + case "GUILD_CREATE": + + var server = self.getServer("id", data.id); + + if (!server) { + //if server doesn't already exist because duh + server = self.addServer(data); + } /*else if(server.channels.length === 0){ + + var srv = new Server(data, self); + for(channel of data.channels){ + srv.channels.push(new Channel(channel, data.id)); + } + self.serverCache[self.serverCache.indexOf(server)] = srv; + + }*/ + + if (self.serverCreateListener.get(data.id)) { + var cbs = self.serverCreateListener.get(data.id); + cbs[0](server); //promise then callback + cbs[1](null, server); //legacy callback + self.serverCreateListener["delete"](data.id); + } + + self.trigger("serverCreate", server); + + break; + + case "CHANNEL_CREATE": + + var channel = self.getChannel("id", data.id); + + if (!channel) { + + var chann = self.addChannel(data, data.guild_id); + var srv = self.getServer("id", data.guild_id); + if (srv) { + srv.addChannel(chann); + } + self.trigger("channelCreate", chann); + } + + break; + + case "GUILD_MEMBER_ADD": + + var server = self.getServer("id", data.guild_id); + + if (server) { + + var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. + + if (! ~server.members.indexOf(user)) { + server.members.push(user); + } + + self.trigger("serverNewMember", user, server); + } + + break; + + case "GUILD_MEMBER_REMOVE": + + var server = self.getServer("id", data.guild_id); + + if (server) { + + var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. + + if (~server.members.indexOf(user)) { + server.members.splice(server.members.indexOf(user), 1); + } + + self.trigger("serverRemoveMember", user, server); + } + + break; + + case "USER_UPDATE": + + if (self.user && data.id === self.user.id) { + + var newUser = new User(data); //not actually adding to the cache + + self.trigger("userUpdate", newUser, self.user); + + if (~self.userCache.indexOf(self.user)) { + self.userCache[self.userCache.indexOf(self.user)] = newUser; + } + + self.user = newUser; + } + + break; + + case "PRESENCE_UPDATE": + + var userInCache = self.getUser("id", data.user.id); + + if (userInCache) { + //user exists + var presenceUser = new User(data.user); + if (presenceUser.equalsStrict(userInCache)) { + //they're exactly the same, an actual presence update + self.trigger("presence", { + user: userInCache, + status: data.status, + server: self.getServer("id", data.guild_id), + gameId: data.game_id + }); + } else { + //one of their details changed. + self.trigger("userUpdate", userInCache, presenceUser); + self.userCache[self.userCache.indexOf(userInCache)] = presenceUser; + } + } + + break; + + default: + self.debug("received unknown packet"); + self.trigger("unknown", dat); + break; + + } + }; + } + + //def addUser + }, { + key: "addUser", + value: function addUser(data) { + if (!this.getUser("id", data.id)) { + this.userCache.push(new User(data)); + } + return this.getUser("id", data.id); + } + + //def addChannel + }, { + key: "addChannel", + value: function addChannel(data, serverId) { + if (!this.getChannel("id", data.id)) { + this.channelCache.push(new Channel(data, this.getServer("id", serverId))); + } + return this.getChannel("id", data.id); + } + }, { + key: "addPMChannel", + value: function addPMChannel(data) { + if (!this.getPMChannel("id", data.id)) { + this.pmChannelCache.push(new PMChannel(data, this)); + } + return this.getPMChannel("id", data.id); + } + + //def addServer + }, { + key: "addServer", + value: function addServer(data) { + + var server = this.getServer("id", data.id); + + if (!server) { + server = new Server(data, this); + this.serverCache.push(server); + if (data.channels) { + var _iteratorNormalCompletion8 = true; + var _didIteratorError8 = false; + var _iteratorError8 = undefined; + + try { + for (var _iterator8 = data.channels[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) { + var channel = _step8.value; + + server.channels.push(this.addChannel(channel, server.id)); + } + } catch (err) { + _didIteratorError8 = true; + _iteratorError8 = err; + } finally { + try { + if (!_iteratorNormalCompletion8 && _iterator8["return"]) { + _iterator8["return"](); + } + } finally { + if (_didIteratorError8) { + throw _iteratorError8; + } + } + } + } + } + + return server; + } + + //def getUser + }, { + key: "getUser", + value: function getUser(key, value) { + var _iteratorNormalCompletion9 = true; + var _didIteratorError9 = false; + var _iteratorError9 = undefined; + + try { + for (var _iterator9 = this.userCache[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) { + var user = _step9.value; + + if (user[key] === value) { + return user; + } + } + } catch (err) { + _didIteratorError9 = true; + _iteratorError9 = err; + } finally { + try { + if (!_iteratorNormalCompletion9 && _iterator9["return"]) { + _iterator9["return"](); + } + } finally { + if (_didIteratorError9) { + throw _iteratorError9; + } + } + } + + return null; + } + + //def getChannel + }, { + key: "getChannel", + value: function getChannel(key, value) { + var _iteratorNormalCompletion10 = true; + var _didIteratorError10 = false; + var _iteratorError10 = undefined; + + try { + for (var _iterator10 = this.channelCache[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) { + var channel = _step10.value; + + if (channel[key] === value) { + return channel; + } + } + } catch (err) { + _didIteratorError10 = true; + _iteratorError10 = err; + } finally { + try { + if (!_iteratorNormalCompletion10 && _iterator10["return"]) { + _iterator10["return"](); + } + } finally { + if (_didIteratorError10) { + throw _iteratorError10; + } + } + } + + return this.getPMChannel(key, value); //might be a PM + } + }, { + key: "getPMChannel", + value: function getPMChannel(key, value) { + var _iteratorNormalCompletion11 = true; + var _didIteratorError11 = false; + var _iteratorError11 = undefined; + + try { + for (var _iterator11 = this.pmChannelCache[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) { + var channel = _step11.value; + + if (channel[key] === value) { + return channel; + } + } + } catch (err) { + _didIteratorError11 = true; + _iteratorError11 = err; + } finally { + try { + if (!_iteratorNormalCompletion11 && _iterator11["return"]) { + _iterator11["return"](); + } + } finally { + if (_didIteratorError11) { + throw _iteratorError11; + } + } + } + + return null; + } + + //def getServer + }, { + key: "getServer", + value: function getServer(key, value) { + var _iteratorNormalCompletion12 = true; + var _didIteratorError12 = false; + var _iteratorError12 = undefined; + + try { + for (var _iterator12 = this.serverCache[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) { + var server = _step12.value; + + if (server[key] === value) { + return server; + } + } + } catch (err) { + _didIteratorError12 = true; + _iteratorError12 = err; + } finally { + try { + if (!_iteratorNormalCompletion12 && _iterator12["return"]) { + _iterator12["return"](); + } + } finally { + if (_didIteratorError12) { + throw _iteratorError12; + } + } + } + + return null; + } + + //def trySendConnData + }, { + key: "trySendConnData", + value: function trySendConnData() { + + if (this.token && !this.alreadySentData) { + + this.alreadySentData = true; + + var data = { + op: 2, + d: { + token: this.token, + v: 2, + properties: { + "$os": "discord.js", + "$browser": "discord.js", + "$device": "discord.js", + "$referrer": "", + "$referring_domain": "" + } + } + }; + this.websocket.send(JSON.stringify(data)); + } + } + }, { + key: "resolveServerID", + value: function resolveServerID(resource) { + + if (resource instanceof Server) { + return resource.id; + } else if (!isNaN(resource) && resource.length && resource.length === 17) { + return resource; + } + } + }, { + key: "resolveDestination", + value: function resolveDestination(destination) { + var channId = false; + var self = this; + + return new Promise(function (resolve, reject) { + if (destination instanceof Server) { + channId = destination.id; //general is the same as server id + } else if (destination instanceof Channel) { + channId = destination.id; + } else if (destination instanceof Message) { + channId = destination.channel.id; + } else if (destination instanceof User) { + + //check if we have a PM + var _iteratorNormalCompletion13 = true; + var _didIteratorError13 = false; + var _iteratorError13 = undefined; + + try { + for (var _iterator13 = self.pmChannelCache[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) { + var pmc = _step13.value; + + if (pmc.user.equals(destination)) { + resolve(pmc.id); + return; + } + } + + //we don't, at this point we're late + } catch (err) { + _didIteratorError13 = true; + _iteratorError13 = err; + } finally { + try { + if (!_iteratorNormalCompletion13 && _iterator13["return"]) { + _iterator13["return"](); + } + } finally { + if (_didIteratorError13) { + throw _iteratorError13; + } + } + } + + self.startPM(destination).then(function (pmc) { + console.log(pmc); + resolve(pmc.id); + })["catch"](reject); + } else { + channId = destination; + } + if (channId) resolve(channId); + }); + } + }, { + key: "_sendMessage", + value: function _sendMessage(destination, content, tts, mentions) { + + var self = this; + + return new Promise(function (resolve, reject) { + request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).send({ + content: content, + mentions: mentions, + tts: tts + }).end(function (err, res) { + + if (err) { + reject(err); + } else { + var data = res.body; + + var mentions = []; + + data.mentions = data.mentions || []; //for some reason this was not defined at some point? + + var _iteratorNormalCompletion14 = true; + var _didIteratorError14 = false; + var _iteratorError14 = undefined; + + try { + for (var _iterator14 = data.mentions[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) { + var mention = _step14.value; + + mentions.push(self.addUser(mention)); + } + } catch (err) { + _didIteratorError14 = true; + _iteratorError14 = err; + } finally { + try { + if (!_iteratorNormalCompletion14 && _iterator14["return"]) { + _iterator14["return"](); + } + } finally { + if (_didIteratorError14) { + throw _iteratorError14; + } + } + } + + var channel = self.getChannel("id", data.channel_id); + if (channel) { + var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); + resolve(msg); + } + } + }); + }); + } + }, { + key: "_sendFile", + value: function _sendFile(destination, attachment) { + var attachmentName = arguments.length <= 2 || arguments[2] === undefined ? "DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png" : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).attach("file", attachment, attachmentName).end(function (err, res) { + + if (err) { + reject(err); + } else { + + var chann = self.getChannel("id", destination); + if (chann) { + var msg = chann.addMessage(new Message(res.body, chann, [], self.user)); + resolve(msg); + } + } + }); + }); + } + }, { + key: "_updateMessage", + value: function _updateMessage(message, content) { + var self = this; + return new Promise(function (resolve, reject) { + request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).send({ + content: content, + mentions: [] + }).end(function (err, res) { + if (err) { + reject(err); + } else { + var msg = new Message(res.body, message.channel, message.mentions, message.sender); + resolve(msg); + message.channel.messages[message.channel.messages.indexOf(message)] = msg; + } + }); + }); + } + }, { + key: "_deleteMessage", + value: function _deleteMessage(message) { + var self = this; + return new Promise(function (resolve, reject) { + + request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + }); + } + }, { + key: "checkQueue", + value: function checkQueue(channelID) { + var _this = this; + + var self = this; + + if (!this.checkingQueue[channelID]) { + (function () { + var doNext = function doNext() { + if (self.queue[channelID].length === 0) { + done(); + return; + } + var queuedEvent = self.queue[channelID][0]; + switch (queuedEvent.action) { + case "sendMessage": + var msgToSend = queuedEvent; + self._sendMessage(channelID, msgToSend.content, msgToSend.tts, msgToSend.mentions).then(function (msg) { + msgToSend.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + msgToSend.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + case "sendFile": + var fileToSend = queuedEvent; + self._sendFile(channelID, fileToSend.attachment, fileToSend.attachmentName).then(function (msg) { + fileToSend.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + fileToSend.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + case "updateMessage": + var msgToUpd = queuedEvent; + self._updateMessage(msgToUpd.message, msgToUpd.content).then(function (msg) { + msgToUpd.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + msgToUpd.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + case "deleteMessage": + var msgToDel = queuedEvent; + self._deleteMessage(msgToDel.message).then(function (msg) { + msgToDel.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + msgToDel.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + default: + done(); + break; + } + }; + + var done = function done() { + self.checkingQueue[channelID] = false; + return; + }; + + //if we aren't already checking this queue. + _this.checkingQueue[channelID] = true; + doNext(); + })(); + } + } + }, { + key: "uptime", + get: function get() { + + return this.readyTime ? Date.now() - this.readyTime : null; + } + }, { + key: "ready", + get: function get() { + return this.state === 3; + } + }, { + key: "servers", + get: function get() { + return this.serverCache; + } + }, { + key: "channels", + get: function get() { + return this.channelCache; + } + }, { + key: "users", + get: function get() { + return this.userCache; + } + }, { + key: "PMChannels", + get: function get() { + return this.pmChannelCache; + } + }, { + key: "messages", + get: function get() { + + var msgs = []; + var _iteratorNormalCompletion15 = true; + var _didIteratorError15 = false; + var _iteratorError15 = undefined; + + try { + for (var _iterator15 = this.channelCache[Symbol.iterator](), _step15; !(_iteratorNormalCompletion15 = (_step15 = _iterator15.next()).done); _iteratorNormalCompletion15 = true) { + var channel = _step15.value; + + msgs = msgs.concat(channel.messages); + } + } catch (err) { + _didIteratorError15 = true; + _iteratorError15 = err; + } finally { + try { + if (!_iteratorNormalCompletion15 && _iterator15["return"]) { + _iterator15["return"](); + } + } finally { + if (_didIteratorError15) { + throw _iteratorError15; + } + } + } + + return msgs; + } + }]); + + return Client; +})(); + +function getGateway() { + + var self = this; + + return new Promise(function (resolve, reject) { + request.get(Endpoints.API + "/gateway").end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(res.body.url); + } + }); + }); +} + +module.exports = Client; +},{"./Endpoints.js":2,"./PMChannel.js":3,"./channel.js":4,"./invite.js":6,"./message.js":7,"./server.js":8,"./user.js":9,"fs":10,"superagent":11,"ws":14}],2:[function(require,module,exports){ +"use strict"; + +exports.BASE_DOMAIN = "discordapp.com"; +exports.BASE = "https://" + exports.BASE_DOMAIN; +exports.WEBSOCKET_HUB = "wss://" + exports.BASE_DOMAIN + "/hub"; + +exports.API = exports.BASE + "/api"; +exports.AUTH = exports.API + "/auth"; +exports.LOGIN = exports.AUTH + "/login"; +exports.LOGOUT = exports.AUTH + "/logout"; +exports.USERS = exports.API + "/users"; +exports.SERVERS = exports.API + "/guilds"; +exports.CHANNELS = exports.API + "/channels"; +},{}],3:[function(require,module,exports){ +"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 PMChannel = (function () { + function PMChannel(data, client) { + _classCallCheck(this, PMChannel); + + this.user = client.getUser("id", data.recipient.id); + this.id = data.id; + this.messages = []; + } + + _createClass(PMChannel, [{ + key: "addMessage", + value: function addMessage(data) { + if (!this.getMessage("id", data.id)) { + this.messages.push(data); + } + return this.getMessage("id", data.id); + } + }, { + key: "getMessage", + value: function getMessage(key, value) { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var message = _step.value; + + if (message[key] === value) { + return message; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return null; + } + }, { + key: "isPrivate", + get: function get() { + return true; + } + }]); + + return PMChannel; +})(); + +module.exports = PMChannel; +},{}],4:[function(require,module,exports){ +"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 Channel = (function () { + function Channel(data, server) { + _classCallCheck(this, Channel); + + this.server = server; + this.name = data.name; + this.type = data.type; + this.id = data.id; + this.messages = []; + //this.isPrivate = isPrivate; //not sure about the implementation of this... + } + + _createClass(Channel, [{ + key: "equals", + value: function equals(object) { + return object && object.id === this.id; + } + }, { + key: "addMessage", + value: function addMessage(data) { + if (!this.getMessage("id", data.id)) { + this.messages.push(data); + } + return this.getMessage("id", data.id); + } + }, { + key: "getMessage", + value: function getMessage(key, value) { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var message = _step.value; + + if (message[key] === value) { + return message; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return null; + } + }, { + key: "toString", + value: function toString() { + return "#" + this.name; + } + }, { + key: "client", + get: function get() { + return this.server.client; + } + }, { + key: "isPrivate", + get: function get() { + return false; + } + }]); + + return Channel; +})(); + +module.exports = Channel; +},{}],5:[function(require,module,exports){ +"use strict"; + +var request = require("superagent"); +var Endpoints = require("./Endpoints.js"); +var Client = require("./Client.js"); + +var Discord = { + Endpoints: Endpoints, + Client: Client +}; + +module.exports = Discord; +},{"./Client.js":1,"./Endpoints.js":2,"superagent":11}],6:[function(require,module,exports){ +"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 Invite = (function () { + function Invite(data, client) { + _classCallCheck(this, Invite); + + this.max_age = data.max_age; + this.code = data.code; + this.server = client.getServer("id", data.guild.id); + this.revoked = data.revoked; + this.created_at = Date.parse(data.created_at); + this.temporary = data.temporary; + this.uses = data.uses; + this.max_uses = data.uses; + this.inviter = client.addUser(data.inviter); + this.xkcd = data.xkcdpass; + this.channel = client.getChannel("id", data.channel.id); + } + + _createClass(Invite, [{ + key: "URL", + get: function get() { + var code = this.xkcd ? this.xkcdpass : this.code; + return "https://discord.gg/" + code; + } + }]); + + return Invite; +})(); + +module.exports = Invite; +},{}],7:[function(require,module,exports){ +"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 PMChannel = require("./PMChannel.js"); + +var Message = (function () { + function Message(data, channel, mentions, author) { + _classCallCheck(this, Message); + + this.tts = data.tts; + this.timestamp = Date.parse(data.timestamp); + this.nonce = data.nonce; + this.mentions = mentions; + this.everyoneMentioned = data.mention_everyone; + this.id = data.id; + this.embeds = data.embeds; + this.editedTimestamp = data.edited_timestamp; + this.content = data.content.trim(); + this.channel = channel; + this.author = author; + this.attachments = data.attachments; + } + + /*exports.Message.prototype.isPM = function() { + return ( this.channel instanceof PMChannel ); + }*/ + + _createClass(Message, [{ + key: "isMentioned", + value: function isMentioned(user) { + var id = user.id ? user.id : user; + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.mentions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var mention = _step.value; + + if (mention.id === id) { + return true; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return false; + } + }, { + key: "sender", + get: function get() { + return this.author; + } + }, { + key: "isPrivate", + get: function get() { + return this.channel.isPrivate; + } + }]); + + return Message; +})(); + +module.exports = Message; +},{"./PMChannel.js":3}],8:[function(require,module,exports){ +"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 = (function () { + function Server(data, client) { + _classCallCheck(this, Server); + + this.client = client; + this.region = data.region; + this.ownerID = data.owner_id; + this.name = data.name; + this.id = data.id; + this.members = []; + this.channels = []; + this.icon = data.icon; + this.afkTimeout = data.afk_timeout; + this.afkChannelId = data.afk_channel_id; + + if (!data.members) { + data.members = [client.user]; + return; + } + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = data.members[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var member = _step.value; + + // first we cache the user in our Discord Client, + // then we add it to our list. This way when we + // get a user from this server's member list, + // it will be identical (unless an async change occurred) + // to the client's cache. + if (member.user) this.members.push(client.addUser(member.user)); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + } + + _createClass(Server, [{ + key: "getChannel", + + // get/set + value: function getChannel(key, value) { + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = this.channels[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var channel = _step2.value; + + if (channel[key] === value) { + return channel; + } + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2["return"]) { + _iterator2["return"](); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + + return null; + } + }, { + key: "getMember", + value: function getMember(key, value) { + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = this.members[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var member = _step3.value; + + if (member[key] === value) { + return member; + } + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3["return"]) { + _iterator3["return"](); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + + return null; + } + }, { + key: "addChannel", + value: function addChannel(chann) { + if (!this.getChannel("id", chann.id)) { + this.channels.push(chann); + } + return chann; + } + }, { + key: "addMember", + value: function addMember(member) { + if (!this.getMember("id", member.id)) { + this.members.push(member); + } + return member; + } + }, { + key: "toString", + value: function toString() { + return this.name; + } + }, { + key: "iconURL", + get: function get() { + if (!this.icon) return null; + return "https://discordapp.com/api/guilds/" + this.id + "/icons/" + this.icon + ".jpg"; + } + }, { + key: "afkChannel", + get: function get() { + if (!this.afkChannelId) return false; + + return this.getChannel("id", this.afkChannelId); + } + }, { + key: "defaultChannel", + get: function get() { + return this.getChannel("name", "general"); + } + }, { + key: "owner", + get: function get() { + return this.client.getUser("id", this.ownerID); + } + }]); + + return Server; +})(); + +module.exports = Server; +},{}],9:[function(require,module,exports){ +"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 User = (function () { + function User(data) { + _classCallCheck(this, User); + + this.username = data.username; + this.discriminator = data.discriminator; + this.id = data.id; + this.avatar = data.avatar; + } + + // access using user.avatarURL; + + _createClass(User, [{ + key: "mention", + value: function mention() { + return "<@" + this.id + ">"; + } + }, { + key: "toString", + value: function toString() { + /* + if we embed a user in a String - like so: + "Yo " + user + " what's up?" + It would generate something along the lines of: + "Yo @hydrabolt what's up?" + */ + return this.mention(); + } + }, { + key: "equals", + value: function equals(object) { + return object.id === this.id; + } + }, { + key: "equalsStrict", + value: function equalsStrict(object) { + return object.id === this.id && object.avatar === this.avatar && object.username === this.username && object.discriminator === this.discriminator; + } + }, { + key: "avatarURL", + get: function get() { + if (!this.avatar) return null; + return "https://discordapp.com/api/users/" + this.id + "/avatars/" + this.avatar + ".jpg"; + } + }]); + + return User; +})(); + +module.exports = User; +},{}],10:[function(require,module,exports){ + +},{}],11:[function(require,module,exports){ +/** + * Module dependencies. + */ + +var Emitter = require('emitter'); +var reduce = require('reduce'); + +/** + * Root reference for iframes. + */ + +var root = 'undefined' == typeof window + ? (this || self) + : window; + +/** + * Noop. + */ + +function noop(){}; + +/** + * Check if `obj` is a host object, + * we don't want to serialize these :) + * + * TODO: future proof, move to compoent land + * + * @param {Object} obj + * @return {Boolean} + * @api private + */ + +function isHost(obj) { + var str = {}.toString.call(obj); + + switch (str) { + case '[object File]': + case '[object Blob]': + case '[object FormData]': + return true; + default: + return false; + } +} + +/** + * Determine XHR. + */ + +request.getXHR = function () { + if (root.XMLHttpRequest + && (!root.location || 'file:' != root.location.protocol + || !root.ActiveXObject)) { + return new XMLHttpRequest; + } else { + try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {} + } + return false; +}; + +/** + * Removes leading and trailing whitespace, added to support IE. + * + * @param {String} s + * @return {String} + * @api private + */ + +var trim = ''.trim + ? function(s) { return s.trim(); } + : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); }; + +/** + * Check if `obj` is an object. + * + * @param {Object} obj + * @return {Boolean} + * @api private + */ + +function isObject(obj) { + return obj === Object(obj); +} + +/** + * Serialize the given `obj`. + * + * @param {Object} obj + * @return {String} + * @api private + */ + +function serialize(obj) { + if (!isObject(obj)) return obj; + var pairs = []; + for (var key in obj) { + if (null != obj[key]) { + pairs.push(encodeURIComponent(key) + + '=' + encodeURIComponent(obj[key])); + } + } + return pairs.join('&'); +} + +/** + * Expose serialization method. + */ + + request.serializeObject = serialize; + + /** + * Parse the given x-www-form-urlencoded `str`. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function parseString(str) { + var obj = {}; + var pairs = str.split('&'); + var parts; + var pair; + + for (var i = 0, len = pairs.length; i < len; ++i) { + pair = pairs[i]; + parts = pair.split('='); + obj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]); + } + + return obj; +} + +/** + * Expose parser. + */ + +request.parseString = parseString; + +/** + * Default MIME type map. + * + * superagent.types.xml = 'application/xml'; + * + */ + +request.types = { + html: 'text/html', + json: 'application/json', + xml: 'application/xml', + urlencoded: 'application/x-www-form-urlencoded', + 'form': 'application/x-www-form-urlencoded', + 'form-data': 'application/x-www-form-urlencoded' +}; + +/** + * Default serialization map. + * + * superagent.serialize['application/xml'] = function(obj){ + * return 'generated xml here'; + * }; + * + */ + + request.serialize = { + 'application/x-www-form-urlencoded': serialize, + 'application/json': JSON.stringify + }; + + /** + * Default parsers. + * + * superagent.parse['application/xml'] = function(str){ + * return { object parsed from str }; + * }; + * + */ + +request.parse = { + 'application/x-www-form-urlencoded': parseString, + 'application/json': JSON.parse +}; + +/** + * Parse the given header `str` into + * an object containing the mapped fields. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function parseHeader(str) { + var lines = str.split(/\r?\n/); + var fields = {}; + var index; + var line; + var field; + var val; + + lines.pop(); // trailing CRLF + + for (var i = 0, len = lines.length; i < len; ++i) { + line = lines[i]; + index = line.indexOf(':'); + field = line.slice(0, index).toLowerCase(); + val = trim(line.slice(index + 1)); + fields[field] = val; + } + + return fields; +} + +/** + * Return the mime type for the given `str`. + * + * @param {String} str + * @return {String} + * @api private + */ + +function type(str){ + return str.split(/ *; */).shift(); +}; + +/** + * Return header field parameters. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function params(str){ + return reduce(str.split(/ *; */), function(obj, str){ + var parts = str.split(/ *= */) + , key = parts.shift() + , val = parts.shift(); + + if (key && val) obj[key] = val; + return obj; + }, {}); +}; + +/** + * Initialize a new `Response` with the given `xhr`. + * + * - set flags (.ok, .error, etc) + * - parse header + * + * Examples: + * + * Aliasing `superagent` as `request` is nice: + * + * request = superagent; + * + * We can use the promise-like API, or pass callbacks: + * + * request.get('/').end(function(res){}); + * request.get('/', function(res){}); + * + * Sending data can be chained: + * + * request + * .post('/user') + * .send({ name: 'tj' }) + * .end(function(res){}); + * + * Or passed to `.send()`: + * + * request + * .post('/user') + * .send({ name: 'tj' }, function(res){}); + * + * Or passed to `.post()`: + * + * request + * .post('/user', { name: 'tj' }) + * .end(function(res){}); + * + * Or further reduced to a single call for simple cases: + * + * request + * .post('/user', { name: 'tj' }, function(res){}); + * + * @param {XMLHTTPRequest} xhr + * @param {Object} options + * @api private + */ + +function Response(req, options) { + options = options || {}; + this.req = req; + this.xhr = this.req.xhr; + // responseText is accessible only if responseType is '' or 'text' and on older browsers + this.text = ((this.req.method !='HEAD' && (this.xhr.responseType === '' || this.xhr.responseType === 'text')) || typeof this.xhr.responseType === 'undefined') + ? this.xhr.responseText + : null; + this.statusText = this.req.xhr.statusText; + this.setStatusProperties(this.xhr.status); + this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders()); + // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but + // getResponseHeader still works. so we get content-type even if getting + // other headers fails. + this.header['content-type'] = this.xhr.getResponseHeader('content-type'); + this.setHeaderProperties(this.header); + this.body = this.req.method != 'HEAD' + ? this.parseBody(this.text ? this.text : this.xhr.response) + : null; +} + +/** + * Get case-insensitive `field` value. + * + * @param {String} field + * @return {String} + * @api public + */ + +Response.prototype.get = function(field){ + return this.header[field.toLowerCase()]; +}; + +/** + * Set header related properties: + * + * - `.type` the content type without params + * + * A response of "Content-Type: text/plain; charset=utf-8" + * will provide you with a `.type` of "text/plain". + * + * @param {Object} header + * @api private + */ + +Response.prototype.setHeaderProperties = function(header){ + // content-type + var ct = this.header['content-type'] || ''; + this.type = type(ct); + + // params + var obj = params(ct); + for (var key in obj) this[key] = obj[key]; +}; + +/** + * Parse the given body `str`. + * + * Used for auto-parsing of bodies. Parsers + * are defined on the `superagent.parse` object. + * + * @param {String} str + * @return {Mixed} + * @api private + */ + +Response.prototype.parseBody = function(str){ + var parse = request.parse[this.type]; + return parse && str && (str.length || str instanceof Object) + ? parse(str) + : null; +}; + +/** + * Set flags such as `.ok` based on `status`. + * + * For example a 2xx response will give you a `.ok` of __true__ + * whereas 5xx will be __false__ and `.error` will be __true__. The + * `.clientError` and `.serverError` are also available to be more + * specific, and `.statusType` is the class of error ranging from 1..5 + * sometimes useful for mapping respond colors etc. + * + * "sugar" properties are also defined for common cases. Currently providing: + * + * - .noContent + * - .badRequest + * - .unauthorized + * - .notAcceptable + * - .notFound + * + * @param {Number} status + * @api private + */ + +Response.prototype.setStatusProperties = function(status){ + // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request + if (status === 1223) { + status = 204; + } + + var type = status / 100 | 0; + + // status / class + this.status = status; + this.statusType = type; + + // basics + this.info = 1 == type; + this.ok = 2 == type; + this.clientError = 4 == type; + this.serverError = 5 == type; + this.error = (4 == type || 5 == type) + ? this.toError() + : false; + + // sugar + this.accepted = 202 == status; + this.noContent = 204 == status; + this.badRequest = 400 == status; + this.unauthorized = 401 == status; + this.notAcceptable = 406 == status; + this.notFound = 404 == status; + this.forbidden = 403 == status; +}; + +/** + * Return an `Error` representative of this response. + * + * @return {Error} + * @api public + */ + +Response.prototype.toError = function(){ + var req = this.req; + var method = req.method; + var url = req.url; + + var msg = 'cannot ' + method + ' ' + url + ' (' + this.status + ')'; + var err = new Error(msg); + err.status = this.status; + err.method = method; + err.url = url; + + return err; +}; + +/** + * Expose `Response`. + */ + +request.Response = Response; + +/** + * Initialize a new `Request` with the given `method` and `url`. + * + * @param {String} method + * @param {String} url + * @api public + */ + +function Request(method, url) { + var self = this; + Emitter.call(this); + this._query = this._query || []; + this.method = method; + this.url = url; + this.header = {}; + this._header = {}; + this.on('end', function(){ + var err = null; + var res = null; + + try { + res = new Response(self); + } catch(e) { + err = new Error('Parser is unable to parse the response'); + err.parse = true; + err.original = e; + return self.callback(err); + } + + self.emit('response', res); + + if (err) { + return self.callback(err, res); + } + + if (res.status >= 200 && res.status < 300) { + return self.callback(err, res); + } + + var new_err = new Error(res.statusText || 'Unsuccessful HTTP response'); + new_err.original = err; + new_err.response = res; + new_err.status = res.status; + + self.callback(new_err, res); + }); +} + +/** + * Mixin `Emitter`. + */ + +Emitter(Request.prototype); + +/** + * Allow for extension + */ + +Request.prototype.use = function(fn) { + fn(this); + return this; +} + +/** + * Set timeout to `ms`. + * + * @param {Number} ms + * @return {Request} for chaining + * @api public + */ + +Request.prototype.timeout = function(ms){ + this._timeout = ms; + return this; +}; + +/** + * Clear previous timeout. + * + * @return {Request} for chaining + * @api public + */ + +Request.prototype.clearTimeout = function(){ + this._timeout = 0; + clearTimeout(this._timer); + return this; +}; + +/** + * Abort the request, and clear potential timeout. + * + * @return {Request} + * @api public + */ + +Request.prototype.abort = function(){ + if (this.aborted) return; + this.aborted = true; + this.xhr.abort(); + this.clearTimeout(); + this.emit('abort'); + return this; +}; + +/** + * Set header `field` to `val`, or multiple fields with one object. + * + * Examples: + * + * req.get('/') + * .set('Accept', 'application/json') + * .set('X-API-Key', 'foobar') + * .end(callback); + * + * req.get('/') + * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' }) + * .end(callback); + * + * @param {String|Object} field + * @param {String} val + * @return {Request} for chaining + * @api public + */ + +Request.prototype.set = function(field, val){ + if (isObject(field)) { + for (var key in field) { + this.set(key, field[key]); + } + return this; + } + this._header[field.toLowerCase()] = val; + this.header[field] = val; + return this; +}; + +/** + * Remove header `field`. + * + * Example: + * + * req.get('/') + * .unset('User-Agent') + * .end(callback); + * + * @param {String} field + * @return {Request} for chaining + * @api public + */ + +Request.prototype.unset = function(field){ + delete this._header[field.toLowerCase()]; + delete this.header[field]; + return this; +}; + +/** + * Get case-insensitive header `field` value. + * + * @param {String} field + * @return {String} + * @api private + */ + +Request.prototype.getHeader = function(field){ + return this._header[field.toLowerCase()]; +}; + +/** + * Set Content-Type to `type`, mapping values from `request.types`. + * + * Examples: + * + * superagent.types.xml = 'application/xml'; + * + * request.post('/') + * .type('xml') + * .send(xmlstring) + * .end(callback); + * + * request.post('/') + * .type('application/xml') + * .send(xmlstring) + * .end(callback); + * + * @param {String} type + * @return {Request} for chaining + * @api public + */ + +Request.prototype.type = function(type){ + this.set('Content-Type', request.types[type] || type); + return this; +}; + +/** + * Set Accept to `type`, mapping values from `request.types`. + * + * Examples: + * + * superagent.types.json = 'application/json'; + * + * request.get('/agent') + * .accept('json') + * .end(callback); + * + * request.get('/agent') + * .accept('application/json') + * .end(callback); + * + * @param {String} accept + * @return {Request} for chaining + * @api public + */ + +Request.prototype.accept = function(type){ + this.set('Accept', request.types[type] || type); + return this; +}; + +/** + * Set Authorization field value with `user` and `pass`. + * + * @param {String} user + * @param {String} pass + * @return {Request} for chaining + * @api public + */ + +Request.prototype.auth = function(user, pass){ + var str = btoa(user + ':' + pass); + this.set('Authorization', 'Basic ' + str); + return this; +}; + +/** +* Add query-string `val`. +* +* Examples: +* +* request.get('/shoes') +* .query('size=10') +* .query({ color: 'blue' }) +* +* @param {Object|String} val +* @return {Request} for chaining +* @api public +*/ + +Request.prototype.query = function(val){ + if ('string' != typeof val) val = serialize(val); + if (val) this._query.push(val); + return this; +}; + +/** + * Write the field `name` and `val` for "multipart/form-data" + * request bodies. + * + * ``` js + * request.post('/upload') + * .field('foo', 'bar') + * .end(callback); + * ``` + * + * @param {String} name + * @param {String|Blob|File} val + * @return {Request} for chaining + * @api public + */ + +Request.prototype.field = function(name, val){ + if (!this._formData) this._formData = new root.FormData(); + this._formData.append(name, val); + return this; +}; + +/** + * Queue the given `file` as an attachment to the specified `field`, + * with optional `filename`. + * + * ``` js + * request.post('/upload') + * .attach(new Blob(['hey!'], { type: "text/html"})) + * .end(callback); + * ``` + * + * @param {String} field + * @param {Blob|File} file + * @param {String} filename + * @return {Request} for chaining + * @api public + */ + +Request.prototype.attach = function(field, file, filename){ + if (!this._formData) this._formData = new root.FormData(); + this._formData.append(field, file, filename); + return this; +}; + +/** + * Send `data`, defaulting the `.type()` to "json" when + * an object is given. + * + * Examples: + * + * // querystring + * request.get('/search') + * .end(callback) + * + * // multiple data "writes" + * request.get('/search') + * .send({ search: 'query' }) + * .send({ range: '1..5' }) + * .send({ order: 'desc' }) + * .end(callback) + * + * // manual json + * request.post('/user') + * .type('json') + * .send('{"name":"tj"}) + * .end(callback) + * + * // auto json + * request.post('/user') + * .send({ name: 'tj' }) + * .end(callback) + * + * // manual x-www-form-urlencoded + * request.post('/user') + * .type('form') + * .send('name=tj') + * .end(callback) + * + * // auto x-www-form-urlencoded + * request.post('/user') + * .type('form') + * .send({ name: 'tj' }) + * .end(callback) + * + * // defaults to x-www-form-urlencoded + * request.post('/user') + * .send('name=tobi') + * .send('species=ferret') + * .end(callback) + * + * @param {String|Object} data + * @return {Request} for chaining + * @api public + */ + +Request.prototype.send = function(data){ + var obj = isObject(data); + var type = this.getHeader('Content-Type'); + + // merge + if (obj && isObject(this._data)) { + for (var key in data) { + this._data[key] = data[key]; + } + } else if ('string' == typeof data) { + if (!type) this.type('form'); + type = this.getHeader('Content-Type'); + if ('application/x-www-form-urlencoded' == type) { + this._data = this._data + ? this._data + '&' + data + : data; + } else { + this._data = (this._data || '') + data; + } + } else { + this._data = data; + } + + if (!obj || isHost(data)) return this; + if (!type) this.type('json'); + return this; +}; + +/** + * Invoke the callback with `err` and `res` + * and handle arity check. + * + * @param {Error} err + * @param {Response} res + * @api private + */ + +Request.prototype.callback = function(err, res){ + var fn = this._callback; + this.clearTimeout(); + fn(err, res); +}; + +/** + * Invoke callback with x-domain error. + * + * @api private + */ + +Request.prototype.crossDomainError = function(){ + var err = new Error('Origin is not allowed by Access-Control-Allow-Origin'); + err.crossDomain = true; + this.callback(err); +}; + +/** + * Invoke callback with timeout error. + * + * @api private + */ + +Request.prototype.timeoutError = function(){ + var timeout = this._timeout; + var err = new Error('timeout of ' + timeout + 'ms exceeded'); + err.timeout = timeout; + this.callback(err); +}; + +/** + * Enable transmission of cookies with x-domain requests. + * + * Note that for this to work the origin must not be + * using "Access-Control-Allow-Origin" with a wildcard, + * and also must set "Access-Control-Allow-Credentials" + * to "true". + * + * @api public + */ + +Request.prototype.withCredentials = function(){ + this._withCredentials = true; + return this; +}; + +/** + * Initiate request, invoking callback `fn(res)` + * with an instanceof `Response`. + * + * @param {Function} fn + * @return {Request} for chaining + * @api public + */ + +Request.prototype.end = function(fn){ + var self = this; + var xhr = this.xhr = request.getXHR(); + var query = this._query.join('&'); + var timeout = this._timeout; + var data = this._formData || this._data; + + // store callback + this._callback = fn || noop; + + // state change + xhr.onreadystatechange = function(){ + if (4 != xhr.readyState) return; + + // In IE9, reads to any property (e.g. status) off of an aborted XHR will + // result in the error "Could not complete the operation due to error c00c023f" + var status; + try { status = xhr.status } catch(e) { status = 0; } + + if (0 == status) { + if (self.timedout) return self.timeoutError(); + if (self.aborted) return; + return self.crossDomainError(); + } + self.emit('end'); + }; + + // progress + var handleProgress = function(e){ + if (e.total > 0) { + e.percent = e.loaded / e.total * 100; + } + self.emit('progress', e); + }; + if (this.hasListeners('progress')) { + xhr.onprogress = handleProgress; + } + try { + if (xhr.upload && this.hasListeners('progress')) { + xhr.upload.onprogress = handleProgress; + } + } catch(e) { + // Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist. + // Reported here: + // https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context + } + + // timeout + if (timeout && !this._timer) { + this._timer = setTimeout(function(){ + self.timedout = true; + self.abort(); + }, timeout); + } + + // querystring + if (query) { + query = request.serializeObject(query); + this.url += ~this.url.indexOf('?') + ? '&' + query + : '?' + query; + } + + // initiate request + xhr.open(this.method, this.url, true); + + // CORS + if (this._withCredentials) xhr.withCredentials = true; + + // body + if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) { + // serialize stuff + var contentType = this.getHeader('Content-Type'); + var serialize = request.serialize[contentType ? contentType.split(';')[0] : '']; + if (serialize) data = serialize(data); + } + + // set header fields + for (var field in this.header) { + if (null == this.header[field]) continue; + xhr.setRequestHeader(field, this.header[field]); + } + + // send stuff + this.emit('request', this); + xhr.send(data); + return this; +}; + +/** + * Faux promise support + * + * @param {Function} fulfill + * @param {Function} reject + * @return {Request} + */ + +Request.prototype.then = function (fulfill, reject) { + return this.end(function(err, res) { + err ? reject(err) : fulfill(res); + }); +} + +/** + * Expose `Request`. + */ + +request.Request = Request; + +/** + * Issue a request: + * + * Examples: + * + * request('GET', '/users').end(callback) + * request('/users').end(callback) + * request('/users', callback) + * + * @param {String} method + * @param {String|Function} url or callback + * @return {Request} + * @api public + */ + +function request(method, url) { + // callback + if ('function' == typeof url) { + return new Request('GET', method).end(url); + } + + // url first + if (1 == arguments.length) { + return new Request('GET', method); + } + + return new Request(method, url); +} + +/** + * GET `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.get = function(url, data, fn){ + var req = request('GET', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.query(data); + if (fn) req.end(fn); + return req; +}; + +/** + * HEAD `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.head = function(url, data, fn){ + var req = request('HEAD', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * DELETE `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.del = function(url, fn){ + var req = request('DELETE', url); + if (fn) req.end(fn); + return req; +}; + +/** + * PATCH `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed} data + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.patch = function(url, data, fn){ + var req = request('PATCH', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * POST `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed} data + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.post = function(url, data, fn){ + var req = request('POST', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * PUT `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.put = function(url, data, fn){ + var req = request('PUT', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * Expose `request`. + */ + +module.exports = request; + +},{"emitter":12,"reduce":13}],12:[function(require,module,exports){ + +/** + * Expose `Emitter`. + */ + +module.exports = Emitter; + +/** + * Initialize a new `Emitter`. + * + * @api public + */ + +function Emitter(obj) { + if (obj) return mixin(obj); +}; + +/** + * Mixin the emitter properties. + * + * @param {Object} obj + * @return {Object} + * @api private + */ + +function mixin(obj) { + for (var key in Emitter.prototype) { + obj[key] = Emitter.prototype[key]; + } + return obj; +} + +/** + * Listen on the given `event` with `fn`. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.on = +Emitter.prototype.addEventListener = function(event, fn){ + this._callbacks = this._callbacks || {}; + (this._callbacks[event] = this._callbacks[event] || []) + .push(fn); + return this; +}; + +/** + * Adds an `event` listener that will be invoked a single + * time then automatically removed. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.once = function(event, fn){ + var self = this; + this._callbacks = this._callbacks || {}; + + function on() { + self.off(event, on); + fn.apply(this, arguments); + } + + on.fn = fn; + this.on(event, on); + return this; +}; + +/** + * Remove the given callback for `event` or all + * registered callbacks. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.off = +Emitter.prototype.removeListener = +Emitter.prototype.removeAllListeners = +Emitter.prototype.removeEventListener = function(event, fn){ + this._callbacks = this._callbacks || {}; + + // all + if (0 == arguments.length) { + this._callbacks = {}; + return this; + } + + // specific event + var callbacks = this._callbacks[event]; + if (!callbacks) return this; + + // remove all handlers + if (1 == arguments.length) { + delete this._callbacks[event]; + return this; + } + + // remove specific handler + var cb; + for (var i = 0; i < callbacks.length; i++) { + cb = callbacks[i]; + if (cb === fn || cb.fn === fn) { + callbacks.splice(i, 1); + break; + } + } + return this; +}; + +/** + * Emit `event` with the given args. + * + * @param {String} event + * @param {Mixed} ... + * @return {Emitter} + */ + +Emitter.prototype.emit = function(event){ + this._callbacks = this._callbacks || {}; + var args = [].slice.call(arguments, 1) + , callbacks = this._callbacks[event]; + + if (callbacks) { + callbacks = callbacks.slice(0); + for (var i = 0, len = callbacks.length; i < len; ++i) { + callbacks[i].apply(this, args); + } + } + + return this; +}; + +/** + * Return array of callbacks for `event`. + * + * @param {String} event + * @return {Array} + * @api public + */ + +Emitter.prototype.listeners = function(event){ + this._callbacks = this._callbacks || {}; + return this._callbacks[event] || []; +}; + +/** + * Check if this emitter has `event` handlers. + * + * @param {String} event + * @return {Boolean} + * @api public + */ + +Emitter.prototype.hasListeners = function(event){ + return !! this.listeners(event).length; +}; + +},{}],13:[function(require,module,exports){ + +/** + * Reduce `arr` with `fn`. + * + * @param {Array} arr + * @param {Function} fn + * @param {Mixed} initial + * + * TODO: combatible error handling? + */ + +module.exports = function(arr, fn, initial){ + var idx = 0; + var len = arr.length; + var curr = arguments.length == 3 + ? initial + : arr[idx++]; + + while (idx < len) { + curr = fn.call(null, curr, arr[idx], ++idx, arr); + } + + return curr; +}; +},{}],14:[function(require,module,exports){ + +/** + * Module dependencies. + */ + +var global = (function() { return this; })(); + +/** + * WebSocket constructor. + */ + +var WebSocket = global.WebSocket || global.MozWebSocket; + +/** + * Module exports. + */ + +module.exports = WebSocket ? ws : null; + +/** + * WebSocket constructor. + * + * The third `opts` options object gets ignored in web browsers, since it's + * non-standard, and throws a TypeError if passed to the constructor. + * See: https://github.com/einaros/ws/issues/227 + * + * @param {String} uri + * @param {Array} protocols (optional) + * @param {Object) opts (optional) + * @api public + */ + +function ws(uri, protocols, opts) { + var instance; + if (protocols) { + instance = new WebSocket(uri, protocols); + } else { + instance = new WebSocket(uri); + } + return instance; +} + +if (WebSocket) ws.prototype = WebSocket.prototype; + +},{}]},{},[5])(5) +}); \ No newline at end of file diff --git a/web-dist/discord.min.3.3.2.js b/web-dist/discord.min.3.3.2.js new file mode 100644 index 000000000..9a41bcaad --- /dev/null +++ b/web-dist/discord.min.3.3.2.js @@ -0,0 +1,2 @@ +!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Discord=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g]*>/g)||[])[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;a.push(h.substring(2,h.length-1))}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return a}"function"==typeof c&&(d=c,c=!1),b=e+n(b);var p=o();f.resolveDestination(a).then(k)["catch"](j)});return g}},{key:"createws",value:function(a){if(this.websocket)return!1;var b=this;this.websocket=new o(a),this.websocket.onopen=function(){b.trySendConnData()},this.websocket.onclose=function(){b.trigger("disconnected")},this.websocket.onmessage=function(a){var c=!1,d={};try{c=JSON.parse(a.data),d=c.d}catch(e){return void b.trigger("error",e,a)}switch(c.t){case"READY":b.debug("received ready packet"),b.user=b.addUser(d.user);var f=!0,g=!1,i=void 0;try{for(var j,l=d.guilds[Symbol.iterator]();!(f=(j=l.next()).done);f=!0)var m=j.value,n=b.addServer(m)}catch(e){g=!0,i=e}finally{try{!f&&l["return"]&&l["return"]()}finally{if(g)throw i}}var o=!0,p=!1,q=void 0;try{for(var r,s=d.private_channels[Symbol.iterator]();!(o=(r=s.next()).done);o=!0){var t=r.value;b.addPMChannel(t)}}catch(e){p=!0,q=e}finally{try{!o&&s["return"]&&s["return"]()}finally{if(p)throw q}}b.trigger("ready"),b.readyTime=Date.now(),b.debug("cached "+b.serverCache.length+" servers, "+b.channelCache.length+" channels, "+b.pmChannelCache.length+" PMs and "+b.userCache.length+" users."),b.state=3,setInterval(function(){b.keepAlive.apply(b)},d.heartbeat_interval);break;case"MESSAGE_CREATE":b.debug("received message");var u=[];d.mentions=d.mentions||[];var v=!0,w=!1,x=void 0;try{for(var y,z=d.mentions[Symbol.iterator]();!(v=(y=z.next()).done);v=!0){var A=y.value;u.push(b.addUser(A))}}catch(e){w=!0,x=e}finally{try{!v&&z["return"]&&z["return"]()}finally{if(w)throw x}}var B=b.getChannel("id",d.channel_id);if(B){var C=B.addMessage(new k(d,B,u,b.addUser(d.author)));b.trigger("message",C)}break;case"MESSAGE_DELETE":b.debug("message deleted");var B=b.getChannel("id",d.channel_id),D=B.getMessage("id",d.id);D?(b.trigger("messageDelete",B,D),B.messages.splice(B.messages.indexOf(D),1)):b.trigger("messageDelete",B);break;case"MESSAGE_UPDATE":b.debug("message updated");var B=b.getChannel("id",d.channel_id),E=B.getMessage("id",d.id);if(E){var F={};for(var G in E)F[G]=E[G];for(var G in d)F[G]=d[G];var u=[],H=!0,I=!1,J=void 0;try{for(var K,L=F.mentions[Symbol.iterator]();!(H=(K=L.next()).done);H=!0){var A=K.value;u.push(b.addUser(A))}}catch(e){I=!0,J=e}finally{try{!H&&L["return"]&&L["return"]()}finally{if(I)throw J}}var M=new k(F,B,u,E.author);b.trigger("messageUpdate",M,E),B.messages[B.messages.indexOf(E)]=M}break;case"GUILD_DELETE":var n=b.getServer("id",d.id);n&&(b.serverCache.splice(b.serverCache.indexOf(n),1),b.trigger("serverDelete",n));break;case"CHANNEL_DELETE":var B=b.getChannel("id",d.id);if(B){var n=B.server;n&&n.channels.splice(n.channels.indexOf(B),1),b.trigger("channelDelete",B),b.serverCache.splice(b.serverCache.indexOf(B),1)}break;case"GUILD_CREATE":var n=b.getServer("id",d.id);if(n||(n=b.addServer(d)),b.serverCreateListener.get(d.id)){var N=b.serverCreateListener.get(d.id);N[0](n),N[1](null,n),b.serverCreateListener["delete"](d.id)}b.trigger("serverCreate",n);break;case"CHANNEL_CREATE":var B=b.getChannel("id",d.id);if(!B){var O=b.addChannel(d,d.guild_id),P=b.getServer("id",d.guild_id);P&&P.addChannel(O),b.trigger("channelCreate",O)}break;case"GUILD_MEMBER_ADD":var n=b.getServer("id",d.guild_id);if(n){var Q=b.addUser(d.user);~n.members.indexOf(Q)||n.members.push(Q),b.trigger("serverNewMember",Q,n)}break;case"GUILD_MEMBER_REMOVE":var n=b.getServer("id",d.guild_id);if(n){var Q=b.addUser(d.user);~n.members.indexOf(Q)&&n.members.splice(n.members.indexOf(Q),1),b.trigger("serverRemoveMember",Q,n)}break;case"USER_UPDATE":if(b.user&&d.id===b.user.id){var R=new h(d);b.trigger("userUpdate",R,b.user),~b.userCache.indexOf(b.user)&&(b.userCache[b.userCache.indexOf(b.user)]=R),b.user=R}break;case"PRESENCE_UPDATE":var S=b.getUser("id",d.user.id);if(S){var T=new h(d.user);T.equalsStrict(S)?b.trigger("presence",{user:S,status:d.status,server:b.getServer("id",d.guild_id),gameId:d.game_id}):(b.trigger("userUpdate",S,T),b.userCache[b.userCache.indexOf(S)]=T)}break;default:b.debug("received unknown packet"),b.trigger("unknown",c)}}}},{key:"addUser",value:function(a){return this.getUser("id",a.id)||this.userCache.push(new h(a)),this.getUser("id",a.id)}},{key:"addChannel",value:function(a,b){return this.getChannel("id",a.id)||this.channelCache.push(new j(a,this.getServer("id",b))),this.getChannel("id",a.id)}},{key:"addPMChannel",value:function(a){return this.getPMChannel("id",a.id)||this.pmChannelCache.push(new m(a,this)),this.getPMChannel("id",a.id)}},{key:"addServer",value:function(a){var b=this.getServer("id",a.id);if(!b&&(b=new i(a,this),this.serverCache.push(b),a.channels)){var c=!0,d=!1,e=void 0;try{for(var f,g=a.channels[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;b.channels.push(this.addChannel(h,b.id))}}catch(j){d=!0,e=j}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}}return b}},{key:"getUser",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.userCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"getChannel",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.channelCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return this.getPMChannel(a,b)}},{key:"getPMChannel",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.pmChannelCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"getServer",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.serverCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"trySendConnData",value:function(){if(this.token&&!this.alreadySentData){this.alreadySentData=!0;var a={op:2,d:{token:this.token,v:2,properties:{$os:"discord.js",$browser:"discord.js",$device:"discord.js",$referrer:"",$referring_domain:""}}};this.websocket.send(JSON.stringify(a))}}},{key:"resolveServerID",value:function(a){return a instanceof i?a.id:!isNaN(a)&&a.length&&17===a.length?a:void 0}},{key:"resolveDestination",value:function(a){var b=!1,c=this;return new Promise(function(d,e){if(a instanceof i)b=a.id;else if(a instanceof j)b=a.id;else if(a instanceof k)b=a.channel.id;else if(a instanceof h){var f=!0,g=!1,l=void 0;try{for(var m,n=c.pmChannelCache[Symbol.iterator]();!(f=(m=n.next()).done);f=!0){var o=m.value;if(o.user.equals(a))return void d(o.id)}}catch(p){g=!0,l=p}finally{try{!f&&n["return"]&&n["return"]()}finally{if(g)throw l}}c.startPM(a).then(function(a){console.log(a),d(a.id)})["catch"](e)}else b=a;b&&d(b)})}},{key:"_sendMessage",value:function(a,b,c,d){var e=this;return new Promise(function(f,h){n.post(g.CHANNELS+"/"+a+"/messages").set("authorization",e.token).send({content:b,mentions:d,tts:c}).end(function(a,b){if(a)h(a);else{var c=b.body,d=[];c.mentions=c.mentions||[];var g=!0,i=!1,j=void 0;try{for(var l,m=c.mentions[Symbol.iterator]();!(g=(l=m.next()).done);g=!0){var n=l.value;d.push(e.addUser(n))}}catch(a){i=!0,j=a}finally{try{!g&&m["return"]&&m["return"]()}finally{if(i)throw j}}var o=e.getChannel("id",c.channel_id);if(o){var p=o.addMessage(new k(c,o,d,e.addUser(c.author)));f(p)}}})})}},{key:"_sendFile",value:function(a,b){var c=arguments.length<=2||void 0===arguments[2]?"DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png":arguments[2],d=this;return new Promise(function(e,f){n.post(g.CHANNELS+"/"+a+"/messages").set("authorization",d.token).attach("file",b,c).end(function(b,c){if(b)f(b);else{var g=d.getChannel("id",a);if(g){var h=g.addMessage(new k(c.body,g,[],d.user));e(h)}}})})}},{key:"_updateMessage",value:function(a,b){var c=this;return new Promise(function(d,e){n.patch(g.CHANNELS+"/"+a.channel.id+"/messages/"+a.id).set("authorization",c.token).send({content:b,mentions:[]}).end(function(b,c){if(b)e(b);else{var f=new k(c.body,a.channel,a.mentions,a.sender);d(f),a.channel.messages[a.channel.messages.indexOf(a)]=f}})})}},{key:"_deleteMessage",value:function(a){var b=this;return new Promise(function(c,d){n.del(g.CHANNELS+"/"+a.channel.id+"/messages/"+a.id).set("authorization",b.token).end(function(a,b){a?d(a):c()})})}},{key:"checkQueue",value:function(a){var b=this,c=this;this.checkingQueue[a]||!function(){var d=function f(){if(0===c.queue[a].length)return void e();var b=c.queue[a][0];switch(b.action){case"sendMessage":var d=b;c._sendMessage(a,d.content,d.tts,d.mentions).then(function(b){d.then(b),c.queue[a].shift(),f()})["catch"](function(b){d.error(b),c.queue[a].shift(),f()});break;case"sendFile":var g=b;c._sendFile(a,g.attachment,g.attachmentName).then(function(b){g.then(b),c.queue[a].shift(),f()})["catch"](function(b){g.error(b),c.queue[a].shift(),f()});break;case"updateMessage":var h=b;c._updateMessage(h.message,h.content).then(function(b){h.then(b),c.queue[a].shift(),f()})["catch"](function(b){h.error(b),c.queue[a].shift(),f()});break;case"deleteMessage":var i=b;c._deleteMessage(i.message).then(function(b){i.then(b),c.queue[a].shift(),f()})["catch"](function(b){i.error(b),c.queue[a].shift(),f()});break;default:e()}},e=function(){c.checkingQueue[a]=!1};b.checkingQueue[a]=!0,d()}()}},{key:"uptime",get:function(){return this.readyTime?Date.now()-this.readyTime:null}},{key:"ready",get:function(){return 3===this.state}},{key:"servers",get:function(){return this.serverCache}},{key:"channels",get:function(){return this.channelCache}},{key:"users",get:function(){return this.userCache}},{key:"PMChannels",get:function(){return this.pmChannelCache}},{key:"messages",get:function(){var a=[],b=!0,c=!1,d=void 0;try{for(var e,f=this.channelCache[Symbol.iterator]();!(b=(e=f.next()).done);b=!0){var g=e.value;a=a.concat(g.messages)}}catch(h){c=!0,d=h}finally{try{!b&&f["return"]&&f["return"]()}finally{if(c)throw d}}return a}}]),a}();b.exports=r},{"./Endpoints.js":2,"./PMChannel.js":3,"./channel.js":4,"./invite.js":6,"./message.js":7,"./server.js":8,"./user.js":9,fs:10,superagent:11,ws:14}],2:[function(a,b,c){"use strict";c.BASE_DOMAIN="discordapp.com",c.BASE="https://"+c.BASE_DOMAIN,c.WEBSOCKET_HUB="wss://"+c.BASE_DOMAIN+"/hub",c.API=c.BASE+"/api",c.AUTH=c.API+"/auth",c.LOGIN=c.AUTH+"/login",c.LOGOUT=c.AUTH+"/logout",c.USERS=c.API+"/users",c.SERVERS=c.API+"/guilds",c.CHANNELS=c.API+"/channels"},{}],3:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c"}},{key:"toString",value:function(){return this.mention()}},{key:"equals",value:function(a){return a.id===this.id}},{key:"equalsStrict",value:function(a){return a.id===this.id&&a.avatar===this.avatar&&a.username===this.username&&a.discriminator===this.discriminator}},{key:"avatarURL",get:function(){return this.avatar?"https://discordapp.com/api/users/"+this.id+"/avatars/"+this.avatar+".jpg":null}}]),a}();b.exports=f},{}],10:[function(a,b,c){},{}],11:[function(a,b,c){function d(){}function e(a){var b={}.toString.call(a);switch(b){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function f(a){return a===Object(a)}function g(a){if(!f(a))return a;var b=[];for(var c in a)null!=a[c]&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")}function h(a){for(var b,c,d={},e=a.split("&"),f=0,g=e.length;g>f;++f)c=e[f],b=c.split("="),d[decodeURIComponent(b[0])]=decodeURIComponent(b[1]);return d}function i(a){var b,c,d,e,f=a.split(/\r?\n/),g={};f.pop();for(var h=0,i=f.length;i>h;++h)c=f[h],b=c.indexOf(":"),d=c.slice(0,b).toLowerCase(),e=r(c.slice(b+1)),g[d]=e;return g}function j(a){return a.split(/ *; */).shift()}function k(a){return p(a.split(/ *; */),function(a,b){var c=b.split(/ *= */),d=c.shift(),e=c.shift();return d&&e&&(a[d]=e),a},{})}function l(a,b){b=b||{},this.req=a,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||"undefined"==typeof this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText,this.setStatusProperties(this.xhr.status),this.header=this.headers=i(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body="HEAD"!=this.req.method?this.parseBody(this.text?this.text:this.xhr.response):null}function m(a,b){var c=this;o.call(this),this._query=this._query||[],this.method=a,this.url=b,this.header={},this._header={},this.on("end",function(){var a=null,b=null;try{b=new l(c)}catch(d){return a=new Error("Parser is unable to parse the response"),a.parse=!0,a.original=d,c.callback(a)}if(c.emit("response",b),a)return c.callback(a,b);if(b.status>=200&&b.status<300)return c.callback(a,b);var e=new Error(b.statusText||"Unsuccessful HTTP response");e.original=a,e.response=b,e.status=b.status,c.callback(e,b)})}function n(a,b){return"function"==typeof b?new m("GET",a).end(b):1==arguments.length?new m("GET",a):new m(a,b)}var o=a("emitter"),p=a("reduce"),q="undefined"==typeof window?this||self:window;n.getXHR=function(){if(!(!q.XMLHttpRequest||q.location&&"file:"==q.location.protocol&&q.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(a){}return!1};var r="".trim?function(a){return a.trim()}:function(a){return a.replace(/(^\s*|\s*$)/g,"")};n.serializeObject=g,n.parseString=h,n.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},n.serialize={"application/x-www-form-urlencoded":g,"application/json":JSON.stringify},n.parse={"application/x-www-form-urlencoded":h,"application/json":JSON.parse},l.prototype.get=function(a){return this.header[a.toLowerCase()]},l.prototype.setHeaderProperties=function(a){var b=this.header["content-type"]||"";this.type=j(b);var c=k(b);for(var d in c)this[d]=c[d]},l.prototype.parseBody=function(a){var b=n.parse[this.type];return b&&a&&(a.length||a instanceof Object)?b(a):null},l.prototype.setStatusProperties=function(a){1223===a&&(a=204);var b=a/100|0;this.status=a,this.statusType=b,this.info=1==b,this.ok=2==b,this.clientError=4==b,this.serverError=5==b,this.error=4==b||5==b?this.toError():!1,this.accepted=202==a,this.noContent=204==a,this.badRequest=400==a,this.unauthorized=401==a,this.notAcceptable=406==a,this.notFound=404==a,this.forbidden=403==a},l.prototype.toError=function(){var a=this.req,b=a.method,c=a.url,d="cannot "+b+" "+c+" ("+this.status+")",e=new Error(d);return e.status=this.status,e.method=b,e.url=c,e},n.Response=l,o(m.prototype),m.prototype.use=function(a){return a(this),this},m.prototype.timeout=function(a){return this._timeout=a,this},m.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},m.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0, +this.xhr.abort(),this.clearTimeout(),this.emit("abort"),this)},m.prototype.set=function(a,b){if(f(a)){for(var c in a)this.set(c,a[c]);return this}return this._header[a.toLowerCase()]=b,this.header[a]=b,this},m.prototype.unset=function(a){return delete this._header[a.toLowerCase()],delete this.header[a],this},m.prototype.getHeader=function(a){return this._header[a.toLowerCase()]},m.prototype.type=function(a){return this.set("Content-Type",n.types[a]||a),this},m.prototype.accept=function(a){return this.set("Accept",n.types[a]||a),this},m.prototype.auth=function(a,b){var c=btoa(a+":"+b);return this.set("Authorization","Basic "+c),this},m.prototype.query=function(a){return"string"!=typeof a&&(a=g(a)),a&&this._query.push(a),this},m.prototype.field=function(a,b){return this._formData||(this._formData=new q.FormData),this._formData.append(a,b),this},m.prototype.attach=function(a,b,c){return this._formData||(this._formData=new q.FormData),this._formData.append(a,b,c),this},m.prototype.send=function(a){var b=f(a),c=this.getHeader("Content-Type");if(b&&f(this._data))for(var d in a)this._data[d]=a[d];else"string"==typeof a?(c||this.type("form"),c=this.getHeader("Content-Type"),"application/x-www-form-urlencoded"==c?this._data=this._data?this._data+"&"+a:a:this._data=(this._data||"")+a):this._data=a;return!b||e(a)?this:(c||this.type("json"),this)},m.prototype.callback=function(a,b){var c=this._callback;this.clearTimeout(),c(a,b)},m.prototype.crossDomainError=function(){var a=new Error("Origin is not allowed by Access-Control-Allow-Origin");a.crossDomain=!0,this.callback(a)},m.prototype.timeoutError=function(){var a=this._timeout,b=new Error("timeout of "+a+"ms exceeded");b.timeout=a,this.callback(b)},m.prototype.withCredentials=function(){return this._withCredentials=!0,this},m.prototype.end=function(a){var b=this,c=this.xhr=n.getXHR(),f=this._query.join("&"),g=this._timeout,h=this._formData||this._data;this._callback=a||d,c.onreadystatechange=function(){if(4==c.readyState){var a;try{a=c.status}catch(d){a=0}if(0==a){if(b.timedout)return b.timeoutError();if(b.aborted)return;return b.crossDomainError()}b.emit("end")}};var i=function(a){a.total>0&&(a.percent=a.loaded/a.total*100),b.emit("progress",a)};this.hasListeners("progress")&&(c.onprogress=i);try{c.upload&&this.hasListeners("progress")&&(c.upload.onprogress=i)}catch(j){}if(g&&!this._timer&&(this._timer=setTimeout(function(){b.timedout=!0,b.abort()},g)),f&&(f=n.serializeObject(f),this.url+=~this.url.indexOf("?")?"&"+f:"?"+f),c.open(this.method,this.url,!0),this._withCredentials&&(c.withCredentials=!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof h&&!e(h)){var k=this.getHeader("Content-Type"),l=n.serialize[k?k.split(";")[0]:""];l&&(h=l(h))}for(var m in this.header)null!=this.header[m]&&c.setRequestHeader(m,this.header[m]);return this.emit("request",this),c.send(h),this},m.prototype.then=function(a,b){return this.end(function(c,d){c?b(c):a(d)})},n.Request=m,n.get=function(a,b,c){var d=n("GET",a);return"function"==typeof b&&(c=b,b=null),b&&d.query(b),c&&d.end(c),d},n.head=function(a,b,c){var d=n("HEAD",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.del=function(a,b){var c=n("DELETE",a);return b&&c.end(b),c},n.patch=function(a,b,c){var d=n("PATCH",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.post=function(a,b,c){var d=n("POST",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.put=function(a,b,c){var d=n("PUT",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},b.exports=n},{emitter:12,reduce:13}],12:[function(a,b,c){function d(a){return a?e(a):void 0}function e(a){for(var b in d.prototype)a[b]=d.prototype[b];return a}b.exports=d,d.prototype.on=d.prototype.addEventListener=function(a,b){return this._callbacks=this._callbacks||{},(this._callbacks[a]=this._callbacks[a]||[]).push(b),this},d.prototype.once=function(a,b){function c(){d.off(a,c),b.apply(this,arguments)}var d=this;return this._callbacks=this._callbacks||{},c.fn=b,this.on(a,c),this},d.prototype.off=d.prototype.removeListener=d.prototype.removeAllListeners=d.prototype.removeEventListener=function(a,b){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var c=this._callbacks[a];if(!c)return this;if(1==arguments.length)return delete this._callbacks[a],this;for(var d,e=0;ed;++d)c[d].apply(this,b)}return this},d.prototype.listeners=function(a){return this._callbacks=this._callbacks||{},this._callbacks[a]||[]},d.prototype.hasListeners=function(a){return!!this.listeners(a).length}},{}],13:[function(a,b,c){b.exports=function(a,b,c){for(var d=0,e=a.length,f=3==arguments.length?c:a[d++];e>d;)f=b.call(null,f,a[d],++d,a);return f}},{}],14:[function(a,b,c){function d(a,b,c){var d;return d=b?new f(a,b):new f(a)}var e=function(){return this}(),f=e.WebSocket||e.MozWebSocket;b.exports=f?d:null,f&&(d.prototype=f.prototype)},{}]},{},[5])(5)}); \ No newline at end of file From c4d9405f64621146ce0c06d366bb4b7dc773dbc1 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 12 Sep 2015 16:00:38 +0100 Subject: [PATCH 014/151] Preparing for major API change, added authorisation param to request --- lib/Client.js | 31 ++++--- src/Client.js | 230 +++++++++++++++++++++++++------------------------- 2 files changed, 129 insertions(+), 132 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 80b9a925f..b14d8815d 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -148,7 +148,7 @@ var Client = (function () { self.state = 2; //set state to logged in (not yet ready) self.token = res.body.token; //set our token - getGateway().then(function (url) { + self.getGateway().then(function (url) { self.createws(url); callback(null, self.token); resolve(self.token); @@ -1600,6 +1600,20 @@ var Client = (function () { })(); } } + }, { + key: "getGateway", + value: function getGateway() { + var self = this; + return new Promise(function (resolve, reject) { + request.get(Endpoints.API + "/gateway").set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(res.body.url); + } + }); + }); + } }, { key: "uptime", get: function get() { @@ -1668,19 +1682,4 @@ var Client = (function () { return Client; })(); -function getGateway() { - - var self = this; - - return new Promise(function (resolve, reject) { - request.get(Endpoints.API + "/gateway").end(function (err, res) { - if (err) { - reject(err); - } else { - resolve(res.body.url); - } - }); - }); -} - module.exports = Client; \ No newline at end of file diff --git a/src/Client.js b/src/Client.js index 6421121e6..1f46a0850 100644 --- a/src/Client.js +++ b/src/Client.js @@ -153,7 +153,7 @@ class Client { if (err) { self.state = 4; //set state to disconnected self.trigger("disconnected"); - if(self.websocket){ + if (self.websocket) { self.websocket.close(); } callback(err); @@ -162,7 +162,7 @@ class Client { self.state = 2; //set state to logged in (not yet ready) self.token = res.body.token; //set our token - getGateway().then(function (url) { + self.getGateway().then(function (url) { self.createws(url); callback(null, self.token); resolve(self.token); @@ -367,7 +367,7 @@ class Client { return new Promise(function (response, reject) { - if(typeof tts === "function"){ + if (typeof tts === "function") { // tts is a function, which means the developer wants this to be the callback callback = tts; tts = false; @@ -383,7 +383,7 @@ class Client { deleteMessage(message, timeout, callback = function (err, msg) { }) { var self = this; - + var prom = new Promise(function (resolve, reject) { if (timeout) { setTimeout(remove, timeout) @@ -392,7 +392,7 @@ class Client { } function remove() { - if(self.options.queue){ + if (self.options.queue) { if (!self.queue[message.channel.id]) { self.queue[message.channel.id] = []; } @@ -402,26 +402,26 @@ class Client { then: good, error: bad }); - + self.checkQueue(message.channel.id); - }else{ + } else { self._deleteMessage(message).then(good).catch(bad); } } - - function good(){ + + function good() { prom.success = true; callback(null); resolve(); } - - function bad(err){ + + function bad(err) { prom.error = err; callback(err); reject(err); } }); - + return prom; } @@ -433,7 +433,7 @@ class Client { content = (content instanceof Array ? content.join("\n") : content); - if(self.options.queue){ + if (self.options.queue) { if (!self.queue[message.channel.id]) { self.queue[message.channel.id] = []; } @@ -444,26 +444,26 @@ class Client { then: good, error: bad }); - + self.checkQueue(message.channel.id); - }else{ + } else { self._updateMessage(message, content).then(good).catch(bad); } - - function good(msg){ - prom.message = msg; - callback(null, msg); - resolve(msg); - } - - function bad(error){ - prom.error = error; - callback(error); - reject(error); - } + + function good(msg) { + prom.message = msg; + callback(null, msg); + resolve(msg); + } + + function bad(error) { + prom.error = error; + callback(error); + reject(error); + } }); - + return prom; } @@ -611,7 +611,7 @@ class Client { self.resolveDestination(destination).then(send).catch(bad); function send(destination) { - if(self.options.queue){ + if (self.options.queue) { //queue send file too if (!self.queue[destination]) { self.queue[destination] = []; @@ -619,14 +619,14 @@ class Client { self.queue[destination].push({ action: "sendFile", - attachment : fstream, - attachmentName : fileName, + attachment: fstream, + attachmentName: fileName, then: good, error: bad }); self.checkQueue(destination); - }else{ + } else { //not queue self._sendFile(destination, fstream, fileName).then(good).catch(bad); } @@ -645,7 +645,7 @@ class Client { } }); - + return prom; } @@ -655,13 +655,13 @@ class Client { var self = this; var prom = new Promise(function (resolve, reject) { - - if(typeof tts === "function"){ + + if (typeof tts === "function") { // tts is a function, which means the developer wants this to be the callback callback = tts; tts = false; } - + message = premessage + resolveMessage(message); var mentions = resolveMentions(); self.resolveDestination(destination).then(send).catch(error); @@ -682,7 +682,7 @@ class Client { action: "sendMessage", content: message, mentions: mentions, - tts : !!tts, //incase it's not a boolean + tts: !!tts, //incase it's not a boolean then: mgood, error: mbad }); @@ -723,7 +723,7 @@ class Client { } }); - + return prom; } @@ -1179,7 +1179,7 @@ class Client { .send({ content: content, mentions: mentions, - tts : tts + tts: tts }) .end(function (err, res) { @@ -1207,39 +1207,39 @@ class Client { }); } - - _sendFile(destination, attachment, attachmentName = "DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png"){ - + + _sendFile(destination, attachment, attachmentName = "DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png") { + var self = this; - - return new Promise(function(resolve, reject){ - request - .post(`${Endpoints.CHANNELS}/${destination}/messages`) - .set("authorization", self.token) - .attach("file", attachment, attachmentName) - .end(function (err, res) { - if (err) { - reject(err); - } else { - - var chann = self.getChannel("id", destination); - if (chann) { - var msg = chann.addMessage(new Message(res.body, chann, [], self.user)); - resolve(msg); - } + return new Promise(function (resolve, reject) { + request + .post(`${Endpoints.CHANNELS}/${destination}/messages`) + .set("authorization", self.token) + .attach("file", attachment, attachmentName) + .end(function (err, res) { + if (err) { + reject(err); + } else { + var chann = self.getChannel("id", destination); + if (chann) { + var msg = chann.addMessage(new Message(res.body, chann, [], self.user)); + resolve(msg); } - }); + + } + + }); }); - + } - - _updateMessage(message, content){ + + _updateMessage(message, content) { var self = this; - return new Promise(function(resolve, reject){ + return new Promise(function (resolve, reject) { request .patch(`${Endpoints.CHANNELS}/${message.channel.id}/messages/${message.id}`) .set("authorization", self.token) @@ -1258,28 +1258,28 @@ class Client { }); }); } - - _deleteMessage(message){ + + _deleteMessage(message) { var self = this; - return new Promise(function(resolve, reject){ - + return new Promise(function (resolve, reject) { + request - .del(`${Endpoints.CHANNELS}/${message.channel.id}/messages/${message.id}`) - .set("authorization", self.token) - .end(function (err, res) { - if (err) { - reject(err); - } else { - resolve(); - } - }); + .del(`${Endpoints.CHANNELS}/${message.channel.id}/messages/${message.id}`) + .set("authorization", self.token) + .end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(); + } + }); }); } checkQueue(channelID) { var self = this; - + if (!this.checkingQueue[channelID]) { //if we aren't already checking this queue. this.checkingQueue[channelID] = true; @@ -1309,12 +1309,12 @@ class Client { case "sendFile": var fileToSend = queuedEvent; self._sendFile(channelID, fileToSend.attachment, fileToSend.attachmentName) - .then(function (msg){ + .then(function (msg) { fileToSend.then(msg); self.queue[channelID].shift(); doNext(); }) - .catch(function(err){ + .catch(function (err) { fileToSend.error(err); self.queue[channelID].shift(); doNext(); @@ -1323,30 +1323,30 @@ class Client { case "updateMessage": var msgToUpd = queuedEvent; self._updateMessage(msgToUpd.message, msgToUpd.content) - .then(function(msg){ - msgToUpd.then(msg); - self.queue[channelID].shift(); - doNext(); - }) - .catch(function(err){ - msgToUpd.error(err); - self.queue[channelID].shift(); - doNext(); - }); + .then(function (msg) { + msgToUpd.then(msg); + self.queue[channelID].shift(); + doNext(); + }) + .catch(function (err) { + msgToUpd.error(err); + self.queue[channelID].shift(); + doNext(); + }); break; case "deleteMessage": var msgToDel = queuedEvent; self._deleteMessage(msgToDel.message) - .then(function(msg){ - msgToDel.then(msg); - self.queue[channelID].shift(); - doNext(); - }) - .catch(function(err){ - msgToDel.error(err); - self.queue[channelID].shift(); - doNext(); - }); + .then(function (msg) { + msgToDel.then(msg); + self.queue[channelID].shift(); + doNext(); + }) + .catch(function (err) { + msgToDel.error(err); + self.queue[channelID].shift(); + doNext(); + }); break; default: done(); @@ -1360,24 +1360,22 @@ class Client { } } } -} - -function getGateway() { - - var self = this; - - return new Promise(function (resolve, reject) { - request - .get(`${Endpoints.API}/gateway`) - .end(function (err, res) { - if (err) { - reject(err); - } else { - resolve(res.body.url); - } - }); - }); + getGateway() { + var self = this; + return new Promise(function (resolve, reject) { + request + .get(`${Endpoints.API}/gateway`) + .set("authorization", self.token) + .end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(res.body.url); + } + }); + }); + } } module.exports = Client; \ No newline at end of file From c904bdb3c30c96bc3cf4b7bb19b0b39057f2f222 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 12 Sep 2015 16:05:52 +0100 Subject: [PATCH 015/151] added .users as well as .members in Server class --- lib/server.js | 5 +++++ src/server.js | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/lib/server.js b/lib/server.js index 5bf3beca1..a5c90170d 100644 --- a/lib/server.js +++ b/lib/server.js @@ -165,6 +165,11 @@ var Server = (function () { get: function get() { return this.client.getUser("id", this.ownerID); } + }, { + key: "users", + get: function get() { + return this.members; + } }]); return Server; diff --git a/src/server.js b/src/server.js index 248a04683..c0f24af27 100644 --- a/src/server.js +++ b/src/server.js @@ -50,6 +50,10 @@ class Server { return this.client.getUser("id", this.ownerID); } + get users() { + return this.members; + } + // get/set getChannel(key, value) { for (var channel of this.channels) { From 106addbb1a0293c23b6bfd8f80f883d89fd7e153 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 12 Sep 2015 16:07:48 +0100 Subject: [PATCH 016/151] Added channel toString --- lib/channel.js | 2 +- src/channel.js | 2 +- test/bot.1.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/channel.js b/lib/channel.js index dfb4f72d8..79bc71b55 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -64,7 +64,7 @@ var Channel = (function () { }, { key: "toString", value: function toString() { - return "#" + this.name; + return "<#" + this.id + ">"; } }, { key: "client", diff --git a/src/channel.js b/src/channel.js index 0dc0b957a..d813e9b74 100644 --- a/src/channel.js +++ b/src/channel.js @@ -34,7 +34,7 @@ class Channel { } toString(){ - return "#" + this.name; + return "<#" + this.id + ">"; } get isPrivate(){ diff --git a/test/bot.1.js b/test/bot.1.js index f99314baa..38f25d390 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -17,7 +17,7 @@ mybot.on("message", function (message) { } // we can go ahead :) - mybot.sendMessage(message.author, message.sender.username); + mybot.reply(message, message.channel); }); mybot.on("ready", function () { From efe07dbfc5b890f4771131afbea4a2b8876b8b4a Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 12 Sep 2015 16:09:10 +0100 Subject: [PATCH 017/151] Fixed reply method --- lib/Client.js | 2 +- src/Client.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index b14d8815d..71124b2ce 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -337,7 +337,7 @@ var Client = (function () { } var user = destination.sender; - self.sendMessage(destination, message, callback, user + ", ").then(response)["catch"](reject); + self.sendMessage(destination, message, tts, callback, user + ", ").then(response)["catch"](reject); }); } }, { diff --git a/src/Client.js b/src/Client.js index 1f46a0850..89486be44 100644 --- a/src/Client.js +++ b/src/Client.js @@ -374,7 +374,7 @@ class Client { } var user = destination.sender; - self.sendMessage(destination, message, callback, user + ", ").then(response).catch(reject); + self.sendMessage(destination, message, tts, callback, user + ", ").then(response).catch(reject); }); From cc2470054a65e5c2e20dbb297acb09e93b4807f9 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 12 Sep 2015 16:10:09 +0100 Subject: [PATCH 018/151] Updated version to 3.3.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4af3dbde8..55f98889f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.3.2", + "version": "3.3.3", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From ae1202aa2d254876f677eb8c822da0012a83b840 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 13 Sep 2015 15:19:54 +0100 Subject: [PATCH 019/151] 3.3.4, added support for older node versions --- lib/Client.js | 12 ++++++------ package.json | 2 +- src/Client.js | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 71124b2ce..eff03e5aa 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -42,7 +42,7 @@ var Client = (function () { this.events = {}; this.user = null; this.alreadySentData = false; - this.serverCreateListener = new Map(); + this.serverCreateListener = {}; this.email = "abc"; this.password = "abc"; @@ -205,7 +205,7 @@ var Client = (function () { // potentially redundant in future // creating here does NOT give us the channels of the server // so we must wait for the guild_create event. - self.serverCreateListener.set(res.body.id, [resolve, callback]); + self.serverCreateListener[res.body.id] = [resolve, callback]; /*var srv = self.addServer(res.body); callback(null, srv); resolve(srv);*/ @@ -578,7 +578,7 @@ var Client = (function () { if (self.getServer("id", res.body.guild.id)) { resolve(self.getServer("id", res.body.guild.id)); } else { - self.serverCreateListener.set(res.body.guild.id, [resolve, callback]); + self.serverCreateListener[res.body.guild.id] = [resolve, callback]; } } }); @@ -1000,11 +1000,11 @@ var Client = (function () { }*/ - if (self.serverCreateListener.get(data.id)) { - var cbs = self.serverCreateListener.get(data.id); + if (self.serverCreateListener[data.id]) { + var cbs = self.serverCreateListener[data.id]; cbs[0](server); //promise then callback cbs[1](null, server); //legacy callback - self.serverCreateListener["delete"](data.id); + self.serverCreateListener[data.id] = null; } self.trigger("serverCreate", server); diff --git a/package.json b/package.json index 55f98889f..89ca0fba0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.3.3", + "version": "3.3.4", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { diff --git a/src/Client.js b/src/Client.js index 89486be44..f7919a653 100644 --- a/src/Client.js +++ b/src/Client.js @@ -32,7 +32,7 @@ class Client { this.events = {}; this.user = null; this.alreadySentData = false; - this.serverCreateListener = new Map(); + this.serverCreateListener = {}; this.email = "abc"; this.password = "abc"; @@ -227,7 +227,7 @@ class Client { // potentially redundant in future // creating here does NOT give us the channels of the server // so we must wait for the guild_create event. - self.serverCreateListener.set(res.body.id, [resolve, callback]); + self.serverCreateListener[res.body.id] = [resolve, callback]; /*var srv = self.addServer(res.body); callback(null, srv); resolve(srv);*/ @@ -584,7 +584,7 @@ class Client { if (self.getServer("id", res.body.guild.id)) { resolve(self.getServer("id", res.body.guild.id)); } else { - self.serverCreateListener.set(res.body.guild.id, [resolve, callback]); + self.serverCreateListener[res.body.guild.id] = [resolve, callback]; } } }); @@ -903,11 +903,11 @@ class Client { }*/ - if (self.serverCreateListener.get(data.id)) { - var cbs = self.serverCreateListener.get(data.id); + if (self.serverCreateListener[data.id]) { + var cbs = self.serverCreateListener[data.id]; cbs[0](server); //promise then callback cbs[1](null, server); //legacy callback - self.serverCreateListener.delete(data.id); + self.serverCreateListener[data.id] = null; } self.trigger("serverCreate", server); From e1458b6405936c9d6599edc1aba591c14fd62cb3 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 25 Sep 2015 17:26:10 +0100 Subject: [PATCH 020/151] makethedocs commit 1 init --- docs/Makefile | 192 +++++++++++++++++++++++++++++++++ docs/conf.py | 284 +++++++++++++++++++++++++++++++++++++++++++++++++ docs/index.rst | 22 ++++ docs/make.bat | 263 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 761 insertions(+) create mode 100644 docs/Makefile create mode 100644 docs/conf.py create mode 100644 docs/index.rst create mode 100644 docs/make.bat diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 000000000..751136e57 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,192 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) +$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " applehelp to make an Apple Help Book" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + @echo " coverage to run coverage check of the documentation (if enabled)" + +clean: + rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/discordjs.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/discordjs.qhc" + +applehelp: + $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp + @echo + @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." + @echo "N.B. You won't be able to view it unless you put it in" \ + "~/Library/Documentation/Help or install it in your application" \ + "bundle." + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/discordjs" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/discordjs" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +coverage: + $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage + @echo "Testing of coverage in the sources finished, look at the " \ + "results in $(BUILDDIR)/coverage/python.txt." + +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 000000000..a7c230819 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,284 @@ +# -*- coding: utf-8 -*- +# +# discord.js documentation build configuration file, created by +# sphinx-quickstart on Fri Sep 25 17:25:49 2015. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os +import shlex + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.insert(0, os.path.abspath('.')) + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'discord.js' +copyright = u'2015, hydrabolt' +author = u'hydrabolt' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '3.3.4' +# The full version, including alpha/beta/rc tags. +release = '3.3.4' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'alabaster' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' +#html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# Now only 'ja' uses this config value +#html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +#html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = 'discordjsdoc' + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', + +# Latex figure (float) alignment +#'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'discordjs.tex', u'discord.js Documentation', + u'hydrabolt', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'discordjs', u'discord.js Documentation', + [author], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'discordjs', u'discord.js Documentation', + author, 'discordjs', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 000000000..88345f66d --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,22 @@ +.. discord.js documentation master file, created by + sphinx-quickstart on Fri Sep 25 17:25:49 2015. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to discord.js's documentation! +====================================== + +Contents: + +.. toctree:: + :maxdepth: 2 + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 000000000..c3d1c3bcc --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,263 @@ +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set BUILDDIR=_build +set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . +set I18NSPHINXOPTS=%SPHINXOPTS% . +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^` where ^ is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. xml to make Docutils-native XML files + echo. pseudoxml to make pseudoxml-XML files for display purposes + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + echo. coverage to run coverage check of the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + + +REM Check if sphinx-build is available and fallback to Python version if any +%SPHINXBUILD% 2> nul +if errorlevel 9009 goto sphinx_python +goto sphinx_ok + +:sphinx_python + +set SPHINXBUILD=python -m sphinx.__init__ +%SPHINXBUILD% 2> nul +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +:sphinx_ok + + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\discordjs.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\discordjs.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdf" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf + cd %~dp0 + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdfja" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf-ja + cd %~dp0 + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +if "%1" == "coverage" ( + %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage + if errorlevel 1 exit /b 1 + echo. + echo.Testing of coverage in the sources finished, look at the ^ +results in %BUILDDIR%/coverage/python.txt. + goto end +) + +if "%1" == "xml" ( + %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The XML files are in %BUILDDIR%/xml. + goto end +) + +if "%1" == "pseudoxml" ( + %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. + goto end +) + +:end From 88b4332583cc1ddcd6784167184e629754bca58d Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 25 Sep 2015 17:29:32 +0100 Subject: [PATCH 021/151] updated theme on docs --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index a7c230819..d3f40bee4 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -108,7 +108,7 @@ todo_include_todos = False # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'alabaster' +html_theme = 'default' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the From 8986b9d939c667974235fb9c79f9d10c65c35f50 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 25 Sep 2015 17:38:36 +0100 Subject: [PATCH 022/151] added get started --- docs/get_started.rst | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 docs/get_started.rst diff --git a/docs/get_started.rst b/docs/get_started.rst new file mode 100644 index 000000000..ce05adbb9 --- /dev/null +++ b/docs/get_started.rst @@ -0,0 +1,8 @@ +=========== +Get Started +=========== + +Overview +-------- + +todo \ No newline at end of file From 76772d987633c437e0a2a45af98f2dc780c16c10 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 25 Sep 2015 17:40:56 +0100 Subject: [PATCH 023/151] added get started to contents --- docs/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/index.rst b/docs/index.rst index 88345f66d..76666f375 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -10,6 +10,7 @@ Contents: .. toctree:: :maxdepth: 2 + get_started From 3ff02584222a5c368caed60d27ffae2950f93826 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 25 Sep 2015 17:43:23 +0100 Subject: [PATCH 024/151] fixed get started? --- docs/index.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index 76666f375..338583ef0 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -9,7 +9,6 @@ Welcome to discord.js's documentation! Contents: .. toctree:: - :maxdepth: 2 get_started From a74276ffdd4d1ec43c624cae0d2c1cbae512a3b8 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 25 Sep 2015 17:57:42 +0100 Subject: [PATCH 025/151] updated get started --- docs/get_started.rst | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/get_started.rst b/docs/get_started.rst index ce05adbb9..687d5fcbf 100644 --- a/docs/get_started.rst +++ b/docs/get_started.rst @@ -2,7 +2,17 @@ Get Started =========== -Overview --------- +Installation +------------ -todo \ No newline at end of file +Linux / OS X +~~~~~~~~~~~~ +Run ``npm install discord.js --save`` in your project's directory and you should be good to go! + +Windows +~~~~~~~~~~~~ +Unfortunately, the Windows installation process is a little more lengthy. You need to have `Visual Studio Express`_ (or any of the other distributions of it). This is necessary for build tools for the WebSocket dependency. + +After you have obtained these tools, you need to run ``npm install discord.js --save --msvs_version=2015`` in your working directory. Hopefully this should all go well! + +.. _`Visual Studio Express`: https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx \ No newline at end of file From f5fec11758ae6cfd54b254472b66aad58c76f65e Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 25 Sep 2015 18:05:04 +0100 Subject: [PATCH 026/151] added small note --- docs/get_started.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/get_started.rst b/docs/get_started.rst index 687d5fcbf..a6d88d366 100644 --- a/docs/get_started.rst +++ b/docs/get_started.rst @@ -15,4 +15,6 @@ Unfortunately, the Windows installation process is a little more lengthy. You ne After you have obtained these tools, you need to run ``npm install discord.js --save --msvs_version=2015`` in your working directory. Hopefully this should all go well! +.. note:: If you are using another version of Visual Studio, such as 2012, replace the flag with ``--msvs_version=2012`` + .. _`Visual Studio Express`: https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx \ No newline at end of file From 5948e49445e7f87c1f294242164bf98c00d4e05f Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 25 Sep 2015 19:37:37 +0100 Subject: [PATCH 027/151] updated docs --- docs/get_started.rst | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/get_started.rst b/docs/get_started.rst index a6d88d366..8933558d1 100644 --- a/docs/get_started.rst +++ b/docs/get_started.rst @@ -13,8 +13,25 @@ Windows ~~~~~~~~~~~~ Unfortunately, the Windows installation process is a little more lengthy. You need to have `Visual Studio Express`_ (or any of the other distributions of it). This is necessary for build tools for the WebSocket dependency. -After you have obtained these tools, you need to run ``npm install discord.js --save --msvs_version=2015`` in your working directory. Hopefully this should all go well! - .. note:: If you are using another version of Visual Studio, such as 2012, replace the flag with ``--msvs_version=2012`` -.. _`Visual Studio Express`: https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx \ No newline at end of file +After you have obtained these tools, you need to run ``npm install discord.js --save --msvs_version=2015`` in your working directory. Hopefully this should all go well! + +Cloning the Repo +---------------- +If you want to try some examples or make your own changes to discord.js, you can `clone the repo`_. + +Running Examples +~~~~~~~~~~~~~~~~ +If you've cloned the repo, you also have the option to run some examples. You can also do this by just copying the examples_ and then running them. I'd be more than happy to get some pull requests if you want to make any patches ;) + + +Before you run them though, you need to configure the ``examples/auth.json`` file. This should contain valid Discord credentials and passwords. + +After you've configured your credentials, just run ``node examples/pingpong.js`` to run the ping pong example. + + + +.. _Visual Studio Express: https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx +.. _clone the repo: https://github.com/hydrabolt/discord.js.git +.. _examples: https://github.com/hydrabolt/discord.js/tree/master/examples \ No newline at end of file From cbfb78cc51f4a81e43418500035d24d053ce9830 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 25 Sep 2015 19:43:42 +0100 Subject: [PATCH 028/151] Updated index.rst --- docs/index.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index 338583ef0..adb6ebfd9 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -6,6 +6,11 @@ Welcome to discord.js's documentation! ====================================== +discord.js is an easy-to-use and intuitive JavaScript API for Discord_. It should be able to +run in node.js / io.js and in the browser. + +.. note:: This documentation is still a work-in-progress, apologies if something isn't yet documented! + Contents: .. toctree:: @@ -17,6 +22,6 @@ Indices and tables ================== * :ref:`genindex` -* :ref:`modindex` * :ref:`search` +.. _Discord : https://discordapp.com/ From a8da6609db52c8a4cb09dae2c45ddd5f16ec9d03 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 25 Sep 2015 20:00:05 +0100 Subject: [PATCH 029/151] Added troubleshooting to docs --- .vscode/settings.json | 3 +-- docs/get_started.rst | 2 +- docs/troubleshooting.rst | 10 ++++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 docs/troubleshooting.rst diff --git a/.vscode/settings.json b/.vscode/settings.json index 20af2f68a..81c4b4351 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,2 @@ // Place your settings in this file to overwrite default and user settings. -{ -} \ No newline at end of file +{ "editor.wrappingColumn": 0 } \ No newline at end of file diff --git a/docs/get_started.rst b/docs/get_started.rst index 8933558d1..96c7b1af6 100644 --- a/docs/get_started.rst +++ b/docs/get_started.rst @@ -19,7 +19,7 @@ After you have obtained these tools, you need to run ``npm install discord.js -- Cloning the Repo ---------------- -If you want to try some examples or make your own changes to discord.js, you can `clone the repo`_. +If you want to try some examples or make your own changes to discord.js, you can `clone the repo`_. After that run ``npm install`` to install dependencies. Running Examples ~~~~~~~~~~~~~~~~ diff --git a/docs/troubleshooting.rst b/docs/troubleshooting.rst new file mode 100644 index 000000000..3f5fa02ad --- /dev/null +++ b/docs/troubleshooting.rst @@ -0,0 +1,10 @@ +Troubleshooting +=============== + +Occasionally, the API can stop working for whatever reason. If it was working previously and it stopped working on the same version, it means that there's been a change to the Discord API. In this case, please `make an issue`_ if one relating to a similar issue doesn't exist. Please post a stacktrace if there is one, and be as detailed as possible - *"the API isn't working"* doesn't help at all. + +If there is already an issue, feel free to comment that you're also experiencing the same thing. This helps to see how widespread the bug is. + +You can try reconnecting before submitting an issue, as sometimes some of the servers may be slightly different. + +.. _make an issue : https://github.com/hydrabolt/discord.js/issues \ No newline at end of file From d9528f19805022b76bb95bc0a9b581fb77b7c16f Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 25 Sep 2015 20:27:45 +0100 Subject: [PATCH 030/151] Added simple bot --- docs/create_simple_bot.rst | 132 +++++++++++++++++++++++++++++++++++++ docs/index.rst | 2 + 2 files changed, 134 insertions(+) create mode 100644 docs/create_simple_bot.rst diff --git a/docs/create_simple_bot.rst b/docs/create_simple_bot.rst new file mode 100644 index 000000000..f1115cd12 --- /dev/null +++ b/docs/create_simple_bot.rst @@ -0,0 +1,132 @@ +Creating a Simple Bot +===================== + +This page will walk you through writing a simple bot and will introduce you to some of the most important functions and objects you will encounter in the API. + +Setting up a Project +-------------------- + +Before you start creating your bot, you need to create a directory, for example *discordbot*. + +After you've done that, open up the directory and have a look at how to `install the module`_. After you've installed the module, you can progress to the next step + +Creating the Bot +---------------- + +Now we can begin writing the bot. This bot will just server the user their avatar but at a higher resolution - assuming they have one. + +Firstly, create a file named ``bot.js`` in the directory you made earlier. Open it up, and type the following lines of code: + +.. code-block:: js + + var Discord = require("discord.js"); + var bot = new Discord.Client(); + +This code firstly imports the discord.js module, which contains classes to help you create clients for Discord. The second line creates a new Discord Client, which we can manipulate later. Now, we want the client to be alerted when there is a new message and do something, so we can type this: + +.. code-block:: js + + bot.on("message", function(message){ + + } ) + +This will simply get our client to listen out for new messages, but not yet do anything. Let's have a look at this: + +.. code-block:: js + + bot.on("message", function(message){ + + if( message.content === "avatar me!" ){ + + } + + } ) + +This code will now get our client to execute anything inside the if statement as long as the message sent was "avatar me!" We can now get it to see if the user has an avatar: + +.. code-block:: js + + bot.on("message", function(message){ + + if( message.content === "avatar me!" ){ + + var usersAvatar = message.sender.avatarURL; + + if(usersAvatar){ + // user has an avatar + }else{ + // user doesn't have an avatar + } + + } + + } ) + +This code will now see if the user has an avatar and then do something based on that, let's finalise it: + +.. code-block:: js + + bot.on("message", function(message){ + + if( message.content === "avatar me!" ){ + + var usersAvatar = message.sender.avatarURL; + + if(usersAvatar){ + // user has an avatar + + bot.reply(message, "your avatar can be found at " + usersAvatar); + + }else{ + // user doesn't have an avatar + + bot.reply(message, "you don't have an avatar!"); + } + + } + + } ) + +Let's have a look at the function we used here; *bot.reply*. This function takes 2 necessary parameters, a message object to reply to and a message to send. The first parameter we already have, and it is the message we have received. The second parameter is what we want to send. + +Now that we've finished the listener event, we need to log the client in: + +.. code-block:: js + + bot.login("your discord email", "your discord password"); + +And that's it! Run the code with ``node bot.js`` and wait a few seconds, and then try sending *avatar me!* to any of the channels that the user you provided has details to. + +Final Product +------------- +.. code-block:: js + + var Discord = require("discord.js"); + var bot = new Discord.Client(); + + bot.on("message", function(message){ + + if( message.content === "avatar me!" ){ + + var usersAvatar = message.sender.avatarURL; + + if(usersAvatar){ + // user has an avatar + + bot.reply(message, "your avatar can be found at " + usersAvatar); + + }else{ + // user doesn't have an avatar + + bot.reply(message, "you don't have an avatar!"); + } + + } + + } ); + + bot.login("your discord email", "your discord password"); + +.. note:: This page is still a WIP, check back later for more documentation on it. + +.. _install the module : http://discordjs.readthedocs.org/en/latest/get_started.html#installation \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst index adb6ebfd9..af0d5dcf0 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -15,6 +15,8 @@ Contents: .. toctree:: get_started + troubleshooting + create_simple_bot From fc9c46d1a201016baf95f7587843299d07222441 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 26 Sep 2015 13:45:22 +0100 Subject: [PATCH 031/151] updated docs --- docs/docs_client.rst | 33 +++++++++++++++++++++++++++++++++ docs/index.rst | 1 + 2 files changed, 34 insertions(+) create mode 100644 docs/docs_client.rst diff --git a/docs/docs_client.rst b/docs/docs_client.rst new file mode 100644 index 000000000..69d9bcda2 --- /dev/null +++ b/docs/docs_client.rst @@ -0,0 +1,33 @@ +Client Documentation +==================== + +Attributes +---------- + +``options`` +~~~~~~~~~~~ +An `Object` containing a configuration for the Client. Currently can only be configured like so: + +.. code-block:: js + + { + queue : false // whether messages should be sent one after the other or + // just send straight away. + } + +``token`` +~~~~~~~~~ +A `String` that is the token received after logging in. It is used to authorise the Client when joining WebSockets or making HTTP requests. + +``state`` +~~~~~~~~~ +An `Integer` representing what state of connection the Client is in. + +- **0** is idle, meaning the Client has been created but no login attempts have been made. +- **1** is logging in, meaning the Client is in the process of logging in. +- **2** is logged in, meaning the Client is logged in but not necessarily ready. +- **3** is ready, meaning the Client is ready to begin listening. +- **4** is disconnected, meaning the Client was disconnected due to any reason. + +Functions +--------- \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst index af0d5dcf0..70b5f1698 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -17,6 +17,7 @@ Contents: get_started troubleshooting create_simple_bot + docs_client From 3e9af4454d6271dce77afc350af999487b4da25e Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 26 Sep 2015 13:47:42 +0100 Subject: [PATCH 032/151] Update to docs --- docs/docs_client.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 69d9bcda2..382528cf9 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -4,8 +4,8 @@ Client Documentation Attributes ---------- -``options`` -~~~~~~~~~~~ +options +~~~~~~~ An `Object` containing a configuration for the Client. Currently can only be configured like so: .. code-block:: js @@ -15,12 +15,12 @@ An `Object` containing a configuration for the Client. Currently can only be con // just send straight away. } -``token`` -~~~~~~~~~ +token +~~~~~ A `String` that is the token received after logging in. It is used to authorise the Client when joining WebSockets or making HTTP requests. -``state`` -~~~~~~~~~ +state +~~~~~ An `Integer` representing what state of connection the Client is in. - **0** is idle, meaning the Client has been created but no login attempts have been made. From 1ef4fa41a77f33af882baa140b2e6084d2f4a233 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 26 Sep 2015 21:28:09 +0100 Subject: [PATCH 033/151] Channels now store 1000 messages maximum Will drastically improve the longevity of the process and reduce memory required --- src/channel.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/channel.js b/src/channel.js index d813e9b74..91e961547 100644 --- a/src/channel.js +++ b/src/channel.js @@ -18,9 +18,15 @@ class Channel { } addMessage(data){ + + if(this.messages.length > 1000){ + this.messages.splice(0,1); + } + if(!this.getMessage("id", data.id)){ this.messages.push(data); } + return this.getMessage("id", data.id); } From 2f9585a6b9ccd30e7bfe19b009b9a2e95d56a4c2 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 26 Sep 2015 21:41:23 +0100 Subject: [PATCH 034/151] Added semi-functional statuses --- lib/Client.js | 158 ++++++++++++++++++++++++++++--------------------- lib/channel.js | 6 ++ lib/user.js | 1 + src/Client.js | 5 ++ src/user.js | 1 + 5 files changed, 105 insertions(+), 66 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index eff03e5aa..b80665556 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1144,6 +1144,7 @@ var Client = (function () { key: "addServer", value: function addServer(data) { + var self = this; var server = this.getServer("id", data.id); if (!server) { @@ -1177,24 +1178,15 @@ var Client = (function () { } } - return server; - } - - //def getUser - }, { - key: "getUser", - value: function getUser(key, value) { var _iteratorNormalCompletion9 = true; var _didIteratorError9 = false; var _iteratorError9 = undefined; try { - for (var _iterator9 = this.userCache[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) { - var user = _step9.value; + for (var _iterator9 = data.presences[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) { + var presence = _step9.value; - if (user[key] === value) { - return user; - } + self.getUser("id", presence.user.id).status = presence.status; } } catch (err) { _didIteratorError9 = true; @@ -1211,23 +1203,23 @@ var Client = (function () { } } - return null; + return server; } - //def getChannel + //def getUser }, { - key: "getChannel", - value: function getChannel(key, value) { + key: "getUser", + value: function getUser(key, value) { var _iteratorNormalCompletion10 = true; var _didIteratorError10 = false; var _iteratorError10 = undefined; try { - for (var _iterator10 = this.channelCache[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) { - var channel = _step10.value; + for (var _iterator10 = this.userCache[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) { + var user = _step10.value; - if (channel[key] === value) { - return channel; + if (user[key] === value) { + return user; } } } catch (err) { @@ -1245,17 +1237,19 @@ var Client = (function () { } } - return this.getPMChannel(key, value); //might be a PM + return null; } + + //def getChannel }, { - key: "getPMChannel", - value: function getPMChannel(key, value) { + key: "getChannel", + value: function getChannel(key, value) { var _iteratorNormalCompletion11 = true; var _didIteratorError11 = false; var _iteratorError11 = undefined; try { - for (var _iterator11 = this.pmChannelCache[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) { + for (var _iterator11 = this.channelCache[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) { var channel = _step11.value; if (channel[key] === value) { @@ -1277,23 +1271,21 @@ var Client = (function () { } } - return null; + return this.getPMChannel(key, value); //might be a PM } - - //def getServer }, { - key: "getServer", - value: function getServer(key, value) { + key: "getPMChannel", + value: function getPMChannel(key, value) { var _iteratorNormalCompletion12 = true; var _didIteratorError12 = false; var _iteratorError12 = undefined; try { - for (var _iterator12 = this.serverCache[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) { - var server = _step12.value; + for (var _iterator12 = this.pmChannelCache[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) { + var channel = _step12.value; - if (server[key] === value) { - return server; + if (channel[key] === value) { + return channel; } } } catch (err) { @@ -1314,6 +1306,40 @@ var Client = (function () { return null; } + //def getServer + }, { + key: "getServer", + value: function getServer(key, value) { + var _iteratorNormalCompletion13 = true; + var _didIteratorError13 = false; + var _iteratorError13 = undefined; + + try { + for (var _iterator13 = this.serverCache[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) { + var server = _step13.value; + + if (server[key] === value) { + return server; + } + } + } catch (err) { + _didIteratorError13 = true; + _iteratorError13 = err; + } finally { + try { + if (!_iteratorNormalCompletion13 && _iterator13["return"]) { + _iterator13["return"](); + } + } finally { + if (_didIteratorError13) { + throw _iteratorError13; + } + } + } + + return null; + } + //def trySendConnData }, { key: "trySendConnData", @@ -1366,13 +1392,13 @@ var Client = (function () { } else if (destination instanceof User) { //check if we have a PM - var _iteratorNormalCompletion13 = true; - var _didIteratorError13 = false; - var _iteratorError13 = undefined; + var _iteratorNormalCompletion14 = true; + var _didIteratorError14 = false; + var _iteratorError14 = undefined; try { - for (var _iterator13 = self.pmChannelCache[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) { - var pmc = _step13.value; + for (var _iterator14 = self.pmChannelCache[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) { + var pmc = _step14.value; if (pmc.user.equals(destination)) { resolve(pmc.id); @@ -1382,16 +1408,16 @@ var Client = (function () { //we don't, at this point we're late } catch (err) { - _didIteratorError13 = true; - _iteratorError13 = err; + _didIteratorError14 = true; + _iteratorError14 = err; } finally { try { - if (!_iteratorNormalCompletion13 && _iterator13["return"]) { - _iterator13["return"](); + if (!_iteratorNormalCompletion14 && _iterator14["return"]) { + _iterator14["return"](); } } finally { - if (_didIteratorError13) { - throw _iteratorError13; + if (_didIteratorError14) { + throw _iteratorError14; } } } @@ -1428,27 +1454,27 @@ var Client = (function () { data.mentions = data.mentions || []; //for some reason this was not defined at some point? - var _iteratorNormalCompletion14 = true; - var _didIteratorError14 = false; - var _iteratorError14 = undefined; + var _iteratorNormalCompletion15 = true; + var _didIteratorError15 = false; + var _iteratorError15 = undefined; try { - for (var _iterator14 = data.mentions[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) { - var mention = _step14.value; + for (var _iterator15 = data.mentions[Symbol.iterator](), _step15; !(_iteratorNormalCompletion15 = (_step15 = _iterator15.next()).done); _iteratorNormalCompletion15 = true) { + var mention = _step15.value; mentions.push(self.addUser(mention)); } } catch (err) { - _didIteratorError14 = true; - _iteratorError14 = err; + _didIteratorError15 = true; + _iteratorError15 = err; } finally { try { - if (!_iteratorNormalCompletion14 && _iterator14["return"]) { - _iterator14["return"](); + if (!_iteratorNormalCompletion15 && _iterator15["return"]) { + _iterator15["return"](); } } finally { - if (_didIteratorError14) { - throw _iteratorError14; + if (_didIteratorError15) { + throw _iteratorError15; } } } @@ -1650,27 +1676,27 @@ var Client = (function () { get: function get() { var msgs = []; - var _iteratorNormalCompletion15 = true; - var _didIteratorError15 = false; - var _iteratorError15 = undefined; + var _iteratorNormalCompletion16 = true; + var _didIteratorError16 = false; + var _iteratorError16 = undefined; try { - for (var _iterator15 = this.channelCache[Symbol.iterator](), _step15; !(_iteratorNormalCompletion15 = (_step15 = _iterator15.next()).done); _iteratorNormalCompletion15 = true) { - var channel = _step15.value; + for (var _iterator16 = this.channelCache[Symbol.iterator](), _step16; !(_iteratorNormalCompletion16 = (_step16 = _iterator16.next()).done); _iteratorNormalCompletion16 = true) { + var channel = _step16.value; msgs = msgs.concat(channel.messages); } } catch (err) { - _didIteratorError15 = true; - _iteratorError15 = err; + _didIteratorError16 = true; + _iteratorError16 = err; } finally { try { - if (!_iteratorNormalCompletion15 && _iterator15["return"]) { - _iterator15["return"](); + if (!_iteratorNormalCompletion16 && _iterator16["return"]) { + _iterator16["return"](); } } finally { - if (_didIteratorError15) { - throw _iteratorError15; + if (_didIteratorError16) { + throw _iteratorError16; } } } diff --git a/lib/channel.js b/lib/channel.js index 79bc71b55..8e9ca5703 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -24,9 +24,15 @@ var Channel = (function () { }, { key: "addMessage", value: function addMessage(data) { + + if (this.messages.length > 1000) { + this.messages.splice(0, 1); + } + if (!this.getMessage("id", data.id)) { this.messages.push(data); } + return this.getMessage("id", data.id); } }, { diff --git a/lib/user.js b/lib/user.js index 2f363dd1e..5e38e132e 100644 --- a/lib/user.js +++ b/lib/user.js @@ -12,6 +12,7 @@ var User = (function () { this.discriminator = data.discriminator; this.id = data.id; this.avatar = data.avatar; + this.status = "offline"; } // access using user.avatarURL; diff --git a/src/Client.js b/src/Client.js index f7919a653..09a3f004c 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1044,6 +1044,7 @@ class Client { //def addServer addServer(data) { + var self = this; var server = this.getServer("id", data.id); if (!server) { @@ -1055,6 +1056,10 @@ class Client { } } } + + for(var presence of data.presences){ + self.getUser("id", presence.user.id).status = presence.status; + } return server; } diff --git a/src/user.js b/src/user.js index 375ec7c60..73eef604f 100644 --- a/src/user.js +++ b/src/user.js @@ -4,6 +4,7 @@ class User{ this.discriminator = data.discriminator; this.id = data.id; this.avatar = data.avatar; + this.status = "offline"; } // access using user.avatarURL; From ca1b4bdf0eb6705a620da2e01d47cfd2c6715718 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 26 Sep 2015 21:43:49 +0100 Subject: [PATCH 035/151] Added shortcut to users from channel class --- lib/channel.js | 10 ++++++++++ src/channel.js | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/channel.js b/lib/channel.js index 8e9ca5703..17390e9e6 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -82,6 +82,16 @@ var Channel = (function () { get: function get() { return false; } + }, { + key: "users", + get: function get() { + return this.server.members; + } + }, { + key: "members", + get: function get() { + return this.server.members; + } }]); return Channel; diff --git a/src/channel.js b/src/channel.js index 91e961547..df266ba1c 100644 --- a/src/channel.js +++ b/src/channel.js @@ -46,6 +46,14 @@ class Channel { get isPrivate(){ return false; } + + get users(){ + return this.server.members; + } + + get members(){ + return this.server.members; + } } module.exports = Channel; \ No newline at end of file From 76e9cef7e1c213d83928e72dc9a1a010094ea9dd Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 26 Sep 2015 21:45:13 +0100 Subject: [PATCH 036/151] Added user presence tracking changes User status in cache is now updated as well as firing the event --- lib/Client.js | 1 + src/Client.js | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/Client.js b/lib/Client.js index b80665556..7d7bba771 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1087,6 +1087,7 @@ var Client = (function () { var presenceUser = new User(data.user); if (presenceUser.equalsStrict(userInCache)) { //they're exactly the same, an actual presence update + userInCache.status = data.status; self.trigger("presence", { user: userInCache, status: data.status, diff --git a/src/Client.js b/src/Client.js index 09a3f004c..5b5bc872f 100644 --- a/src/Client.js +++ b/src/Client.js @@ -992,6 +992,7 @@ class Client { var presenceUser = new User(data.user); if (presenceUser.equalsStrict(userInCache)) { //they're exactly the same, an actual presence update + userInCache.status = data.status; self.trigger("presence", { user: userInCache, status: data.status, From 4f928301ba164737c2537fa68e55bc17b63b393d Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 26 Sep 2015 21:45:51 +0100 Subject: [PATCH 037/151] Updated bot --- test/bot.1.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test/bot.1.js b/test/bot.1.js index 38f25d390..ed608f092 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -1,13 +1,12 @@ var Discord = require("../"); -var mybot = new Discord.Client({ - queue: true -}); +var mybot = new Discord.Client(); var fs = require("fs"); var server, channel, message, sentMessage = false; mybot.on("message", function (message) { - + + console.log("Everyone mentioned? " + message.everyoneMentioned); if (mybot.user.equals(message.sender)) { return; } @@ -17,7 +16,14 @@ mybot.on("message", function (message) { } // we can go ahead :) - mybot.reply(message, message.channel); + + var onlineUsers = 0; + for(user of message.channel.users){ + if(user.status === "online" || user.status === "idle") + onlineUsers++; + } + + mybot.reply(message, onlineUsers); }); mybot.on("ready", function () { From ad60af6185bacf03cb80c5f248e45fe14bc359c8 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 26 Sep 2015 21:45:56 +0100 Subject: [PATCH 038/151] 3.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 89ca0fba0..b9a82de25 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.3.4", + "version": "3.4.0", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From 8943a2fffcb4739fc8cc24ddba7b7d476c7a365f Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 26 Sep 2015 21:47:02 +0100 Subject: [PATCH 039/151] Added 3.4.0 web dist --- web-dist/discord.3.4.0.js | 3641 +++++++++++++++++++++++++++++++++ web-dist/discord.min.3.4.0.js | 2 + 2 files changed, 3643 insertions(+) create mode 100644 web-dist/discord.3.4.0.js create mode 100644 web-dist/discord.min.3.4.0.js diff --git a/web-dist/discord.3.4.0.js b/web-dist/discord.3.4.0.js new file mode 100644 index 000000000..1cbe30419 --- /dev/null +++ b/web-dist/discord.3.4.0.js @@ -0,0 +1,3641 @@ +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Discord = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o]*>/g) || [])[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var mention = _step3.value; + + _mentions.push(mention.substring(2, mention.length - 1)); + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3["return"]) { + _iterator3["return"](); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + + return _mentions; + } + }); + + return prom; + } + + //def createws + }, { + key: "createws", + value: function createws(url) { + if (this.websocket) return false; + + var self = this; + + //good to go + this.websocket = new WebSocket(url); + + //open + this.websocket.onopen = function () { + self.trySendConnData(); //try connecting + }; + + //close + this.websocket.onclose = function () { + self.trigger("disconnected"); + }; + + //message + this.websocket.onmessage = function (e) { + + var dat = false, + data = {}; + + try { + dat = JSON.parse(e.data); + data = dat.d; + } catch (err) { + self.trigger("error", err, e); + return; + } + + //valid message + switch (dat.t) { + + case "READY": + self.debug("received ready packet"); + + self.user = self.addUser(data.user); + + var _iteratorNormalCompletion4 = true; + var _didIteratorError4 = false; + var _iteratorError4 = undefined; + + try { + for (var _iterator4 = data.guilds[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var _server = _step4.value; + + var server = self.addServer(_server); + } + } catch (err) { + _didIteratorError4 = true; + _iteratorError4 = err; + } finally { + try { + if (!_iteratorNormalCompletion4 && _iterator4["return"]) { + _iterator4["return"](); + } + } finally { + if (_didIteratorError4) { + throw _iteratorError4; + } + } + } + + var _iteratorNormalCompletion5 = true; + var _didIteratorError5 = false; + var _iteratorError5 = undefined; + + try { + for (var _iterator5 = data.private_channels[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { + var _pmc = _step5.value; + + var pmc = self.addPMChannel(_pmc); + } + } catch (err) { + _didIteratorError5 = true; + _iteratorError5 = err; + } finally { + try { + if (!_iteratorNormalCompletion5 && _iterator5["return"]) { + _iterator5["return"](); + } + } finally { + if (_didIteratorError5) { + throw _iteratorError5; + } + } + } + + self.trigger("ready"); + self.readyTime = Date.now(); + self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users."); + self.state = 3; + setInterval(function () { + self.keepAlive.apply(self); + }, data.heartbeat_interval); + + break; + case "MESSAGE_CREATE": + self.debug("received message"); + + var mentions = []; + data.mentions = data.mentions || []; //for some reason this was not defined at some point? + var _iteratorNormalCompletion6 = true; + var _didIteratorError6 = false; + var _iteratorError6 = undefined; + + try { + for (var _iterator6 = data.mentions[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { + var mention = _step6.value; + + mentions.push(self.addUser(mention)); + } + } catch (err) { + _didIteratorError6 = true; + _iteratorError6 = err; + } finally { + try { + if (!_iteratorNormalCompletion6 && _iterator6["return"]) { + _iterator6["return"](); + } + } finally { + if (_didIteratorError6) { + throw _iteratorError6; + } + } + } + + var channel = self.getChannel("id", data.channel_id); + if (channel) { + var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); + self.trigger("message", msg); + } + + break; + case "MESSAGE_DELETE": + self.debug("message deleted"); + + var channel = self.getChannel("id", data.channel_id); + var message = channel.getMessage("id", data.id); + if (message) { + self.trigger("messageDelete", channel, message); + channel.messages.splice(channel.messages.indexOf(message), 1); + } else { + //don't have the cache of that message ;( + self.trigger("messageDelete", channel); + } + break; + case "MESSAGE_UPDATE": + self.debug("message updated"); + + var channel = self.getChannel("id", data.channel_id); + var formerMessage = channel.getMessage("id", data.id); + + if (formerMessage) { + + //new message might be partial, so we need to fill it with whatever the old message was. + var info = {}; + + for (var key in formerMessage) { + info[key] = formerMessage[key]; + } + + for (var key in data) { + info[key] = data[key]; + } + + var mentions = []; + var _iteratorNormalCompletion7 = true; + var _didIteratorError7 = false; + var _iteratorError7 = undefined; + + try { + for (var _iterator7 = info.mentions[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { + var mention = _step7.value; + + mentions.push(self.addUser(mention)); + } + } catch (err) { + _didIteratorError7 = true; + _iteratorError7 = err; + } finally { + try { + if (!_iteratorNormalCompletion7 && _iterator7["return"]) { + _iterator7["return"](); + } + } finally { + if (_didIteratorError7) { + throw _iteratorError7; + } + } + } + + var newMessage = new Message(info, channel, mentions, formerMessage.author); + + self.trigger("messageUpdate", newMessage, formerMessage); + + channel.messages[channel.messages.indexOf(formerMessage)] = newMessage; + } + + // message isn't in cache, and if it's a partial it could cause + // all hell to break loose... best to just act as if nothing happened + + break; + + case "GUILD_DELETE": + + var server = self.getServer("id", data.id); + + if (server) { + self.serverCache.splice(self.serverCache.indexOf(server), 1); + self.trigger("serverDelete", server); + } + + break; + + case "CHANNEL_DELETE": + + var channel = self.getChannel("id", data.id); + + if (channel) { + + var server = channel.server; + + if (server) { + + server.channels.splice(server.channels.indexOf(channel), 1); + } + + self.trigger("channelDelete", channel); + + self.serverCache.splice(self.serverCache.indexOf(channel), 1); + } + + break; + + case "GUILD_CREATE": + + var server = self.getServer("id", data.id); + + if (!server) { + //if server doesn't already exist because duh + server = self.addServer(data); + } /*else if(server.channels.length === 0){ + + var srv = new Server(data, self); + for(channel of data.channels){ + srv.channels.push(new Channel(channel, data.id)); + } + self.serverCache[self.serverCache.indexOf(server)] = srv; + + }*/ + + if (self.serverCreateListener[data.id]) { + var cbs = self.serverCreateListener[data.id]; + cbs[0](server); //promise then callback + cbs[1](null, server); //legacy callback + self.serverCreateListener[data.id] = null; + } + + self.trigger("serverCreate", server); + + break; + + case "CHANNEL_CREATE": + + var channel = self.getChannel("id", data.id); + + if (!channel) { + + var chann = self.addChannel(data, data.guild_id); + var srv = self.getServer("id", data.guild_id); + if (srv) { + srv.addChannel(chann); + } + self.trigger("channelCreate", chann); + } + + break; + + case "GUILD_MEMBER_ADD": + + var server = self.getServer("id", data.guild_id); + + if (server) { + + var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. + + if (! ~server.members.indexOf(user)) { + server.members.push(user); + } + + self.trigger("serverNewMember", user, server); + } + + break; + + case "GUILD_MEMBER_REMOVE": + + var server = self.getServer("id", data.guild_id); + + if (server) { + + var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. + + if (~server.members.indexOf(user)) { + server.members.splice(server.members.indexOf(user), 1); + } + + self.trigger("serverRemoveMember", user, server); + } + + break; + + case "USER_UPDATE": + + if (self.user && data.id === self.user.id) { + + var newUser = new User(data); //not actually adding to the cache + + self.trigger("userUpdate", newUser, self.user); + + if (~self.userCache.indexOf(self.user)) { + self.userCache[self.userCache.indexOf(self.user)] = newUser; + } + + self.user = newUser; + } + + break; + + case "PRESENCE_UPDATE": + + var userInCache = self.getUser("id", data.user.id); + + if (userInCache) { + //user exists + var presenceUser = new User(data.user); + if (presenceUser.equalsStrict(userInCache)) { + //they're exactly the same, an actual presence update + userInCache.status = data.status; + self.trigger("presence", { + user: userInCache, + status: data.status, + server: self.getServer("id", data.guild_id), + gameId: data.game_id + }); + } else { + //one of their details changed. + self.trigger("userUpdate", userInCache, presenceUser); + self.userCache[self.userCache.indexOf(userInCache)] = presenceUser; + } + } + + break; + + default: + self.debug("received unknown packet"); + self.trigger("unknown", dat); + break; + + } + }; + } + + //def addUser + }, { + key: "addUser", + value: function addUser(data) { + if (!this.getUser("id", data.id)) { + this.userCache.push(new User(data)); + } + return this.getUser("id", data.id); + } + + //def addChannel + }, { + key: "addChannel", + value: function addChannel(data, serverId) { + if (!this.getChannel("id", data.id)) { + this.channelCache.push(new Channel(data, this.getServer("id", serverId))); + } + return this.getChannel("id", data.id); + } + }, { + key: "addPMChannel", + value: function addPMChannel(data) { + if (!this.getPMChannel("id", data.id)) { + this.pmChannelCache.push(new PMChannel(data, this)); + } + return this.getPMChannel("id", data.id); + } + + //def addServer + }, { + key: "addServer", + value: function addServer(data) { + + var self = this; + var server = this.getServer("id", data.id); + + if (!server) { + server = new Server(data, this); + this.serverCache.push(server); + if (data.channels) { + var _iteratorNormalCompletion8 = true; + var _didIteratorError8 = false; + var _iteratorError8 = undefined; + + try { + for (var _iterator8 = data.channels[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) { + var channel = _step8.value; + + server.channels.push(this.addChannel(channel, server.id)); + } + } catch (err) { + _didIteratorError8 = true; + _iteratorError8 = err; + } finally { + try { + if (!_iteratorNormalCompletion8 && _iterator8["return"]) { + _iterator8["return"](); + } + } finally { + if (_didIteratorError8) { + throw _iteratorError8; + } + } + } + } + } + + var _iteratorNormalCompletion9 = true; + var _didIteratorError9 = false; + var _iteratorError9 = undefined; + + try { + for (var _iterator9 = data.presences[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) { + var presence = _step9.value; + + self.getUser("id", presence.user.id).status = presence.status; + } + } catch (err) { + _didIteratorError9 = true; + _iteratorError9 = err; + } finally { + try { + if (!_iteratorNormalCompletion9 && _iterator9["return"]) { + _iterator9["return"](); + } + } finally { + if (_didIteratorError9) { + throw _iteratorError9; + } + } + } + + return server; + } + + //def getUser + }, { + key: "getUser", + value: function getUser(key, value) { + var _iteratorNormalCompletion10 = true; + var _didIteratorError10 = false; + var _iteratorError10 = undefined; + + try { + for (var _iterator10 = this.userCache[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) { + var user = _step10.value; + + if (user[key] === value) { + return user; + } + } + } catch (err) { + _didIteratorError10 = true; + _iteratorError10 = err; + } finally { + try { + if (!_iteratorNormalCompletion10 && _iterator10["return"]) { + _iterator10["return"](); + } + } finally { + if (_didIteratorError10) { + throw _iteratorError10; + } + } + } + + return null; + } + + //def getChannel + }, { + key: "getChannel", + value: function getChannel(key, value) { + var _iteratorNormalCompletion11 = true; + var _didIteratorError11 = false; + var _iteratorError11 = undefined; + + try { + for (var _iterator11 = this.channelCache[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) { + var channel = _step11.value; + + if (channel[key] === value) { + return channel; + } + } + } catch (err) { + _didIteratorError11 = true; + _iteratorError11 = err; + } finally { + try { + if (!_iteratorNormalCompletion11 && _iterator11["return"]) { + _iterator11["return"](); + } + } finally { + if (_didIteratorError11) { + throw _iteratorError11; + } + } + } + + return this.getPMChannel(key, value); //might be a PM + } + }, { + key: "getPMChannel", + value: function getPMChannel(key, value) { + var _iteratorNormalCompletion12 = true; + var _didIteratorError12 = false; + var _iteratorError12 = undefined; + + try { + for (var _iterator12 = this.pmChannelCache[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) { + var channel = _step12.value; + + if (channel[key] === value) { + return channel; + } + } + } catch (err) { + _didIteratorError12 = true; + _iteratorError12 = err; + } finally { + try { + if (!_iteratorNormalCompletion12 && _iterator12["return"]) { + _iterator12["return"](); + } + } finally { + if (_didIteratorError12) { + throw _iteratorError12; + } + } + } + + return null; + } + + //def getServer + }, { + key: "getServer", + value: function getServer(key, value) { + var _iteratorNormalCompletion13 = true; + var _didIteratorError13 = false; + var _iteratorError13 = undefined; + + try { + for (var _iterator13 = this.serverCache[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) { + var server = _step13.value; + + if (server[key] === value) { + return server; + } + } + } catch (err) { + _didIteratorError13 = true; + _iteratorError13 = err; + } finally { + try { + if (!_iteratorNormalCompletion13 && _iterator13["return"]) { + _iterator13["return"](); + } + } finally { + if (_didIteratorError13) { + throw _iteratorError13; + } + } + } + + return null; + } + + //def trySendConnData + }, { + key: "trySendConnData", + value: function trySendConnData() { + + if (this.token && !this.alreadySentData) { + + this.alreadySentData = true; + + var data = { + op: 2, + d: { + token: this.token, + v: 2, + properties: { + "$os": "discord.js", + "$browser": "discord.js", + "$device": "discord.js", + "$referrer": "", + "$referring_domain": "" + } + } + }; + this.websocket.send(JSON.stringify(data)); + } + } + }, { + key: "resolveServerID", + value: function resolveServerID(resource) { + + if (resource instanceof Server) { + return resource.id; + } else if (!isNaN(resource) && resource.length && resource.length === 17) { + return resource; + } + } + }, { + key: "resolveDestination", + value: function resolveDestination(destination) { + var channId = false; + var self = this; + + return new Promise(function (resolve, reject) { + if (destination instanceof Server) { + channId = destination.id; //general is the same as server id + } else if (destination instanceof Channel) { + channId = destination.id; + } else if (destination instanceof Message) { + channId = destination.channel.id; + } else if (destination instanceof User) { + + //check if we have a PM + var _iteratorNormalCompletion14 = true; + var _didIteratorError14 = false; + var _iteratorError14 = undefined; + + try { + for (var _iterator14 = self.pmChannelCache[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) { + var pmc = _step14.value; + + if (pmc.user.equals(destination)) { + resolve(pmc.id); + return; + } + } + + //we don't, at this point we're late + } catch (err) { + _didIteratorError14 = true; + _iteratorError14 = err; + } finally { + try { + if (!_iteratorNormalCompletion14 && _iterator14["return"]) { + _iterator14["return"](); + } + } finally { + if (_didIteratorError14) { + throw _iteratorError14; + } + } + } + + self.startPM(destination).then(function (pmc) { + console.log(pmc); + resolve(pmc.id); + })["catch"](reject); + } else { + channId = destination; + } + if (channId) resolve(channId); + }); + } + }, { + key: "_sendMessage", + value: function _sendMessage(destination, content, tts, mentions) { + + var self = this; + + return new Promise(function (resolve, reject) { + request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).send({ + content: content, + mentions: mentions, + tts: tts + }).end(function (err, res) { + + if (err) { + reject(err); + } else { + var data = res.body; + + var mentions = []; + + data.mentions = data.mentions || []; //for some reason this was not defined at some point? + + var _iteratorNormalCompletion15 = true; + var _didIteratorError15 = false; + var _iteratorError15 = undefined; + + try { + for (var _iterator15 = data.mentions[Symbol.iterator](), _step15; !(_iteratorNormalCompletion15 = (_step15 = _iterator15.next()).done); _iteratorNormalCompletion15 = true) { + var mention = _step15.value; + + mentions.push(self.addUser(mention)); + } + } catch (err) { + _didIteratorError15 = true; + _iteratorError15 = err; + } finally { + try { + if (!_iteratorNormalCompletion15 && _iterator15["return"]) { + _iterator15["return"](); + } + } finally { + if (_didIteratorError15) { + throw _iteratorError15; + } + } + } + + var channel = self.getChannel("id", data.channel_id); + if (channel) { + var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); + resolve(msg); + } + } + }); + }); + } + }, { + key: "_sendFile", + value: function _sendFile(destination, attachment) { + var attachmentName = arguments.length <= 2 || arguments[2] === undefined ? "DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png" : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).attach("file", attachment, attachmentName).end(function (err, res) { + + if (err) { + reject(err); + } else { + + var chann = self.getChannel("id", destination); + if (chann) { + var msg = chann.addMessage(new Message(res.body, chann, [], self.user)); + resolve(msg); + } + } + }); + }); + } + }, { + key: "_updateMessage", + value: function _updateMessage(message, content) { + var self = this; + return new Promise(function (resolve, reject) { + request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).send({ + content: content, + mentions: [] + }).end(function (err, res) { + if (err) { + reject(err); + } else { + var msg = new Message(res.body, message.channel, message.mentions, message.sender); + resolve(msg); + message.channel.messages[message.channel.messages.indexOf(message)] = msg; + } + }); + }); + } + }, { + key: "_deleteMessage", + value: function _deleteMessage(message) { + var self = this; + return new Promise(function (resolve, reject) { + + request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + }); + } + }, { + key: "checkQueue", + value: function checkQueue(channelID) { + var _this = this; + + var self = this; + + if (!this.checkingQueue[channelID]) { + (function () { + var doNext = function doNext() { + if (self.queue[channelID].length === 0) { + done(); + return; + } + var queuedEvent = self.queue[channelID][0]; + switch (queuedEvent.action) { + case "sendMessage": + var msgToSend = queuedEvent; + self._sendMessage(channelID, msgToSend.content, msgToSend.tts, msgToSend.mentions).then(function (msg) { + msgToSend.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + msgToSend.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + case "sendFile": + var fileToSend = queuedEvent; + self._sendFile(channelID, fileToSend.attachment, fileToSend.attachmentName).then(function (msg) { + fileToSend.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + fileToSend.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + case "updateMessage": + var msgToUpd = queuedEvent; + self._updateMessage(msgToUpd.message, msgToUpd.content).then(function (msg) { + msgToUpd.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + msgToUpd.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + case "deleteMessage": + var msgToDel = queuedEvent; + self._deleteMessage(msgToDel.message).then(function (msg) { + msgToDel.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + msgToDel.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + default: + done(); + break; + } + }; + + var done = function done() { + self.checkingQueue[channelID] = false; + return; + }; + + //if we aren't already checking this queue. + _this.checkingQueue[channelID] = true; + doNext(); + })(); + } + } + }, { + key: "getGateway", + value: function getGateway() { + var self = this; + return new Promise(function (resolve, reject) { + request.get(Endpoints.API + "/gateway").set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(res.body.url); + } + }); + }); + } + }, { + key: "uptime", + get: function get() { + + return this.readyTime ? Date.now() - this.readyTime : null; + } + }, { + key: "ready", + get: function get() { + return this.state === 3; + } + }, { + key: "servers", + get: function get() { + return this.serverCache; + } + }, { + key: "channels", + get: function get() { + return this.channelCache; + } + }, { + key: "users", + get: function get() { + return this.userCache; + } + }, { + key: "PMChannels", + get: function get() { + return this.pmChannelCache; + } + }, { + key: "messages", + get: function get() { + + var msgs = []; + var _iteratorNormalCompletion16 = true; + var _didIteratorError16 = false; + var _iteratorError16 = undefined; + + try { + for (var _iterator16 = this.channelCache[Symbol.iterator](), _step16; !(_iteratorNormalCompletion16 = (_step16 = _iterator16.next()).done); _iteratorNormalCompletion16 = true) { + var channel = _step16.value; + + msgs = msgs.concat(channel.messages); + } + } catch (err) { + _didIteratorError16 = true; + _iteratorError16 = err; + } finally { + try { + if (!_iteratorNormalCompletion16 && _iterator16["return"]) { + _iterator16["return"](); + } + } finally { + if (_didIteratorError16) { + throw _iteratorError16; + } + } + } + + return msgs; + } + }]); + + return Client; +})(); + +module.exports = Client; +},{"./Endpoints.js":2,"./PMChannel.js":3,"./channel.js":4,"./invite.js":6,"./message.js":7,"./server.js":8,"./user.js":9,"fs":10,"superagent":11,"ws":14}],2:[function(require,module,exports){ +"use strict"; + +exports.BASE_DOMAIN = "discordapp.com"; +exports.BASE = "https://" + exports.BASE_DOMAIN; +exports.WEBSOCKET_HUB = "wss://" + exports.BASE_DOMAIN + "/hub"; + +exports.API = exports.BASE + "/api"; +exports.AUTH = exports.API + "/auth"; +exports.LOGIN = exports.AUTH + "/login"; +exports.LOGOUT = exports.AUTH + "/logout"; +exports.USERS = exports.API + "/users"; +exports.SERVERS = exports.API + "/guilds"; +exports.CHANNELS = exports.API + "/channels"; +},{}],3:[function(require,module,exports){ +"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 PMChannel = (function () { + function PMChannel(data, client) { + _classCallCheck(this, PMChannel); + + this.user = client.getUser("id", data.recipient.id); + this.id = data.id; + this.messages = []; + } + + _createClass(PMChannel, [{ + key: "addMessage", + value: function addMessage(data) { + if (!this.getMessage("id", data.id)) { + this.messages.push(data); + } + return this.getMessage("id", data.id); + } + }, { + key: "getMessage", + value: function getMessage(key, value) { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var message = _step.value; + + if (message[key] === value) { + return message; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return null; + } + }, { + key: "isPrivate", + get: function get() { + return true; + } + }]); + + return PMChannel; +})(); + +module.exports = PMChannel; +},{}],4:[function(require,module,exports){ +"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 Channel = (function () { + function Channel(data, server) { + _classCallCheck(this, Channel); + + this.server = server; + this.name = data.name; + this.type = data.type; + this.id = data.id; + this.messages = []; + //this.isPrivate = isPrivate; //not sure about the implementation of this... + } + + _createClass(Channel, [{ + key: "equals", + value: function equals(object) { + return object && object.id === this.id; + } + }, { + key: "addMessage", + value: function addMessage(data) { + + if (this.messages.length > 1000) { + this.messages.splice(0, 1); + } + + if (!this.getMessage("id", data.id)) { + this.messages.push(data); + } + + return this.getMessage("id", data.id); + } + }, { + key: "getMessage", + value: function getMessage(key, value) { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var message = _step.value; + + if (message[key] === value) { + return message; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return null; + } + }, { + key: "toString", + value: function toString() { + return "<#" + this.id + ">"; + } + }, { + key: "client", + get: function get() { + return this.server.client; + } + }, { + key: "isPrivate", + get: function get() { + return false; + } + }, { + key: "users", + get: function get() { + return this.server.members; + } + }, { + key: "members", + get: function get() { + return this.server.members; + } + }]); + + return Channel; +})(); + +module.exports = Channel; +},{}],5:[function(require,module,exports){ +"use strict"; + +var request = require("superagent"); +var Endpoints = require("./Endpoints.js"); +var Client = require("./Client.js"); + +var Discord = { + Endpoints: Endpoints, + Client: Client +}; + +module.exports = Discord; +},{"./Client.js":1,"./Endpoints.js":2,"superagent":11}],6:[function(require,module,exports){ +"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 Invite = (function () { + function Invite(data, client) { + _classCallCheck(this, Invite); + + this.max_age = data.max_age; + this.code = data.code; + this.server = client.getServer("id", data.guild.id); + this.revoked = data.revoked; + this.created_at = Date.parse(data.created_at); + this.temporary = data.temporary; + this.uses = data.uses; + this.max_uses = data.uses; + this.inviter = client.addUser(data.inviter); + this.xkcd = data.xkcdpass; + this.channel = client.getChannel("id", data.channel.id); + } + + _createClass(Invite, [{ + key: "URL", + get: function get() { + var code = this.xkcd ? this.xkcdpass : this.code; + return "https://discord.gg/" + code; + } + }]); + + return Invite; +})(); + +module.exports = Invite; +},{}],7:[function(require,module,exports){ +"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 PMChannel = require("./PMChannel.js"); + +var Message = (function () { + function Message(data, channel, mentions, author) { + _classCallCheck(this, Message); + + this.tts = data.tts; + this.timestamp = Date.parse(data.timestamp); + this.nonce = data.nonce; + this.mentions = mentions; + this.everyoneMentioned = data.mention_everyone; + this.id = data.id; + this.embeds = data.embeds; + this.editedTimestamp = data.edited_timestamp; + this.content = data.content.trim(); + this.channel = channel; + this.author = author; + this.attachments = data.attachments; + } + + /*exports.Message.prototype.isPM = function() { + return ( this.channel instanceof PMChannel ); + }*/ + + _createClass(Message, [{ + key: "isMentioned", + value: function isMentioned(user) { + var id = user.id ? user.id : user; + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.mentions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var mention = _step.value; + + if (mention.id === id) { + return true; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return false; + } + }, { + key: "sender", + get: function get() { + return this.author; + } + }, { + key: "isPrivate", + get: function get() { + return this.channel.isPrivate; + } + }]); + + return Message; +})(); + +module.exports = Message; +},{"./PMChannel.js":3}],8:[function(require,module,exports){ +"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 = (function () { + function Server(data, client) { + _classCallCheck(this, Server); + + this.client = client; + this.region = data.region; + this.ownerID = data.owner_id; + this.name = data.name; + this.id = data.id; + this.members = []; + this.channels = []; + this.icon = data.icon; + this.afkTimeout = data.afk_timeout; + this.afkChannelId = data.afk_channel_id; + + if (!data.members) { + data.members = [client.user]; + return; + } + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = data.members[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var member = _step.value; + + // first we cache the user in our Discord Client, + // then we add it to our list. This way when we + // get a user from this server's member list, + // it will be identical (unless an async change occurred) + // to the client's cache. + if (member.user) this.members.push(client.addUser(member.user)); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + } + + _createClass(Server, [{ + key: "getChannel", + + // get/set + value: function getChannel(key, value) { + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = this.channels[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var channel = _step2.value; + + if (channel[key] === value) { + return channel; + } + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2["return"]) { + _iterator2["return"](); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + + return null; + } + }, { + key: "getMember", + value: function getMember(key, value) { + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = this.members[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var member = _step3.value; + + if (member[key] === value) { + return member; + } + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3["return"]) { + _iterator3["return"](); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + + return null; + } + }, { + key: "addChannel", + value: function addChannel(chann) { + if (!this.getChannel("id", chann.id)) { + this.channels.push(chann); + } + return chann; + } + }, { + key: "addMember", + value: function addMember(member) { + if (!this.getMember("id", member.id)) { + this.members.push(member); + } + return member; + } + }, { + key: "toString", + value: function toString() { + return this.name; + } + }, { + key: "iconURL", + get: function get() { + if (!this.icon) return null; + return "https://discordapp.com/api/guilds/" + this.id + "/icons/" + this.icon + ".jpg"; + } + }, { + key: "afkChannel", + get: function get() { + if (!this.afkChannelId) return false; + + return this.getChannel("id", this.afkChannelId); + } + }, { + key: "defaultChannel", + get: function get() { + return this.getChannel("name", "general"); + } + }, { + key: "owner", + get: function get() { + return this.client.getUser("id", this.ownerID); + } + }, { + key: "users", + get: function get() { + return this.members; + } + }]); + + return Server; +})(); + +module.exports = Server; +},{}],9:[function(require,module,exports){ +"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 User = (function () { + function User(data) { + _classCallCheck(this, User); + + this.username = data.username; + this.discriminator = data.discriminator; + this.id = data.id; + this.avatar = data.avatar; + this.status = "offline"; + } + + // access using user.avatarURL; + + _createClass(User, [{ + key: "mention", + value: function mention() { + return "<@" + this.id + ">"; + } + }, { + key: "toString", + value: function toString() { + /* + if we embed a user in a String - like so: + "Yo " + user + " what's up?" + It would generate something along the lines of: + "Yo @hydrabolt what's up?" + */ + return this.mention(); + } + }, { + key: "equals", + value: function equals(object) { + return object.id === this.id; + } + }, { + key: "equalsStrict", + value: function equalsStrict(object) { + return object.id === this.id && object.avatar === this.avatar && object.username === this.username && object.discriminator === this.discriminator; + } + }, { + key: "avatarURL", + get: function get() { + if (!this.avatar) return null; + return "https://discordapp.com/api/users/" + this.id + "/avatars/" + this.avatar + ".jpg"; + } + }]); + + return User; +})(); + +module.exports = User; +},{}],10:[function(require,module,exports){ + +},{}],11:[function(require,module,exports){ +/** + * Module dependencies. + */ + +var Emitter = require('emitter'); +var reduce = require('reduce'); + +/** + * Root reference for iframes. + */ + +var root = 'undefined' == typeof window + ? (this || self) + : window; + +/** + * Noop. + */ + +function noop(){}; + +/** + * Check if `obj` is a host object, + * we don't want to serialize these :) + * + * TODO: future proof, move to compoent land + * + * @param {Object} obj + * @return {Boolean} + * @api private + */ + +function isHost(obj) { + var str = {}.toString.call(obj); + + switch (str) { + case '[object File]': + case '[object Blob]': + case '[object FormData]': + return true; + default: + return false; + } +} + +/** + * Determine XHR. + */ + +request.getXHR = function () { + if (root.XMLHttpRequest + && (!root.location || 'file:' != root.location.protocol + || !root.ActiveXObject)) { + return new XMLHttpRequest; + } else { + try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {} + } + return false; +}; + +/** + * Removes leading and trailing whitespace, added to support IE. + * + * @param {String} s + * @return {String} + * @api private + */ + +var trim = ''.trim + ? function(s) { return s.trim(); } + : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); }; + +/** + * Check if `obj` is an object. + * + * @param {Object} obj + * @return {Boolean} + * @api private + */ + +function isObject(obj) { + return obj === Object(obj); +} + +/** + * Serialize the given `obj`. + * + * @param {Object} obj + * @return {String} + * @api private + */ + +function serialize(obj) { + if (!isObject(obj)) return obj; + var pairs = []; + for (var key in obj) { + if (null != obj[key]) { + pairs.push(encodeURIComponent(key) + + '=' + encodeURIComponent(obj[key])); + } + } + return pairs.join('&'); +} + +/** + * Expose serialization method. + */ + + request.serializeObject = serialize; + + /** + * Parse the given x-www-form-urlencoded `str`. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function parseString(str) { + var obj = {}; + var pairs = str.split('&'); + var parts; + var pair; + + for (var i = 0, len = pairs.length; i < len; ++i) { + pair = pairs[i]; + parts = pair.split('='); + obj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]); + } + + return obj; +} + +/** + * Expose parser. + */ + +request.parseString = parseString; + +/** + * Default MIME type map. + * + * superagent.types.xml = 'application/xml'; + * + */ + +request.types = { + html: 'text/html', + json: 'application/json', + xml: 'application/xml', + urlencoded: 'application/x-www-form-urlencoded', + 'form': 'application/x-www-form-urlencoded', + 'form-data': 'application/x-www-form-urlencoded' +}; + +/** + * Default serialization map. + * + * superagent.serialize['application/xml'] = function(obj){ + * return 'generated xml here'; + * }; + * + */ + + request.serialize = { + 'application/x-www-form-urlencoded': serialize, + 'application/json': JSON.stringify + }; + + /** + * Default parsers. + * + * superagent.parse['application/xml'] = function(str){ + * return { object parsed from str }; + * }; + * + */ + +request.parse = { + 'application/x-www-form-urlencoded': parseString, + 'application/json': JSON.parse +}; + +/** + * Parse the given header `str` into + * an object containing the mapped fields. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function parseHeader(str) { + var lines = str.split(/\r?\n/); + var fields = {}; + var index; + var line; + var field; + var val; + + lines.pop(); // trailing CRLF + + for (var i = 0, len = lines.length; i < len; ++i) { + line = lines[i]; + index = line.indexOf(':'); + field = line.slice(0, index).toLowerCase(); + val = trim(line.slice(index + 1)); + fields[field] = val; + } + + return fields; +} + +/** + * Return the mime type for the given `str`. + * + * @param {String} str + * @return {String} + * @api private + */ + +function type(str){ + return str.split(/ *; */).shift(); +}; + +/** + * Return header field parameters. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function params(str){ + return reduce(str.split(/ *; */), function(obj, str){ + var parts = str.split(/ *= */) + , key = parts.shift() + , val = parts.shift(); + + if (key && val) obj[key] = val; + return obj; + }, {}); +}; + +/** + * Initialize a new `Response` with the given `xhr`. + * + * - set flags (.ok, .error, etc) + * - parse header + * + * Examples: + * + * Aliasing `superagent` as `request` is nice: + * + * request = superagent; + * + * We can use the promise-like API, or pass callbacks: + * + * request.get('/').end(function(res){}); + * request.get('/', function(res){}); + * + * Sending data can be chained: + * + * request + * .post('/user') + * .send({ name: 'tj' }) + * .end(function(res){}); + * + * Or passed to `.send()`: + * + * request + * .post('/user') + * .send({ name: 'tj' }, function(res){}); + * + * Or passed to `.post()`: + * + * request + * .post('/user', { name: 'tj' }) + * .end(function(res){}); + * + * Or further reduced to a single call for simple cases: + * + * request + * .post('/user', { name: 'tj' }, function(res){}); + * + * @param {XMLHTTPRequest} xhr + * @param {Object} options + * @api private + */ + +function Response(req, options) { + options = options || {}; + this.req = req; + this.xhr = this.req.xhr; + // responseText is accessible only if responseType is '' or 'text' and on older browsers + this.text = ((this.req.method !='HEAD' && (this.xhr.responseType === '' || this.xhr.responseType === 'text')) || typeof this.xhr.responseType === 'undefined') + ? this.xhr.responseText + : null; + this.statusText = this.req.xhr.statusText; + this.setStatusProperties(this.xhr.status); + this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders()); + // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but + // getResponseHeader still works. so we get content-type even if getting + // other headers fails. + this.header['content-type'] = this.xhr.getResponseHeader('content-type'); + this.setHeaderProperties(this.header); + this.body = this.req.method != 'HEAD' + ? this.parseBody(this.text ? this.text : this.xhr.response) + : null; +} + +/** + * Get case-insensitive `field` value. + * + * @param {String} field + * @return {String} + * @api public + */ + +Response.prototype.get = function(field){ + return this.header[field.toLowerCase()]; +}; + +/** + * Set header related properties: + * + * - `.type` the content type without params + * + * A response of "Content-Type: text/plain; charset=utf-8" + * will provide you with a `.type` of "text/plain". + * + * @param {Object} header + * @api private + */ + +Response.prototype.setHeaderProperties = function(header){ + // content-type + var ct = this.header['content-type'] || ''; + this.type = type(ct); + + // params + var obj = params(ct); + for (var key in obj) this[key] = obj[key]; +}; + +/** + * Parse the given body `str`. + * + * Used for auto-parsing of bodies. Parsers + * are defined on the `superagent.parse` object. + * + * @param {String} str + * @return {Mixed} + * @api private + */ + +Response.prototype.parseBody = function(str){ + var parse = request.parse[this.type]; + return parse && str && (str.length || str instanceof Object) + ? parse(str) + : null; +}; + +/** + * Set flags such as `.ok` based on `status`. + * + * For example a 2xx response will give you a `.ok` of __true__ + * whereas 5xx will be __false__ and `.error` will be __true__. The + * `.clientError` and `.serverError` are also available to be more + * specific, and `.statusType` is the class of error ranging from 1..5 + * sometimes useful for mapping respond colors etc. + * + * "sugar" properties are also defined for common cases. Currently providing: + * + * - .noContent + * - .badRequest + * - .unauthorized + * - .notAcceptable + * - .notFound + * + * @param {Number} status + * @api private + */ + +Response.prototype.setStatusProperties = function(status){ + // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request + if (status === 1223) { + status = 204; + } + + var type = status / 100 | 0; + + // status / class + this.status = status; + this.statusType = type; + + // basics + this.info = 1 == type; + this.ok = 2 == type; + this.clientError = 4 == type; + this.serverError = 5 == type; + this.error = (4 == type || 5 == type) + ? this.toError() + : false; + + // sugar + this.accepted = 202 == status; + this.noContent = 204 == status; + this.badRequest = 400 == status; + this.unauthorized = 401 == status; + this.notAcceptable = 406 == status; + this.notFound = 404 == status; + this.forbidden = 403 == status; +}; + +/** + * Return an `Error` representative of this response. + * + * @return {Error} + * @api public + */ + +Response.prototype.toError = function(){ + var req = this.req; + var method = req.method; + var url = req.url; + + var msg = 'cannot ' + method + ' ' + url + ' (' + this.status + ')'; + var err = new Error(msg); + err.status = this.status; + err.method = method; + err.url = url; + + return err; +}; + +/** + * Expose `Response`. + */ + +request.Response = Response; + +/** + * Initialize a new `Request` with the given `method` and `url`. + * + * @param {String} method + * @param {String} url + * @api public + */ + +function Request(method, url) { + var self = this; + Emitter.call(this); + this._query = this._query || []; + this.method = method; + this.url = url; + this.header = {}; + this._header = {}; + this.on('end', function(){ + var err = null; + var res = null; + + try { + res = new Response(self); + } catch(e) { + err = new Error('Parser is unable to parse the response'); + err.parse = true; + err.original = e; + return self.callback(err); + } + + self.emit('response', res); + + if (err) { + return self.callback(err, res); + } + + if (res.status >= 200 && res.status < 300) { + return self.callback(err, res); + } + + var new_err = new Error(res.statusText || 'Unsuccessful HTTP response'); + new_err.original = err; + new_err.response = res; + new_err.status = res.status; + + self.callback(new_err, res); + }); +} + +/** + * Mixin `Emitter`. + */ + +Emitter(Request.prototype); + +/** + * Allow for extension + */ + +Request.prototype.use = function(fn) { + fn(this); + return this; +} + +/** + * Set timeout to `ms`. + * + * @param {Number} ms + * @return {Request} for chaining + * @api public + */ + +Request.prototype.timeout = function(ms){ + this._timeout = ms; + return this; +}; + +/** + * Clear previous timeout. + * + * @return {Request} for chaining + * @api public + */ + +Request.prototype.clearTimeout = function(){ + this._timeout = 0; + clearTimeout(this._timer); + return this; +}; + +/** + * Abort the request, and clear potential timeout. + * + * @return {Request} + * @api public + */ + +Request.prototype.abort = function(){ + if (this.aborted) return; + this.aborted = true; + this.xhr.abort(); + this.clearTimeout(); + this.emit('abort'); + return this; +}; + +/** + * Set header `field` to `val`, or multiple fields with one object. + * + * Examples: + * + * req.get('/') + * .set('Accept', 'application/json') + * .set('X-API-Key', 'foobar') + * .end(callback); + * + * req.get('/') + * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' }) + * .end(callback); + * + * @param {String|Object} field + * @param {String} val + * @return {Request} for chaining + * @api public + */ + +Request.prototype.set = function(field, val){ + if (isObject(field)) { + for (var key in field) { + this.set(key, field[key]); + } + return this; + } + this._header[field.toLowerCase()] = val; + this.header[field] = val; + return this; +}; + +/** + * Remove header `field`. + * + * Example: + * + * req.get('/') + * .unset('User-Agent') + * .end(callback); + * + * @param {String} field + * @return {Request} for chaining + * @api public + */ + +Request.prototype.unset = function(field){ + delete this._header[field.toLowerCase()]; + delete this.header[field]; + return this; +}; + +/** + * Get case-insensitive header `field` value. + * + * @param {String} field + * @return {String} + * @api private + */ + +Request.prototype.getHeader = function(field){ + return this._header[field.toLowerCase()]; +}; + +/** + * Set Content-Type to `type`, mapping values from `request.types`. + * + * Examples: + * + * superagent.types.xml = 'application/xml'; + * + * request.post('/') + * .type('xml') + * .send(xmlstring) + * .end(callback); + * + * request.post('/') + * .type('application/xml') + * .send(xmlstring) + * .end(callback); + * + * @param {String} type + * @return {Request} for chaining + * @api public + */ + +Request.prototype.type = function(type){ + this.set('Content-Type', request.types[type] || type); + return this; +}; + +/** + * Set Accept to `type`, mapping values from `request.types`. + * + * Examples: + * + * superagent.types.json = 'application/json'; + * + * request.get('/agent') + * .accept('json') + * .end(callback); + * + * request.get('/agent') + * .accept('application/json') + * .end(callback); + * + * @param {String} accept + * @return {Request} for chaining + * @api public + */ + +Request.prototype.accept = function(type){ + this.set('Accept', request.types[type] || type); + return this; +}; + +/** + * Set Authorization field value with `user` and `pass`. + * + * @param {String} user + * @param {String} pass + * @return {Request} for chaining + * @api public + */ + +Request.prototype.auth = function(user, pass){ + var str = btoa(user + ':' + pass); + this.set('Authorization', 'Basic ' + str); + return this; +}; + +/** +* Add query-string `val`. +* +* Examples: +* +* request.get('/shoes') +* .query('size=10') +* .query({ color: 'blue' }) +* +* @param {Object|String} val +* @return {Request} for chaining +* @api public +*/ + +Request.prototype.query = function(val){ + if ('string' != typeof val) val = serialize(val); + if (val) this._query.push(val); + return this; +}; + +/** + * Write the field `name` and `val` for "multipart/form-data" + * request bodies. + * + * ``` js + * request.post('/upload') + * .field('foo', 'bar') + * .end(callback); + * ``` + * + * @param {String} name + * @param {String|Blob|File} val + * @return {Request} for chaining + * @api public + */ + +Request.prototype.field = function(name, val){ + if (!this._formData) this._formData = new root.FormData(); + this._formData.append(name, val); + return this; +}; + +/** + * Queue the given `file` as an attachment to the specified `field`, + * with optional `filename`. + * + * ``` js + * request.post('/upload') + * .attach(new Blob(['hey!'], { type: "text/html"})) + * .end(callback); + * ``` + * + * @param {String} field + * @param {Blob|File} file + * @param {String} filename + * @return {Request} for chaining + * @api public + */ + +Request.prototype.attach = function(field, file, filename){ + if (!this._formData) this._formData = new root.FormData(); + this._formData.append(field, file, filename); + return this; +}; + +/** + * Send `data`, defaulting the `.type()` to "json" when + * an object is given. + * + * Examples: + * + * // querystring + * request.get('/search') + * .end(callback) + * + * // multiple data "writes" + * request.get('/search') + * .send({ search: 'query' }) + * .send({ range: '1..5' }) + * .send({ order: 'desc' }) + * .end(callback) + * + * // manual json + * request.post('/user') + * .type('json') + * .send('{"name":"tj"}) + * .end(callback) + * + * // auto json + * request.post('/user') + * .send({ name: 'tj' }) + * .end(callback) + * + * // manual x-www-form-urlencoded + * request.post('/user') + * .type('form') + * .send('name=tj') + * .end(callback) + * + * // auto x-www-form-urlencoded + * request.post('/user') + * .type('form') + * .send({ name: 'tj' }) + * .end(callback) + * + * // defaults to x-www-form-urlencoded + * request.post('/user') + * .send('name=tobi') + * .send('species=ferret') + * .end(callback) + * + * @param {String|Object} data + * @return {Request} for chaining + * @api public + */ + +Request.prototype.send = function(data){ + var obj = isObject(data); + var type = this.getHeader('Content-Type'); + + // merge + if (obj && isObject(this._data)) { + for (var key in data) { + this._data[key] = data[key]; + } + } else if ('string' == typeof data) { + if (!type) this.type('form'); + type = this.getHeader('Content-Type'); + if ('application/x-www-form-urlencoded' == type) { + this._data = this._data + ? this._data + '&' + data + : data; + } else { + this._data = (this._data || '') + data; + } + } else { + this._data = data; + } + + if (!obj || isHost(data)) return this; + if (!type) this.type('json'); + return this; +}; + +/** + * Invoke the callback with `err` and `res` + * and handle arity check. + * + * @param {Error} err + * @param {Response} res + * @api private + */ + +Request.prototype.callback = function(err, res){ + var fn = this._callback; + this.clearTimeout(); + fn(err, res); +}; + +/** + * Invoke callback with x-domain error. + * + * @api private + */ + +Request.prototype.crossDomainError = function(){ + var err = new Error('Origin is not allowed by Access-Control-Allow-Origin'); + err.crossDomain = true; + this.callback(err); +}; + +/** + * Invoke callback with timeout error. + * + * @api private + */ + +Request.prototype.timeoutError = function(){ + var timeout = this._timeout; + var err = new Error('timeout of ' + timeout + 'ms exceeded'); + err.timeout = timeout; + this.callback(err); +}; + +/** + * Enable transmission of cookies with x-domain requests. + * + * Note that for this to work the origin must not be + * using "Access-Control-Allow-Origin" with a wildcard, + * and also must set "Access-Control-Allow-Credentials" + * to "true". + * + * @api public + */ + +Request.prototype.withCredentials = function(){ + this._withCredentials = true; + return this; +}; + +/** + * Initiate request, invoking callback `fn(res)` + * with an instanceof `Response`. + * + * @param {Function} fn + * @return {Request} for chaining + * @api public + */ + +Request.prototype.end = function(fn){ + var self = this; + var xhr = this.xhr = request.getXHR(); + var query = this._query.join('&'); + var timeout = this._timeout; + var data = this._formData || this._data; + + // store callback + this._callback = fn || noop; + + // state change + xhr.onreadystatechange = function(){ + if (4 != xhr.readyState) return; + + // In IE9, reads to any property (e.g. status) off of an aborted XHR will + // result in the error "Could not complete the operation due to error c00c023f" + var status; + try { status = xhr.status } catch(e) { status = 0; } + + if (0 == status) { + if (self.timedout) return self.timeoutError(); + if (self.aborted) return; + return self.crossDomainError(); + } + self.emit('end'); + }; + + // progress + var handleProgress = function(e){ + if (e.total > 0) { + e.percent = e.loaded / e.total * 100; + } + self.emit('progress', e); + }; + if (this.hasListeners('progress')) { + xhr.onprogress = handleProgress; + } + try { + if (xhr.upload && this.hasListeners('progress')) { + xhr.upload.onprogress = handleProgress; + } + } catch(e) { + // Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist. + // Reported here: + // https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context + } + + // timeout + if (timeout && !this._timer) { + this._timer = setTimeout(function(){ + self.timedout = true; + self.abort(); + }, timeout); + } + + // querystring + if (query) { + query = request.serializeObject(query); + this.url += ~this.url.indexOf('?') + ? '&' + query + : '?' + query; + } + + // initiate request + xhr.open(this.method, this.url, true); + + // CORS + if (this._withCredentials) xhr.withCredentials = true; + + // body + if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) { + // serialize stuff + var contentType = this.getHeader('Content-Type'); + var serialize = request.serialize[contentType ? contentType.split(';')[0] : '']; + if (serialize) data = serialize(data); + } + + // set header fields + for (var field in this.header) { + if (null == this.header[field]) continue; + xhr.setRequestHeader(field, this.header[field]); + } + + // send stuff + this.emit('request', this); + xhr.send(data); + return this; +}; + +/** + * Faux promise support + * + * @param {Function} fulfill + * @param {Function} reject + * @return {Request} + */ + +Request.prototype.then = function (fulfill, reject) { + return this.end(function(err, res) { + err ? reject(err) : fulfill(res); + }); +} + +/** + * Expose `Request`. + */ + +request.Request = Request; + +/** + * Issue a request: + * + * Examples: + * + * request('GET', '/users').end(callback) + * request('/users').end(callback) + * request('/users', callback) + * + * @param {String} method + * @param {String|Function} url or callback + * @return {Request} + * @api public + */ + +function request(method, url) { + // callback + if ('function' == typeof url) { + return new Request('GET', method).end(url); + } + + // url first + if (1 == arguments.length) { + return new Request('GET', method); + } + + return new Request(method, url); +} + +/** + * GET `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.get = function(url, data, fn){ + var req = request('GET', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.query(data); + if (fn) req.end(fn); + return req; +}; + +/** + * HEAD `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.head = function(url, data, fn){ + var req = request('HEAD', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * DELETE `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.del = function(url, fn){ + var req = request('DELETE', url); + if (fn) req.end(fn); + return req; +}; + +/** + * PATCH `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed} data + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.patch = function(url, data, fn){ + var req = request('PATCH', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * POST `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed} data + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.post = function(url, data, fn){ + var req = request('POST', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * PUT `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.put = function(url, data, fn){ + var req = request('PUT', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * Expose `request`. + */ + +module.exports = request; + +},{"emitter":12,"reduce":13}],12:[function(require,module,exports){ + +/** + * Expose `Emitter`. + */ + +module.exports = Emitter; + +/** + * Initialize a new `Emitter`. + * + * @api public + */ + +function Emitter(obj) { + if (obj) return mixin(obj); +}; + +/** + * Mixin the emitter properties. + * + * @param {Object} obj + * @return {Object} + * @api private + */ + +function mixin(obj) { + for (var key in Emitter.prototype) { + obj[key] = Emitter.prototype[key]; + } + return obj; +} + +/** + * Listen on the given `event` with `fn`. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.on = +Emitter.prototype.addEventListener = function(event, fn){ + this._callbacks = this._callbacks || {}; + (this._callbacks[event] = this._callbacks[event] || []) + .push(fn); + return this; +}; + +/** + * Adds an `event` listener that will be invoked a single + * time then automatically removed. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.once = function(event, fn){ + var self = this; + this._callbacks = this._callbacks || {}; + + function on() { + self.off(event, on); + fn.apply(this, arguments); + } + + on.fn = fn; + this.on(event, on); + return this; +}; + +/** + * Remove the given callback for `event` or all + * registered callbacks. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.off = +Emitter.prototype.removeListener = +Emitter.prototype.removeAllListeners = +Emitter.prototype.removeEventListener = function(event, fn){ + this._callbacks = this._callbacks || {}; + + // all + if (0 == arguments.length) { + this._callbacks = {}; + return this; + } + + // specific event + var callbacks = this._callbacks[event]; + if (!callbacks) return this; + + // remove all handlers + if (1 == arguments.length) { + delete this._callbacks[event]; + return this; + } + + // remove specific handler + var cb; + for (var i = 0; i < callbacks.length; i++) { + cb = callbacks[i]; + if (cb === fn || cb.fn === fn) { + callbacks.splice(i, 1); + break; + } + } + return this; +}; + +/** + * Emit `event` with the given args. + * + * @param {String} event + * @param {Mixed} ... + * @return {Emitter} + */ + +Emitter.prototype.emit = function(event){ + this._callbacks = this._callbacks || {}; + var args = [].slice.call(arguments, 1) + , callbacks = this._callbacks[event]; + + if (callbacks) { + callbacks = callbacks.slice(0); + for (var i = 0, len = callbacks.length; i < len; ++i) { + callbacks[i].apply(this, args); + } + } + + return this; +}; + +/** + * Return array of callbacks for `event`. + * + * @param {String} event + * @return {Array} + * @api public + */ + +Emitter.prototype.listeners = function(event){ + this._callbacks = this._callbacks || {}; + return this._callbacks[event] || []; +}; + +/** + * Check if this emitter has `event` handlers. + * + * @param {String} event + * @return {Boolean} + * @api public + */ + +Emitter.prototype.hasListeners = function(event){ + return !! this.listeners(event).length; +}; + +},{}],13:[function(require,module,exports){ + +/** + * Reduce `arr` with `fn`. + * + * @param {Array} arr + * @param {Function} fn + * @param {Mixed} initial + * + * TODO: combatible error handling? + */ + +module.exports = function(arr, fn, initial){ + var idx = 0; + var len = arr.length; + var curr = arguments.length == 3 + ? initial + : arr[idx++]; + + while (idx < len) { + curr = fn.call(null, curr, arr[idx], ++idx, arr); + } + + return curr; +}; +},{}],14:[function(require,module,exports){ + +/** + * Module dependencies. + */ + +var global = (function() { return this; })(); + +/** + * WebSocket constructor. + */ + +var WebSocket = global.WebSocket || global.MozWebSocket; + +/** + * Module exports. + */ + +module.exports = WebSocket ? ws : null; + +/** + * WebSocket constructor. + * + * The third `opts` options object gets ignored in web browsers, since it's + * non-standard, and throws a TypeError if passed to the constructor. + * See: https://github.com/einaros/ws/issues/227 + * + * @param {String} uri + * @param {Array} protocols (optional) + * @param {Object) opts (optional) + * @api public + */ + +function ws(uri, protocols, opts) { + var instance; + if (protocols) { + instance = new WebSocket(uri, protocols); + } else { + instance = new WebSocket(uri); + } + return instance; +} + +if (WebSocket) ws.prototype = WebSocket.prototype; + +},{}]},{},[5])(5) +}); \ No newline at end of file diff --git a/web-dist/discord.min.3.4.0.js b/web-dist/discord.min.3.4.0.js new file mode 100644 index 000000000..9028bea6a --- /dev/null +++ b/web-dist/discord.min.3.4.0.js @@ -0,0 +1,2 @@ +!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Discord=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g]*>/g)||[])[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;a.push(h.substring(2,h.length-1))}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return a}"function"==typeof c&&(d=c,c=!1),b=e+n(b);var p=o();f.resolveDestination(a).then(k)["catch"](j)});return g}},{key:"createws",value:function(a){if(this.websocket)return!1;var b=this;this.websocket=new n(a),this.websocket.onopen=function(){b.trySendConnData()},this.websocket.onclose=function(){b.trigger("disconnected")},this.websocket.onmessage=function(a){var c=!1,d={};try{c=JSON.parse(a.data),d=c.d}catch(e){return void b.trigger("error",e,a)}switch(c.t){case"READY":b.debug("received ready packet"),b.user=b.addUser(d.user);var f=!0,h=!1,i=void 0;try{for(var k,l=d.guilds[Symbol.iterator]();!(f=(k=l.next()).done);f=!0)var m=k.value,n=b.addServer(m)}catch(e){h=!0,i=e}finally{try{!f&&l["return"]&&l["return"]()}finally{if(h)throw i}}var o=!0,p=!1,q=void 0;try{for(var r,s=d.private_channels[Symbol.iterator]();!(o=(r=s.next()).done);o=!0){var t=r.value;b.addPMChannel(t)}}catch(e){p=!0,q=e}finally{try{!o&&s["return"]&&s["return"]()}finally{if(p)throw q}}b.trigger("ready"),b.readyTime=Date.now(),b.debug("cached "+b.serverCache.length+" servers, "+b.channelCache.length+" channels, "+b.pmChannelCache.length+" PMs and "+b.userCache.length+" users."),b.state=3,setInterval(function(){b.keepAlive.apply(b)},d.heartbeat_interval);break;case"MESSAGE_CREATE":b.debug("received message");var u=[];d.mentions=d.mentions||[];var v=!0,w=!1,x=void 0;try{for(var y,z=d.mentions[Symbol.iterator]();!(v=(y=z.next()).done);v=!0){var A=y.value;u.push(b.addUser(A))}}catch(e){w=!0,x=e}finally{try{!v&&z["return"]&&z["return"]()}finally{if(w)throw x}}var B=b.getChannel("id",d.channel_id);if(B){var C=B.addMessage(new j(d,B,u,b.addUser(d.author)));b.trigger("message",C)}break;case"MESSAGE_DELETE":b.debug("message deleted");var B=b.getChannel("id",d.channel_id),D=B.getMessage("id",d.id);D?(b.trigger("messageDelete",B,D),B.messages.splice(B.messages.indexOf(D),1)):b.trigger("messageDelete",B);break;case"MESSAGE_UPDATE":b.debug("message updated");var B=b.getChannel("id",d.channel_id),E=B.getMessage("id",d.id);if(E){var F={};for(var G in E)F[G]=E[G];for(var G in d)F[G]=d[G];var u=[],H=!0,I=!1,J=void 0;try{for(var K,L=F.mentions[Symbol.iterator]();!(H=(K=L.next()).done);H=!0){var A=K.value;u.push(b.addUser(A))}}catch(e){I=!0,J=e}finally{try{!H&&L["return"]&&L["return"]()}finally{if(I)throw J}}var M=new j(F,B,u,E.author);b.trigger("messageUpdate",M,E),B.messages[B.messages.indexOf(E)]=M}break;case"GUILD_DELETE":var n=b.getServer("id",d.id);n&&(b.serverCache.splice(b.serverCache.indexOf(n),1),b.trigger("serverDelete",n));break;case"CHANNEL_DELETE":var B=b.getChannel("id",d.id);if(B){var n=B.server;n&&n.channels.splice(n.channels.indexOf(B),1),b.trigger("channelDelete",B),b.serverCache.splice(b.serverCache.indexOf(B),1)}break;case"GUILD_CREATE":var n=b.getServer("id",d.id);if(n||(n=b.addServer(d)),b.serverCreateListener[d.id]){var N=b.serverCreateListener[d.id];N[0](n),N[1](null,n),b.serverCreateListener[d.id]=null}b.trigger("serverCreate",n);break;case"CHANNEL_CREATE":var B=b.getChannel("id",d.id);if(!B){var O=b.addChannel(d,d.guild_id),P=b.getServer("id",d.guild_id);P&&P.addChannel(O),b.trigger("channelCreate",O)}break;case"GUILD_MEMBER_ADD":var n=b.getServer("id",d.guild_id);if(n){var Q=b.addUser(d.user);~n.members.indexOf(Q)||n.members.push(Q),b.trigger("serverNewMember",Q,n)}break;case"GUILD_MEMBER_REMOVE":var n=b.getServer("id",d.guild_id);if(n){var Q=b.addUser(d.user);~n.members.indexOf(Q)&&n.members.splice(n.members.indexOf(Q),1),b.trigger("serverRemoveMember",Q,n)}break;case"USER_UPDATE":if(b.user&&d.id===b.user.id){var R=new g(d);b.trigger("userUpdate",R,b.user),~b.userCache.indexOf(b.user)&&(b.userCache[b.userCache.indexOf(b.user)]=R),b.user=R}break;case"PRESENCE_UPDATE":var S=b.getUser("id",d.user.id);if(S){var T=new g(d.user);T.equalsStrict(S)?(S.status=d.status,b.trigger("presence",{user:S,status:d.status,server:b.getServer("id",d.guild_id),gameId:d.game_id})):(b.trigger("userUpdate",S,T),b.userCache[b.userCache.indexOf(S)]=T)}break;default:b.debug("received unknown packet"),b.trigger("unknown",c)}}}},{key:"addUser",value:function(a){return this.getUser("id",a.id)||this.userCache.push(new g(a)),this.getUser("id",a.id)}},{key:"addChannel",value:function(a,b){return this.getChannel("id",a.id)||this.channelCache.push(new i(a,this.getServer("id",b))),this.getChannel("id",a.id)}},{key:"addPMChannel",value:function(a){return this.getPMChannel("id",a.id)||this.pmChannelCache.push(new l(a,this)),this.getPMChannel("id",a.id)}},{key:"addServer",value:function(a){var b=this,c=this.getServer("id",a.id);if(!c&&(c=new h(a,this),this.serverCache.push(c),a.channels)){var d=!0,e=!1,f=void 0;try{for(var g,i=a.channels[Symbol.iterator]();!(d=(g=i.next()).done);d=!0){var j=g.value;c.channels.push(this.addChannel(j,c.id))}}catch(k){e=!0,f=k}finally{try{!d&&i["return"]&&i["return"]()}finally{if(e)throw f}}}var l=!0,m=!1,n=void 0;try{for(var o,p=a.presences[Symbol.iterator]();!(l=(o=p.next()).done);l=!0){var q=o.value;b.getUser("id",q.user.id).status=q.status}}catch(k){m=!0,n=k}finally{try{!l&&p["return"]&&p["return"]()}finally{if(m)throw n}}return c}},{key:"getUser",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.userCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"getChannel",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.channelCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return this.getPMChannel(a,b)}},{key:"getPMChannel",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.pmChannelCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"getServer",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.serverCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"trySendConnData",value:function(){if(this.token&&!this.alreadySentData){this.alreadySentData=!0;var a={op:2,d:{token:this.token,v:2,properties:{$os:"discord.js",$browser:"discord.js",$device:"discord.js",$referrer:"",$referring_domain:""}}};this.websocket.send(JSON.stringify(a))}}},{key:"resolveServerID",value:function(a){return a instanceof h?a.id:!isNaN(a)&&a.length&&17===a.length?a:void 0}},{key:"resolveDestination",value:function(a){var b=!1,c=this;return new Promise(function(d,e){if(a instanceof h)b=a.id;else if(a instanceof i)b=a.id;else if(a instanceof j)b=a.channel.id;else if(a instanceof g){var f=!0,k=!1,l=void 0;try{for(var m,n=c.pmChannelCache[Symbol.iterator]();!(f=(m=n.next()).done);f=!0){var o=m.value;if(o.user.equals(a))return void d(o.id)}}catch(p){k=!0,l=p}finally{try{!f&&n["return"]&&n["return"]()}finally{if(k)throw l}}c.startPM(a).then(function(a){console.log(a),d(a.id)})["catch"](e)}else b=a;b&&d(b)})}},{key:"_sendMessage",value:function(a,b,c,d){var e=this;return new Promise(function(g,h){m.post(f.CHANNELS+"/"+a+"/messages").set("authorization",e.token).send({content:b,mentions:d,tts:c}).end(function(a,b){if(a)h(a);else{var c=b.body,d=[];c.mentions=c.mentions||[];var f=!0,i=!1,k=void 0;try{for(var l,m=c.mentions[Symbol.iterator]();!(f=(l=m.next()).done);f=!0){var n=l.value;d.push(e.addUser(n))}}catch(a){i=!0,k=a}finally{try{!f&&m["return"]&&m["return"]()}finally{if(i)throw k}}var o=e.getChannel("id",c.channel_id);if(o){var p=o.addMessage(new j(c,o,d,e.addUser(c.author)));g(p)}}})})}},{key:"_sendFile",value:function(a,b){var c=arguments.length<=2||void 0===arguments[2]?"DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png":arguments[2],d=this;return new Promise(function(e,g){m.post(f.CHANNELS+"/"+a+"/messages").set("authorization",d.token).attach("file",b,c).end(function(b,c){if(b)g(b);else{var f=d.getChannel("id",a);if(f){var h=f.addMessage(new j(c.body,f,[],d.user));e(h)}}})})}},{key:"_updateMessage",value:function(a,b){var c=this;return new Promise(function(d,e){m.patch(f.CHANNELS+"/"+a.channel.id+"/messages/"+a.id).set("authorization",c.token).send({content:b,mentions:[]}).end(function(b,c){if(b)e(b);else{var f=new j(c.body,a.channel,a.mentions,a.sender);d(f),a.channel.messages[a.channel.messages.indexOf(a)]=f}})})}},{key:"_deleteMessage",value:function(a){var b=this;return new Promise(function(c,d){m.del(f.CHANNELS+"/"+a.channel.id+"/messages/"+a.id).set("authorization",b.token).end(function(a,b){a?d(a):c()})})}},{key:"checkQueue",value:function(a){var b=this,c=this;this.checkingQueue[a]||!function(){var d=function f(){if(0===c.queue[a].length)return void e();var b=c.queue[a][0];switch(b.action){case"sendMessage":var d=b;c._sendMessage(a,d.content,d.tts,d.mentions).then(function(b){d.then(b),c.queue[a].shift(),f()})["catch"](function(b){d.error(b),c.queue[a].shift(),f()});break;case"sendFile":var g=b;c._sendFile(a,g.attachment,g.attachmentName).then(function(b){g.then(b),c.queue[a].shift(),f()})["catch"](function(b){g.error(b),c.queue[a].shift(),f()});break;case"updateMessage":var h=b;c._updateMessage(h.message,h.content).then(function(b){h.then(b),c.queue[a].shift(),f()})["catch"](function(b){h.error(b),c.queue[a].shift(),f()});break;case"deleteMessage":var i=b;c._deleteMessage(i.message).then(function(b){i.then(b),c.queue[a].shift(),f()})["catch"](function(b){i.error(b),c.queue[a].shift(),f()});break;default:e()}},e=function(){c.checkingQueue[a]=!1};b.checkingQueue[a]=!0,d()}()}},{key:"getGateway",value:function(){var a=this;return new Promise(function(b,c){m.get(f.API+"/gateway").set("authorization",a.token).end(function(a,d){a?c(a):b(d.body.url)})})}},{key:"uptime",get:function(){return this.readyTime?Date.now()-this.readyTime:null}},{key:"ready",get:function(){return 3===this.state}},{key:"servers",get:function(){return this.serverCache}},{key:"channels",get:function(){return this.channelCache}},{key:"users",get:function(){return this.userCache}},{key:"PMChannels",get:function(){return this.pmChannelCache}},{key:"messages",get:function(){var a=[],b=!0,c=!1,d=void 0;try{for(var e,f=this.channelCache[Symbol.iterator]();!(b=(e=f.next()).done);b=!0){var g=e.value;a=a.concat(g.messages)}}catch(h){c=!0,d=h}finally{try{!b&&f["return"]&&f["return"]()}finally{if(c)throw d}}return a}}]),a}();b.exports=q},{"./Endpoints.js":2,"./PMChannel.js":3,"./channel.js":4,"./invite.js":6,"./message.js":7,"./server.js":8,"./user.js":9,fs:10,superagent:11,ws:14}],2:[function(a,b,c){"use strict";c.BASE_DOMAIN="discordapp.com",c.BASE="https://"+c.BASE_DOMAIN,c.WEBSOCKET_HUB="wss://"+c.BASE_DOMAIN+"/hub",c.API=c.BASE+"/api",c.AUTH=c.API+"/auth",c.LOGIN=c.AUTH+"/login",c.LOGOUT=c.AUTH+"/logout",c.USERS=c.API+"/users",c.SERVERS=c.API+"/guilds",c.CHANNELS=c.API+"/channels"},{}],3:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c1e3&&this.messages.splice(0,1),this.getMessage("id",a.id)||this.messages.push(a),this.getMessage("id",a.id)}},{key:"getMessage",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.messages[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"toString",value:function(){return"<#"+this.id+">"}},{key:"client",get:function(){return this.server.client}},{key:"isPrivate",get:function(){return!1}},{key:"users",get:function(){return this.server.members}},{key:"members",get:function(){return this.server.members}}]),a}();b.exports=f},{}],5:[function(a,b,c){"use strict";var d=(a("superagent"),a("./Endpoints.js")),e=a("./Client.js"),f={Endpoints:d,Client:e};b.exports=f},{"./Client.js":1,"./Endpoints.js":2,superagent:11}],6:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c"}},{key:"toString",value:function(){return this.mention()}},{key:"equals",value:function(a){return a.id===this.id}},{key:"equalsStrict",value:function(a){return a.id===this.id&&a.avatar===this.avatar&&a.username===this.username&&a.discriminator===this.discriminator}},{key:"avatarURL",get:function(){return this.avatar?"https://discordapp.com/api/users/"+this.id+"/avatars/"+this.avatar+".jpg":null}}]),a}();b.exports=f},{}],10:[function(a,b,c){},{}],11:[function(a,b,c){function d(){}function e(a){var b={}.toString.call(a);switch(b){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function f(a){return a===Object(a)}function g(a){if(!f(a))return a;var b=[];for(var c in a)null!=a[c]&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")}function h(a){for(var b,c,d={},e=a.split("&"),f=0,g=e.length;g>f;++f)c=e[f],b=c.split("="),d[decodeURIComponent(b[0])]=decodeURIComponent(b[1]);return d}function i(a){var b,c,d,e,f=a.split(/\r?\n/),g={};f.pop();for(var h=0,i=f.length;i>h;++h)c=f[h],b=c.indexOf(":"),d=c.slice(0,b).toLowerCase(),e=r(c.slice(b+1)),g[d]=e;return g}function j(a){return a.split(/ *; */).shift()}function k(a){return p(a.split(/ *; */),function(a,b){var c=b.split(/ *= */),d=c.shift(),e=c.shift();return d&&e&&(a[d]=e),a},{})}function l(a,b){b=b||{},this.req=a,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||"undefined"==typeof this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText,this.setStatusProperties(this.xhr.status),this.header=this.headers=i(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body="HEAD"!=this.req.method?this.parseBody(this.text?this.text:this.xhr.response):null}function m(a,b){var c=this;o.call(this),this._query=this._query||[],this.method=a,this.url=b,this.header={},this._header={},this.on("end",function(){var a=null,b=null;try{b=new l(c)}catch(d){return a=new Error("Parser is unable to parse the response"),a.parse=!0,a.original=d,c.callback(a)}if(c.emit("response",b),a)return c.callback(a,b);if(b.status>=200&&b.status<300)return c.callback(a,b);var e=new Error(b.statusText||"Unsuccessful HTTP response");e.original=a,e.response=b,e.status=b.status,c.callback(e,b)})}function n(a,b){return"function"==typeof b?new m("GET",a).end(b):1==arguments.length?new m("GET",a):new m(a,b)}var o=a("emitter"),p=a("reduce"),q="undefined"==typeof window?this||self:window;n.getXHR=function(){if(!(!q.XMLHttpRequest||q.location&&"file:"==q.location.protocol&&q.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(a){}return!1};var r="".trim?function(a){return a.trim()}:function(a){return a.replace(/(^\s*|\s*$)/g,"")};n.serializeObject=g,n.parseString=h,n.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},n.serialize={"application/x-www-form-urlencoded":g,"application/json":JSON.stringify},n.parse={"application/x-www-form-urlencoded":h,"application/json":JSON.parse},l.prototype.get=function(a){return this.header[a.toLowerCase()]},l.prototype.setHeaderProperties=function(a){var b=this.header["content-type"]||"";this.type=j(b);var c=k(b);for(var d in c)this[d]=c[d]},l.prototype.parseBody=function(a){var b=n.parse[this.type];return b&&a&&(a.length||a instanceof Object)?b(a):null},l.prototype.setStatusProperties=function(a){1223===a&&(a=204);var b=a/100|0;this.status=a,this.statusType=b,this.info=1==b,this.ok=2==b,this.clientError=4==b,this.serverError=5==b,this.error=4==b||5==b?this.toError():!1,this.accepted=202==a,this.noContent=204==a,this.badRequest=400==a, +this.unauthorized=401==a,this.notAcceptable=406==a,this.notFound=404==a,this.forbidden=403==a},l.prototype.toError=function(){var a=this.req,b=a.method,c=a.url,d="cannot "+b+" "+c+" ("+this.status+")",e=new Error(d);return e.status=this.status,e.method=b,e.url=c,e},n.Response=l,o(m.prototype),m.prototype.use=function(a){return a(this),this},m.prototype.timeout=function(a){return this._timeout=a,this},m.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},m.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(),this.clearTimeout(),this.emit("abort"),this)},m.prototype.set=function(a,b){if(f(a)){for(var c in a)this.set(c,a[c]);return this}return this._header[a.toLowerCase()]=b,this.header[a]=b,this},m.prototype.unset=function(a){return delete this._header[a.toLowerCase()],delete this.header[a],this},m.prototype.getHeader=function(a){return this._header[a.toLowerCase()]},m.prototype.type=function(a){return this.set("Content-Type",n.types[a]||a),this},m.prototype.accept=function(a){return this.set("Accept",n.types[a]||a),this},m.prototype.auth=function(a,b){var c=btoa(a+":"+b);return this.set("Authorization","Basic "+c),this},m.prototype.query=function(a){return"string"!=typeof a&&(a=g(a)),a&&this._query.push(a),this},m.prototype.field=function(a,b){return this._formData||(this._formData=new q.FormData),this._formData.append(a,b),this},m.prototype.attach=function(a,b,c){return this._formData||(this._formData=new q.FormData),this._formData.append(a,b,c),this},m.prototype.send=function(a){var b=f(a),c=this.getHeader("Content-Type");if(b&&f(this._data))for(var d in a)this._data[d]=a[d];else"string"==typeof a?(c||this.type("form"),c=this.getHeader("Content-Type"),"application/x-www-form-urlencoded"==c?this._data=this._data?this._data+"&"+a:a:this._data=(this._data||"")+a):this._data=a;return!b||e(a)?this:(c||this.type("json"),this)},m.prototype.callback=function(a,b){var c=this._callback;this.clearTimeout(),c(a,b)},m.prototype.crossDomainError=function(){var a=new Error("Origin is not allowed by Access-Control-Allow-Origin");a.crossDomain=!0,this.callback(a)},m.prototype.timeoutError=function(){var a=this._timeout,b=new Error("timeout of "+a+"ms exceeded");b.timeout=a,this.callback(b)},m.prototype.withCredentials=function(){return this._withCredentials=!0,this},m.prototype.end=function(a){var b=this,c=this.xhr=n.getXHR(),f=this._query.join("&"),g=this._timeout,h=this._formData||this._data;this._callback=a||d,c.onreadystatechange=function(){if(4==c.readyState){var a;try{a=c.status}catch(d){a=0}if(0==a){if(b.timedout)return b.timeoutError();if(b.aborted)return;return b.crossDomainError()}b.emit("end")}};var i=function(a){a.total>0&&(a.percent=a.loaded/a.total*100),b.emit("progress",a)};this.hasListeners("progress")&&(c.onprogress=i);try{c.upload&&this.hasListeners("progress")&&(c.upload.onprogress=i)}catch(j){}if(g&&!this._timer&&(this._timer=setTimeout(function(){b.timedout=!0,b.abort()},g)),f&&(f=n.serializeObject(f),this.url+=~this.url.indexOf("?")?"&"+f:"?"+f),c.open(this.method,this.url,!0),this._withCredentials&&(c.withCredentials=!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof h&&!e(h)){var k=this.getHeader("Content-Type"),l=n.serialize[k?k.split(";")[0]:""];l&&(h=l(h))}for(var m in this.header)null!=this.header[m]&&c.setRequestHeader(m,this.header[m]);return this.emit("request",this),c.send(h),this},m.prototype.then=function(a,b){return this.end(function(c,d){c?b(c):a(d)})},n.Request=m,n.get=function(a,b,c){var d=n("GET",a);return"function"==typeof b&&(c=b,b=null),b&&d.query(b),c&&d.end(c),d},n.head=function(a,b,c){var d=n("HEAD",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.del=function(a,b){var c=n("DELETE",a);return b&&c.end(b),c},n.patch=function(a,b,c){var d=n("PATCH",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.post=function(a,b,c){var d=n("POST",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.put=function(a,b,c){var d=n("PUT",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},b.exports=n},{emitter:12,reduce:13}],12:[function(a,b,c){function d(a){return a?e(a):void 0}function e(a){for(var b in d.prototype)a[b]=d.prototype[b];return a}b.exports=d,d.prototype.on=d.prototype.addEventListener=function(a,b){return this._callbacks=this._callbacks||{},(this._callbacks[a]=this._callbacks[a]||[]).push(b),this},d.prototype.once=function(a,b){function c(){d.off(a,c),b.apply(this,arguments)}var d=this;return this._callbacks=this._callbacks||{},c.fn=b,this.on(a,c),this},d.prototype.off=d.prototype.removeListener=d.prototype.removeAllListeners=d.prototype.removeEventListener=function(a,b){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var c=this._callbacks[a];if(!c)return this;if(1==arguments.length)return delete this._callbacks[a],this;for(var d,e=0;ed;++d)c[d].apply(this,b)}return this},d.prototype.listeners=function(a){return this._callbacks=this._callbacks||{},this._callbacks[a]||[]},d.prototype.hasListeners=function(a){return!!this.listeners(a).length}},{}],13:[function(a,b,c){b.exports=function(a,b,c){for(var d=0,e=a.length,f=3==arguments.length?c:a[d++];e>d;)f=b.call(null,f,a[d],++d,a);return f}},{}],14:[function(a,b,c){function d(a,b,c){var d;return d=b?new f(a,b):new f(a)}var e=function(){return this}(),f=e.WebSocket||e.MozWebSocket;b.exports=f?d:null,f&&(d.prototype=f.prototype)},{}]},{},[5])(5)}); \ No newline at end of file From 7f5050f9798c516f5d0e24d5e334da569dad97b4 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 26 Sep 2015 21:53:23 +0100 Subject: [PATCH 040/151] Began to work on status setting --- lib/Client.js | 13 +++++++++++++ src/Client.js | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/Client.js b/lib/Client.js index 7d7bba771..a0629dced 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1641,6 +1641,19 @@ var Client = (function () { }); }); } + }, { + key: "setStatusIdle", + value: function setStatusIdle() { + this.setStatus("idle"); + } + }, { + key: "setStatusOnline", + value: function setStatusOnline() { + this.setStatus("online"); + } + }, { + key: "setStatus", + value: function setStatus() {} }, { key: "uptime", get: function get() { diff --git a/src/Client.js b/src/Client.js index 5b5bc872f..e06d5525d 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1382,6 +1382,18 @@ class Client { }); }); } + + setStatusIdle(){ + this.setStatus("idle"); + } + + setStatusOnline(){ + this.setStatus("online"); + } + + setStatus(){ + + } } module.exports = Client; \ No newline at end of file From 3094c223ec90588ef3deefeef18fed4007322ea0 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 26 Sep 2015 21:59:27 +0100 Subject: [PATCH 041/151] Added status setting You can now run bot.setStatusIdle() or bot.setStatusOnline() (or any aliases) to manually set the status of the bot. --- lib/Client.js | 28 +++++++++++++++++++++++++++- src/Client.js | 23 ++++++++++++++++++++++- test/bot.1.js | 10 ++++++---- 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index a0629dced..035d49f07 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1651,9 +1651,35 @@ var Client = (function () { value: function setStatusOnline() { this.setStatus("online"); } + }, { + key: "setStatusActive", + value: function setStatusActive() { + this.setStatusOnline(); + } + }, { + key: "setStatusHere", + value: function setStatusHere() { + this.setStatusOnline(); + } + }, { + key: "setStatusAway", + value: function setStatusAway() { + this.setStatusIdle(); + } }, { key: "setStatus", - value: function setStatus() {} + value: function setStatus(stat) { + + var idleTime = stat === "online" ? null : Date.now(); + + this.websocket.send(JSON.stringify({ + op: 3, + d: { + idle_since: idleTime, + game_id: null + } + })); + } }, { key: "uptime", get: function get() { diff --git a/src/Client.js b/src/Client.js index e06d5525d..927c79bfa 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1391,8 +1391,29 @@ class Client { this.setStatus("online"); } - setStatus(){ + setStatusActive(){ + this.setStatusOnline(); + } + + setStatusHere(){ + this.setStatusOnline(); + } + + setStatusAway(){ + this.setStatusIdle(); + } + + setStatus(stat){ + var idleTime = (stat === "online" ? null : Date.now()); + + this.websocket.send(JSON.stringify({ + op : 3, + d : { + idle_since : idleTime, + game_id : null + } + })); } } diff --git a/test/bot.1.js b/test/bot.1.js index ed608f092..131ac7322 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -18,12 +18,14 @@ mybot.on("message", function (message) { // we can go ahead :) var onlineUsers = 0; - for(user of message.channel.users){ - if(user.status === "online" || user.status === "idle") - onlineUsers++; - } + + mybot.setStatusIdle(); mybot.reply(message, onlineUsers); + + setTimeout(function(){ + mybot.setStatusOnline(); + },5000); }); mybot.on("ready", function () { From 5fa7bace1089b983725438b60752ef99923b88d4 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 26 Sep 2015 22:41:33 +0100 Subject: [PATCH 042/151] Added startTyping and stopTyping --- lib/Client.js | 45 +++++++++++++++++++++++++++++++++++++++++++-- src/Client.js | 47 +++++++++++++++++++++++++++++++++++++++++++++-- test/bot.1.js | 10 +++++----- 3 files changed, 93 insertions(+), 9 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 035d49f07..29b5bb38f 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -43,7 +43,7 @@ var Client = (function () { this.user = null; this.alreadySentData = false; this.serverCreateListener = {}; - + this.typingIntervals = {}; this.email = "abc"; this.password = "abc"; @@ -1354,7 +1354,7 @@ var Client = (function () { op: 2, d: { token: this.token, - v: 2, + v: 3, properties: { "$os": "discord.js", "$browser": "discord.js", @@ -1666,6 +1666,47 @@ var Client = (function () { value: function setStatusAway() { this.setStatusIdle(); } + }, { + key: "startTyping", + value: function startTyping(chann) { + var self = this; + + this.resolveDestination(chann).then(next); + + function next(channel) { + if (self.typingIntervals[channel]) { + return; + } + + var fn = function fn() { + console.log(Endpoints.CHANNELS + "/" + channel + "/typing"); + request.post(Endpoints.CHANNELS + "/" + channel + "/typing").set("authorization", self.token).end(); + }; + + fn(); + + var interval = setInterval(fn, 3000); + + self.typingIntervals[channel] = interval; + } + } + }, { + key: "stopTyping", + value: function stopTyping(chann) { + var self = this; + + this.resolveDestination(chann).then(next); + + function next(channel) { + if (!self.typingIntervals[channel]) { + return; + } + + clearInterval(self.typingIntervals[channel]); + + delete self.typingIntervals[channel]; + } + } }, { key: "setStatus", value: function setStatus(stat) { diff --git a/src/Client.js b/src/Client.js index 927c79bfa..f0a0aba1f 100644 --- a/src/Client.js +++ b/src/Client.js @@ -33,7 +33,7 @@ class Client { this.user = null; this.alreadySentData = false; this.serverCreateListener = {}; - + this.typingIntervals = {}; this.email = "abc"; this.password = "abc"; @@ -1115,7 +1115,7 @@ class Client { op: 2, d: { token: this.token, - v: 2, + v: 3, properties: { "$os": "discord.js", "$browser": "discord.js", @@ -1403,6 +1403,49 @@ class Client { this.setStatusIdle(); } + startTyping(chann){ + var self = this; + + this.resolveDestination(chann).then(next); + + function next(channel){ + if(self.typingIntervals[channel]){ + return; + } + + var fn = function(){ + console.log(`${Endpoints.CHANNELS}/${channel}/typing`); + request + .post(`${Endpoints.CHANNELS}/${channel}/typing`) + .set("authorization", self.token) + .end(); + }; + + fn(); + + var interval = setInterval(fn, 3000); + + self.typingIntervals[channel] = interval; + } + } + + stopTyping(chann){ + var self = this; + + this.resolveDestination(chann).then(next); + + function next(channel){ + if(!self.typingIntervals[channel]){ + return; + } + + clearInterval(self.typingIntervals[channel]); + + delete self.typingIntervals[channel]; + + } + } + setStatus(stat){ var idleTime = (stat === "online" ? null : Date.now()); diff --git a/test/bot.1.js b/test/bot.1.js index 131ac7322..464caec86 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -19,13 +19,13 @@ mybot.on("message", function (message) { var onlineUsers = 0; - mybot.setStatusIdle(); - - mybot.reply(message, onlineUsers); + mybot.startTyping(message.channel); setTimeout(function(){ - mybot.setStatusOnline(); - },5000); + mybot.reply(message, "stopping now k"); + mybot.stopTyping(message.channel); + }, 6000); + }); mybot.on("ready", function () { From 223753408c210ec8dce19018dbc474d560bc43e7 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 17:05:17 +0100 Subject: [PATCH 043/151] Added support for server unavailability it happened just now RIP discord server Date: Sun, 27 Sep 2015 17:05:31 +0100 Subject: [PATCH 044/151] 3.4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b9a82de25..9d7b3fc10 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.4.0", + "version": "3.4.1", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From bef49850640d704cc5327f5b9aa4c5122b077d9b Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 17:06:16 +0100 Subject: [PATCH 045/151] Removed debug info whoops --- lib/Client.js | 2 -- src/Client.js | 2 -- 2 files changed, 4 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index c6cbb5903..a885c6c28 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1430,7 +1430,6 @@ var Client = (function () { } self.startPM(destination).then(function (pmc) { - console.log(pmc); resolve(pmc.id); })["catch"](reject); } else { @@ -1685,7 +1684,6 @@ var Client = (function () { } var fn = function fn() { - console.log(Endpoints.CHANNELS + "/" + channel + "/typing"); request.post(Endpoints.CHANNELS + "/" + channel + "/typing").set("authorization", self.token).end(); }; diff --git a/src/Client.js b/src/Client.js index 58ad78c49..f6b8859d1 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1168,7 +1168,6 @@ class Client { //we don't, at this point we're late self.startPM(destination).then(function (pmc) { - console.log(pmc); resolve(pmc.id); }).catch(reject); @@ -1420,7 +1419,6 @@ class Client { } var fn = function(){ - console.log(`${Endpoints.CHANNELS}/${channel}/typing`); request .post(`${Endpoints.CHANNELS}/${channel}/typing`) .set("authorization", self.token) From 007977588698d3d7f2bb141de3f9d4346d3c39d6 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 17:06:27 +0100 Subject: [PATCH 046/151] 3.4.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9d7b3fc10..861d7fc72 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.4.1", + "version": "3.4.2", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From 5819fb4dafdf9343bfe2c1b2607a1591306446a6 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 17:17:03 +0100 Subject: [PATCH 047/151] Fixed unavailable message --- lib/Client.js | 4 +++- src/Client.js | 4 +++- test/bot.1.js | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index a885c6c28..ecacab82a 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -778,6 +778,8 @@ var Client = (function () { return; } + self.trigger("raw", dat); + //valid message switch (dat.t) { @@ -1150,7 +1152,7 @@ var Client = (function () { if (data.unavailable) { self.trigger("unavailable", data); - self.debug("Server ID" + +" has been marked unavailable by Discord. It was not cached."); + self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached."); return; } diff --git a/src/Client.js b/src/Client.js index f6b8859d1..483f9ec3d 100644 --- a/src/Client.js +++ b/src/Client.js @@ -760,6 +760,8 @@ class Client { return; } + self.trigger("raw", dat); + //valid message switch (dat.t) { @@ -1050,7 +1052,7 @@ class Client { if(data.unavailable){ self.trigger("unavailable", data); - self.debug("Server ID" + + " has been marked unavailable by Discord. It was not cached."); + self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached."); return; } diff --git a/test/bot.1.js b/test/bot.1.js index a79a36505..b615255c1 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -36,7 +36,7 @@ mybot.on("debug", function(info){ console.log(info); }) -mybot.on("unavailable", function(info){ +mybot.on("unknown", function(info){ console.log("warning!", info); }) From 5559809aff6943715b774302cab09c3116e04576 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 17:18:09 +0100 Subject: [PATCH 048/151] Added channel.topic --- lib/channel.js | 1 + src/channel.js | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/channel.js b/lib/channel.js index 17390e9e6..bb67fcf4f 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -11,6 +11,7 @@ var Channel = (function () { this.server = server; this.name = data.name; this.type = data.type; + this.topic = data.topic; this.id = data.id; this.messages = []; //this.isPrivate = isPrivate; //not sure about the implementation of this... diff --git a/src/channel.js b/src/channel.js index df266ba1c..a7185e17f 100644 --- a/src/channel.js +++ b/src/channel.js @@ -4,6 +4,7 @@ class Channel { this.server = server; this.name = data.name; this.type = data.type; + this.topic = data.topic; this.id = data.id; this.messages = []; //this.isPrivate = isPrivate; //not sure about the implementation of this... From 16d24104502cfbc7e4cd6a003306d9c7de90d4f2 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 17:37:46 +0100 Subject: [PATCH 049/151] Added setting of channel topics --- lib/Client.js | 38 +++++++++++++++++++++++++++++++++++++- src/Client.js | 42 ++++++++++++++++++++++++++++++++++++++++++ test/bot.1.js | 4 ++++ 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/lib/Client.js b/lib/Client.js index ecacab82a..32025062d 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1141,6 +1141,42 @@ var Client = (function () { } return this.getPMChannel("id", data.id); } + }, { + key: "setTopic", + value: function setTopic(channel, topic) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + + self.resolveDestination(channel).then(next)["catch"](error); + + function error(e) { + callback(e); + reject(e); + } + + function next(destination) { + + var asChan = self.getChannel("id", destination); + + request.patch(Endpoints.CHANNELS + "/" + destination).set("authorization", self.token).send({ + name: asChan.name, + position: 0, + topic: topic + }).end(function (err, res) { + if (err) { + error(err); + } else { + asChan.topic = res.body.topic; + resolve(); + callback(); + } + }); + } + }); + } //def addServer }, { @@ -1437,7 +1473,7 @@ var Client = (function () { } else { channId = destination; } - if (channId) resolve(channId); + if (channId) resolve(channId);else reject(); }); } }, { diff --git a/src/Client.js b/src/Client.js index 483f9ec3d..08a0ecbde 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1044,6 +1044,46 @@ class Client { return this.getPMChannel("id", data.id); } + setTopic(channel, topic, callback = function(err){}){ + + var self = this; + + return new Promise(function(resolve, reject){ + + self.resolveDestination(channel).then(next).catch(error); + + function error(e){ + callback(e); + reject(e); + } + + function next(destination){ + + var asChan = self.getChannel("id", destination); + + request + .patch(`${Endpoints.CHANNELS}/${destination}`) + .set("authorization", self.token) + .send({ + name : asChan.name, + position : 0, + topic : topic + }) + .end(function(err, res){ + if(err){ + error(err); + }else{ + asChan.topic = res.body.topic; + resolve(); + callback(); + } + }); + } + + }); + + } + //def addServer addServer(data) { @@ -1178,6 +1218,8 @@ class Client { } if (channId) resolve(channId); + else + reject(); }); } diff --git a/test/bot.1.js b/test/bot.1.js index b615255c1..1e425423f 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -30,6 +30,10 @@ mybot.on("message", function (message) { mybot.on("ready", function () { console.log("im ready"); + + for(var chann of mybot.channels){ + mybot.setTopic(chann, "HELLO I AM A BOT BOOP BOOP"); + } }); mybot.on("debug", function(info){ From c32f600a6aba46731bc5110306c9995961e453f2 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 17:54:03 +0100 Subject: [PATCH 050/151] Added channelUpdate listener --- lib/Client.js | 17 +++++++++++++++++ src/Client.js | 17 +++++++++++++++++ test/bot.1.js | 8 +++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/Client.js b/lib/Client.js index 32025062d..54ed14d17 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1105,6 +1105,23 @@ var Client = (function () { break; + case "CHANNEL_UPDATE": + + var channelInCache = self.getChannel("id", data.id), + serverInCache = self.getServer("id", data.guild_id); + + if (channelInCache && serverInCache) { + + var newChann = new Channel(data, serverInCache); + newChann.messages = channelInCache.messages; + + self.trigger("channelUpdate", channelInCache, newChann); + + self.channelCache[self.channelCache.indexOf(channelInCache)] = newChann; + } + + break; + default: self.debug("received unknown packet"); self.trigger("unknown", dat); diff --git a/src/Client.js b/src/Client.js index 08a0ecbde..67b36bd7d 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1009,6 +1009,23 @@ class Client { } break; + + case "CHANNEL_UPDATE": + + var channelInCache = self.getChannel("id", data.id), + serverInCache = self.getServer("id", data.guild_id); + + if(channelInCache && serverInCache){ + + var newChann = new Channel(data, serverInCache); + newChann.messages = channelInCache.messages; + + self.trigger("channelUpdate", channelInCache, newChann); + + self.channelCache[ self.channelCache.indexOf(channelInCache) ] = newChann; + } + + break; default: self.debug("received unknown packet"); diff --git a/test/bot.1.js b/test/bot.1.js index 1e425423f..03c507889 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -32,7 +32,7 @@ mybot.on("ready", function () { console.log("im ready"); for(var chann of mybot.channels){ - mybot.setTopic(chann, "HELLO I AM A BOT BOOP BOOP"); + mybot.setTopic(chann, "THINGS"); } }); @@ -44,6 +44,12 @@ mybot.on("unknown", function(info){ console.log("warning!", info); }) +mybot.on("channelUpdate", function(oldChan, newChan){ + + console.log(oldChan.topic + " vs " + newChan.topic); + +}); + function dump(msg) { console.log(msg); } From a70d6f9b32e91350d857a5464917e739c9b2ae4c Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 18:03:43 +0100 Subject: [PATCH 051/151] added parameter for optional stopTypeTime in startTyping --- lib/Client.js | 8 +++++++- src/Client.js | 8 +++++++- test/bot.1.js | 7 +------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 54ed14d17..d3d6f1f78 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1728,7 +1728,7 @@ var Client = (function () { } }, { key: "startTyping", - value: function startTyping(chann) { + value: function startTyping(chann, stopTypeTime) { var self = this; this.resolveDestination(chann).then(next); @@ -1747,6 +1747,12 @@ var Client = (function () { var interval = setInterval(fn, 3000); self.typingIntervals[channel] = interval; + + if (stopTypeTime) { + setTimeout(function () { + self.stopTyping(channel); + }, stopTypeTime); + } } } }, { diff --git a/src/Client.js b/src/Client.js index 67b36bd7d..ef51e2c42 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1469,7 +1469,7 @@ class Client { this.setStatusIdle(); } - startTyping(chann){ + startTyping(chann, stopTypeTime){ var self = this; this.resolveDestination(chann).then(next); @@ -1491,6 +1491,12 @@ class Client { var interval = setInterval(fn, 3000); self.typingIntervals[channel] = interval; + + if(stopTypeTime){ + setTimeout(function(){ + self.stopTyping(channel); + }, stopTypeTime); + } } } diff --git a/test/bot.1.js b/test/bot.1.js index 03c507889..4eb5ab07f 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -19,12 +19,7 @@ mybot.on("message", function (message) { var onlineUsers = 0; - mybot.startTyping(message.channel); - - setTimeout(function(){ - mybot.reply(message, "stopping now k"); - mybot.stopTyping(message.channel); - }, 6000); + mybot.startTyping(message.channel, 6000); }); From f4a7b2b07c5d439e08e1a292fce56486c098d2ff Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 18:16:14 +0100 Subject: [PATCH 052/151] 3.5.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 861d7fc72..d2500be5a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.4.2", + "version": "3.5.0", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From ffa415afdfced83a09a8e378f4049c165dcc4177 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 19:11:58 +0100 Subject: [PATCH 053/151] Updated doc index --- docs/index.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/index.rst b/docs/index.rst index 70b5f1698..d9c10260b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -13,10 +13,20 @@ run in node.js / io.js and in the browser. Contents: +.. _general-docs: + .. toctree:: + :caption: General + get_started troubleshooting create_simple_bot + +.. _docs: + +.. toctree:: + :caption: Documentation + docs_client From d581bf4d630b209a7cd7a781be5cc27b324a321c Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 19:19:15 +0100 Subject: [PATCH 054/151] Updated, testing something --- docs/docs_client.rst | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 382528cf9..50ed4ef34 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -1,6 +1,8 @@ Client Documentation ==================== +This page contains documentation on the `Discord.Client` class. This should be used when you want to start creating things with the API. + Attributes ---------- @@ -17,7 +19,11 @@ An `Object` containing a configuration for the Client. Currently can only be con token ~~~~~ -A `String` that is the token received after logging in. It is used to authorise the Client when joining WebSockets or making HTTP requests. +A `String` that is the token received after logging in. It is used to authorise the Client when joining WebSockets or making HTTP requests. Example token: + +.. code-block:: js + + ODAzTOc4MTA2BjQ2MjY4ODg.COmrCA.fEtD_Tc0JU6iZJU_11coEWBOQHE state ~~~~~ @@ -29,5 +35,17 @@ An `Integer` representing what state of connection the Client is in. - **3** is ready, meaning the Client is ready to begin listening. - **4** is disconnected, meaning the Client was disconnected due to any reason. +.. code-block:: js + + if( bot.state === 3 ) // ready to go + +user +~~~~ +A `User`_ object representing the user of the signed in client. + + + Functions ---------- \ No newline at end of file +--------- + +.. _User : #user \ No newline at end of file From 626f7eab6be22043c156dc644c6c670498da81fa Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 19:35:55 +0100 Subject: [PATCH 055/151] Finalised attributes on docs --- docs/docs_client.rst | 60 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 50ed4ef34..b6a5ec28e 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -35,17 +35,73 @@ An `Integer` representing what state of connection the Client is in. - **3** is ready, meaning the Client is ready to begin listening. - **4** is disconnected, meaning the Client was disconnected due to any reason. +See also ready_. + .. code-block:: js if( bot.state === 3 ) // ready to go user ~~~~ -A `User`_ object representing the user of the signed in client. +A `User`_ object representing the account of the signed in client. This will only be available when the client is in the ready state (3). +.. code-block:: js + bot.user.username; // username of the account logged in + +email +~~~~~ +A `String` that is the email used to sign the client in. + +password +~~~~~~~~ +A `String` that is the password used to sign the client in. + +readyTime +~~~~~~~~~ +A `Number` representing the unix timestamp from when the client was ready. `Null` if not yet ready. + +.. code-block:: js + + bot.readyTime; // 1443378242464 + +uptime +~~~~~~ +A `Number` representing how many milliseconds have passed since the client was ready. `Null` if not yet ready. + +.. code-block:: js + + if( bot.uptime > 5000 ) // true if the client has been up for more than 5 seconds + +ready +~~~~~ +A `Boolean` that is true if the client is ready. A shortcut to checking if ``bot.state === 3``. + +servers +~~~~~~~ +An `Array` of Server_ objects that the client has access to. Represents the servers the client is in. + +channels +~~~~~~~~ +An `Array` of Channel_ objects that the client has access to. Represents the channels the client can access. + +users +~~~~~ +An `Array` of User_ objects that the client has access to. + +PMChannels +~~~~~~~~~~ +An `Array` of PMChannel_ objects the client has access to. + +messages +~~~~~~~~ +An `Array` of Message_ objects the client has received over its uptime. Functions --------- -.. _User : #user \ No newline at end of file +.. _User : #user +.. _ready : #ready +.. _Server : #server +.. _Channel : #channel +.. _Message : #message \ No newline at end of file From d27638b421e513aa285ed35db5496f8c13e080f5 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 19:48:45 +0100 Subject: [PATCH 056/151] docs --- docs/docs_client.rst | 14 +++++--------- docs/docs_resolvable.rst | 9 +++++++++ docs/vars.rst | 5 +++++ 3 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 docs/docs_resolvable.rst create mode 100644 docs/vars.rst diff --git a/docs/docs_client.rst b/docs/docs_client.rst index b6a5ec28e..35c929cb7 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -1,3 +1,5 @@ +.. include:: ./vars.rst + Client Documentation ==================== @@ -79,11 +81,11 @@ A `Boolean` that is true if the client is ready. A shortcut to checking if ``bot servers ~~~~~~~ -An `Array` of Server_ objects that the client has access to. Represents the servers the client is in. +An `Array` of Server_ objects that the client has access to. channels ~~~~~~~~ -An `Array` of Channel_ objects that the client has access to. Represents the channels the client can access. +An `Array` of Channel_ objects that the client has access to. users ~~~~~ @@ -98,10 +100,4 @@ messages An `Array` of Message_ objects the client has received over its uptime. Functions ---------- - -.. _User : #user -.. _ready : #ready -.. _Server : #server -.. _Channel : #channel -.. _Message : #message \ No newline at end of file +--------- \ No newline at end of file diff --git a/docs/docs_resolvable.rst b/docs/docs_resolvable.rst new file mode 100644 index 000000000..cb6e14e71 --- /dev/null +++ b/docs/docs_resolvable.rst @@ -0,0 +1,9 @@ +Resolvable Documentation +======================== + +To be robust, discord.js needs to handle a wide amount of ambiguous data that is supplied to it. This means you can use functions much more easily. Anything that is resolvable means it can be normalised without you having to do it explicitly. + +Channel Resolvable +------------------ + +A Channel Resolvable is data that can be resolved to a channel ID. Here is what is currently supported: \ No newline at end of file diff --git a/docs/vars.rst b/docs/vars.rst new file mode 100644 index 000000000..f99759fb4 --- /dev/null +++ b/docs/vars.rst @@ -0,0 +1,5 @@ +.. _User : #user +.. _ready : #ready +.. _Server : #server +.. _Channel : #channel +.. _Message : #message \ No newline at end of file From 2f52ca50bf86e1c4f0f55147e7af9c85645fef44 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 20:02:41 +0100 Subject: [PATCH 057/151] MORE DOCUMENTATION KANYE BELIEVE IT --- docs/docs_resolvable.rst | 12 +++++++++++- docs/index.rst | 3 +++ docs/vars.rst | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/docs_resolvable.rst b/docs/docs_resolvable.rst index cb6e14e71..6fcbc2903 100644 --- a/docs/docs_resolvable.rst +++ b/docs/docs_resolvable.rst @@ -1,3 +1,5 @@ +.. include:: ./vars.rst + Resolvable Documentation ======================== @@ -6,4 +8,12 @@ To be robust, discord.js needs to handle a wide amount of ambiguous data that is Channel Resolvable ------------------ -A Channel Resolvable is data that can be resolved to a channel ID. Here is what is currently supported: \ No newline at end of file +A Channel Resolvable is data that can be resolved to a channel ID. Here is what is currently supported: + +- A Channel_ object +- A Server_ object (the #general channel of the server will be used) +- A String_ representing the channel ID +- A Message_ (the channel the message was sent in will be used) +- A User_ (will get the PM channel with the specified user) + +.. note:: A User cannot always be specified in certain cases. For example, if using `bot.setTopic`, a User or PM Channel can't be specified as these do not support channel topics. \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst index d9c10260b..c0e0451a6 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -16,6 +16,7 @@ Contents: .. _general-docs: .. toctree:: + :maxdepth: 2 :caption: General get_started @@ -25,9 +26,11 @@ Contents: .. _docs: .. toctree:: + :maxdepth: 2 :caption: Documentation docs_client + docs_resolvable diff --git a/docs/vars.rst b/docs/vars.rst index f99759fb4..2a45df682 100644 --- a/docs/vars.rst +++ b/docs/vars.rst @@ -2,4 +2,5 @@ .. _ready : #ready .. _Server : #server .. _Channel : #channel -.. _Message : #message \ No newline at end of file +.. _Message : #message +.. _PMChannel : #PMChannel \ No newline at end of file From 3e9a2bd3468e410f95ca44437ee8260b18689e0d Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 20:10:15 +0100 Subject: [PATCH 058/151] Started work on function --- docs/docs_client.rst | 14 +++++++++++++- docs/docs_resolvable.rst | 2 +- docs/vars.rst | 4 +++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 35c929cb7..d4377ad9a 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -100,4 +100,16 @@ messages An `Array` of Message_ objects the client has received over its uptime. Functions ---------- \ No newline at end of file +--------- + +.. note :: Any functions used here that take callbacks as an optional parameter can also be used as Promises_. For example, you can do: + +.. code-block:: js + + bot.login(email, password).then(success).catch(err); + + // OR use callbacks: + + bot.login(email, password, function(err, token){ + + }); \ No newline at end of file diff --git a/docs/docs_resolvable.rst b/docs/docs_resolvable.rst index 6fcbc2903..b52a358a5 100644 --- a/docs/docs_resolvable.rst +++ b/docs/docs_resolvable.rst @@ -12,7 +12,7 @@ A Channel Resolvable is data that can be resolved to a channel ID. Here is what - A Channel_ object - A Server_ object (the #general channel of the server will be used) -- A String_ representing the channel ID +- A `String` representing the channel ID - A Message_ (the channel the message was sent in will be used) - A User_ (will get the PM channel with the specified user) diff --git a/docs/vars.rst b/docs/vars.rst index 2a45df682..5aa029c1c 100644 --- a/docs/vars.rst +++ b/docs/vars.rst @@ -3,4 +3,6 @@ .. _Server : #server .. _Channel : #channel .. _Message : #message -.. _PMChannel : #PMChannel \ No newline at end of file +.. _PMChannel : #PMChannel +.. _Channel Resolvable : ./docs_resolvable.html#channel-resolvable +.. _Promises : https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise \ No newline at end of file From e0b9ab12da4fc4b940c7b5be9ad706c7f5a9be2e Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 20:11:38 +0100 Subject: [PATCH 059/151] Retest --- docs/docs_client.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index d4377ad9a..181032ab3 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -103,7 +103,6 @@ Functions --------- .. note :: Any functions used here that take callbacks as an optional parameter can also be used as Promises_. For example, you can do: - .. code-block:: js bot.login(email, password).then(success).catch(err); From 9cdd1d416e76b2a36c0ec32e77a0d2a63f6e7be5 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 20:17:54 +0100 Subject: [PATCH 060/151] Test --- docs/docs_client.rst | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 181032ab3..4ac734955 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -102,13 +102,34 @@ An `Array` of Message_ objects the client has received over its uptime. Functions --------- -.. note :: Any functions used here that take callbacks as an optional parameter can also be used as Promises_. For example, you can do: +.. note :: Any functions used here that take callbacks as an optional parameter can also be used as Promises_. Promises take the exact same parameters for each use case, except errors are moved to catch statements instead of then. For example, you can do: + .. code-block:: js bot.login(email, password).then(success).catch(err); + function success(token){ + + } + + function err(error){ + + } + // OR use callbacks: - bot.login(email, password, function(err, token){ + bot.login(email, password, function(error, token){ - }); \ No newline at end of file + }); + +----- + +login(email, password, `callback`) +~~~~~ + +``Parameters``: +- `email` - A `String` which is the email you want to sign in with. +- `password` - A `String` which is the password you want to sign in with. +- `callback` - A `function` that can take the following parameters: + - `error` - null if there was no error, otherwise it is set. + - `token` - if successful, it is the received authorisation token. \ No newline at end of file From f10895680f4ef447892c25488040cc2322434e65 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 20:19:12 +0100 Subject: [PATCH 061/151] welp try to fix --- docs/docs_client.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 4ac734955..a2d1b4228 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -127,9 +127,11 @@ Functions login(email, password, `callback`) ~~~~~ -``Parameters``: +`Parameters`: + - `email` - A `String` which is the email you want to sign in with. - `password` - A `String` which is the password you want to sign in with. - `callback` - A `function` that can take the following parameters: + - `error` - null if there was no error, otherwise it is set. - `token` - if successful, it is the received authorisation token. \ No newline at end of file From 9588f5cbf5ec17b65910b3a64fb0f25f9188dd7a Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 20:21:22 +0100 Subject: [PATCH 062/151] doc formatting test --- docs/docs_client.rst | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index a2d1b4228..3a900dd7a 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -125,13 +125,12 @@ Functions ----- login(email, password, `callback`) -~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `Parameters`: -- `email` - A `String` which is the email you want to sign in with. -- `password` - A `String` which is the password you want to sign in with. -- `callback` - A `function` that can take the following parameters: - - - `error` - null if there was no error, otherwise it is set. - - `token` - if successful, it is the received authorisation token. \ No newline at end of file +- **email** - A `String` which is the email you want to sign in with. +- **password** - A `String` which is the password you want to sign in with. +- **callback** - A `function` that can take the following parameters: + - **error** - null if there was no error, otherwise it is set. + - **token** - if successful, it is the received authorisation token. \ No newline at end of file From 66840c6a27e40f39ca16897f570e85af47954c87 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 27 Sep 2015 20:26:53 +0100 Subject: [PATCH 063/151] more docs --- docs/docs_client.rst | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 3a900dd7a..376d6e964 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -127,10 +127,20 @@ Functions login(email, password, `callback`) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -`Parameters`: +Logs the client in to set it up. Use this after registering your event listeners to ensure they are called. - **email** - A `String` which is the email you want to sign in with. - **password** - A `String` which is the password you want to sign in with. - **callback** - A `function` that can take the following parameters: + - **error** - null if there was no error, otherwise it is set. - - **token** - if successful, it is the received authorisation token. \ No newline at end of file + - **token** - if successful, it is the received authorisation token. + +logout(`callback`) +~~~~~~~~~~~~~~~~~~ + +Logs the client out if it is logged in. If successful, ``bot.state == 4``. + +- **callback** - A `function` that can take the following parameters: + + - **error** - null if there was no error, otherwise it is set. \ No newline at end of file From afb2a66fe2b2ac1df2a5d889dbd2b9dfc558d8a9 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Mon, 28 Sep 2015 17:05:02 +0100 Subject: [PATCH 064/151] Added createServer to documentation --- docs/docs_client.rst | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 376d6e964..9b4064aab 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -133,7 +133,7 @@ Logs the client in to set it up. Use this after registering your event listeners - **password** - A `String` which is the password you want to sign in with. - **callback** - A `function` that can take the following parameters: - - **error** - null if there was no error, otherwise it is set. + - **error** - An error if one occurred, otherwise it is null. - **token** - if successful, it is the received authorisation token. logout(`callback`) @@ -143,4 +143,18 @@ Logs the client out if it is logged in. If successful, ``bot.state == 4``. - **callback** - A `function` that can take the following parameters: - - **error** - null if there was no error, otherwise it is set. \ No newline at end of file + - **error** - An error if one occurred, otherwise it is null. + +createServer(name, region, `callback`) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Creates a server with the specified name or region. See valid regions below: + +- **name** - A `String` that will be the name of your server. +- **region** - A `String` that is a valid Discord region. Currently **``us-west``**, **``us-east``**, **``singapore``**, **``london``**, **``sydney``** or **``amsterdam``**. Providing an invalid region will result in an error. To find the latest available regions, check the `official API here`_. +- **callback** - A `function` that can take the following parameters: + + - **error** - An error if one occurred, otherwise it is null. + - **server** - A Server_ that represents the created Server. + +.. _official API here : https://discordapp.com/api/voice/regions \ No newline at end of file From 00083e96edd07513b18bc39bf3afb8c9c93211ee Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Mon, 28 Sep 2015 17:23:24 +0100 Subject: [PATCH 065/151] more documentation --- docs/docs_client.rst | 48 +++++++++++++++++++++++++++++++++++++++- docs/docs_resolvable.rst | 10 ++++++++- docs/vars.rst | 2 ++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 9b4064aab..84be2e411 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -151,10 +151,56 @@ createServer(name, region, `callback`) Creates a server with the specified name or region. See valid regions below: - **name** - A `String` that will be the name of your server. -- **region** - A `String` that is a valid Discord region. Currently **``us-west``**, **``us-east``**, **``singapore``**, **``london``**, **``sydney``** or **``amsterdam``**. Providing an invalid region will result in an error. To find the latest available regions, check the `official API here`_. +- **region** - A `String` that is a valid Discord region. Currently **us-west**, **us-east**, **singapore**, **london**, **sydney** or **amsterdam**. Providing an invalid region will result in an error. To find the latest available regions, check the `official API here`_. - **callback** - A `function` that can take the following parameters: - **error** - An error if one occurred, otherwise it is null. - **server** - A Server_ that represents the created Server. + +joinServer(invite, `callback`) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Accepts a given invite to join a server. The server is automatically cached ASAP. + +- **invite** - An `Invite Resolvable`_ which is the invite that should be accepted. +- **callback** - A `function` that can take the following parameters: + + - **error** - An error if one occurred, otherwise it is null. + - **server** - A Server_ that represents the joined Server. + +leaveServer(server, `callback`) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Leaves the given server. + +- **server** - A `Server Resolvable`_ that represents the server you want to leave. +- **callback** - A `function` that can take the following parameters: + + - **error** - An error if one occurred, otherwise it is null. + +createInvite(channel, options, `callback`) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Creates an invite for the given channel and returns an Invite_. + +- **channel** - A `Channel Resolvable`_ that is the channel you want to create an invite for. +- **options** - An `object` containing configurable options for the invite. See below for possible configurations. +- **callback** - A `function` that can take the following parameters: + + - **error** - An error if one occurred, otherwise it is null. + - **invite** - An Invite_ object that contains the details about the created invite. + +.. code-block:: js + + // default configuration of the options variable: + + options = { + max_age : 0, //A number signifying the expiry time for the invite. 0 means infinite. + max_uses : 0, //A number signifying the amount of uses of the invite. 0 means infinite. + temporary : false, //boolean - whether users who use it are kicked unless promoted within 24h. + xkcd : false //boolean - whether the invite's URL should be human-readable + } + + .. _official API here : https://discordapp.com/api/voice/regions \ No newline at end of file diff --git a/docs/docs_resolvable.rst b/docs/docs_resolvable.rst index b52a358a5..ebd1f2211 100644 --- a/docs/docs_resolvable.rst +++ b/docs/docs_resolvable.rst @@ -5,6 +5,8 @@ Resolvable Documentation To be robust, discord.js needs to handle a wide amount of ambiguous data that is supplied to it. This means you can use functions much more easily. Anything that is resolvable means it can be normalised without you having to do it explicitly. +Resolvables are not objects or classes, they are just ways of expressing what type of data is expected. + Channel Resolvable ------------------ @@ -16,4 +18,10 @@ A Channel Resolvable is data that can be resolved to a channel ID. Here is what - A Message_ (the channel the message was sent in will be used) - A User_ (will get the PM channel with the specified user) -.. note:: A User cannot always be specified in certain cases. For example, if using `bot.setTopic`, a User or PM Channel can't be specified as these do not support channel topics. \ No newline at end of file +.. note:: A User cannot always be specified in certain cases. For example, if using `bot.setTopic`, a User or PM Channel can't be specified as these do not support channel topics. + +Server Resolvable +----------------- + +Invite Resolvable +----------------- \ No newline at end of file diff --git a/docs/vars.rst b/docs/vars.rst index 5aa029c1c..60e2bc533 100644 --- a/docs/vars.rst +++ b/docs/vars.rst @@ -4,5 +4,7 @@ .. _Channel : #channel .. _Message : #message .. _PMChannel : #PMChannel +.. _Invite : #invite .. _Channel Resolvable : ./docs_resolvable.html#channel-resolvable +.. _Invite Resolvable : ./docs_resolvable.html#invite-resolvable .. _Promises : https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise \ No newline at end of file From 7f124f68db6da2bcf2689ab8bcf6f64f80dae7f8 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Mon, 28 Sep 2015 18:10:11 +0100 Subject: [PATCH 066/151] more more more docs --- docs/docs_client.rst | 96 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 84be2e411..3b2c0517a 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -201,6 +201,100 @@ Creates an invite for the given channel and returns an Invite_. xkcd : false //boolean - whether the invite's URL should be human-readable } - +createChannel(server, channelName, channelType, `callback`) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Creates a channel in the given server. + +- **server** - A `Server Resolvable`_ that will be the server the channel is created in. +- **channelName** - A `String` that is the name of the channel. +- **channelType** - A `String` that is the type of the channel, either **voice** or **text**. +- **callback** - A `function` that can take the following parameters: + + - **error** - An error if one occurred, otherwise it is null. + - **channel** - An Channel_ object that represents the created channel. + +deleteChannel(channel, `callback`) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Deletes the specified channel. + +- **channel** - A `Channel Resolvable`_ that will be the channel to delete. +- **callback** - A `function` that can take the following parameters: + + - **error** - An error if one occurred, otherwise it is null. + +getChannelLogs(channel, `amount`, `callback`) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Gets previous messages from the specified channel. + +- **channel** - A `Channel Resolvable`_ to take logs from. +- **amount** - A `Number` that defaults to **500**. This is the amount of messages to try and get. +- **callback** - A `function` that can take the following parameters: + + - **error** - An error if one occurred, otherwise it is null. + - **logs** - An `Array` of Message_ objects that represent the previous messages. + +.. warning:: If the logs contain messages from a user who is no longer in the server, the user object *MAY* be malformed. + +sendMessage(channel, message, `callback`) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Sends a message to the specified channel. + +- **channel** - A `Channel Resolvable`_ to send the message to. +- **message** - A `String` or an Array of strings. If an Array, the array will be joined with a new line as a delimiter and this will be the message to be sent. +- **callback** - A `function` that can take the following parameters: + + - **error** - An error if one occurred, otherwise it is null. + - **message** - A Message_ representing the sent message. + +sendFile(channel, file, `fileName`, `callback`) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Sends a file to the specified channel. Note that **fileName is necessary in certain cases** for when a file other than an image is sent. For example, if you send a file containing JS code, fileName should be something like ``myCode.js``. + +- **channel** - A `Channel Resolvable`_ to send the file to. +- **file** - The file to send, either a `Buffer` or `String` - if a String, it should be a relative (`./`) or absolute path to a file. +- **fileName** - A `String` containing the file's name and extension, used by Discord (I didn't make this please don't shoot me :s) Examples include `picture.png`, `text.txt`, `wowanamazingscript.js` + +- **callback** - A `function` that can take the following parameters: + + - **error** - An error if one occurred, otherwise it is null. + - **message** - A Message_ representing the sent file. + +updateMessage(message, content, `callback`) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Updates/edits a message with new content. + +- **message** - A Message_ that should be updated. +- **content** - A `String` or an Array of strings. If an Array, the array will be joined with a new line as a delimiter and this will be the message to be sent. +- **callback** - A `function` that can take the following parameters: + + - **error** - An error if one occurred, otherwise it is null. + - **message** - A Message_ representing the updated message. + +reply(message, yourMessage, `callback`) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Alias for sendMessage, but prepends a mention to whoever sent the specified mention. Useful shortcut for directing a message at a user. + +.. code-block:: js + + // example usage: + + the user 'bob' sent a message + + bot.reply(message, "hello"); + // will send the message '@bob, hello' to the channel the message that bob sent was in. + +- **message** - A Message_ that should be replied to. +- **yourMessage** - A `String` or an Array of strings. If an Array, the array will be joined with a new line as a delimiter and this will be the message to be sent. +- **callback** - A `function` that can take the following parameters: + + - **error** - An error if one occurred, otherwise it is null. + - **message** - A Message_ representing the sent message. .. _official API here : https://discordapp.com/api/voice/regions \ No newline at end of file From d318620b2d7c7cfd0166e6b65235ba9d2099bc6b Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Mon, 28 Sep 2015 18:42:51 +0100 Subject: [PATCH 067/151] Documentation is so fun /s --- docs/docs_client.rst | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 3b2c0517a..263a3d82f 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -296,5 +296,60 @@ Alias for sendMessage, but prepends a mention to whoever sent the specified ment - **error** - An error if one occurred, otherwise it is null. - **message** - A Message_ representing the sent message. + +setUsername(newName, `callback`) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Sets the username of the logged in client. + +- **newName** - The new name of the client, a `String`. +- **callback** - A `function` that can take the following parameters: + + - **error** - An error if one occurred, otherwise it is null. + +startTyping(channel, *stopTime*) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Makes the client appear to be typing in the specified channel. + +- **channel** - A `Channel Resolvable`_ that should be the channel to start typing in +- **stopTime** - A `Number` in ms which should make the client stop typing after. Allow 5 seconds. + +stopTyping(channel) +~~~~~~~~~~~~~~~~~~~ + +Makes the client stop typing in a specified channel. + +- **channel** - A `Channel Resolvable`_ that should be the channel to stop typing in. + +setStatusOnline() +~~~~~~~~~~~~~~~~~ + +**Aliases**: ``setStatusActive()`` and ``setStatusHere()`` + +Sets the client's status to online; green. + +setStatusIdle() +~~~~~~~~~~~~~~~~~ + +**Aliases**: ``setStatusAway()`` + +Sets the client's status to idle; orange. + +setTopic(channel, topic, `callback`) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Sets the topic of the specified channel + +- **channel** - A `Channel Resolvable`_ that is the channel you want to change the topic of +- **topic** - A `String` that is the topic you want +- **callback** - A `function` that can take the following parameters: + + - **error** - An error if one occurred, otherwise it is null. + +----- + +Events +------ .. _official API here : https://discordapp.com/api/voice/regions \ No newline at end of file From 9a3916428f8e62e908625db9fc4458dd61ef55f8 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Mon, 28 Sep 2015 18:47:53 +0100 Subject: [PATCH 068/151] finalised function doc --- docs/docs_client.rst | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 263a3d82f..916f8dc37 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -347,6 +347,56 @@ Sets the topic of the specified channel - **error** - An error if one occurred, otherwise it is null. +getUser(key, value) +~~~~~~~~~~~~~~~~~~~ + +Gets a User_ that matches the specified criteria. E.g: + +.. code-block:: js + + bot.getUser("id", 1243987349) // returns a user where user.id === 1243987349 + +- **key** - a `String` that is the key +- **value** - a `String` that is the value + +getServer(key, value) +~~~~~~~~~~~~~~~~~~~~~ + +Gets a Server_ that matches the specified criteria. E.g: + +.. code-block:: js + + bot.getServer("id", 1243987349) // returns a server where server.id === 1243987349 + +- **key** - a `String` that is the key +- **value** - a `String` that is the value + + +getChannel(key, value) +~~~~~~~~~~~~~~~~~~~~~~ + +Gets a Channel_ that matches the specified criteria. E.g: + +.. code-block:: js + + bot.getChannel("id", 1243987349) // returns a Channel where channel.id === 1243987349 + +- **key** - a `String` that is the key +- **value** - a `String` that is the value + + +getPMChannel(key, value) +~~~~~~~~~~~~~~~~~~~~~~~~ + +Gets a PMChannel_ that matches the specified criteria. E.g: + +.. code-block:: js + + bot.getPMChannel("id", 1243987349) // returns a PMChannel where pmchannel.id === 1243987349 + +- **key** - a `String` that is the key +- **value** - a `String` that is the value + ----- Events From 04fc4ce64898042a30ab17cfdb1ede193cecfeb8 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Mon, 28 Sep 2015 18:52:57 +0100 Subject: [PATCH 069/151] working on events --- docs/docs_client.rst | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 916f8dc37..b03ae01cd 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -399,7 +399,33 @@ Gets a PMChannel_ that matches the specified criteria. E.g: ----- -Events ------- +Event Management +---------------- + +Events are a useful way of listening to events and are available in every API. + +Registering Events +~~~~~~~~~~~~~~~~~~ + +.. code-block:: js + + bot.on("eventName", function(arg1, arg2...){ + // code here is called when eventName is emitted. + }) + +.. note:: You can only have one listening function per event + +Unregistering Events +~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: js + + bot.off("eventName") + // eventName is no longer listened for + +Event Types +----------- + + .. _official API here : https://discordapp.com/api/voice/regions \ No newline at end of file From 74a3cdcadec4604433fd3d9b92c22207027adf1d Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Mon, 28 Sep 2015 19:01:59 +0100 Subject: [PATCH 070/151] event docs --- docs/docs_client.rst | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index b03ae01cd..8a43c6d5a 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -426,6 +426,56 @@ Unregistering Events Event Types ----------- +ready +~~~~~ +Called when the bot is ready and you can begin working with it. + +disconnected +~~~~~~~~~~~~ + +Called when the bot is disconnected for whatever reason. + +error +~~~~~ + +Called whenever there is an error. + +**Parameters** + +- **error** - the encountered error + +.. note:: There may be more parameters supplied depending on the errors. Use the ``arguments`` variable to check for this for advanced debugging. + +debug +~~~~~ + +Called when the client debugs some information that might be useful for a developer but not for an end user. + +**Parameters** + +- **message** - the debug message as a `String` + +message +~~~~~~~ + +Called when a message has been received by the client. + +**Parameters** + +- **message** - the received Message_. + +messageDelete +~~~~~~~~~~~~~ + +Called when a message has been deleted. + +**Parameters** + +- **channel** - The Channel_ that the deleted message was in. +- ***message*** - *May* be available. If the message wasn't previously cached, this will not be supplied and all you would know is that a message was deleted in the channel. If it is available, it will be in the format of a Message_. + +messageUpdate +~~~~~~~~~~~~~ .. _official API here : https://discordapp.com/api/voice/regions \ No newline at end of file From ec6108a230b9dc86b752ab0fa6a6fc6945c8e936 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Mon, 28 Sep 2015 20:34:07 +0100 Subject: [PATCH 071/151] CLIENT DOCS ARE DONE WOO --- docs/docs_client.rst | 107 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 8a43c6d5a..5774dfe53 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -473,9 +473,114 @@ Called when a message has been deleted. **Parameters** - **channel** - The Channel_ that the deleted message was in. -- ***message*** - *May* be available. If the message wasn't previously cached, this will not be supplied and all you would know is that a message was deleted in the channel. If it is available, it will be in the format of a Message_. +- **message** - *May* be available. If the message wasn't previously cached, this will not be supplied and all you would know is that a message was deleted in the channel. If it is available, it will be in the format of a Message_. messageUpdate ~~~~~~~~~~~~~ +Called when a message has been updated. + +**Parameters** + +- **newMessage** - The updated Message_. +- **oldMessage** - The old Message_ before it was updated. + +serverDelete +~~~~~~~~~~~~ + +Called when a server is deleted. + +**Parameters** + +- **server** - The deleted Server_. + +channelDelete +~~~~~~~~~~~~~ + +Called when a channel is deleted. + +**Parameters** + +- **channel** - The deleted Channel_. + +serverCreate +~~~~~~~~~~~~ + +Called when a server is created/joined. + +**Parameters** + +- **server** - The created Server_. + +channelCreate +~~~~~~~~~~~~ + +Called when a channel is created. + +**Parameters** + +- **channel** - The created Channel_. + +serverNewMember +~~~~~~~~~~~~~~~ + +Called when a new member is added to a server. + +**Parameters** + +- **user** - The User_ that was added. +- **server** - The Server_ that the user was added to. + +serverRemoveMember +~~~~~~~~~~~~~~~~~~ + +Called when a member of a server leaves or is kicked out. + +**Parameters** + +- **user** - The User_ that was removed. +- **server** - The Server_ that the user was removed from. + +userUpdate +~~~~~~~~~~ + +Called when information about a user changes, such as their username. + +**Parameters** + +- **newUser** - A User_ object representing the changes to the old user (this will be in the cache) +- **oldUser** - A User_ object representing the user before the update. + +presence +~~~~~~~~ + +Called when a user goes online/offline/away or starts/stops playing a game. + +**Parameters** + +- **dataObject** - Instead of separate arguments, presence update takes an object containing the following information: + + - **user** - A User_ representing the User that had a presence update + - **status** - The status change as a `String`. + - **server** - The Server_ that the presence change occurred in. + - **gameId** - A `Number` representing the game they are playing if any. Currently, discord.js has no internal support for converting this into a game name. + +unknown +~~~~~~~ + +Called when an unknown packet was received or there is no handler for it. + +**Parameters** + +- **data** - A `JSON Object` which is the message received over WebSocket. + +raw +~~~ + +Called when a WebSocket message is received and it gives you the message. + +**Parameters** + +- **data** - A `JSON Object` which is the message received over WebSocket. + .. _official API here : https://discordapp.com/api/voice/regions \ No newline at end of file From 274d61a0616a37d1422e7d2b9cf3f1baef778791 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Mon, 28 Sep 2015 20:37:18 +0100 Subject: [PATCH 072/151] client docs --- docs/docs_client.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 5774dfe53..4c0f19cae 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -5,6 +5,8 @@ Client Documentation This page contains documentation on the `Discord.Client` class. This should be used when you want to start creating things with the API. +It might be beneficial to use CTRL+F to search for what you're looking for, or use the navigation provided by readthedocs on the left. + Attributes ---------- From 32f6f31cdff0b2ae96d5cbcb32c5a92768ddc959 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Mon, 28 Sep 2015 20:48:41 +0100 Subject: [PATCH 073/151] Added user documentation --- docs/docs_user.rst | 67 ++++++++++++++++++++++++++++++++++++++++++++++ docs/index.rst | 3 ++- docs/vars.rst | 2 +- 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 docs/docs_user.rst diff --git a/docs/docs_user.rst b/docs/docs_user.rst new file mode 100644 index 000000000..70cf51b2d --- /dev/null +++ b/docs/docs_user.rst @@ -0,0 +1,67 @@ +.. include:: ./vars.rst + +User Documentation +================== + +The User Class is used to represent data about users. + +Attributes +---------- + +username +~~~~~~~~ + +A `String` that is the username of the user. + +discriminator +~~~~~~~~~~~~~ + +Used to differentiate users with the same username, provided by Discord. If you want to differentiate users, we'd recommend using the `id` attribute. + +id +~~ + +A `String` UUID of the user, will never change. + +avatar +~~~~~~ + +A `String` that is the user's avatar's ID, or if they don't have one this is `null`. + +avatarURL +~~~~~~~~~ + +A `String` that points to the user's avatar's URL, or if they don't have an avatar this is `null`. + +status +~~~~~~ + +The status of the user as a `String`; offline/online/idle. + +----- + +Functions +--------- + +mention() +~~~~~~~~~ + +Returns a `String`. This function will generate the mention string for the user, which when sent will preview as a mention. E.g: + +.. code-block:: js + + user.mention(); // something like <@3245982345035> + +This is mainly used internally by the API to correct mentions when sending messages, however you can use it. + +.. note:: You can also just concatenate a User object with strings to get the mention code, as the `toString()` method points to this. This is useful when sending messages. + +equals(object) +~~~~~~~~~~~~~~ + +Returns a `Boolean` depending on whether the User's ID (``user.id``) equals the object's ID (``object.id``). You should **always**, always use this if you want to compare users. **NEVER** do ``user1 == user2``. + +equalsStrict(object) +~~~~~~~~~~~~~~~~~~~~ + +Sees if the supplied object has the same username, ID, avatar and discriminator of the user. Mainly used internally. Returns a `Boolean` depending on the result. diff --git a/docs/index.rst b/docs/index.rst index c0e0451a6..afcd0cfd1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -29,8 +29,9 @@ Contents: :maxdepth: 2 :caption: Documentation - docs_client docs_resolvable + docs_client + docs_user diff --git a/docs/vars.rst b/docs/vars.rst index 60e2bc533..a0b315c9a 100644 --- a/docs/vars.rst +++ b/docs/vars.rst @@ -1,4 +1,4 @@ -.. _User : #user +.. _User : ./docs_user.html .. _ready : #ready .. _Server : #server .. _Channel : #channel From f36e61ac2a263fe8fdfabff037de425fba62c160 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Mon, 28 Sep 2015 20:59:53 +0100 Subject: [PATCH 074/151] Added equals object to documentation, counting as a minor --- docs/docs_server.rst | 107 +++++++++++++++++++++++++++++++++++++++++++ docs/index.rst | 1 + docs/vars.rst | 3 +- src/server.js | 4 ++ 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 docs/docs_server.rst diff --git a/docs/docs_server.rst b/docs/docs_server.rst new file mode 100644 index 000000000..0baa9d331 --- /dev/null +++ b/docs/docs_server.rst @@ -0,0 +1,107 @@ +.. include:: ./vars.rst + +Server Documentation +================== + +The Server Class is used to represent data about a server. + +Attributes +---------- + +client +~~~~~~ + +The Discord Client_ that the Server was cached by. + +region +~~~~~~ + +The region that the server is in, a `String`. + +name +~~~~ + +The server's name, as a `String`. + +id +~~ + +The server's id, as a `String`. + +members +~~~~~~~ + +**Aliases** : `users` + +The members in a server, an `Array` of User_ objects. + +channels +~~~~~~~~ + +The channels in a server, an `Array` of Channel_ objects. + +icon +~~~~ + +The icon ID of the server if it has one as a `String`, otherwise it is `null`. + +iconURL +~~~~~~~ + +A `String` that is the URL of the server icon if it has one, otherwise it is `null`. + +afkTimeout +~~~~~~~~~~ + +A `Number` that is the AFK Timeout of the Server. + +afkChannel +~~~~~~~~~~ + +A Channel_ that represents the AFK Channel of the server if it has one, otherwise it is `null`. + +defaultChannel +~~~~~~~~~~~~~~ + +The **#general** Channel_ of the server. + +owner +~~~~~ + +A User_ object representing the user that owns the server. + +----- + +Functions +--------- + +.. note:: When concatenated with a String, the object will become the server's name, e.g. ``"this is " + server`` would be ``this is Discord API`` if the server was called `Discord API`. + +getChannel(key, value) +~~~~~~~~~~~~~~~~~~~~~~ + +Gets a Channel_ that matches the specified criteria. E.g: + +.. code-block:: js + + server.getChannel("id", 1243987349) // returns a Channel where channel.id === 1243987349 + +- **key** - a `String` that is the key +- **value** - a `String` that is the value + +getMember(key, value) +~~~~~~~~~~~~~~~~~~~~~ + +Gets a User_ that matches the specified criteria. E.g: + +.. code-block:: js + + bot.getUser("id", 1243987349) // returns a user where user.id === 1243987349 + +- **key** - a `String` that is the key +- **value** - a `String` that is the value + +equals(object) +~~~~~~~~~~~~~~ + +Returns a `Boolean` depending on whether the Server's ID (``server.id``) equals the object's ID (``object.id``). You should **always**, always use this if you want to compare servers. **NEVER** do ``server1 == server2``. diff --git a/docs/index.rst b/docs/index.rst index afcd0cfd1..4db5e17e2 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -32,6 +32,7 @@ Contents: docs_resolvable docs_client docs_user + docs_server diff --git a/docs/vars.rst b/docs/vars.rst index a0b315c9a..ef98675e4 100644 --- a/docs/vars.rst +++ b/docs/vars.rst @@ -1,6 +1,7 @@ +.. _Client : ./docs_client.html .. _User : ./docs_user.html .. _ready : #ready -.. _Server : #server +.. _Server : ./docs_server.html .. _Channel : #channel .. _Message : #message .. _PMChannel : #PMChannel diff --git a/src/server.js b/src/server.js index c0f24af27..d0d56578c 100644 --- a/src/server.js +++ b/src/server.js @@ -92,6 +92,10 @@ class Server { toString(){ return this.name; } + + equals(object){ + return object.id === this.id; + } } module.exports = Server; \ No newline at end of file From 751eb9095d3112f2f0ca1f06e6e6f53a3f4a26c5 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Mon, 28 Sep 2015 21:00:18 +0100 Subject: [PATCH 075/151] 3.6.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d2500be5a..458024ac2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.5.0", + "version": "3.6.0", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From 55f4e33ada354f796c80ff3472190e6a2404d900 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Tue, 29 Sep 2015 17:26:33 +0100 Subject: [PATCH 076/151] Added channel documentation --- docs/docs_channel.rst | 75 +++++++++++++++++++++++++++++++++++++++++++ docs/index.rst | 1 + docs/vars.rst | 2 +- 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 docs/docs_channel.rst diff --git a/docs/docs_channel.rst b/docs/docs_channel.rst new file mode 100644 index 000000000..b81ee763f --- /dev/null +++ b/docs/docs_channel.rst @@ -0,0 +1,75 @@ +.. include:: ./vars.rst + +Channel Documentation +===================== + +The Channel Class is used to represent data about a Channel. + +Attributes +---------- + +client +~~~~~~ + +The Discord Client_ that cached the channel + +server +~~~~~~ + +The Server_ that the channel belongs to + +name +~~~~ + +The channel's name, as a `String`. + +id +~~ + +The channel's id, as a `String`. + +type +~~~~ + +The type of the channel as a `String`, either ``text`` or ``voice``. + +topic +~~~~~ + +A `String` that is the topic of the channel, if the channel doesn't have a topic this will be `null`. + +messages +~~~~~~~~ + +An `Array` of Message_ objects received from the channel. There are up to a 1000 messages here, and the older messages will be deleted if necessary. + +members +~~~~~~~ + +**Aliases** : `users` + +The members in the channel's server, an `Array` of User_ objects. + +----- + +Functions +--------- + +.. note:: When concatenated with a String, the object will become the channel's embed code, e.g. ``"this is " + channel`` would be ``this is <#channelid>`` + +getMessage(key, value) +~~~~~~~~~~~~~~~~~~~~~~ + +Gets a Message_ from the channel that matches the specified criteria. E.g: + +.. code-block:: js + + channel.getMessage("id", 1243987349) // returns a Channel where message.id === 1243987349 + +- **key** - a `String` that is the key +- **value** - a `String` that is the value + +equals(object) +~~~~~~~~~~~~~~ + +Returns a `Boolean` depending on whether the Channel's ID (``channel.id``) equals the object's ID (``object.id``). You should **always**, always use this if you want to compare channels. **NEVER** do ``channel1 == channel2``. diff --git a/docs/index.rst b/docs/index.rst index 4db5e17e2..2b08bfcca 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -33,6 +33,7 @@ Contents: docs_client docs_user docs_server + docs_channel diff --git a/docs/vars.rst b/docs/vars.rst index ef98675e4..7a59d8007 100644 --- a/docs/vars.rst +++ b/docs/vars.rst @@ -2,7 +2,7 @@ .. _User : ./docs_user.html .. _ready : #ready .. _Server : ./docs_server.html -.. _Channel : #channel +.. _Channel : ./docs_channel.html .. _Message : #message .. _PMChannel : #PMChannel .. _Invite : #invite From d50d8907d0ac28fb1fd743b3ad7aa8536e29bc8e Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Tue, 29 Sep 2015 17:45:29 +0100 Subject: [PATCH 077/151] Added message documentation --- docs/docs_message.rst | 84 +++++++++++++++++++++++++++++++++++++++++++ docs/index.rst | 1 + docs/vars.rst | 2 +- 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 docs/docs_message.rst diff --git a/docs/docs_message.rst b/docs/docs_message.rst new file mode 100644 index 000000000..7dbbbfc3d --- /dev/null +++ b/docs/docs_message.rst @@ -0,0 +1,84 @@ +.. include:: ./vars.rst + +Message Documentation +===================== + +The Message Class is used to represent data about a Message. + +Attributes +---------- + +tts +~~~ + +A `Boolean` that is ``true`` if the sent message was text-to-speech, otherwise ``false``. + +timestamp +~~~~~~~~~ + +A `unix timestamp` as a `Number` representing when the message was sent. + +mentions +~~~~~~~~ + +An `Array` of User_ objects that represent the users mentioned in the message. + +everyoneMentioned +~~~~~~~~~~~~~~~~~ + +A `Boolean` that is ``true`` if **@everyone** was used, otherwise ``false``. + +id +~~ + +A `String` UUID of the message, will never change. + +.. note:: Currently, message IDs are totally unique. However, in the future they may only be unique within a channel. Make sure to check periodically whether this has changed. + +embeds +~~~~~~ + +A raw, unhandled `JSON object` that will contain embeds of the message - if any. + +editedTimestamp +~~~~~~~~~~~~~~~ + +A `unix timestamp` as a `Number` that is when the message was last edited. + +content +~~~~~~~ + +The actual content of the message as a `String`. + +channel +~~~~~~~ + +The Channel_ that the message was sent in. + +author +~~~~~~ + +**Aliases** : `sender` + +The User_ that sent the message. + +attachments +~~~~~~~~~~~ + +A raw, unhandled `JSON object` that will contain attachments of the message - if any. + +isPrivate +~~~~~~~~~ + +A `Boolean` that is ``true`` if the message was sent in a PM / DM chat, or if it was sent in a group chat it will be ``false``. + +Functions +--------- + +isMentioned(user) +~~~~~~~~~~~~~~~~~ + +A `Boolean` that will return ``true`` if the specified user was mentioned in the message. If everyone is mentioned, this will be false - this function checks specifically for if they were mentioned. + + +- **user** - The User_ that you want to see is mentioned or not. \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst index 2b08bfcca..1fe8e6be3 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -34,6 +34,7 @@ Contents: docs_user docs_server docs_channel + docs_message diff --git a/docs/vars.rst b/docs/vars.rst index 7a59d8007..c6284a22b 100644 --- a/docs/vars.rst +++ b/docs/vars.rst @@ -3,7 +3,7 @@ .. _ready : #ready .. _Server : ./docs_server.html .. _Channel : ./docs_channel.html -.. _Message : #message +.. _Message : ./docs_message.html .. _PMChannel : #PMChannel .. _Invite : #invite .. _Channel Resolvable : ./docs_resolvable.html#channel-resolvable From e7adc3ddbf12fca12c951be93b4f2dbda3372535 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Wed, 30 Sep 2015 18:23:21 +0100 Subject: [PATCH 078/151] More documentation and updated some PM Channel code The PM Channel will now also trunc messages and cap the array size --- docs/docs_channel.rst | 2 +- docs/docs_pmchannel.rst | 41 +++++++++++++++++++++++++++++++++++++++++ docs/index.rst | 1 + docs/vars.rst | 2 +- src/PMChannel.js | 5 +++++ 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 docs/docs_pmchannel.rst diff --git a/docs/docs_channel.rst b/docs/docs_channel.rst index b81ee763f..063fb0790 100644 --- a/docs/docs_channel.rst +++ b/docs/docs_channel.rst @@ -64,7 +64,7 @@ Gets a Message_ from the channel that matches the specified criteria. E.g: .. code-block:: js - channel.getMessage("id", 1243987349) // returns a Channel where message.id === 1243987349 + channel.getMessage("id", 1243987349) // returns a Message where message.id === 1243987349 - **key** - a `String` that is the key - **value** - a `String` that is the value diff --git a/docs/docs_pmchannel.rst b/docs/docs_pmchannel.rst new file mode 100644 index 000000000..3f10acec2 --- /dev/null +++ b/docs/docs_pmchannel.rst @@ -0,0 +1,41 @@ +.. include:: ./vars.rst + +PMChannel Documentation +======================= + +The PMChannel Class is used to represent data about a Private Message Channel. + +.. note:: Beware! The PMChannel class does `not` extend the Channel_ class. + +Attributes +---------- + +user +~~~~ + +The recipient User_ of the PM Channel. + +id +~~ + +`String` UUID of the PM Channel. + +messages +~~~~~~~~ + +An `Array` of Message_ objects. Contains all the cached messages sent in this channel up to a limit of 1000. If the limit is reached, the oldest message is removed first to make space for it. + +Functions +--------- + +getMessage(key, value) +~~~~~~~~~~~~~~~~~~~~~~ + +Gets a Message_ from the PM Channel that matches the specified criteria. E.g: + +.. code-block:: js + + pmchannel.getMessage("id", 1243987349) // returns a Message where message.id === 1243987349 + +- **key** - a `String` that is the key +- **value** - a `String` that is the value \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst index 1fe8e6be3..ff7a59144 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -34,6 +34,7 @@ Contents: docs_user docs_server docs_channel + docs_pmchannel docs_message diff --git a/docs/vars.rst b/docs/vars.rst index c6284a22b..523c83d2d 100644 --- a/docs/vars.rst +++ b/docs/vars.rst @@ -4,7 +4,7 @@ .. _Server : ./docs_server.html .. _Channel : ./docs_channel.html .. _Message : ./docs_message.html -.. _PMChannel : #PMChannel +.. _PMChannel : ./docs_pmchannel.html .. _Invite : #invite .. _Channel Resolvable : ./docs_resolvable.html#channel-resolvable .. _Invite Resolvable : ./docs_resolvable.html#invite-resolvable diff --git a/src/PMChannel.js b/src/PMChannel.js index d82cf7932..d7985f9c4 100644 --- a/src/PMChannel.js +++ b/src/PMChannel.js @@ -13,6 +13,11 @@ class PMChannel { } getMessage(key, value){ + + if(this.messages.length > 1000){ + this.messages.splice(0,1); + } + for(var message of this.messages){ if(message[key] === value){ return message; From ab5f0f8b7e720508f083358cd7322bfa3e467abc Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Wed, 30 Sep 2015 18:31:50 +0100 Subject: [PATCH 079/151] Last of most of the documentation! --- docs/docs_invite.rst | 64 ++++++++++++++++++++++++++++++++++++++++++++ docs/index.rst | 1 + docs/vars.rst | 2 +- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 docs/docs_invite.rst diff --git a/docs/docs_invite.rst b/docs/docs_invite.rst new file mode 100644 index 000000000..4c1688b1e --- /dev/null +++ b/docs/docs_invite.rst @@ -0,0 +1,64 @@ +.. include:: ./vars.rst + +Invite Documentation +==================== + +The Invite Class is used to represent data about an Invite. + +Attributes +---------- + +max_age +~~~~~~~ + +A `Number` in minutes for how long the Invite should be valid for. E.g. a value of ``3600`` is equal to 30 minutes. + +code +~~~~ + +`String` an alphanumeric code for the Invite. + +revoked +~~~~~~~ + +`Boolean` that dictates whether the Invite has been cancelled or not + +created_at +~~~~~~~~~~ + +A unix timestamp as a `Number` which is the time that the invite was created. + +temporary +~~~~~~~~~ + +`Boolean` that dictates whether the invite is temporary. + +uses +~~~~ + +`Number` the number of uses of the Invite, a value of ``0`` is none. + +max_uses +~~~~~~~~ + +`Number` that is the maximum amount of uses of the invite, ``0`` is unlimited. + +inviter +~~~~~~~ + +The User_ that created the invite. + +xkcd +~~~~ + +`Boolean` that is true if the invite should be human-readable. + +channel +~~~~~~~ + +The Channel_ that the invite is inviting to. + +URL +~~~ + +A `String` that generates a clickable link to the invite. \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst index ff7a59144..34e8f71a9 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -36,6 +36,7 @@ Contents: docs_channel docs_pmchannel docs_message + docs_invite diff --git a/docs/vars.rst b/docs/vars.rst index 523c83d2d..ad4b9720a 100644 --- a/docs/vars.rst +++ b/docs/vars.rst @@ -5,7 +5,7 @@ .. _Channel : ./docs_channel.html .. _Message : ./docs_message.html .. _PMChannel : ./docs_pmchannel.html -.. _Invite : #invite +.. _Invite : ./docs_invite.html .. _Channel Resolvable : ./docs_resolvable.html#channel-resolvable .. _Invite Resolvable : ./docs_resolvable.html#invite-resolvable .. _Promises : https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise \ No newline at end of file From a99b628fcf415cfd0de1e09311e290d83bdf2e19 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Wed, 30 Sep 2015 18:51:07 +0100 Subject: [PATCH 080/151] Updated readme @ 3.6.1 --- README.md | 51 +++++++++------------------------------------------ package.json | 2 +- 2 files changed, 10 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index b83cdabae..38c7f8c09 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,13 @@

-[![Build Status](https://travis-ci.org/hydrabolt/discord.js.svg)](https://travis-ci.org/hydrabolt/discord.js) +[![Build Status](https://travis-ci.org/hydrabolt/discord.js.svg)](https://travis-ci.org/hydrabolt/discord.js) [![Documentation Status](https://readthedocs.org/projects/discordjs/badge/?version=latest)](http://discordjs.readthedocs.org/en/latest/?badge=latest) + discord.js is a node module used as a way of interfacing with [Discord](https://discordapp.com/). It is a very useful module for creating bots. -**Updating to 3.1.1 is essential as it has new changes to be compatible with Discord's API, -and to make sure your application still works an update is a good idea.** - ### Installation `npm install --save discord.js` @@ -46,7 +44,7 @@ Here is a list of other Discord APIs: [DiscordSharp](https://github.com/Luigifan/DiscordSharp) #### NodeJS -[node-discord](https://github.com/izy521/node-discord) (similar to discord.js but lower level) +[discord.io](https://github.com/izy521/node-discord) (similar to discord.js but lower level) #### PHP [DiscordPHP](https://github.com/teamreflex/DiscordPHP) @@ -59,42 +57,8 @@ Here is a list of other Discord APIs: --- -### Changes in 3.1.4 - -No, not π. But instead, pseduo-synchronous messaging was added! This means that -you can tell your Client to make a queue of "actions" per channel, and it will -work through them one by one. This is a really useful tool if you need to send -messages in a specific order without callback hell. - -It also allows you to store responses - such as created messages - in the returned -promise - named action. Example: - -```js -var mybot = new Discord.Client({ - queue : true //enable queueing, disabled by default -}); - -mybot.on("message", function(msg){ - - mybot.sendMessage(msg.channel, "this is message 1"); - var action = mybot.sendMessage(msg.channel, "this is message 2"); - mybot.sendMessage(msg.channel, "this is message 3").then(rmv); - - function rmv(){ - if(!action.error){ - mybot.deleteMessage(action.message); - } - } - -}); -``` - -This is still in development, and will see many more enhancements in future. - ---- - ### Links -**[Documentation](https://github.com/discord-js/discord.js/wiki/Documentation)** +**[Documentation](http://discordjs.readthedocs.org/en/latest/)** **[GitHub](https://github.com/discord-js/discord.js)** @@ -108,5 +72,8 @@ This is still in development, and will see many more enhancements in future. ### Contact -If you would like to contact me, you can create an issue on the GitHub repo -or send a DM to **hydrabolt** in [Discord API](https://discord.gg/0SBTUU1wZTYd2XyW). +If you have an issue or want to know if a feature exists, [read the documentation](http://discordjs.readthedocs.org/en/latest/) before contacting me about any issues! If it's badly/wrongly implemented, let me know! + + +If you would like to contact me, you can create an issue on the GitHub repo, e-mail me via the one available on my NPM profile. +Or you could just send a DM to **hydrabolt** in [**Discord API**](https://discord.gg/0SBTUU1wZTYd2XyW). diff --git a/package.json b/package.json index 458024ac2..2059611ee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.6.0", + "version": "3.6.1", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From 46846fcacc2523488beb8f089ce1728d3ab24314 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Wed, 30 Sep 2015 20:47:26 +0100 Subject: [PATCH 081/151] added setPlaying and now working on docs --- docs/docs_client.rst | 7 ++++ lib/Client.js | 90 +++++++++++++++++++++++++++++++++++++------- lib/PMChannel.js | 5 +++ lib/server.js | 5 +++ ref/gameMap.json | 1 + src/Client.js | 51 ++++++++++++++++++++++++- test/bot.1.js | 10 ++--- 7 files changed, 149 insertions(+), 20 deletions(-) create mode 100644 ref/gameMap.json diff --git a/docs/docs_client.rst b/docs/docs_client.rst index 4c0f19cae..d312ab6a2 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -399,6 +399,13 @@ Gets a PMChannel_ that matches the specified criteria. E.g: - **key** - a `String` that is the key - **value** - a `String` that is the value +setPlayingGame(id) +~~~~~~~~~~~~~~~~~~ + +Sets the client as playing the specified game name/id. + +- **id** - Either a `Number` or a `String`. If it's a Number, it's assumed that you are using the Discord Game ID + ----- Event Management diff --git a/lib/Client.js b/lib/Client.js index d3d6f1f78..8b9c7f5c6 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -13,6 +13,8 @@ var Message = require("./message.js"); var Invite = require("./invite.js"); var PMChannel = require("./PMChannel.js"); +var gameMap = require("../ref/gameMap.json"); + //node modules var request = require("superagent"); var WebSocket = require("ws"); @@ -63,6 +65,9 @@ var Client = (function () { this.readyTime = null; this.checkingQueue = {}; this.queue = {}; + + this.__idleTime = null; + this.__gameId = null; } _createClass(Client, [{ @@ -1778,14 +1783,73 @@ var Client = (function () { var idleTime = stat === "online" ? null : Date.now(); + this.__idleTime = idleTime; + this.websocket.send(JSON.stringify({ op: 3, d: { - idle_since: idleTime, - game_id: null + idle_since: this.__idleTime, + game_id: this.__gameId } })); } + }, { + key: "setPlayingGame", + value: function setPlayingGame(id) { + + if (id instanceof String || typeof id === "string") { + + // working on names + var gid = id.trim().toUpperCase(); + + id = null; + + var _iteratorNormalCompletion16 = true; + var _didIteratorError16 = false; + var _iteratorError16 = undefined; + + try { + for (var _iterator16 = gameMap[Symbol.iterator](), _step16; !(_iteratorNormalCompletion16 = (_step16 = _iterator16.next()).done); _iteratorNormalCompletion16 = true) { + var game = _step16.value; + + if (game.name.trim().toUpperCase() === gid) { + + id = game.id; + break; + } + } + } catch (err) { + _didIteratorError16 = true; + _iteratorError16 = err; + } finally { + try { + if (!_iteratorNormalCompletion16 && _iterator16["return"]) { + _iterator16["return"](); + } + } finally { + if (_didIteratorError16) { + throw _iteratorError16; + } + } + } + } + + this.__gameId = id; + + this.websocket.send(JSON.stringify({ + op: 3, + d: { + idle_since: this.__idleTime, + game_id: this.__gameId + } + })); + } + }, { + key: "playingGame", + value: function playingGame(id) { + + this.setPlayingGame(id); + } }, { key: "uptime", get: function get() { @@ -1822,27 +1886,27 @@ var Client = (function () { get: function get() { var msgs = []; - var _iteratorNormalCompletion16 = true; - var _didIteratorError16 = false; - var _iteratorError16 = undefined; + var _iteratorNormalCompletion17 = true; + var _didIteratorError17 = false; + var _iteratorError17 = undefined; try { - for (var _iterator16 = this.channelCache[Symbol.iterator](), _step16; !(_iteratorNormalCompletion16 = (_step16 = _iterator16.next()).done); _iteratorNormalCompletion16 = true) { - var channel = _step16.value; + for (var _iterator17 = this.channelCache[Symbol.iterator](), _step17; !(_iteratorNormalCompletion17 = (_step17 = _iterator17.next()).done); _iteratorNormalCompletion17 = true) { + var channel = _step17.value; msgs = msgs.concat(channel.messages); } } catch (err) { - _didIteratorError16 = true; - _iteratorError16 = err; + _didIteratorError17 = true; + _iteratorError17 = err; } finally { try { - if (!_iteratorNormalCompletion16 && _iterator16["return"]) { - _iterator16["return"](); + if (!_iteratorNormalCompletion17 && _iterator17["return"]) { + _iterator17["return"](); } } finally { - if (_didIteratorError16) { - throw _iteratorError16; + if (_didIteratorError17) { + throw _iteratorError17; } } } diff --git a/lib/PMChannel.js b/lib/PMChannel.js index 7c30a7c34..0dbc0405e 100644 --- a/lib/PMChannel.js +++ b/lib/PMChannel.js @@ -24,6 +24,11 @@ var PMChannel = (function () { }, { key: "getMessage", value: function getMessage(key, value) { + + if (this.messages.length > 1000) { + this.messages.splice(0, 1); + } + var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; diff --git a/lib/server.js b/lib/server.js index a5c90170d..c8758d5da 100644 --- a/lib/server.js +++ b/lib/server.js @@ -142,6 +142,11 @@ var Server = (function () { value: function toString() { return this.name; } + }, { + key: "equals", + value: function equals(object) { + return object.id === this.id; + } }, { key: "iconURL", get: function get() { diff --git a/ref/gameMap.json b/ref/gameMap.json new file mode 100644 index 000000000..8b351465f --- /dev/null +++ b/ref/gameMap.json @@ -0,0 +1 @@ +[{"executables":{"win32":["pol.exe"]},"id":0,"name":"FINAL FANTASY XI"},{"executables":{"win32":["ffxiv.exe","ffxiv_dx11.exe"]},"id":1,"name":"FINAL FANTASY XIV"},{"executables":{"win32":["Wow.exe","Wow-64.exe"]},"id":3,"name":"World of Warcraft"},{"executables":{"darwin":["LoLLauncher.app"],"win32":["LolClient.exe","League of Legends.exe"]},"id":4,"name":"League of Legends"},{"executables":{"darwin":["Diablo%20III.app"],"win32":["Diablo III.exe"]},"id":5,"name":"Diablo 3"},{"executables":{"darwin":["dota_osx.app"],"win32":["dota2.exe"]},"id":6,"name":"DOTA 2"},{"executables":{"darwin":["Heroes.app"],"win32":["Heroes of the Storm.exe","HeroesOfTheStorm_x64.exe","HeroesOfTheStorm.exe"]},"id":7,"name":"Heroes of the Storm"},{"executables":{"darwin":["Hearthstone.app"],"win32":["Hearthstone.exe"]},"id":8,"name":"Hearthstone"},{"executables":{"win32":["csgo.exe"]},"id":9,"name":"Counter-Strike: Global Offensive"},{"executables":{"win32":["WorldOfTanks.exe"]},"id":10,"name":"World of Tanks"},{"executables":{"darwin":["gw2.app"],"win32":["gw2.exe"]},"id":11,"name":"Guild Wars 2"},{"executables":{"win32":["dayz.exe"]},"id":12,"name":"Day Z"},{"executables":{"darwin":["starcraft%20ii.app"],"win32":["starcraft ii.exe","SC2_x64.exe","SC2.exe"]},"id":13,"name":"Starcraft II"},{"executables":{"win32":["diablo.exe"]},"id":14,"name":"Diablo"},{"executables":{"win32":["diablo ii.exe"]},"id":15,"name":"Diablo 2"},{"executables":{"win32":["left4dead.exe"]},"id":17,"name":"Left 4 Dead"},{"executables":{"darwin":["minecraft.app"],"win32":["minecraft.exe"]},"id":18,"name":"Minecraft"},{"executables":{"win32":["smite.exe"]},"id":19,"name":"Smite"},{"executables":{"win32":["bf4.exe"]},"id":20,"name":"Battlefield 4"},{"executables":{"win32":["AoK HD.exe","empires2.exe"]},"id":101,"name":"Age of Empire II"},{"executables":{"win32":["age3y.exe"]},"id":102,"name":"Age of Empire III"},{"executables":{"win32":["AlanWake.exe"]},"id":104,"name":"Alan Wake"},{"executables":{"win32":["alan_wakes_american_nightmare.exe"]},"id":105,"name":"Alan Wake's American Nightmare"},{"executables":{"win32":["AlienBreed2Assault.exe"]},"id":106,"name":"Alien Breed 2: Assault"},{"executables":{"win32":["Amnesia.exe"]},"id":107,"name":"Amnesia: The Dark Descent"},{"executables":{"win32":["UDK.exe"]},"id":108,"name":"Antichamber"},{"executables":{"win32":["ArcheAge.exe"]},"id":109,"name":"ArcheAge"},{"executables":{"win32":["arma3.exe"]},"id":110,"name":"Arma III"},{"executables":{"win32":["AC3SP.exe"]},"id":111,"name":"Assassin's Creed 3"},{"executables":{"win32":["Bastion.exe"]},"id":112,"name":"Bastion"},{"executables":{"win32":["BF2.exe"]},"id":113,"name":"Battlefield 2"},{"executables":{"win32":["bf3.exe"]},"id":114,"name":"Battlefield 3"},{"executables":{"win32":["Besiege.exe"]},"id":116,"name":"Besiege"},{"executables":{"win32":["Bioshock.exe"]},"id":117,"name":"Bioshock"},{"executables":{"win32":["Bioshock2.exe"]},"id":118,"name":"BioShock II"},{"executables":{"win32":["BioShockInfinite.exe"]},"id":119,"name":"BioShock Infinite"},{"executables":{"win32":["Borderlands2.exe"]},"id":122,"name":"Borderlands 2"},{"executables":{"win32":["braid.exe"]},"id":123,"name":"Braid"},{"executables":{"win32":["ShippingPC-StormGame.exe"]},"id":124,"name":"Bulletstorm"},{"executables":{},"id":125,"name":"Cabal 2"},{"executables":{"win32":["CabalMain.exe"]},"id":126,"name":"Cabal Online"},{"executables":{"win32":["iw4mp.exe","iw4sp.exe"]},"id":127,"name":"Call of Duty: Modern Warfare 2"},{"executables":{"win32":["t6sp.exe"]},"id":128,"name":"Call of Duty: Black Ops"},{"executables":{"win32":["iw5mp.exe"]},"id":129,"name":"Call of Duty: Modern Warfare 3"},{"executables":{"win32":["RelicCOH.exe"]},"id":132,"name":"Company of Heroes"},{"executables":{"win32":["Crysis64.exe"]},"id":135,"name":"Crysis"},{"executables":{"win32":["Crysis2.exe"]},"id":136,"name":"Crysis 2"},{"executables":{"win32":["Crysis3.exe"]},"id":137,"name":"Crysis 3"},{"executables":{"win32":["Crysis.exe"]},"id":138,"name":"Crysis 4 "},{"executables":{"win32":["DATA.exe"]},"id":140,"name":"Dark Souls"},{"executables":{"win32":["DarkSoulsII.exe"]},"id":141,"name":"Dark Souls II"},{"executables":{"win32":["dfuw.exe"]},"id":142,"name":"Darkfall: Unholy Wars"},{"executables":{"win32":["DCGAME.exe"]},"id":144,"name":"DC Universe Online"},{"executables":{"win32":["DeadIslandGame.exe"]},"id":145,"name":"Dead Island"},{"executables":{"win32":["deadspace2.exe"]},"id":146,"name":"Dead Space 2"},{"executables":{"win32":["LOTDGame.exe"]},"id":147,"name":"Deadlight"},{"executables":{"win32":["dxhr.exe"]},"id":148,"name":"Deus Ex: Human Revolution"},{"executables":{"win32":["DeviMayCry4.exe"]},"id":149,"name":"Devil May Cry 4"},{"executables":{"win32":["DMC-DevilMayCry.exe"]},"id":150,"name":"DmC Devil May Cry"},{"executables":{"win32":["dirt2_game.exe"]},"id":154,"name":"DiRT 2"},{"executables":{"win32":["dirt3_game.exe"]},"id":155,"name":"DiRT 3"},{"executables":{"win32":["dota.exe"]},"id":156,"name":"DOTA"},{"executables":{"win32":["DoubleDragon.exe"]},"id":158,"name":"Double Dragon Neon"},{"executables":{"win32":["DragonAge2.exe"]},"id":159,"name":"Dragon Age II"},{"executables":{"win32":["DragonAgeInquisition.exe"]},"id":160,"name":"Dragon Age: Inquisition"},{"executables":{"win32":["daorigins.exe"]},"id":161,"name":"Dragon Age: Origins"},{"executables":{"win32":["DBXV.exe"]},"id":162,"name":"Dragon Ball XenoVerse"},{"executables":{"win32":["DukeForever.exe"]},"id":163,"name":"Duke Nukem Forever"},{"executables":{"darwin":["Dustforce.app"],"win32":["dustforce.exe"]},"id":164,"name":"Dustforce"},{"executables":{"win32":["EliteDangerous32.exe"]},"id":165,"name":"Elite: Dangerous"},{"executables":{"win32":["exefile.exe"]},"id":166,"name":"Eve Online"},{"executables":{"win32":["eqgame.exe"]},"id":167,"name":"EverQuest"},{"executables":{"win32":["EverQuest2.exe"]},"id":168,"name":"EverQuest II"},{"executables":{},"id":169,"name":"EverQuest Next"},{"executables":{"win32":["Engine.exe"]},"id":170,"name":"F.E.A.R."},{"executables":{"win32":["FEAR2.exe"]},"id":171,"name":"F.E.A.R. 2: Project Origin"},{"executables":{"win32":["fallout3.exe"]},"id":172,"name":"Fallout 3"},{"executables":{"win32":["FalloutNV.exe"]},"id":174,"name":"Fallout: New Vegas"},{"executables":{"win32":["farcry3.exe"]},"id":175,"name":"Far Cry 3"},{"executables":{"win32":["fifa15.exe"]},"id":176,"name":"FIFA 15"},{"executables":{"win32":["FTLGame.exe"]},"id":180,"name":"FTL: Faster Than Light"},{"executables":{"win32":["GTAIV.exe"]},"id":181,"name":"Grand Theft Auto 4"},{"executables":{"win32":["GTA5.exe"]},"id":182,"name":"Grand Theft Auto 5"},{"executables":{"win32":["Gw.exe"]},"id":183,"name":"Guild Wars"},{"executables":{"win32":["H1Z1.exe"]},"id":186,"name":"H1Z1"},{"executables":{"win32":["HL2HL2.exe","hl2.exe"]},"id":188,"name":"Half Life 2"},{"executables":{"win32":["HOMEFRONT.exe"]},"id":195,"name":"Homefront"},{"executables":{"win32":["invisibleinc.exe"]},"id":196,"name":"Invisible Inc."},{"executables":{"win32":["LANoire.exe"]},"id":197,"name":"L.A. Noire"},{"executables":{"win32":["Landmark64.exe"]},"id":198,"name":"Landmark"},{"executables":{"win32":["left4dead2.exe"]},"id":201,"name":"Left 4 Dead 2"},{"executables":{"win32":["lineage.exe"]},"id":203,"name":"Lineage"},{"executables":{"win32":["Magicka.exe"]},"id":206,"name":"Magicka"},{"executables":{"win32":["MapleStory.exe"]},"id":208,"name":"MapleStory"},{"executables":{},"id":209,"name":"Mark of the Ninja"},{"executables":{"win32":["MassEffect.exe"]},"id":210,"name":"Mass Effect"},{"executables":{"win32":["MassEffect2.exe"]},"id":211,"name":"Mass Effect 2"},{"executables":{"win32":["MassEffect3Demo.exe"]},"id":212,"name":"Mass Effect 3"},{"executables":{"win32":["METAL GEAR RISING REVENGEANCE.exe"]},"id":214,"name":"Metal Gear Rising: Revengeance"},{"executables":{"win32":["metro2033.exe"]},"id":215,"name":"Metro 2033"},{"executables":{"win32":["MetroLL.exe"]},"id":216,"name":"Metro Last Light"},{"executables":{"win32":["MK10.exe"]},"id":218,"name":"Mortal Kombat X"},{"executables":{"win32":["speed.exe"]},"id":219,"name":"Need For Speed Most Wanted"},{"executables":{},"id":220,"name":"Neverwinder"},{"executables":{"darwin":["Outlast.app"],"win32":["OLGame.exe"]},"id":221,"name":"Outlast"},{"executables":{"win32":["PapersPlease.exe"]},"id":222,"name":"Papers, Please"},{"executables":{"win32":["payday_win32_release.exe"]},"id":223,"name":"PAYDAY"},{"executables":{"win32":["payday2_win32_release.exe"]},"id":224,"name":"PAYDAY2"},{"executables":{"win32":["PillarsOfEternity.exe"]},"id":225,"name":"Pillars of Eternity"},{"executables":{"win32":["PA.exe"]},"id":226,"name":"Planetary Annihilation"},{"executables":{"win32":["planetside2_x86.exe"]},"id":227,"name":"Planetside 2"},{"executables":{"win32":["hl2P.exe"]},"id":228,"name":"Portal"},{"executables":{"win32":["portal2.exe"]},"id":229,"name":"Portal 2"},{"executables":{"win32":["PrimalCarnageGame.exe"]},"id":231,"name":"Primal Cargnage"},{"executables":{"win32":["pCARS.exe"]},"id":232,"name":"Project Cars"},{"executables":{"win32":["RaceTheSun.exe"]},"id":233,"name":"Race The Sun"},{"executables":{"win32":["Rage.exe"]},"id":234,"name":"RAGE"},{"executables":{"win32":["ragexe.exe"]},"id":235,"name":"Ragnarok Online"},{"executables":{"win32":["rift.exe"]},"id":236,"name":"Rift"},{"executables":{"win32":["Rocksmith2014.exe"]},"id":237,"name":"Rocksmith 2014"},{"executables":{"win32":["SwiftKit-RS.exe","JagexLauncher.exe"]},"id":238,"name":"RuneScape"},{"executables":{"win32":["Shadowgrounds.exe"]},"id":239,"name":"Shadowgrounds"},{"executables":{"win32":["survivor.exe"]},"id":240,"name":"Shadowgrounds: Survivor"},{"executables":{"win32":["ShovelKnight.exe"]},"id":241,"name":"Shovel Knight"},{"executables":{"win32":["SimCity.exe"]},"id":242,"name":"SimCity"},{"executables":{"win32":["SporeApp.exe"]},"id":245,"name":"Spore"},{"executables":{"win32":["StarCitizen.exe"]},"id":246,"name":"Star Citizen"},{"executables":{},"id":247,"name":"Star Trek Online"},{"executables":{"win32":["battlefront.exe"]},"id":248,"name":"Star Wars Battlefront"},{"executables":{"win32":["swtor.exe"]},"id":249,"name":"Star Wars: The Old Republic"},{"executables":{"win32":["starbound.exe","starbound_opengl.exe"]},"id":250,"name":"Starbound"},{"executables":{"win32":["starcraft.exe"]},"id":251,"name":"Starcraft"},{"executables":{"win32":["SSFIV.exe"]},"id":253,"name":"Ultra Street Fighter IV"},{"executables":{"win32":["superhexagon.exe"]},"id":254,"name":"Super Hexagon"},{"executables":{"win32":["swordandsworcery_pc.exe"]},"id":255,"name":"Superbrothers: Sword & Sworcery EP"},{"executables":{"win32":["hl2TF.exe"]},"id":256,"name":"Team Fortress 2"},{"executables":{"win32":["TERA.exe"]},"id":258,"name":"TERA"},{"executables":{"win32":["Terraria.exe"]},"id":259,"name":"Terraria"},{"executables":{"win32":["Bethesda.net_Launcher.exe"]},"id":260,"name":"The Elder Scrolls Online"},{"executables":{"win32":["TESV.exe"]},"id":261,"name":"The Elder Scrolls V: Skyrim"},{"executables":{"win32":["TheSecretWorld.exe"]},"id":262,"name":"The Secret World"},{"executables":{"win32":["TS3.exe","ts3w.exe"]},"id":264,"name":"The Sims 3"},{"executables":{"win32":["WALKINGDEAD101.EXE"]},"id":265,"name":"The Walking Dead"},{"executables":{"win32":["TheWalkingDead2.exe"]},"id":266,"name":"The Walking Dead Season Two"},{"executables":{"win32":["witcher3.exe"]},"id":267,"name":"The Witcher 3"},{"executables":{"win32":["Future Soldier.exe"]},"id":268,"name":"Tom Clancy's Ghost Recon: Future Solider"},{"executables":{"win32":["TombRaider.exe"]},"id":269,"name":"Tomb Raider (2013)"},{"executables":{"win32":["Torchlight.exe"]},"id":271,"name":"Torchlight"},{"executables":{"win32":["Torchlight2.exe"]},"id":272,"name":"Torchlight 2"},{"executables":{"win32":["Shogun2.exe"]},"id":273,"name":"Total War: Shogun 2"},{"executables":{"win32":["Transistor.exe"]},"id":274,"name":"Transistor"},{"executables":{"win32":["trine.exe"]},"id":275,"name":"Trine"},{"executables":{"win32":["trine2_32bit.exe"]},"id":276,"name":"Trine 2"},{"executables":{"win32":["UOKR.exe"]},"id":277,"name":"Ultima Online"},{"executables":{"win32":["aces.exe"]},"id":279,"name":"War Thunder"},{"executables":{"win32":["Warcraft III.exe","wc3.exe"]},"id":281,"name":"Warcraft 3: Reign of Chaos"},{"executables":{"win32":["Warcraft II BNE.exe"]},"id":282,"name":"Warcraft II"},{"executables":{"win32":["Warframe.x64.exe","Warframe.exe"]},"id":283,"name":"Warframe"},{"executables":{"win32":["watch_dogs.exe"]},"id":284,"name":"Watch Dogs"},{"executables":{"win32":["WildStar64.exe"]},"id":285,"name":"WildStar"},{"executables":{"win32":["XComGame.exe"]},"id":288,"name":"XCOM: Enemy Unknown"},{"executables":{"win32":["DFO.exe","dfo.exe"]},"id":289,"name":"Dungeon Fighter Online"},{"executables":{"win32":["aclauncher.exe","acclient.exe"]},"id":290,"name":"Asheron's Call"},{"executables":{"win32":["MapleStory2.exe"]},"id":291,"name":"MapleStory 2"},{"executables":{"win32":["ksp.exe"]},"id":292,"name":"Kerbal Space Program"},{"executables":{"win32":["PINBALL.EXE"]},"id":293,"name":"3D Pinball: Space Cadet"},{"executables":{"win32":["dave.exe"]},"id":294,"name":"Dangerous Dave"},{"executables":{"win32":["iwbtgbeta(slomo).exe","iwbtgbeta(fs).exe"]},"id":295,"name":"I Wanna Be The Guy"},{"executables":{"win32":["MechWarriorOnline.exe "]},"id":296,"name":"Mech Warrior Online"},{"executables":{"win32":["dontstarve_steam.exe"]},"id":297,"name":"Don't Starve"},{"executables":{"win32":["GalCiv3.exe"]},"id":298,"name":"Galactic Civilization 3"},{"executables":{"win32":["Risk of Rain.exe"]},"id":299,"name":"Risk of Rain"},{"executables":{"win32":["Binding_of_Isaac.exe","Isaac-ng.exe"]},"id":300,"name":"The Binding of Isaac"},{"executables":{"win32":["RustClient.exe"]},"id":301,"name":"Rust"},{"executables":{"win32":["Clicker Heroes.exe"]},"id":302,"name":"Clicker Heroes"},{"executables":{"win32":["Brawlhalla.exe"]},"id":303,"name":"Brawlhalla"},{"executables":{"win32":["TownOfSalem.exe"]},"id":304,"name":"Town of Salem"},{"executables":{"win32":["osu!.exe"]},"id":305,"name":"osu!"},{"executables":{"win32":["PathOfExileSteam.exe","PathOfExile.exe"]},"id":306,"name":"Path of Exile"},{"executables":{"win32":["Dolphin.exe"]},"id":307,"name":"Dolphin"},{"executables":{"win32":["RocketLeague.exe"]},"id":308,"name":"Rocket League"},{"executables":{"win32":["TJPP.exe"]},"id":309,"name":"Jackbox Party Pack"},{"executables":{"win32":["KFGame.exe"]},"id":310,"name":"Killing Floor 2"},{"executables":{"win32":["ShooterGame.exe"]},"id":311,"name":"Ark: Survival Evolved"},{"executables":{"win32":["LifeIsStrange.exe"]},"id":312,"name":"Life Is Strange"},{"executables":{"win32":["Client_tos.exe"]},"id":313,"name":"Tree of Savior"},{"executables":{"win32":["olliolli2.exe"]},"id":314,"name":"OlliOlli2"},{"executables":{"win32":["cw.exe"]},"id":315,"name":"Closers Dimension Conflict"},{"executables":{"win32":["ESSTEAM.exe","elsword.exe","x2.exe"]},"id":316,"name":"Elsword"},{"executables":{"win32":["ori.exe"]},"id":317,"name":"Ori and the Blind Forest"},{"executables":{"win32":["Skyforge.exe"]},"id":318,"name":"Skyforge"},{"executables":{"win32":["projectzomboid64.exe","projectzomboid32.exe"]},"id":319,"name":"Project Zomboid"},{"executables":{"win32":["From_The_Depths.exe"]},"id":320,"name":"The Depths"},{"executables":{"win32":["TheCrew.exe"]},"id":321,"name":"The Crew"},{"executables":{"win32":["MarvelHeroes2015.exe"]},"id":322,"name":"Marvel Heroes 2015"},{"executables":{"win32":["timeclickers.exe"]},"id":324,"name":"Time Clickers"},{"executables":{"win32":["eurotrucks2.exe"]},"id":325,"name":"Euro Truck Simulator 2"},{"executables":{"win32":["FarmingSimulator2015Game.exe"]},"id":326,"name":"Farming Simulator 15"},{"executables":{"win32":["strife.exe"]},"id":327,"name":"Strife"},{"executables":{"win32":["Awesomenauts.exe"]},"id":328,"name":"Awesomenauts"},{"executables":{"win32":["Dofus.exe"]},"id":329,"name":"Dofus"},{"executables":{"win32":["Boid.exe"]},"id":330,"name":"Boid"},{"executables":{"win32":["adventure-capitalist.exe"]},"id":331,"name":"AdVenture Capitalist"},{"executables":{"win32":["OrcsMustDie2.exe"]},"id":332,"name":"Orcs Must Die! 2"},{"executables":{"win32":["Mountain.exe"]},"id":333,"name":"Mountain"},{"executables":{"win32":["Valkyria.exe"]},"id":335,"name":"Valkyria Chronicles"},{"executables":{"win32":["ffxiiiimg.exe"]},"id":336,"name":"Final Fantasy XIII"},{"executables":{"win32":["TLR.exe"]},"id":337,"name":"The Last Remnant"},{"executables":{"win32":["Cities.exe"]},"id":339,"name":"Cities Skylines"},{"executables":{"win32":["worldofwarships.exe","WoWSLauncher.exe"]},"id":341,"name":"World of Warships"},{"executables":{"win32":["spacegame-Win64-shipping.exe"]},"id":342,"name":"Fractured Space"},{"executables":{"win32":["thespacegame.exe"]},"id":343,"name":"Ascent - The Space Game"},{"executables":{"win32":["DuckGame.exe"]},"id":344,"name":"Duck Game"},{"executables":{"win32":["PPSSPPWindows.exe"]},"id":345,"name":"PPSSPP"},{"executables":{"win32":["MBAA.exe"]},"id":346,"name":"Melty Blood Actress Again: Current Code"},{"executables":{"win32":["TheWolfAmongUs.exe"]},"id":347,"name":"The Wolf Among Us"},{"executables":{"win32":["SpaceEngineers.exe"]},"id":348,"name":"Space Engineers"},{"executables":{"win32":["Borderlands.exe"]},"id":349,"name":"Borderlands"},{"executables":{"win32":["100orange.exe"]},"id":351,"name":"100% Orange Juice"},{"executables":{"win32":["reflex.exe"]},"id":354,"name":"Reflex"},{"executables":{"win32":["pso2.exe"]},"id":355,"name":"Phantasy Star Online 2"},{"executables":{"win32":["AssettoCorsa.exe"]},"id":356,"name":"Assetto Corsa"},{"executables":{"win32":["iw3mp.exe","iw3sp.exe"]},"id":357,"name":"Call of Duty 4: Modern Warfare"},{"executables":{"win32":["WolfOldBlood_x64.exe"]},"id":358,"name":"Wolfenstein: The Old Blood"},{"executables":{"win32":["castle.exe"]},"id":359,"name":"Castle Crashers"},{"executables":{"win32":["vindictus.exe"]},"id":360,"name":"Vindictus"},{"executables":{"win32":["ShooterGame-Win32-Shipping.exe"]},"id":361,"name":"Dirty Bomb"},{"executables":{"win32":["BatmanAK.exe"]},"id":362,"name":"Batman Arkham Knight"},{"executables":{"win32":["drt.exe"]},"id":363,"name":"Dirt Rally"},{"executables":{"win32":["rFactor.exe"]},"id":364,"name":"rFactor"},{"executables":{"win32":["clonk.exe"]},"id":365,"name":"Clonk Rage"},{"executables":{"win32":["SRHK.exe"]},"id":366,"name":"Shadowrun: Hong Kong"},{"executables":{"win32":["Insurgency.exe"]},"id":367,"name":"Insurgency"},{"executables":{"win32":["StepMania.exe"]},"id":368,"name":"Step Mania"},{"executables":{"win32":["FirefallCLient.exe"]},"id":369,"name":"Firefall"},{"executables":{"win32":["mirrorsedge.exe"]},"id":370,"name":"Mirrors Edge"},{"executables":{"win32":["MgsGroundZeroes.exe"]},"id":371,"name":"Metal Gear Solid V: Ground Zeroes"},{"executables":{"win32":["mgsvtpp.exe"]},"id":372,"name":"Metal Gear Solid V: The Phantom Pain"},{"executables":{"win32":["tld.exe"]},"id":373,"name":"The Long Dark"},{"executables":{"win32":["TKOM.exe"]},"id":374,"name":"Take On Mars"},{"executables":{"win32":["robloxplayerlauncher.exe","Roblox.exe"]},"id":375,"name":"Roblox"},{"executables":{"win32":["eu4.exe"]},"id":376,"name":"Europa Universalis 4"},{"executables":{"win32":["APB.exe"]},"id":377,"name":"APB Reloaded"},{"executables":{"win32":["Robocraft.exe"]},"id":378,"name":"Robocraft"},{"executables":{"win32":["Unity.exe"]},"id":379,"name":"Unity"},{"executables":{"win32":["Simpsons.exe"]},"id":380,"name":"The Simpsons: Hit & Run"},{"executables":{"win32":["Dnlauncher.exe","DragonNest.exe"]},"id":381,"name":"Dragon Nest"},{"executables":{"win32":["Trove.exe"]},"id":382,"name":"Trove"},{"executables":{"win32":["EndlessLegend.exe"]},"id":383,"name":"Endless Legend"},{"executables":{"win32":["TurbineLauncher.exe","dndclient.exe"]},"id":384,"name":"Dungeons & Dragons Online"},{"executables":{"win32":["quakelive.exe","quakelive_steam.exe"]},"id":385,"name":"Quake Live"},{"executables":{"win32":["7DaysToDie.exe"]},"id":386,"name":"7DaysToDie"},{"executables":{"win32":["SpeedRunners.exe"]},"id":387,"name":"SpeedRunners"},{"executables":{"win32":["gamemd.exe"]},"id":388,"name":"Command & Conquer: Red Alert 2"},{"executables":{"win32":["generals.exe"]},"id":389,"name":"Command & Conquer Generals: Zero Hour"},{"executables":{"win32":["Oblivion.exe"]},"id":390,"name":"The Elder Scrolls 4: Oblivion"},{"executables":{"win32":["mgsi.exe"]},"id":391,"name":"Metal Gear Solid"},{"executables":{"win32":["EoCApp.exe"]},"id":392,"name":"Divinity - Original Sin"},{"executables":{"win32":["Torment.exe"]},"id":393,"name":"Planescape: Torment"},{"executables":{"win32":["HexPatch.exe"]},"id":394,"name":"Hex: Shards of Fate"},{"executables":{"win32":["NS3FB.exe"]},"id":395,"name":"Naruto Shippuden Ultimate Ninja Storm 3 Full Burst"},{"executables":{"win32":["NSUNSR.exe"]},"id":396,"name":"Naruto Shippuden Ultimate Ninja Storm Revolution"},{"executables":{"win32":["SaintsRowIV.exe"]},"id":397,"name":"Saints Row IV"},{"executables":{"win32":["Shadowrun.exe"]},"id":398,"name":"Shadowrun"},{"executables":{"win32":["DungeonoftheEndless.exe"]},"id":399,"name":"Dungeon of the Endless"},{"executables":{"win32":["Hon.exe"]},"id":400,"name":"Heroes of Newerth"},{"executables":{"win32":["mabinogi.exe"]},"id":401,"name":"Mabinogi"},{"executables":{"win32":["CoD2MP_s.exe","CoDSP_s.exe"]},"id":402,"name":"Call of Duty 2:"},{"executables":{"win32":["CoDWaWmp.exe","CoDWaw.exe"]},"id":403,"name":"Call of Duty: World at War"},{"executables":{"win32":["heroes.exe"]},"id":404,"name":"Mabinogi Heroes (Vindictus) "},{"executables":{"win32":["KanColleViewer.exe"]},"id":405,"name":"KanColle "},{"executables":{"win32":["cyphers.exe"]},"id":406,"name":"Cyphers"},{"executables":{"win32":["RelicCoH2.exe"]},"id":407,"name":"Company of Heroes 2"},{"executables":{"win32":["MJ.exe"]},"id":408,"name":"セガNET麻雀MJ"},{"executables":{"win32":["ge.exe"]},"id":409,"name":"Granado Espada"},{"executables":{"win32":["NovaRO.exe"]},"id":410,"name":"Nova Ragnarok Online"},{"executables":{"win32":["RivalsofAether.exe"]},"id":411,"name":"Rivals of Aether"},{"executables":{"win32":["bfh.exe"]},"id":412,"name":"Battlefield Hardline"},{"executables":{"win32":["GrowHome.exe"]},"id":413,"name":"Grow Home"},{"executables":{"win32":["patriots.exe"]},"id":414,"name":"Rise of Nations Extended"},{"executables":{"win32":["Railroads.exe"]},"id":415,"name":"Sid Meier's Railroads!"},{"executables":{"win32":["Empire.exe"]},"id":416,"name":"Empire: Total War"},{"executables":{"win32":["Napoleon.exe"]},"id":417,"name":"Napoleon: Total War"},{"executables":{"win32":["gta_sa.exe"]},"id":418,"name":"Grand Theft Auto: San Andreas"},{"executables":{"win32":["MadMax.exe"]},"id":419,"name":"Mad Max"},{"executables":{"win32":["Titanfall.exe"]},"id":420,"name":"Titanfall"},{"executables":{"win32":["age2_x1.exe"]},"id":421,"name":"Age of Empires II: The Conquerors"},{"executables":{"win32":["Rome2.exe"]},"id":422,"name":"Total War: ROME 2"},{"executables":{"win32":["ShadowOfMordor.exe"]},"id":423,"name":"Middle-earth: Shadow of Mordor"},{"executables":{"win32":["Subnautica.exe"]},"id":424,"name":"Subnautica"},{"executables":{"win32":["anno5.exe"]},"id":425,"name":"Anno 2070"},{"executables":{"win32":["carrier.exe"]},"id":426,"name":"Carrier Command Gaea Mission"},{"executables":{"win32":["DarksidersPC.exe"]},"id":427,"name":"Darksiders"},{"executables":{"win32":["Darksiders2.exe"]},"id":428,"name":"Darksiders 2"},{"executables":{"win32":["mudlet.exe"]},"id":429,"name":"Mudlet"},{"executables":{"win32":["DunDefLauncher.exe"]},"id":430,"name":"Dungeon Defenders II"},{"executables":{"win32":["hng.exe"]},"id":431,"name":"Heroes and Generals"},{"executables":{"win32":["WFTOGame.exe"]},"id":432,"name":"War of the Overworld"},{"executables":{"win32":["Talisman.exe"]},"id":433,"name":"Talisman: Digital Edition"},{"executables":{"win32":["limbo.exe"]},"id":434,"name":"Limbo"},{"executables":{"win32":["ibbobb.exe"]},"id":435,"name":"ibb & obb"},{"executables":{"win32":["BattleBlockTheater.exe"]},"id":436,"name":"BattleBlock Theater"},{"executables":{"win32":["iracinglauncher.exe","iracingsim.exe","iracingsim64.exe"]},"id":437,"name":"iRacing"},{"executables":{"win32":["CivilizationV_DX11.exe"]},"id":438,"name":"Civilization V"}] \ No newline at end of file diff --git a/src/Client.js b/src/Client.js index ef51e2c42..ef3d7009c 100644 --- a/src/Client.js +++ b/src/Client.js @@ -7,6 +7,8 @@ var Message = require("./message.js"); var Invite = require("./invite.js"); var PMChannel = require("./PMChannel.js"); +var gameMap = require("../ref/gameMap.json"); + //node modules var request = require("superagent"); var WebSocket = require("ws"); @@ -53,6 +55,9 @@ class Client { this.readyTime = null; this.checkingQueue = {}; this.queue = {}; + + this.__idleTime = null; + this.__gameId = null; } get uptime() { @@ -1521,14 +1526,56 @@ class Client { var idleTime = (stat === "online" ? null : Date.now()); + this.__idleTime = idleTime; + this.websocket.send(JSON.stringify({ op : 3, d : { - idle_since : idleTime, - game_id : null + idle_since : this.__idleTime, + game_id : this.__gameId } })); } + + setPlayingGame(id){ + + if( id instanceof String || typeof id === `string` ){ + + // working on names + var gid = id.trim().toUpperCase(); + + id = null; + + for( var game of gameMap ){ + + if(game.name.trim().toUpperCase() === gid){ + + id = game.id; + break; + + } + + } + + } + + this.__gameId = id; + + this.websocket.send(JSON.stringify({ + op : 3, + d : { + idle_since : this.__idleTime, + game_id : this.__gameId + } + })); + + } + + playingGame(id){ + + this.setPlayingGame(id); + + } } module.exports = Client; \ No newline at end of file diff --git a/test/bot.1.js b/test/bot.1.js index 4eb5ab07f..289d3c7bb 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -4,6 +4,8 @@ var fs = require("fs"); var server, channel, message, sentMessage = false; +counter = 1; + mybot.on("message", function (message) { console.log("Everyone mentioned? " + message.everyoneMentioned); @@ -19,16 +21,14 @@ mybot.on("message", function (message) { var onlineUsers = 0; - mybot.startTyping(message.channel, 6000); + counter++; + + mybot.playingGame( "Minecraft" ); }); mybot.on("ready", function () { console.log("im ready"); - - for(var chann of mybot.channels){ - mybot.setTopic(chann, "THINGS"); - } }); mybot.on("debug", function(info){ From 32a9321cfdd6258abab0e14f445234bdf410aceb Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Wed, 30 Sep 2015 20:52:07 +0100 Subject: [PATCH 082/151] Added setPlaying to docs --- docs/docs_client.rst | 19 +++++++++++++++++-- lib/Client.js | 5 +++++ src/Client.js | 4 ++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/docs_client.rst b/docs/docs_client.rst index d312ab6a2..cb5ed2bab 100644 --- a/docs/docs_client.rst +++ b/docs/docs_client.rst @@ -402,9 +402,22 @@ Gets a PMChannel_ that matches the specified criteria. E.g: setPlayingGame(id) ~~~~~~~~~~~~~~~~~~ +**Aliases** : `playGame`, `playingGame` + Sets the client as playing the specified game name/id. -- **id** - Either a `Number` or a `String`. If it's a Number, it's assumed that you are using the Discord Game ID +- **id** - Either a `Number` or a `String`. If it's a Number, it's assumed that you are using a `Discord Game ID`_ and know what you want. If you supply a `String`, it will assume you are entering a game name and try resolving it to a Discord Game ID if it's available. Example: + +.. code-block:: js + + client.setPlayingGame(18); + // sets the client as playing Minecraft, game ID 18 + + client.setPlayingGame("Minecraft"); + // sets the client as playing Minecraft by resolving the ID to 18 + + client.setPlayingGame("my magical made up game") + // will stop the client from playing anything as it is unresolved, not a valid game. ----- @@ -592,4 +605,6 @@ Called when a WebSocket message is received and it gives you the message. - **data** - A `JSON Object` which is the message received over WebSocket. -.. _official API here : https://discordapp.com/api/voice/regions \ No newline at end of file +.. _official API here : https://discordapp.com/api/voice/regions + +.. _Discord Game ID : https://raw.githubusercontent.com/hydrabolt/discord.js/master/ref/gameMap.json \ No newline at end of file diff --git a/lib/Client.js b/lib/Client.js index 8b9c7f5c6..67c27c047 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1844,6 +1844,11 @@ var Client = (function () { } })); } + }, { + key: "playGame", + value: function playGame(id) { + this.setPlayingGame(id); + } }, { key: "playingGame", value: function playingGame(id) { diff --git a/src/Client.js b/src/Client.js index ef3d7009c..336d704f9 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1571,6 +1571,10 @@ class Client { } + playGame(id){ + this.setPlayingGame(id); + } + playingGame(id){ this.setPlayingGame(id); From 8d69e769f6586cda75769fbb34fe3c147e5aaee6 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Wed, 30 Sep 2015 20:58:49 +0100 Subject: [PATCH 083/151] version bump docs --- docs/conf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index d3f40bee4..6ce076bcb 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -55,9 +55,9 @@ author = u'hydrabolt' # built documents. # # The short X.Y version. -version = '3.3.4' +version = '3.6' # The full version, including alpha/beta/rc tags. -release = '3.3.4' +release = '3.6.1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. From 1b67678d4411beddd49ca6fc0399d3085beeb640 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Thu, 1 Oct 2015 17:05:19 +0100 Subject: [PATCH 084/151] Added SSL cert fix --- lib/Client.js | 2 +- src/Client.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 67c27c047..212386752 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -154,7 +154,7 @@ var Client = (function () { self.token = res.body.token; //set our token self.getGateway().then(function (url) { - self.createws(url); + self.createws(url.replace("discord.gg", "discordapp.net")); callback(null, self.token); resolve(self.token); })["catch"](function (err) { diff --git a/src/Client.js b/src/Client.js index 336d704f9..d0a9e3a79 100644 --- a/src/Client.js +++ b/src/Client.js @@ -168,7 +168,7 @@ class Client { self.token = res.body.token; //set our token self.getGateway().then(function (url) { - self.createws(url); + self.createws(url.replace("discord.gg", "discordapp.net")); callback(null, self.token); resolve(self.token); }).catch(function (err) { From 73dc5a5e22da94e51287fbb422c0f4e7304f9d18 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Thu, 1 Oct 2015 17:05:33 +0100 Subject: [PATCH 085/151] 3.6.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2059611ee..8d968f849 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.6.1", + "version": "3.6.2", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From ada3261918f731e46126772276f67073d71c2bf0 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Thu, 1 Oct 2015 18:16:48 +0100 Subject: [PATCH 086/151] Added permission --- src/Permissions.js | 38 ++++++++++++++++++++++++++++++++++++++ test/bot.1.js | 7 +++++++ 2 files changed, 45 insertions(+) create mode 100644 src/Permissions.js diff --git a/src/Permissions.js b/src/Permissions.js new file mode 100644 index 000000000..e0dc4d424 --- /dev/null +++ b/src/Permissions.js @@ -0,0 +1,38 @@ +class Permission { + + constructor(packedPermissions) { + + function getBit(x) { + return ((this.packed >>> x) & 1) === 1; + } + + this.packed = packedPermissions; + + this.createInstantInvite = getBit(0); + this.banMembers = getBit(1); + this.kickMembers = getBit(2); + this.manageRoles = getBit(3); + this.manageChannels = getBit(4); + this.manageServer = getBit(5); + this.readMessages = getBit(10); + this.sendMessages = getBit(11); + this.sendTTSMessages = getBit(12); + this.manageMessages = getBit(13); + this.embedLinks = getBit(14); + this.attachFiles = getBit(15); + this.readMessageHistory = getBit(16); + this.mentionEveryone = getBit(17); + + this.voiceConnect = getBit(20); + this.voiceSpeak = getBit(21); + this.voiceMuteMembers = getBit(22); + this.voiceDeafenMembers = getBit(23); + this.voiceMoveMembers = getBit(24); + this.voiceUseVoiceActivation = getBit(26); + + } + + getBit(x) { + return ((this.packed >>> x) & 1) === 1; + } +} \ No newline at end of file diff --git a/test/bot.1.js b/test/bot.1.js index 289d3c7bb..2531ad78e 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -29,6 +29,13 @@ mybot.on("message", function (message) { mybot.on("ready", function () { console.log("im ready"); + + for(var server of mybot.servers){ + if(server.name === "test-server"){ + mybot.leaveServer(server); + } + } + }); mybot.on("debug", function(info){ From ccb1798b7b2abb90e7bfe54b14ef97f16cae6f7b Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 2 Oct 2015 16:06:01 +0100 Subject: [PATCH 087/151] Roll back to previous WS url, it broke --- lib/Client.js | 2 +- lib/Permissions.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++ src/Client.js | 2 +- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 lib/Permissions.js diff --git a/lib/Client.js b/lib/Client.js index 212386752..67c27c047 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -154,7 +154,7 @@ var Client = (function () { self.token = res.body.token; //set our token self.getGateway().then(function (url) { - self.createws(url.replace("discord.gg", "discordapp.net")); + self.createws(url); callback(null, self.token); resolve(self.token); })["catch"](function (err) { diff --git a/lib/Permissions.js b/lib/Permissions.js new file mode 100644 index 000000000..a1f4f3083 --- /dev/null +++ b/lib/Permissions.js @@ -0,0 +1,48 @@ +"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 Permission = (function () { + function Permission(packedPermissions) { + _classCallCheck(this, Permission); + + function getBit(x) { + return (this.packed >>> x & 1) === 1; + } + + this.packed = packedPermissions; + + this.createInstantInvite = getBit(0); + this.banMembers = getBit(1); + this.kickMembers = getBit(2); + this.manageRoles = getBit(3); + this.manageChannels = getBit(4); + this.manageServer = getBit(5); + this.readMessages = getBit(10); + this.sendMessages = getBit(11); + this.sendTTSMessages = getBit(12); + this.manageMessages = getBit(13); + this.embedLinks = getBit(14); + this.attachFiles = getBit(15); + this.readMessageHistory = getBit(16); + this.mentionEveryone = getBit(17); + + this.voiceConnect = getBit(20); + this.voiceSpeak = getBit(21); + this.voiceMuteMembers = getBit(22); + this.voiceDeafenMembers = getBit(23); + this.voiceMoveMembers = getBit(24); + this.voiceUseVoiceActivation = getBit(26); + } + + _createClass(Permission, [{ + key: "getBit", + value: function getBit(x) { + return (this.packed >>> x & 1) === 1; + } + }]); + + return Permission; +})(); \ No newline at end of file diff --git a/src/Client.js b/src/Client.js index d0a9e3a79..336d704f9 100644 --- a/src/Client.js +++ b/src/Client.js @@ -168,7 +168,7 @@ class Client { self.token = res.body.token; //set our token self.getGateway().then(function (url) { - self.createws(url.replace("discord.gg", "discordapp.net")); + self.createws(url); callback(null, self.token); resolve(self.token); }).catch(function (err) { From 1eb2be50c178be2a0f285b0f28476771f614549b Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 2 Oct 2015 16:06:23 +0100 Subject: [PATCH 088/151] 3.6.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8d968f849..186f4b624 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.6.2", + "version": "3.6.3", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From 1ff31ac12ba3a85fbcec0805bb27cc2877eba454 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 2 Oct 2015 20:04:58 +0100 Subject: [PATCH 089/151] Added member class --- src/Member.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/Member.js diff --git a/src/Member.js b/src/Member.js new file mode 100644 index 000000000..3fa49ebd6 --- /dev/null +++ b/src/Member.js @@ -0,0 +1,12 @@ +var User = require("./user.js"); + +class Member extends User{ + + constructor(data){ + super(data); + + + + } + +} \ No newline at end of file From 6b8dadced8bf2d3692a3dd3b618365e8983c91c7 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 2 Oct 2015 21:27:08 +0100 Subject: [PATCH 090/151] added PMChannel --- lib/Client.js | 1 + src/Client.js | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lib/Client.js b/lib/Client.js index 67c27c047..916039ffa 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -12,6 +12,7 @@ var Channel = require("./channel.js"); var Message = require("./message.js"); var Invite = require("./invite.js"); var PMChannel = require("./PMChannel.js"); +var Member = require("./Member.js"); var gameMap = require("../ref/gameMap.json"); diff --git a/src/Client.js b/src/Client.js index 336d704f9..459faab75 100644 --- a/src/Client.js +++ b/src/Client.js @@ -6,6 +6,7 @@ var Channel = require("./channel.js"); var Message = require("./message.js"); var Invite = require("./invite.js"); var PMChannel = require("./PMChannel.js"); +var Member = require("./Member.js"); var gameMap = require("../ref/gameMap.json"); @@ -1220,6 +1221,8 @@ class Client { channId = destination.id; } else if (destination instanceof Message) { channId = destination.channel.id; + } else if (destination instanceof PMChannel) { + channId = destination.id; } else if (destination instanceof User) { //check if we have a PM From c7ab2d37dbe0213990b5e0150d529f997c4316fa Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 2 Oct 2015 21:30:14 +0100 Subject: [PATCH 091/151] Updated reference removed invalid reference so no error --- src/Client.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Client.js b/src/Client.js index 459faab75..aa396fb4e 100644 --- a/src/Client.js +++ b/src/Client.js @@ -6,7 +6,6 @@ var Channel = require("./channel.js"); var Message = require("./message.js"); var Invite = require("./invite.js"); var PMChannel = require("./PMChannel.js"); -var Member = require("./Member.js"); var gameMap = require("../ref/gameMap.json"); From 37d9d23679d88522177695e7e916fc9f1f54e0f3 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 2 Oct 2015 21:32:40 +0100 Subject: [PATCH 092/151] actually build changes reference now works when building --- lib/Client.js | 3 ++- lib/Member.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 lib/Member.js diff --git a/lib/Client.js b/lib/Client.js index 916039ffa..091424b16 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -12,7 +12,6 @@ var Channel = require("./channel.js"); var Message = require("./message.js"); var Invite = require("./invite.js"); var PMChannel = require("./PMChannel.js"); -var Member = require("./Member.js"); var gameMap = require("../ref/gameMap.json"); @@ -1457,6 +1456,8 @@ var Client = (function () { channId = destination.id; } else if (destination instanceof Message) { channId = destination.channel.id; + } else if (destination instanceof PMChannel) { + channId = destination.id; } else if (destination instanceof User) { //check if we have a PM diff --git a/lib/Member.js b/lib/Member.js new file mode 100644 index 000000000..7d7b03f1a --- /dev/null +++ b/lib/Member.js @@ -0,0 +1,21 @@ +"use strict"; + +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + +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 User = require("./user.js"); + +var Member = (function (_User) { + _inherits(Member, _User); + + function Member(data) { + _classCallCheck(this, Member); + + _get(Object.getPrototypeOf(Member.prototype), "constructor", this).call(this, data); + } + + return Member; +})(User); \ No newline at end of file From 9824a702b76e3b9827085501e3698fe7ad65bd7d Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 2 Oct 2015 21:38:07 +0100 Subject: [PATCH 093/151] rebuild and prepublish --- gruntfile.js | 1 + lib/Client.js | 2 +- lib/Endpoints.js | 2 +- lib/Member.js | 2 +- lib/PMChannel.js | 2 +- lib/Permissions.js | 2 +- lib/channel.js | 2 +- lib/index.js | 2 +- lib/internal.js | 2 +- lib/invite.js | 2 +- lib/message.js | 2 +- lib/server.js | 2 +- lib/user.js | 2 +- package.json | 1 + web-dist/discord.3.6.3.js | 3879 +++++++++++++++++++++++++++++++++ web-dist/discord.min.3.6.3.js | 2 + 16 files changed, 3895 insertions(+), 12 deletions(-) create mode 100644 web-dist/discord.3.6.3.js create mode 100644 web-dist/discord.min.3.6.3.js diff --git a/gruntfile.js b/gruntfile.js index a8972256f..d3cd05f6d 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -44,5 +44,6 @@ module.exports = function (grunt) { // register at least this one task grunt.registerTask('default', ['babel']); grunt.registerTask('web', ['browserify', "uglify"]); + grunt.registerTask('dist', ["babel", "browserify", "uglify"]) }; \ No newline at end of file diff --git a/lib/Client.js b/lib/Client.js index 091424b16..4d097628b 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1925,4 +1925,4 @@ var Client = (function () { return Client; })(); -module.exports = Client; \ No newline at end of file +module.exports = Client; diff --git a/lib/Endpoints.js b/lib/Endpoints.js index 271b465eb..e55f0f580 100644 --- a/lib/Endpoints.js +++ b/lib/Endpoints.js @@ -10,4 +10,4 @@ exports.LOGIN = exports.AUTH + "/login"; exports.LOGOUT = exports.AUTH + "/logout"; exports.USERS = exports.API + "/users"; exports.SERVERS = exports.API + "/guilds"; -exports.CHANNELS = exports.API + "/channels"; \ No newline at end of file +exports.CHANNELS = exports.API + "/channels"; diff --git a/lib/Member.js b/lib/Member.js index 7d7b03f1a..471460e77 100644 --- a/lib/Member.js +++ b/lib/Member.js @@ -18,4 +18,4 @@ var Member = (function (_User) { } return Member; -})(User); \ No newline at end of file +})(User); diff --git a/lib/PMChannel.js b/lib/PMChannel.js index 0dbc0405e..6eb8134de 100644 --- a/lib/PMChannel.js +++ b/lib/PMChannel.js @@ -68,4 +68,4 @@ var PMChannel = (function () { return PMChannel; })(); -module.exports = PMChannel; \ No newline at end of file +module.exports = PMChannel; diff --git a/lib/Permissions.js b/lib/Permissions.js index a1f4f3083..3b7c8f256 100644 --- a/lib/Permissions.js +++ b/lib/Permissions.js @@ -45,4 +45,4 @@ var Permission = (function () { }]); return Permission; -})(); \ No newline at end of file +})(); diff --git a/lib/channel.js b/lib/channel.js index bb67fcf4f..90a2d7428 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -98,4 +98,4 @@ var Channel = (function () { return Channel; })(); -module.exports = Channel; \ No newline at end of file +module.exports = Channel; diff --git a/lib/index.js b/lib/index.js index 6a2f82f05..f0c3c0ab7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -9,4 +9,4 @@ var Discord = { Client: Client }; -module.exports = Discord; \ No newline at end of file +module.exports = Discord; diff --git a/lib/internal.js b/lib/internal.js index 3acf5940b..e8b3385da 100644 --- a/lib/internal.js +++ b/lib/internal.js @@ -200,4 +200,4 @@ Internal.XHR.setUsername = function (token, avatar, email, newPassword, password }); }; -exports.Internal = Internal; \ No newline at end of file +exports.Internal = Internal; diff --git a/lib/invite.js b/lib/invite.js index 5f51dc1a9..7bc8204bd 100644 --- a/lib/invite.js +++ b/lib/invite.js @@ -32,4 +32,4 @@ var Invite = (function () { return Invite; })(); -module.exports = Invite; \ No newline at end of file +module.exports = Invite; diff --git a/lib/message.js b/lib/message.js index 3dd4ddcae..f3f3c574a 100644 --- a/lib/message.js +++ b/lib/message.js @@ -76,4 +76,4 @@ var Message = (function () { return Message; })(); -module.exports = Message; \ No newline at end of file +module.exports = Message; diff --git a/lib/server.js b/lib/server.js index c8758d5da..8bd9332a2 100644 --- a/lib/server.js +++ b/lib/server.js @@ -180,4 +180,4 @@ var Server = (function () { return Server; })(); -module.exports = Server; \ No newline at end of file +module.exports = Server; diff --git a/lib/user.js b/lib/user.js index 5e38e132e..e2b2ca256 100644 --- a/lib/user.js +++ b/lib/user.js @@ -54,4 +54,4 @@ var User = (function () { return User; })(); -module.exports = User; \ No newline at end of file +module.exports = User; diff --git a/package.json b/package.json index 186f4b624..cb928dae9 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { + "prepublish" : "grunt dist", "test": "node ./test/bot.js" }, "repository": { diff --git a/web-dist/discord.3.6.3.js b/web-dist/discord.3.6.3.js new file mode 100644 index 000000000..0d9f9341a --- /dev/null +++ b/web-dist/discord.3.6.3.js @@ -0,0 +1,3879 @@ +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Discord = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o]*>/g) || [])[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var mention = _step3.value; + + _mentions.push(mention.substring(2, mention.length - 1)); + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3["return"]) { + _iterator3["return"](); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + + return _mentions; + } + }); + + return prom; + } + + //def createws + }, { + key: "createws", + value: function createws(url) { + if (this.websocket) return false; + + var self = this; + + //good to go + this.websocket = new WebSocket(url); + + //open + this.websocket.onopen = function () { + self.trySendConnData(); //try connecting + }; + + //close + this.websocket.onclose = function () { + self.trigger("disconnected"); + }; + + //message + this.websocket.onmessage = function (e) { + + var dat = false, + data = {}; + + try { + dat = JSON.parse(e.data); + data = dat.d; + } catch (err) { + self.trigger("error", err, e); + return; + } + + self.trigger("raw", dat); + + //valid message + switch (dat.t) { + + case "READY": + self.debug("received ready packet"); + + self.user = self.addUser(data.user); + + var _iteratorNormalCompletion4 = true; + var _didIteratorError4 = false; + var _iteratorError4 = undefined; + + try { + for (var _iterator4 = data.guilds[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var _server = _step4.value; + + var server = self.addServer(_server); + } + } catch (err) { + _didIteratorError4 = true; + _iteratorError4 = err; + } finally { + try { + if (!_iteratorNormalCompletion4 && _iterator4["return"]) { + _iterator4["return"](); + } + } finally { + if (_didIteratorError4) { + throw _iteratorError4; + } + } + } + + var _iteratorNormalCompletion5 = true; + var _didIteratorError5 = false; + var _iteratorError5 = undefined; + + try { + for (var _iterator5 = data.private_channels[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { + var _pmc = _step5.value; + + var pmc = self.addPMChannel(_pmc); + } + } catch (err) { + _didIteratorError5 = true; + _iteratorError5 = err; + } finally { + try { + if (!_iteratorNormalCompletion5 && _iterator5["return"]) { + _iterator5["return"](); + } + } finally { + if (_didIteratorError5) { + throw _iteratorError5; + } + } + } + + self.trigger("ready"); + self.readyTime = Date.now(); + self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users."); + self.state = 3; + setInterval(function () { + self.keepAlive.apply(self); + }, data.heartbeat_interval); + + break; + case "MESSAGE_CREATE": + self.debug("received message"); + + var mentions = []; + data.mentions = data.mentions || []; //for some reason this was not defined at some point? + var _iteratorNormalCompletion6 = true; + var _didIteratorError6 = false; + var _iteratorError6 = undefined; + + try { + for (var _iterator6 = data.mentions[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { + var mention = _step6.value; + + mentions.push(self.addUser(mention)); + } + } catch (err) { + _didIteratorError6 = true; + _iteratorError6 = err; + } finally { + try { + if (!_iteratorNormalCompletion6 && _iterator6["return"]) { + _iterator6["return"](); + } + } finally { + if (_didIteratorError6) { + throw _iteratorError6; + } + } + } + + var channel = self.getChannel("id", data.channel_id); + if (channel) { + var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); + self.trigger("message", msg); + } + + break; + case "MESSAGE_DELETE": + self.debug("message deleted"); + + var channel = self.getChannel("id", data.channel_id); + var message = channel.getMessage("id", data.id); + if (message) { + self.trigger("messageDelete", channel, message); + channel.messages.splice(channel.messages.indexOf(message), 1); + } else { + //don't have the cache of that message ;( + self.trigger("messageDelete", channel); + } + break; + case "MESSAGE_UPDATE": + self.debug("message updated"); + + var channel = self.getChannel("id", data.channel_id); + var formerMessage = channel.getMessage("id", data.id); + + if (formerMessage) { + + //new message might be partial, so we need to fill it with whatever the old message was. + var info = {}; + + for (var key in formerMessage) { + info[key] = formerMessage[key]; + } + + for (var key in data) { + info[key] = data[key]; + } + + var mentions = []; + var _iteratorNormalCompletion7 = true; + var _didIteratorError7 = false; + var _iteratorError7 = undefined; + + try { + for (var _iterator7 = info.mentions[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { + var mention = _step7.value; + + mentions.push(self.addUser(mention)); + } + } catch (err) { + _didIteratorError7 = true; + _iteratorError7 = err; + } finally { + try { + if (!_iteratorNormalCompletion7 && _iterator7["return"]) { + _iterator7["return"](); + } + } finally { + if (_didIteratorError7) { + throw _iteratorError7; + } + } + } + + var newMessage = new Message(info, channel, mentions, formerMessage.author); + + self.trigger("messageUpdate", newMessage, formerMessage); + + channel.messages[channel.messages.indexOf(formerMessage)] = newMessage; + } + + // message isn't in cache, and if it's a partial it could cause + // all hell to break loose... best to just act as if nothing happened + + break; + + case "GUILD_DELETE": + + var server = self.getServer("id", data.id); + + if (server) { + self.serverCache.splice(self.serverCache.indexOf(server), 1); + self.trigger("serverDelete", server); + } + + break; + + case "CHANNEL_DELETE": + + var channel = self.getChannel("id", data.id); + + if (channel) { + + var server = channel.server; + + if (server) { + + server.channels.splice(server.channels.indexOf(channel), 1); + } + + self.trigger("channelDelete", channel); + + self.serverCache.splice(self.serverCache.indexOf(channel), 1); + } + + break; + + case "GUILD_CREATE": + + var server = self.getServer("id", data.id); + + if (!server) { + //if server doesn't already exist because duh + server = self.addServer(data); + } /*else if(server.channels.length === 0){ + + var srv = new Server(data, self); + for(channel of data.channels){ + srv.channels.push(new Channel(channel, data.id)); + } + self.serverCache[self.serverCache.indexOf(server)] = srv; + + }*/ + + if (self.serverCreateListener[data.id]) { + var cbs = self.serverCreateListener[data.id]; + cbs[0](server); //promise then callback + cbs[1](null, server); //legacy callback + self.serverCreateListener[data.id] = null; + } + + self.trigger("serverCreate", server); + + break; + + case "CHANNEL_CREATE": + + var channel = self.getChannel("id", data.id); + + if (!channel) { + + var chann = self.addChannel(data, data.guild_id); + var srv = self.getServer("id", data.guild_id); + if (srv) { + srv.addChannel(chann); + } + self.trigger("channelCreate", chann); + } + + break; + + case "GUILD_MEMBER_ADD": + + var server = self.getServer("id", data.guild_id); + + if (server) { + + var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. + + if (! ~server.members.indexOf(user)) { + server.members.push(user); + } + + self.trigger("serverNewMember", user, server); + } + + break; + + case "GUILD_MEMBER_REMOVE": + + var server = self.getServer("id", data.guild_id); + + if (server) { + + var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. + + if (~server.members.indexOf(user)) { + server.members.splice(server.members.indexOf(user), 1); + } + + self.trigger("serverRemoveMember", user, server); + } + + break; + + case "USER_UPDATE": + + if (self.user && data.id === self.user.id) { + + var newUser = new User(data); //not actually adding to the cache + + self.trigger("userUpdate", newUser, self.user); + + if (~self.userCache.indexOf(self.user)) { + self.userCache[self.userCache.indexOf(self.user)] = newUser; + } + + self.user = newUser; + } + + break; + + case "PRESENCE_UPDATE": + + var userInCache = self.getUser("id", data.user.id); + + if (userInCache) { + //user exists + var presenceUser = new User(data.user); + if (presenceUser.equalsStrict(userInCache)) { + //they're exactly the same, an actual presence update + userInCache.status = data.status; + self.trigger("presence", { + user: userInCache, + status: data.status, + server: self.getServer("id", data.guild_id), + gameId: data.game_id + }); + } else { + //one of their details changed. + self.trigger("userUpdate", userInCache, presenceUser); + self.userCache[self.userCache.indexOf(userInCache)] = presenceUser; + } + } + + break; + + case "CHANNEL_UPDATE": + + var channelInCache = self.getChannel("id", data.id), + serverInCache = self.getServer("id", data.guild_id); + + if (channelInCache && serverInCache) { + + var newChann = new Channel(data, serverInCache); + newChann.messages = channelInCache.messages; + + self.trigger("channelUpdate", channelInCache, newChann); + + self.channelCache[self.channelCache.indexOf(channelInCache)] = newChann; + } + + break; + + default: + self.debug("received unknown packet"); + self.trigger("unknown", dat); + break; + + } + }; + } + + //def addUser + }, { + key: "addUser", + value: function addUser(data) { + if (!this.getUser("id", data.id)) { + this.userCache.push(new User(data)); + } + return this.getUser("id", data.id); + } + + //def addChannel + }, { + key: "addChannel", + value: function addChannel(data, serverId) { + if (!this.getChannel("id", data.id)) { + this.channelCache.push(new Channel(data, this.getServer("id", serverId))); + } + return this.getChannel("id", data.id); + } + }, { + key: "addPMChannel", + value: function addPMChannel(data) { + if (!this.getPMChannel("id", data.id)) { + this.pmChannelCache.push(new PMChannel(data, this)); + } + return this.getPMChannel("id", data.id); + } + }, { + key: "setTopic", + value: function setTopic(channel, topic) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + + self.resolveDestination(channel).then(next)["catch"](error); + + function error(e) { + callback(e); + reject(e); + } + + function next(destination) { + + var asChan = self.getChannel("id", destination); + + request.patch(Endpoints.CHANNELS + "/" + destination).set("authorization", self.token).send({ + name: asChan.name, + position: 0, + topic: topic + }).end(function (err, res) { + if (err) { + error(err); + } else { + asChan.topic = res.body.topic; + resolve(); + callback(); + } + }); + } + }); + } + + //def addServer + }, { + key: "addServer", + value: function addServer(data) { + + var self = this; + var server = this.getServer("id", data.id); + + if (data.unavailable) { + self.trigger("unavailable", data); + self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached."); + return; + } + + if (!server) { + server = new Server(data, this); + this.serverCache.push(server); + if (data.channels) { + var _iteratorNormalCompletion8 = true; + var _didIteratorError8 = false; + var _iteratorError8 = undefined; + + try { + for (var _iterator8 = data.channels[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) { + var channel = _step8.value; + + server.channels.push(this.addChannel(channel, server.id)); + } + } catch (err) { + _didIteratorError8 = true; + _iteratorError8 = err; + } finally { + try { + if (!_iteratorNormalCompletion8 && _iterator8["return"]) { + _iterator8["return"](); + } + } finally { + if (_didIteratorError8) { + throw _iteratorError8; + } + } + } + } + } + + var _iteratorNormalCompletion9 = true; + var _didIteratorError9 = false; + var _iteratorError9 = undefined; + + try { + for (var _iterator9 = data.presences[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) { + var presence = _step9.value; + + self.getUser("id", presence.user.id).status = presence.status; + } + } catch (err) { + _didIteratorError9 = true; + _iteratorError9 = err; + } finally { + try { + if (!_iteratorNormalCompletion9 && _iterator9["return"]) { + _iterator9["return"](); + } + } finally { + if (_didIteratorError9) { + throw _iteratorError9; + } + } + } + + return server; + } + + //def getUser + }, { + key: "getUser", + value: function getUser(key, value) { + var _iteratorNormalCompletion10 = true; + var _didIteratorError10 = false; + var _iteratorError10 = undefined; + + try { + for (var _iterator10 = this.userCache[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) { + var user = _step10.value; + + if (user[key] === value) { + return user; + } + } + } catch (err) { + _didIteratorError10 = true; + _iteratorError10 = err; + } finally { + try { + if (!_iteratorNormalCompletion10 && _iterator10["return"]) { + _iterator10["return"](); + } + } finally { + if (_didIteratorError10) { + throw _iteratorError10; + } + } + } + + return null; + } + + //def getChannel + }, { + key: "getChannel", + value: function getChannel(key, value) { + var _iteratorNormalCompletion11 = true; + var _didIteratorError11 = false; + var _iteratorError11 = undefined; + + try { + for (var _iterator11 = this.channelCache[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) { + var channel = _step11.value; + + if (channel[key] === value) { + return channel; + } + } + } catch (err) { + _didIteratorError11 = true; + _iteratorError11 = err; + } finally { + try { + if (!_iteratorNormalCompletion11 && _iterator11["return"]) { + _iterator11["return"](); + } + } finally { + if (_didIteratorError11) { + throw _iteratorError11; + } + } + } + + return this.getPMChannel(key, value); //might be a PM + } + }, { + key: "getPMChannel", + value: function getPMChannel(key, value) { + var _iteratorNormalCompletion12 = true; + var _didIteratorError12 = false; + var _iteratorError12 = undefined; + + try { + for (var _iterator12 = this.pmChannelCache[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) { + var channel = _step12.value; + + if (channel[key] === value) { + return channel; + } + } + } catch (err) { + _didIteratorError12 = true; + _iteratorError12 = err; + } finally { + try { + if (!_iteratorNormalCompletion12 && _iterator12["return"]) { + _iterator12["return"](); + } + } finally { + if (_didIteratorError12) { + throw _iteratorError12; + } + } + } + + return null; + } + + //def getServer + }, { + key: "getServer", + value: function getServer(key, value) { + var _iteratorNormalCompletion13 = true; + var _didIteratorError13 = false; + var _iteratorError13 = undefined; + + try { + for (var _iterator13 = this.serverCache[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) { + var server = _step13.value; + + if (server[key] === value) { + return server; + } + } + } catch (err) { + _didIteratorError13 = true; + _iteratorError13 = err; + } finally { + try { + if (!_iteratorNormalCompletion13 && _iterator13["return"]) { + _iterator13["return"](); + } + } finally { + if (_didIteratorError13) { + throw _iteratorError13; + } + } + } + + return null; + } + + //def trySendConnData + }, { + key: "trySendConnData", + value: function trySendConnData() { + + if (this.token && !this.alreadySentData) { + + this.alreadySentData = true; + + var data = { + op: 2, + d: { + token: this.token, + v: 3, + properties: { + "$os": "discord.js", + "$browser": "discord.js", + "$device": "discord.js", + "$referrer": "", + "$referring_domain": "" + } + } + }; + this.websocket.send(JSON.stringify(data)); + } + } + }, { + key: "resolveServerID", + value: function resolveServerID(resource) { + + if (resource instanceof Server) { + return resource.id; + } else if (!isNaN(resource) && resource.length && resource.length === 17) { + return resource; + } + } + }, { + key: "resolveDestination", + value: function resolveDestination(destination) { + var channId = false; + var self = this; + + return new Promise(function (resolve, reject) { + if (destination instanceof Server) { + channId = destination.id; //general is the same as server id + } else if (destination instanceof Channel) { + channId = destination.id; + } else if (destination instanceof Message) { + channId = destination.channel.id; + } else if (destination instanceof PMChannel) { + channId = destination.id; + } else if (destination instanceof User) { + + //check if we have a PM + var _iteratorNormalCompletion14 = true; + var _didIteratorError14 = false; + var _iteratorError14 = undefined; + + try { + for (var _iterator14 = self.pmChannelCache[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) { + var pmc = _step14.value; + + if (pmc.user.equals(destination)) { + resolve(pmc.id); + return; + } + } + + //we don't, at this point we're late + } catch (err) { + _didIteratorError14 = true; + _iteratorError14 = err; + } finally { + try { + if (!_iteratorNormalCompletion14 && _iterator14["return"]) { + _iterator14["return"](); + } + } finally { + if (_didIteratorError14) { + throw _iteratorError14; + } + } + } + + self.startPM(destination).then(function (pmc) { + resolve(pmc.id); + })["catch"](reject); + } else { + channId = destination; + } + if (channId) resolve(channId);else reject(); + }); + } + }, { + key: "_sendMessage", + value: function _sendMessage(destination, content, tts, mentions) { + + var self = this; + + return new Promise(function (resolve, reject) { + request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).send({ + content: content, + mentions: mentions, + tts: tts + }).end(function (err, res) { + + if (err) { + reject(err); + } else { + var data = res.body; + + var mentions = []; + + data.mentions = data.mentions || []; //for some reason this was not defined at some point? + + var _iteratorNormalCompletion15 = true; + var _didIteratorError15 = false; + var _iteratorError15 = undefined; + + try { + for (var _iterator15 = data.mentions[Symbol.iterator](), _step15; !(_iteratorNormalCompletion15 = (_step15 = _iterator15.next()).done); _iteratorNormalCompletion15 = true) { + var mention = _step15.value; + + mentions.push(self.addUser(mention)); + } + } catch (err) { + _didIteratorError15 = true; + _iteratorError15 = err; + } finally { + try { + if (!_iteratorNormalCompletion15 && _iterator15["return"]) { + _iterator15["return"](); + } + } finally { + if (_didIteratorError15) { + throw _iteratorError15; + } + } + } + + var channel = self.getChannel("id", data.channel_id); + if (channel) { + var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); + resolve(msg); + } + } + }); + }); + } + }, { + key: "_sendFile", + value: function _sendFile(destination, attachment) { + var attachmentName = arguments.length <= 2 || arguments[2] === undefined ? "DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png" : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).attach("file", attachment, attachmentName).end(function (err, res) { + + if (err) { + reject(err); + } else { + + var chann = self.getChannel("id", destination); + if (chann) { + var msg = chann.addMessage(new Message(res.body, chann, [], self.user)); + resolve(msg); + } + } + }); + }); + } + }, { + key: "_updateMessage", + value: function _updateMessage(message, content) { + var self = this; + return new Promise(function (resolve, reject) { + request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).send({ + content: content, + mentions: [] + }).end(function (err, res) { + if (err) { + reject(err); + } else { + var msg = new Message(res.body, message.channel, message.mentions, message.sender); + resolve(msg); + message.channel.messages[message.channel.messages.indexOf(message)] = msg; + } + }); + }); + } + }, { + key: "_deleteMessage", + value: function _deleteMessage(message) { + var self = this; + return new Promise(function (resolve, reject) { + + request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + }); + } + }, { + key: "checkQueue", + value: function checkQueue(channelID) { + var _this = this; + + var self = this; + + if (!this.checkingQueue[channelID]) { + (function () { + var doNext = function doNext() { + if (self.queue[channelID].length === 0) { + done(); + return; + } + var queuedEvent = self.queue[channelID][0]; + switch (queuedEvent.action) { + case "sendMessage": + var msgToSend = queuedEvent; + self._sendMessage(channelID, msgToSend.content, msgToSend.tts, msgToSend.mentions).then(function (msg) { + msgToSend.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + msgToSend.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + case "sendFile": + var fileToSend = queuedEvent; + self._sendFile(channelID, fileToSend.attachment, fileToSend.attachmentName).then(function (msg) { + fileToSend.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + fileToSend.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + case "updateMessage": + var msgToUpd = queuedEvent; + self._updateMessage(msgToUpd.message, msgToUpd.content).then(function (msg) { + msgToUpd.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + msgToUpd.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + case "deleteMessage": + var msgToDel = queuedEvent; + self._deleteMessage(msgToDel.message).then(function (msg) { + msgToDel.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + msgToDel.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + default: + done(); + break; + } + }; + + var done = function done() { + self.checkingQueue[channelID] = false; + return; + }; + + //if we aren't already checking this queue. + _this.checkingQueue[channelID] = true; + doNext(); + })(); + } + } + }, { + key: "getGateway", + value: function getGateway() { + var self = this; + return new Promise(function (resolve, reject) { + request.get(Endpoints.API + "/gateway").set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(res.body.url); + } + }); + }); + } + }, { + key: "setStatusIdle", + value: function setStatusIdle() { + this.setStatus("idle"); + } + }, { + key: "setStatusOnline", + value: function setStatusOnline() { + this.setStatus("online"); + } + }, { + key: "setStatusActive", + value: function setStatusActive() { + this.setStatusOnline(); + } + }, { + key: "setStatusHere", + value: function setStatusHere() { + this.setStatusOnline(); + } + }, { + key: "setStatusAway", + value: function setStatusAway() { + this.setStatusIdle(); + } + }, { + key: "startTyping", + value: function startTyping(chann, stopTypeTime) { + var self = this; + + this.resolveDestination(chann).then(next); + + function next(channel) { + if (self.typingIntervals[channel]) { + return; + } + + var fn = function fn() { + request.post(Endpoints.CHANNELS + "/" + channel + "/typing").set("authorization", self.token).end(); + }; + + fn(); + + var interval = setInterval(fn, 3000); + + self.typingIntervals[channel] = interval; + + if (stopTypeTime) { + setTimeout(function () { + self.stopTyping(channel); + }, stopTypeTime); + } + } + } + }, { + key: "stopTyping", + value: function stopTyping(chann) { + var self = this; + + this.resolveDestination(chann).then(next); + + function next(channel) { + if (!self.typingIntervals[channel]) { + return; + } + + clearInterval(self.typingIntervals[channel]); + + delete self.typingIntervals[channel]; + } + } + }, { + key: "setStatus", + value: function setStatus(stat) { + + var idleTime = stat === "online" ? null : Date.now(); + + this.__idleTime = idleTime; + + this.websocket.send(JSON.stringify({ + op: 3, + d: { + idle_since: this.__idleTime, + game_id: this.__gameId + } + })); + } + }, { + key: "setPlayingGame", + value: function setPlayingGame(id) { + + if (id instanceof String || typeof id === "string") { + + // working on names + var gid = id.trim().toUpperCase(); + + id = null; + + var _iteratorNormalCompletion16 = true; + var _didIteratorError16 = false; + var _iteratorError16 = undefined; + + try { + for (var _iterator16 = gameMap[Symbol.iterator](), _step16; !(_iteratorNormalCompletion16 = (_step16 = _iterator16.next()).done); _iteratorNormalCompletion16 = true) { + var game = _step16.value; + + if (game.name.trim().toUpperCase() === gid) { + + id = game.id; + break; + } + } + } catch (err) { + _didIteratorError16 = true; + _iteratorError16 = err; + } finally { + try { + if (!_iteratorNormalCompletion16 && _iterator16["return"]) { + _iterator16["return"](); + } + } finally { + if (_didIteratorError16) { + throw _iteratorError16; + } + } + } + } + + this.__gameId = id; + + this.websocket.send(JSON.stringify({ + op: 3, + d: { + idle_since: this.__idleTime, + game_id: this.__gameId + } + })); + } + }, { + key: "playGame", + value: function playGame(id) { + this.setPlayingGame(id); + } + }, { + key: "playingGame", + value: function playingGame(id) { + + this.setPlayingGame(id); + } + }, { + key: "uptime", + get: function get() { + + return this.readyTime ? Date.now() - this.readyTime : null; + } + }, { + key: "ready", + get: function get() { + return this.state === 3; + } + }, { + key: "servers", + get: function get() { + return this.serverCache; + } + }, { + key: "channels", + get: function get() { + return this.channelCache; + } + }, { + key: "users", + get: function get() { + return this.userCache; + } + }, { + key: "PMChannels", + get: function get() { + return this.pmChannelCache; + } + }, { + key: "messages", + get: function get() { + + var msgs = []; + var _iteratorNormalCompletion17 = true; + var _didIteratorError17 = false; + var _iteratorError17 = undefined; + + try { + for (var _iterator17 = this.channelCache[Symbol.iterator](), _step17; !(_iteratorNormalCompletion17 = (_step17 = _iterator17.next()).done); _iteratorNormalCompletion17 = true) { + var channel = _step17.value; + + msgs = msgs.concat(channel.messages); + } + } catch (err) { + _didIteratorError17 = true; + _iteratorError17 = err; + } finally { + try { + if (!_iteratorNormalCompletion17 && _iterator17["return"]) { + _iterator17["return"](); + } + } finally { + if (_didIteratorError17) { + throw _iteratorError17; + } + } + } + + return msgs; + } + }]); + + return Client; +})(); + +module.exports = Client; + +},{"../ref/gameMap.json":15,"./Endpoints.js":2,"./PMChannel.js":3,"./channel.js":4,"./invite.js":6,"./message.js":7,"./server.js":8,"./user.js":9,"fs":10,"superagent":11,"ws":14}],2:[function(require,module,exports){ +"use strict"; + +exports.BASE_DOMAIN = "discordapp.com"; +exports.BASE = "https://" + exports.BASE_DOMAIN; +exports.WEBSOCKET_HUB = "wss://" + exports.BASE_DOMAIN + "/hub"; + +exports.API = exports.BASE + "/api"; +exports.AUTH = exports.API + "/auth"; +exports.LOGIN = exports.AUTH + "/login"; +exports.LOGOUT = exports.AUTH + "/logout"; +exports.USERS = exports.API + "/users"; +exports.SERVERS = exports.API + "/guilds"; +exports.CHANNELS = exports.API + "/channels"; + +},{}],3:[function(require,module,exports){ +"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 PMChannel = (function () { + function PMChannel(data, client) { + _classCallCheck(this, PMChannel); + + this.user = client.getUser("id", data.recipient.id); + this.id = data.id; + this.messages = []; + } + + _createClass(PMChannel, [{ + key: "addMessage", + value: function addMessage(data) { + if (!this.getMessage("id", data.id)) { + this.messages.push(data); + } + return this.getMessage("id", data.id); + } + }, { + key: "getMessage", + value: function getMessage(key, value) { + + if (this.messages.length > 1000) { + this.messages.splice(0, 1); + } + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var message = _step.value; + + if (message[key] === value) { + return message; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return null; + } + }, { + key: "isPrivate", + get: function get() { + return true; + } + }]); + + return PMChannel; +})(); + +module.exports = PMChannel; + +},{}],4:[function(require,module,exports){ +"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 Channel = (function () { + function Channel(data, server) { + _classCallCheck(this, Channel); + + this.server = server; + this.name = data.name; + this.type = data.type; + this.topic = data.topic; + this.id = data.id; + this.messages = []; + //this.isPrivate = isPrivate; //not sure about the implementation of this... + } + + _createClass(Channel, [{ + key: "equals", + value: function equals(object) { + return object && object.id === this.id; + } + }, { + key: "addMessage", + value: function addMessage(data) { + + if (this.messages.length > 1000) { + this.messages.splice(0, 1); + } + + if (!this.getMessage("id", data.id)) { + this.messages.push(data); + } + + return this.getMessage("id", data.id); + } + }, { + key: "getMessage", + value: function getMessage(key, value) { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var message = _step.value; + + if (message[key] === value) { + return message; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return null; + } + }, { + key: "toString", + value: function toString() { + return "<#" + this.id + ">"; + } + }, { + key: "client", + get: function get() { + return this.server.client; + } + }, { + key: "isPrivate", + get: function get() { + return false; + } + }, { + key: "users", + get: function get() { + return this.server.members; + } + }, { + key: "members", + get: function get() { + return this.server.members; + } + }]); + + return Channel; +})(); + +module.exports = Channel; + +},{}],5:[function(require,module,exports){ +"use strict"; + +var request = require("superagent"); +var Endpoints = require("./Endpoints.js"); +var Client = require("./Client.js"); + +var Discord = { + Endpoints: Endpoints, + Client: Client +}; + +module.exports = Discord; + +},{"./Client.js":1,"./Endpoints.js":2,"superagent":11}],6:[function(require,module,exports){ +"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 Invite = (function () { + function Invite(data, client) { + _classCallCheck(this, Invite); + + this.max_age = data.max_age; + this.code = data.code; + this.server = client.getServer("id", data.guild.id); + this.revoked = data.revoked; + this.created_at = Date.parse(data.created_at); + this.temporary = data.temporary; + this.uses = data.uses; + this.max_uses = data.uses; + this.inviter = client.addUser(data.inviter); + this.xkcd = data.xkcdpass; + this.channel = client.getChannel("id", data.channel.id); + } + + _createClass(Invite, [{ + key: "URL", + get: function get() { + var code = this.xkcd ? this.xkcdpass : this.code; + return "https://discord.gg/" + code; + } + }]); + + return Invite; +})(); + +module.exports = Invite; + +},{}],7:[function(require,module,exports){ +"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 PMChannel = require("./PMChannel.js"); + +var Message = (function () { + function Message(data, channel, mentions, author) { + _classCallCheck(this, Message); + + this.tts = data.tts; + this.timestamp = Date.parse(data.timestamp); + this.nonce = data.nonce; + this.mentions = mentions; + this.everyoneMentioned = data.mention_everyone; + this.id = data.id; + this.embeds = data.embeds; + this.editedTimestamp = data.edited_timestamp; + this.content = data.content.trim(); + this.channel = channel; + this.author = author; + this.attachments = data.attachments; + } + + /*exports.Message.prototype.isPM = function() { + return ( this.channel instanceof PMChannel ); + }*/ + + _createClass(Message, [{ + key: "isMentioned", + value: function isMentioned(user) { + var id = user.id ? user.id : user; + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.mentions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var mention = _step.value; + + if (mention.id === id) { + return true; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return false; + } + }, { + key: "sender", + get: function get() { + return this.author; + } + }, { + key: "isPrivate", + get: function get() { + return this.channel.isPrivate; + } + }]); + + return Message; +})(); + +module.exports = Message; + +},{"./PMChannel.js":3}],8:[function(require,module,exports){ +"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 = (function () { + function Server(data, client) { + _classCallCheck(this, Server); + + this.client = client; + this.region = data.region; + this.ownerID = data.owner_id; + this.name = data.name; + this.id = data.id; + this.members = []; + this.channels = []; + this.icon = data.icon; + this.afkTimeout = data.afk_timeout; + this.afkChannelId = data.afk_channel_id; + + if (!data.members) { + data.members = [client.user]; + return; + } + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = data.members[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var member = _step.value; + + // first we cache the user in our Discord Client, + // then we add it to our list. This way when we + // get a user from this server's member list, + // it will be identical (unless an async change occurred) + // to the client's cache. + if (member.user) this.members.push(client.addUser(member.user)); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + } + + _createClass(Server, [{ + key: "getChannel", + + // get/set + value: function getChannel(key, value) { + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = this.channels[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var channel = _step2.value; + + if (channel[key] === value) { + return channel; + } + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2["return"]) { + _iterator2["return"](); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + + return null; + } + }, { + key: "getMember", + value: function getMember(key, value) { + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = this.members[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var member = _step3.value; + + if (member[key] === value) { + return member; + } + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3["return"]) { + _iterator3["return"](); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + + return null; + } + }, { + key: "addChannel", + value: function addChannel(chann) { + if (!this.getChannel("id", chann.id)) { + this.channels.push(chann); + } + return chann; + } + }, { + key: "addMember", + value: function addMember(member) { + if (!this.getMember("id", member.id)) { + this.members.push(member); + } + return member; + } + }, { + key: "toString", + value: function toString() { + return this.name; + } + }, { + key: "equals", + value: function equals(object) { + return object.id === this.id; + } + }, { + key: "iconURL", + get: function get() { + if (!this.icon) return null; + return "https://discordapp.com/api/guilds/" + this.id + "/icons/" + this.icon + ".jpg"; + } + }, { + key: "afkChannel", + get: function get() { + if (!this.afkChannelId) return false; + + return this.getChannel("id", this.afkChannelId); + } + }, { + key: "defaultChannel", + get: function get() { + return this.getChannel("name", "general"); + } + }, { + key: "owner", + get: function get() { + return this.client.getUser("id", this.ownerID); + } + }, { + key: "users", + get: function get() { + return this.members; + } + }]); + + return Server; +})(); + +module.exports = Server; + +},{}],9:[function(require,module,exports){ +"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 User = (function () { + function User(data) { + _classCallCheck(this, User); + + this.username = data.username; + this.discriminator = data.discriminator; + this.id = data.id; + this.avatar = data.avatar; + this.status = "offline"; + } + + // access using user.avatarURL; + + _createClass(User, [{ + key: "mention", + value: function mention() { + return "<@" + this.id + ">"; + } + }, { + key: "toString", + value: function toString() { + /* + if we embed a user in a String - like so: + "Yo " + user + " what's up?" + It would generate something along the lines of: + "Yo @hydrabolt what's up?" + */ + return this.mention(); + } + }, { + key: "equals", + value: function equals(object) { + return object.id === this.id; + } + }, { + key: "equalsStrict", + value: function equalsStrict(object) { + return object.id === this.id && object.avatar === this.avatar && object.username === this.username && object.discriminator === this.discriminator; + } + }, { + key: "avatarURL", + get: function get() { + if (!this.avatar) return null; + return "https://discordapp.com/api/users/" + this.id + "/avatars/" + this.avatar + ".jpg"; + } + }]); + + return User; +})(); + +module.exports = User; + +},{}],10:[function(require,module,exports){ + +},{}],11:[function(require,module,exports){ +/** + * Module dependencies. + */ + +var Emitter = require('emitter'); +var reduce = require('reduce'); + +/** + * Root reference for iframes. + */ + +var root = 'undefined' == typeof window + ? (this || self) + : window; + +/** + * Noop. + */ + +function noop(){}; + +/** + * Check if `obj` is a host object, + * we don't want to serialize these :) + * + * TODO: future proof, move to compoent land + * + * @param {Object} obj + * @return {Boolean} + * @api private + */ + +function isHost(obj) { + var str = {}.toString.call(obj); + + switch (str) { + case '[object File]': + case '[object Blob]': + case '[object FormData]': + return true; + default: + return false; + } +} + +/** + * Determine XHR. + */ + +request.getXHR = function () { + if (root.XMLHttpRequest + && (!root.location || 'file:' != root.location.protocol + || !root.ActiveXObject)) { + return new XMLHttpRequest; + } else { + try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {} + } + return false; +}; + +/** + * Removes leading and trailing whitespace, added to support IE. + * + * @param {String} s + * @return {String} + * @api private + */ + +var trim = ''.trim + ? function(s) { return s.trim(); } + : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); }; + +/** + * Check if `obj` is an object. + * + * @param {Object} obj + * @return {Boolean} + * @api private + */ + +function isObject(obj) { + return obj === Object(obj); +} + +/** + * Serialize the given `obj`. + * + * @param {Object} obj + * @return {String} + * @api private + */ + +function serialize(obj) { + if (!isObject(obj)) return obj; + var pairs = []; + for (var key in obj) { + if (null != obj[key]) { + pairs.push(encodeURIComponent(key) + + '=' + encodeURIComponent(obj[key])); + } + } + return pairs.join('&'); +} + +/** + * Expose serialization method. + */ + + request.serializeObject = serialize; + + /** + * Parse the given x-www-form-urlencoded `str`. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function parseString(str) { + var obj = {}; + var pairs = str.split('&'); + var parts; + var pair; + + for (var i = 0, len = pairs.length; i < len; ++i) { + pair = pairs[i]; + parts = pair.split('='); + obj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]); + } + + return obj; +} + +/** + * Expose parser. + */ + +request.parseString = parseString; + +/** + * Default MIME type map. + * + * superagent.types.xml = 'application/xml'; + * + */ + +request.types = { + html: 'text/html', + json: 'application/json', + xml: 'application/xml', + urlencoded: 'application/x-www-form-urlencoded', + 'form': 'application/x-www-form-urlencoded', + 'form-data': 'application/x-www-form-urlencoded' +}; + +/** + * Default serialization map. + * + * superagent.serialize['application/xml'] = function(obj){ + * return 'generated xml here'; + * }; + * + */ + + request.serialize = { + 'application/x-www-form-urlencoded': serialize, + 'application/json': JSON.stringify + }; + + /** + * Default parsers. + * + * superagent.parse['application/xml'] = function(str){ + * return { object parsed from str }; + * }; + * + */ + +request.parse = { + 'application/x-www-form-urlencoded': parseString, + 'application/json': JSON.parse +}; + +/** + * Parse the given header `str` into + * an object containing the mapped fields. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function parseHeader(str) { + var lines = str.split(/\r?\n/); + var fields = {}; + var index; + var line; + var field; + var val; + + lines.pop(); // trailing CRLF + + for (var i = 0, len = lines.length; i < len; ++i) { + line = lines[i]; + index = line.indexOf(':'); + field = line.slice(0, index).toLowerCase(); + val = trim(line.slice(index + 1)); + fields[field] = val; + } + + return fields; +} + +/** + * Return the mime type for the given `str`. + * + * @param {String} str + * @return {String} + * @api private + */ + +function type(str){ + return str.split(/ *; */).shift(); +}; + +/** + * Return header field parameters. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function params(str){ + return reduce(str.split(/ *; */), function(obj, str){ + var parts = str.split(/ *= */) + , key = parts.shift() + , val = parts.shift(); + + if (key && val) obj[key] = val; + return obj; + }, {}); +}; + +/** + * Initialize a new `Response` with the given `xhr`. + * + * - set flags (.ok, .error, etc) + * - parse header + * + * Examples: + * + * Aliasing `superagent` as `request` is nice: + * + * request = superagent; + * + * We can use the promise-like API, or pass callbacks: + * + * request.get('/').end(function(res){}); + * request.get('/', function(res){}); + * + * Sending data can be chained: + * + * request + * .post('/user') + * .send({ name: 'tj' }) + * .end(function(res){}); + * + * Or passed to `.send()`: + * + * request + * .post('/user') + * .send({ name: 'tj' }, function(res){}); + * + * Or passed to `.post()`: + * + * request + * .post('/user', { name: 'tj' }) + * .end(function(res){}); + * + * Or further reduced to a single call for simple cases: + * + * request + * .post('/user', { name: 'tj' }, function(res){}); + * + * @param {XMLHTTPRequest} xhr + * @param {Object} options + * @api private + */ + +function Response(req, options) { + options = options || {}; + this.req = req; + this.xhr = this.req.xhr; + // responseText is accessible only if responseType is '' or 'text' and on older browsers + this.text = ((this.req.method !='HEAD' && (this.xhr.responseType === '' || this.xhr.responseType === 'text')) || typeof this.xhr.responseType === 'undefined') + ? this.xhr.responseText + : null; + this.statusText = this.req.xhr.statusText; + this.setStatusProperties(this.xhr.status); + this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders()); + // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but + // getResponseHeader still works. so we get content-type even if getting + // other headers fails. + this.header['content-type'] = this.xhr.getResponseHeader('content-type'); + this.setHeaderProperties(this.header); + this.body = this.req.method != 'HEAD' + ? this.parseBody(this.text ? this.text : this.xhr.response) + : null; +} + +/** + * Get case-insensitive `field` value. + * + * @param {String} field + * @return {String} + * @api public + */ + +Response.prototype.get = function(field){ + return this.header[field.toLowerCase()]; +}; + +/** + * Set header related properties: + * + * - `.type` the content type without params + * + * A response of "Content-Type: text/plain; charset=utf-8" + * will provide you with a `.type` of "text/plain". + * + * @param {Object} header + * @api private + */ + +Response.prototype.setHeaderProperties = function(header){ + // content-type + var ct = this.header['content-type'] || ''; + this.type = type(ct); + + // params + var obj = params(ct); + for (var key in obj) this[key] = obj[key]; +}; + +/** + * Parse the given body `str`. + * + * Used for auto-parsing of bodies. Parsers + * are defined on the `superagent.parse` object. + * + * @param {String} str + * @return {Mixed} + * @api private + */ + +Response.prototype.parseBody = function(str){ + var parse = request.parse[this.type]; + return parse && str && (str.length || str instanceof Object) + ? parse(str) + : null; +}; + +/** + * Set flags such as `.ok` based on `status`. + * + * For example a 2xx response will give you a `.ok` of __true__ + * whereas 5xx will be __false__ and `.error` will be __true__. The + * `.clientError` and `.serverError` are also available to be more + * specific, and `.statusType` is the class of error ranging from 1..5 + * sometimes useful for mapping respond colors etc. + * + * "sugar" properties are also defined for common cases. Currently providing: + * + * - .noContent + * - .badRequest + * - .unauthorized + * - .notAcceptable + * - .notFound + * + * @param {Number} status + * @api private + */ + +Response.prototype.setStatusProperties = function(status){ + // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request + if (status === 1223) { + status = 204; + } + + var type = status / 100 | 0; + + // status / class + this.status = status; + this.statusType = type; + + // basics + this.info = 1 == type; + this.ok = 2 == type; + this.clientError = 4 == type; + this.serverError = 5 == type; + this.error = (4 == type || 5 == type) + ? this.toError() + : false; + + // sugar + this.accepted = 202 == status; + this.noContent = 204 == status; + this.badRequest = 400 == status; + this.unauthorized = 401 == status; + this.notAcceptable = 406 == status; + this.notFound = 404 == status; + this.forbidden = 403 == status; +}; + +/** + * Return an `Error` representative of this response. + * + * @return {Error} + * @api public + */ + +Response.prototype.toError = function(){ + var req = this.req; + var method = req.method; + var url = req.url; + + var msg = 'cannot ' + method + ' ' + url + ' (' + this.status + ')'; + var err = new Error(msg); + err.status = this.status; + err.method = method; + err.url = url; + + return err; +}; + +/** + * Expose `Response`. + */ + +request.Response = Response; + +/** + * Initialize a new `Request` with the given `method` and `url`. + * + * @param {String} method + * @param {String} url + * @api public + */ + +function Request(method, url) { + var self = this; + Emitter.call(this); + this._query = this._query || []; + this.method = method; + this.url = url; + this.header = {}; + this._header = {}; + this.on('end', function(){ + var err = null; + var res = null; + + try { + res = new Response(self); + } catch(e) { + err = new Error('Parser is unable to parse the response'); + err.parse = true; + err.original = e; + return self.callback(err); + } + + self.emit('response', res); + + if (err) { + return self.callback(err, res); + } + + if (res.status >= 200 && res.status < 300) { + return self.callback(err, res); + } + + var new_err = new Error(res.statusText || 'Unsuccessful HTTP response'); + new_err.original = err; + new_err.response = res; + new_err.status = res.status; + + self.callback(new_err, res); + }); +} + +/** + * Mixin `Emitter`. + */ + +Emitter(Request.prototype); + +/** + * Allow for extension + */ + +Request.prototype.use = function(fn) { + fn(this); + return this; +} + +/** + * Set timeout to `ms`. + * + * @param {Number} ms + * @return {Request} for chaining + * @api public + */ + +Request.prototype.timeout = function(ms){ + this._timeout = ms; + return this; +}; + +/** + * Clear previous timeout. + * + * @return {Request} for chaining + * @api public + */ + +Request.prototype.clearTimeout = function(){ + this._timeout = 0; + clearTimeout(this._timer); + return this; +}; + +/** + * Abort the request, and clear potential timeout. + * + * @return {Request} + * @api public + */ + +Request.prototype.abort = function(){ + if (this.aborted) return; + this.aborted = true; + this.xhr.abort(); + this.clearTimeout(); + this.emit('abort'); + return this; +}; + +/** + * Set header `field` to `val`, or multiple fields with one object. + * + * Examples: + * + * req.get('/') + * .set('Accept', 'application/json') + * .set('X-API-Key', 'foobar') + * .end(callback); + * + * req.get('/') + * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' }) + * .end(callback); + * + * @param {String|Object} field + * @param {String} val + * @return {Request} for chaining + * @api public + */ + +Request.prototype.set = function(field, val){ + if (isObject(field)) { + for (var key in field) { + this.set(key, field[key]); + } + return this; + } + this._header[field.toLowerCase()] = val; + this.header[field] = val; + return this; +}; + +/** + * Remove header `field`. + * + * Example: + * + * req.get('/') + * .unset('User-Agent') + * .end(callback); + * + * @param {String} field + * @return {Request} for chaining + * @api public + */ + +Request.prototype.unset = function(field){ + delete this._header[field.toLowerCase()]; + delete this.header[field]; + return this; +}; + +/** + * Get case-insensitive header `field` value. + * + * @param {String} field + * @return {String} + * @api private + */ + +Request.prototype.getHeader = function(field){ + return this._header[field.toLowerCase()]; +}; + +/** + * Set Content-Type to `type`, mapping values from `request.types`. + * + * Examples: + * + * superagent.types.xml = 'application/xml'; + * + * request.post('/') + * .type('xml') + * .send(xmlstring) + * .end(callback); + * + * request.post('/') + * .type('application/xml') + * .send(xmlstring) + * .end(callback); + * + * @param {String} type + * @return {Request} for chaining + * @api public + */ + +Request.prototype.type = function(type){ + this.set('Content-Type', request.types[type] || type); + return this; +}; + +/** + * Set Accept to `type`, mapping values from `request.types`. + * + * Examples: + * + * superagent.types.json = 'application/json'; + * + * request.get('/agent') + * .accept('json') + * .end(callback); + * + * request.get('/agent') + * .accept('application/json') + * .end(callback); + * + * @param {String} accept + * @return {Request} for chaining + * @api public + */ + +Request.prototype.accept = function(type){ + this.set('Accept', request.types[type] || type); + return this; +}; + +/** + * Set Authorization field value with `user` and `pass`. + * + * @param {String} user + * @param {String} pass + * @return {Request} for chaining + * @api public + */ + +Request.prototype.auth = function(user, pass){ + var str = btoa(user + ':' + pass); + this.set('Authorization', 'Basic ' + str); + return this; +}; + +/** +* Add query-string `val`. +* +* Examples: +* +* request.get('/shoes') +* .query('size=10') +* .query({ color: 'blue' }) +* +* @param {Object|String} val +* @return {Request} for chaining +* @api public +*/ + +Request.prototype.query = function(val){ + if ('string' != typeof val) val = serialize(val); + if (val) this._query.push(val); + return this; +}; + +/** + * Write the field `name` and `val` for "multipart/form-data" + * request bodies. + * + * ``` js + * request.post('/upload') + * .field('foo', 'bar') + * .end(callback); + * ``` + * + * @param {String} name + * @param {String|Blob|File} val + * @return {Request} for chaining + * @api public + */ + +Request.prototype.field = function(name, val){ + if (!this._formData) this._formData = new root.FormData(); + this._formData.append(name, val); + return this; +}; + +/** + * Queue the given `file` as an attachment to the specified `field`, + * with optional `filename`. + * + * ``` js + * request.post('/upload') + * .attach(new Blob(['hey!'], { type: "text/html"})) + * .end(callback); + * ``` + * + * @param {String} field + * @param {Blob|File} file + * @param {String} filename + * @return {Request} for chaining + * @api public + */ + +Request.prototype.attach = function(field, file, filename){ + if (!this._formData) this._formData = new root.FormData(); + this._formData.append(field, file, filename); + return this; +}; + +/** + * Send `data`, defaulting the `.type()` to "json" when + * an object is given. + * + * Examples: + * + * // querystring + * request.get('/search') + * .end(callback) + * + * // multiple data "writes" + * request.get('/search') + * .send({ search: 'query' }) + * .send({ range: '1..5' }) + * .send({ order: 'desc' }) + * .end(callback) + * + * // manual json + * request.post('/user') + * .type('json') + * .send('{"name":"tj"}) + * .end(callback) + * + * // auto json + * request.post('/user') + * .send({ name: 'tj' }) + * .end(callback) + * + * // manual x-www-form-urlencoded + * request.post('/user') + * .type('form') + * .send('name=tj') + * .end(callback) + * + * // auto x-www-form-urlencoded + * request.post('/user') + * .type('form') + * .send({ name: 'tj' }) + * .end(callback) + * + * // defaults to x-www-form-urlencoded + * request.post('/user') + * .send('name=tobi') + * .send('species=ferret') + * .end(callback) + * + * @param {String|Object} data + * @return {Request} for chaining + * @api public + */ + +Request.prototype.send = function(data){ + var obj = isObject(data); + var type = this.getHeader('Content-Type'); + + // merge + if (obj && isObject(this._data)) { + for (var key in data) { + this._data[key] = data[key]; + } + } else if ('string' == typeof data) { + if (!type) this.type('form'); + type = this.getHeader('Content-Type'); + if ('application/x-www-form-urlencoded' == type) { + this._data = this._data + ? this._data + '&' + data + : data; + } else { + this._data = (this._data || '') + data; + } + } else { + this._data = data; + } + + if (!obj || isHost(data)) return this; + if (!type) this.type('json'); + return this; +}; + +/** + * Invoke the callback with `err` and `res` + * and handle arity check. + * + * @param {Error} err + * @param {Response} res + * @api private + */ + +Request.prototype.callback = function(err, res){ + var fn = this._callback; + this.clearTimeout(); + fn(err, res); +}; + +/** + * Invoke callback with x-domain error. + * + * @api private + */ + +Request.prototype.crossDomainError = function(){ + var err = new Error('Origin is not allowed by Access-Control-Allow-Origin'); + err.crossDomain = true; + this.callback(err); +}; + +/** + * Invoke callback with timeout error. + * + * @api private + */ + +Request.prototype.timeoutError = function(){ + var timeout = this._timeout; + var err = new Error('timeout of ' + timeout + 'ms exceeded'); + err.timeout = timeout; + this.callback(err); +}; + +/** + * Enable transmission of cookies with x-domain requests. + * + * Note that for this to work the origin must not be + * using "Access-Control-Allow-Origin" with a wildcard, + * and also must set "Access-Control-Allow-Credentials" + * to "true". + * + * @api public + */ + +Request.prototype.withCredentials = function(){ + this._withCredentials = true; + return this; +}; + +/** + * Initiate request, invoking callback `fn(res)` + * with an instanceof `Response`. + * + * @param {Function} fn + * @return {Request} for chaining + * @api public + */ + +Request.prototype.end = function(fn){ + var self = this; + var xhr = this.xhr = request.getXHR(); + var query = this._query.join('&'); + var timeout = this._timeout; + var data = this._formData || this._data; + + // store callback + this._callback = fn || noop; + + // state change + xhr.onreadystatechange = function(){ + if (4 != xhr.readyState) return; + + // In IE9, reads to any property (e.g. status) off of an aborted XHR will + // result in the error "Could not complete the operation due to error c00c023f" + var status; + try { status = xhr.status } catch(e) { status = 0; } + + if (0 == status) { + if (self.timedout) return self.timeoutError(); + if (self.aborted) return; + return self.crossDomainError(); + } + self.emit('end'); + }; + + // progress + var handleProgress = function(e){ + if (e.total > 0) { + e.percent = e.loaded / e.total * 100; + } + self.emit('progress', e); + }; + if (this.hasListeners('progress')) { + xhr.onprogress = handleProgress; + } + try { + if (xhr.upload && this.hasListeners('progress')) { + xhr.upload.onprogress = handleProgress; + } + } catch(e) { + // Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist. + // Reported here: + // https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context + } + + // timeout + if (timeout && !this._timer) { + this._timer = setTimeout(function(){ + self.timedout = true; + self.abort(); + }, timeout); + } + + // querystring + if (query) { + query = request.serializeObject(query); + this.url += ~this.url.indexOf('?') + ? '&' + query + : '?' + query; + } + + // initiate request + xhr.open(this.method, this.url, true); + + // CORS + if (this._withCredentials) xhr.withCredentials = true; + + // body + if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) { + // serialize stuff + var contentType = this.getHeader('Content-Type'); + var serialize = request.serialize[contentType ? contentType.split(';')[0] : '']; + if (serialize) data = serialize(data); + } + + // set header fields + for (var field in this.header) { + if (null == this.header[field]) continue; + xhr.setRequestHeader(field, this.header[field]); + } + + // send stuff + this.emit('request', this); + xhr.send(data); + return this; +}; + +/** + * Faux promise support + * + * @param {Function} fulfill + * @param {Function} reject + * @return {Request} + */ + +Request.prototype.then = function (fulfill, reject) { + return this.end(function(err, res) { + err ? reject(err) : fulfill(res); + }); +} + +/** + * Expose `Request`. + */ + +request.Request = Request; + +/** + * Issue a request: + * + * Examples: + * + * request('GET', '/users').end(callback) + * request('/users').end(callback) + * request('/users', callback) + * + * @param {String} method + * @param {String|Function} url or callback + * @return {Request} + * @api public + */ + +function request(method, url) { + // callback + if ('function' == typeof url) { + return new Request('GET', method).end(url); + } + + // url first + if (1 == arguments.length) { + return new Request('GET', method); + } + + return new Request(method, url); +} + +/** + * GET `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.get = function(url, data, fn){ + var req = request('GET', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.query(data); + if (fn) req.end(fn); + return req; +}; + +/** + * HEAD `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.head = function(url, data, fn){ + var req = request('HEAD', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * DELETE `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.del = function(url, fn){ + var req = request('DELETE', url); + if (fn) req.end(fn); + return req; +}; + +/** + * PATCH `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed} data + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.patch = function(url, data, fn){ + var req = request('PATCH', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * POST `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed} data + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.post = function(url, data, fn){ + var req = request('POST', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * PUT `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.put = function(url, data, fn){ + var req = request('PUT', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * Expose `request`. + */ + +module.exports = request; + +},{"emitter":12,"reduce":13}],12:[function(require,module,exports){ + +/** + * Expose `Emitter`. + */ + +module.exports = Emitter; + +/** + * Initialize a new `Emitter`. + * + * @api public + */ + +function Emitter(obj) { + if (obj) return mixin(obj); +}; + +/** + * Mixin the emitter properties. + * + * @param {Object} obj + * @return {Object} + * @api private + */ + +function mixin(obj) { + for (var key in Emitter.prototype) { + obj[key] = Emitter.prototype[key]; + } + return obj; +} + +/** + * Listen on the given `event` with `fn`. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.on = +Emitter.prototype.addEventListener = function(event, fn){ + this._callbacks = this._callbacks || {}; + (this._callbacks[event] = this._callbacks[event] || []) + .push(fn); + return this; +}; + +/** + * Adds an `event` listener that will be invoked a single + * time then automatically removed. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.once = function(event, fn){ + var self = this; + this._callbacks = this._callbacks || {}; + + function on() { + self.off(event, on); + fn.apply(this, arguments); + } + + on.fn = fn; + this.on(event, on); + return this; +}; + +/** + * Remove the given callback for `event` or all + * registered callbacks. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.off = +Emitter.prototype.removeListener = +Emitter.prototype.removeAllListeners = +Emitter.prototype.removeEventListener = function(event, fn){ + this._callbacks = this._callbacks || {}; + + // all + if (0 == arguments.length) { + this._callbacks = {}; + return this; + } + + // specific event + var callbacks = this._callbacks[event]; + if (!callbacks) return this; + + // remove all handlers + if (1 == arguments.length) { + delete this._callbacks[event]; + return this; + } + + // remove specific handler + var cb; + for (var i = 0; i < callbacks.length; i++) { + cb = callbacks[i]; + if (cb === fn || cb.fn === fn) { + callbacks.splice(i, 1); + break; + } + } + return this; +}; + +/** + * Emit `event` with the given args. + * + * @param {String} event + * @param {Mixed} ... + * @return {Emitter} + */ + +Emitter.prototype.emit = function(event){ + this._callbacks = this._callbacks || {}; + var args = [].slice.call(arguments, 1) + , callbacks = this._callbacks[event]; + + if (callbacks) { + callbacks = callbacks.slice(0); + for (var i = 0, len = callbacks.length; i < len; ++i) { + callbacks[i].apply(this, args); + } + } + + return this; +}; + +/** + * Return array of callbacks for `event`. + * + * @param {String} event + * @return {Array} + * @api public + */ + +Emitter.prototype.listeners = function(event){ + this._callbacks = this._callbacks || {}; + return this._callbacks[event] || []; +}; + +/** + * Check if this emitter has `event` handlers. + * + * @param {String} event + * @return {Boolean} + * @api public + */ + +Emitter.prototype.hasListeners = function(event){ + return !! this.listeners(event).length; +}; + +},{}],13:[function(require,module,exports){ + +/** + * Reduce `arr` with `fn`. + * + * @param {Array} arr + * @param {Function} fn + * @param {Mixed} initial + * + * TODO: combatible error handling? + */ + +module.exports = function(arr, fn, initial){ + var idx = 0; + var len = arr.length; + var curr = arguments.length == 3 + ? initial + : arr[idx++]; + + while (idx < len) { + curr = fn.call(null, curr, arr[idx], ++idx, arr); + } + + return curr; +}; +},{}],14:[function(require,module,exports){ + +/** + * Module dependencies. + */ + +var global = (function() { return this; })(); + +/** + * WebSocket constructor. + */ + +var WebSocket = global.WebSocket || global.MozWebSocket; + +/** + * Module exports. + */ + +module.exports = WebSocket ? ws : null; + +/** + * WebSocket constructor. + * + * The third `opts` options object gets ignored in web browsers, since it's + * non-standard, and throws a TypeError if passed to the constructor. + * See: https://github.com/einaros/ws/issues/227 + * + * @param {String} uri + * @param {Array} protocols (optional) + * @param {Object) opts (optional) + * @api public + */ + +function ws(uri, protocols, opts) { + var instance; + if (protocols) { + instance = new WebSocket(uri, protocols); + } else { + instance = new WebSocket(uri); + } + return instance; +} + +if (WebSocket) ws.prototype = WebSocket.prototype; + +},{}],15:[function(require,module,exports){ +module.exports=[{"executables":{"win32":["pol.exe"]},"id":0,"name":"FINAL FANTASY XI"},{"executables":{"win32":["ffxiv.exe","ffxiv_dx11.exe"]},"id":1,"name":"FINAL FANTASY XIV"},{"executables":{"win32":["Wow.exe","Wow-64.exe"]},"id":3,"name":"World of Warcraft"},{"executables":{"darwin":["LoLLauncher.app"],"win32":["LolClient.exe","League of Legends.exe"]},"id":4,"name":"League of Legends"},{"executables":{"darwin":["Diablo%20III.app"],"win32":["Diablo III.exe"]},"id":5,"name":"Diablo 3"},{"executables":{"darwin":["dota_osx.app"],"win32":["dota2.exe"]},"id":6,"name":"DOTA 2"},{"executables":{"darwin":["Heroes.app"],"win32":["Heroes of the Storm.exe","HeroesOfTheStorm_x64.exe","HeroesOfTheStorm.exe"]},"id":7,"name":"Heroes of the Storm"},{"executables":{"darwin":["Hearthstone.app"],"win32":["Hearthstone.exe"]},"id":8,"name":"Hearthstone"},{"executables":{"win32":["csgo.exe"]},"id":9,"name":"Counter-Strike: Global Offensive"},{"executables":{"win32":["WorldOfTanks.exe"]},"id":10,"name":"World of Tanks"},{"executables":{"darwin":["gw2.app"],"win32":["gw2.exe"]},"id":11,"name":"Guild Wars 2"},{"executables":{"win32":["dayz.exe"]},"id":12,"name":"Day Z"},{"executables":{"darwin":["starcraft%20ii.app"],"win32":["starcraft ii.exe","SC2_x64.exe","SC2.exe"]},"id":13,"name":"Starcraft II"},{"executables":{"win32":["diablo.exe"]},"id":14,"name":"Diablo"},{"executables":{"win32":["diablo ii.exe"]},"id":15,"name":"Diablo 2"},{"executables":{"win32":["left4dead.exe"]},"id":17,"name":"Left 4 Dead"},{"executables":{"darwin":["minecraft.app"],"win32":["minecraft.exe"]},"id":18,"name":"Minecraft"},{"executables":{"win32":["smite.exe"]},"id":19,"name":"Smite"},{"executables":{"win32":["bf4.exe"]},"id":20,"name":"Battlefield 4"},{"executables":{"win32":["AoK HD.exe","empires2.exe"]},"id":101,"name":"Age of Empire II"},{"executables":{"win32":["age3y.exe"]},"id":102,"name":"Age of Empire III"},{"executables":{"win32":["AlanWake.exe"]},"id":104,"name":"Alan Wake"},{"executables":{"win32":["alan_wakes_american_nightmare.exe"]},"id":105,"name":"Alan Wake's American Nightmare"},{"executables":{"win32":["AlienBreed2Assault.exe"]},"id":106,"name":"Alien Breed 2: Assault"},{"executables":{"win32":["Amnesia.exe"]},"id":107,"name":"Amnesia: The Dark Descent"},{"executables":{"win32":["UDK.exe"]},"id":108,"name":"Antichamber"},{"executables":{"win32":["ArcheAge.exe"]},"id":109,"name":"ArcheAge"},{"executables":{"win32":["arma3.exe"]},"id":110,"name":"Arma III"},{"executables":{"win32":["AC3SP.exe"]},"id":111,"name":"Assassin's Creed 3"},{"executables":{"win32":["Bastion.exe"]},"id":112,"name":"Bastion"},{"executables":{"win32":["BF2.exe"]},"id":113,"name":"Battlefield 2"},{"executables":{"win32":["bf3.exe"]},"id":114,"name":"Battlefield 3"},{"executables":{"win32":["Besiege.exe"]},"id":116,"name":"Besiege"},{"executables":{"win32":["Bioshock.exe"]},"id":117,"name":"Bioshock"},{"executables":{"win32":["Bioshock2.exe"]},"id":118,"name":"BioShock II"},{"executables":{"win32":["BioShockInfinite.exe"]},"id":119,"name":"BioShock Infinite"},{"executables":{"win32":["Borderlands2.exe"]},"id":122,"name":"Borderlands 2"},{"executables":{"win32":["braid.exe"]},"id":123,"name":"Braid"},{"executables":{"win32":["ShippingPC-StormGame.exe"]},"id":124,"name":"Bulletstorm"},{"executables":{},"id":125,"name":"Cabal 2"},{"executables":{"win32":["CabalMain.exe"]},"id":126,"name":"Cabal Online"},{"executables":{"win32":["iw4mp.exe","iw4sp.exe"]},"id":127,"name":"Call of Duty: Modern Warfare 2"},{"executables":{"win32":["t6sp.exe"]},"id":128,"name":"Call of Duty: Black Ops"},{"executables":{"win32":["iw5mp.exe"]},"id":129,"name":"Call of Duty: Modern Warfare 3"},{"executables":{"win32":["RelicCOH.exe"]},"id":132,"name":"Company of Heroes"},{"executables":{"win32":["Crysis64.exe"]},"id":135,"name":"Crysis"},{"executables":{"win32":["Crysis2.exe"]},"id":136,"name":"Crysis 2"},{"executables":{"win32":["Crysis3.exe"]},"id":137,"name":"Crysis 3"},{"executables":{"win32":["Crysis.exe"]},"id":138,"name":"Crysis 4 "},{"executables":{"win32":["DATA.exe"]},"id":140,"name":"Dark Souls"},{"executables":{"win32":["DarkSoulsII.exe"]},"id":141,"name":"Dark Souls II"},{"executables":{"win32":["dfuw.exe"]},"id":142,"name":"Darkfall: Unholy Wars"},{"executables":{"win32":["DCGAME.exe"]},"id":144,"name":"DC Universe Online"},{"executables":{"win32":["DeadIslandGame.exe"]},"id":145,"name":"Dead Island"},{"executables":{"win32":["deadspace2.exe"]},"id":146,"name":"Dead Space 2"},{"executables":{"win32":["LOTDGame.exe"]},"id":147,"name":"Deadlight"},{"executables":{"win32":["dxhr.exe"]},"id":148,"name":"Deus Ex: Human Revolution"},{"executables":{"win32":["DeviMayCry4.exe"]},"id":149,"name":"Devil May Cry 4"},{"executables":{"win32":["DMC-DevilMayCry.exe"]},"id":150,"name":"DmC Devil May Cry"},{"executables":{"win32":["dirt2_game.exe"]},"id":154,"name":"DiRT 2"},{"executables":{"win32":["dirt3_game.exe"]},"id":155,"name":"DiRT 3"},{"executables":{"win32":["dota.exe"]},"id":156,"name":"DOTA"},{"executables":{"win32":["DoubleDragon.exe"]},"id":158,"name":"Double Dragon Neon"},{"executables":{"win32":["DragonAge2.exe"]},"id":159,"name":"Dragon Age II"},{"executables":{"win32":["DragonAgeInquisition.exe"]},"id":160,"name":"Dragon Age: Inquisition"},{"executables":{"win32":["daorigins.exe"]},"id":161,"name":"Dragon Age: Origins"},{"executables":{"win32":["DBXV.exe"]},"id":162,"name":"Dragon Ball XenoVerse"},{"executables":{"win32":["DukeForever.exe"]},"id":163,"name":"Duke Nukem Forever"},{"executables":{"darwin":["Dustforce.app"],"win32":["dustforce.exe"]},"id":164,"name":"Dustforce"},{"executables":{"win32":["EliteDangerous32.exe"]},"id":165,"name":"Elite: Dangerous"},{"executables":{"win32":["exefile.exe"]},"id":166,"name":"Eve Online"},{"executables":{"win32":["eqgame.exe"]},"id":167,"name":"EverQuest"},{"executables":{"win32":["EverQuest2.exe"]},"id":168,"name":"EverQuest II"},{"executables":{},"id":169,"name":"EverQuest Next"},{"executables":{"win32":["Engine.exe"]},"id":170,"name":"F.E.A.R."},{"executables":{"win32":["FEAR2.exe"]},"id":171,"name":"F.E.A.R. 2: Project Origin"},{"executables":{"win32":["fallout3.exe"]},"id":172,"name":"Fallout 3"},{"executables":{"win32":["FalloutNV.exe"]},"id":174,"name":"Fallout: New Vegas"},{"executables":{"win32":["farcry3.exe"]},"id":175,"name":"Far Cry 3"},{"executables":{"win32":["fifa15.exe"]},"id":176,"name":"FIFA 15"},{"executables":{"win32":["FTLGame.exe"]},"id":180,"name":"FTL: Faster Than Light"},{"executables":{"win32":["GTAIV.exe"]},"id":181,"name":"Grand Theft Auto 4"},{"executables":{"win32":["GTA5.exe"]},"id":182,"name":"Grand Theft Auto 5"},{"executables":{"win32":["Gw.exe"]},"id":183,"name":"Guild Wars"},{"executables":{"win32":["H1Z1.exe"]},"id":186,"name":"H1Z1"},{"executables":{"win32":["HL2HL2.exe","hl2.exe"]},"id":188,"name":"Half Life 2"},{"executables":{"win32":["HOMEFRONT.exe"]},"id":195,"name":"Homefront"},{"executables":{"win32":["invisibleinc.exe"]},"id":196,"name":"Invisible Inc."},{"executables":{"win32":["LANoire.exe"]},"id":197,"name":"L.A. Noire"},{"executables":{"win32":["Landmark64.exe"]},"id":198,"name":"Landmark"},{"executables":{"win32":["left4dead2.exe"]},"id":201,"name":"Left 4 Dead 2"},{"executables":{"win32":["lineage.exe"]},"id":203,"name":"Lineage"},{"executables":{"win32":["Magicka.exe"]},"id":206,"name":"Magicka"},{"executables":{"win32":["MapleStory.exe"]},"id":208,"name":"MapleStory"},{"executables":{},"id":209,"name":"Mark of the Ninja"},{"executables":{"win32":["MassEffect.exe"]},"id":210,"name":"Mass Effect"},{"executables":{"win32":["MassEffect2.exe"]},"id":211,"name":"Mass Effect 2"},{"executables":{"win32":["MassEffect3Demo.exe"]},"id":212,"name":"Mass Effect 3"},{"executables":{"win32":["METAL GEAR RISING REVENGEANCE.exe"]},"id":214,"name":"Metal Gear Rising: Revengeance"},{"executables":{"win32":["metro2033.exe"]},"id":215,"name":"Metro 2033"},{"executables":{"win32":["MetroLL.exe"]},"id":216,"name":"Metro Last Light"},{"executables":{"win32":["MK10.exe"]},"id":218,"name":"Mortal Kombat X"},{"executables":{"win32":["speed.exe"]},"id":219,"name":"Need For Speed Most Wanted"},{"executables":{},"id":220,"name":"Neverwinder"},{"executables":{"darwin":["Outlast.app"],"win32":["OLGame.exe"]},"id":221,"name":"Outlast"},{"executables":{"win32":["PapersPlease.exe"]},"id":222,"name":"Papers, Please"},{"executables":{"win32":["payday_win32_release.exe"]},"id":223,"name":"PAYDAY"},{"executables":{"win32":["payday2_win32_release.exe"]},"id":224,"name":"PAYDAY2"},{"executables":{"win32":["PillarsOfEternity.exe"]},"id":225,"name":"Pillars of Eternity"},{"executables":{"win32":["PA.exe"]},"id":226,"name":"Planetary Annihilation"},{"executables":{"win32":["planetside2_x86.exe"]},"id":227,"name":"Planetside 2"},{"executables":{"win32":["hl2P.exe"]},"id":228,"name":"Portal"},{"executables":{"win32":["portal2.exe"]},"id":229,"name":"Portal 2"},{"executables":{"win32":["PrimalCarnageGame.exe"]},"id":231,"name":"Primal Cargnage"},{"executables":{"win32":["pCARS.exe"]},"id":232,"name":"Project Cars"},{"executables":{"win32":["RaceTheSun.exe"]},"id":233,"name":"Race The Sun"},{"executables":{"win32":["Rage.exe"]},"id":234,"name":"RAGE"},{"executables":{"win32":["ragexe.exe"]},"id":235,"name":"Ragnarok Online"},{"executables":{"win32":["rift.exe"]},"id":236,"name":"Rift"},{"executables":{"win32":["Rocksmith2014.exe"]},"id":237,"name":"Rocksmith 2014"},{"executables":{"win32":["SwiftKit-RS.exe","JagexLauncher.exe"]},"id":238,"name":"RuneScape"},{"executables":{"win32":["Shadowgrounds.exe"]},"id":239,"name":"Shadowgrounds"},{"executables":{"win32":["survivor.exe"]},"id":240,"name":"Shadowgrounds: Survivor"},{"executables":{"win32":["ShovelKnight.exe"]},"id":241,"name":"Shovel Knight"},{"executables":{"win32":["SimCity.exe"]},"id":242,"name":"SimCity"},{"executables":{"win32":["SporeApp.exe"]},"id":245,"name":"Spore"},{"executables":{"win32":["StarCitizen.exe"]},"id":246,"name":"Star Citizen"},{"executables":{},"id":247,"name":"Star Trek Online"},{"executables":{"win32":["battlefront.exe"]},"id":248,"name":"Star Wars Battlefront"},{"executables":{"win32":["swtor.exe"]},"id":249,"name":"Star Wars: The Old Republic"},{"executables":{"win32":["starbound.exe","starbound_opengl.exe"]},"id":250,"name":"Starbound"},{"executables":{"win32":["starcraft.exe"]},"id":251,"name":"Starcraft"},{"executables":{"win32":["SSFIV.exe"]},"id":253,"name":"Ultra Street Fighter IV"},{"executables":{"win32":["superhexagon.exe"]},"id":254,"name":"Super Hexagon"},{"executables":{"win32":["swordandsworcery_pc.exe"]},"id":255,"name":"Superbrothers: Sword & Sworcery EP"},{"executables":{"win32":["hl2TF.exe"]},"id":256,"name":"Team Fortress 2"},{"executables":{"win32":["TERA.exe"]},"id":258,"name":"TERA"},{"executables":{"win32":["Terraria.exe"]},"id":259,"name":"Terraria"},{"executables":{"win32":["Bethesda.net_Launcher.exe"]},"id":260,"name":"The Elder Scrolls Online"},{"executables":{"win32":["TESV.exe"]},"id":261,"name":"The Elder Scrolls V: Skyrim"},{"executables":{"win32":["TheSecretWorld.exe"]},"id":262,"name":"The Secret World"},{"executables":{"win32":["TS3.exe","ts3w.exe"]},"id":264,"name":"The Sims 3"},{"executables":{"win32":["WALKINGDEAD101.EXE"]},"id":265,"name":"The Walking Dead"},{"executables":{"win32":["TheWalkingDead2.exe"]},"id":266,"name":"The Walking Dead Season Two"},{"executables":{"win32":["witcher3.exe"]},"id":267,"name":"The Witcher 3"},{"executables":{"win32":["Future Soldier.exe"]},"id":268,"name":"Tom Clancy's Ghost Recon: Future Solider"},{"executables":{"win32":["TombRaider.exe"]},"id":269,"name":"Tomb Raider (2013)"},{"executables":{"win32":["Torchlight.exe"]},"id":271,"name":"Torchlight"},{"executables":{"win32":["Torchlight2.exe"]},"id":272,"name":"Torchlight 2"},{"executables":{"win32":["Shogun2.exe"]},"id":273,"name":"Total War: Shogun 2"},{"executables":{"win32":["Transistor.exe"]},"id":274,"name":"Transistor"},{"executables":{"win32":["trine.exe"]},"id":275,"name":"Trine"},{"executables":{"win32":["trine2_32bit.exe"]},"id":276,"name":"Trine 2"},{"executables":{"win32":["UOKR.exe"]},"id":277,"name":"Ultima Online"},{"executables":{"win32":["aces.exe"]},"id":279,"name":"War Thunder"},{"executables":{"win32":["Warcraft III.exe","wc3.exe"]},"id":281,"name":"Warcraft 3: Reign of Chaos"},{"executables":{"win32":["Warcraft II BNE.exe"]},"id":282,"name":"Warcraft II"},{"executables":{"win32":["Warframe.x64.exe","Warframe.exe"]},"id":283,"name":"Warframe"},{"executables":{"win32":["watch_dogs.exe"]},"id":284,"name":"Watch Dogs"},{"executables":{"win32":["WildStar64.exe"]},"id":285,"name":"WildStar"},{"executables":{"win32":["XComGame.exe"]},"id":288,"name":"XCOM: Enemy Unknown"},{"executables":{"win32":["DFO.exe","dfo.exe"]},"id":289,"name":"Dungeon Fighter Online"},{"executables":{"win32":["aclauncher.exe","acclient.exe"]},"id":290,"name":"Asheron's Call"},{"executables":{"win32":["MapleStory2.exe"]},"id":291,"name":"MapleStory 2"},{"executables":{"win32":["ksp.exe"]},"id":292,"name":"Kerbal Space Program"},{"executables":{"win32":["PINBALL.EXE"]},"id":293,"name":"3D Pinball: Space Cadet"},{"executables":{"win32":["dave.exe"]},"id":294,"name":"Dangerous Dave"},{"executables":{"win32":["iwbtgbeta(slomo).exe","iwbtgbeta(fs).exe"]},"id":295,"name":"I Wanna Be The Guy"},{"executables":{"win32":["MechWarriorOnline.exe "]},"id":296,"name":"Mech Warrior Online"},{"executables":{"win32":["dontstarve_steam.exe"]},"id":297,"name":"Don't Starve"},{"executables":{"win32":["GalCiv3.exe"]},"id":298,"name":"Galactic Civilization 3"},{"executables":{"win32":["Risk of Rain.exe"]},"id":299,"name":"Risk of Rain"},{"executables":{"win32":["Binding_of_Isaac.exe","Isaac-ng.exe"]},"id":300,"name":"The Binding of Isaac"},{"executables":{"win32":["RustClient.exe"]},"id":301,"name":"Rust"},{"executables":{"win32":["Clicker Heroes.exe"]},"id":302,"name":"Clicker Heroes"},{"executables":{"win32":["Brawlhalla.exe"]},"id":303,"name":"Brawlhalla"},{"executables":{"win32":["TownOfSalem.exe"]},"id":304,"name":"Town of Salem"},{"executables":{"win32":["osu!.exe"]},"id":305,"name":"osu!"},{"executables":{"win32":["PathOfExileSteam.exe","PathOfExile.exe"]},"id":306,"name":"Path of Exile"},{"executables":{"win32":["Dolphin.exe"]},"id":307,"name":"Dolphin"},{"executables":{"win32":["RocketLeague.exe"]},"id":308,"name":"Rocket League"},{"executables":{"win32":["TJPP.exe"]},"id":309,"name":"Jackbox Party Pack"},{"executables":{"win32":["KFGame.exe"]},"id":310,"name":"Killing Floor 2"},{"executables":{"win32":["ShooterGame.exe"]},"id":311,"name":"Ark: Survival Evolved"},{"executables":{"win32":["LifeIsStrange.exe"]},"id":312,"name":"Life Is Strange"},{"executables":{"win32":["Client_tos.exe"]},"id":313,"name":"Tree of Savior"},{"executables":{"win32":["olliolli2.exe"]},"id":314,"name":"OlliOlli2"},{"executables":{"win32":["cw.exe"]},"id":315,"name":"Closers Dimension Conflict"},{"executables":{"win32":["ESSTEAM.exe","elsword.exe","x2.exe"]},"id":316,"name":"Elsword"},{"executables":{"win32":["ori.exe"]},"id":317,"name":"Ori and the Blind Forest"},{"executables":{"win32":["Skyforge.exe"]},"id":318,"name":"Skyforge"},{"executables":{"win32":["projectzomboid64.exe","projectzomboid32.exe"]},"id":319,"name":"Project Zomboid"},{"executables":{"win32":["From_The_Depths.exe"]},"id":320,"name":"The Depths"},{"executables":{"win32":["TheCrew.exe"]},"id":321,"name":"The Crew"},{"executables":{"win32":["MarvelHeroes2015.exe"]},"id":322,"name":"Marvel Heroes 2015"},{"executables":{"win32":["timeclickers.exe"]},"id":324,"name":"Time Clickers"},{"executables":{"win32":["eurotrucks2.exe"]},"id":325,"name":"Euro Truck Simulator 2"},{"executables":{"win32":["FarmingSimulator2015Game.exe"]},"id":326,"name":"Farming Simulator 15"},{"executables":{"win32":["strife.exe"]},"id":327,"name":"Strife"},{"executables":{"win32":["Awesomenauts.exe"]},"id":328,"name":"Awesomenauts"},{"executables":{"win32":["Dofus.exe"]},"id":329,"name":"Dofus"},{"executables":{"win32":["Boid.exe"]},"id":330,"name":"Boid"},{"executables":{"win32":["adventure-capitalist.exe"]},"id":331,"name":"AdVenture Capitalist"},{"executables":{"win32":["OrcsMustDie2.exe"]},"id":332,"name":"Orcs Must Die! 2"},{"executables":{"win32":["Mountain.exe"]},"id":333,"name":"Mountain"},{"executables":{"win32":["Valkyria.exe"]},"id":335,"name":"Valkyria Chronicles"},{"executables":{"win32":["ffxiiiimg.exe"]},"id":336,"name":"Final Fantasy XIII"},{"executables":{"win32":["TLR.exe"]},"id":337,"name":"The Last Remnant"},{"executables":{"win32":["Cities.exe"]},"id":339,"name":"Cities Skylines"},{"executables":{"win32":["worldofwarships.exe","WoWSLauncher.exe"]},"id":341,"name":"World of Warships"},{"executables":{"win32":["spacegame-Win64-shipping.exe"]},"id":342,"name":"Fractured Space"},{"executables":{"win32":["thespacegame.exe"]},"id":343,"name":"Ascent - The Space Game"},{"executables":{"win32":["DuckGame.exe"]},"id":344,"name":"Duck Game"},{"executables":{"win32":["PPSSPPWindows.exe"]},"id":345,"name":"PPSSPP"},{"executables":{"win32":["MBAA.exe"]},"id":346,"name":"Melty Blood Actress Again: Current Code"},{"executables":{"win32":["TheWolfAmongUs.exe"]},"id":347,"name":"The Wolf Among Us"},{"executables":{"win32":["SpaceEngineers.exe"]},"id":348,"name":"Space Engineers"},{"executables":{"win32":["Borderlands.exe"]},"id":349,"name":"Borderlands"},{"executables":{"win32":["100orange.exe"]},"id":351,"name":"100% Orange Juice"},{"executables":{"win32":["reflex.exe"]},"id":354,"name":"Reflex"},{"executables":{"win32":["pso2.exe"]},"id":355,"name":"Phantasy Star Online 2"},{"executables":{"win32":["AssettoCorsa.exe"]},"id":356,"name":"Assetto Corsa"},{"executables":{"win32":["iw3mp.exe","iw3sp.exe"]},"id":357,"name":"Call of Duty 4: Modern Warfare"},{"executables":{"win32":["WolfOldBlood_x64.exe"]},"id":358,"name":"Wolfenstein: The Old Blood"},{"executables":{"win32":["castle.exe"]},"id":359,"name":"Castle Crashers"},{"executables":{"win32":["vindictus.exe"]},"id":360,"name":"Vindictus"},{"executables":{"win32":["ShooterGame-Win32-Shipping.exe"]},"id":361,"name":"Dirty Bomb"},{"executables":{"win32":["BatmanAK.exe"]},"id":362,"name":"Batman Arkham Knight"},{"executables":{"win32":["drt.exe"]},"id":363,"name":"Dirt Rally"},{"executables":{"win32":["rFactor.exe"]},"id":364,"name":"rFactor"},{"executables":{"win32":["clonk.exe"]},"id":365,"name":"Clonk Rage"},{"executables":{"win32":["SRHK.exe"]},"id":366,"name":"Shadowrun: Hong Kong"},{"executables":{"win32":["Insurgency.exe"]},"id":367,"name":"Insurgency"},{"executables":{"win32":["StepMania.exe"]},"id":368,"name":"Step Mania"},{"executables":{"win32":["FirefallCLient.exe"]},"id":369,"name":"Firefall"},{"executables":{"win32":["mirrorsedge.exe"]},"id":370,"name":"Mirrors Edge"},{"executables":{"win32":["MgsGroundZeroes.exe"]},"id":371,"name":"Metal Gear Solid V: Ground Zeroes"},{"executables":{"win32":["mgsvtpp.exe"]},"id":372,"name":"Metal Gear Solid V: The Phantom Pain"},{"executables":{"win32":["tld.exe"]},"id":373,"name":"The Long Dark"},{"executables":{"win32":["TKOM.exe"]},"id":374,"name":"Take On Mars"},{"executables":{"win32":["robloxplayerlauncher.exe","Roblox.exe"]},"id":375,"name":"Roblox"},{"executables":{"win32":["eu4.exe"]},"id":376,"name":"Europa Universalis 4"},{"executables":{"win32":["APB.exe"]},"id":377,"name":"APB Reloaded"},{"executables":{"win32":["Robocraft.exe"]},"id":378,"name":"Robocraft"},{"executables":{"win32":["Unity.exe"]},"id":379,"name":"Unity"},{"executables":{"win32":["Simpsons.exe"]},"id":380,"name":"The Simpsons: Hit & Run"},{"executables":{"win32":["Dnlauncher.exe","DragonNest.exe"]},"id":381,"name":"Dragon Nest"},{"executables":{"win32":["Trove.exe"]},"id":382,"name":"Trove"},{"executables":{"win32":["EndlessLegend.exe"]},"id":383,"name":"Endless Legend"},{"executables":{"win32":["TurbineLauncher.exe","dndclient.exe"]},"id":384,"name":"Dungeons & Dragons Online"},{"executables":{"win32":["quakelive.exe","quakelive_steam.exe"]},"id":385,"name":"Quake Live"},{"executables":{"win32":["7DaysToDie.exe"]},"id":386,"name":"7DaysToDie"},{"executables":{"win32":["SpeedRunners.exe"]},"id":387,"name":"SpeedRunners"},{"executables":{"win32":["gamemd.exe"]},"id":388,"name":"Command & Conquer: Red Alert 2"},{"executables":{"win32":["generals.exe"]},"id":389,"name":"Command & Conquer Generals: Zero Hour"},{"executables":{"win32":["Oblivion.exe"]},"id":390,"name":"The Elder Scrolls 4: Oblivion"},{"executables":{"win32":["mgsi.exe"]},"id":391,"name":"Metal Gear Solid"},{"executables":{"win32":["EoCApp.exe"]},"id":392,"name":"Divinity - Original Sin"},{"executables":{"win32":["Torment.exe"]},"id":393,"name":"Planescape: Torment"},{"executables":{"win32":["HexPatch.exe"]},"id":394,"name":"Hex: Shards of Fate"},{"executables":{"win32":["NS3FB.exe"]},"id":395,"name":"Naruto Shippuden Ultimate Ninja Storm 3 Full Burst"},{"executables":{"win32":["NSUNSR.exe"]},"id":396,"name":"Naruto Shippuden Ultimate Ninja Storm Revolution"},{"executables":{"win32":["SaintsRowIV.exe"]},"id":397,"name":"Saints Row IV"},{"executables":{"win32":["Shadowrun.exe"]},"id":398,"name":"Shadowrun"},{"executables":{"win32":["DungeonoftheEndless.exe"]},"id":399,"name":"Dungeon of the Endless"},{"executables":{"win32":["Hon.exe"]},"id":400,"name":"Heroes of Newerth"},{"executables":{"win32":["mabinogi.exe"]},"id":401,"name":"Mabinogi"},{"executables":{"win32":["CoD2MP_s.exe","CoDSP_s.exe"]},"id":402,"name":"Call of Duty 2:"},{"executables":{"win32":["CoDWaWmp.exe","CoDWaw.exe"]},"id":403,"name":"Call of Duty: World at War"},{"executables":{"win32":["heroes.exe"]},"id":404,"name":"Mabinogi Heroes (Vindictus) "},{"executables":{"win32":["KanColleViewer.exe"]},"id":405,"name":"KanColle "},{"executables":{"win32":["cyphers.exe"]},"id":406,"name":"Cyphers"},{"executables":{"win32":["RelicCoH2.exe"]},"id":407,"name":"Company of Heroes 2"},{"executables":{"win32":["MJ.exe"]},"id":408,"name":"セガNET麻雀MJ"},{"executables":{"win32":["ge.exe"]},"id":409,"name":"Granado Espada"},{"executables":{"win32":["NovaRO.exe"]},"id":410,"name":"Nova Ragnarok Online"},{"executables":{"win32":["RivalsofAether.exe"]},"id":411,"name":"Rivals of Aether"},{"executables":{"win32":["bfh.exe"]},"id":412,"name":"Battlefield Hardline"},{"executables":{"win32":["GrowHome.exe"]},"id":413,"name":"Grow Home"},{"executables":{"win32":["patriots.exe"]},"id":414,"name":"Rise of Nations Extended"},{"executables":{"win32":["Railroads.exe"]},"id":415,"name":"Sid Meier's Railroads!"},{"executables":{"win32":["Empire.exe"]},"id":416,"name":"Empire: Total War"},{"executables":{"win32":["Napoleon.exe"]},"id":417,"name":"Napoleon: Total War"},{"executables":{"win32":["gta_sa.exe"]},"id":418,"name":"Grand Theft Auto: San Andreas"},{"executables":{"win32":["MadMax.exe"]},"id":419,"name":"Mad Max"},{"executables":{"win32":["Titanfall.exe"]},"id":420,"name":"Titanfall"},{"executables":{"win32":["age2_x1.exe"]},"id":421,"name":"Age of Empires II: The Conquerors"},{"executables":{"win32":["Rome2.exe"]},"id":422,"name":"Total War: ROME 2"},{"executables":{"win32":["ShadowOfMordor.exe"]},"id":423,"name":"Middle-earth: Shadow of Mordor"},{"executables":{"win32":["Subnautica.exe"]},"id":424,"name":"Subnautica"},{"executables":{"win32":["anno5.exe"]},"id":425,"name":"Anno 2070"},{"executables":{"win32":["carrier.exe"]},"id":426,"name":"Carrier Command Gaea Mission"},{"executables":{"win32":["DarksidersPC.exe"]},"id":427,"name":"Darksiders"},{"executables":{"win32":["Darksiders2.exe"]},"id":428,"name":"Darksiders 2"},{"executables":{"win32":["mudlet.exe"]},"id":429,"name":"Mudlet"},{"executables":{"win32":["DunDefLauncher.exe"]},"id":430,"name":"Dungeon Defenders II"},{"executables":{"win32":["hng.exe"]},"id":431,"name":"Heroes and Generals"},{"executables":{"win32":["WFTOGame.exe"]},"id":432,"name":"War of the Overworld"},{"executables":{"win32":["Talisman.exe"]},"id":433,"name":"Talisman: Digital Edition"},{"executables":{"win32":["limbo.exe"]},"id":434,"name":"Limbo"},{"executables":{"win32":["ibbobb.exe"]},"id":435,"name":"ibb & obb"},{"executables":{"win32":["BattleBlockTheater.exe"]},"id":436,"name":"BattleBlock Theater"},{"executables":{"win32":["iracinglauncher.exe","iracingsim.exe","iracingsim64.exe"]},"id":437,"name":"iRacing"},{"executables":{"win32":["CivilizationV_DX11.exe"]},"id":438,"name":"Civilization V"}] +},{}]},{},[5])(5) +}); \ No newline at end of file diff --git a/web-dist/discord.min.3.6.3.js b/web-dist/discord.min.3.6.3.js new file mode 100644 index 000000000..84ac649e8 --- /dev/null +++ b/web-dist/discord.min.3.6.3.js @@ -0,0 +1,2 @@ +!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Discord=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g]*>/g)||[])[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;a.push(h.substring(2,h.length-1))}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return a}"function"==typeof c&&(d=c,c=!1),b=e+n(b);var p=o();f.resolveDestination(a).then(k)["catch"](j)});return g}},{key:"createws",value:function(a){if(this.websocket)return!1;var b=this;this.websocket=new o(a),this.websocket.onopen=function(){b.trySendConnData()},this.websocket.onclose=function(){b.trigger("disconnected")},this.websocket.onmessage=function(a){var c=!1,d={};try{c=JSON.parse(a.data),d=c.d}catch(e){return void b.trigger("error",e,a)}switch(b.trigger("raw",c),c.t){case"READY":b.debug("received ready packet"),b.user=b.addUser(d.user);var f=!0,h=!1,k=void 0;try{for(var l,m=d.guilds[Symbol.iterator]();!(f=(l=m.next()).done);f=!0)var n=l.value,o=b.addServer(n)}catch(e){h=!0,k=e}finally{try{!f&&m["return"]&&m["return"]()}finally{if(h)throw k}}var p=!0,q=!1,r=void 0;try{for(var s,t=d.private_channels[Symbol.iterator]();!(p=(s=t.next()).done);p=!0){var u=s.value;b.addPMChannel(u)}}catch(e){q=!0,r=e}finally{try{!p&&t["return"]&&t["return"]()}finally{if(q)throw r}}b.trigger("ready"),b.readyTime=Date.now(),b.debug("cached "+b.serverCache.length+" servers, "+b.channelCache.length+" channels, "+b.pmChannelCache.length+" PMs and "+b.userCache.length+" users."),b.state=3,setInterval(function(){b.keepAlive.apply(b)},d.heartbeat_interval);break;case"MESSAGE_CREATE":b.debug("received message");var v=[];d.mentions=d.mentions||[];var w=!0,x=!1,y=void 0;try{for(var z,A=d.mentions[Symbol.iterator]();!(w=(z=A.next()).done);w=!0){var B=z.value;v.push(b.addUser(B))}}catch(e){x=!0,y=e}finally{try{!w&&A["return"]&&A["return"]()}finally{if(x)throw y}}var C=b.getChannel("id",d.channel_id);if(C){var D=C.addMessage(new j(d,C,v,b.addUser(d.author)));b.trigger("message",D)}break;case"MESSAGE_DELETE":b.debug("message deleted");var C=b.getChannel("id",d.channel_id),E=C.getMessage("id",d.id);E?(b.trigger("messageDelete",C,E),C.messages.splice(C.messages.indexOf(E),1)):b.trigger("messageDelete",C);break;case"MESSAGE_UPDATE":b.debug("message updated");var C=b.getChannel("id",d.channel_id),F=C.getMessage("id",d.id);if(F){var G={};for(var H in F)G[H]=F[H];for(var H in d)G[H]=d[H];var v=[],I=!0,J=!1,K=void 0;try{for(var L,M=G.mentions[Symbol.iterator]();!(I=(L=M.next()).done);I=!0){var B=L.value;v.push(b.addUser(B))}}catch(e){J=!0,K=e}finally{try{!I&&M["return"]&&M["return"]()}finally{if(J)throw K}}var N=new j(G,C,v,F.author);b.trigger("messageUpdate",N,F),C.messages[C.messages.indexOf(F)]=N}break;case"GUILD_DELETE":var o=b.getServer("id",d.id);o&&(b.serverCache.splice(b.serverCache.indexOf(o),1),b.trigger("serverDelete",o));break;case"CHANNEL_DELETE":var C=b.getChannel("id",d.id);if(C){var o=C.server;o&&o.channels.splice(o.channels.indexOf(C),1),b.trigger("channelDelete",C),b.serverCache.splice(b.serverCache.indexOf(C),1)}break;case"GUILD_CREATE":var o=b.getServer("id",d.id);if(o||(o=b.addServer(d)),b.serverCreateListener[d.id]){var O=b.serverCreateListener[d.id];O[0](o),O[1](null,o),b.serverCreateListener[d.id]=null}b.trigger("serverCreate",o);break;case"CHANNEL_CREATE":var C=b.getChannel("id",d.id);if(!C){var P=b.addChannel(d,d.guild_id),Q=b.getServer("id",d.guild_id);Q&&Q.addChannel(P),b.trigger("channelCreate",P)}break;case"GUILD_MEMBER_ADD":var o=b.getServer("id",d.guild_id);if(o){var R=b.addUser(d.user);~o.members.indexOf(R)||o.members.push(R),b.trigger("serverNewMember",R,o)}break;case"GUILD_MEMBER_REMOVE":var o=b.getServer("id",d.guild_id);if(o){var R=b.addUser(d.user);~o.members.indexOf(R)&&o.members.splice(o.members.indexOf(R),1),b.trigger("serverRemoveMember",R,o)}break;case"USER_UPDATE":if(b.user&&d.id===b.user.id){var S=new g(d);b.trigger("userUpdate",S,b.user),~b.userCache.indexOf(b.user)&&(b.userCache[b.userCache.indexOf(b.user)]=S),b.user=S}break;case"PRESENCE_UPDATE":var T=b.getUser("id",d.user.id);if(T){var U=new g(d.user);U.equalsStrict(T)?(T.status=d.status,b.trigger("presence",{user:T,status:d.status,server:b.getServer("id",d.guild_id),gameId:d.game_id})):(b.trigger("userUpdate",T,U),b.userCache[b.userCache.indexOf(T)]=U)}break;case"CHANNEL_UPDATE":var V=b.getChannel("id",d.id),W=b.getServer("id",d.guild_id);if(V&&W){var X=new i(d,W);X.messages=V.messages,b.trigger("channelUpdate",V,X),b.channelCache[b.channelCache.indexOf(V)]=X}break;default:b.debug("received unknown packet"),b.trigger("unknown",c)}}}},{key:"addUser",value:function(a){return this.getUser("id",a.id)||this.userCache.push(new g(a)),this.getUser("id",a.id)}},{key:"addChannel",value:function(a,b){return this.getChannel("id",a.id)||this.channelCache.push(new i(a,this.getServer("id",b))),this.getChannel("id",a.id)}},{key:"addPMChannel",value:function(a){return this.getPMChannel("id",a.id)||this.pmChannelCache.push(new l(a,this)),this.getPMChannel("id",a.id)}},{key:"setTopic",value:function(a,b){var c=arguments.length<=2||void 0===arguments[2]?function(a){}:arguments[2],d=this;return new Promise(function(e,g){function h(a){c(a),g(a)}function i(a){var g=d.getChannel("id",a);n.patch(f.CHANNELS+"/"+a).set("authorization",d.token).send({name:g.name,position:0,topic:b}).end(function(a,b){a?h(a):(g.topic=b.body.topic,e(),c())})}d.resolveDestination(a).then(i)["catch"](h)})}},{key:"addServer",value:function(a){var b=this,c=this.getServer("id",a.id);if(a.unavailable)return b.trigger("unavailable",a),void b.debug("Server ID "+a.id+" has been marked unavailable by Discord. It was not cached.");if(!c&&(c=new h(a,this),this.serverCache.push(c),a.channels)){var d=!0,e=!1,f=void 0;try{for(var g,i=a.channels[Symbol.iterator]();!(d=(g=i.next()).done);d=!0){var j=g.value;c.channels.push(this.addChannel(j,c.id))}}catch(k){e=!0,f=k}finally{try{!d&&i["return"]&&i["return"]()}finally{if(e)throw f}}}var l=!0,m=!1,n=void 0;try{for(var o,p=a.presences[Symbol.iterator]();!(l=(o=p.next()).done);l=!0){var q=o.value;b.getUser("id",q.user.id).status=q.status}}catch(k){m=!0,n=k}finally{try{!l&&p["return"]&&p["return"]()}finally{if(m)throw n}}return c}},{key:"getUser",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.userCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"getChannel",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.channelCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return this.getPMChannel(a,b)}},{key:"getPMChannel",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.pmChannelCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"getServer",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.serverCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"trySendConnData",value:function(){if(this.token&&!this.alreadySentData){this.alreadySentData=!0;var a={op:2,d:{token:this.token,v:3,properties:{$os:"discord.js",$browser:"discord.js",$device:"discord.js",$referrer:"",$referring_domain:""}}};this.websocket.send(JSON.stringify(a))}}},{key:"resolveServerID",value:function(a){return a instanceof h?a.id:!isNaN(a)&&a.length&&17===a.length?a:void 0}},{key:"resolveDestination",value:function(a){var b=!1,c=this;return new Promise(function(d,e){if(a instanceof h)b=a.id;else if(a instanceof i)b=a.id;else if(a instanceof j)b=a.channel.id;else if(a instanceof l)b=a.id;else if(a instanceof g){var f=!0,k=!1,m=void 0;try{for(var n,o=c.pmChannelCache[Symbol.iterator]();!(f=(n=o.next()).done);f=!0){var p=n.value;if(p.user.equals(a))return void d(p.id)}}catch(q){k=!0,m=q}finally{try{!f&&o["return"]&&o["return"]()}finally{if(k)throw m}}c.startPM(a).then(function(a){d(a.id)})["catch"](e)}else b=a;b?d(b):e()})}},{key:"_sendMessage",value:function(a,b,c,d){var e=this;return new Promise(function(g,h){n.post(f.CHANNELS+"/"+a+"/messages").set("authorization",e.token).send({content:b,mentions:d,tts:c}).end(function(a,b){if(a)h(a);else{var c=b.body,d=[];c.mentions=c.mentions||[];var f=!0,i=!1,k=void 0;try{for(var l,m=c.mentions[Symbol.iterator]();!(f=(l=m.next()).done);f=!0){var n=l.value;d.push(e.addUser(n))}}catch(a){i=!0,k=a}finally{try{!f&&m["return"]&&m["return"]()}finally{if(i)throw k}}var o=e.getChannel("id",c.channel_id);if(o){var p=o.addMessage(new j(c,o,d,e.addUser(c.author)));g(p)}}})})}},{key:"_sendFile",value:function(a,b){var c=arguments.length<=2||void 0===arguments[2]?"DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png":arguments[2],d=this;return new Promise(function(e,g){n.post(f.CHANNELS+"/"+a+"/messages").set("authorization",d.token).attach("file",b,c).end(function(b,c){if(b)g(b);else{var f=d.getChannel("id",a);if(f){var h=f.addMessage(new j(c.body,f,[],d.user));e(h)}}})})}},{key:"_updateMessage",value:function(a,b){var c=this;return new Promise(function(d,e){n.patch(f.CHANNELS+"/"+a.channel.id+"/messages/"+a.id).set("authorization",c.token).send({content:b,mentions:[]}).end(function(b,c){if(b)e(b);else{var f=new j(c.body,a.channel,a.mentions,a.sender);d(f),a.channel.messages[a.channel.messages.indexOf(a)]=f}})})}},{key:"_deleteMessage",value:function(a){var b=this;return new Promise(function(c,d){n.del(f.CHANNELS+"/"+a.channel.id+"/messages/"+a.id).set("authorization",b.token).end(function(a,b){a?d(a):c()})})}},{key:"checkQueue",value:function(a){var b=this,c=this;this.checkingQueue[a]||!function(){var d=function f(){if(0===c.queue[a].length)return void e();var b=c.queue[a][0];switch(b.action){case"sendMessage":var d=b;c._sendMessage(a,d.content,d.tts,d.mentions).then(function(b){d.then(b),c.queue[a].shift(),f()})["catch"](function(b){d.error(b),c.queue[a].shift(),f()});break;case"sendFile":var g=b;c._sendFile(a,g.attachment,g.attachmentName).then(function(b){g.then(b),c.queue[a].shift(),f()})["catch"](function(b){g.error(b),c.queue[a].shift(),f()});break;case"updateMessage":var h=b;c._updateMessage(h.message,h.content).then(function(b){h.then(b),c.queue[a].shift(),f()})["catch"](function(b){h.error(b),c.queue[a].shift(),f()});break;case"deleteMessage":var i=b;c._deleteMessage(i.message).then(function(b){i.then(b),c.queue[a].shift(),f()})["catch"](function(b){i.error(b),c.queue[a].shift(),f()});break;default:e()}},e=function(){c.checkingQueue[a]=!1};b.checkingQueue[a]=!0,d()}()}},{key:"getGateway",value:function(){var a=this;return new Promise(function(b,c){n.get(f.API+"/gateway").set("authorization",a.token).end(function(a,d){a?c(a):b(d.body.url)})})}},{key:"setStatusIdle",value:function(){this.setStatus("idle")}},{key:"setStatusOnline",value:function(){this.setStatus("online")}},{key:"setStatusActive",value:function(){this.setStatusOnline()}},{key:"setStatusHere",value:function(){this.setStatusOnline()}},{key:"setStatusAway",value:function(){this.setStatusIdle()}},{key:"startTyping",value:function(a,b){function c(a){if(!d.typingIntervals[a]){var c=function(){n.post(f.CHANNELS+"/"+a+"/typing").set("authorization",d.token).end()};c();var e=setInterval(c,3e3);d.typingIntervals[a]=e,b&&setTimeout(function(){d.stopTyping(a)},b)}}var d=this;this.resolveDestination(a).then(c)}},{key:"stopTyping",value:function(a){function b(a){c.typingIntervals[a]&&(clearInterval(c.typingIntervals[a]),delete c.typingIntervals[a])}var c=this;this.resolveDestination(a).then(b)}},{key:"setStatus",value:function(a){var b="online"===a?null:Date.now();this.__idleTime=b,this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}))}},{key:"setPlayingGame",value:function(a){if(a instanceof String||"string"==typeof a){var b=a.trim().toUpperCase();a=null;var c=!0,d=!1,e=void 0;try{for(var f,g=m[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h.name.trim().toUpperCase()===b){a=h.id;break}}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}}this.__gameId=a,this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}))}},{key:"playGame",value:function(a){this.setPlayingGame(a)}},{key:"playingGame",value:function(a){this.setPlayingGame(a)}},{key:"uptime",get:function(){return this.readyTime?Date.now()-this.readyTime:null}},{key:"ready",get:function(){return 3===this.state}},{key:"servers",get:function(){return this.serverCache}},{key:"channels",get:function(){return this.channelCache}},{key:"users",get:function(){return this.userCache}},{key:"PMChannels",get:function(){return this.pmChannelCache}},{key:"messages",get:function(){var a=[],b=!0,c=!1,d=void 0;try{for(var e,f=this.channelCache[Symbol.iterator]();!(b=(e=f.next()).done);b=!0){var g=e.value;a=a.concat(g.messages)}}catch(h){c=!0,d=h}finally{try{!b&&f["return"]&&f["return"]()}finally{if(c)throw d}}return a}}]),a}();b.exports=r},{"../ref/gameMap.json":15,"./Endpoints.js":2,"./PMChannel.js":3,"./channel.js":4,"./invite.js":6,"./message.js":7,"./server.js":8,"./user.js":9,fs:10,superagent:11,ws:14}],2:[function(a,b,c){"use strict";c.BASE_DOMAIN="discordapp.com",c.BASE="https://"+c.BASE_DOMAIN,c.WEBSOCKET_HUB="wss://"+c.BASE_DOMAIN+"/hub",c.API=c.BASE+"/api",c.AUTH=c.API+"/auth",c.LOGIN=c.AUTH+"/login",c.LOGOUT=c.AUTH+"/logout",c.USERS=c.API+"/users",c.SERVERS=c.API+"/guilds",c.CHANNELS=c.API+"/channels"},{}],3:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c1e3&&this.messages.splice(0,1);var c=!0,d=!1,e=void 0;try{for(var f,g=this.messages[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"isPrivate",get:function(){return!0}}]),a}();b.exports=f},{}],4:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c1e3&&this.messages.splice(0,1),this.getMessage("id",a.id)||this.messages.push(a),this.getMessage("id",a.id)}},{key:"getMessage",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.messages[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"toString",value:function(){return"<#"+this.id+">"}},{key:"client",get:function(){return this.server.client}},{key:"isPrivate",get:function(){return!1}},{key:"users",get:function(){return this.server.members}},{key:"members",get:function(){return this.server.members}}]),a}();b.exports=f},{}],5:[function(a,b,c){"use strict";var d=(a("superagent"),a("./Endpoints.js")),e=a("./Client.js"),f={Endpoints:d,Client:e};b.exports=f},{"./Client.js":1,"./Endpoints.js":2,superagent:11}],6:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c"}},{key:"toString",value:function(){return this.mention()}},{key:"equals",value:function(a){return a.id===this.id}},{key:"equalsStrict",value:function(a){return a.id===this.id&&a.avatar===this.avatar&&a.username===this.username&&a.discriminator===this.discriminator}},{key:"avatarURL",get:function(){return this.avatar?"https://discordapp.com/api/users/"+this.id+"/avatars/"+this.avatar+".jpg":null}}]),a}();b.exports=f},{}],10:[function(a,b,c){},{}],11:[function(a,b,c){function d(){}function e(a){var b={}.toString.call(a);switch(b){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function f(a){return a===Object(a)}function g(a){if(!f(a))return a;var b=[];for(var c in a)null!=a[c]&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")}function h(a){for(var b,c,d={},e=a.split("&"),f=0,g=e.length;g>f;++f)c=e[f],b=c.split("="),d[decodeURIComponent(b[0])]=decodeURIComponent(b[1]);return d}function i(a){var b,c,d,e,f=a.split(/\r?\n/),g={};f.pop();for(var h=0,i=f.length;i>h;++h)c=f[h],b=c.indexOf(":"),d=c.slice(0,b).toLowerCase(),e=r(c.slice(b+1)),g[d]=e;return g}function j(a){return a.split(/ *; */).shift()}function k(a){return p(a.split(/ *; */),function(a,b){var c=b.split(/ *= */),d=c.shift(),e=c.shift();return d&&e&&(a[d]=e),a},{})}function l(a,b){b=b||{},this.req=a,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||"undefined"==typeof this.xhr.responseType?this.xhr.responseText:null, +this.statusText=this.req.xhr.statusText,this.setStatusProperties(this.xhr.status),this.header=this.headers=i(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body="HEAD"!=this.req.method?this.parseBody(this.text?this.text:this.xhr.response):null}function m(a,b){var c=this;o.call(this),this._query=this._query||[],this.method=a,this.url=b,this.header={},this._header={},this.on("end",function(){var a=null,b=null;try{b=new l(c)}catch(d){return a=new Error("Parser is unable to parse the response"),a.parse=!0,a.original=d,c.callback(a)}if(c.emit("response",b),a)return c.callback(a,b);if(b.status>=200&&b.status<300)return c.callback(a,b);var e=new Error(b.statusText||"Unsuccessful HTTP response");e.original=a,e.response=b,e.status=b.status,c.callback(e,b)})}function n(a,b){return"function"==typeof b?new m("GET",a).end(b):1==arguments.length?new m("GET",a):new m(a,b)}var o=a("emitter"),p=a("reduce"),q="undefined"==typeof window?this||self:window;n.getXHR=function(){if(!(!q.XMLHttpRequest||q.location&&"file:"==q.location.protocol&&q.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(a){}return!1};var r="".trim?function(a){return a.trim()}:function(a){return a.replace(/(^\s*|\s*$)/g,"")};n.serializeObject=g,n.parseString=h,n.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},n.serialize={"application/x-www-form-urlencoded":g,"application/json":JSON.stringify},n.parse={"application/x-www-form-urlencoded":h,"application/json":JSON.parse},l.prototype.get=function(a){return this.header[a.toLowerCase()]},l.prototype.setHeaderProperties=function(a){var b=this.header["content-type"]||"";this.type=j(b);var c=k(b);for(var d in c)this[d]=c[d]},l.prototype.parseBody=function(a){var b=n.parse[this.type];return b&&a&&(a.length||a instanceof Object)?b(a):null},l.prototype.setStatusProperties=function(a){1223===a&&(a=204);var b=a/100|0;this.status=a,this.statusType=b,this.info=1==b,this.ok=2==b,this.clientError=4==b,this.serverError=5==b,this.error=4==b||5==b?this.toError():!1,this.accepted=202==a,this.noContent=204==a,this.badRequest=400==a,this.unauthorized=401==a,this.notAcceptable=406==a,this.notFound=404==a,this.forbidden=403==a},l.prototype.toError=function(){var a=this.req,b=a.method,c=a.url,d="cannot "+b+" "+c+" ("+this.status+")",e=new Error(d);return e.status=this.status,e.method=b,e.url=c,e},n.Response=l,o(m.prototype),m.prototype.use=function(a){return a(this),this},m.prototype.timeout=function(a){return this._timeout=a,this},m.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},m.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(),this.clearTimeout(),this.emit("abort"),this)},m.prototype.set=function(a,b){if(f(a)){for(var c in a)this.set(c,a[c]);return this}return this._header[a.toLowerCase()]=b,this.header[a]=b,this},m.prototype.unset=function(a){return delete this._header[a.toLowerCase()],delete this.header[a],this},m.prototype.getHeader=function(a){return this._header[a.toLowerCase()]},m.prototype.type=function(a){return this.set("Content-Type",n.types[a]||a),this},m.prototype.accept=function(a){return this.set("Accept",n.types[a]||a),this},m.prototype.auth=function(a,b){var c=btoa(a+":"+b);return this.set("Authorization","Basic "+c),this},m.prototype.query=function(a){return"string"!=typeof a&&(a=g(a)),a&&this._query.push(a),this},m.prototype.field=function(a,b){return this._formData||(this._formData=new q.FormData),this._formData.append(a,b),this},m.prototype.attach=function(a,b,c){return this._formData||(this._formData=new q.FormData),this._formData.append(a,b,c),this},m.prototype.send=function(a){var b=f(a),c=this.getHeader("Content-Type");if(b&&f(this._data))for(var d in a)this._data[d]=a[d];else"string"==typeof a?(c||this.type("form"),c=this.getHeader("Content-Type"),"application/x-www-form-urlencoded"==c?this._data=this._data?this._data+"&"+a:a:this._data=(this._data||"")+a):this._data=a;return!b||e(a)?this:(c||this.type("json"),this)},m.prototype.callback=function(a,b){var c=this._callback;this.clearTimeout(),c(a,b)},m.prototype.crossDomainError=function(){var a=new Error("Origin is not allowed by Access-Control-Allow-Origin");a.crossDomain=!0,this.callback(a)},m.prototype.timeoutError=function(){var a=this._timeout,b=new Error("timeout of "+a+"ms exceeded");b.timeout=a,this.callback(b)},m.prototype.withCredentials=function(){return this._withCredentials=!0,this},m.prototype.end=function(a){var b=this,c=this.xhr=n.getXHR(),f=this._query.join("&"),g=this._timeout,h=this._formData||this._data;this._callback=a||d,c.onreadystatechange=function(){if(4==c.readyState){var a;try{a=c.status}catch(d){a=0}if(0==a){if(b.timedout)return b.timeoutError();if(b.aborted)return;return b.crossDomainError()}b.emit("end")}};var i=function(a){a.total>0&&(a.percent=a.loaded/a.total*100),b.emit("progress",a)};this.hasListeners("progress")&&(c.onprogress=i);try{c.upload&&this.hasListeners("progress")&&(c.upload.onprogress=i)}catch(j){}if(g&&!this._timer&&(this._timer=setTimeout(function(){b.timedout=!0,b.abort()},g)),f&&(f=n.serializeObject(f),this.url+=~this.url.indexOf("?")?"&"+f:"?"+f),c.open(this.method,this.url,!0),this._withCredentials&&(c.withCredentials=!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof h&&!e(h)){var k=this.getHeader("Content-Type"),l=n.serialize[k?k.split(";")[0]:""];l&&(h=l(h))}for(var m in this.header)null!=this.header[m]&&c.setRequestHeader(m,this.header[m]);return this.emit("request",this),c.send(h),this},m.prototype.then=function(a,b){return this.end(function(c,d){c?b(c):a(d)})},n.Request=m,n.get=function(a,b,c){var d=n("GET",a);return"function"==typeof b&&(c=b,b=null),b&&d.query(b),c&&d.end(c),d},n.head=function(a,b,c){var d=n("HEAD",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.del=function(a,b){var c=n("DELETE",a);return b&&c.end(b),c},n.patch=function(a,b,c){var d=n("PATCH",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.post=function(a,b,c){var d=n("POST",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.put=function(a,b,c){var d=n("PUT",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},b.exports=n},{emitter:12,reduce:13}],12:[function(a,b,c){function d(a){return a?e(a):void 0}function e(a){for(var b in d.prototype)a[b]=d.prototype[b];return a}b.exports=d,d.prototype.on=d.prototype.addEventListener=function(a,b){return this._callbacks=this._callbacks||{},(this._callbacks[a]=this._callbacks[a]||[]).push(b),this},d.prototype.once=function(a,b){function c(){d.off(a,c),b.apply(this,arguments)}var d=this;return this._callbacks=this._callbacks||{},c.fn=b,this.on(a,c),this},d.prototype.off=d.prototype.removeListener=d.prototype.removeAllListeners=d.prototype.removeEventListener=function(a,b){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var c=this._callbacks[a];if(!c)return this;if(1==arguments.length)return delete this._callbacks[a],this;for(var d,e=0;ed;++d)c[d].apply(this,b)}return this},d.prototype.listeners=function(a){return this._callbacks=this._callbacks||{},this._callbacks[a]||[]},d.prototype.hasListeners=function(a){return!!this.listeners(a).length}},{}],13:[function(a,b,c){b.exports=function(a,b,c){for(var d=0,e=a.length,f=3==arguments.length?c:a[d++];e>d;)f=b.call(null,f,a[d],++d,a);return f}},{}],14:[function(a,b,c){function d(a,b,c){var d;return d=b?new f(a,b):new f(a)}var e=function(){return this}(),f=e.WebSocket||e.MozWebSocket;b.exports=f?d:null,f&&(d.prototype=f.prototype)},{}],15:[function(a,b,c){b.exports=[{executables:{win32:["pol.exe"]},id:0,name:"FINAL FANTASY XI"},{executables:{win32:["ffxiv.exe","ffxiv_dx11.exe"]},id:1,name:"FINAL FANTASY XIV"},{executables:{win32:["Wow.exe","Wow-64.exe"]},id:3,name:"World of Warcraft"},{executables:{darwin:["LoLLauncher.app"],win32:["LolClient.exe","League of Legends.exe"]},id:4,name:"League of Legends"},{executables:{darwin:["Diablo%20III.app"],win32:["Diablo III.exe"]},id:5,name:"Diablo 3"},{executables:{darwin:["dota_osx.app"],win32:["dota2.exe"]},id:6,name:"DOTA 2"},{executables:{darwin:["Heroes.app"],win32:["Heroes of the Storm.exe","HeroesOfTheStorm_x64.exe","HeroesOfTheStorm.exe"]},id:7,name:"Heroes of the Storm"},{executables:{darwin:["Hearthstone.app"],win32:["Hearthstone.exe"]},id:8,name:"Hearthstone"},{executables:{win32:["csgo.exe"]},id:9,name:"Counter-Strike: Global Offensive"},{executables:{win32:["WorldOfTanks.exe"]},id:10,name:"World of Tanks"},{executables:{darwin:["gw2.app"],win32:["gw2.exe"]},id:11,name:"Guild Wars 2"},{executables:{win32:["dayz.exe"]},id:12,name:"Day Z"},{executables:{darwin:["starcraft%20ii.app"],win32:["starcraft ii.exe","SC2_x64.exe","SC2.exe"]},id:13,name:"Starcraft II"},{executables:{win32:["diablo.exe"]},id:14,name:"Diablo"},{executables:{win32:["diablo ii.exe"]},id:15,name:"Diablo 2"},{executables:{win32:["left4dead.exe"]},id:17,name:"Left 4 Dead"},{executables:{darwin:["minecraft.app"],win32:["minecraft.exe"]},id:18,name:"Minecraft"},{executables:{win32:["smite.exe"]},id:19,name:"Smite"},{executables:{win32:["bf4.exe"]},id:20,name:"Battlefield 4"},{executables:{win32:["AoK HD.exe","empires2.exe"]},id:101,name:"Age of Empire II"},{executables:{win32:["age3y.exe"]},id:102,name:"Age of Empire III"},{executables:{win32:["AlanWake.exe"]},id:104,name:"Alan Wake"},{executables:{win32:["alan_wakes_american_nightmare.exe"]},id:105,name:"Alan Wake's American Nightmare"},{executables:{win32:["AlienBreed2Assault.exe"]},id:106,name:"Alien Breed 2: Assault"},{executables:{win32:["Amnesia.exe"]},id:107,name:"Amnesia: The Dark Descent"},{executables:{win32:["UDK.exe"]},id:108,name:"Antichamber"},{executables:{win32:["ArcheAge.exe"]},id:109,name:"ArcheAge"},{executables:{win32:["arma3.exe"]},id:110,name:"Arma III"},{executables:{win32:["AC3SP.exe"]},id:111,name:"Assassin's Creed 3"},{executables:{win32:["Bastion.exe"]},id:112,name:"Bastion"},{executables:{win32:["BF2.exe"]},id:113,name:"Battlefield 2"},{executables:{win32:["bf3.exe"]},id:114,name:"Battlefield 3"},{executables:{win32:["Besiege.exe"]},id:116,name:"Besiege"},{executables:{win32:["Bioshock.exe"]},id:117,name:"Bioshock"},{executables:{win32:["Bioshock2.exe"]},id:118,name:"BioShock II"},{executables:{win32:["BioShockInfinite.exe"]},id:119,name:"BioShock Infinite"},{executables:{win32:["Borderlands2.exe"]},id:122,name:"Borderlands 2"},{executables:{win32:["braid.exe"]},id:123,name:"Braid"},{executables:{win32:["ShippingPC-StormGame.exe"]},id:124,name:"Bulletstorm"},{executables:{},id:125,name:"Cabal 2"},{executables:{win32:["CabalMain.exe"]},id:126,name:"Cabal Online"},{executables:{win32:["iw4mp.exe","iw4sp.exe"]},id:127,name:"Call of Duty: Modern Warfare 2"},{executables:{win32:["t6sp.exe"]},id:128,name:"Call of Duty: Black Ops"},{executables:{win32:["iw5mp.exe"]},id:129,name:"Call of Duty: Modern Warfare 3"},{executables:{win32:["RelicCOH.exe"]},id:132,name:"Company of Heroes"},{executables:{win32:["Crysis64.exe"]},id:135,name:"Crysis"},{executables:{win32:["Crysis2.exe"]},id:136,name:"Crysis 2"},{executables:{win32:["Crysis3.exe"]},id:137,name:"Crysis 3"},{executables:{win32:["Crysis.exe"]},id:138,name:"Crysis 4 "},{executables:{win32:["DATA.exe"]},id:140,name:"Dark Souls"},{executables:{win32:["DarkSoulsII.exe"]},id:141,name:"Dark Souls II"},{executables:{win32:["dfuw.exe"]},id:142,name:"Darkfall: Unholy Wars"},{executables:{win32:["DCGAME.exe"]},id:144,name:"DC Universe Online"},{executables:{win32:["DeadIslandGame.exe"]},id:145,name:"Dead Island"},{executables:{win32:["deadspace2.exe"]},id:146,name:"Dead Space 2"},{executables:{win32:["LOTDGame.exe"]},id:147,name:"Deadlight"},{executables:{win32:["dxhr.exe"]},id:148,name:"Deus Ex: Human Revolution"},{executables:{win32:["DeviMayCry4.exe"]},id:149,name:"Devil May Cry 4"},{executables:{win32:["DMC-DevilMayCry.exe"]},id:150,name:"DmC Devil May Cry"},{executables:{win32:["dirt2_game.exe"]},id:154,name:"DiRT 2"},{executables:{win32:["dirt3_game.exe"]},id:155,name:"DiRT 3"},{executables:{win32:["dota.exe"]},id:156,name:"DOTA"},{executables:{win32:["DoubleDragon.exe"]},id:158,name:"Double Dragon Neon"},{executables:{win32:["DragonAge2.exe"]},id:159,name:"Dragon Age II"},{executables:{win32:["DragonAgeInquisition.exe"]},id:160,name:"Dragon Age: Inquisition"},{executables:{win32:["daorigins.exe"]},id:161,name:"Dragon Age: Origins"},{executables:{win32:["DBXV.exe"]},id:162,name:"Dragon Ball XenoVerse"},{executables:{win32:["DukeForever.exe"]},id:163,name:"Duke Nukem Forever"},{executables:{darwin:["Dustforce.app"],win32:["dustforce.exe"]},id:164,name:"Dustforce"},{executables:{win32:["EliteDangerous32.exe"]},id:165,name:"Elite: Dangerous"},{executables:{win32:["exefile.exe"]},id:166,name:"Eve Online"},{executables:{win32:["eqgame.exe"]},id:167,name:"EverQuest"},{executables:{win32:["EverQuest2.exe"]},id:168,name:"EverQuest II"},{executables:{},id:169,name:"EverQuest Next"},{executables:{win32:["Engine.exe"]},id:170,name:"F.E.A.R."},{executables:{win32:["FEAR2.exe"]},id:171,name:"F.E.A.R. 2: Project Origin"},{executables:{win32:["fallout3.exe"]},id:172,name:"Fallout 3"},{executables:{win32:["FalloutNV.exe"]},id:174,name:"Fallout: New Vegas"},{executables:{win32:["farcry3.exe"]},id:175,name:"Far Cry 3"},{executables:{win32:["fifa15.exe"]},id:176,name:"FIFA 15"},{executables:{win32:["FTLGame.exe"]},id:180,name:"FTL: Faster Than Light"},{executables:{win32:["GTAIV.exe"]},id:181,name:"Grand Theft Auto 4"},{executables:{win32:["GTA5.exe"]},id:182,name:"Grand Theft Auto 5"},{executables:{win32:["Gw.exe"]},id:183,name:"Guild Wars"},{executables:{win32:["H1Z1.exe"]},id:186,name:"H1Z1"},{executables:{win32:["HL2HL2.exe","hl2.exe"]},id:188,name:"Half Life 2"},{executables:{win32:["HOMEFRONT.exe"]},id:195,name:"Homefront"},{executables:{win32:["invisibleinc.exe"]},id:196,name:"Invisible Inc."},{executables:{win32:["LANoire.exe"]},id:197,name:"L.A. Noire"},{executables:{win32:["Landmark64.exe"]},id:198,name:"Landmark"},{executables:{win32:["left4dead2.exe"]},id:201,name:"Left 4 Dead 2"},{executables:{win32:["lineage.exe"]},id:203,name:"Lineage"},{executables:{win32:["Magicka.exe"]},id:206,name:"Magicka"},{executables:{win32:["MapleStory.exe"]},id:208,name:"MapleStory"},{executables:{},id:209,name:"Mark of the Ninja"},{executables:{win32:["MassEffect.exe"]},id:210,name:"Mass Effect"},{executables:{win32:["MassEffect2.exe"]},id:211,name:"Mass Effect 2"},{executables:{win32:["MassEffect3Demo.exe"]},id:212,name:"Mass Effect 3"},{executables:{win32:["METAL GEAR RISING REVENGEANCE.exe"]},id:214,name:"Metal Gear Rising: Revengeance"},{executables:{win32:["metro2033.exe"]},id:215,name:"Metro 2033"},{executables:{win32:["MetroLL.exe"]},id:216,name:"Metro Last Light"},{executables:{win32:["MK10.exe"]},id:218,name:"Mortal Kombat X"},{executables:{win32:["speed.exe"]},id:219,name:"Need For Speed Most Wanted"},{executables:{},id:220,name:"Neverwinder"},{executables:{darwin:["Outlast.app"],win32:["OLGame.exe"]},id:221,name:"Outlast"},{executables:{win32:["PapersPlease.exe"]},id:222,name:"Papers, Please"},{executables:{win32:["payday_win32_release.exe"]},id:223,name:"PAYDAY"},{executables:{win32:["payday2_win32_release.exe"]},id:224,name:"PAYDAY2"},{executables:{win32:["PillarsOfEternity.exe"]},id:225,name:"Pillars of Eternity"},{executables:{win32:["PA.exe"]},id:226,name:"Planetary Annihilation"},{executables:{win32:["planetside2_x86.exe"]},id:227,name:"Planetside 2"},{executables:{win32:["hl2P.exe"]},id:228,name:"Portal"},{executables:{win32:["portal2.exe"]},id:229,name:"Portal 2"},{executables:{win32:["PrimalCarnageGame.exe"]},id:231,name:"Primal Cargnage"},{executables:{win32:["pCARS.exe"]},id:232,name:"Project Cars"},{executables:{win32:["RaceTheSun.exe"]},id:233,name:"Race The Sun"},{executables:{win32:["Rage.exe"]},id:234,name:"RAGE"},{executables:{win32:["ragexe.exe"]},id:235,name:"Ragnarok Online"},{executables:{win32:["rift.exe"]},id:236,name:"Rift"},{executables:{win32:["Rocksmith2014.exe"]},id:237,name:"Rocksmith 2014"},{executables:{win32:["SwiftKit-RS.exe","JagexLauncher.exe"]},id:238,name:"RuneScape"},{executables:{win32:["Shadowgrounds.exe"]},id:239,name:"Shadowgrounds"},{executables:{win32:["survivor.exe"]},id:240,name:"Shadowgrounds: Survivor"},{executables:{win32:["ShovelKnight.exe"]},id:241,name:"Shovel Knight"},{executables:{win32:["SimCity.exe"]},id:242,name:"SimCity"},{executables:{win32:["SporeApp.exe"]},id:245,name:"Spore"},{executables:{win32:["StarCitizen.exe"]},id:246,name:"Star Citizen"},{executables:{},id:247,name:"Star Trek Online"},{executables:{win32:["battlefront.exe"]},id:248,name:"Star Wars Battlefront"},{executables:{win32:["swtor.exe"]},id:249,name:"Star Wars: The Old Republic"},{executables:{win32:["starbound.exe","starbound_opengl.exe"]},id:250,name:"Starbound"},{executables:{win32:["starcraft.exe"]},id:251,name:"Starcraft"},{executables:{win32:["SSFIV.exe"]},id:253,name:"Ultra Street Fighter IV"},{executables:{win32:["superhexagon.exe"]},id:254,name:"Super Hexagon"},{executables:{win32:["swordandsworcery_pc.exe"]},id:255,name:"Superbrothers: Sword & Sworcery EP"},{executables:{win32:["hl2TF.exe"]},id:256,name:"Team Fortress 2"},{executables:{win32:["TERA.exe"]},id:258,name:"TERA"},{executables:{win32:["Terraria.exe"]},id:259,name:"Terraria"},{executables:{win32:["Bethesda.net_Launcher.exe"]},id:260,name:"The Elder Scrolls Online"},{executables:{win32:["TESV.exe"]},id:261,name:"The Elder Scrolls V: Skyrim"},{executables:{win32:["TheSecretWorld.exe"]},id:262,name:"The Secret World"},{executables:{win32:["TS3.exe","ts3w.exe"]},id:264,name:"The Sims 3"},{executables:{win32:["WALKINGDEAD101.EXE"]},id:265,name:"The Walking Dead"},{executables:{win32:["TheWalkingDead2.exe"]},id:266,name:"The Walking Dead Season Two"},{executables:{win32:["witcher3.exe"]},id:267,name:"The Witcher 3"},{executables:{win32:["Future Soldier.exe"]},id:268,name:"Tom Clancy's Ghost Recon: Future Solider"},{executables:{win32:["TombRaider.exe"]},id:269,name:"Tomb Raider (2013)"},{executables:{win32:["Torchlight.exe"]},id:271,name:"Torchlight"},{executables:{win32:["Torchlight2.exe"]},id:272,name:"Torchlight 2"},{executables:{win32:["Shogun2.exe"]},id:273,name:"Total War: Shogun 2"},{executables:{win32:["Transistor.exe"]},id:274,name:"Transistor"},{executables:{win32:["trine.exe"]},id:275,name:"Trine"},{executables:{win32:["trine2_32bit.exe"]},id:276,name:"Trine 2"},{executables:{win32:["UOKR.exe"]},id:277,name:"Ultima Online"},{executables:{win32:["aces.exe"]},id:279,name:"War Thunder"},{executables:{win32:["Warcraft III.exe","wc3.exe"]},id:281,name:"Warcraft 3: Reign of Chaos"},{executables:{win32:["Warcraft II BNE.exe"]},id:282,name:"Warcraft II"},{executables:{win32:["Warframe.x64.exe","Warframe.exe"]},id:283,name:"Warframe"},{executables:{win32:["watch_dogs.exe"]},id:284,name:"Watch Dogs"},{executables:{win32:["WildStar64.exe"]},id:285,name:"WildStar"},{executables:{win32:["XComGame.exe"]},id:288,name:"XCOM: Enemy Unknown"},{executables:{win32:["DFO.exe","dfo.exe"]},id:289,name:"Dungeon Fighter Online"},{executables:{win32:["aclauncher.exe","acclient.exe"]},id:290,name:"Asheron's Call"},{executables:{win32:["MapleStory2.exe"]},id:291,name:"MapleStory 2"},{executables:{win32:["ksp.exe"]},id:292,name:"Kerbal Space Program"},{executables:{win32:["PINBALL.EXE"]},id:293,name:"3D Pinball: Space Cadet"},{executables:{win32:["dave.exe"]},id:294,name:"Dangerous Dave"},{executables:{win32:["iwbtgbeta(slomo).exe","iwbtgbeta(fs).exe"]},id:295,name:"I Wanna Be The Guy"},{executables:{win32:["MechWarriorOnline.exe "]},id:296,name:"Mech Warrior Online"},{executables:{win32:["dontstarve_steam.exe"]},id:297,name:"Don't Starve"},{executables:{win32:["GalCiv3.exe"]},id:298,name:"Galactic Civilization 3"},{executables:{win32:["Risk of Rain.exe"]},id:299,name:"Risk of Rain"},{executables:{win32:["Binding_of_Isaac.exe","Isaac-ng.exe"]},id:300,name:"The Binding of Isaac"},{executables:{win32:["RustClient.exe"]},id:301,name:"Rust"},{executables:{win32:["Clicker Heroes.exe"]},id:302,name:"Clicker Heroes"},{executables:{win32:["Brawlhalla.exe"]},id:303,name:"Brawlhalla"},{executables:{win32:["TownOfSalem.exe"]},id:304,name:"Town of Salem"},{executables:{win32:["osu!.exe"]},id:305,name:"osu!"},{executables:{win32:["PathOfExileSteam.exe","PathOfExile.exe"]},id:306,name:"Path of Exile"},{executables:{win32:["Dolphin.exe"]},id:307,name:"Dolphin"},{executables:{win32:["RocketLeague.exe"]},id:308,name:"Rocket League"},{executables:{win32:["TJPP.exe"]},id:309,name:"Jackbox Party Pack"},{executables:{win32:["KFGame.exe"]},id:310,name:"Killing Floor 2"},{executables:{win32:["ShooterGame.exe"]},id:311,name:"Ark: Survival Evolved"},{executables:{win32:["LifeIsStrange.exe"]},id:312,name:"Life Is Strange"},{executables:{win32:["Client_tos.exe"]},id:313,name:"Tree of Savior"},{executables:{win32:["olliolli2.exe"]},id:314,name:"OlliOlli2"},{executables:{win32:["cw.exe"]},id:315,name:"Closers Dimension Conflict"},{executables:{win32:["ESSTEAM.exe","elsword.exe","x2.exe"]},id:316,name:"Elsword"},{executables:{win32:["ori.exe"]},id:317,name:"Ori and the Blind Forest"},{executables:{win32:["Skyforge.exe"]},id:318,name:"Skyforge"},{executables:{win32:["projectzomboid64.exe","projectzomboid32.exe"]},id:319,name:"Project Zomboid"},{executables:{win32:["From_The_Depths.exe"]},id:320,name:"The Depths"},{executables:{win32:["TheCrew.exe"]},id:321,name:"The Crew"},{executables:{win32:["MarvelHeroes2015.exe"]},id:322,name:"Marvel Heroes 2015"},{executables:{win32:["timeclickers.exe"]},id:324,name:"Time Clickers"},{executables:{win32:["eurotrucks2.exe"]},id:325,name:"Euro Truck Simulator 2"},{executables:{win32:["FarmingSimulator2015Game.exe"]},id:326,name:"Farming Simulator 15"},{executables:{win32:["strife.exe"]},id:327,name:"Strife"},{executables:{win32:["Awesomenauts.exe"]},id:328,name:"Awesomenauts"},{executables:{win32:["Dofus.exe"]},id:329,name:"Dofus"},{executables:{win32:["Boid.exe"]},id:330,name:"Boid"},{executables:{win32:["adventure-capitalist.exe"]},id:331,name:"AdVenture Capitalist"},{executables:{win32:["OrcsMustDie2.exe"]},id:332,name:"Orcs Must Die! 2"},{executables:{win32:["Mountain.exe"]},id:333,name:"Mountain"},{executables:{win32:["Valkyria.exe"]},id:335,name:"Valkyria Chronicles"},{executables:{win32:["ffxiiiimg.exe"]},id:336,name:"Final Fantasy XIII"},{executables:{win32:["TLR.exe"]},id:337,name:"The Last Remnant"},{executables:{win32:["Cities.exe"]},id:339,name:"Cities Skylines"},{executables:{win32:["worldofwarships.exe","WoWSLauncher.exe"]},id:341,name:"World of Warships"},{executables:{win32:["spacegame-Win64-shipping.exe"]},id:342,name:"Fractured Space"},{executables:{win32:["thespacegame.exe"]},id:343,name:"Ascent - The Space Game"},{executables:{win32:["DuckGame.exe"]},id:344,name:"Duck Game"},{executables:{win32:["PPSSPPWindows.exe"]},id:345,name:"PPSSPP"},{executables:{win32:["MBAA.exe"]},id:346,name:"Melty Blood Actress Again: Current Code"},{executables:{win32:["TheWolfAmongUs.exe"]},id:347,name:"The Wolf Among Us"},{executables:{win32:["SpaceEngineers.exe"]},id:348,name:"Space Engineers"},{executables:{win32:["Borderlands.exe"]},id:349,name:"Borderlands"},{executables:{win32:["100orange.exe"]},id:351,name:"100% Orange Juice"},{executables:{win32:["reflex.exe"]},id:354,name:"Reflex"},{executables:{win32:["pso2.exe"]},id:355,name:"Phantasy Star Online 2"},{executables:{win32:["AssettoCorsa.exe"]},id:356,name:"Assetto Corsa"},{executables:{win32:["iw3mp.exe","iw3sp.exe"]},id:357,name:"Call of Duty 4: Modern Warfare"},{executables:{win32:["WolfOldBlood_x64.exe"]},id:358,name:"Wolfenstein: The Old Blood"},{executables:{win32:["castle.exe"]},id:359,name:"Castle Crashers"},{executables:{win32:["vindictus.exe"]},id:360,name:"Vindictus"},{executables:{win32:["ShooterGame-Win32-Shipping.exe"]},id:361,name:"Dirty Bomb"},{executables:{win32:["BatmanAK.exe"]},id:362,name:"Batman Arkham Knight"},{executables:{win32:["drt.exe"]},id:363,name:"Dirt Rally"},{executables:{win32:["rFactor.exe"]},id:364,name:"rFactor"},{executables:{win32:["clonk.exe"]},id:365,name:"Clonk Rage"},{executables:{win32:["SRHK.exe"]},id:366,name:"Shadowrun: Hong Kong"},{executables:{win32:["Insurgency.exe"]},id:367,name:"Insurgency"},{executables:{win32:["StepMania.exe"]},id:368,name:"Step Mania"},{executables:{win32:["FirefallCLient.exe"]},id:369,name:"Firefall"},{executables:{win32:["mirrorsedge.exe"]},id:370,name:"Mirrors Edge"},{executables:{win32:["MgsGroundZeroes.exe"]},id:371,name:"Metal Gear Solid V: Ground Zeroes"},{executables:{win32:["mgsvtpp.exe"]},id:372,name:"Metal Gear Solid V: The Phantom Pain"},{executables:{win32:["tld.exe"]},id:373,name:"The Long Dark"},{executables:{win32:["TKOM.exe"]},id:374,name:"Take On Mars"},{executables:{win32:["robloxplayerlauncher.exe","Roblox.exe"]},id:375,name:"Roblox"},{executables:{win32:["eu4.exe"]},id:376,name:"Europa Universalis 4"},{executables:{win32:["APB.exe"]},id:377,name:"APB Reloaded"},{executables:{win32:["Robocraft.exe"]},id:378,name:"Robocraft"},{executables:{win32:["Unity.exe"]},id:379,name:"Unity"},{executables:{win32:["Simpsons.exe"]},id:380,name:"The Simpsons: Hit & Run"},{executables:{win32:["Dnlauncher.exe","DragonNest.exe"]},id:381,name:"Dragon Nest"},{executables:{win32:["Trove.exe"]},id:382,name:"Trove"},{executables:{win32:["EndlessLegend.exe"]},id:383,name:"Endless Legend"},{executables:{win32:["TurbineLauncher.exe","dndclient.exe"]},id:384,name:"Dungeons & Dragons Online"},{executables:{win32:["quakelive.exe","quakelive_steam.exe"]},id:385,name:"Quake Live"},{executables:{win32:["7DaysToDie.exe"]},id:386,name:"7DaysToDie"},{executables:{win32:["SpeedRunners.exe"]},id:387,name:"SpeedRunners"},{executables:{win32:["gamemd.exe"]},id:388,name:"Command & Conquer: Red Alert 2"},{executables:{win32:["generals.exe"]},id:389,name:"Command & Conquer Generals: Zero Hour"},{executables:{win32:["Oblivion.exe"]},id:390,name:"The Elder Scrolls 4: Oblivion"},{executables:{win32:["mgsi.exe"]},id:391,name:"Metal Gear Solid"},{executables:{win32:["EoCApp.exe"]},id:392,name:"Divinity - Original Sin"},{executables:{win32:["Torment.exe"]},id:393,name:"Planescape: Torment"},{executables:{win32:["HexPatch.exe"]},id:394,name:"Hex: Shards of Fate"},{executables:{win32:["NS3FB.exe"]},id:395,name:"Naruto Shippuden Ultimate Ninja Storm 3 Full Burst"},{executables:{win32:["NSUNSR.exe"]},id:396,name:"Naruto Shippuden Ultimate Ninja Storm Revolution"},{executables:{win32:["SaintsRowIV.exe"]},id:397,name:"Saints Row IV"},{executables:{win32:["Shadowrun.exe"]},id:398,name:"Shadowrun"},{executables:{win32:["DungeonoftheEndless.exe"]},id:399,name:"Dungeon of the Endless"},{executables:{win32:["Hon.exe"]},id:400,name:"Heroes of Newerth"},{executables:{win32:["mabinogi.exe"]},id:401,name:"Mabinogi"},{executables:{win32:["CoD2MP_s.exe","CoDSP_s.exe"]},id:402,name:"Call of Duty 2:"},{executables:{win32:["CoDWaWmp.exe","CoDWaw.exe"]},id:403,name:"Call of Duty: World at War"},{executables:{win32:["heroes.exe"]},id:404,name:"Mabinogi Heroes (Vindictus) "},{executables:{win32:["KanColleViewer.exe"]},id:405,name:"KanColle "},{executables:{win32:["cyphers.exe"]},id:406,name:"Cyphers"},{executables:{win32:["RelicCoH2.exe"]},id:407,name:"Company of Heroes 2"},{executables:{win32:["MJ.exe"]},id:408,name:"セガNET麻雀MJ"},{executables:{win32:["ge.exe"]},id:409,name:"Granado Espada"},{executables:{win32:["NovaRO.exe"]},id:410,name:"Nova Ragnarok Online"},{executables:{win32:["RivalsofAether.exe"]},id:411,name:"Rivals of Aether"},{executables:{win32:["bfh.exe"]},id:412,name:"Battlefield Hardline"},{executables:{win32:["GrowHome.exe"]},id:413,name:"Grow Home"},{executables:{win32:["patriots.exe"]},id:414,name:"Rise of Nations Extended"},{executables:{win32:["Railroads.exe"]},id:415,name:"Sid Meier's Railroads!"},{executables:{win32:["Empire.exe"]},id:416,name:"Empire: Total War"},{executables:{win32:["Napoleon.exe"]},id:417,name:"Napoleon: Total War"},{executables:{win32:["gta_sa.exe"]},id:418,name:"Grand Theft Auto: San Andreas"},{executables:{win32:["MadMax.exe"]},id:419,name:"Mad Max"},{executables:{win32:["Titanfall.exe"]},id:420,name:"Titanfall"},{executables:{win32:["age2_x1.exe"]},id:421,name:"Age of Empires II: The Conquerors"},{executables:{win32:["Rome2.exe"]},id:422,name:"Total War: ROME 2"},{executables:{win32:["ShadowOfMordor.exe"]},id:423,name:"Middle-earth: Shadow of Mordor"},{executables:{win32:["Subnautica.exe"]},id:424,name:"Subnautica"},{executables:{win32:["anno5.exe"]},id:425,name:"Anno 2070"},{executables:{win32:["carrier.exe"]},id:426,name:"Carrier Command Gaea Mission"},{executables:{win32:["DarksidersPC.exe"]},id:427,name:"Darksiders"},{executables:{win32:["Darksiders2.exe"]},id:428,name:"Darksiders 2"},{executables:{win32:["mudlet.exe"]},id:429,name:"Mudlet"},{executables:{win32:["DunDefLauncher.exe"]},id:430,name:"Dungeon Defenders II"},{executables:{win32:["hng.exe"]},id:431,name:"Heroes and Generals"},{executables:{win32:["WFTOGame.exe"]},id:432,name:"War of the Overworld"},{executables:{win32:["Talisman.exe"]},id:433,name:"Talisman: Digital Edition"},{executables:{win32:["limbo.exe"]},id:434,name:"Limbo"},{executables:{win32:["ibbobb.exe"]},id:435,name:"ibb & obb"},{executables:{win32:["BattleBlockTheater.exe"]},id:436,name:"BattleBlock Theater"},{executables:{win32:["iracinglauncher.exe","iracingsim.exe","iracingsim64.exe"]},id:437,name:"iRacing"},{executables:{win32:["CivilizationV_DX11.exe"]},id:438,name:"Civilization V"}]},{}]},{},[5])(5)}); \ No newline at end of file From 239cb38e4db076b70737851ce9ec22598239e445 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 2 Oct 2015 21:38:46 +0100 Subject: [PATCH 094/151] 3.7.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 186f4b624..8da8d52dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.6.3", + "version": "3.7.0", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From eab6837f87d0c8c5b3abd695ca4690e1f55b2151 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 2 Oct 2015 21:40:45 +0100 Subject: [PATCH 095/151] Updated package.json --- gruntfile.js | 1 + package.json | 1 + 2 files changed, 2 insertions(+) diff --git a/gruntfile.js b/gruntfile.js index a8972256f..298e8c7c9 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -44,5 +44,6 @@ module.exports = function (grunt) { // register at least this one task grunt.registerTask('default', ['babel']); grunt.registerTask('web', ['browserify', "uglify"]); + grunt.registerTask("dist", ["babel", "browserify", "uglify"]) }; \ No newline at end of file diff --git a/package.json b/package.json index 8da8d52dd..e8621e6d2 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { + "prepublish": "grunt dist" "test": "node ./test/bot.js" }, "repository": { From 70f2dfef3e4ca2010c837ab0d903738802e1e505 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 2 Oct 2015 21:41:32 +0100 Subject: [PATCH 096/151] Fixed package.json.... --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e8621e6d2..3e6e30b09 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { - "prepublish": "grunt dist" + "prepublish": "grunt dist", "test": "node ./test/bot.js" }, "repository": { From 4e15ba1edd3e3c2761862fa11d5f1706e3ff0707 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 2 Oct 2015 21:41:35 +0100 Subject: [PATCH 097/151] 3.7.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3e6e30b09..af4e59f4b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.7.0", + "version": "3.7.1", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From 7361cf3dc36cafae2fd99714e8f8c617e2badb14 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 2 Oct 2015 21:42:03 +0100 Subject: [PATCH 098/151] 3.7.1 rebuild --- lib/Client.js | 2 +- lib/Endpoints.js | 2 +- lib/Member.js | 2 +- lib/PMChannel.js | 2 +- lib/Permissions.js | 2 +- lib/channel.js | 2 +- lib/index.js | 2 +- lib/internal.js | 2 +- lib/invite.js | 2 +- lib/message.js | 2 +- lib/server.js | 2 +- lib/user.js | 2 +- web-dist/discord.3.7.1.js | 3879 +++++++++++++++++++++++++++++++++ web-dist/discord.min.3.7.1.js | 2 + 14 files changed, 3893 insertions(+), 12 deletions(-) create mode 100644 web-dist/discord.3.7.1.js create mode 100644 web-dist/discord.min.3.7.1.js diff --git a/lib/Client.js b/lib/Client.js index 091424b16..4d097628b 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1925,4 +1925,4 @@ var Client = (function () { return Client; })(); -module.exports = Client; \ No newline at end of file +module.exports = Client; diff --git a/lib/Endpoints.js b/lib/Endpoints.js index 271b465eb..e55f0f580 100644 --- a/lib/Endpoints.js +++ b/lib/Endpoints.js @@ -10,4 +10,4 @@ exports.LOGIN = exports.AUTH + "/login"; exports.LOGOUT = exports.AUTH + "/logout"; exports.USERS = exports.API + "/users"; exports.SERVERS = exports.API + "/guilds"; -exports.CHANNELS = exports.API + "/channels"; \ No newline at end of file +exports.CHANNELS = exports.API + "/channels"; diff --git a/lib/Member.js b/lib/Member.js index 7d7b03f1a..471460e77 100644 --- a/lib/Member.js +++ b/lib/Member.js @@ -18,4 +18,4 @@ var Member = (function (_User) { } return Member; -})(User); \ No newline at end of file +})(User); diff --git a/lib/PMChannel.js b/lib/PMChannel.js index 0dbc0405e..6eb8134de 100644 --- a/lib/PMChannel.js +++ b/lib/PMChannel.js @@ -68,4 +68,4 @@ var PMChannel = (function () { return PMChannel; })(); -module.exports = PMChannel; \ No newline at end of file +module.exports = PMChannel; diff --git a/lib/Permissions.js b/lib/Permissions.js index a1f4f3083..3b7c8f256 100644 --- a/lib/Permissions.js +++ b/lib/Permissions.js @@ -45,4 +45,4 @@ var Permission = (function () { }]); return Permission; -})(); \ No newline at end of file +})(); diff --git a/lib/channel.js b/lib/channel.js index bb67fcf4f..90a2d7428 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -98,4 +98,4 @@ var Channel = (function () { return Channel; })(); -module.exports = Channel; \ No newline at end of file +module.exports = Channel; diff --git a/lib/index.js b/lib/index.js index 6a2f82f05..f0c3c0ab7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -9,4 +9,4 @@ var Discord = { Client: Client }; -module.exports = Discord; \ No newline at end of file +module.exports = Discord; diff --git a/lib/internal.js b/lib/internal.js index 3acf5940b..e8b3385da 100644 --- a/lib/internal.js +++ b/lib/internal.js @@ -200,4 +200,4 @@ Internal.XHR.setUsername = function (token, avatar, email, newPassword, password }); }; -exports.Internal = Internal; \ No newline at end of file +exports.Internal = Internal; diff --git a/lib/invite.js b/lib/invite.js index 5f51dc1a9..7bc8204bd 100644 --- a/lib/invite.js +++ b/lib/invite.js @@ -32,4 +32,4 @@ var Invite = (function () { return Invite; })(); -module.exports = Invite; \ No newline at end of file +module.exports = Invite; diff --git a/lib/message.js b/lib/message.js index 3dd4ddcae..f3f3c574a 100644 --- a/lib/message.js +++ b/lib/message.js @@ -76,4 +76,4 @@ var Message = (function () { return Message; })(); -module.exports = Message; \ No newline at end of file +module.exports = Message; diff --git a/lib/server.js b/lib/server.js index c8758d5da..8bd9332a2 100644 --- a/lib/server.js +++ b/lib/server.js @@ -180,4 +180,4 @@ var Server = (function () { return Server; })(); -module.exports = Server; \ No newline at end of file +module.exports = Server; diff --git a/lib/user.js b/lib/user.js index 5e38e132e..e2b2ca256 100644 --- a/lib/user.js +++ b/lib/user.js @@ -54,4 +54,4 @@ var User = (function () { return User; })(); -module.exports = User; \ No newline at end of file +module.exports = User; diff --git a/web-dist/discord.3.7.1.js b/web-dist/discord.3.7.1.js new file mode 100644 index 000000000..0d9f9341a --- /dev/null +++ b/web-dist/discord.3.7.1.js @@ -0,0 +1,3879 @@ +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Discord = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o]*>/g) || [])[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var mention = _step3.value; + + _mentions.push(mention.substring(2, mention.length - 1)); + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3["return"]) { + _iterator3["return"](); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + + return _mentions; + } + }); + + return prom; + } + + //def createws + }, { + key: "createws", + value: function createws(url) { + if (this.websocket) return false; + + var self = this; + + //good to go + this.websocket = new WebSocket(url); + + //open + this.websocket.onopen = function () { + self.trySendConnData(); //try connecting + }; + + //close + this.websocket.onclose = function () { + self.trigger("disconnected"); + }; + + //message + this.websocket.onmessage = function (e) { + + var dat = false, + data = {}; + + try { + dat = JSON.parse(e.data); + data = dat.d; + } catch (err) { + self.trigger("error", err, e); + return; + } + + self.trigger("raw", dat); + + //valid message + switch (dat.t) { + + case "READY": + self.debug("received ready packet"); + + self.user = self.addUser(data.user); + + var _iteratorNormalCompletion4 = true; + var _didIteratorError4 = false; + var _iteratorError4 = undefined; + + try { + for (var _iterator4 = data.guilds[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var _server = _step4.value; + + var server = self.addServer(_server); + } + } catch (err) { + _didIteratorError4 = true; + _iteratorError4 = err; + } finally { + try { + if (!_iteratorNormalCompletion4 && _iterator4["return"]) { + _iterator4["return"](); + } + } finally { + if (_didIteratorError4) { + throw _iteratorError4; + } + } + } + + var _iteratorNormalCompletion5 = true; + var _didIteratorError5 = false; + var _iteratorError5 = undefined; + + try { + for (var _iterator5 = data.private_channels[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { + var _pmc = _step5.value; + + var pmc = self.addPMChannel(_pmc); + } + } catch (err) { + _didIteratorError5 = true; + _iteratorError5 = err; + } finally { + try { + if (!_iteratorNormalCompletion5 && _iterator5["return"]) { + _iterator5["return"](); + } + } finally { + if (_didIteratorError5) { + throw _iteratorError5; + } + } + } + + self.trigger("ready"); + self.readyTime = Date.now(); + self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users."); + self.state = 3; + setInterval(function () { + self.keepAlive.apply(self); + }, data.heartbeat_interval); + + break; + case "MESSAGE_CREATE": + self.debug("received message"); + + var mentions = []; + data.mentions = data.mentions || []; //for some reason this was not defined at some point? + var _iteratorNormalCompletion6 = true; + var _didIteratorError6 = false; + var _iteratorError6 = undefined; + + try { + for (var _iterator6 = data.mentions[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { + var mention = _step6.value; + + mentions.push(self.addUser(mention)); + } + } catch (err) { + _didIteratorError6 = true; + _iteratorError6 = err; + } finally { + try { + if (!_iteratorNormalCompletion6 && _iterator6["return"]) { + _iterator6["return"](); + } + } finally { + if (_didIteratorError6) { + throw _iteratorError6; + } + } + } + + var channel = self.getChannel("id", data.channel_id); + if (channel) { + var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); + self.trigger("message", msg); + } + + break; + case "MESSAGE_DELETE": + self.debug("message deleted"); + + var channel = self.getChannel("id", data.channel_id); + var message = channel.getMessage("id", data.id); + if (message) { + self.trigger("messageDelete", channel, message); + channel.messages.splice(channel.messages.indexOf(message), 1); + } else { + //don't have the cache of that message ;( + self.trigger("messageDelete", channel); + } + break; + case "MESSAGE_UPDATE": + self.debug("message updated"); + + var channel = self.getChannel("id", data.channel_id); + var formerMessage = channel.getMessage("id", data.id); + + if (formerMessage) { + + //new message might be partial, so we need to fill it with whatever the old message was. + var info = {}; + + for (var key in formerMessage) { + info[key] = formerMessage[key]; + } + + for (var key in data) { + info[key] = data[key]; + } + + var mentions = []; + var _iteratorNormalCompletion7 = true; + var _didIteratorError7 = false; + var _iteratorError7 = undefined; + + try { + for (var _iterator7 = info.mentions[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { + var mention = _step7.value; + + mentions.push(self.addUser(mention)); + } + } catch (err) { + _didIteratorError7 = true; + _iteratorError7 = err; + } finally { + try { + if (!_iteratorNormalCompletion7 && _iterator7["return"]) { + _iterator7["return"](); + } + } finally { + if (_didIteratorError7) { + throw _iteratorError7; + } + } + } + + var newMessage = new Message(info, channel, mentions, formerMessage.author); + + self.trigger("messageUpdate", newMessage, formerMessage); + + channel.messages[channel.messages.indexOf(formerMessage)] = newMessage; + } + + // message isn't in cache, and if it's a partial it could cause + // all hell to break loose... best to just act as if nothing happened + + break; + + case "GUILD_DELETE": + + var server = self.getServer("id", data.id); + + if (server) { + self.serverCache.splice(self.serverCache.indexOf(server), 1); + self.trigger("serverDelete", server); + } + + break; + + case "CHANNEL_DELETE": + + var channel = self.getChannel("id", data.id); + + if (channel) { + + var server = channel.server; + + if (server) { + + server.channels.splice(server.channels.indexOf(channel), 1); + } + + self.trigger("channelDelete", channel); + + self.serverCache.splice(self.serverCache.indexOf(channel), 1); + } + + break; + + case "GUILD_CREATE": + + var server = self.getServer("id", data.id); + + if (!server) { + //if server doesn't already exist because duh + server = self.addServer(data); + } /*else if(server.channels.length === 0){ + + var srv = new Server(data, self); + for(channel of data.channels){ + srv.channels.push(new Channel(channel, data.id)); + } + self.serverCache[self.serverCache.indexOf(server)] = srv; + + }*/ + + if (self.serverCreateListener[data.id]) { + var cbs = self.serverCreateListener[data.id]; + cbs[0](server); //promise then callback + cbs[1](null, server); //legacy callback + self.serverCreateListener[data.id] = null; + } + + self.trigger("serverCreate", server); + + break; + + case "CHANNEL_CREATE": + + var channel = self.getChannel("id", data.id); + + if (!channel) { + + var chann = self.addChannel(data, data.guild_id); + var srv = self.getServer("id", data.guild_id); + if (srv) { + srv.addChannel(chann); + } + self.trigger("channelCreate", chann); + } + + break; + + case "GUILD_MEMBER_ADD": + + var server = self.getServer("id", data.guild_id); + + if (server) { + + var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. + + if (! ~server.members.indexOf(user)) { + server.members.push(user); + } + + self.trigger("serverNewMember", user, server); + } + + break; + + case "GUILD_MEMBER_REMOVE": + + var server = self.getServer("id", data.guild_id); + + if (server) { + + var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. + + if (~server.members.indexOf(user)) { + server.members.splice(server.members.indexOf(user), 1); + } + + self.trigger("serverRemoveMember", user, server); + } + + break; + + case "USER_UPDATE": + + if (self.user && data.id === self.user.id) { + + var newUser = new User(data); //not actually adding to the cache + + self.trigger("userUpdate", newUser, self.user); + + if (~self.userCache.indexOf(self.user)) { + self.userCache[self.userCache.indexOf(self.user)] = newUser; + } + + self.user = newUser; + } + + break; + + case "PRESENCE_UPDATE": + + var userInCache = self.getUser("id", data.user.id); + + if (userInCache) { + //user exists + var presenceUser = new User(data.user); + if (presenceUser.equalsStrict(userInCache)) { + //they're exactly the same, an actual presence update + userInCache.status = data.status; + self.trigger("presence", { + user: userInCache, + status: data.status, + server: self.getServer("id", data.guild_id), + gameId: data.game_id + }); + } else { + //one of their details changed. + self.trigger("userUpdate", userInCache, presenceUser); + self.userCache[self.userCache.indexOf(userInCache)] = presenceUser; + } + } + + break; + + case "CHANNEL_UPDATE": + + var channelInCache = self.getChannel("id", data.id), + serverInCache = self.getServer("id", data.guild_id); + + if (channelInCache && serverInCache) { + + var newChann = new Channel(data, serverInCache); + newChann.messages = channelInCache.messages; + + self.trigger("channelUpdate", channelInCache, newChann); + + self.channelCache[self.channelCache.indexOf(channelInCache)] = newChann; + } + + break; + + default: + self.debug("received unknown packet"); + self.trigger("unknown", dat); + break; + + } + }; + } + + //def addUser + }, { + key: "addUser", + value: function addUser(data) { + if (!this.getUser("id", data.id)) { + this.userCache.push(new User(data)); + } + return this.getUser("id", data.id); + } + + //def addChannel + }, { + key: "addChannel", + value: function addChannel(data, serverId) { + if (!this.getChannel("id", data.id)) { + this.channelCache.push(new Channel(data, this.getServer("id", serverId))); + } + return this.getChannel("id", data.id); + } + }, { + key: "addPMChannel", + value: function addPMChannel(data) { + if (!this.getPMChannel("id", data.id)) { + this.pmChannelCache.push(new PMChannel(data, this)); + } + return this.getPMChannel("id", data.id); + } + }, { + key: "setTopic", + value: function setTopic(channel, topic) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + + self.resolveDestination(channel).then(next)["catch"](error); + + function error(e) { + callback(e); + reject(e); + } + + function next(destination) { + + var asChan = self.getChannel("id", destination); + + request.patch(Endpoints.CHANNELS + "/" + destination).set("authorization", self.token).send({ + name: asChan.name, + position: 0, + topic: topic + }).end(function (err, res) { + if (err) { + error(err); + } else { + asChan.topic = res.body.topic; + resolve(); + callback(); + } + }); + } + }); + } + + //def addServer + }, { + key: "addServer", + value: function addServer(data) { + + var self = this; + var server = this.getServer("id", data.id); + + if (data.unavailable) { + self.trigger("unavailable", data); + self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached."); + return; + } + + if (!server) { + server = new Server(data, this); + this.serverCache.push(server); + if (data.channels) { + var _iteratorNormalCompletion8 = true; + var _didIteratorError8 = false; + var _iteratorError8 = undefined; + + try { + for (var _iterator8 = data.channels[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) { + var channel = _step8.value; + + server.channels.push(this.addChannel(channel, server.id)); + } + } catch (err) { + _didIteratorError8 = true; + _iteratorError8 = err; + } finally { + try { + if (!_iteratorNormalCompletion8 && _iterator8["return"]) { + _iterator8["return"](); + } + } finally { + if (_didIteratorError8) { + throw _iteratorError8; + } + } + } + } + } + + var _iteratorNormalCompletion9 = true; + var _didIteratorError9 = false; + var _iteratorError9 = undefined; + + try { + for (var _iterator9 = data.presences[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) { + var presence = _step9.value; + + self.getUser("id", presence.user.id).status = presence.status; + } + } catch (err) { + _didIteratorError9 = true; + _iteratorError9 = err; + } finally { + try { + if (!_iteratorNormalCompletion9 && _iterator9["return"]) { + _iterator9["return"](); + } + } finally { + if (_didIteratorError9) { + throw _iteratorError9; + } + } + } + + return server; + } + + //def getUser + }, { + key: "getUser", + value: function getUser(key, value) { + var _iteratorNormalCompletion10 = true; + var _didIteratorError10 = false; + var _iteratorError10 = undefined; + + try { + for (var _iterator10 = this.userCache[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) { + var user = _step10.value; + + if (user[key] === value) { + return user; + } + } + } catch (err) { + _didIteratorError10 = true; + _iteratorError10 = err; + } finally { + try { + if (!_iteratorNormalCompletion10 && _iterator10["return"]) { + _iterator10["return"](); + } + } finally { + if (_didIteratorError10) { + throw _iteratorError10; + } + } + } + + return null; + } + + //def getChannel + }, { + key: "getChannel", + value: function getChannel(key, value) { + var _iteratorNormalCompletion11 = true; + var _didIteratorError11 = false; + var _iteratorError11 = undefined; + + try { + for (var _iterator11 = this.channelCache[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) { + var channel = _step11.value; + + if (channel[key] === value) { + return channel; + } + } + } catch (err) { + _didIteratorError11 = true; + _iteratorError11 = err; + } finally { + try { + if (!_iteratorNormalCompletion11 && _iterator11["return"]) { + _iterator11["return"](); + } + } finally { + if (_didIteratorError11) { + throw _iteratorError11; + } + } + } + + return this.getPMChannel(key, value); //might be a PM + } + }, { + key: "getPMChannel", + value: function getPMChannel(key, value) { + var _iteratorNormalCompletion12 = true; + var _didIteratorError12 = false; + var _iteratorError12 = undefined; + + try { + for (var _iterator12 = this.pmChannelCache[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) { + var channel = _step12.value; + + if (channel[key] === value) { + return channel; + } + } + } catch (err) { + _didIteratorError12 = true; + _iteratorError12 = err; + } finally { + try { + if (!_iteratorNormalCompletion12 && _iterator12["return"]) { + _iterator12["return"](); + } + } finally { + if (_didIteratorError12) { + throw _iteratorError12; + } + } + } + + return null; + } + + //def getServer + }, { + key: "getServer", + value: function getServer(key, value) { + var _iteratorNormalCompletion13 = true; + var _didIteratorError13 = false; + var _iteratorError13 = undefined; + + try { + for (var _iterator13 = this.serverCache[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) { + var server = _step13.value; + + if (server[key] === value) { + return server; + } + } + } catch (err) { + _didIteratorError13 = true; + _iteratorError13 = err; + } finally { + try { + if (!_iteratorNormalCompletion13 && _iterator13["return"]) { + _iterator13["return"](); + } + } finally { + if (_didIteratorError13) { + throw _iteratorError13; + } + } + } + + return null; + } + + //def trySendConnData + }, { + key: "trySendConnData", + value: function trySendConnData() { + + if (this.token && !this.alreadySentData) { + + this.alreadySentData = true; + + var data = { + op: 2, + d: { + token: this.token, + v: 3, + properties: { + "$os": "discord.js", + "$browser": "discord.js", + "$device": "discord.js", + "$referrer": "", + "$referring_domain": "" + } + } + }; + this.websocket.send(JSON.stringify(data)); + } + } + }, { + key: "resolveServerID", + value: function resolveServerID(resource) { + + if (resource instanceof Server) { + return resource.id; + } else if (!isNaN(resource) && resource.length && resource.length === 17) { + return resource; + } + } + }, { + key: "resolveDestination", + value: function resolveDestination(destination) { + var channId = false; + var self = this; + + return new Promise(function (resolve, reject) { + if (destination instanceof Server) { + channId = destination.id; //general is the same as server id + } else if (destination instanceof Channel) { + channId = destination.id; + } else if (destination instanceof Message) { + channId = destination.channel.id; + } else if (destination instanceof PMChannel) { + channId = destination.id; + } else if (destination instanceof User) { + + //check if we have a PM + var _iteratorNormalCompletion14 = true; + var _didIteratorError14 = false; + var _iteratorError14 = undefined; + + try { + for (var _iterator14 = self.pmChannelCache[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) { + var pmc = _step14.value; + + if (pmc.user.equals(destination)) { + resolve(pmc.id); + return; + } + } + + //we don't, at this point we're late + } catch (err) { + _didIteratorError14 = true; + _iteratorError14 = err; + } finally { + try { + if (!_iteratorNormalCompletion14 && _iterator14["return"]) { + _iterator14["return"](); + } + } finally { + if (_didIteratorError14) { + throw _iteratorError14; + } + } + } + + self.startPM(destination).then(function (pmc) { + resolve(pmc.id); + })["catch"](reject); + } else { + channId = destination; + } + if (channId) resolve(channId);else reject(); + }); + } + }, { + key: "_sendMessage", + value: function _sendMessage(destination, content, tts, mentions) { + + var self = this; + + return new Promise(function (resolve, reject) { + request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).send({ + content: content, + mentions: mentions, + tts: tts + }).end(function (err, res) { + + if (err) { + reject(err); + } else { + var data = res.body; + + var mentions = []; + + data.mentions = data.mentions || []; //for some reason this was not defined at some point? + + var _iteratorNormalCompletion15 = true; + var _didIteratorError15 = false; + var _iteratorError15 = undefined; + + try { + for (var _iterator15 = data.mentions[Symbol.iterator](), _step15; !(_iteratorNormalCompletion15 = (_step15 = _iterator15.next()).done); _iteratorNormalCompletion15 = true) { + var mention = _step15.value; + + mentions.push(self.addUser(mention)); + } + } catch (err) { + _didIteratorError15 = true; + _iteratorError15 = err; + } finally { + try { + if (!_iteratorNormalCompletion15 && _iterator15["return"]) { + _iterator15["return"](); + } + } finally { + if (_didIteratorError15) { + throw _iteratorError15; + } + } + } + + var channel = self.getChannel("id", data.channel_id); + if (channel) { + var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); + resolve(msg); + } + } + }); + }); + } + }, { + key: "_sendFile", + value: function _sendFile(destination, attachment) { + var attachmentName = arguments.length <= 2 || arguments[2] === undefined ? "DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png" : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).attach("file", attachment, attachmentName).end(function (err, res) { + + if (err) { + reject(err); + } else { + + var chann = self.getChannel("id", destination); + if (chann) { + var msg = chann.addMessage(new Message(res.body, chann, [], self.user)); + resolve(msg); + } + } + }); + }); + } + }, { + key: "_updateMessage", + value: function _updateMessage(message, content) { + var self = this; + return new Promise(function (resolve, reject) { + request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).send({ + content: content, + mentions: [] + }).end(function (err, res) { + if (err) { + reject(err); + } else { + var msg = new Message(res.body, message.channel, message.mentions, message.sender); + resolve(msg); + message.channel.messages[message.channel.messages.indexOf(message)] = msg; + } + }); + }); + } + }, { + key: "_deleteMessage", + value: function _deleteMessage(message) { + var self = this; + return new Promise(function (resolve, reject) { + + request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + }); + } + }, { + key: "checkQueue", + value: function checkQueue(channelID) { + var _this = this; + + var self = this; + + if (!this.checkingQueue[channelID]) { + (function () { + var doNext = function doNext() { + if (self.queue[channelID].length === 0) { + done(); + return; + } + var queuedEvent = self.queue[channelID][0]; + switch (queuedEvent.action) { + case "sendMessage": + var msgToSend = queuedEvent; + self._sendMessage(channelID, msgToSend.content, msgToSend.tts, msgToSend.mentions).then(function (msg) { + msgToSend.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + msgToSend.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + case "sendFile": + var fileToSend = queuedEvent; + self._sendFile(channelID, fileToSend.attachment, fileToSend.attachmentName).then(function (msg) { + fileToSend.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + fileToSend.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + case "updateMessage": + var msgToUpd = queuedEvent; + self._updateMessage(msgToUpd.message, msgToUpd.content).then(function (msg) { + msgToUpd.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + msgToUpd.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + case "deleteMessage": + var msgToDel = queuedEvent; + self._deleteMessage(msgToDel.message).then(function (msg) { + msgToDel.then(msg); + self.queue[channelID].shift(); + doNext(); + })["catch"](function (err) { + msgToDel.error(err); + self.queue[channelID].shift(); + doNext(); + }); + break; + default: + done(); + break; + } + }; + + var done = function done() { + self.checkingQueue[channelID] = false; + return; + }; + + //if we aren't already checking this queue. + _this.checkingQueue[channelID] = true; + doNext(); + })(); + } + } + }, { + key: "getGateway", + value: function getGateway() { + var self = this; + return new Promise(function (resolve, reject) { + request.get(Endpoints.API + "/gateway").set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(res.body.url); + } + }); + }); + } + }, { + key: "setStatusIdle", + value: function setStatusIdle() { + this.setStatus("idle"); + } + }, { + key: "setStatusOnline", + value: function setStatusOnline() { + this.setStatus("online"); + } + }, { + key: "setStatusActive", + value: function setStatusActive() { + this.setStatusOnline(); + } + }, { + key: "setStatusHere", + value: function setStatusHere() { + this.setStatusOnline(); + } + }, { + key: "setStatusAway", + value: function setStatusAway() { + this.setStatusIdle(); + } + }, { + key: "startTyping", + value: function startTyping(chann, stopTypeTime) { + var self = this; + + this.resolveDestination(chann).then(next); + + function next(channel) { + if (self.typingIntervals[channel]) { + return; + } + + var fn = function fn() { + request.post(Endpoints.CHANNELS + "/" + channel + "/typing").set("authorization", self.token).end(); + }; + + fn(); + + var interval = setInterval(fn, 3000); + + self.typingIntervals[channel] = interval; + + if (stopTypeTime) { + setTimeout(function () { + self.stopTyping(channel); + }, stopTypeTime); + } + } + } + }, { + key: "stopTyping", + value: function stopTyping(chann) { + var self = this; + + this.resolveDestination(chann).then(next); + + function next(channel) { + if (!self.typingIntervals[channel]) { + return; + } + + clearInterval(self.typingIntervals[channel]); + + delete self.typingIntervals[channel]; + } + } + }, { + key: "setStatus", + value: function setStatus(stat) { + + var idleTime = stat === "online" ? null : Date.now(); + + this.__idleTime = idleTime; + + this.websocket.send(JSON.stringify({ + op: 3, + d: { + idle_since: this.__idleTime, + game_id: this.__gameId + } + })); + } + }, { + key: "setPlayingGame", + value: function setPlayingGame(id) { + + if (id instanceof String || typeof id === "string") { + + // working on names + var gid = id.trim().toUpperCase(); + + id = null; + + var _iteratorNormalCompletion16 = true; + var _didIteratorError16 = false; + var _iteratorError16 = undefined; + + try { + for (var _iterator16 = gameMap[Symbol.iterator](), _step16; !(_iteratorNormalCompletion16 = (_step16 = _iterator16.next()).done); _iteratorNormalCompletion16 = true) { + var game = _step16.value; + + if (game.name.trim().toUpperCase() === gid) { + + id = game.id; + break; + } + } + } catch (err) { + _didIteratorError16 = true; + _iteratorError16 = err; + } finally { + try { + if (!_iteratorNormalCompletion16 && _iterator16["return"]) { + _iterator16["return"](); + } + } finally { + if (_didIteratorError16) { + throw _iteratorError16; + } + } + } + } + + this.__gameId = id; + + this.websocket.send(JSON.stringify({ + op: 3, + d: { + idle_since: this.__idleTime, + game_id: this.__gameId + } + })); + } + }, { + key: "playGame", + value: function playGame(id) { + this.setPlayingGame(id); + } + }, { + key: "playingGame", + value: function playingGame(id) { + + this.setPlayingGame(id); + } + }, { + key: "uptime", + get: function get() { + + return this.readyTime ? Date.now() - this.readyTime : null; + } + }, { + key: "ready", + get: function get() { + return this.state === 3; + } + }, { + key: "servers", + get: function get() { + return this.serverCache; + } + }, { + key: "channels", + get: function get() { + return this.channelCache; + } + }, { + key: "users", + get: function get() { + return this.userCache; + } + }, { + key: "PMChannels", + get: function get() { + return this.pmChannelCache; + } + }, { + key: "messages", + get: function get() { + + var msgs = []; + var _iteratorNormalCompletion17 = true; + var _didIteratorError17 = false; + var _iteratorError17 = undefined; + + try { + for (var _iterator17 = this.channelCache[Symbol.iterator](), _step17; !(_iteratorNormalCompletion17 = (_step17 = _iterator17.next()).done); _iteratorNormalCompletion17 = true) { + var channel = _step17.value; + + msgs = msgs.concat(channel.messages); + } + } catch (err) { + _didIteratorError17 = true; + _iteratorError17 = err; + } finally { + try { + if (!_iteratorNormalCompletion17 && _iterator17["return"]) { + _iterator17["return"](); + } + } finally { + if (_didIteratorError17) { + throw _iteratorError17; + } + } + } + + return msgs; + } + }]); + + return Client; +})(); + +module.exports = Client; + +},{"../ref/gameMap.json":15,"./Endpoints.js":2,"./PMChannel.js":3,"./channel.js":4,"./invite.js":6,"./message.js":7,"./server.js":8,"./user.js":9,"fs":10,"superagent":11,"ws":14}],2:[function(require,module,exports){ +"use strict"; + +exports.BASE_DOMAIN = "discordapp.com"; +exports.BASE = "https://" + exports.BASE_DOMAIN; +exports.WEBSOCKET_HUB = "wss://" + exports.BASE_DOMAIN + "/hub"; + +exports.API = exports.BASE + "/api"; +exports.AUTH = exports.API + "/auth"; +exports.LOGIN = exports.AUTH + "/login"; +exports.LOGOUT = exports.AUTH + "/logout"; +exports.USERS = exports.API + "/users"; +exports.SERVERS = exports.API + "/guilds"; +exports.CHANNELS = exports.API + "/channels"; + +},{}],3:[function(require,module,exports){ +"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 PMChannel = (function () { + function PMChannel(data, client) { + _classCallCheck(this, PMChannel); + + this.user = client.getUser("id", data.recipient.id); + this.id = data.id; + this.messages = []; + } + + _createClass(PMChannel, [{ + key: "addMessage", + value: function addMessage(data) { + if (!this.getMessage("id", data.id)) { + this.messages.push(data); + } + return this.getMessage("id", data.id); + } + }, { + key: "getMessage", + value: function getMessage(key, value) { + + if (this.messages.length > 1000) { + this.messages.splice(0, 1); + } + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var message = _step.value; + + if (message[key] === value) { + return message; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return null; + } + }, { + key: "isPrivate", + get: function get() { + return true; + } + }]); + + return PMChannel; +})(); + +module.exports = PMChannel; + +},{}],4:[function(require,module,exports){ +"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 Channel = (function () { + function Channel(data, server) { + _classCallCheck(this, Channel); + + this.server = server; + this.name = data.name; + this.type = data.type; + this.topic = data.topic; + this.id = data.id; + this.messages = []; + //this.isPrivate = isPrivate; //not sure about the implementation of this... + } + + _createClass(Channel, [{ + key: "equals", + value: function equals(object) { + return object && object.id === this.id; + } + }, { + key: "addMessage", + value: function addMessage(data) { + + if (this.messages.length > 1000) { + this.messages.splice(0, 1); + } + + if (!this.getMessage("id", data.id)) { + this.messages.push(data); + } + + return this.getMessage("id", data.id); + } + }, { + key: "getMessage", + value: function getMessage(key, value) { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var message = _step.value; + + if (message[key] === value) { + return message; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return null; + } + }, { + key: "toString", + value: function toString() { + return "<#" + this.id + ">"; + } + }, { + key: "client", + get: function get() { + return this.server.client; + } + }, { + key: "isPrivate", + get: function get() { + return false; + } + }, { + key: "users", + get: function get() { + return this.server.members; + } + }, { + key: "members", + get: function get() { + return this.server.members; + } + }]); + + return Channel; +})(); + +module.exports = Channel; + +},{}],5:[function(require,module,exports){ +"use strict"; + +var request = require("superagent"); +var Endpoints = require("./Endpoints.js"); +var Client = require("./Client.js"); + +var Discord = { + Endpoints: Endpoints, + Client: Client +}; + +module.exports = Discord; + +},{"./Client.js":1,"./Endpoints.js":2,"superagent":11}],6:[function(require,module,exports){ +"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 Invite = (function () { + function Invite(data, client) { + _classCallCheck(this, Invite); + + this.max_age = data.max_age; + this.code = data.code; + this.server = client.getServer("id", data.guild.id); + this.revoked = data.revoked; + this.created_at = Date.parse(data.created_at); + this.temporary = data.temporary; + this.uses = data.uses; + this.max_uses = data.uses; + this.inviter = client.addUser(data.inviter); + this.xkcd = data.xkcdpass; + this.channel = client.getChannel("id", data.channel.id); + } + + _createClass(Invite, [{ + key: "URL", + get: function get() { + var code = this.xkcd ? this.xkcdpass : this.code; + return "https://discord.gg/" + code; + } + }]); + + return Invite; +})(); + +module.exports = Invite; + +},{}],7:[function(require,module,exports){ +"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 PMChannel = require("./PMChannel.js"); + +var Message = (function () { + function Message(data, channel, mentions, author) { + _classCallCheck(this, Message); + + this.tts = data.tts; + this.timestamp = Date.parse(data.timestamp); + this.nonce = data.nonce; + this.mentions = mentions; + this.everyoneMentioned = data.mention_everyone; + this.id = data.id; + this.embeds = data.embeds; + this.editedTimestamp = data.edited_timestamp; + this.content = data.content.trim(); + this.channel = channel; + this.author = author; + this.attachments = data.attachments; + } + + /*exports.Message.prototype.isPM = function() { + return ( this.channel instanceof PMChannel ); + }*/ + + _createClass(Message, [{ + key: "isMentioned", + value: function isMentioned(user) { + var id = user.id ? user.id : user; + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.mentions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var mention = _step.value; + + if (mention.id === id) { + return true; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return false; + } + }, { + key: "sender", + get: function get() { + return this.author; + } + }, { + key: "isPrivate", + get: function get() { + return this.channel.isPrivate; + } + }]); + + return Message; +})(); + +module.exports = Message; + +},{"./PMChannel.js":3}],8:[function(require,module,exports){ +"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 = (function () { + function Server(data, client) { + _classCallCheck(this, Server); + + this.client = client; + this.region = data.region; + this.ownerID = data.owner_id; + this.name = data.name; + this.id = data.id; + this.members = []; + this.channels = []; + this.icon = data.icon; + this.afkTimeout = data.afk_timeout; + this.afkChannelId = data.afk_channel_id; + + if (!data.members) { + data.members = [client.user]; + return; + } + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = data.members[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var member = _step.value; + + // first we cache the user in our Discord Client, + // then we add it to our list. This way when we + // get a user from this server's member list, + // it will be identical (unless an async change occurred) + // to the client's cache. + if (member.user) this.members.push(client.addUser(member.user)); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + } + + _createClass(Server, [{ + key: "getChannel", + + // get/set + value: function getChannel(key, value) { + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = this.channels[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var channel = _step2.value; + + if (channel[key] === value) { + return channel; + } + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2["return"]) { + _iterator2["return"](); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + + return null; + } + }, { + key: "getMember", + value: function getMember(key, value) { + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = this.members[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var member = _step3.value; + + if (member[key] === value) { + return member; + } + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3["return"]) { + _iterator3["return"](); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + + return null; + } + }, { + key: "addChannel", + value: function addChannel(chann) { + if (!this.getChannel("id", chann.id)) { + this.channels.push(chann); + } + return chann; + } + }, { + key: "addMember", + value: function addMember(member) { + if (!this.getMember("id", member.id)) { + this.members.push(member); + } + return member; + } + }, { + key: "toString", + value: function toString() { + return this.name; + } + }, { + key: "equals", + value: function equals(object) { + return object.id === this.id; + } + }, { + key: "iconURL", + get: function get() { + if (!this.icon) return null; + return "https://discordapp.com/api/guilds/" + this.id + "/icons/" + this.icon + ".jpg"; + } + }, { + key: "afkChannel", + get: function get() { + if (!this.afkChannelId) return false; + + return this.getChannel("id", this.afkChannelId); + } + }, { + key: "defaultChannel", + get: function get() { + return this.getChannel("name", "general"); + } + }, { + key: "owner", + get: function get() { + return this.client.getUser("id", this.ownerID); + } + }, { + key: "users", + get: function get() { + return this.members; + } + }]); + + return Server; +})(); + +module.exports = Server; + +},{}],9:[function(require,module,exports){ +"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 User = (function () { + function User(data) { + _classCallCheck(this, User); + + this.username = data.username; + this.discriminator = data.discriminator; + this.id = data.id; + this.avatar = data.avatar; + this.status = "offline"; + } + + // access using user.avatarURL; + + _createClass(User, [{ + key: "mention", + value: function mention() { + return "<@" + this.id + ">"; + } + }, { + key: "toString", + value: function toString() { + /* + if we embed a user in a String - like so: + "Yo " + user + " what's up?" + It would generate something along the lines of: + "Yo @hydrabolt what's up?" + */ + return this.mention(); + } + }, { + key: "equals", + value: function equals(object) { + return object.id === this.id; + } + }, { + key: "equalsStrict", + value: function equalsStrict(object) { + return object.id === this.id && object.avatar === this.avatar && object.username === this.username && object.discriminator === this.discriminator; + } + }, { + key: "avatarURL", + get: function get() { + if (!this.avatar) return null; + return "https://discordapp.com/api/users/" + this.id + "/avatars/" + this.avatar + ".jpg"; + } + }]); + + return User; +})(); + +module.exports = User; + +},{}],10:[function(require,module,exports){ + +},{}],11:[function(require,module,exports){ +/** + * Module dependencies. + */ + +var Emitter = require('emitter'); +var reduce = require('reduce'); + +/** + * Root reference for iframes. + */ + +var root = 'undefined' == typeof window + ? (this || self) + : window; + +/** + * Noop. + */ + +function noop(){}; + +/** + * Check if `obj` is a host object, + * we don't want to serialize these :) + * + * TODO: future proof, move to compoent land + * + * @param {Object} obj + * @return {Boolean} + * @api private + */ + +function isHost(obj) { + var str = {}.toString.call(obj); + + switch (str) { + case '[object File]': + case '[object Blob]': + case '[object FormData]': + return true; + default: + return false; + } +} + +/** + * Determine XHR. + */ + +request.getXHR = function () { + if (root.XMLHttpRequest + && (!root.location || 'file:' != root.location.protocol + || !root.ActiveXObject)) { + return new XMLHttpRequest; + } else { + try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {} + } + return false; +}; + +/** + * Removes leading and trailing whitespace, added to support IE. + * + * @param {String} s + * @return {String} + * @api private + */ + +var trim = ''.trim + ? function(s) { return s.trim(); } + : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); }; + +/** + * Check if `obj` is an object. + * + * @param {Object} obj + * @return {Boolean} + * @api private + */ + +function isObject(obj) { + return obj === Object(obj); +} + +/** + * Serialize the given `obj`. + * + * @param {Object} obj + * @return {String} + * @api private + */ + +function serialize(obj) { + if (!isObject(obj)) return obj; + var pairs = []; + for (var key in obj) { + if (null != obj[key]) { + pairs.push(encodeURIComponent(key) + + '=' + encodeURIComponent(obj[key])); + } + } + return pairs.join('&'); +} + +/** + * Expose serialization method. + */ + + request.serializeObject = serialize; + + /** + * Parse the given x-www-form-urlencoded `str`. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function parseString(str) { + var obj = {}; + var pairs = str.split('&'); + var parts; + var pair; + + for (var i = 0, len = pairs.length; i < len; ++i) { + pair = pairs[i]; + parts = pair.split('='); + obj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]); + } + + return obj; +} + +/** + * Expose parser. + */ + +request.parseString = parseString; + +/** + * Default MIME type map. + * + * superagent.types.xml = 'application/xml'; + * + */ + +request.types = { + html: 'text/html', + json: 'application/json', + xml: 'application/xml', + urlencoded: 'application/x-www-form-urlencoded', + 'form': 'application/x-www-form-urlencoded', + 'form-data': 'application/x-www-form-urlencoded' +}; + +/** + * Default serialization map. + * + * superagent.serialize['application/xml'] = function(obj){ + * return 'generated xml here'; + * }; + * + */ + + request.serialize = { + 'application/x-www-form-urlencoded': serialize, + 'application/json': JSON.stringify + }; + + /** + * Default parsers. + * + * superagent.parse['application/xml'] = function(str){ + * return { object parsed from str }; + * }; + * + */ + +request.parse = { + 'application/x-www-form-urlencoded': parseString, + 'application/json': JSON.parse +}; + +/** + * Parse the given header `str` into + * an object containing the mapped fields. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function parseHeader(str) { + var lines = str.split(/\r?\n/); + var fields = {}; + var index; + var line; + var field; + var val; + + lines.pop(); // trailing CRLF + + for (var i = 0, len = lines.length; i < len; ++i) { + line = lines[i]; + index = line.indexOf(':'); + field = line.slice(0, index).toLowerCase(); + val = trim(line.slice(index + 1)); + fields[field] = val; + } + + return fields; +} + +/** + * Return the mime type for the given `str`. + * + * @param {String} str + * @return {String} + * @api private + */ + +function type(str){ + return str.split(/ *; */).shift(); +}; + +/** + * Return header field parameters. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function params(str){ + return reduce(str.split(/ *; */), function(obj, str){ + var parts = str.split(/ *= */) + , key = parts.shift() + , val = parts.shift(); + + if (key && val) obj[key] = val; + return obj; + }, {}); +}; + +/** + * Initialize a new `Response` with the given `xhr`. + * + * - set flags (.ok, .error, etc) + * - parse header + * + * Examples: + * + * Aliasing `superagent` as `request` is nice: + * + * request = superagent; + * + * We can use the promise-like API, or pass callbacks: + * + * request.get('/').end(function(res){}); + * request.get('/', function(res){}); + * + * Sending data can be chained: + * + * request + * .post('/user') + * .send({ name: 'tj' }) + * .end(function(res){}); + * + * Or passed to `.send()`: + * + * request + * .post('/user') + * .send({ name: 'tj' }, function(res){}); + * + * Or passed to `.post()`: + * + * request + * .post('/user', { name: 'tj' }) + * .end(function(res){}); + * + * Or further reduced to a single call for simple cases: + * + * request + * .post('/user', { name: 'tj' }, function(res){}); + * + * @param {XMLHTTPRequest} xhr + * @param {Object} options + * @api private + */ + +function Response(req, options) { + options = options || {}; + this.req = req; + this.xhr = this.req.xhr; + // responseText is accessible only if responseType is '' or 'text' and on older browsers + this.text = ((this.req.method !='HEAD' && (this.xhr.responseType === '' || this.xhr.responseType === 'text')) || typeof this.xhr.responseType === 'undefined') + ? this.xhr.responseText + : null; + this.statusText = this.req.xhr.statusText; + this.setStatusProperties(this.xhr.status); + this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders()); + // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but + // getResponseHeader still works. so we get content-type even if getting + // other headers fails. + this.header['content-type'] = this.xhr.getResponseHeader('content-type'); + this.setHeaderProperties(this.header); + this.body = this.req.method != 'HEAD' + ? this.parseBody(this.text ? this.text : this.xhr.response) + : null; +} + +/** + * Get case-insensitive `field` value. + * + * @param {String} field + * @return {String} + * @api public + */ + +Response.prototype.get = function(field){ + return this.header[field.toLowerCase()]; +}; + +/** + * Set header related properties: + * + * - `.type` the content type without params + * + * A response of "Content-Type: text/plain; charset=utf-8" + * will provide you with a `.type` of "text/plain". + * + * @param {Object} header + * @api private + */ + +Response.prototype.setHeaderProperties = function(header){ + // content-type + var ct = this.header['content-type'] || ''; + this.type = type(ct); + + // params + var obj = params(ct); + for (var key in obj) this[key] = obj[key]; +}; + +/** + * Parse the given body `str`. + * + * Used for auto-parsing of bodies. Parsers + * are defined on the `superagent.parse` object. + * + * @param {String} str + * @return {Mixed} + * @api private + */ + +Response.prototype.parseBody = function(str){ + var parse = request.parse[this.type]; + return parse && str && (str.length || str instanceof Object) + ? parse(str) + : null; +}; + +/** + * Set flags such as `.ok` based on `status`. + * + * For example a 2xx response will give you a `.ok` of __true__ + * whereas 5xx will be __false__ and `.error` will be __true__. The + * `.clientError` and `.serverError` are also available to be more + * specific, and `.statusType` is the class of error ranging from 1..5 + * sometimes useful for mapping respond colors etc. + * + * "sugar" properties are also defined for common cases. Currently providing: + * + * - .noContent + * - .badRequest + * - .unauthorized + * - .notAcceptable + * - .notFound + * + * @param {Number} status + * @api private + */ + +Response.prototype.setStatusProperties = function(status){ + // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request + if (status === 1223) { + status = 204; + } + + var type = status / 100 | 0; + + // status / class + this.status = status; + this.statusType = type; + + // basics + this.info = 1 == type; + this.ok = 2 == type; + this.clientError = 4 == type; + this.serverError = 5 == type; + this.error = (4 == type || 5 == type) + ? this.toError() + : false; + + // sugar + this.accepted = 202 == status; + this.noContent = 204 == status; + this.badRequest = 400 == status; + this.unauthorized = 401 == status; + this.notAcceptable = 406 == status; + this.notFound = 404 == status; + this.forbidden = 403 == status; +}; + +/** + * Return an `Error` representative of this response. + * + * @return {Error} + * @api public + */ + +Response.prototype.toError = function(){ + var req = this.req; + var method = req.method; + var url = req.url; + + var msg = 'cannot ' + method + ' ' + url + ' (' + this.status + ')'; + var err = new Error(msg); + err.status = this.status; + err.method = method; + err.url = url; + + return err; +}; + +/** + * Expose `Response`. + */ + +request.Response = Response; + +/** + * Initialize a new `Request` with the given `method` and `url`. + * + * @param {String} method + * @param {String} url + * @api public + */ + +function Request(method, url) { + var self = this; + Emitter.call(this); + this._query = this._query || []; + this.method = method; + this.url = url; + this.header = {}; + this._header = {}; + this.on('end', function(){ + var err = null; + var res = null; + + try { + res = new Response(self); + } catch(e) { + err = new Error('Parser is unable to parse the response'); + err.parse = true; + err.original = e; + return self.callback(err); + } + + self.emit('response', res); + + if (err) { + return self.callback(err, res); + } + + if (res.status >= 200 && res.status < 300) { + return self.callback(err, res); + } + + var new_err = new Error(res.statusText || 'Unsuccessful HTTP response'); + new_err.original = err; + new_err.response = res; + new_err.status = res.status; + + self.callback(new_err, res); + }); +} + +/** + * Mixin `Emitter`. + */ + +Emitter(Request.prototype); + +/** + * Allow for extension + */ + +Request.prototype.use = function(fn) { + fn(this); + return this; +} + +/** + * Set timeout to `ms`. + * + * @param {Number} ms + * @return {Request} for chaining + * @api public + */ + +Request.prototype.timeout = function(ms){ + this._timeout = ms; + return this; +}; + +/** + * Clear previous timeout. + * + * @return {Request} for chaining + * @api public + */ + +Request.prototype.clearTimeout = function(){ + this._timeout = 0; + clearTimeout(this._timer); + return this; +}; + +/** + * Abort the request, and clear potential timeout. + * + * @return {Request} + * @api public + */ + +Request.prototype.abort = function(){ + if (this.aborted) return; + this.aborted = true; + this.xhr.abort(); + this.clearTimeout(); + this.emit('abort'); + return this; +}; + +/** + * Set header `field` to `val`, or multiple fields with one object. + * + * Examples: + * + * req.get('/') + * .set('Accept', 'application/json') + * .set('X-API-Key', 'foobar') + * .end(callback); + * + * req.get('/') + * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' }) + * .end(callback); + * + * @param {String|Object} field + * @param {String} val + * @return {Request} for chaining + * @api public + */ + +Request.prototype.set = function(field, val){ + if (isObject(field)) { + for (var key in field) { + this.set(key, field[key]); + } + return this; + } + this._header[field.toLowerCase()] = val; + this.header[field] = val; + return this; +}; + +/** + * Remove header `field`. + * + * Example: + * + * req.get('/') + * .unset('User-Agent') + * .end(callback); + * + * @param {String} field + * @return {Request} for chaining + * @api public + */ + +Request.prototype.unset = function(field){ + delete this._header[field.toLowerCase()]; + delete this.header[field]; + return this; +}; + +/** + * Get case-insensitive header `field` value. + * + * @param {String} field + * @return {String} + * @api private + */ + +Request.prototype.getHeader = function(field){ + return this._header[field.toLowerCase()]; +}; + +/** + * Set Content-Type to `type`, mapping values from `request.types`. + * + * Examples: + * + * superagent.types.xml = 'application/xml'; + * + * request.post('/') + * .type('xml') + * .send(xmlstring) + * .end(callback); + * + * request.post('/') + * .type('application/xml') + * .send(xmlstring) + * .end(callback); + * + * @param {String} type + * @return {Request} for chaining + * @api public + */ + +Request.prototype.type = function(type){ + this.set('Content-Type', request.types[type] || type); + return this; +}; + +/** + * Set Accept to `type`, mapping values from `request.types`. + * + * Examples: + * + * superagent.types.json = 'application/json'; + * + * request.get('/agent') + * .accept('json') + * .end(callback); + * + * request.get('/agent') + * .accept('application/json') + * .end(callback); + * + * @param {String} accept + * @return {Request} for chaining + * @api public + */ + +Request.prototype.accept = function(type){ + this.set('Accept', request.types[type] || type); + return this; +}; + +/** + * Set Authorization field value with `user` and `pass`. + * + * @param {String} user + * @param {String} pass + * @return {Request} for chaining + * @api public + */ + +Request.prototype.auth = function(user, pass){ + var str = btoa(user + ':' + pass); + this.set('Authorization', 'Basic ' + str); + return this; +}; + +/** +* Add query-string `val`. +* +* Examples: +* +* request.get('/shoes') +* .query('size=10') +* .query({ color: 'blue' }) +* +* @param {Object|String} val +* @return {Request} for chaining +* @api public +*/ + +Request.prototype.query = function(val){ + if ('string' != typeof val) val = serialize(val); + if (val) this._query.push(val); + return this; +}; + +/** + * Write the field `name` and `val` for "multipart/form-data" + * request bodies. + * + * ``` js + * request.post('/upload') + * .field('foo', 'bar') + * .end(callback); + * ``` + * + * @param {String} name + * @param {String|Blob|File} val + * @return {Request} for chaining + * @api public + */ + +Request.prototype.field = function(name, val){ + if (!this._formData) this._formData = new root.FormData(); + this._formData.append(name, val); + return this; +}; + +/** + * Queue the given `file` as an attachment to the specified `field`, + * with optional `filename`. + * + * ``` js + * request.post('/upload') + * .attach(new Blob(['hey!'], { type: "text/html"})) + * .end(callback); + * ``` + * + * @param {String} field + * @param {Blob|File} file + * @param {String} filename + * @return {Request} for chaining + * @api public + */ + +Request.prototype.attach = function(field, file, filename){ + if (!this._formData) this._formData = new root.FormData(); + this._formData.append(field, file, filename); + return this; +}; + +/** + * Send `data`, defaulting the `.type()` to "json" when + * an object is given. + * + * Examples: + * + * // querystring + * request.get('/search') + * .end(callback) + * + * // multiple data "writes" + * request.get('/search') + * .send({ search: 'query' }) + * .send({ range: '1..5' }) + * .send({ order: 'desc' }) + * .end(callback) + * + * // manual json + * request.post('/user') + * .type('json') + * .send('{"name":"tj"}) + * .end(callback) + * + * // auto json + * request.post('/user') + * .send({ name: 'tj' }) + * .end(callback) + * + * // manual x-www-form-urlencoded + * request.post('/user') + * .type('form') + * .send('name=tj') + * .end(callback) + * + * // auto x-www-form-urlencoded + * request.post('/user') + * .type('form') + * .send({ name: 'tj' }) + * .end(callback) + * + * // defaults to x-www-form-urlencoded + * request.post('/user') + * .send('name=tobi') + * .send('species=ferret') + * .end(callback) + * + * @param {String|Object} data + * @return {Request} for chaining + * @api public + */ + +Request.prototype.send = function(data){ + var obj = isObject(data); + var type = this.getHeader('Content-Type'); + + // merge + if (obj && isObject(this._data)) { + for (var key in data) { + this._data[key] = data[key]; + } + } else if ('string' == typeof data) { + if (!type) this.type('form'); + type = this.getHeader('Content-Type'); + if ('application/x-www-form-urlencoded' == type) { + this._data = this._data + ? this._data + '&' + data + : data; + } else { + this._data = (this._data || '') + data; + } + } else { + this._data = data; + } + + if (!obj || isHost(data)) return this; + if (!type) this.type('json'); + return this; +}; + +/** + * Invoke the callback with `err` and `res` + * and handle arity check. + * + * @param {Error} err + * @param {Response} res + * @api private + */ + +Request.prototype.callback = function(err, res){ + var fn = this._callback; + this.clearTimeout(); + fn(err, res); +}; + +/** + * Invoke callback with x-domain error. + * + * @api private + */ + +Request.prototype.crossDomainError = function(){ + var err = new Error('Origin is not allowed by Access-Control-Allow-Origin'); + err.crossDomain = true; + this.callback(err); +}; + +/** + * Invoke callback with timeout error. + * + * @api private + */ + +Request.prototype.timeoutError = function(){ + var timeout = this._timeout; + var err = new Error('timeout of ' + timeout + 'ms exceeded'); + err.timeout = timeout; + this.callback(err); +}; + +/** + * Enable transmission of cookies with x-domain requests. + * + * Note that for this to work the origin must not be + * using "Access-Control-Allow-Origin" with a wildcard, + * and also must set "Access-Control-Allow-Credentials" + * to "true". + * + * @api public + */ + +Request.prototype.withCredentials = function(){ + this._withCredentials = true; + return this; +}; + +/** + * Initiate request, invoking callback `fn(res)` + * with an instanceof `Response`. + * + * @param {Function} fn + * @return {Request} for chaining + * @api public + */ + +Request.prototype.end = function(fn){ + var self = this; + var xhr = this.xhr = request.getXHR(); + var query = this._query.join('&'); + var timeout = this._timeout; + var data = this._formData || this._data; + + // store callback + this._callback = fn || noop; + + // state change + xhr.onreadystatechange = function(){ + if (4 != xhr.readyState) return; + + // In IE9, reads to any property (e.g. status) off of an aborted XHR will + // result in the error "Could not complete the operation due to error c00c023f" + var status; + try { status = xhr.status } catch(e) { status = 0; } + + if (0 == status) { + if (self.timedout) return self.timeoutError(); + if (self.aborted) return; + return self.crossDomainError(); + } + self.emit('end'); + }; + + // progress + var handleProgress = function(e){ + if (e.total > 0) { + e.percent = e.loaded / e.total * 100; + } + self.emit('progress', e); + }; + if (this.hasListeners('progress')) { + xhr.onprogress = handleProgress; + } + try { + if (xhr.upload && this.hasListeners('progress')) { + xhr.upload.onprogress = handleProgress; + } + } catch(e) { + // Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist. + // Reported here: + // https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context + } + + // timeout + if (timeout && !this._timer) { + this._timer = setTimeout(function(){ + self.timedout = true; + self.abort(); + }, timeout); + } + + // querystring + if (query) { + query = request.serializeObject(query); + this.url += ~this.url.indexOf('?') + ? '&' + query + : '?' + query; + } + + // initiate request + xhr.open(this.method, this.url, true); + + // CORS + if (this._withCredentials) xhr.withCredentials = true; + + // body + if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) { + // serialize stuff + var contentType = this.getHeader('Content-Type'); + var serialize = request.serialize[contentType ? contentType.split(';')[0] : '']; + if (serialize) data = serialize(data); + } + + // set header fields + for (var field in this.header) { + if (null == this.header[field]) continue; + xhr.setRequestHeader(field, this.header[field]); + } + + // send stuff + this.emit('request', this); + xhr.send(data); + return this; +}; + +/** + * Faux promise support + * + * @param {Function} fulfill + * @param {Function} reject + * @return {Request} + */ + +Request.prototype.then = function (fulfill, reject) { + return this.end(function(err, res) { + err ? reject(err) : fulfill(res); + }); +} + +/** + * Expose `Request`. + */ + +request.Request = Request; + +/** + * Issue a request: + * + * Examples: + * + * request('GET', '/users').end(callback) + * request('/users').end(callback) + * request('/users', callback) + * + * @param {String} method + * @param {String|Function} url or callback + * @return {Request} + * @api public + */ + +function request(method, url) { + // callback + if ('function' == typeof url) { + return new Request('GET', method).end(url); + } + + // url first + if (1 == arguments.length) { + return new Request('GET', method); + } + + return new Request(method, url); +} + +/** + * GET `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.get = function(url, data, fn){ + var req = request('GET', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.query(data); + if (fn) req.end(fn); + return req; +}; + +/** + * HEAD `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.head = function(url, data, fn){ + var req = request('HEAD', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * DELETE `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.del = function(url, fn){ + var req = request('DELETE', url); + if (fn) req.end(fn); + return req; +}; + +/** + * PATCH `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed} data + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.patch = function(url, data, fn){ + var req = request('PATCH', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * POST `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed} data + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.post = function(url, data, fn){ + var req = request('POST', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * PUT `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.put = function(url, data, fn){ + var req = request('PUT', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * Expose `request`. + */ + +module.exports = request; + +},{"emitter":12,"reduce":13}],12:[function(require,module,exports){ + +/** + * Expose `Emitter`. + */ + +module.exports = Emitter; + +/** + * Initialize a new `Emitter`. + * + * @api public + */ + +function Emitter(obj) { + if (obj) return mixin(obj); +}; + +/** + * Mixin the emitter properties. + * + * @param {Object} obj + * @return {Object} + * @api private + */ + +function mixin(obj) { + for (var key in Emitter.prototype) { + obj[key] = Emitter.prototype[key]; + } + return obj; +} + +/** + * Listen on the given `event` with `fn`. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.on = +Emitter.prototype.addEventListener = function(event, fn){ + this._callbacks = this._callbacks || {}; + (this._callbacks[event] = this._callbacks[event] || []) + .push(fn); + return this; +}; + +/** + * Adds an `event` listener that will be invoked a single + * time then automatically removed. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.once = function(event, fn){ + var self = this; + this._callbacks = this._callbacks || {}; + + function on() { + self.off(event, on); + fn.apply(this, arguments); + } + + on.fn = fn; + this.on(event, on); + return this; +}; + +/** + * Remove the given callback for `event` or all + * registered callbacks. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.off = +Emitter.prototype.removeListener = +Emitter.prototype.removeAllListeners = +Emitter.prototype.removeEventListener = function(event, fn){ + this._callbacks = this._callbacks || {}; + + // all + if (0 == arguments.length) { + this._callbacks = {}; + return this; + } + + // specific event + var callbacks = this._callbacks[event]; + if (!callbacks) return this; + + // remove all handlers + if (1 == arguments.length) { + delete this._callbacks[event]; + return this; + } + + // remove specific handler + var cb; + for (var i = 0; i < callbacks.length; i++) { + cb = callbacks[i]; + if (cb === fn || cb.fn === fn) { + callbacks.splice(i, 1); + break; + } + } + return this; +}; + +/** + * Emit `event` with the given args. + * + * @param {String} event + * @param {Mixed} ... + * @return {Emitter} + */ + +Emitter.prototype.emit = function(event){ + this._callbacks = this._callbacks || {}; + var args = [].slice.call(arguments, 1) + , callbacks = this._callbacks[event]; + + if (callbacks) { + callbacks = callbacks.slice(0); + for (var i = 0, len = callbacks.length; i < len; ++i) { + callbacks[i].apply(this, args); + } + } + + return this; +}; + +/** + * Return array of callbacks for `event`. + * + * @param {String} event + * @return {Array} + * @api public + */ + +Emitter.prototype.listeners = function(event){ + this._callbacks = this._callbacks || {}; + return this._callbacks[event] || []; +}; + +/** + * Check if this emitter has `event` handlers. + * + * @param {String} event + * @return {Boolean} + * @api public + */ + +Emitter.prototype.hasListeners = function(event){ + return !! this.listeners(event).length; +}; + +},{}],13:[function(require,module,exports){ + +/** + * Reduce `arr` with `fn`. + * + * @param {Array} arr + * @param {Function} fn + * @param {Mixed} initial + * + * TODO: combatible error handling? + */ + +module.exports = function(arr, fn, initial){ + var idx = 0; + var len = arr.length; + var curr = arguments.length == 3 + ? initial + : arr[idx++]; + + while (idx < len) { + curr = fn.call(null, curr, arr[idx], ++idx, arr); + } + + return curr; +}; +},{}],14:[function(require,module,exports){ + +/** + * Module dependencies. + */ + +var global = (function() { return this; })(); + +/** + * WebSocket constructor. + */ + +var WebSocket = global.WebSocket || global.MozWebSocket; + +/** + * Module exports. + */ + +module.exports = WebSocket ? ws : null; + +/** + * WebSocket constructor. + * + * The third `opts` options object gets ignored in web browsers, since it's + * non-standard, and throws a TypeError if passed to the constructor. + * See: https://github.com/einaros/ws/issues/227 + * + * @param {String} uri + * @param {Array} protocols (optional) + * @param {Object) opts (optional) + * @api public + */ + +function ws(uri, protocols, opts) { + var instance; + if (protocols) { + instance = new WebSocket(uri, protocols); + } else { + instance = new WebSocket(uri); + } + return instance; +} + +if (WebSocket) ws.prototype = WebSocket.prototype; + +},{}],15:[function(require,module,exports){ +module.exports=[{"executables":{"win32":["pol.exe"]},"id":0,"name":"FINAL FANTASY XI"},{"executables":{"win32":["ffxiv.exe","ffxiv_dx11.exe"]},"id":1,"name":"FINAL FANTASY XIV"},{"executables":{"win32":["Wow.exe","Wow-64.exe"]},"id":3,"name":"World of Warcraft"},{"executables":{"darwin":["LoLLauncher.app"],"win32":["LolClient.exe","League of Legends.exe"]},"id":4,"name":"League of Legends"},{"executables":{"darwin":["Diablo%20III.app"],"win32":["Diablo III.exe"]},"id":5,"name":"Diablo 3"},{"executables":{"darwin":["dota_osx.app"],"win32":["dota2.exe"]},"id":6,"name":"DOTA 2"},{"executables":{"darwin":["Heroes.app"],"win32":["Heroes of the Storm.exe","HeroesOfTheStorm_x64.exe","HeroesOfTheStorm.exe"]},"id":7,"name":"Heroes of the Storm"},{"executables":{"darwin":["Hearthstone.app"],"win32":["Hearthstone.exe"]},"id":8,"name":"Hearthstone"},{"executables":{"win32":["csgo.exe"]},"id":9,"name":"Counter-Strike: Global Offensive"},{"executables":{"win32":["WorldOfTanks.exe"]},"id":10,"name":"World of Tanks"},{"executables":{"darwin":["gw2.app"],"win32":["gw2.exe"]},"id":11,"name":"Guild Wars 2"},{"executables":{"win32":["dayz.exe"]},"id":12,"name":"Day Z"},{"executables":{"darwin":["starcraft%20ii.app"],"win32":["starcraft ii.exe","SC2_x64.exe","SC2.exe"]},"id":13,"name":"Starcraft II"},{"executables":{"win32":["diablo.exe"]},"id":14,"name":"Diablo"},{"executables":{"win32":["diablo ii.exe"]},"id":15,"name":"Diablo 2"},{"executables":{"win32":["left4dead.exe"]},"id":17,"name":"Left 4 Dead"},{"executables":{"darwin":["minecraft.app"],"win32":["minecraft.exe"]},"id":18,"name":"Minecraft"},{"executables":{"win32":["smite.exe"]},"id":19,"name":"Smite"},{"executables":{"win32":["bf4.exe"]},"id":20,"name":"Battlefield 4"},{"executables":{"win32":["AoK HD.exe","empires2.exe"]},"id":101,"name":"Age of Empire II"},{"executables":{"win32":["age3y.exe"]},"id":102,"name":"Age of Empire III"},{"executables":{"win32":["AlanWake.exe"]},"id":104,"name":"Alan Wake"},{"executables":{"win32":["alan_wakes_american_nightmare.exe"]},"id":105,"name":"Alan Wake's American Nightmare"},{"executables":{"win32":["AlienBreed2Assault.exe"]},"id":106,"name":"Alien Breed 2: Assault"},{"executables":{"win32":["Amnesia.exe"]},"id":107,"name":"Amnesia: The Dark Descent"},{"executables":{"win32":["UDK.exe"]},"id":108,"name":"Antichamber"},{"executables":{"win32":["ArcheAge.exe"]},"id":109,"name":"ArcheAge"},{"executables":{"win32":["arma3.exe"]},"id":110,"name":"Arma III"},{"executables":{"win32":["AC3SP.exe"]},"id":111,"name":"Assassin's Creed 3"},{"executables":{"win32":["Bastion.exe"]},"id":112,"name":"Bastion"},{"executables":{"win32":["BF2.exe"]},"id":113,"name":"Battlefield 2"},{"executables":{"win32":["bf3.exe"]},"id":114,"name":"Battlefield 3"},{"executables":{"win32":["Besiege.exe"]},"id":116,"name":"Besiege"},{"executables":{"win32":["Bioshock.exe"]},"id":117,"name":"Bioshock"},{"executables":{"win32":["Bioshock2.exe"]},"id":118,"name":"BioShock II"},{"executables":{"win32":["BioShockInfinite.exe"]},"id":119,"name":"BioShock Infinite"},{"executables":{"win32":["Borderlands2.exe"]},"id":122,"name":"Borderlands 2"},{"executables":{"win32":["braid.exe"]},"id":123,"name":"Braid"},{"executables":{"win32":["ShippingPC-StormGame.exe"]},"id":124,"name":"Bulletstorm"},{"executables":{},"id":125,"name":"Cabal 2"},{"executables":{"win32":["CabalMain.exe"]},"id":126,"name":"Cabal Online"},{"executables":{"win32":["iw4mp.exe","iw4sp.exe"]},"id":127,"name":"Call of Duty: Modern Warfare 2"},{"executables":{"win32":["t6sp.exe"]},"id":128,"name":"Call of Duty: Black Ops"},{"executables":{"win32":["iw5mp.exe"]},"id":129,"name":"Call of Duty: Modern Warfare 3"},{"executables":{"win32":["RelicCOH.exe"]},"id":132,"name":"Company of Heroes"},{"executables":{"win32":["Crysis64.exe"]},"id":135,"name":"Crysis"},{"executables":{"win32":["Crysis2.exe"]},"id":136,"name":"Crysis 2"},{"executables":{"win32":["Crysis3.exe"]},"id":137,"name":"Crysis 3"},{"executables":{"win32":["Crysis.exe"]},"id":138,"name":"Crysis 4 "},{"executables":{"win32":["DATA.exe"]},"id":140,"name":"Dark Souls"},{"executables":{"win32":["DarkSoulsII.exe"]},"id":141,"name":"Dark Souls II"},{"executables":{"win32":["dfuw.exe"]},"id":142,"name":"Darkfall: Unholy Wars"},{"executables":{"win32":["DCGAME.exe"]},"id":144,"name":"DC Universe Online"},{"executables":{"win32":["DeadIslandGame.exe"]},"id":145,"name":"Dead Island"},{"executables":{"win32":["deadspace2.exe"]},"id":146,"name":"Dead Space 2"},{"executables":{"win32":["LOTDGame.exe"]},"id":147,"name":"Deadlight"},{"executables":{"win32":["dxhr.exe"]},"id":148,"name":"Deus Ex: Human Revolution"},{"executables":{"win32":["DeviMayCry4.exe"]},"id":149,"name":"Devil May Cry 4"},{"executables":{"win32":["DMC-DevilMayCry.exe"]},"id":150,"name":"DmC Devil May Cry"},{"executables":{"win32":["dirt2_game.exe"]},"id":154,"name":"DiRT 2"},{"executables":{"win32":["dirt3_game.exe"]},"id":155,"name":"DiRT 3"},{"executables":{"win32":["dota.exe"]},"id":156,"name":"DOTA"},{"executables":{"win32":["DoubleDragon.exe"]},"id":158,"name":"Double Dragon Neon"},{"executables":{"win32":["DragonAge2.exe"]},"id":159,"name":"Dragon Age II"},{"executables":{"win32":["DragonAgeInquisition.exe"]},"id":160,"name":"Dragon Age: Inquisition"},{"executables":{"win32":["daorigins.exe"]},"id":161,"name":"Dragon Age: Origins"},{"executables":{"win32":["DBXV.exe"]},"id":162,"name":"Dragon Ball XenoVerse"},{"executables":{"win32":["DukeForever.exe"]},"id":163,"name":"Duke Nukem Forever"},{"executables":{"darwin":["Dustforce.app"],"win32":["dustforce.exe"]},"id":164,"name":"Dustforce"},{"executables":{"win32":["EliteDangerous32.exe"]},"id":165,"name":"Elite: Dangerous"},{"executables":{"win32":["exefile.exe"]},"id":166,"name":"Eve Online"},{"executables":{"win32":["eqgame.exe"]},"id":167,"name":"EverQuest"},{"executables":{"win32":["EverQuest2.exe"]},"id":168,"name":"EverQuest II"},{"executables":{},"id":169,"name":"EverQuest Next"},{"executables":{"win32":["Engine.exe"]},"id":170,"name":"F.E.A.R."},{"executables":{"win32":["FEAR2.exe"]},"id":171,"name":"F.E.A.R. 2: Project Origin"},{"executables":{"win32":["fallout3.exe"]},"id":172,"name":"Fallout 3"},{"executables":{"win32":["FalloutNV.exe"]},"id":174,"name":"Fallout: New Vegas"},{"executables":{"win32":["farcry3.exe"]},"id":175,"name":"Far Cry 3"},{"executables":{"win32":["fifa15.exe"]},"id":176,"name":"FIFA 15"},{"executables":{"win32":["FTLGame.exe"]},"id":180,"name":"FTL: Faster Than Light"},{"executables":{"win32":["GTAIV.exe"]},"id":181,"name":"Grand Theft Auto 4"},{"executables":{"win32":["GTA5.exe"]},"id":182,"name":"Grand Theft Auto 5"},{"executables":{"win32":["Gw.exe"]},"id":183,"name":"Guild Wars"},{"executables":{"win32":["H1Z1.exe"]},"id":186,"name":"H1Z1"},{"executables":{"win32":["HL2HL2.exe","hl2.exe"]},"id":188,"name":"Half Life 2"},{"executables":{"win32":["HOMEFRONT.exe"]},"id":195,"name":"Homefront"},{"executables":{"win32":["invisibleinc.exe"]},"id":196,"name":"Invisible Inc."},{"executables":{"win32":["LANoire.exe"]},"id":197,"name":"L.A. Noire"},{"executables":{"win32":["Landmark64.exe"]},"id":198,"name":"Landmark"},{"executables":{"win32":["left4dead2.exe"]},"id":201,"name":"Left 4 Dead 2"},{"executables":{"win32":["lineage.exe"]},"id":203,"name":"Lineage"},{"executables":{"win32":["Magicka.exe"]},"id":206,"name":"Magicka"},{"executables":{"win32":["MapleStory.exe"]},"id":208,"name":"MapleStory"},{"executables":{},"id":209,"name":"Mark of the Ninja"},{"executables":{"win32":["MassEffect.exe"]},"id":210,"name":"Mass Effect"},{"executables":{"win32":["MassEffect2.exe"]},"id":211,"name":"Mass Effect 2"},{"executables":{"win32":["MassEffect3Demo.exe"]},"id":212,"name":"Mass Effect 3"},{"executables":{"win32":["METAL GEAR RISING REVENGEANCE.exe"]},"id":214,"name":"Metal Gear Rising: Revengeance"},{"executables":{"win32":["metro2033.exe"]},"id":215,"name":"Metro 2033"},{"executables":{"win32":["MetroLL.exe"]},"id":216,"name":"Metro Last Light"},{"executables":{"win32":["MK10.exe"]},"id":218,"name":"Mortal Kombat X"},{"executables":{"win32":["speed.exe"]},"id":219,"name":"Need For Speed Most Wanted"},{"executables":{},"id":220,"name":"Neverwinder"},{"executables":{"darwin":["Outlast.app"],"win32":["OLGame.exe"]},"id":221,"name":"Outlast"},{"executables":{"win32":["PapersPlease.exe"]},"id":222,"name":"Papers, Please"},{"executables":{"win32":["payday_win32_release.exe"]},"id":223,"name":"PAYDAY"},{"executables":{"win32":["payday2_win32_release.exe"]},"id":224,"name":"PAYDAY2"},{"executables":{"win32":["PillarsOfEternity.exe"]},"id":225,"name":"Pillars of Eternity"},{"executables":{"win32":["PA.exe"]},"id":226,"name":"Planetary Annihilation"},{"executables":{"win32":["planetside2_x86.exe"]},"id":227,"name":"Planetside 2"},{"executables":{"win32":["hl2P.exe"]},"id":228,"name":"Portal"},{"executables":{"win32":["portal2.exe"]},"id":229,"name":"Portal 2"},{"executables":{"win32":["PrimalCarnageGame.exe"]},"id":231,"name":"Primal Cargnage"},{"executables":{"win32":["pCARS.exe"]},"id":232,"name":"Project Cars"},{"executables":{"win32":["RaceTheSun.exe"]},"id":233,"name":"Race The Sun"},{"executables":{"win32":["Rage.exe"]},"id":234,"name":"RAGE"},{"executables":{"win32":["ragexe.exe"]},"id":235,"name":"Ragnarok Online"},{"executables":{"win32":["rift.exe"]},"id":236,"name":"Rift"},{"executables":{"win32":["Rocksmith2014.exe"]},"id":237,"name":"Rocksmith 2014"},{"executables":{"win32":["SwiftKit-RS.exe","JagexLauncher.exe"]},"id":238,"name":"RuneScape"},{"executables":{"win32":["Shadowgrounds.exe"]},"id":239,"name":"Shadowgrounds"},{"executables":{"win32":["survivor.exe"]},"id":240,"name":"Shadowgrounds: Survivor"},{"executables":{"win32":["ShovelKnight.exe"]},"id":241,"name":"Shovel Knight"},{"executables":{"win32":["SimCity.exe"]},"id":242,"name":"SimCity"},{"executables":{"win32":["SporeApp.exe"]},"id":245,"name":"Spore"},{"executables":{"win32":["StarCitizen.exe"]},"id":246,"name":"Star Citizen"},{"executables":{},"id":247,"name":"Star Trek Online"},{"executables":{"win32":["battlefront.exe"]},"id":248,"name":"Star Wars Battlefront"},{"executables":{"win32":["swtor.exe"]},"id":249,"name":"Star Wars: The Old Republic"},{"executables":{"win32":["starbound.exe","starbound_opengl.exe"]},"id":250,"name":"Starbound"},{"executables":{"win32":["starcraft.exe"]},"id":251,"name":"Starcraft"},{"executables":{"win32":["SSFIV.exe"]},"id":253,"name":"Ultra Street Fighter IV"},{"executables":{"win32":["superhexagon.exe"]},"id":254,"name":"Super Hexagon"},{"executables":{"win32":["swordandsworcery_pc.exe"]},"id":255,"name":"Superbrothers: Sword & Sworcery EP"},{"executables":{"win32":["hl2TF.exe"]},"id":256,"name":"Team Fortress 2"},{"executables":{"win32":["TERA.exe"]},"id":258,"name":"TERA"},{"executables":{"win32":["Terraria.exe"]},"id":259,"name":"Terraria"},{"executables":{"win32":["Bethesda.net_Launcher.exe"]},"id":260,"name":"The Elder Scrolls Online"},{"executables":{"win32":["TESV.exe"]},"id":261,"name":"The Elder Scrolls V: Skyrim"},{"executables":{"win32":["TheSecretWorld.exe"]},"id":262,"name":"The Secret World"},{"executables":{"win32":["TS3.exe","ts3w.exe"]},"id":264,"name":"The Sims 3"},{"executables":{"win32":["WALKINGDEAD101.EXE"]},"id":265,"name":"The Walking Dead"},{"executables":{"win32":["TheWalkingDead2.exe"]},"id":266,"name":"The Walking Dead Season Two"},{"executables":{"win32":["witcher3.exe"]},"id":267,"name":"The Witcher 3"},{"executables":{"win32":["Future Soldier.exe"]},"id":268,"name":"Tom Clancy's Ghost Recon: Future Solider"},{"executables":{"win32":["TombRaider.exe"]},"id":269,"name":"Tomb Raider (2013)"},{"executables":{"win32":["Torchlight.exe"]},"id":271,"name":"Torchlight"},{"executables":{"win32":["Torchlight2.exe"]},"id":272,"name":"Torchlight 2"},{"executables":{"win32":["Shogun2.exe"]},"id":273,"name":"Total War: Shogun 2"},{"executables":{"win32":["Transistor.exe"]},"id":274,"name":"Transistor"},{"executables":{"win32":["trine.exe"]},"id":275,"name":"Trine"},{"executables":{"win32":["trine2_32bit.exe"]},"id":276,"name":"Trine 2"},{"executables":{"win32":["UOKR.exe"]},"id":277,"name":"Ultima Online"},{"executables":{"win32":["aces.exe"]},"id":279,"name":"War Thunder"},{"executables":{"win32":["Warcraft III.exe","wc3.exe"]},"id":281,"name":"Warcraft 3: Reign of Chaos"},{"executables":{"win32":["Warcraft II BNE.exe"]},"id":282,"name":"Warcraft II"},{"executables":{"win32":["Warframe.x64.exe","Warframe.exe"]},"id":283,"name":"Warframe"},{"executables":{"win32":["watch_dogs.exe"]},"id":284,"name":"Watch Dogs"},{"executables":{"win32":["WildStar64.exe"]},"id":285,"name":"WildStar"},{"executables":{"win32":["XComGame.exe"]},"id":288,"name":"XCOM: Enemy Unknown"},{"executables":{"win32":["DFO.exe","dfo.exe"]},"id":289,"name":"Dungeon Fighter Online"},{"executables":{"win32":["aclauncher.exe","acclient.exe"]},"id":290,"name":"Asheron's Call"},{"executables":{"win32":["MapleStory2.exe"]},"id":291,"name":"MapleStory 2"},{"executables":{"win32":["ksp.exe"]},"id":292,"name":"Kerbal Space Program"},{"executables":{"win32":["PINBALL.EXE"]},"id":293,"name":"3D Pinball: Space Cadet"},{"executables":{"win32":["dave.exe"]},"id":294,"name":"Dangerous Dave"},{"executables":{"win32":["iwbtgbeta(slomo).exe","iwbtgbeta(fs).exe"]},"id":295,"name":"I Wanna Be The Guy"},{"executables":{"win32":["MechWarriorOnline.exe "]},"id":296,"name":"Mech Warrior Online"},{"executables":{"win32":["dontstarve_steam.exe"]},"id":297,"name":"Don't Starve"},{"executables":{"win32":["GalCiv3.exe"]},"id":298,"name":"Galactic Civilization 3"},{"executables":{"win32":["Risk of Rain.exe"]},"id":299,"name":"Risk of Rain"},{"executables":{"win32":["Binding_of_Isaac.exe","Isaac-ng.exe"]},"id":300,"name":"The Binding of Isaac"},{"executables":{"win32":["RustClient.exe"]},"id":301,"name":"Rust"},{"executables":{"win32":["Clicker Heroes.exe"]},"id":302,"name":"Clicker Heroes"},{"executables":{"win32":["Brawlhalla.exe"]},"id":303,"name":"Brawlhalla"},{"executables":{"win32":["TownOfSalem.exe"]},"id":304,"name":"Town of Salem"},{"executables":{"win32":["osu!.exe"]},"id":305,"name":"osu!"},{"executables":{"win32":["PathOfExileSteam.exe","PathOfExile.exe"]},"id":306,"name":"Path of Exile"},{"executables":{"win32":["Dolphin.exe"]},"id":307,"name":"Dolphin"},{"executables":{"win32":["RocketLeague.exe"]},"id":308,"name":"Rocket League"},{"executables":{"win32":["TJPP.exe"]},"id":309,"name":"Jackbox Party Pack"},{"executables":{"win32":["KFGame.exe"]},"id":310,"name":"Killing Floor 2"},{"executables":{"win32":["ShooterGame.exe"]},"id":311,"name":"Ark: Survival Evolved"},{"executables":{"win32":["LifeIsStrange.exe"]},"id":312,"name":"Life Is Strange"},{"executables":{"win32":["Client_tos.exe"]},"id":313,"name":"Tree of Savior"},{"executables":{"win32":["olliolli2.exe"]},"id":314,"name":"OlliOlli2"},{"executables":{"win32":["cw.exe"]},"id":315,"name":"Closers Dimension Conflict"},{"executables":{"win32":["ESSTEAM.exe","elsword.exe","x2.exe"]},"id":316,"name":"Elsword"},{"executables":{"win32":["ori.exe"]},"id":317,"name":"Ori and the Blind Forest"},{"executables":{"win32":["Skyforge.exe"]},"id":318,"name":"Skyforge"},{"executables":{"win32":["projectzomboid64.exe","projectzomboid32.exe"]},"id":319,"name":"Project Zomboid"},{"executables":{"win32":["From_The_Depths.exe"]},"id":320,"name":"The Depths"},{"executables":{"win32":["TheCrew.exe"]},"id":321,"name":"The Crew"},{"executables":{"win32":["MarvelHeroes2015.exe"]},"id":322,"name":"Marvel Heroes 2015"},{"executables":{"win32":["timeclickers.exe"]},"id":324,"name":"Time Clickers"},{"executables":{"win32":["eurotrucks2.exe"]},"id":325,"name":"Euro Truck Simulator 2"},{"executables":{"win32":["FarmingSimulator2015Game.exe"]},"id":326,"name":"Farming Simulator 15"},{"executables":{"win32":["strife.exe"]},"id":327,"name":"Strife"},{"executables":{"win32":["Awesomenauts.exe"]},"id":328,"name":"Awesomenauts"},{"executables":{"win32":["Dofus.exe"]},"id":329,"name":"Dofus"},{"executables":{"win32":["Boid.exe"]},"id":330,"name":"Boid"},{"executables":{"win32":["adventure-capitalist.exe"]},"id":331,"name":"AdVenture Capitalist"},{"executables":{"win32":["OrcsMustDie2.exe"]},"id":332,"name":"Orcs Must Die! 2"},{"executables":{"win32":["Mountain.exe"]},"id":333,"name":"Mountain"},{"executables":{"win32":["Valkyria.exe"]},"id":335,"name":"Valkyria Chronicles"},{"executables":{"win32":["ffxiiiimg.exe"]},"id":336,"name":"Final Fantasy XIII"},{"executables":{"win32":["TLR.exe"]},"id":337,"name":"The Last Remnant"},{"executables":{"win32":["Cities.exe"]},"id":339,"name":"Cities Skylines"},{"executables":{"win32":["worldofwarships.exe","WoWSLauncher.exe"]},"id":341,"name":"World of Warships"},{"executables":{"win32":["spacegame-Win64-shipping.exe"]},"id":342,"name":"Fractured Space"},{"executables":{"win32":["thespacegame.exe"]},"id":343,"name":"Ascent - The Space Game"},{"executables":{"win32":["DuckGame.exe"]},"id":344,"name":"Duck Game"},{"executables":{"win32":["PPSSPPWindows.exe"]},"id":345,"name":"PPSSPP"},{"executables":{"win32":["MBAA.exe"]},"id":346,"name":"Melty Blood Actress Again: Current Code"},{"executables":{"win32":["TheWolfAmongUs.exe"]},"id":347,"name":"The Wolf Among Us"},{"executables":{"win32":["SpaceEngineers.exe"]},"id":348,"name":"Space Engineers"},{"executables":{"win32":["Borderlands.exe"]},"id":349,"name":"Borderlands"},{"executables":{"win32":["100orange.exe"]},"id":351,"name":"100% Orange Juice"},{"executables":{"win32":["reflex.exe"]},"id":354,"name":"Reflex"},{"executables":{"win32":["pso2.exe"]},"id":355,"name":"Phantasy Star Online 2"},{"executables":{"win32":["AssettoCorsa.exe"]},"id":356,"name":"Assetto Corsa"},{"executables":{"win32":["iw3mp.exe","iw3sp.exe"]},"id":357,"name":"Call of Duty 4: Modern Warfare"},{"executables":{"win32":["WolfOldBlood_x64.exe"]},"id":358,"name":"Wolfenstein: The Old Blood"},{"executables":{"win32":["castle.exe"]},"id":359,"name":"Castle Crashers"},{"executables":{"win32":["vindictus.exe"]},"id":360,"name":"Vindictus"},{"executables":{"win32":["ShooterGame-Win32-Shipping.exe"]},"id":361,"name":"Dirty Bomb"},{"executables":{"win32":["BatmanAK.exe"]},"id":362,"name":"Batman Arkham Knight"},{"executables":{"win32":["drt.exe"]},"id":363,"name":"Dirt Rally"},{"executables":{"win32":["rFactor.exe"]},"id":364,"name":"rFactor"},{"executables":{"win32":["clonk.exe"]},"id":365,"name":"Clonk Rage"},{"executables":{"win32":["SRHK.exe"]},"id":366,"name":"Shadowrun: Hong Kong"},{"executables":{"win32":["Insurgency.exe"]},"id":367,"name":"Insurgency"},{"executables":{"win32":["StepMania.exe"]},"id":368,"name":"Step Mania"},{"executables":{"win32":["FirefallCLient.exe"]},"id":369,"name":"Firefall"},{"executables":{"win32":["mirrorsedge.exe"]},"id":370,"name":"Mirrors Edge"},{"executables":{"win32":["MgsGroundZeroes.exe"]},"id":371,"name":"Metal Gear Solid V: Ground Zeroes"},{"executables":{"win32":["mgsvtpp.exe"]},"id":372,"name":"Metal Gear Solid V: The Phantom Pain"},{"executables":{"win32":["tld.exe"]},"id":373,"name":"The Long Dark"},{"executables":{"win32":["TKOM.exe"]},"id":374,"name":"Take On Mars"},{"executables":{"win32":["robloxplayerlauncher.exe","Roblox.exe"]},"id":375,"name":"Roblox"},{"executables":{"win32":["eu4.exe"]},"id":376,"name":"Europa Universalis 4"},{"executables":{"win32":["APB.exe"]},"id":377,"name":"APB Reloaded"},{"executables":{"win32":["Robocraft.exe"]},"id":378,"name":"Robocraft"},{"executables":{"win32":["Unity.exe"]},"id":379,"name":"Unity"},{"executables":{"win32":["Simpsons.exe"]},"id":380,"name":"The Simpsons: Hit & Run"},{"executables":{"win32":["Dnlauncher.exe","DragonNest.exe"]},"id":381,"name":"Dragon Nest"},{"executables":{"win32":["Trove.exe"]},"id":382,"name":"Trove"},{"executables":{"win32":["EndlessLegend.exe"]},"id":383,"name":"Endless Legend"},{"executables":{"win32":["TurbineLauncher.exe","dndclient.exe"]},"id":384,"name":"Dungeons & Dragons Online"},{"executables":{"win32":["quakelive.exe","quakelive_steam.exe"]},"id":385,"name":"Quake Live"},{"executables":{"win32":["7DaysToDie.exe"]},"id":386,"name":"7DaysToDie"},{"executables":{"win32":["SpeedRunners.exe"]},"id":387,"name":"SpeedRunners"},{"executables":{"win32":["gamemd.exe"]},"id":388,"name":"Command & Conquer: Red Alert 2"},{"executables":{"win32":["generals.exe"]},"id":389,"name":"Command & Conquer Generals: Zero Hour"},{"executables":{"win32":["Oblivion.exe"]},"id":390,"name":"The Elder Scrolls 4: Oblivion"},{"executables":{"win32":["mgsi.exe"]},"id":391,"name":"Metal Gear Solid"},{"executables":{"win32":["EoCApp.exe"]},"id":392,"name":"Divinity - Original Sin"},{"executables":{"win32":["Torment.exe"]},"id":393,"name":"Planescape: Torment"},{"executables":{"win32":["HexPatch.exe"]},"id":394,"name":"Hex: Shards of Fate"},{"executables":{"win32":["NS3FB.exe"]},"id":395,"name":"Naruto Shippuden Ultimate Ninja Storm 3 Full Burst"},{"executables":{"win32":["NSUNSR.exe"]},"id":396,"name":"Naruto Shippuden Ultimate Ninja Storm Revolution"},{"executables":{"win32":["SaintsRowIV.exe"]},"id":397,"name":"Saints Row IV"},{"executables":{"win32":["Shadowrun.exe"]},"id":398,"name":"Shadowrun"},{"executables":{"win32":["DungeonoftheEndless.exe"]},"id":399,"name":"Dungeon of the Endless"},{"executables":{"win32":["Hon.exe"]},"id":400,"name":"Heroes of Newerth"},{"executables":{"win32":["mabinogi.exe"]},"id":401,"name":"Mabinogi"},{"executables":{"win32":["CoD2MP_s.exe","CoDSP_s.exe"]},"id":402,"name":"Call of Duty 2:"},{"executables":{"win32":["CoDWaWmp.exe","CoDWaw.exe"]},"id":403,"name":"Call of Duty: World at War"},{"executables":{"win32":["heroes.exe"]},"id":404,"name":"Mabinogi Heroes (Vindictus) "},{"executables":{"win32":["KanColleViewer.exe"]},"id":405,"name":"KanColle "},{"executables":{"win32":["cyphers.exe"]},"id":406,"name":"Cyphers"},{"executables":{"win32":["RelicCoH2.exe"]},"id":407,"name":"Company of Heroes 2"},{"executables":{"win32":["MJ.exe"]},"id":408,"name":"セガNET麻雀MJ"},{"executables":{"win32":["ge.exe"]},"id":409,"name":"Granado Espada"},{"executables":{"win32":["NovaRO.exe"]},"id":410,"name":"Nova Ragnarok Online"},{"executables":{"win32":["RivalsofAether.exe"]},"id":411,"name":"Rivals of Aether"},{"executables":{"win32":["bfh.exe"]},"id":412,"name":"Battlefield Hardline"},{"executables":{"win32":["GrowHome.exe"]},"id":413,"name":"Grow Home"},{"executables":{"win32":["patriots.exe"]},"id":414,"name":"Rise of Nations Extended"},{"executables":{"win32":["Railroads.exe"]},"id":415,"name":"Sid Meier's Railroads!"},{"executables":{"win32":["Empire.exe"]},"id":416,"name":"Empire: Total War"},{"executables":{"win32":["Napoleon.exe"]},"id":417,"name":"Napoleon: Total War"},{"executables":{"win32":["gta_sa.exe"]},"id":418,"name":"Grand Theft Auto: San Andreas"},{"executables":{"win32":["MadMax.exe"]},"id":419,"name":"Mad Max"},{"executables":{"win32":["Titanfall.exe"]},"id":420,"name":"Titanfall"},{"executables":{"win32":["age2_x1.exe"]},"id":421,"name":"Age of Empires II: The Conquerors"},{"executables":{"win32":["Rome2.exe"]},"id":422,"name":"Total War: ROME 2"},{"executables":{"win32":["ShadowOfMordor.exe"]},"id":423,"name":"Middle-earth: Shadow of Mordor"},{"executables":{"win32":["Subnautica.exe"]},"id":424,"name":"Subnautica"},{"executables":{"win32":["anno5.exe"]},"id":425,"name":"Anno 2070"},{"executables":{"win32":["carrier.exe"]},"id":426,"name":"Carrier Command Gaea Mission"},{"executables":{"win32":["DarksidersPC.exe"]},"id":427,"name":"Darksiders"},{"executables":{"win32":["Darksiders2.exe"]},"id":428,"name":"Darksiders 2"},{"executables":{"win32":["mudlet.exe"]},"id":429,"name":"Mudlet"},{"executables":{"win32":["DunDefLauncher.exe"]},"id":430,"name":"Dungeon Defenders II"},{"executables":{"win32":["hng.exe"]},"id":431,"name":"Heroes and Generals"},{"executables":{"win32":["WFTOGame.exe"]},"id":432,"name":"War of the Overworld"},{"executables":{"win32":["Talisman.exe"]},"id":433,"name":"Talisman: Digital Edition"},{"executables":{"win32":["limbo.exe"]},"id":434,"name":"Limbo"},{"executables":{"win32":["ibbobb.exe"]},"id":435,"name":"ibb & obb"},{"executables":{"win32":["BattleBlockTheater.exe"]},"id":436,"name":"BattleBlock Theater"},{"executables":{"win32":["iracinglauncher.exe","iracingsim.exe","iracingsim64.exe"]},"id":437,"name":"iRacing"},{"executables":{"win32":["CivilizationV_DX11.exe"]},"id":438,"name":"Civilization V"}] +},{}]},{},[5])(5) +}); \ No newline at end of file diff --git a/web-dist/discord.min.3.7.1.js b/web-dist/discord.min.3.7.1.js new file mode 100644 index 000000000..84ac649e8 --- /dev/null +++ b/web-dist/discord.min.3.7.1.js @@ -0,0 +1,2 @@ +!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Discord=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g]*>/g)||[])[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;a.push(h.substring(2,h.length-1))}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return a}"function"==typeof c&&(d=c,c=!1),b=e+n(b);var p=o();f.resolveDestination(a).then(k)["catch"](j)});return g}},{key:"createws",value:function(a){if(this.websocket)return!1;var b=this;this.websocket=new o(a),this.websocket.onopen=function(){b.trySendConnData()},this.websocket.onclose=function(){b.trigger("disconnected")},this.websocket.onmessage=function(a){var c=!1,d={};try{c=JSON.parse(a.data),d=c.d}catch(e){return void b.trigger("error",e,a)}switch(b.trigger("raw",c),c.t){case"READY":b.debug("received ready packet"),b.user=b.addUser(d.user);var f=!0,h=!1,k=void 0;try{for(var l,m=d.guilds[Symbol.iterator]();!(f=(l=m.next()).done);f=!0)var n=l.value,o=b.addServer(n)}catch(e){h=!0,k=e}finally{try{!f&&m["return"]&&m["return"]()}finally{if(h)throw k}}var p=!0,q=!1,r=void 0;try{for(var s,t=d.private_channels[Symbol.iterator]();!(p=(s=t.next()).done);p=!0){var u=s.value;b.addPMChannel(u)}}catch(e){q=!0,r=e}finally{try{!p&&t["return"]&&t["return"]()}finally{if(q)throw r}}b.trigger("ready"),b.readyTime=Date.now(),b.debug("cached "+b.serverCache.length+" servers, "+b.channelCache.length+" channels, "+b.pmChannelCache.length+" PMs and "+b.userCache.length+" users."),b.state=3,setInterval(function(){b.keepAlive.apply(b)},d.heartbeat_interval);break;case"MESSAGE_CREATE":b.debug("received message");var v=[];d.mentions=d.mentions||[];var w=!0,x=!1,y=void 0;try{for(var z,A=d.mentions[Symbol.iterator]();!(w=(z=A.next()).done);w=!0){var B=z.value;v.push(b.addUser(B))}}catch(e){x=!0,y=e}finally{try{!w&&A["return"]&&A["return"]()}finally{if(x)throw y}}var C=b.getChannel("id",d.channel_id);if(C){var D=C.addMessage(new j(d,C,v,b.addUser(d.author)));b.trigger("message",D)}break;case"MESSAGE_DELETE":b.debug("message deleted");var C=b.getChannel("id",d.channel_id),E=C.getMessage("id",d.id);E?(b.trigger("messageDelete",C,E),C.messages.splice(C.messages.indexOf(E),1)):b.trigger("messageDelete",C);break;case"MESSAGE_UPDATE":b.debug("message updated");var C=b.getChannel("id",d.channel_id),F=C.getMessage("id",d.id);if(F){var G={};for(var H in F)G[H]=F[H];for(var H in d)G[H]=d[H];var v=[],I=!0,J=!1,K=void 0;try{for(var L,M=G.mentions[Symbol.iterator]();!(I=(L=M.next()).done);I=!0){var B=L.value;v.push(b.addUser(B))}}catch(e){J=!0,K=e}finally{try{!I&&M["return"]&&M["return"]()}finally{if(J)throw K}}var N=new j(G,C,v,F.author);b.trigger("messageUpdate",N,F),C.messages[C.messages.indexOf(F)]=N}break;case"GUILD_DELETE":var o=b.getServer("id",d.id);o&&(b.serverCache.splice(b.serverCache.indexOf(o),1),b.trigger("serverDelete",o));break;case"CHANNEL_DELETE":var C=b.getChannel("id",d.id);if(C){var o=C.server;o&&o.channels.splice(o.channels.indexOf(C),1),b.trigger("channelDelete",C),b.serverCache.splice(b.serverCache.indexOf(C),1)}break;case"GUILD_CREATE":var o=b.getServer("id",d.id);if(o||(o=b.addServer(d)),b.serverCreateListener[d.id]){var O=b.serverCreateListener[d.id];O[0](o),O[1](null,o),b.serverCreateListener[d.id]=null}b.trigger("serverCreate",o);break;case"CHANNEL_CREATE":var C=b.getChannel("id",d.id);if(!C){var P=b.addChannel(d,d.guild_id),Q=b.getServer("id",d.guild_id);Q&&Q.addChannel(P),b.trigger("channelCreate",P)}break;case"GUILD_MEMBER_ADD":var o=b.getServer("id",d.guild_id);if(o){var R=b.addUser(d.user);~o.members.indexOf(R)||o.members.push(R),b.trigger("serverNewMember",R,o)}break;case"GUILD_MEMBER_REMOVE":var o=b.getServer("id",d.guild_id);if(o){var R=b.addUser(d.user);~o.members.indexOf(R)&&o.members.splice(o.members.indexOf(R),1),b.trigger("serverRemoveMember",R,o)}break;case"USER_UPDATE":if(b.user&&d.id===b.user.id){var S=new g(d);b.trigger("userUpdate",S,b.user),~b.userCache.indexOf(b.user)&&(b.userCache[b.userCache.indexOf(b.user)]=S),b.user=S}break;case"PRESENCE_UPDATE":var T=b.getUser("id",d.user.id);if(T){var U=new g(d.user);U.equalsStrict(T)?(T.status=d.status,b.trigger("presence",{user:T,status:d.status,server:b.getServer("id",d.guild_id),gameId:d.game_id})):(b.trigger("userUpdate",T,U),b.userCache[b.userCache.indexOf(T)]=U)}break;case"CHANNEL_UPDATE":var V=b.getChannel("id",d.id),W=b.getServer("id",d.guild_id);if(V&&W){var X=new i(d,W);X.messages=V.messages,b.trigger("channelUpdate",V,X),b.channelCache[b.channelCache.indexOf(V)]=X}break;default:b.debug("received unknown packet"),b.trigger("unknown",c)}}}},{key:"addUser",value:function(a){return this.getUser("id",a.id)||this.userCache.push(new g(a)),this.getUser("id",a.id)}},{key:"addChannel",value:function(a,b){return this.getChannel("id",a.id)||this.channelCache.push(new i(a,this.getServer("id",b))),this.getChannel("id",a.id)}},{key:"addPMChannel",value:function(a){return this.getPMChannel("id",a.id)||this.pmChannelCache.push(new l(a,this)),this.getPMChannel("id",a.id)}},{key:"setTopic",value:function(a,b){var c=arguments.length<=2||void 0===arguments[2]?function(a){}:arguments[2],d=this;return new Promise(function(e,g){function h(a){c(a),g(a)}function i(a){var g=d.getChannel("id",a);n.patch(f.CHANNELS+"/"+a).set("authorization",d.token).send({name:g.name,position:0,topic:b}).end(function(a,b){a?h(a):(g.topic=b.body.topic,e(),c())})}d.resolveDestination(a).then(i)["catch"](h)})}},{key:"addServer",value:function(a){var b=this,c=this.getServer("id",a.id);if(a.unavailable)return b.trigger("unavailable",a),void b.debug("Server ID "+a.id+" has been marked unavailable by Discord. It was not cached.");if(!c&&(c=new h(a,this),this.serverCache.push(c),a.channels)){var d=!0,e=!1,f=void 0;try{for(var g,i=a.channels[Symbol.iterator]();!(d=(g=i.next()).done);d=!0){var j=g.value;c.channels.push(this.addChannel(j,c.id))}}catch(k){e=!0,f=k}finally{try{!d&&i["return"]&&i["return"]()}finally{if(e)throw f}}}var l=!0,m=!1,n=void 0;try{for(var o,p=a.presences[Symbol.iterator]();!(l=(o=p.next()).done);l=!0){var q=o.value;b.getUser("id",q.user.id).status=q.status}}catch(k){m=!0,n=k}finally{try{!l&&p["return"]&&p["return"]()}finally{if(m)throw n}}return c}},{key:"getUser",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.userCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"getChannel",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.channelCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return this.getPMChannel(a,b)}},{key:"getPMChannel",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.pmChannelCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"getServer",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.serverCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"trySendConnData",value:function(){if(this.token&&!this.alreadySentData){this.alreadySentData=!0;var a={op:2,d:{token:this.token,v:3,properties:{$os:"discord.js",$browser:"discord.js",$device:"discord.js",$referrer:"",$referring_domain:""}}};this.websocket.send(JSON.stringify(a))}}},{key:"resolveServerID",value:function(a){return a instanceof h?a.id:!isNaN(a)&&a.length&&17===a.length?a:void 0}},{key:"resolveDestination",value:function(a){var b=!1,c=this;return new Promise(function(d,e){if(a instanceof h)b=a.id;else if(a instanceof i)b=a.id;else if(a instanceof j)b=a.channel.id;else if(a instanceof l)b=a.id;else if(a instanceof g){var f=!0,k=!1,m=void 0;try{for(var n,o=c.pmChannelCache[Symbol.iterator]();!(f=(n=o.next()).done);f=!0){var p=n.value;if(p.user.equals(a))return void d(p.id)}}catch(q){k=!0,m=q}finally{try{!f&&o["return"]&&o["return"]()}finally{if(k)throw m}}c.startPM(a).then(function(a){d(a.id)})["catch"](e)}else b=a;b?d(b):e()})}},{key:"_sendMessage",value:function(a,b,c,d){var e=this;return new Promise(function(g,h){n.post(f.CHANNELS+"/"+a+"/messages").set("authorization",e.token).send({content:b,mentions:d,tts:c}).end(function(a,b){if(a)h(a);else{var c=b.body,d=[];c.mentions=c.mentions||[];var f=!0,i=!1,k=void 0;try{for(var l,m=c.mentions[Symbol.iterator]();!(f=(l=m.next()).done);f=!0){var n=l.value;d.push(e.addUser(n))}}catch(a){i=!0,k=a}finally{try{!f&&m["return"]&&m["return"]()}finally{if(i)throw k}}var o=e.getChannel("id",c.channel_id);if(o){var p=o.addMessage(new j(c,o,d,e.addUser(c.author)));g(p)}}})})}},{key:"_sendFile",value:function(a,b){var c=arguments.length<=2||void 0===arguments[2]?"DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png":arguments[2],d=this;return new Promise(function(e,g){n.post(f.CHANNELS+"/"+a+"/messages").set("authorization",d.token).attach("file",b,c).end(function(b,c){if(b)g(b);else{var f=d.getChannel("id",a);if(f){var h=f.addMessage(new j(c.body,f,[],d.user));e(h)}}})})}},{key:"_updateMessage",value:function(a,b){var c=this;return new Promise(function(d,e){n.patch(f.CHANNELS+"/"+a.channel.id+"/messages/"+a.id).set("authorization",c.token).send({content:b,mentions:[]}).end(function(b,c){if(b)e(b);else{var f=new j(c.body,a.channel,a.mentions,a.sender);d(f),a.channel.messages[a.channel.messages.indexOf(a)]=f}})})}},{key:"_deleteMessage",value:function(a){var b=this;return new Promise(function(c,d){n.del(f.CHANNELS+"/"+a.channel.id+"/messages/"+a.id).set("authorization",b.token).end(function(a,b){a?d(a):c()})})}},{key:"checkQueue",value:function(a){var b=this,c=this;this.checkingQueue[a]||!function(){var d=function f(){if(0===c.queue[a].length)return void e();var b=c.queue[a][0];switch(b.action){case"sendMessage":var d=b;c._sendMessage(a,d.content,d.tts,d.mentions).then(function(b){d.then(b),c.queue[a].shift(),f()})["catch"](function(b){d.error(b),c.queue[a].shift(),f()});break;case"sendFile":var g=b;c._sendFile(a,g.attachment,g.attachmentName).then(function(b){g.then(b),c.queue[a].shift(),f()})["catch"](function(b){g.error(b),c.queue[a].shift(),f()});break;case"updateMessage":var h=b;c._updateMessage(h.message,h.content).then(function(b){h.then(b),c.queue[a].shift(),f()})["catch"](function(b){h.error(b),c.queue[a].shift(),f()});break;case"deleteMessage":var i=b;c._deleteMessage(i.message).then(function(b){i.then(b),c.queue[a].shift(),f()})["catch"](function(b){i.error(b),c.queue[a].shift(),f()});break;default:e()}},e=function(){c.checkingQueue[a]=!1};b.checkingQueue[a]=!0,d()}()}},{key:"getGateway",value:function(){var a=this;return new Promise(function(b,c){n.get(f.API+"/gateway").set("authorization",a.token).end(function(a,d){a?c(a):b(d.body.url)})})}},{key:"setStatusIdle",value:function(){this.setStatus("idle")}},{key:"setStatusOnline",value:function(){this.setStatus("online")}},{key:"setStatusActive",value:function(){this.setStatusOnline()}},{key:"setStatusHere",value:function(){this.setStatusOnline()}},{key:"setStatusAway",value:function(){this.setStatusIdle()}},{key:"startTyping",value:function(a,b){function c(a){if(!d.typingIntervals[a]){var c=function(){n.post(f.CHANNELS+"/"+a+"/typing").set("authorization",d.token).end()};c();var e=setInterval(c,3e3);d.typingIntervals[a]=e,b&&setTimeout(function(){d.stopTyping(a)},b)}}var d=this;this.resolveDestination(a).then(c)}},{key:"stopTyping",value:function(a){function b(a){c.typingIntervals[a]&&(clearInterval(c.typingIntervals[a]),delete c.typingIntervals[a])}var c=this;this.resolveDestination(a).then(b)}},{key:"setStatus",value:function(a){var b="online"===a?null:Date.now();this.__idleTime=b,this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}))}},{key:"setPlayingGame",value:function(a){if(a instanceof String||"string"==typeof a){var b=a.trim().toUpperCase();a=null;var c=!0,d=!1,e=void 0;try{for(var f,g=m[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h.name.trim().toUpperCase()===b){a=h.id;break}}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}}this.__gameId=a,this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}))}},{key:"playGame",value:function(a){this.setPlayingGame(a)}},{key:"playingGame",value:function(a){this.setPlayingGame(a)}},{key:"uptime",get:function(){return this.readyTime?Date.now()-this.readyTime:null}},{key:"ready",get:function(){return 3===this.state}},{key:"servers",get:function(){return this.serverCache}},{key:"channels",get:function(){return this.channelCache}},{key:"users",get:function(){return this.userCache}},{key:"PMChannels",get:function(){return this.pmChannelCache}},{key:"messages",get:function(){var a=[],b=!0,c=!1,d=void 0;try{for(var e,f=this.channelCache[Symbol.iterator]();!(b=(e=f.next()).done);b=!0){var g=e.value;a=a.concat(g.messages)}}catch(h){c=!0,d=h}finally{try{!b&&f["return"]&&f["return"]()}finally{if(c)throw d}}return a}}]),a}();b.exports=r},{"../ref/gameMap.json":15,"./Endpoints.js":2,"./PMChannel.js":3,"./channel.js":4,"./invite.js":6,"./message.js":7,"./server.js":8,"./user.js":9,fs:10,superagent:11,ws:14}],2:[function(a,b,c){"use strict";c.BASE_DOMAIN="discordapp.com",c.BASE="https://"+c.BASE_DOMAIN,c.WEBSOCKET_HUB="wss://"+c.BASE_DOMAIN+"/hub",c.API=c.BASE+"/api",c.AUTH=c.API+"/auth",c.LOGIN=c.AUTH+"/login",c.LOGOUT=c.AUTH+"/logout",c.USERS=c.API+"/users",c.SERVERS=c.API+"/guilds",c.CHANNELS=c.API+"/channels"},{}],3:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c1e3&&this.messages.splice(0,1);var c=!0,d=!1,e=void 0;try{for(var f,g=this.messages[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"isPrivate",get:function(){return!0}}]),a}();b.exports=f},{}],4:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c1e3&&this.messages.splice(0,1),this.getMessage("id",a.id)||this.messages.push(a),this.getMessage("id",a.id)}},{key:"getMessage",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.messages[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"toString",value:function(){return"<#"+this.id+">"}},{key:"client",get:function(){return this.server.client}},{key:"isPrivate",get:function(){return!1}},{key:"users",get:function(){return this.server.members}},{key:"members",get:function(){return this.server.members}}]),a}();b.exports=f},{}],5:[function(a,b,c){"use strict";var d=(a("superagent"),a("./Endpoints.js")),e=a("./Client.js"),f={Endpoints:d,Client:e};b.exports=f},{"./Client.js":1,"./Endpoints.js":2,superagent:11}],6:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c"}},{key:"toString",value:function(){return this.mention()}},{key:"equals",value:function(a){return a.id===this.id}},{key:"equalsStrict",value:function(a){return a.id===this.id&&a.avatar===this.avatar&&a.username===this.username&&a.discriminator===this.discriminator}},{key:"avatarURL",get:function(){return this.avatar?"https://discordapp.com/api/users/"+this.id+"/avatars/"+this.avatar+".jpg":null}}]),a}();b.exports=f},{}],10:[function(a,b,c){},{}],11:[function(a,b,c){function d(){}function e(a){var b={}.toString.call(a);switch(b){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function f(a){return a===Object(a)}function g(a){if(!f(a))return a;var b=[];for(var c in a)null!=a[c]&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")}function h(a){for(var b,c,d={},e=a.split("&"),f=0,g=e.length;g>f;++f)c=e[f],b=c.split("="),d[decodeURIComponent(b[0])]=decodeURIComponent(b[1]);return d}function i(a){var b,c,d,e,f=a.split(/\r?\n/),g={};f.pop();for(var h=0,i=f.length;i>h;++h)c=f[h],b=c.indexOf(":"),d=c.slice(0,b).toLowerCase(),e=r(c.slice(b+1)),g[d]=e;return g}function j(a){return a.split(/ *; */).shift()}function k(a){return p(a.split(/ *; */),function(a,b){var c=b.split(/ *= */),d=c.shift(),e=c.shift();return d&&e&&(a[d]=e),a},{})}function l(a,b){b=b||{},this.req=a,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||"undefined"==typeof this.xhr.responseType?this.xhr.responseText:null, +this.statusText=this.req.xhr.statusText,this.setStatusProperties(this.xhr.status),this.header=this.headers=i(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body="HEAD"!=this.req.method?this.parseBody(this.text?this.text:this.xhr.response):null}function m(a,b){var c=this;o.call(this),this._query=this._query||[],this.method=a,this.url=b,this.header={},this._header={},this.on("end",function(){var a=null,b=null;try{b=new l(c)}catch(d){return a=new Error("Parser is unable to parse the response"),a.parse=!0,a.original=d,c.callback(a)}if(c.emit("response",b),a)return c.callback(a,b);if(b.status>=200&&b.status<300)return c.callback(a,b);var e=new Error(b.statusText||"Unsuccessful HTTP response");e.original=a,e.response=b,e.status=b.status,c.callback(e,b)})}function n(a,b){return"function"==typeof b?new m("GET",a).end(b):1==arguments.length?new m("GET",a):new m(a,b)}var o=a("emitter"),p=a("reduce"),q="undefined"==typeof window?this||self:window;n.getXHR=function(){if(!(!q.XMLHttpRequest||q.location&&"file:"==q.location.protocol&&q.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(a){}return!1};var r="".trim?function(a){return a.trim()}:function(a){return a.replace(/(^\s*|\s*$)/g,"")};n.serializeObject=g,n.parseString=h,n.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},n.serialize={"application/x-www-form-urlencoded":g,"application/json":JSON.stringify},n.parse={"application/x-www-form-urlencoded":h,"application/json":JSON.parse},l.prototype.get=function(a){return this.header[a.toLowerCase()]},l.prototype.setHeaderProperties=function(a){var b=this.header["content-type"]||"";this.type=j(b);var c=k(b);for(var d in c)this[d]=c[d]},l.prototype.parseBody=function(a){var b=n.parse[this.type];return b&&a&&(a.length||a instanceof Object)?b(a):null},l.prototype.setStatusProperties=function(a){1223===a&&(a=204);var b=a/100|0;this.status=a,this.statusType=b,this.info=1==b,this.ok=2==b,this.clientError=4==b,this.serverError=5==b,this.error=4==b||5==b?this.toError():!1,this.accepted=202==a,this.noContent=204==a,this.badRequest=400==a,this.unauthorized=401==a,this.notAcceptable=406==a,this.notFound=404==a,this.forbidden=403==a},l.prototype.toError=function(){var a=this.req,b=a.method,c=a.url,d="cannot "+b+" "+c+" ("+this.status+")",e=new Error(d);return e.status=this.status,e.method=b,e.url=c,e},n.Response=l,o(m.prototype),m.prototype.use=function(a){return a(this),this},m.prototype.timeout=function(a){return this._timeout=a,this},m.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},m.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(),this.clearTimeout(),this.emit("abort"),this)},m.prototype.set=function(a,b){if(f(a)){for(var c in a)this.set(c,a[c]);return this}return this._header[a.toLowerCase()]=b,this.header[a]=b,this},m.prototype.unset=function(a){return delete this._header[a.toLowerCase()],delete this.header[a],this},m.prototype.getHeader=function(a){return this._header[a.toLowerCase()]},m.prototype.type=function(a){return this.set("Content-Type",n.types[a]||a),this},m.prototype.accept=function(a){return this.set("Accept",n.types[a]||a),this},m.prototype.auth=function(a,b){var c=btoa(a+":"+b);return this.set("Authorization","Basic "+c),this},m.prototype.query=function(a){return"string"!=typeof a&&(a=g(a)),a&&this._query.push(a),this},m.prototype.field=function(a,b){return this._formData||(this._formData=new q.FormData),this._formData.append(a,b),this},m.prototype.attach=function(a,b,c){return this._formData||(this._formData=new q.FormData),this._formData.append(a,b,c),this},m.prototype.send=function(a){var b=f(a),c=this.getHeader("Content-Type");if(b&&f(this._data))for(var d in a)this._data[d]=a[d];else"string"==typeof a?(c||this.type("form"),c=this.getHeader("Content-Type"),"application/x-www-form-urlencoded"==c?this._data=this._data?this._data+"&"+a:a:this._data=(this._data||"")+a):this._data=a;return!b||e(a)?this:(c||this.type("json"),this)},m.prototype.callback=function(a,b){var c=this._callback;this.clearTimeout(),c(a,b)},m.prototype.crossDomainError=function(){var a=new Error("Origin is not allowed by Access-Control-Allow-Origin");a.crossDomain=!0,this.callback(a)},m.prototype.timeoutError=function(){var a=this._timeout,b=new Error("timeout of "+a+"ms exceeded");b.timeout=a,this.callback(b)},m.prototype.withCredentials=function(){return this._withCredentials=!0,this},m.prototype.end=function(a){var b=this,c=this.xhr=n.getXHR(),f=this._query.join("&"),g=this._timeout,h=this._formData||this._data;this._callback=a||d,c.onreadystatechange=function(){if(4==c.readyState){var a;try{a=c.status}catch(d){a=0}if(0==a){if(b.timedout)return b.timeoutError();if(b.aborted)return;return b.crossDomainError()}b.emit("end")}};var i=function(a){a.total>0&&(a.percent=a.loaded/a.total*100),b.emit("progress",a)};this.hasListeners("progress")&&(c.onprogress=i);try{c.upload&&this.hasListeners("progress")&&(c.upload.onprogress=i)}catch(j){}if(g&&!this._timer&&(this._timer=setTimeout(function(){b.timedout=!0,b.abort()},g)),f&&(f=n.serializeObject(f),this.url+=~this.url.indexOf("?")?"&"+f:"?"+f),c.open(this.method,this.url,!0),this._withCredentials&&(c.withCredentials=!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof h&&!e(h)){var k=this.getHeader("Content-Type"),l=n.serialize[k?k.split(";")[0]:""];l&&(h=l(h))}for(var m in this.header)null!=this.header[m]&&c.setRequestHeader(m,this.header[m]);return this.emit("request",this),c.send(h),this},m.prototype.then=function(a,b){return this.end(function(c,d){c?b(c):a(d)})},n.Request=m,n.get=function(a,b,c){var d=n("GET",a);return"function"==typeof b&&(c=b,b=null),b&&d.query(b),c&&d.end(c),d},n.head=function(a,b,c){var d=n("HEAD",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.del=function(a,b){var c=n("DELETE",a);return b&&c.end(b),c},n.patch=function(a,b,c){var d=n("PATCH",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.post=function(a,b,c){var d=n("POST",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.put=function(a,b,c){var d=n("PUT",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},b.exports=n},{emitter:12,reduce:13}],12:[function(a,b,c){function d(a){return a?e(a):void 0}function e(a){for(var b in d.prototype)a[b]=d.prototype[b];return a}b.exports=d,d.prototype.on=d.prototype.addEventListener=function(a,b){return this._callbacks=this._callbacks||{},(this._callbacks[a]=this._callbacks[a]||[]).push(b),this},d.prototype.once=function(a,b){function c(){d.off(a,c),b.apply(this,arguments)}var d=this;return this._callbacks=this._callbacks||{},c.fn=b,this.on(a,c),this},d.prototype.off=d.prototype.removeListener=d.prototype.removeAllListeners=d.prototype.removeEventListener=function(a,b){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var c=this._callbacks[a];if(!c)return this;if(1==arguments.length)return delete this._callbacks[a],this;for(var d,e=0;ed;++d)c[d].apply(this,b)}return this},d.prototype.listeners=function(a){return this._callbacks=this._callbacks||{},this._callbacks[a]||[]},d.prototype.hasListeners=function(a){return!!this.listeners(a).length}},{}],13:[function(a,b,c){b.exports=function(a,b,c){for(var d=0,e=a.length,f=3==arguments.length?c:a[d++];e>d;)f=b.call(null,f,a[d],++d,a);return f}},{}],14:[function(a,b,c){function d(a,b,c){var d;return d=b?new f(a,b):new f(a)}var e=function(){return this}(),f=e.WebSocket||e.MozWebSocket;b.exports=f?d:null,f&&(d.prototype=f.prototype)},{}],15:[function(a,b,c){b.exports=[{executables:{win32:["pol.exe"]},id:0,name:"FINAL FANTASY XI"},{executables:{win32:["ffxiv.exe","ffxiv_dx11.exe"]},id:1,name:"FINAL FANTASY XIV"},{executables:{win32:["Wow.exe","Wow-64.exe"]},id:3,name:"World of Warcraft"},{executables:{darwin:["LoLLauncher.app"],win32:["LolClient.exe","League of Legends.exe"]},id:4,name:"League of Legends"},{executables:{darwin:["Diablo%20III.app"],win32:["Diablo III.exe"]},id:5,name:"Diablo 3"},{executables:{darwin:["dota_osx.app"],win32:["dota2.exe"]},id:6,name:"DOTA 2"},{executables:{darwin:["Heroes.app"],win32:["Heroes of the Storm.exe","HeroesOfTheStorm_x64.exe","HeroesOfTheStorm.exe"]},id:7,name:"Heroes of the Storm"},{executables:{darwin:["Hearthstone.app"],win32:["Hearthstone.exe"]},id:8,name:"Hearthstone"},{executables:{win32:["csgo.exe"]},id:9,name:"Counter-Strike: Global Offensive"},{executables:{win32:["WorldOfTanks.exe"]},id:10,name:"World of Tanks"},{executables:{darwin:["gw2.app"],win32:["gw2.exe"]},id:11,name:"Guild Wars 2"},{executables:{win32:["dayz.exe"]},id:12,name:"Day Z"},{executables:{darwin:["starcraft%20ii.app"],win32:["starcraft ii.exe","SC2_x64.exe","SC2.exe"]},id:13,name:"Starcraft II"},{executables:{win32:["diablo.exe"]},id:14,name:"Diablo"},{executables:{win32:["diablo ii.exe"]},id:15,name:"Diablo 2"},{executables:{win32:["left4dead.exe"]},id:17,name:"Left 4 Dead"},{executables:{darwin:["minecraft.app"],win32:["minecraft.exe"]},id:18,name:"Minecraft"},{executables:{win32:["smite.exe"]},id:19,name:"Smite"},{executables:{win32:["bf4.exe"]},id:20,name:"Battlefield 4"},{executables:{win32:["AoK HD.exe","empires2.exe"]},id:101,name:"Age of Empire II"},{executables:{win32:["age3y.exe"]},id:102,name:"Age of Empire III"},{executables:{win32:["AlanWake.exe"]},id:104,name:"Alan Wake"},{executables:{win32:["alan_wakes_american_nightmare.exe"]},id:105,name:"Alan Wake's American Nightmare"},{executables:{win32:["AlienBreed2Assault.exe"]},id:106,name:"Alien Breed 2: Assault"},{executables:{win32:["Amnesia.exe"]},id:107,name:"Amnesia: The Dark Descent"},{executables:{win32:["UDK.exe"]},id:108,name:"Antichamber"},{executables:{win32:["ArcheAge.exe"]},id:109,name:"ArcheAge"},{executables:{win32:["arma3.exe"]},id:110,name:"Arma III"},{executables:{win32:["AC3SP.exe"]},id:111,name:"Assassin's Creed 3"},{executables:{win32:["Bastion.exe"]},id:112,name:"Bastion"},{executables:{win32:["BF2.exe"]},id:113,name:"Battlefield 2"},{executables:{win32:["bf3.exe"]},id:114,name:"Battlefield 3"},{executables:{win32:["Besiege.exe"]},id:116,name:"Besiege"},{executables:{win32:["Bioshock.exe"]},id:117,name:"Bioshock"},{executables:{win32:["Bioshock2.exe"]},id:118,name:"BioShock II"},{executables:{win32:["BioShockInfinite.exe"]},id:119,name:"BioShock Infinite"},{executables:{win32:["Borderlands2.exe"]},id:122,name:"Borderlands 2"},{executables:{win32:["braid.exe"]},id:123,name:"Braid"},{executables:{win32:["ShippingPC-StormGame.exe"]},id:124,name:"Bulletstorm"},{executables:{},id:125,name:"Cabal 2"},{executables:{win32:["CabalMain.exe"]},id:126,name:"Cabal Online"},{executables:{win32:["iw4mp.exe","iw4sp.exe"]},id:127,name:"Call of Duty: Modern Warfare 2"},{executables:{win32:["t6sp.exe"]},id:128,name:"Call of Duty: Black Ops"},{executables:{win32:["iw5mp.exe"]},id:129,name:"Call of Duty: Modern Warfare 3"},{executables:{win32:["RelicCOH.exe"]},id:132,name:"Company of Heroes"},{executables:{win32:["Crysis64.exe"]},id:135,name:"Crysis"},{executables:{win32:["Crysis2.exe"]},id:136,name:"Crysis 2"},{executables:{win32:["Crysis3.exe"]},id:137,name:"Crysis 3"},{executables:{win32:["Crysis.exe"]},id:138,name:"Crysis 4 "},{executables:{win32:["DATA.exe"]},id:140,name:"Dark Souls"},{executables:{win32:["DarkSoulsII.exe"]},id:141,name:"Dark Souls II"},{executables:{win32:["dfuw.exe"]},id:142,name:"Darkfall: Unholy Wars"},{executables:{win32:["DCGAME.exe"]},id:144,name:"DC Universe Online"},{executables:{win32:["DeadIslandGame.exe"]},id:145,name:"Dead Island"},{executables:{win32:["deadspace2.exe"]},id:146,name:"Dead Space 2"},{executables:{win32:["LOTDGame.exe"]},id:147,name:"Deadlight"},{executables:{win32:["dxhr.exe"]},id:148,name:"Deus Ex: Human Revolution"},{executables:{win32:["DeviMayCry4.exe"]},id:149,name:"Devil May Cry 4"},{executables:{win32:["DMC-DevilMayCry.exe"]},id:150,name:"DmC Devil May Cry"},{executables:{win32:["dirt2_game.exe"]},id:154,name:"DiRT 2"},{executables:{win32:["dirt3_game.exe"]},id:155,name:"DiRT 3"},{executables:{win32:["dota.exe"]},id:156,name:"DOTA"},{executables:{win32:["DoubleDragon.exe"]},id:158,name:"Double Dragon Neon"},{executables:{win32:["DragonAge2.exe"]},id:159,name:"Dragon Age II"},{executables:{win32:["DragonAgeInquisition.exe"]},id:160,name:"Dragon Age: Inquisition"},{executables:{win32:["daorigins.exe"]},id:161,name:"Dragon Age: Origins"},{executables:{win32:["DBXV.exe"]},id:162,name:"Dragon Ball XenoVerse"},{executables:{win32:["DukeForever.exe"]},id:163,name:"Duke Nukem Forever"},{executables:{darwin:["Dustforce.app"],win32:["dustforce.exe"]},id:164,name:"Dustforce"},{executables:{win32:["EliteDangerous32.exe"]},id:165,name:"Elite: Dangerous"},{executables:{win32:["exefile.exe"]},id:166,name:"Eve Online"},{executables:{win32:["eqgame.exe"]},id:167,name:"EverQuest"},{executables:{win32:["EverQuest2.exe"]},id:168,name:"EverQuest II"},{executables:{},id:169,name:"EverQuest Next"},{executables:{win32:["Engine.exe"]},id:170,name:"F.E.A.R."},{executables:{win32:["FEAR2.exe"]},id:171,name:"F.E.A.R. 2: Project Origin"},{executables:{win32:["fallout3.exe"]},id:172,name:"Fallout 3"},{executables:{win32:["FalloutNV.exe"]},id:174,name:"Fallout: New Vegas"},{executables:{win32:["farcry3.exe"]},id:175,name:"Far Cry 3"},{executables:{win32:["fifa15.exe"]},id:176,name:"FIFA 15"},{executables:{win32:["FTLGame.exe"]},id:180,name:"FTL: Faster Than Light"},{executables:{win32:["GTAIV.exe"]},id:181,name:"Grand Theft Auto 4"},{executables:{win32:["GTA5.exe"]},id:182,name:"Grand Theft Auto 5"},{executables:{win32:["Gw.exe"]},id:183,name:"Guild Wars"},{executables:{win32:["H1Z1.exe"]},id:186,name:"H1Z1"},{executables:{win32:["HL2HL2.exe","hl2.exe"]},id:188,name:"Half Life 2"},{executables:{win32:["HOMEFRONT.exe"]},id:195,name:"Homefront"},{executables:{win32:["invisibleinc.exe"]},id:196,name:"Invisible Inc."},{executables:{win32:["LANoire.exe"]},id:197,name:"L.A. Noire"},{executables:{win32:["Landmark64.exe"]},id:198,name:"Landmark"},{executables:{win32:["left4dead2.exe"]},id:201,name:"Left 4 Dead 2"},{executables:{win32:["lineage.exe"]},id:203,name:"Lineage"},{executables:{win32:["Magicka.exe"]},id:206,name:"Magicka"},{executables:{win32:["MapleStory.exe"]},id:208,name:"MapleStory"},{executables:{},id:209,name:"Mark of the Ninja"},{executables:{win32:["MassEffect.exe"]},id:210,name:"Mass Effect"},{executables:{win32:["MassEffect2.exe"]},id:211,name:"Mass Effect 2"},{executables:{win32:["MassEffect3Demo.exe"]},id:212,name:"Mass Effect 3"},{executables:{win32:["METAL GEAR RISING REVENGEANCE.exe"]},id:214,name:"Metal Gear Rising: Revengeance"},{executables:{win32:["metro2033.exe"]},id:215,name:"Metro 2033"},{executables:{win32:["MetroLL.exe"]},id:216,name:"Metro Last Light"},{executables:{win32:["MK10.exe"]},id:218,name:"Mortal Kombat X"},{executables:{win32:["speed.exe"]},id:219,name:"Need For Speed Most Wanted"},{executables:{},id:220,name:"Neverwinder"},{executables:{darwin:["Outlast.app"],win32:["OLGame.exe"]},id:221,name:"Outlast"},{executables:{win32:["PapersPlease.exe"]},id:222,name:"Papers, Please"},{executables:{win32:["payday_win32_release.exe"]},id:223,name:"PAYDAY"},{executables:{win32:["payday2_win32_release.exe"]},id:224,name:"PAYDAY2"},{executables:{win32:["PillarsOfEternity.exe"]},id:225,name:"Pillars of Eternity"},{executables:{win32:["PA.exe"]},id:226,name:"Planetary Annihilation"},{executables:{win32:["planetside2_x86.exe"]},id:227,name:"Planetside 2"},{executables:{win32:["hl2P.exe"]},id:228,name:"Portal"},{executables:{win32:["portal2.exe"]},id:229,name:"Portal 2"},{executables:{win32:["PrimalCarnageGame.exe"]},id:231,name:"Primal Cargnage"},{executables:{win32:["pCARS.exe"]},id:232,name:"Project Cars"},{executables:{win32:["RaceTheSun.exe"]},id:233,name:"Race The Sun"},{executables:{win32:["Rage.exe"]},id:234,name:"RAGE"},{executables:{win32:["ragexe.exe"]},id:235,name:"Ragnarok Online"},{executables:{win32:["rift.exe"]},id:236,name:"Rift"},{executables:{win32:["Rocksmith2014.exe"]},id:237,name:"Rocksmith 2014"},{executables:{win32:["SwiftKit-RS.exe","JagexLauncher.exe"]},id:238,name:"RuneScape"},{executables:{win32:["Shadowgrounds.exe"]},id:239,name:"Shadowgrounds"},{executables:{win32:["survivor.exe"]},id:240,name:"Shadowgrounds: Survivor"},{executables:{win32:["ShovelKnight.exe"]},id:241,name:"Shovel Knight"},{executables:{win32:["SimCity.exe"]},id:242,name:"SimCity"},{executables:{win32:["SporeApp.exe"]},id:245,name:"Spore"},{executables:{win32:["StarCitizen.exe"]},id:246,name:"Star Citizen"},{executables:{},id:247,name:"Star Trek Online"},{executables:{win32:["battlefront.exe"]},id:248,name:"Star Wars Battlefront"},{executables:{win32:["swtor.exe"]},id:249,name:"Star Wars: The Old Republic"},{executables:{win32:["starbound.exe","starbound_opengl.exe"]},id:250,name:"Starbound"},{executables:{win32:["starcraft.exe"]},id:251,name:"Starcraft"},{executables:{win32:["SSFIV.exe"]},id:253,name:"Ultra Street Fighter IV"},{executables:{win32:["superhexagon.exe"]},id:254,name:"Super Hexagon"},{executables:{win32:["swordandsworcery_pc.exe"]},id:255,name:"Superbrothers: Sword & Sworcery EP"},{executables:{win32:["hl2TF.exe"]},id:256,name:"Team Fortress 2"},{executables:{win32:["TERA.exe"]},id:258,name:"TERA"},{executables:{win32:["Terraria.exe"]},id:259,name:"Terraria"},{executables:{win32:["Bethesda.net_Launcher.exe"]},id:260,name:"The Elder Scrolls Online"},{executables:{win32:["TESV.exe"]},id:261,name:"The Elder Scrolls V: Skyrim"},{executables:{win32:["TheSecretWorld.exe"]},id:262,name:"The Secret World"},{executables:{win32:["TS3.exe","ts3w.exe"]},id:264,name:"The Sims 3"},{executables:{win32:["WALKINGDEAD101.EXE"]},id:265,name:"The Walking Dead"},{executables:{win32:["TheWalkingDead2.exe"]},id:266,name:"The Walking Dead Season Two"},{executables:{win32:["witcher3.exe"]},id:267,name:"The Witcher 3"},{executables:{win32:["Future Soldier.exe"]},id:268,name:"Tom Clancy's Ghost Recon: Future Solider"},{executables:{win32:["TombRaider.exe"]},id:269,name:"Tomb Raider (2013)"},{executables:{win32:["Torchlight.exe"]},id:271,name:"Torchlight"},{executables:{win32:["Torchlight2.exe"]},id:272,name:"Torchlight 2"},{executables:{win32:["Shogun2.exe"]},id:273,name:"Total War: Shogun 2"},{executables:{win32:["Transistor.exe"]},id:274,name:"Transistor"},{executables:{win32:["trine.exe"]},id:275,name:"Trine"},{executables:{win32:["trine2_32bit.exe"]},id:276,name:"Trine 2"},{executables:{win32:["UOKR.exe"]},id:277,name:"Ultima Online"},{executables:{win32:["aces.exe"]},id:279,name:"War Thunder"},{executables:{win32:["Warcraft III.exe","wc3.exe"]},id:281,name:"Warcraft 3: Reign of Chaos"},{executables:{win32:["Warcraft II BNE.exe"]},id:282,name:"Warcraft II"},{executables:{win32:["Warframe.x64.exe","Warframe.exe"]},id:283,name:"Warframe"},{executables:{win32:["watch_dogs.exe"]},id:284,name:"Watch Dogs"},{executables:{win32:["WildStar64.exe"]},id:285,name:"WildStar"},{executables:{win32:["XComGame.exe"]},id:288,name:"XCOM: Enemy Unknown"},{executables:{win32:["DFO.exe","dfo.exe"]},id:289,name:"Dungeon Fighter Online"},{executables:{win32:["aclauncher.exe","acclient.exe"]},id:290,name:"Asheron's Call"},{executables:{win32:["MapleStory2.exe"]},id:291,name:"MapleStory 2"},{executables:{win32:["ksp.exe"]},id:292,name:"Kerbal Space Program"},{executables:{win32:["PINBALL.EXE"]},id:293,name:"3D Pinball: Space Cadet"},{executables:{win32:["dave.exe"]},id:294,name:"Dangerous Dave"},{executables:{win32:["iwbtgbeta(slomo).exe","iwbtgbeta(fs).exe"]},id:295,name:"I Wanna Be The Guy"},{executables:{win32:["MechWarriorOnline.exe "]},id:296,name:"Mech Warrior Online"},{executables:{win32:["dontstarve_steam.exe"]},id:297,name:"Don't Starve"},{executables:{win32:["GalCiv3.exe"]},id:298,name:"Galactic Civilization 3"},{executables:{win32:["Risk of Rain.exe"]},id:299,name:"Risk of Rain"},{executables:{win32:["Binding_of_Isaac.exe","Isaac-ng.exe"]},id:300,name:"The Binding of Isaac"},{executables:{win32:["RustClient.exe"]},id:301,name:"Rust"},{executables:{win32:["Clicker Heroes.exe"]},id:302,name:"Clicker Heroes"},{executables:{win32:["Brawlhalla.exe"]},id:303,name:"Brawlhalla"},{executables:{win32:["TownOfSalem.exe"]},id:304,name:"Town of Salem"},{executables:{win32:["osu!.exe"]},id:305,name:"osu!"},{executables:{win32:["PathOfExileSteam.exe","PathOfExile.exe"]},id:306,name:"Path of Exile"},{executables:{win32:["Dolphin.exe"]},id:307,name:"Dolphin"},{executables:{win32:["RocketLeague.exe"]},id:308,name:"Rocket League"},{executables:{win32:["TJPP.exe"]},id:309,name:"Jackbox Party Pack"},{executables:{win32:["KFGame.exe"]},id:310,name:"Killing Floor 2"},{executables:{win32:["ShooterGame.exe"]},id:311,name:"Ark: Survival Evolved"},{executables:{win32:["LifeIsStrange.exe"]},id:312,name:"Life Is Strange"},{executables:{win32:["Client_tos.exe"]},id:313,name:"Tree of Savior"},{executables:{win32:["olliolli2.exe"]},id:314,name:"OlliOlli2"},{executables:{win32:["cw.exe"]},id:315,name:"Closers Dimension Conflict"},{executables:{win32:["ESSTEAM.exe","elsword.exe","x2.exe"]},id:316,name:"Elsword"},{executables:{win32:["ori.exe"]},id:317,name:"Ori and the Blind Forest"},{executables:{win32:["Skyforge.exe"]},id:318,name:"Skyforge"},{executables:{win32:["projectzomboid64.exe","projectzomboid32.exe"]},id:319,name:"Project Zomboid"},{executables:{win32:["From_The_Depths.exe"]},id:320,name:"The Depths"},{executables:{win32:["TheCrew.exe"]},id:321,name:"The Crew"},{executables:{win32:["MarvelHeroes2015.exe"]},id:322,name:"Marvel Heroes 2015"},{executables:{win32:["timeclickers.exe"]},id:324,name:"Time Clickers"},{executables:{win32:["eurotrucks2.exe"]},id:325,name:"Euro Truck Simulator 2"},{executables:{win32:["FarmingSimulator2015Game.exe"]},id:326,name:"Farming Simulator 15"},{executables:{win32:["strife.exe"]},id:327,name:"Strife"},{executables:{win32:["Awesomenauts.exe"]},id:328,name:"Awesomenauts"},{executables:{win32:["Dofus.exe"]},id:329,name:"Dofus"},{executables:{win32:["Boid.exe"]},id:330,name:"Boid"},{executables:{win32:["adventure-capitalist.exe"]},id:331,name:"AdVenture Capitalist"},{executables:{win32:["OrcsMustDie2.exe"]},id:332,name:"Orcs Must Die! 2"},{executables:{win32:["Mountain.exe"]},id:333,name:"Mountain"},{executables:{win32:["Valkyria.exe"]},id:335,name:"Valkyria Chronicles"},{executables:{win32:["ffxiiiimg.exe"]},id:336,name:"Final Fantasy XIII"},{executables:{win32:["TLR.exe"]},id:337,name:"The Last Remnant"},{executables:{win32:["Cities.exe"]},id:339,name:"Cities Skylines"},{executables:{win32:["worldofwarships.exe","WoWSLauncher.exe"]},id:341,name:"World of Warships"},{executables:{win32:["spacegame-Win64-shipping.exe"]},id:342,name:"Fractured Space"},{executables:{win32:["thespacegame.exe"]},id:343,name:"Ascent - The Space Game"},{executables:{win32:["DuckGame.exe"]},id:344,name:"Duck Game"},{executables:{win32:["PPSSPPWindows.exe"]},id:345,name:"PPSSPP"},{executables:{win32:["MBAA.exe"]},id:346,name:"Melty Blood Actress Again: Current Code"},{executables:{win32:["TheWolfAmongUs.exe"]},id:347,name:"The Wolf Among Us"},{executables:{win32:["SpaceEngineers.exe"]},id:348,name:"Space Engineers"},{executables:{win32:["Borderlands.exe"]},id:349,name:"Borderlands"},{executables:{win32:["100orange.exe"]},id:351,name:"100% Orange Juice"},{executables:{win32:["reflex.exe"]},id:354,name:"Reflex"},{executables:{win32:["pso2.exe"]},id:355,name:"Phantasy Star Online 2"},{executables:{win32:["AssettoCorsa.exe"]},id:356,name:"Assetto Corsa"},{executables:{win32:["iw3mp.exe","iw3sp.exe"]},id:357,name:"Call of Duty 4: Modern Warfare"},{executables:{win32:["WolfOldBlood_x64.exe"]},id:358,name:"Wolfenstein: The Old Blood"},{executables:{win32:["castle.exe"]},id:359,name:"Castle Crashers"},{executables:{win32:["vindictus.exe"]},id:360,name:"Vindictus"},{executables:{win32:["ShooterGame-Win32-Shipping.exe"]},id:361,name:"Dirty Bomb"},{executables:{win32:["BatmanAK.exe"]},id:362,name:"Batman Arkham Knight"},{executables:{win32:["drt.exe"]},id:363,name:"Dirt Rally"},{executables:{win32:["rFactor.exe"]},id:364,name:"rFactor"},{executables:{win32:["clonk.exe"]},id:365,name:"Clonk Rage"},{executables:{win32:["SRHK.exe"]},id:366,name:"Shadowrun: Hong Kong"},{executables:{win32:["Insurgency.exe"]},id:367,name:"Insurgency"},{executables:{win32:["StepMania.exe"]},id:368,name:"Step Mania"},{executables:{win32:["FirefallCLient.exe"]},id:369,name:"Firefall"},{executables:{win32:["mirrorsedge.exe"]},id:370,name:"Mirrors Edge"},{executables:{win32:["MgsGroundZeroes.exe"]},id:371,name:"Metal Gear Solid V: Ground Zeroes"},{executables:{win32:["mgsvtpp.exe"]},id:372,name:"Metal Gear Solid V: The Phantom Pain"},{executables:{win32:["tld.exe"]},id:373,name:"The Long Dark"},{executables:{win32:["TKOM.exe"]},id:374,name:"Take On Mars"},{executables:{win32:["robloxplayerlauncher.exe","Roblox.exe"]},id:375,name:"Roblox"},{executables:{win32:["eu4.exe"]},id:376,name:"Europa Universalis 4"},{executables:{win32:["APB.exe"]},id:377,name:"APB Reloaded"},{executables:{win32:["Robocraft.exe"]},id:378,name:"Robocraft"},{executables:{win32:["Unity.exe"]},id:379,name:"Unity"},{executables:{win32:["Simpsons.exe"]},id:380,name:"The Simpsons: Hit & Run"},{executables:{win32:["Dnlauncher.exe","DragonNest.exe"]},id:381,name:"Dragon Nest"},{executables:{win32:["Trove.exe"]},id:382,name:"Trove"},{executables:{win32:["EndlessLegend.exe"]},id:383,name:"Endless Legend"},{executables:{win32:["TurbineLauncher.exe","dndclient.exe"]},id:384,name:"Dungeons & Dragons Online"},{executables:{win32:["quakelive.exe","quakelive_steam.exe"]},id:385,name:"Quake Live"},{executables:{win32:["7DaysToDie.exe"]},id:386,name:"7DaysToDie"},{executables:{win32:["SpeedRunners.exe"]},id:387,name:"SpeedRunners"},{executables:{win32:["gamemd.exe"]},id:388,name:"Command & Conquer: Red Alert 2"},{executables:{win32:["generals.exe"]},id:389,name:"Command & Conquer Generals: Zero Hour"},{executables:{win32:["Oblivion.exe"]},id:390,name:"The Elder Scrolls 4: Oblivion"},{executables:{win32:["mgsi.exe"]},id:391,name:"Metal Gear Solid"},{executables:{win32:["EoCApp.exe"]},id:392,name:"Divinity - Original Sin"},{executables:{win32:["Torment.exe"]},id:393,name:"Planescape: Torment"},{executables:{win32:["HexPatch.exe"]},id:394,name:"Hex: Shards of Fate"},{executables:{win32:["NS3FB.exe"]},id:395,name:"Naruto Shippuden Ultimate Ninja Storm 3 Full Burst"},{executables:{win32:["NSUNSR.exe"]},id:396,name:"Naruto Shippuden Ultimate Ninja Storm Revolution"},{executables:{win32:["SaintsRowIV.exe"]},id:397,name:"Saints Row IV"},{executables:{win32:["Shadowrun.exe"]},id:398,name:"Shadowrun"},{executables:{win32:["DungeonoftheEndless.exe"]},id:399,name:"Dungeon of the Endless"},{executables:{win32:["Hon.exe"]},id:400,name:"Heroes of Newerth"},{executables:{win32:["mabinogi.exe"]},id:401,name:"Mabinogi"},{executables:{win32:["CoD2MP_s.exe","CoDSP_s.exe"]},id:402,name:"Call of Duty 2:"},{executables:{win32:["CoDWaWmp.exe","CoDWaw.exe"]},id:403,name:"Call of Duty: World at War"},{executables:{win32:["heroes.exe"]},id:404,name:"Mabinogi Heroes (Vindictus) "},{executables:{win32:["KanColleViewer.exe"]},id:405,name:"KanColle "},{executables:{win32:["cyphers.exe"]},id:406,name:"Cyphers"},{executables:{win32:["RelicCoH2.exe"]},id:407,name:"Company of Heroes 2"},{executables:{win32:["MJ.exe"]},id:408,name:"セガNET麻雀MJ"},{executables:{win32:["ge.exe"]},id:409,name:"Granado Espada"},{executables:{win32:["NovaRO.exe"]},id:410,name:"Nova Ragnarok Online"},{executables:{win32:["RivalsofAether.exe"]},id:411,name:"Rivals of Aether"},{executables:{win32:["bfh.exe"]},id:412,name:"Battlefield Hardline"},{executables:{win32:["GrowHome.exe"]},id:413,name:"Grow Home"},{executables:{win32:["patriots.exe"]},id:414,name:"Rise of Nations Extended"},{executables:{win32:["Railroads.exe"]},id:415,name:"Sid Meier's Railroads!"},{executables:{win32:["Empire.exe"]},id:416,name:"Empire: Total War"},{executables:{win32:["Napoleon.exe"]},id:417,name:"Napoleon: Total War"},{executables:{win32:["gta_sa.exe"]},id:418,name:"Grand Theft Auto: San Andreas"},{executables:{win32:["MadMax.exe"]},id:419,name:"Mad Max"},{executables:{win32:["Titanfall.exe"]},id:420,name:"Titanfall"},{executables:{win32:["age2_x1.exe"]},id:421,name:"Age of Empires II: The Conquerors"},{executables:{win32:["Rome2.exe"]},id:422,name:"Total War: ROME 2"},{executables:{win32:["ShadowOfMordor.exe"]},id:423,name:"Middle-earth: Shadow of Mordor"},{executables:{win32:["Subnautica.exe"]},id:424,name:"Subnautica"},{executables:{win32:["anno5.exe"]},id:425,name:"Anno 2070"},{executables:{win32:["carrier.exe"]},id:426,name:"Carrier Command Gaea Mission"},{executables:{win32:["DarksidersPC.exe"]},id:427,name:"Darksiders"},{executables:{win32:["Darksiders2.exe"]},id:428,name:"Darksiders 2"},{executables:{win32:["mudlet.exe"]},id:429,name:"Mudlet"},{executables:{win32:["DunDefLauncher.exe"]},id:430,name:"Dungeon Defenders II"},{executables:{win32:["hng.exe"]},id:431,name:"Heroes and Generals"},{executables:{win32:["WFTOGame.exe"]},id:432,name:"War of the Overworld"},{executables:{win32:["Talisman.exe"]},id:433,name:"Talisman: Digital Edition"},{executables:{win32:["limbo.exe"]},id:434,name:"Limbo"},{executables:{win32:["ibbobb.exe"]},id:435,name:"ibb & obb"},{executables:{win32:["BattleBlockTheater.exe"]},id:436,name:"BattleBlock Theater"},{executables:{win32:["iracinglauncher.exe","iracingsim.exe","iracingsim64.exe"]},id:437,name:"iRacing"},{executables:{win32:["CivilizationV_DX11.exe"]},id:438,name:"Civilization V"}]},{}]},{},[5])(5)}); \ No newline at end of file From 87901b7643fffc5b8c97defa145e1bf8006b81ee Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 2 Oct 2015 21:46:16 +0100 Subject: [PATCH 099/151] Are you happy yet travis build >_> --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index af4e59f4b..35c83aa5d 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { - "prepublish": "grunt dist", "test": "node ./test/bot.js" }, "repository": { From 4c913902173d1732cf2fa4b168163fc2c813143e Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 2 Oct 2015 21:48:02 +0100 Subject: [PATCH 100/151] 3.7.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 35c83aa5d..74c1b4766 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.7.1", + "version": "3.7.2", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From 8045d849f767a6848d71f84555fc9c8b05703434 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 14:46:42 +0100 Subject: [PATCH 101/151] Rebuild code --- lib/Client.js | 2 +- lib/Endpoints.js | 2 +- lib/Member.js | 2 +- lib/PMChannel.js | 2 +- lib/Permissions.js | 2 +- lib/channel.js | 2 +- lib/index.js | 2 +- lib/internal.js | 2 +- lib/invite.js | 2 +- lib/message.js | 2 +- lib/server.js | 2 +- lib/user.js | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 4d097628b..091424b16 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1925,4 +1925,4 @@ var Client = (function () { return Client; })(); -module.exports = Client; +module.exports = Client; \ No newline at end of file diff --git a/lib/Endpoints.js b/lib/Endpoints.js index e55f0f580..271b465eb 100644 --- a/lib/Endpoints.js +++ b/lib/Endpoints.js @@ -10,4 +10,4 @@ exports.LOGIN = exports.AUTH + "/login"; exports.LOGOUT = exports.AUTH + "/logout"; exports.USERS = exports.API + "/users"; exports.SERVERS = exports.API + "/guilds"; -exports.CHANNELS = exports.API + "/channels"; +exports.CHANNELS = exports.API + "/channels"; \ No newline at end of file diff --git a/lib/Member.js b/lib/Member.js index 471460e77..7d7b03f1a 100644 --- a/lib/Member.js +++ b/lib/Member.js @@ -18,4 +18,4 @@ var Member = (function (_User) { } return Member; -})(User); +})(User); \ No newline at end of file diff --git a/lib/PMChannel.js b/lib/PMChannel.js index 6eb8134de..0dbc0405e 100644 --- a/lib/PMChannel.js +++ b/lib/PMChannel.js @@ -68,4 +68,4 @@ var PMChannel = (function () { return PMChannel; })(); -module.exports = PMChannel; +module.exports = PMChannel; \ No newline at end of file diff --git a/lib/Permissions.js b/lib/Permissions.js index 3b7c8f256..a1f4f3083 100644 --- a/lib/Permissions.js +++ b/lib/Permissions.js @@ -45,4 +45,4 @@ var Permission = (function () { }]); return Permission; -})(); +})(); \ No newline at end of file diff --git a/lib/channel.js b/lib/channel.js index 90a2d7428..bb67fcf4f 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -98,4 +98,4 @@ var Channel = (function () { return Channel; })(); -module.exports = Channel; +module.exports = Channel; \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index f0c3c0ab7..6a2f82f05 100644 --- a/lib/index.js +++ b/lib/index.js @@ -9,4 +9,4 @@ var Discord = { Client: Client }; -module.exports = Discord; +module.exports = Discord; \ No newline at end of file diff --git a/lib/internal.js b/lib/internal.js index e8b3385da..3acf5940b 100644 --- a/lib/internal.js +++ b/lib/internal.js @@ -200,4 +200,4 @@ Internal.XHR.setUsername = function (token, avatar, email, newPassword, password }); }; -exports.Internal = Internal; +exports.Internal = Internal; \ No newline at end of file diff --git a/lib/invite.js b/lib/invite.js index 7bc8204bd..5f51dc1a9 100644 --- a/lib/invite.js +++ b/lib/invite.js @@ -32,4 +32,4 @@ var Invite = (function () { return Invite; })(); -module.exports = Invite; +module.exports = Invite; \ No newline at end of file diff --git a/lib/message.js b/lib/message.js index f3f3c574a..3dd4ddcae 100644 --- a/lib/message.js +++ b/lib/message.js @@ -76,4 +76,4 @@ var Message = (function () { return Message; })(); -module.exports = Message; +module.exports = Message; \ No newline at end of file diff --git a/lib/server.js b/lib/server.js index 8bd9332a2..c8758d5da 100644 --- a/lib/server.js +++ b/lib/server.js @@ -180,4 +180,4 @@ var Server = (function () { return Server; })(); -module.exports = Server; +module.exports = Server; \ No newline at end of file diff --git a/lib/user.js b/lib/user.js index e2b2ca256..5e38e132e 100644 --- a/lib/user.js +++ b/lib/user.js @@ -54,4 +54,4 @@ var User = (function () { return User; })(); -module.exports = User; +module.exports = User; \ No newline at end of file From 843c0defebfed7b35f2ce6f6f7120461076d66b1 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 14:47:32 +0100 Subject: [PATCH 102/151] Removed checkQueue --- lib/Client.js | 81 ------------------------------------------------ src/Client.js | 85 --------------------------------------------------- 2 files changed, 166 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 091424b16..7f9f5c523 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1613,87 +1613,6 @@ var Client = (function () { }); }); } - }, { - key: "checkQueue", - value: function checkQueue(channelID) { - var _this = this; - - var self = this; - - if (!this.checkingQueue[channelID]) { - (function () { - var doNext = function doNext() { - if (self.queue[channelID].length === 0) { - done(); - return; - } - var queuedEvent = self.queue[channelID][0]; - switch (queuedEvent.action) { - case "sendMessage": - var msgToSend = queuedEvent; - self._sendMessage(channelID, msgToSend.content, msgToSend.tts, msgToSend.mentions).then(function (msg) { - msgToSend.then(msg); - self.queue[channelID].shift(); - doNext(); - })["catch"](function (err) { - msgToSend.error(err); - self.queue[channelID].shift(); - doNext(); - }); - break; - case "sendFile": - var fileToSend = queuedEvent; - self._sendFile(channelID, fileToSend.attachment, fileToSend.attachmentName).then(function (msg) { - fileToSend.then(msg); - self.queue[channelID].shift(); - doNext(); - })["catch"](function (err) { - fileToSend.error(err); - self.queue[channelID].shift(); - doNext(); - }); - break; - case "updateMessage": - var msgToUpd = queuedEvent; - self._updateMessage(msgToUpd.message, msgToUpd.content).then(function (msg) { - msgToUpd.then(msg); - self.queue[channelID].shift(); - doNext(); - })["catch"](function (err) { - msgToUpd.error(err); - self.queue[channelID].shift(); - doNext(); - }); - break; - case "deleteMessage": - var msgToDel = queuedEvent; - self._deleteMessage(msgToDel.message).then(function (msg) { - msgToDel.then(msg); - self.queue[channelID].shift(); - doNext(); - })["catch"](function (err) { - msgToDel.error(err); - self.queue[channelID].shift(); - doNext(); - }); - break; - default: - done(); - break; - } - }; - - var done = function done() { - self.checkingQueue[channelID] = false; - return; - }; - - //if we aren't already checking this queue. - _this.checkingQueue[channelID] = true; - doNext(); - })(); - } - } }, { key: "getGateway", value: function getGateway() { diff --git a/src/Client.js b/src/Client.js index aa396fb4e..4f6dbfe84 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1355,91 +1355,6 @@ class Client { }); } - checkQueue(channelID) { - - var self = this; - - if (!this.checkingQueue[channelID]) { - //if we aren't already checking this queue. - this.checkingQueue[channelID] = true; - doNext(); - - function doNext() { - if (self.queue[channelID].length === 0) { - done(); - return; - } - var queuedEvent = self.queue[channelID][0]; - switch (queuedEvent.action) { - case "sendMessage": - var msgToSend = queuedEvent; - self._sendMessage(channelID, msgToSend.content, msgToSend.tts, msgToSend.mentions) - .then(function (msg) { - msgToSend.then(msg); - self.queue[channelID].shift(); - doNext(); - }) - .catch(function (err) { - msgToSend.error(err); - self.queue[channelID].shift(); - doNext(); - }); - break; - case "sendFile": - var fileToSend = queuedEvent; - self._sendFile(channelID, fileToSend.attachment, fileToSend.attachmentName) - .then(function (msg) { - fileToSend.then(msg); - self.queue[channelID].shift(); - doNext(); - }) - .catch(function (err) { - fileToSend.error(err); - self.queue[channelID].shift(); - doNext(); - }); - break; - case "updateMessage": - var msgToUpd = queuedEvent; - self._updateMessage(msgToUpd.message, msgToUpd.content) - .then(function (msg) { - msgToUpd.then(msg); - self.queue[channelID].shift(); - doNext(); - }) - .catch(function (err) { - msgToUpd.error(err); - self.queue[channelID].shift(); - doNext(); - }); - break; - case "deleteMessage": - var msgToDel = queuedEvent; - self._deleteMessage(msgToDel.message) - .then(function (msg) { - msgToDel.then(msg); - self.queue[channelID].shift(); - doNext(); - }) - .catch(function (err) { - msgToDel.error(err); - self.queue[channelID].shift(); - doNext(); - }); - break; - default: - done(); - break; - } - } - - function done() { - self.checkingQueue[channelID] = false; - return; - } - } - } - getGateway() { var self = this; return new Promise(function (resolve, reject) { From ba695380291781646a9b73671317406cb4fd3cd8 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 15:00:57 +0100 Subject: [PATCH 103/151] cleaned up deleteMessage --- lib/Client.js | 43 ++++++++----------------------------------- src/Client.js | 49 ++++++++++++------------------------------------- 2 files changed, 20 insertions(+), 72 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 7f9f5c523..8632319cc 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -352,7 +352,7 @@ var Client = (function () { var self = this; - var prom = new Promise(function (resolve, reject) { + return new Promise(function (resolve, reject) { if (timeout) { setTimeout(remove, timeout); } else { @@ -360,37 +360,25 @@ var Client = (function () { } function remove() { - if (self.options.queue) { - if (!self.queue[message.channel.id]) { - self.queue[message.channel.id] = []; + request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).end(function (err, res) { + if (err) { + bad(); + } else { + good(); } - self.queue[message.channel.id].push({ - action: "deleteMessage", - message: message, - then: good, - error: bad - }); - - self.checkQueue(message.channel.id); - } else { - self._deleteMessage(message).then(good)["catch"](bad); - } + }); } function good() { - prom.success = true; - callback(null); + callback(); resolve(); } function bad(err) { - prom.error = err; callback(err); reject(err); } }); - - return prom; } }, { key: "updateMessage", @@ -1598,21 +1586,6 @@ var Client = (function () { }); }); } - }, { - key: "_deleteMessage", - value: function _deleteMessage(message) { - var self = this; - return new Promise(function (resolve, reject) { - - request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).end(function (err, res) { - if (err) { - reject(err); - } else { - resolve(); - } - }); - }); - } }, { key: "getGateway", value: function getGateway() { diff --git a/src/Client.js b/src/Client.js index 4f6dbfe84..dcccddaa0 100644 --- a/src/Client.js +++ b/src/Client.js @@ -389,7 +389,7 @@ class Client { var self = this; - var prom = new Promise(function (resolve, reject) { + return new Promise(function (resolve, reject) { if (timeout) { setTimeout(remove, timeout) } else { @@ -397,37 +397,29 @@ class Client { } function remove() { - if (self.options.queue) { - if (!self.queue[message.channel.id]) { - self.queue[message.channel.id] = []; + request + .del(`${Endpoints.CHANNELS}/${message.channel.id}/messages/${message.id}`) + .set("authorization", self.token) + .end(function (err, res) { + if(err){ + bad(); + }else{ + good(); } - self.queue[message.channel.id].push({ - action: "deleteMessage", - message: message, - then: good, - error: bad - }); - - self.checkQueue(message.channel.id); - } else { - self._deleteMessage(message).then(good).catch(bad); - } + }); } function good() { - prom.success = true; - callback(null); + callback(); resolve(); } function bad(err) { - prom.error = err; callback(err); reject(err); } }); - - return prom; + } updateMessage(message, content, callback = function (err, msg) { }) { @@ -1338,23 +1330,6 @@ class Client { }); } - _deleteMessage(message) { - var self = this; - return new Promise(function (resolve, reject) { - - request - .del(`${Endpoints.CHANNELS}/${message.channel.id}/messages/${message.id}`) - .set("authorization", self.token) - .end(function (err, res) { - if (err) { - reject(err); - } else { - resolve(); - } - }); - }); - } - getGateway() { var self = this; return new Promise(function (resolve, reject) { From b1f2ed64d39cb39b352e1758e936d4cbef80de5f Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 15:36:51 +0100 Subject: [PATCH 104/151] Added start/stop typing listeners --- lib/Client.js | 25 +++++++++++++++++++++++++ src/Client.js | 25 +++++++++++++++++++++++++ test/bot.1.js | 7 +++++++ 3 files changed, 57 insertions(+) diff --git a/lib/Client.js b/lib/Client.js index 8632319cc..526ea0d77 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -64,6 +64,7 @@ var Client = (function () { this.pmChannelCache = []; this.readyTime = null; this.checkingQueue = {}; + this.userTypingListener = {}; this.queue = {}; this.__idleTime = null; @@ -1115,6 +1116,30 @@ var Client = (function () { break; + case "TYPING_START": + + var userInCache = self.getUser("id", data.user_id); + var channelInCache = self.getChannel("id", data.channel_id); + + if (!self.userTypingListener[data.user_id] || self.userTypingListener[data.user_id] === -1) { + self.trigger("startTyping", userInCache, channelInCache); + } + + self.userTypingListener[data.user_id] = Date.now(); + + setTimeout(function () { + if (self.userTypingListener[data.user_id] === -1) { + return; + } + if (Date.now() - self.userTypingListener[data.user_id] > 6000) { + // stopped typing + self.trigger("stopTyping", userInCache, channelInCache); + self.userTypingListener[data.user_id] = -1; + } + }, 6000); + + break; + default: self.debug("received unknown packet"); self.trigger("unknown", dat); diff --git a/src/Client.js b/src/Client.js index dcccddaa0..6dd6c0fd9 100644 --- a/src/Client.js +++ b/src/Client.js @@ -54,6 +54,7 @@ class Client { this.pmChannelCache = []; this.readyTime = null; this.checkingQueue = {}; + this.userTypingListener = {}; this.queue = {}; this.__idleTime = null; @@ -1023,6 +1024,30 @@ class Client { } break; + + case "TYPING_START": + + var userInCache = self.getUser("id", data.user_id); + var channelInCache = self.getChannel("id", data.channel_id); + + if(!self.userTypingListener[data.user_id] || self.userTypingListener[data.user_id] === -1){ + self.trigger("startTyping", userInCache, channelInCache); + } + + self.userTypingListener[data.user_id] = Date.now(); + + setTimeout(function(){ + if(self.userTypingListener[data.user_id] === -1){ + return; + } + if( Date.now() - self.userTypingListener[data.user_id] > 6000 ){ + // stopped typing + self.trigger("stopTyping", userInCache, channelInCache); + self.userTypingListener[data.user_id] = -1; + } + }, 6000); + + break; default: self.debug("received unknown packet"); diff --git a/test/bot.1.js b/test/bot.1.js index 2531ad78e..d1eb296a7 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -52,6 +52,13 @@ mybot.on("channelUpdate", function(oldChan, newChan){ }); +mybot.on("startTyping", function(user, channel){ + console.log("start", user); +}); +mybot.on("stopTyping", function(user, channel){ + console.log("stop", user); +}); + function dump(msg) { console.log(msg); } From a815b624a67d90c3572066f56fcc7accf4cce98b Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 15:40:16 +0100 Subject: [PATCH 105/151] 3.8.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 74c1b4766..f7bac9516 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.7.2", + "version": "3.8.0", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From 51a3cadab76b6d26cb49ce212c95767c83f3d5f9 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 15:40:42 +0100 Subject: [PATCH 106/151] Revert "3.8.0" This reverts commit a815b624a67d90c3572066f56fcc7accf4cce98b. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f7bac9516..74c1b4766 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.8.0", + "version": "3.7.2", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From 4a8261a369387d7612b3cc1b8e32579fd70d38cf Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 15:40:54 +0100 Subject: [PATCH 107/151] Revert "Revert "3.8.0"" This reverts commit 51a3cadab76b6d26cb49ce212c95767c83f3d5f9. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 74c1b4766..f7bac9516 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.7.2", + "version": "3.8.0", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From 6967f5e6493791fd24c06098744583aea8aeae7d Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 19:04:22 +0100 Subject: [PATCH 108/151] Created serverPermissions and roles array --- src/{Permissions.js => ServerPermissions.js} | 4 ++-- src/server.js | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) rename src/{Permissions.js => ServerPermissions.js} (92%) diff --git a/src/Permissions.js b/src/ServerPermissions.js similarity index 92% rename from src/Permissions.js rename to src/ServerPermissions.js index e0dc4d424..6bc64d152 100644 --- a/src/Permissions.js +++ b/src/ServerPermissions.js @@ -1,4 +1,4 @@ -class Permission { +class ServerPermissions { constructor(packedPermissions) { @@ -28,7 +28,7 @@ class Permission { this.voiceMuteMembers = getBit(22); this.voiceDeafenMembers = getBit(23); this.voiceMoveMembers = getBit(24); - this.voiceUseVoiceActivation = getBit(26); + this.voiceUseVoiceActivation = getBit(25); } diff --git a/src/server.js b/src/server.js index d0d56578c..d0bbcdb71 100644 --- a/src/server.js +++ b/src/server.js @@ -10,6 +10,8 @@ class Server { this.icon = data.icon; this.afkTimeout = data.afk_timeout; this.afkChannelId = data.afk_channel_id; + + this.roles = []; if(!data.members){ data.members = [ client.user ]; From b264b617184a188679129706fb6ce7a04b4103d4 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 19:44:08 +0100 Subject: [PATCH 109/151] Servers now manage server-wide permissions Servers now create ServerPermissions objects for roles --- lib/ServerPermissions.js | 54 ++++++++++++++++ lib/server.js | 130 ++++++++++++++++++++++++--------------- src/ServerPermissions.js | 16 +++-- src/server.js | 10 +++ test/bot.1.js | 6 +- 5 files changed, 159 insertions(+), 57 deletions(-) create mode 100644 lib/ServerPermissions.js diff --git a/lib/ServerPermissions.js b/lib/ServerPermissions.js new file mode 100644 index 000000000..9845c3895 --- /dev/null +++ b/lib/ServerPermissions.js @@ -0,0 +1,54 @@ +"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 ServerPermissions = (function () { + function ServerPermissions(data) { + _classCallCheck(this, ServerPermissions); + + var self = this; + + function getBit(x) { + return (self.packed >>> x & 1) === 1; + } + + this.packed = data.permissions; + this.name = data.name; + this.id = data.id; + + this.createInstantInvite = getBit(0); + this.banMembers = getBit(1); + this.kickMembers = getBit(2); + this.manageRoles = getBit(3); + this.manageChannels = getBit(4); + this.manageServer = getBit(5); + this.readMessages = getBit(10); + this.sendMessages = getBit(11); + this.sendTTSMessages = getBit(12); + this.manageMessages = getBit(13); + this.embedLinks = getBit(14); + this.attachFiles = getBit(15); + this.readMessageHistory = getBit(16); + this.mentionEveryone = getBit(17); + + this.voiceConnect = getBit(20); + this.voiceSpeak = getBit(21); + this.voiceMuteMembers = getBit(22); + this.voiceDeafenMembers = getBit(23); + this.voiceMoveMembers = getBit(24); + this.voiceUseVoiceActivation = getBit(25); + } + + _createClass(ServerPermissions, [{ + key: "getBit", + value: function getBit(x) { + return (this.packed >>> x & 1) === 1; + } + }]); + + return ServerPermissions; +})(); + +module.exports = ServerPermissions; \ No newline at end of file diff --git a/lib/server.js b/lib/server.js index c8758d5da..02892cb07 100644 --- a/lib/server.js +++ b/lib/server.js @@ -4,6 +4,8 @@ var _createClass = (function () { function defineProperties(target, props) { for function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +var ServerPermissions = require("./ServerPermissions.js"); + var Server = (function () { function Server(data, client) { _classCallCheck(this, Server); @@ -19,25 +21,17 @@ var Server = (function () { this.afkTimeout = data.afk_timeout; this.afkChannelId = data.afk_channel_id; - if (!data.members) { - data.members = [client.user]; - return; - } + this.roles = []; var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { - for (var _iterator = data.members[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var member = _step.value; + for (var _iterator = data.roles[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var permissionGroup = _step.value; - // first we cache the user in our Discord Client, - // then we add it to our list. This way when we - // get a user from this server's member list, - // it will be identical (unless an async change occurred) - // to the client's cache. - if (member.user) this.members.push(client.addUser(member.user)); + this.roles.push(new ServerPermissions(permissionGroup)); } } catch (err) { _didIteratorError = true; @@ -53,6 +47,41 @@ var Server = (function () { } } } + + if (!data.members) { + data.members = [client.user]; + return; + } + + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = data.members[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var member = _step2.value; + + // first we cache the user in our Discord Client, + // then we add it to our list. This way when we + // get a user from this server's member list, + // it will be identical (unless an async change occurred) + // to the client's cache. + if (member.user) this.members.push(client.addUser(member.user)); + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2["return"]) { + _iterator2["return"](); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } } _createClass(Server, [{ @@ -60,48 +89,16 @@ var Server = (function () { // get/set value: function getChannel(key, value) { - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; - - try { - for (var _iterator2 = this.channels[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var channel = _step2.value; - - if (channel[key] === value) { - return channel; - } - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { - try { - if (!_iteratorNormalCompletion2 && _iterator2["return"]) { - _iterator2["return"](); - } - } finally { - if (_didIteratorError2) { - throw _iteratorError2; - } - } - } - - return null; - } - }, { - key: "getMember", - value: function getMember(key, value) { var _iteratorNormalCompletion3 = true; var _didIteratorError3 = false; var _iteratorError3 = undefined; try { - for (var _iterator3 = this.members[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { - var member = _step3.value; + for (var _iterator3 = this.channels[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var channel = _step3.value; - if (member[key] === value) { - return member; + if (channel[key] === value) { + return channel; } } } catch (err) { @@ -122,6 +119,38 @@ var Server = (function () { return null; } }, { + key: "getMember", + value: function getMember(key, value) { + var _iteratorNormalCompletion4 = true; + var _didIteratorError4 = false; + var _iteratorError4 = undefined; + + try { + for (var _iterator4 = this.members[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var member = _step4.value; + + if (member[key] === value) { + return member; + } + } + } catch (err) { + _didIteratorError4 = true; + _iteratorError4 = err; + } finally { + try { + if (!_iteratorNormalCompletion4 && _iterator4["return"]) { + _iterator4["return"](); + } + } finally { + if (_didIteratorError4) { + throw _iteratorError4; + } + } + } + + return null; + } + }, { key: "addChannel", value: function addChannel(chann) { if (!this.getChannel("id", chann.id)) { @@ -147,6 +176,11 @@ var Server = (function () { value: function equals(object) { return object.id === this.id; } + }, { + key: "permissionGroups", + get: function get() { + return this.roles; + } }, { key: "iconURL", get: function get() { diff --git a/src/ServerPermissions.js b/src/ServerPermissions.js index 6bc64d152..36bd3a9ca 100644 --- a/src/ServerPermissions.js +++ b/src/ServerPermissions.js @@ -1,12 +1,18 @@ class ServerPermissions { - constructor(packedPermissions) { + constructor(data) { + + var self = this; function getBit(x) { - return ((this.packed >>> x) & 1) === 1; + return ((self.packed >>> x) & 1) === 1; } - this.packed = packedPermissions; + this.packed = data.permissions; + this.name = data.name; + this.id = data.id; + + this.createInstantInvite = getBit(0); this.banMembers = getBit(1); @@ -35,4 +41,6 @@ class ServerPermissions { getBit(x) { return ((this.packed >>> x) & 1) === 1; } -} \ No newline at end of file +} + +module.exports = ServerPermissions; \ No newline at end of file diff --git a/src/server.js b/src/server.js index d0bbcdb71..2269bbafd 100644 --- a/src/server.js +++ b/src/server.js @@ -1,3 +1,5 @@ +var ServerPermissions = require("./ServerPermissions.js"); + class Server { constructor(data, client) { this.client = client; @@ -12,6 +14,10 @@ class Server { this.afkChannelId = data.afk_channel_id; this.roles = []; + + for(var permissionGroup of data.roles){ + this.roles.push( new ServerPermissions(permissionGroup) ); + } if(!data.members){ data.members = [ client.user ]; @@ -30,6 +36,10 @@ class Server { } } + + get permissionGroups(){ + return this.roles; + } get iconURL() { if (!this.icon) diff --git a/test/bot.1.js b/test/bot.1.js index d1eb296a7..b464f1339 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -19,11 +19,7 @@ mybot.on("message", function (message) { // we can go ahead :) - var onlineUsers = 0; - - counter++; - - mybot.playingGame( "Minecraft" ); + mybot.reply(message, "\n\n"+JSON.stringify(message.channel.server.roles)); }); From 8358eadcbd6e815a7af4b1042f662cf205dfa97f Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 19:57:07 +0100 Subject: [PATCH 110/151] User class able to support member extension --- lib/user.js | 2 +- src/Member.js | 3 --- src/user.js | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/user.js b/lib/user.js index 5e38e132e..9a3d64c88 100644 --- a/lib/user.js +++ b/lib/user.js @@ -12,7 +12,7 @@ var User = (function () { this.discriminator = data.discriminator; this.id = data.id; this.avatar = data.avatar; - this.status = "offline"; + this.status = data.status || "offline"; } // access using user.avatarURL; diff --git a/src/Member.js b/src/Member.js index 3fa49ebd6..d0ab27774 100644 --- a/src/Member.js +++ b/src/Member.js @@ -4,9 +4,6 @@ class Member extends User{ constructor(data){ super(data); - - - } } \ No newline at end of file diff --git a/src/user.js b/src/user.js index 73eef604f..9686fed27 100644 --- a/src/user.js +++ b/src/user.js @@ -4,7 +4,7 @@ class User{ this.discriminator = data.discriminator; this.id = data.id; this.avatar = data.avatar; - this.status = "offline"; + this.status = data.status || "offline"; } // access using user.avatarURL; From ad286b9081f2e7041cbf13ca0bd9753949bc99fe Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 20:00:44 +0100 Subject: [PATCH 111/151] Updated member class, server now creates members --- lib/Member.js | 18 ++++- lib/server.js | 218 +------------------------------------------------- src/Member.js | 13 ++- src/server.js | 10 ++- 4 files changed, 32 insertions(+), 227 deletions(-) diff --git a/lib/Member.js b/lib/Member.js index 7d7b03f1a..a60a3d2b4 100644 --- a/lib/Member.js +++ b/lib/Member.js @@ -1,5 +1,7 @@ "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; }; })(); + var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -11,11 +13,21 @@ var User = require("./user.js"); var Member = (function (_User) { _inherits(Member, _User); - function Member(data) { + function Member(user, server) { _classCallCheck(this, Member); - _get(Object.getPrototypeOf(Member.prototype), "constructor", this).call(this, data); + _get(Object.getPrototypeOf(Member.prototype), "constructor", this).call(this, user); // should work, we are basically creating a Member that has the same properties as user and a few more + this.server = server; } + _createClass(Member, [{ + key: "roles", + get: function get() { + return []; + } + }]); + return Member; -})(User); \ No newline at end of file +})(User); + +module.exports = Member; \ No newline at end of file diff --git a/lib/server.js b/lib/server.js index 02892cb07..9a390c31f 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1,217 +1 @@ -"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 ServerPermissions = require("./ServerPermissions.js"); - -var Server = (function () { - function Server(data, client) { - _classCallCheck(this, Server); - - this.client = client; - this.region = data.region; - this.ownerID = data.owner_id; - this.name = data.name; - this.id = data.id; - this.members = []; - this.channels = []; - this.icon = data.icon; - this.afkTimeout = data.afk_timeout; - this.afkChannelId = data.afk_channel_id; - - this.roles = []; - - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = data.roles[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var permissionGroup = _step.value; - - this.roles.push(new ServerPermissions(permissionGroup)); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - - if (!data.members) { - data.members = [client.user]; - return; - } - - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; - - try { - for (var _iterator2 = data.members[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var member = _step2.value; - - // first we cache the user in our Discord Client, - // then we add it to our list. This way when we - // get a user from this server's member list, - // it will be identical (unless an async change occurred) - // to the client's cache. - if (member.user) this.members.push(client.addUser(member.user)); - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { - try { - if (!_iteratorNormalCompletion2 && _iterator2["return"]) { - _iterator2["return"](); - } - } finally { - if (_didIteratorError2) { - throw _iteratorError2; - } - } - } - } - - _createClass(Server, [{ - key: "getChannel", - - // get/set - value: function getChannel(key, value) { - var _iteratorNormalCompletion3 = true; - var _didIteratorError3 = false; - var _iteratorError3 = undefined; - - try { - for (var _iterator3 = this.channels[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { - var channel = _step3.value; - - if (channel[key] === value) { - return channel; - } - } - } catch (err) { - _didIteratorError3 = true; - _iteratorError3 = err; - } finally { - try { - if (!_iteratorNormalCompletion3 && _iterator3["return"]) { - _iterator3["return"](); - } - } finally { - if (_didIteratorError3) { - throw _iteratorError3; - } - } - } - - return null; - } - }, { - key: "getMember", - value: function getMember(key, value) { - var _iteratorNormalCompletion4 = true; - var _didIteratorError4 = false; - var _iteratorError4 = undefined; - - try { - for (var _iterator4 = this.members[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { - var member = _step4.value; - - if (member[key] === value) { - return member; - } - } - } catch (err) { - _didIteratorError4 = true; - _iteratorError4 = err; - } finally { - try { - if (!_iteratorNormalCompletion4 && _iterator4["return"]) { - _iterator4["return"](); - } - } finally { - if (_didIteratorError4) { - throw _iteratorError4; - } - } - } - - return null; - } - }, { - key: "addChannel", - value: function addChannel(chann) { - if (!this.getChannel("id", chann.id)) { - this.channels.push(chann); - } - return chann; - } - }, { - key: "addMember", - value: function addMember(member) { - if (!this.getMember("id", member.id)) { - this.members.push(member); - } - return member; - } - }, { - key: "toString", - value: function toString() { - return this.name; - } - }, { - key: "equals", - value: function equals(object) { - return object.id === this.id; - } - }, { - key: "permissionGroups", - get: function get() { - return this.roles; - } - }, { - key: "iconURL", - get: function get() { - if (!this.icon) return null; - return "https://discordapp.com/api/guilds/" + this.id + "/icons/" + this.icon + ".jpg"; - } - }, { - key: "afkChannel", - get: function get() { - if (!this.afkChannelId) return false; - - return this.getChannel("id", this.afkChannelId); - } - }, { - key: "defaultChannel", - get: function get() { - return this.getChannel("name", "general"); - } - }, { - key: "owner", - get: function get() { - return this.client.getUser("id", this.ownerID); - } - }, { - key: "users", - get: function get() { - return this.members; - } - }]); - - return Server; -})(); - -module.exports = Server; \ No newline at end of file +"use strict"; \ No newline at end of file diff --git a/src/Member.js b/src/Member.js index d0ab27774..afa65cc57 100644 --- a/src/Member.js +++ b/src/Member.js @@ -2,8 +2,15 @@ var User = require("./user.js"); class Member extends User{ - constructor(data){ - super(data); + constructor(user, server){ + super(user); // should work, we are basically creating a Member that has the same properties as user and a few more + this.server = server; } -} \ No newline at end of file + get roles(){ + return []; + } + +} + +module.exports = Member; \ No newline at end of file diff --git a/src/server.js b/src/server.js index 2269bbafd..9f0d63f54 100644 --- a/src/server.js +++ b/src/server.js @@ -1,4 +1,5 @@ var ServerPermissions = require("./ServerPermissions.js"); +var Member = require("./Member.js"); class Server { constructor(data, client) { @@ -94,11 +95,12 @@ class Server { return chann; } - addMember(member){ - if (!this.getMember("id", member.id)){ - this.members.push(member); + addMember(user){ + if (!this.getMember("id", user.id)){ + var mem = new Member(user, this); + this.members.push(mem); } - return member; + return mem; } toString(){ From a10f19a7a7feb61977632d59350b95a927ab36be Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 20:01:21 +0100 Subject: [PATCH 112/151] Reformat code --- src/Client.js | 252 +++++++++++++++++++++++++------------------------- 1 file changed, 126 insertions(+), 126 deletions(-) diff --git a/src/Client.js b/src/Client.js index 6dd6c0fd9..470791ffe 100644 --- a/src/Client.js +++ b/src/Client.js @@ -56,7 +56,7 @@ class Client { this.checkingQueue = {}; this.userTypingListener = {}; this.queue = {}; - + this.__idleTime = null; this.__gameId = null; } @@ -399,15 +399,15 @@ class Client { function remove() { request - .del(`${Endpoints.CHANNELS}/${message.channel.id}/messages/${message.id}`) - .set("authorization", self.token) - .end(function (err, res) { - if(err){ - bad(); - }else{ - good(); - } - }); + .del(`${Endpoints.CHANNELS}/${message.channel.id}/messages/${message.id}`) + .set("authorization", self.token) + .end(function (err, res) { + if (err) { + bad(); + } else { + good(); + } + }); } function good() { @@ -420,7 +420,7 @@ class Client { reject(err); } }); - + } updateMessage(message, content, callback = function (err, msg) { }) { @@ -757,7 +757,7 @@ class Client { self.trigger("error", err, e); return; } - + self.trigger("raw", dat); //valid message @@ -1007,46 +1007,46 @@ class Client { } break; - + case "CHANNEL_UPDATE": - + var channelInCache = self.getChannel("id", data.id), serverInCache = self.getServer("id", data.guild_id); - - if(channelInCache && serverInCache){ - + + if (channelInCache && serverInCache) { + var newChann = new Channel(data, serverInCache); newChann.messages = channelInCache.messages; - + self.trigger("channelUpdate", channelInCache, newChann); - - self.channelCache[ self.channelCache.indexOf(channelInCache) ] = newChann; + + self.channelCache[self.channelCache.indexOf(channelInCache)] = newChann; } - + break; - + case "TYPING_START": - + var userInCache = self.getUser("id", data.user_id); var channelInCache = self.getChannel("id", data.channel_id); - - if(!self.userTypingListener[data.user_id] || self.userTypingListener[data.user_id] === -1){ + + if (!self.userTypingListener[data.user_id] || self.userTypingListener[data.user_id] === -1) { self.trigger("startTyping", userInCache, channelInCache); } - + self.userTypingListener[data.user_id] = Date.now(); - - setTimeout(function(){ - if(self.userTypingListener[data.user_id] === -1){ + + setTimeout(function () { + if (self.userTypingListener[data.user_id] === -1) { return; } - if( Date.now() - self.userTypingListener[data.user_id] > 6000 ){ + if (Date.now() - self.userTypingListener[data.user_id] > 6000) { // stopped typing self.trigger("stopTyping", userInCache, channelInCache); self.userTypingListener[data.user_id] = -1; } }, 6000); - + break; default: @@ -1082,45 +1082,45 @@ class Client { } return this.getPMChannel("id", data.id); } - - setTopic(channel, topic, callback = function(err){}){ - + + setTopic(channel, topic, callback = function (err) { }) { + var self = this; - - return new Promise(function(resolve, reject){ - + + return new Promise(function (resolve, reject) { + self.resolveDestination(channel).then(next).catch(error); - - function error(e){ + + function error(e) { callback(e); reject(e); } - - function next(destination){ - + + function next(destination) { + var asChan = self.getChannel("id", destination); - + request .patch(`${Endpoints.CHANNELS}/${destination}`) .set("authorization", self.token) .send({ - name : asChan.name, - position : 0, - topic : topic + name: asChan.name, + position: 0, + topic: topic }) - .end(function(err, res){ - if(err){ + .end(function (err, res) { + if (err) { error(err); - }else{ + } else { asChan.topic = res.body.topic; resolve(); callback(); } - }); + }); } - + }); - + } //def addServer @@ -1129,7 +1129,7 @@ class Client { var self = this; var server = this.getServer("id", data.id); - if(data.unavailable){ + if (data.unavailable) { self.trigger("unavailable", data); self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached."); return; @@ -1144,8 +1144,8 @@ class Client { } } } - - for(var presence of data.presences){ + + for (var presence of data.presences) { self.getUser("id", presence.user.id).status = presence.status; } @@ -1370,132 +1370,132 @@ class Client { }); }); } - - setStatusIdle(){ + + setStatusIdle() { this.setStatus("idle"); } - - setStatusOnline(){ + + setStatusOnline() { this.setStatus("online"); } - - setStatusActive(){ + + setStatusActive() { this.setStatusOnline(); } - - setStatusHere(){ + + setStatusHere() { this.setStatusOnline(); } - - setStatusAway(){ + + setStatusAway() { this.setStatusIdle(); } - - startTyping(chann, stopTypeTime){ + + startTyping(chann, stopTypeTime) { var self = this; - + this.resolveDestination(chann).then(next); - - function next(channel){ - if(self.typingIntervals[channel]){ + + function next(channel) { + if (self.typingIntervals[channel]) { return; } - - var fn = function(){ + + var fn = function () { request - .post(`${Endpoints.CHANNELS}/${channel}/typing`) - .set("authorization", self.token) - .end(); + .post(`${Endpoints.CHANNELS}/${channel}/typing`) + .set("authorization", self.token) + .end(); }; - + fn(); - + var interval = setInterval(fn, 3000); - + self.typingIntervals[channel] = interval; - - if(stopTypeTime){ - setTimeout(function(){ + + if (stopTypeTime) { + setTimeout(function () { self.stopTyping(channel); }, stopTypeTime); } } } - - stopTyping(chann){ + + stopTyping(chann) { var self = this; - + this.resolveDestination(chann).then(next); - - function next(channel){ - if(!self.typingIntervals[channel]){ + + function next(channel) { + if (!self.typingIntervals[channel]) { return; } - + clearInterval(self.typingIntervals[channel]); - + delete self.typingIntervals[channel]; - + } } - - setStatus(stat){ - + + setStatus(stat) { + var idleTime = (stat === "online" ? null : Date.now()); - + this.__idleTime = idleTime; - + this.websocket.send(JSON.stringify({ - op : 3, - d : { - idle_since : this.__idleTime, - game_id : this.__gameId + op: 3, + d: { + idle_since: this.__idleTime, + game_id: this.__gameId } })); } - - setPlayingGame(id){ - - if( id instanceof String || typeof id === `string` ){ + + setPlayingGame(id) { + + if (id instanceof String || typeof id === `string`) { // working on names var gid = id.trim().toUpperCase(); - + id = null; - - for( var game of gameMap ){ - - if(game.name.trim().toUpperCase() === gid){ - + + for (var game of gameMap) { + + if (game.name.trim().toUpperCase() === gid) { + id = game.id; break; - + } - + } - + } - + this.__gameId = id; - + this.websocket.send(JSON.stringify({ - op : 3, - d : { - idle_since : this.__idleTime, - game_id : this.__gameId + op: 3, + d: { + idle_since: this.__idleTime, + game_id: this.__gameId } })); - + } - - playGame(id){ + + playGame(id) { this.setPlayingGame(id); } - - playingGame(id){ - + + playingGame(id) { + this.setPlayingGame(id); - + } } From 4e117b85d9a91f72649655d475b5f1a85be82055 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 20:18:49 +0100 Subject: [PATCH 113/151] Member role *should* be used properly across the API The Client now SHOULD add roles properly to members, as they leave it up to the Server class. --- lib/Client.js | 10 +- lib/Member.js | 33 +++++- lib/message.js | 2 +- lib/server.js | 286 ++++++++++++++++++++++++++++++++++++++++++++++++- src/Client.js | 12 +-- src/Member.js | 13 ++- src/message.js | 2 +- src/server.js | 28 ++++- test/bot.1.js | 2 +- 9 files changed, 360 insertions(+), 28 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 526ea0d77..e22cac6c8 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1031,11 +1031,7 @@ var Client = (function () { var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. - if (! ~server.members.indexOf(user)) { - server.members.push(user); - } - - self.trigger("serverNewMember", user, server); + self.trigger("serverNewMember", server.addMember(user, data.roles), server); } break; @@ -1048,9 +1044,7 @@ var Client = (function () { var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. - if (~server.members.indexOf(user)) { - server.members.splice(server.members.indexOf(user), 1); - } + server.removeMember("id", user.id); self.trigger("serverRemoveMember", user, server); } diff --git a/lib/Member.js b/lib/Member.js index a60a3d2b4..ea9b35a07 100644 --- a/lib/Member.js +++ b/lib/Member.js @@ -13,17 +13,46 @@ var User = require("./user.js"); var Member = (function (_User) { _inherits(Member, _User); - function Member(user, server) { + function Member(user, server, roles) { _classCallCheck(this, Member); _get(Object.getPrototypeOf(Member.prototype), "constructor", this).call(this, user); // should work, we are basically creating a Member that has the same properties as user and a few more this.server = server; + this.rawRoles = roles; } _createClass(Member, [{ key: "roles", get: function get() { - return []; + + var ufRoles = []; + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.rawRoles[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var rawRole = _step.value; + + ufRoles.push(this.server.getRole(rawRole)); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return ufRoles; } }]); diff --git a/lib/message.js b/lib/message.js index 3dd4ddcae..2e2ddd69d 100644 --- a/lib/message.js +++ b/lib/message.js @@ -20,7 +20,7 @@ var Message = (function () { this.editedTimestamp = data.edited_timestamp; this.content = data.content.trim(); this.channel = channel; - this.author = author; + this.author = this.channel.server.getMember("id", author.id); this.attachments = data.attachments; } diff --git a/lib/server.js b/lib/server.js index 9a390c31f..440b2a3f3 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1 +1,285 @@ -"use strict"; \ No newline at end of file +"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 ServerPermissions = require("./ServerPermissions.js"); +var Member = require("./Member.js"); + +var Server = (function () { + function Server(data, client) { + _classCallCheck(this, Server); + + this.client = client; + this.region = data.region; + this.ownerID = data.owner_id; + this.name = data.name; + this.id = data.id; + this.members = []; + this.channels = []; + this.icon = data.icon; + this.afkTimeout = data.afk_timeout; + this.afkChannelId = data.afk_channel_id; + + this.roles = []; + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = data.roles[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var permissionGroup = _step.value; + + this.roles.push(new ServerPermissions(permissionGroup)); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + if (!data.members) { + data.members = [client.user]; + return; + } + + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = data.members[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var member = _step2.value; + + // first we cache the user in our Discord Client, + // then we add it to our list. This way when we + // get a user from this server's member list, + // it will be identical (unless an async change occurred) + // to the client's cache. + if (member.user) this.addMember(client.addUser(member.user), member.roles); + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2["return"]) { + _iterator2["return"](); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + } + + _createClass(Server, [{ + key: "getRole", + + // get/set + + value: function getRole(id) { + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = this.roles[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var role = _step3.value; + + if (role.id === id) { + return role; + } + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3["return"]) { + _iterator3["return"](); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + + return null; + } + }, { + key: "getChannel", + value: function getChannel(key, value) { + var _iteratorNormalCompletion4 = true; + var _didIteratorError4 = false; + var _iteratorError4 = undefined; + + try { + for (var _iterator4 = this.channels[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var channel = _step4.value; + + if (channel[key] === value) { + return channel; + } + } + } catch (err) { + _didIteratorError4 = true; + _iteratorError4 = err; + } finally { + try { + if (!_iteratorNormalCompletion4 && _iterator4["return"]) { + _iterator4["return"](); + } + } finally { + if (_didIteratorError4) { + throw _iteratorError4; + } + } + } + + return null; + } + }, { + key: "getMember", + value: function getMember(key, value) { + var _iteratorNormalCompletion5 = true; + var _didIteratorError5 = false; + var _iteratorError5 = undefined; + + try { + for (var _iterator5 = this.members[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { + var member = _step5.value; + + if (member[key] === value) { + return member; + } + } + } catch (err) { + _didIteratorError5 = true; + _iteratorError5 = err; + } finally { + try { + if (!_iteratorNormalCompletion5 && _iterator5["return"]) { + _iterator5["return"](); + } + } finally { + if (_didIteratorError5) { + throw _iteratorError5; + } + } + } + + return null; + } + }, { + key: "removeMember", + value: function removeMember(key, value) { + var _iteratorNormalCompletion6 = true; + var _didIteratorError6 = false; + var _iteratorError6 = undefined; + + try { + for (var _iterator6 = this.members[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { + var member = _step6.value; + + if (member[key] === value) { + this.members.splice(key, 1); + return member; + } + } + } catch (err) { + _didIteratorError6 = true; + _iteratorError6 = err; + } finally { + try { + if (!_iteratorNormalCompletion6 && _iterator6["return"]) { + _iterator6["return"](); + } + } finally { + if (_didIteratorError6) { + throw _iteratorError6; + } + } + } + + return false; + } + }, { + key: "addChannel", + value: function addChannel(chann) { + if (!this.getChannel("id", chann.id)) { + this.channels.push(chann); + } + return chann; + } + }, { + key: "addMember", + value: function addMember(user, roles) { + if (!this.getMember("id", user.id)) { + var mem = new Member(user, this, roles); + this.members.push(mem); + } + return mem; + } + }, { + key: "toString", + value: function toString() { + return this.name; + } + }, { + key: "equals", + value: function equals(object) { + return object.id === this.id; + } + }, { + key: "permissionGroups", + get: function get() { + return this.roles; + } + }, { + key: "iconURL", + get: function get() { + if (!this.icon) return null; + return "https://discordapp.com/api/guilds/" + this.id + "/icons/" + this.icon + ".jpg"; + } + }, { + key: "afkChannel", + get: function get() { + if (!this.afkChannelId) return false; + + return this.getChannel("id", this.afkChannelId); + } + }, { + key: "defaultChannel", + get: function get() { + return this.getChannel("name", "general"); + } + }, { + key: "owner", + get: function get() { + return this.client.getUser("id", this.ownerID); + } + }, { + key: "users", + get: function get() { + return this.members; + } + }]); + + return Server; +})(); + +module.exports = Server; \ No newline at end of file diff --git a/src/Client.js b/src/Client.js index 470791ffe..e8560d457 100644 --- a/src/Client.js +++ b/src/Client.js @@ -938,12 +938,8 @@ class Client { if (server) { var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. - - if (!~server.members.indexOf(user)) { - server.members.push(user); - } - self.trigger("serverNewMember", user, server); + self.trigger("serverNewMember", server.addMember(user, data.roles), server); } break; @@ -956,10 +952,8 @@ class Client { var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. - if (~server.members.indexOf(user)) { - server.members.splice(server.members.indexOf(user), 1); - } - + server.removeMember("id", user.id); + self.trigger("serverRemoveMember", user, server); } diff --git a/src/Member.js b/src/Member.js index afa65cc57..4750b7ada 100644 --- a/src/Member.js +++ b/src/Member.js @@ -2,13 +2,22 @@ var User = require("./user.js"); class Member extends User{ - constructor(user, server){ + constructor(user, server, roles){ super(user); // should work, we are basically creating a Member that has the same properties as user and a few more this.server = server; + this.rawRoles = roles; } get roles(){ - return []; + + var ufRoles = []; + + for(var rawRole of this.rawRoles){ + ufRoles.push( this.server.getRole(rawRole) ); + } + + return ufRoles; + } } diff --git a/src/message.js b/src/message.js index 3462ce88c..1cbc8be7e 100644 --- a/src/message.js +++ b/src/message.js @@ -12,7 +12,7 @@ class Message{ this.editedTimestamp = data.edited_timestamp; this.content = data.content.trim(); this.channel = channel; - this.author = author; + this.author = this.channel.server.getMember("id", author.id); this.attachments = data.attachments; } diff --git a/src/server.js b/src/server.js index 9f0d63f54..7e7a4d09e 100644 --- a/src/server.js +++ b/src/server.js @@ -33,7 +33,7 @@ class Server { // it will be identical (unless an async change occurred) // to the client's cache. if(member.user) - this.members.push(client.addUser(member.user)); + this.addMember(client.addUser(member.user), member.roles); } } @@ -68,6 +68,17 @@ class Server { } // get/set + + getRole(id){ + for (var role of this.roles) { + if (role.id === id) { + return role; + } + } + + return null; + } + getChannel(key, value) { for (var channel of this.channels) { if (channel[key] === value) { @@ -88,6 +99,17 @@ class Server { return null; } + removeMember(key, value){ + for (var member of this.members) { + if (member[key] === value) { + this.members.splice(key, 1); + return member; + } + } + + return false; + } + addChannel(chann) { if (!this.getChannel("id", chann.id)) { this.channels.push(chann); @@ -95,9 +117,9 @@ class Server { return chann; } - addMember(user){ + addMember(user, roles){ if (!this.getMember("id", user.id)){ - var mem = new Member(user, this); + var mem = new Member(user, this, roles); this.members.push(mem); } return mem; diff --git a/test/bot.1.js b/test/bot.1.js index b464f1339..88275fd1b 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -19,7 +19,7 @@ mybot.on("message", function (message) { // we can go ahead :) - mybot.reply(message, "\n\n"+JSON.stringify(message.channel.server.roles)); + mybot.reply(message, message.sender.roles); }); From 3869f584b68911d2adc85959face7d7ec9dd0a7a Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 20:30:53 +0100 Subject: [PATCH 114/151] added toString to ServerPermissions --- lib/ServerPermissions.js | 5 +++++ src/ServerPermissions.js | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/ServerPermissions.js b/lib/ServerPermissions.js index 9845c3895..66411f542 100644 --- a/lib/ServerPermissions.js +++ b/lib/ServerPermissions.js @@ -46,6 +46,11 @@ var ServerPermissions = (function () { value: function getBit(x) { return (this.packed >>> x & 1) === 1; } + }, { + key: "toString", + value: function toString() { + return this.name; + } }]); return ServerPermissions; diff --git a/src/ServerPermissions.js b/src/ServerPermissions.js index 36bd3a9ca..dc0a3c9ce 100644 --- a/src/ServerPermissions.js +++ b/src/ServerPermissions.js @@ -12,8 +12,6 @@ class ServerPermissions { this.name = data.name; this.id = data.id; - - this.createInstantInvite = getBit(0); this.banMembers = getBit(1); this.kickMembers = getBit(2); @@ -41,6 +39,10 @@ class ServerPermissions { getBit(x) { return ((this.packed >>> x) & 1) === 1; } + + toString(){ + return this.name; + } } module.exports = ServerPermissions; \ No newline at end of file From e046467d926a66b357d868a41dc25ec393f92564 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 20:33:36 +0100 Subject: [PATCH 115/151] Added permissions directive --- lib/server.js | 5 +++++ src/server.js | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/lib/server.js b/lib/server.js index 440b2a3f3..c9feaa0a3 100644 --- a/lib/server.js +++ b/lib/server.js @@ -249,6 +249,11 @@ var Server = (function () { get: function get() { return this.roles; } + }, { + key: "permissions", + get: function get() { + return this.roles; + } }, { key: "iconURL", get: function get() { diff --git a/src/server.js b/src/server.js index 7e7a4d09e..d2a1bf411 100644 --- a/src/server.js +++ b/src/server.js @@ -41,6 +41,10 @@ class Server { get permissionGroups(){ return this.roles; } + + get permissions(){ + return this.roles; + } get iconURL() { if (!this.icon) From 6d36977f9433f432b319331d651ec975ae9e2365 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 20:34:24 +0100 Subject: [PATCH 116/151] Preparing Channel class for overwrite capability --- lib/channel.js | 11 +++++++++++ src/channel.js | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/channel.js b/lib/channel.js index bb67fcf4f..1edec0f84 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -14,6 +14,7 @@ var Channel = (function () { this.topic = data.topic; this.id = data.id; this.messages = []; + this.roles = []; //this.isPrivate = isPrivate; //not sure about the implementation of this... } @@ -73,6 +74,16 @@ var Channel = (function () { value: function toString() { return "<#" + this.id + ">"; } + }, { + key: "permissionOverwrites", + get: function get() { + return this.roles; + } + }, { + key: "permissions", + get: function get() { + return this.roles; + } }, { key: "client", get: function get() { diff --git a/src/channel.js b/src/channel.js index a7185e17f..939b01e7c 100644 --- a/src/channel.js +++ b/src/channel.js @@ -7,8 +7,17 @@ class Channel { this.topic = data.topic; this.id = data.id; this.messages = []; + this.roles = []; //this.isPrivate = isPrivate; //not sure about the implementation of this... } + + get permissionOverwrites(){ + return this.roles; + } + + get permissions(){ + return this.roles; + } get client() { return this.server.client; From 6b091128cb01825d0b03a72606da6fbbf1c69151 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 20:36:32 +0100 Subject: [PATCH 117/151] Created ChannelPermissions class --- lib/ChannelPermissions.js | 9 +++++ lib/channel.js | 52 ++++++++++++++++++++------- src/ChannelPermissions.js | 7 ++++ src/channel.js | 75 ++++++++++++++++++++++----------------- 4 files changed, 98 insertions(+), 45 deletions(-) create mode 100644 lib/ChannelPermissions.js create mode 100644 src/ChannelPermissions.js diff --git a/lib/ChannelPermissions.js b/lib/ChannelPermissions.js new file mode 100644 index 000000000..2fcc61792 --- /dev/null +++ b/lib/ChannelPermissions.js @@ -0,0 +1,9 @@ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var ChannelPermissions = function ChannelPermissions(data) { + _classCallCheck(this, ChannelPermissions); +}; + +module.exports = ChannelPermissions; \ No newline at end of file diff --git a/lib/channel.js b/lib/channel.js index 1edec0f84..cfa397ccd 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -4,6 +4,8 @@ var _createClass = (function () { function defineProperties(target, props) { for function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +var ChannelPermissions = require("./ChannelPermissions.js"); + var Channel = (function () { function Channel(data, server) { _classCallCheck(this, Channel); @@ -15,7 +17,33 @@ var Channel = (function () { this.id = data.id; this.messages = []; this.roles = []; - //this.isPrivate = isPrivate; //not sure about the implementation of this... + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = data.permission_overwrites[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var role = _step.value; + + this.roles.push(new ChannelPermissions()); + } + + //this.isPrivate = isPrivate; //not sure about the implementation of this... + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } } _createClass(Channel, [{ @@ -40,29 +68,29 @@ var Channel = (function () { }, { key: "getMessage", value: function getMessage(key, value) { - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; try { - for (var _iterator = this.messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var message = _step.value; + for (var _iterator2 = this.messages[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var message = _step2.value; if (message[key] === value) { return message; } } } catch (err) { - _didIteratorError = true; - _iteratorError = err; + _didIteratorError2 = true; + _iteratorError2 = err; } finally { try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); + if (!_iteratorNormalCompletion2 && _iterator2["return"]) { + _iterator2["return"](); } } finally { - if (_didIteratorError) { - throw _iteratorError; + if (_didIteratorError2) { + throw _iteratorError2; } } } diff --git a/src/ChannelPermissions.js b/src/ChannelPermissions.js new file mode 100644 index 000000000..13e29c02f --- /dev/null +++ b/src/ChannelPermissions.js @@ -0,0 +1,7 @@ +class ChannelPermissions{ + constructor(data){ + + } +} + +module.exports = ChannelPermissions; \ No newline at end of file diff --git a/src/channel.js b/src/channel.js index 939b01e7c..bf9380d28 100644 --- a/src/channel.js +++ b/src/channel.js @@ -1,3 +1,5 @@ +var ChannelPermissions = require("./ChannelPermissions.js"); + class Channel { constructor(data, server) { @@ -8,14 +10,21 @@ class Channel { this.id = data.id; this.messages = []; this.roles = []; + + for (var role of data.permission_overwrites) { + + this.roles.push( new ChannelPermissions() ); + + } + //this.isPrivate = isPrivate; //not sure about the implementation of this... } - - get permissionOverwrites(){ + + get permissionOverwrites() { return this.roles; } - - get permissions(){ + + get permissions() { return this.roles; } @@ -26,42 +35,42 @@ class Channel { equals(object) { return (object && object.id === this.id); } - - addMessage(data){ - - if(this.messages.length > 1000){ - this.messages.splice(0,1); - } - - if(!this.getMessage("id", data.id)){ - this.messages.push(data); - } - - return this.getMessage("id", data.id); - } - - getMessage(key, value){ - for(var message of this.messages){ - if(message[key] === value){ - return message; - } - } - return null; - } - toString(){ + addMessage(data) { + + if (this.messages.length > 1000) { + this.messages.splice(0, 1); + } + + if (!this.getMessage("id", data.id)) { + this.messages.push(data); + } + + return this.getMessage("id", data.id); + } + + getMessage(key, value) { + for (var message of this.messages) { + if (message[key] === value) { + return message; + } + } + return null; + } + + toString() { return "<#" + this.id + ">"; } - - get isPrivate(){ + + get isPrivate() { return false; } - - get users(){ + + get users() { return this.server.members; } - - get members(){ + + get members() { return this.server.members; } } From 2ededd61dde5727ad1ba026352bbe8668347142e Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 20:45:04 +0100 Subject: [PATCH 118/151] ChannelPermissions works generically --- src/ChannelPermissions.js | 8 ++++++++ src/channel.js | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ChannelPermissions.js b/src/ChannelPermissions.js index 13e29c02f..83b562f71 100644 --- a/src/ChannelPermissions.js +++ b/src/ChannelPermissions.js @@ -1,6 +1,14 @@ class ChannelPermissions{ constructor(data){ + this.type = data.type; //either member or role + + this.id = data.id; + + this.deny = data.deny; + + this.allow = data.allow; + } } diff --git a/src/channel.js b/src/channel.js index bf9380d28..64c9f22f0 100644 --- a/src/channel.js +++ b/src/channel.js @@ -13,7 +13,7 @@ class Channel { for (var role of data.permission_overwrites) { - this.roles.push( new ChannelPermissions() ); + this.roles.push( new ChannelPermissions(role) ); } From cd91a384bd7150910d0c0342fc9313151563ed48 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 21:10:43 +0100 Subject: [PATCH 119/151] added getBit to channelpermissions --- src/ChannelPermissions.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ChannelPermissions.js b/src/ChannelPermissions.js index 83b562f71..13f183867 100644 --- a/src/ChannelPermissions.js +++ b/src/ChannelPermissions.js @@ -1,6 +1,10 @@ class ChannelPermissions{ constructor(data){ + function getBit(x) { + return ((this.packed >>> x) & 1) === 1; + } + this.type = data.type; //either member or role this.id = data.id; @@ -10,6 +14,10 @@ class ChannelPermissions{ this.allow = data.allow; } + + getBit(x) { + return ((this.packed >>> x) & 1) === 1; + } } module.exports = ChannelPermissions; \ No newline at end of file From 8f4e6e34d5bf40d4265dce70acac905d16cdcf9f Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 21:35:28 +0100 Subject: [PATCH 120/151] Added full evaluation of SERVERwide permissions --- lib/ChannelPermissions.js | 31 ++++++++++++++++++++++++++--- lib/Member.js | 41 ++++++++++++++++++++++++++++++++++++++- lib/channel.js | 2 +- src/Member.js | 19 +++++++++++++++++- test/bot.1.js | 2 +- 5 files changed, 88 insertions(+), 7 deletions(-) diff --git a/lib/ChannelPermissions.js b/lib/ChannelPermissions.js index 2fcc61792..e47395fd3 100644 --- a/lib/ChannelPermissions.js +++ b/lib/ChannelPermissions.js @@ -1,9 +1,34 @@ "use strict"; +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -var ChannelPermissions = function ChannelPermissions(data) { - _classCallCheck(this, ChannelPermissions); -}; +var ChannelPermissions = (function () { + function ChannelPermissions(data) { + _classCallCheck(this, ChannelPermissions); + + function getBit(x) { + return (this.packed >>> x & 1) === 1; + } + + this.type = data.type; //either member or role + + this.id = data.id; + + this.deny = data.deny; + + this.allow = data.allow; + } + + _createClass(ChannelPermissions, [{ + key: "getBit", + value: function getBit(x) { + return (this.packed >>> x & 1) === 1; + } + }]); + + return ChannelPermissions; +})(); module.exports = ChannelPermissions; \ No newline at end of file diff --git a/lib/Member.js b/lib/Member.js index ea9b35a07..093d37d5a 100644 --- a/lib/Member.js +++ b/lib/Member.js @@ -9,6 +9,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var User = require("./user.js"); +var ServerPermissions = require("./ServerPermissions.js"); var Member = (function (_User) { _inherits(Member, _User); @@ -25,8 +26,9 @@ var Member = (function (_User) { key: "roles", get: function get() { - var ufRoles = []; + var ufRoles = [this.server.getRole(this.server.id)]; + console.log(this.rawRoles); var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; @@ -54,6 +56,43 @@ var Member = (function (_User) { return ufRoles; } + }, { + key: "evalPerms", + get: function get() { + + var basePerms = this.roles, + //cache roles as it can be slightly expensive + basePerm = basePerms[0].packed; + + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = basePerms[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var perm = _step2.value; + + basePerm = basePerm | perm.packed; + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2["return"]) { + _iterator2["return"](); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + + return new ServerPermissions({ + permissions: basePerm + }); + } }]); return Member; diff --git a/lib/channel.js b/lib/channel.js index cfa397ccd..be49484d3 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -26,7 +26,7 @@ var Channel = (function () { for (var _iterator = data.permission_overwrites[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var role = _step.value; - this.roles.push(new ChannelPermissions()); + this.roles.push(new ChannelPermissions(role)); } //this.isPrivate = isPrivate; //not sure about the implementation of this... diff --git a/src/Member.js b/src/Member.js index 4750b7ada..5db412403 100644 --- a/src/Member.js +++ b/src/Member.js @@ -1,4 +1,5 @@ var User = require("./user.js"); +var ServerPermissions = require("./ServerPermissions.js"); class Member extends User{ @@ -10,8 +11,9 @@ class Member extends User{ get roles(){ - var ufRoles = []; + var ufRoles = [ this.server.getRole(this.server.id) ]; + console.log(this.rawRoles); for(var rawRole of this.rawRoles){ ufRoles.push( this.server.getRole(rawRole) ); } @@ -20,6 +22,21 @@ class Member extends User{ } + get evalPerms(){ + + var basePerms = this.roles, //cache roles as it can be slightly expensive + basePerm = basePerms[0].packed; + + for(var perm of basePerms){ + basePerm = basePerm | perm.packed; + } + + return new ServerPermissions({ + permissions : basePerm + }); + + } + } module.exports = Member; \ No newline at end of file diff --git a/test/bot.1.js b/test/bot.1.js index 88275fd1b..e216f2e4a 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -19,7 +19,7 @@ mybot.on("message", function (message) { // we can go ahead :) - mybot.reply(message, message.sender.roles); + mybot.reply(message, "your evaluated server-wide permissions are " + JSON.stringify(message.sender.evalPerms, null, 4).replace(/true/g, "**true**")); }); From c60fe266574227c1e89b9bd11510a27734df558e Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 22:50:46 +0100 Subject: [PATCH 121/151] Added permissions evaluation! --- lib/ChannelPermissions.js | 39 +++++++++-- lib/EvaluatedPermissions.js | 52 ++++++++++++++ lib/Member.js | 131 +++++++++++++++++++++++++++++++----- lib/channel.js | 2 +- src/ChannelPermissions.js | 39 +++++++++-- src/EvaluatedPermissions.js | 41 +++++++++++ src/Member.js | 37 +++++++++- src/channel.js | 2 +- test/bot.1.js | 2 +- 9 files changed, 313 insertions(+), 32 deletions(-) create mode 100644 lib/EvaluatedPermissions.js create mode 100644 src/EvaluatedPermissions.js diff --git a/lib/ChannelPermissions.js b/lib/ChannelPermissions.js index e47395fd3..b8109644c 100644 --- a/lib/ChannelPermissions.js +++ b/lib/ChannelPermissions.js @@ -5,20 +5,51 @@ var _createClass = (function () { function defineProperties(target, props) { for function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var ChannelPermissions = (function () { - function ChannelPermissions(data) { + function ChannelPermissions(data, channel) { _classCallCheck(this, ChannelPermissions); + var self = this; + function getBit(x) { - return (this.packed >>> x & 1) === 1; + return (self.packed >>> x & 1) === 1; } this.type = data.type; //either member or role - this.id = data.id; - this.deny = data.deny; + if (this.type === "member") { + this.packed = channel.server.getMember("id", data.id).evalPerms.packed; + } else { + this.packed = channel.server.getRole(data.id).packed; + } + this.packed = this.packed & ~data.deny; + this.packed = this.packed | data.allow; + + this.deny = data.deny; this.allow = data.allow; + + this.createInstantInvite = getBit(0); + //this.banMembers = getBit(1); + //this.kickMembers = getBit(2); + this.managePermissions = getBit(3); + this.manageChannels = getBit(4); + //this.manageServer = getBit(5); + this.readMessages = getBit(10); + this.sendMessages = getBit(11); + this.sendTTSMessages = getBit(12); + this.manageMessages = getBit(13); + this.embedLinks = getBit(14); + this.attachFiles = getBit(15); + this.readMessageHistory = getBit(16); + this.mentionEveryone = getBit(17); + + this.voiceConnect = getBit(20); + this.voiceSpeak = getBit(21); + this.voiceMuteMembers = getBit(22); + this.voiceDeafenMembers = getBit(23); + this.voiceMoveMembers = getBit(24); + this.voiceUseVoiceActivation = getBit(25); } _createClass(ChannelPermissions, [{ diff --git a/lib/EvaluatedPermissions.js b/lib/EvaluatedPermissions.js new file mode 100644 index 000000000..a0795823c --- /dev/null +++ b/lib/EvaluatedPermissions.js @@ -0,0 +1,52 @@ +"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 EvaluatedPermissions = (function () { + function EvaluatedPermissions(data) { + _classCallCheck(this, EvaluatedPermissions); + + var self = this; + + function getBit(x) { + return (self.packed >>> x & 1) === 1; + } + + this.packed = data; + + this.createInstantInvite = getBit(0); + //this.banMembers = getBit(1); + //this.kickMembers = getBit(2); + this.managePermissions = getBit(3); + this.manageChannels = getBit(4); + //this.manageServer = getBit(5); + this.readMessages = getBit(10); + this.sendMessages = getBit(11); + this.sendTTSMessages = getBit(12); + this.manageMessages = getBit(13); + this.embedLinks = getBit(14); + this.attachFiles = getBit(15); + this.readMessageHistory = getBit(16); + this.mentionEveryone = getBit(17); + + this.voiceConnect = getBit(20); + this.voiceSpeak = getBit(21); + this.voiceMuteMembers = getBit(22); + this.voiceDeafenMembers = getBit(23); + this.voiceMoveMembers = getBit(24); + this.voiceUseVoiceActivation = getBit(25); + } + + _createClass(EvaluatedPermissions, [{ + key: "getBit", + value: function getBit(x) { + return (this.packed >>> x & 1) === 1; + } + }]); + + return EvaluatedPermissions; +})(); + +module.exports = EvaluatedPermissions; \ No newline at end of file diff --git a/lib/Member.js b/lib/Member.js index 093d37d5a..a4be7c50b 100644 --- a/lib/Member.js +++ b/lib/Member.js @@ -10,6 +10,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var User = require("./user.js"); var ServerPermissions = require("./ServerPermissions.js"); +var EvaluatedPermissions = require("./EvaluatedPermissions.js"); var Member = (function (_User) { _inherits(Member, _User); @@ -23,21 +24,25 @@ var Member = (function (_User) { } _createClass(Member, [{ - key: "roles", - get: function get() { + key: "permissionsIn", + value: function permissionsIn(channel) { - var ufRoles = [this.server.getRole(this.server.id)]; + var affectingOverwrites = []; + var affectingMemberOverwrites = []; - console.log(this.rawRoles); var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { - for (var _iterator = this.rawRoles[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var rawRole = _step.value; + for (var _iterator = channel.roles[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var overwrite = _step.value; - ufRoles.push(this.server.getRole(rawRole)); + if (overwrite.id === this.id && overwrite.type === "member") { + affectingMemberOverwrites.push(overwrite); + } else if (this.rawRoles.indexOf(overwrite.id) !== -1) { + affectingOverwrites.push(overwrite); + } } } catch (err) { _didIteratorError = true; @@ -54,25 +59,22 @@ var Member = (function (_User) { } } - return ufRoles; - } - }, { - key: "evalPerms", - get: function get() { + if (affectingOverwrites.length === 0) { + return new EvaluatedPermissions(this.evalPerms.packed); + } - var basePerms = this.roles, - //cache roles as it can be slightly expensive - basePerm = basePerms[0].packed; + var finalPacked = affectingOverwrites[0].packed; var _iteratorNormalCompletion2 = true; var _didIteratorError2 = false; var _iteratorError2 = undefined; try { - for (var _iterator2 = basePerms[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var perm = _step2.value; + for (var _iterator2 = affectingOverwrites[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var overwrite = _step2.value; - basePerm = basePerm | perm.packed; + finalPacked = finalPacked & ~overwrite.deny; + finalPacked = finalPacked | overwrite.allow; } } catch (err) { _didIteratorError2 = true; @@ -89,6 +91,99 @@ var Member = (function (_User) { } } + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = affectingMemberOverwrites[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var overwrite = _step3.value; + + finalPacked = finalPacked & ~overwrite.deny; + finalPacked = finalPacked | overwrite.allow; + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3["return"]) { + _iterator3["return"](); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + + return new EvaluatedPermissions(finalPacked); + } + }, { + key: "roles", + get: function get() { + + var ufRoles = [this.server.getRole(this.server.id)]; + + var _iteratorNormalCompletion4 = true; + var _didIteratorError4 = false; + var _iteratorError4 = undefined; + + try { + for (var _iterator4 = this.rawRoles[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var rawRole = _step4.value; + + ufRoles.push(this.server.getRole(rawRole)); + } + } catch (err) { + _didIteratorError4 = true; + _iteratorError4 = err; + } finally { + try { + if (!_iteratorNormalCompletion4 && _iterator4["return"]) { + _iterator4["return"](); + } + } finally { + if (_didIteratorError4) { + throw _iteratorError4; + } + } + } + + return ufRoles; + } + }, { + key: "evalPerms", + get: function get() { + var basePerms = this.roles, + //cache roles as it can be slightly expensive + basePerm = basePerms[0].packed; + + var _iteratorNormalCompletion5 = true; + var _didIteratorError5 = false; + var _iteratorError5 = undefined; + + try { + for (var _iterator5 = basePerms[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { + var perm = _step5.value; + + basePerm = basePerm | perm.packed; + } + } catch (err) { + _didIteratorError5 = true; + _iteratorError5 = err; + } finally { + try { + if (!_iteratorNormalCompletion5 && _iterator5["return"]) { + _iterator5["return"](); + } + } finally { + if (_didIteratorError5) { + throw _iteratorError5; + } + } + } + return new ServerPermissions({ permissions: basePerm }); diff --git a/lib/channel.js b/lib/channel.js index be49484d3..eee332b0d 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -26,7 +26,7 @@ var Channel = (function () { for (var _iterator = data.permission_overwrites[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var role = _step.value; - this.roles.push(new ChannelPermissions(role)); + this.roles.push(new ChannelPermissions(role, this)); } //this.isPrivate = isPrivate; //not sure about the implementation of this... diff --git a/src/ChannelPermissions.js b/src/ChannelPermissions.js index 13f183867..aa70ed2a2 100644 --- a/src/ChannelPermissions.js +++ b/src/ChannelPermissions.js @@ -1,18 +1,49 @@ class ChannelPermissions{ - constructor(data){ + constructor(data, channel){ + + var self = this; function getBit(x) { - return ((this.packed >>> x) & 1) === 1; + return ((self.packed >>> x) & 1) === 1; } this.type = data.type; //either member or role - this.id = data.id; - this.deny = data.deny; + if(this.type === "member"){ + this.packed = channel.server.getMember("id", data.id).evalPerms.packed; + }else{ + this.packed = channel.server.getRole(data.id).packed; + } + this.packed = this.packed & ~data.deny; + this.packed = this.packed | data.allow; + + this.deny = data.deny; this.allow = data.allow; + this.createInstantInvite = getBit(0); + //this.banMembers = getBit(1); + //this.kickMembers = getBit(2); + this.managePermissions = getBit(3); + this.manageChannels = getBit(4); + //this.manageServer = getBit(5); + this.readMessages = getBit(10); + this.sendMessages = getBit(11); + this.sendTTSMessages = getBit(12); + this.manageMessages = getBit(13); + this.embedLinks = getBit(14); + this.attachFiles = getBit(15); + this.readMessageHistory = getBit(16); + this.mentionEveryone = getBit(17); + + this.voiceConnect = getBit(20); + this.voiceSpeak = getBit(21); + this.voiceMuteMembers = getBit(22); + this.voiceDeafenMembers = getBit(23); + this.voiceMoveMembers = getBit(24); + this.voiceUseVoiceActivation = getBit(25); + } getBit(x) { diff --git a/src/EvaluatedPermissions.js b/src/EvaluatedPermissions.js new file mode 100644 index 000000000..3c21e7870 --- /dev/null +++ b/src/EvaluatedPermissions.js @@ -0,0 +1,41 @@ +class EvaluatedPermissions{ + constructor(data){ + + var self = this; + + function getBit(x) { + return ((self.packed >>> x) & 1) === 1; + } + + this.packed = data; + + this.createInstantInvite = getBit(0); + //this.banMembers = getBit(1); + //this.kickMembers = getBit(2); + this.managePermissions = getBit(3); + this.manageChannels = getBit(4); + //this.manageServer = getBit(5); + this.readMessages = getBit(10); + this.sendMessages = getBit(11); + this.sendTTSMessages = getBit(12); + this.manageMessages = getBit(13); + this.embedLinks = getBit(14); + this.attachFiles = getBit(15); + this.readMessageHistory = getBit(16); + this.mentionEveryone = getBit(17); + + this.voiceConnect = getBit(20); + this.voiceSpeak = getBit(21); + this.voiceMuteMembers = getBit(22); + this.voiceDeafenMembers = getBit(23); + this.voiceMoveMembers = getBit(24); + this.voiceUseVoiceActivation = getBit(25); + + } + + getBit(x) { + return ((this.packed >>> x) & 1) === 1; + } +} + +module.exports = EvaluatedPermissions; \ No newline at end of file diff --git a/src/Member.js b/src/Member.js index 5db412403..969c5cd43 100644 --- a/src/Member.js +++ b/src/Member.js @@ -1,5 +1,6 @@ var User = require("./user.js"); var ServerPermissions = require("./ServerPermissions.js"); +var EvaluatedPermissions = require("./EvaluatedPermissions.js"); class Member extends User{ @@ -12,8 +13,7 @@ class Member extends User{ get roles(){ var ufRoles = [ this.server.getRole(this.server.id) ]; - - console.log(this.rawRoles); + for(var rawRole of this.rawRoles){ ufRoles.push( this.server.getRole(rawRole) ); } @@ -23,7 +23,6 @@ class Member extends User{ } get evalPerms(){ - var basePerms = this.roles, //cache roles as it can be slightly expensive basePerm = basePerms[0].packed; @@ -34,6 +33,38 @@ class Member extends User{ return new ServerPermissions({ permissions : basePerm }); + } + + permissionsIn(channel){ + + var affectingOverwrites = []; + var affectingMemberOverwrites = []; + + for(var overwrite of channel.roles){ + if(overwrite.id === this.id && overwrite.type === "member"){ + affectingMemberOverwrites.push(overwrite); + }else if( this.rawRoles.indexOf(overwrite.id) !== -1 ){ + affectingOverwrites.push(overwrite); + } + } + + if(affectingOverwrites.length === 0){ + return new EvaluatedPermissions(this.evalPerms.packed); + } + + var finalPacked = affectingOverwrites[0].packed; + + for(var overwrite of affectingOverwrites){ + finalPacked = finalPacked & ~overwrite.deny; + finalPacked = finalPacked | overwrite.allow; + } + + for(var overwrite of affectingMemberOverwrites){ + finalPacked = finalPacked & ~overwrite.deny; + finalPacked = finalPacked | overwrite.allow; + } + + return new EvaluatedPermissions(finalPacked); } diff --git a/src/channel.js b/src/channel.js index 64c9f22f0..81d5c5b28 100644 --- a/src/channel.js +++ b/src/channel.js @@ -13,7 +13,7 @@ class Channel { for (var role of data.permission_overwrites) { - this.roles.push( new ChannelPermissions(role) ); + this.roles.push( new ChannelPermissions(role, this) ); } diff --git a/test/bot.1.js b/test/bot.1.js index e216f2e4a..0f429ebe4 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -19,7 +19,7 @@ mybot.on("message", function (message) { // we can go ahead :) - mybot.reply(message, "your evaluated server-wide permissions are " + JSON.stringify(message.sender.evalPerms, null, 4).replace(/true/g, "**true**")); + mybot.reply(message, "your evaluated permissions in this channel are " + JSON.stringify(message.sender.permissionsIn(message.channel), null, 4).replace(/true/g, "**true**")); }); From 4eacab784d95b7bef7e7de6f048a6660f457c2a1 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 23:13:33 +0100 Subject: [PATCH 122/151] Fixed evaluation and added basic deletion following --- lib/Client.js | 11 +++++++ lib/Member.js | 83 +++++++++++++++++++++++++++++++++------------------ lib/server.js | 75 +++++++++++++++++++++++++++++++++++----------- src/Client.js | 11 +++++++ src/Member.js | 8 +++-- src/server.js | 20 +++++++++++++ test/bot.1.js | 6 ---- 7 files changed, 160 insertions(+), 54 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index e22cac6c8..51454a9bb 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1134,6 +1134,17 @@ var Client = (function () { break; + case "GUILD_ROLE_DELETE": + + var server = self.getServer("id", data.guild_id); + var role = server.getRole(data.role_id); + + self.trigger("serverRoleDelete", server, role); + + server.removeRole(role.id); + + break; + default: self.debug("received unknown packet"); self.trigger("unknown", dat); diff --git a/lib/Member.js b/lib/Member.js index a4be7c50b..d879355cd 100644 --- a/lib/Member.js +++ b/lib/Member.js @@ -59,22 +59,15 @@ var Member = (function (_User) { } } - if (affectingOverwrites.length === 0) { - return new EvaluatedPermissions(this.evalPerms.packed); - } - - var finalPacked = affectingOverwrites[0].packed; - var _iteratorNormalCompletion2 = true; var _didIteratorError2 = false; var _iteratorError2 = undefined; try { for (var _iterator2 = affectingOverwrites[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var overwrite = _step2.value; + var perm = _step2.value; - finalPacked = finalPacked & ~overwrite.deny; - finalPacked = finalPacked | overwrite.allow; + console.log("hey", perm.attachFiles); } } catch (err) { _didIteratorError2 = true; @@ -91,12 +84,18 @@ var Member = (function (_User) { } } + if (affectingOverwrites.length === 0 && affectingMemberOverwrites.length === 0) { + return new EvaluatedPermissions(this.evalPerms.packed); + } + + var finalPacked = affectingOverwrites.length !== 0 ? affectingOverwrites[0].packed : affectingMemberOverwrites[0].packed; + var _iteratorNormalCompletion3 = true; var _didIteratorError3 = false; var _iteratorError3 = undefined; try { - for (var _iterator3 = affectingMemberOverwrites[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + for (var _iterator3 = affectingOverwrites[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { var overwrite = _step3.value; finalPacked = finalPacked & ~overwrite.deny; @@ -117,23 +116,16 @@ var Member = (function (_User) { } } - return new EvaluatedPermissions(finalPacked); - } - }, { - key: "roles", - get: function get() { - - var ufRoles = [this.server.getRole(this.server.id)]; - var _iteratorNormalCompletion4 = true; var _didIteratorError4 = false; var _iteratorError4 = undefined; try { - for (var _iterator4 = this.rawRoles[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { - var rawRole = _step4.value; + for (var _iterator4 = affectingMemberOverwrites[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var overwrite = _step4.value; - ufRoles.push(this.server.getRole(rawRole)); + finalPacked = finalPacked & ~overwrite.deny; + finalPacked = finalPacked | overwrite.allow; } } catch (err) { _didIteratorError4 = true; @@ -150,24 +142,23 @@ var Member = (function (_User) { } } - return ufRoles; + return new EvaluatedPermissions(finalPacked); } }, { - key: "evalPerms", + key: "roles", get: function get() { - var basePerms = this.roles, - //cache roles as it can be slightly expensive - basePerm = basePerms[0].packed; + + var ufRoles = [this.server.getRole(this.server.id)]; var _iteratorNormalCompletion5 = true; var _didIteratorError5 = false; var _iteratorError5 = undefined; try { - for (var _iterator5 = basePerms[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { - var perm = _step5.value; + for (var _iterator5 = this.rawRoles[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { + var rawRole = _step5.value; - basePerm = basePerm | perm.packed; + ufRoles.push(this.server.getRole(rawRole)); } } catch (err) { _didIteratorError5 = true; @@ -184,6 +175,40 @@ var Member = (function (_User) { } } + return ufRoles; + } + }, { + key: "evalPerms", + get: function get() { + var basePerms = this.roles, + //cache roles as it can be slightly expensive + basePerm = basePerms[0].packed; + + var _iteratorNormalCompletion6 = true; + var _didIteratorError6 = false; + var _iteratorError6 = undefined; + + try { + for (var _iterator6 = basePerms[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { + var perm = _step6.value; + + basePerm = basePerm | perm.packed; + } + } catch (err) { + _didIteratorError6 = true; + _iteratorError6 = err; + } finally { + try { + if (!_iteratorNormalCompletion6 && _iterator6["return"]) { + _iterator6["return"](); + } + } finally { + if (_didIteratorError6) { + throw _iteratorError6; + } + } + } + return new ServerPermissions({ permissions: basePerm }); diff --git a/lib/server.js b/lib/server.js index c9feaa0a3..0bdb36612 100644 --- a/lib/server.js +++ b/lib/server.js @@ -121,18 +121,29 @@ var Server = (function () { return null; } }, { - key: "getChannel", - value: function getChannel(key, value) { + key: "updateRole", + value: function updateRole() {} + }, { + key: "removeRole", + value: function removeRole(id) { + for (var roleId in this.roles) { + if (this.roles[roleId].id === id) { + this.roles.splice(roleId, 1); + } + } + var _iteratorNormalCompletion4 = true; var _didIteratorError4 = false; var _iteratorError4 = undefined; try { - for (var _iterator4 = this.channels[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { - var channel = _step4.value; + for (var _iterator4 = this.members[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var member = _step4.value; - if (channel[key] === value) { - return channel; + for (var roleId in member.rawRoles) { + if (member.rawRoles[roleId] === id) { + member.rawRoles.splice(roleId, 1); + } } } } catch (err) { @@ -149,22 +160,20 @@ var Server = (function () { } } } - - return null; } }, { - key: "getMember", - value: function getMember(key, value) { + key: "getChannel", + value: function getChannel(key, value) { var _iteratorNormalCompletion5 = true; var _didIteratorError5 = false; var _iteratorError5 = undefined; try { - for (var _iterator5 = this.members[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { - var member = _step5.value; + for (var _iterator5 = this.channels[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { + var channel = _step5.value; - if (member[key] === value) { - return member; + if (channel[key] === value) { + return channel; } } } catch (err) { @@ -185,8 +194,8 @@ var Server = (function () { return null; } }, { - key: "removeMember", - value: function removeMember(key, value) { + key: "getMember", + value: function getMember(key, value) { var _iteratorNormalCompletion6 = true; var _didIteratorError6 = false; var _iteratorError6 = undefined; @@ -196,7 +205,6 @@ var Server = (function () { var member = _step6.value; if (member[key] === value) { - this.members.splice(key, 1); return member; } } @@ -215,6 +223,39 @@ var Server = (function () { } } + return null; + } + }, { + key: "removeMember", + value: function removeMember(key, value) { + var _iteratorNormalCompletion7 = true; + var _didIteratorError7 = false; + var _iteratorError7 = undefined; + + try { + for (var _iterator7 = this.members[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { + var member = _step7.value; + + if (member[key] === value) { + this.members.splice(key, 1); + return member; + } + } + } catch (err) { + _didIteratorError7 = true; + _iteratorError7 = err; + } finally { + try { + if (!_iteratorNormalCompletion7 && _iterator7["return"]) { + _iterator7["return"](); + } + } finally { + if (_didIteratorError7) { + throw _iteratorError7; + } + } + } + return false; } }, { diff --git a/src/Client.js b/src/Client.js index e8560d457..20d71f330 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1042,6 +1042,17 @@ class Client { }, 6000); break; + + case "GUILD_ROLE_DELETE": + + var server = self.getServer("id", data.guild_id); + var role = server.getRole(data.role_id); + + self.trigger("serverRoleDelete", server, role); + + server.removeRole(role.id); + + break; default: self.debug("received unknown packet"); diff --git a/src/Member.js b/src/Member.js index 969c5cd43..e5cc946f1 100644 --- a/src/Member.js +++ b/src/Member.js @@ -48,11 +48,15 @@ class Member extends User{ } } - if(affectingOverwrites.length === 0){ + for(var perm of affectingOverwrites){ + console.log("hey", perm.attachFiles); + } + + if(affectingOverwrites.length === 0 && affectingMemberOverwrites.length === 0){ return new EvaluatedPermissions(this.evalPerms.packed); } - var finalPacked = affectingOverwrites[0].packed; + var finalPacked = (affectingOverwrites.length !== 0 ? affectingOverwrites[0].packed : affectingMemberOverwrites[0].packed); for(var overwrite of affectingOverwrites){ finalPacked = finalPacked & ~overwrite.deny; diff --git a/src/server.js b/src/server.js index d2a1bf411..6ae83ad58 100644 --- a/src/server.js +++ b/src/server.js @@ -83,6 +83,26 @@ class Server { return null; } + updateRole(){ + + } + + removeRole(id){ + for (var roleId in this.roles) { + if (this.roles[roleId].id === id) { + this.roles.splice(roleId, 1); + } + } + + for(var member of this.members){ + for(var roleId in member.rawRoles){ + if(member.rawRoles[roleId] === id){ + member.rawRoles.splice(roleId, 1); + } + } + } + } + getChannel(key, value) { for (var channel of this.channels) { if (channel[key] === value) { diff --git a/test/bot.1.js b/test/bot.1.js index 0f429ebe4..0d21c7af2 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -9,10 +9,6 @@ counter = 1; mybot.on("message", function (message) { console.log("Everyone mentioned? " + message.everyoneMentioned); - if (mybot.user.equals(message.sender)) { - return; - } - if (message.content !== "$$$") { return; } @@ -44,8 +40,6 @@ mybot.on("unknown", function(info){ mybot.on("channelUpdate", function(oldChan, newChan){ - console.log(oldChan.topic + " vs " + newChan.topic); - }); mybot.on("startTyping", function(user, channel){ From 0b020f92642e27842820f686640d65b0a8d55c9e Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 23:33:00 +0100 Subject: [PATCH 123/151] Fixed some stuff so much I don't even remember --- lib/EvaluatedPermissions.js | 3 +++ lib/Member.js | 4 ++++ lib/channel.js | 12 ++++++++++++ src/EvaluatedPermissions.js | 3 +++ src/Member.js | 4 ++++ src/channel.js | 12 ++++++++++++ test/bot.1.js | 13 +++++++++++-- 7 files changed, 49 insertions(+), 2 deletions(-) diff --git a/lib/EvaluatedPermissions.js b/lib/EvaluatedPermissions.js index a0795823c..4c56d9e64 100644 --- a/lib/EvaluatedPermissions.js +++ b/lib/EvaluatedPermissions.js @@ -11,6 +11,9 @@ var EvaluatedPermissions = (function () { var self = this; function getBit(x) { + if ((self.packed >>> 3 & 1) === 1) { + return true; + } return (self.packed >>> x & 1) === 1; } diff --git a/lib/Member.js b/lib/Member.js index d879355cd..ba29467db 100644 --- a/lib/Member.js +++ b/lib/Member.js @@ -27,6 +27,10 @@ var Member = (function (_User) { key: "permissionsIn", value: function permissionsIn(channel) { + if (channel.server.ownerID === this.id) { + return new EvaluatedPermissions(4294967295); //all perms + } + var affectingOverwrites = []; var affectingMemberOverwrites = []; diff --git a/lib/channel.js b/lib/channel.js index eee332b0d..fbaa8ce4c 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -47,6 +47,18 @@ var Channel = (function () { } _createClass(Channel, [{ + key: "permissionsOf", + value: function permissionsOf(member) { + + var mem = this.server.getMember("id", member.id); + + if (mem) { + return mem.permissionsIn(this); + } else { + return null; + } + } + }, { key: "equals", value: function equals(object) { return object && object.id === this.id; diff --git a/src/EvaluatedPermissions.js b/src/EvaluatedPermissions.js index 3c21e7870..ba71f8e85 100644 --- a/src/EvaluatedPermissions.js +++ b/src/EvaluatedPermissions.js @@ -4,6 +4,9 @@ class EvaluatedPermissions{ var self = this; function getBit(x) { + if(((self.packed >>> 3) & 1) === 1){ + return true; + } return ((self.packed >>> x) & 1) === 1; } diff --git a/src/Member.js b/src/Member.js index e5cc946f1..9ac6c644b 100644 --- a/src/Member.js +++ b/src/Member.js @@ -37,6 +37,10 @@ class Member extends User{ permissionsIn(channel){ + if(channel.server.ownerID === this.id){ + return new EvaluatedPermissions(4294967295); //all perms + } + var affectingOverwrites = []; var affectingMemberOverwrites = []; diff --git a/src/channel.js b/src/channel.js index 81d5c5b28..6e3b2ef99 100644 --- a/src/channel.js +++ b/src/channel.js @@ -32,6 +32,18 @@ class Channel { return this.server.client; } + permissionsOf(member){ + + var mem = this.server.getMember("id", member.id); + + if(mem){ + return mem.permissionsIn(this); + }else{ + return null; + } + + } + equals(object) { return (object && object.id === this.id); } diff --git a/test/bot.1.js b/test/bot.1.js index 0d21c7af2..19caf0151 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -9,13 +9,22 @@ counter = 1; mybot.on("message", function (message) { console.log("Everyone mentioned? " + message.everyoneMentioned); - if (message.content !== "$$$") { + if (message.content.substr(0,3) !== "$$$") { return; } // we can go ahead :) - mybot.reply(message, "your evaluated permissions in this channel are " + JSON.stringify(message.sender.permissionsIn(message.channel), null, 4).replace(/true/g, "**true**")); + var user; + if(message.mentions.length > 0){ + user = message.mentions[0]; + }else{ + user = message.sender; + } + + console.log("the ID is ", user.id); + + mybot.reply(message, user + "'s evaluated permissions in this channel are " + JSON.stringify(message.channel.permissionsOf(user), null, 4).replace(/true/g, "**true**")); }); From aed7d3c1c2cbd71c7b6ae111c080a5cdeeabb295 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 23:40:29 +0100 Subject: [PATCH 124/151] began to work on update listening --- lib/ServerPermissions.js | 9 ++++++++- lib/server.js | 13 ++++++++++++- src/ServerPermissions.js | 6 ++++-- src/server.js | 13 ++++++++++++- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/lib/ServerPermissions.js b/lib/ServerPermissions.js index 66411f542..b96249b9d 100644 --- a/lib/ServerPermissions.js +++ b/lib/ServerPermissions.js @@ -18,7 +18,6 @@ var ServerPermissions = (function () { this.name = data.name; this.id = data.id; - this.createInstantInvite = getBit(0); this.banMembers = getBit(1); this.kickMembers = getBit(2); this.manageRoles = getBit(3); @@ -51,6 +50,14 @@ var ServerPermissions = (function () { value: function toString() { return this.name; } + }, { + key: "createInstantInvite", + get: function get() { + return this.getBit(0); + }, + set: function set(val) { + this.setBit(0, val); + } }]); return ServerPermissions; diff --git a/lib/server.js b/lib/server.js index 0bdb36612..cd6fddaad 100644 --- a/lib/server.js +++ b/lib/server.js @@ -122,7 +122,18 @@ var Server = (function () { } }, { key: "updateRole", - value: function updateRole() {} + value: function updateRole(data) { + + var oldRole = this.getRole(data.id); + + if (oldRole) { + + oldRole.packed = data.permissions; + oldRole.name = data.name; + } else { + return false; + } + } }, { key: "removeRole", value: function removeRole(id) { diff --git a/src/ServerPermissions.js b/src/ServerPermissions.js index dc0a3c9ce..7d4babd32 100644 --- a/src/ServerPermissions.js +++ b/src/ServerPermissions.js @@ -11,8 +11,7 @@ class ServerPermissions { this.packed = data.permissions; this.name = data.name; this.id = data.id; - - this.createInstantInvite = getBit(0); + this.banMembers = getBit(1); this.kickMembers = getBit(2); this.manageRoles = getBit(3); @@ -35,6 +34,9 @@ class ServerPermissions { this.voiceUseVoiceActivation = getBit(25); } + + get createInstantInvite(){return this.getBit(0);} + set createInstantInvite(val){this.setBit(0, val);} getBit(x) { return ((this.packed >>> x) & 1) === 1; diff --git a/src/server.js b/src/server.js index 6ae83ad58..92bbd970f 100644 --- a/src/server.js +++ b/src/server.js @@ -83,7 +83,18 @@ class Server { return null; } - updateRole(){ + updateRole(data){ + + var oldRole = this.getRole(data.id); + + if(oldRole){ + + oldRole.packed = data.permissions; + oldRole.name = data.name; + + }else{ + return false; + } } From 780369b90a3842de07061bec5013fac9162ed04d Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 3 Oct 2015 23:50:21 +0100 Subject: [PATCH 125/151] Moved permissions to get/set the grind was unreal --- lib/ChannelPermissions.js | 161 +++++++++++++++++++++++++++----- lib/EvaluatedPermissions.js | 161 +++++++++++++++++++++++++++----- lib/ServerPermissions.js | 178 +++++++++++++++++++++++++++++++----- src/ChannelPermissions.js | 77 +++++++++++----- src/EvaluatedPermissions.js | 92 +++++++++++++------ src/ServerPermissions.js | 82 ++++++++++++----- 6 files changed, 613 insertions(+), 138 deletions(-) diff --git a/lib/ChannelPermissions.js b/lib/ChannelPermissions.js index b8109644c..bbc8545db 100644 --- a/lib/ChannelPermissions.js +++ b/lib/ChannelPermissions.js @@ -28,28 +28,6 @@ var ChannelPermissions = (function () { this.deny = data.deny; this.allow = data.allow; - - this.createInstantInvite = getBit(0); - //this.banMembers = getBit(1); - //this.kickMembers = getBit(2); - this.managePermissions = getBit(3); - this.manageChannels = getBit(4); - //this.manageServer = getBit(5); - this.readMessages = getBit(10); - this.sendMessages = getBit(11); - this.sendTTSMessages = getBit(12); - this.manageMessages = getBit(13); - this.embedLinks = getBit(14); - this.attachFiles = getBit(15); - this.readMessageHistory = getBit(16); - this.mentionEveryone = getBit(17); - - this.voiceConnect = getBit(20); - this.voiceSpeak = getBit(21); - this.voiceMuteMembers = getBit(22); - this.voiceDeafenMembers = getBit(23); - this.voiceMoveMembers = getBit(24); - this.voiceUseVoiceActivation = getBit(25); } _createClass(ChannelPermissions, [{ @@ -57,6 +35,145 @@ var ChannelPermissions = (function () { value: function getBit(x) { return (this.packed >>> x & 1) === 1; } + }, { + key: "setBit", + value: function setBit() {} + }, { + key: "createInstantInvite", + get: function get() { + return this.getBit(0); + }, + set: function set(val) { + this.setBit(0, val); + } + }, { + key: "manageRoles", + get: function get() { + return this.getBit(3); + }, + set: function set(val) { + this.setBit(3, val); + } + }, { + key: "manageChannels", + get: function get() { + return this.getBit(4); + }, + set: function set(val) { + this.setBit(4, val); + } + }, { + key: "readMessages", + get: function get() { + return this.getBit(10); + }, + set: function set(val) { + this.setBit(10, val); + } + }, { + key: "sendMessages", + get: function get() { + return this.getBit(11); + }, + set: function set(val) { + this.setBit(11, val); + } + }, { + key: "sendTTSMessages", + get: function get() { + return this.getBit(12); + }, + set: function set(val) { + this.setBit(12, val); + } + }, { + key: "manageMessages", + get: function get() { + return this.getBit(13); + }, + set: function set(val) { + this.setBit(13, val); + } + }, { + key: "embedLinks", + get: function get() { + return this.getBit(14); + }, + set: function set(val) { + this.setBit(14, val); + } + }, { + key: "attachFiles", + get: function get() { + return this.getBit(15); + }, + set: function set(val) { + this.setBit(15, val); + } + }, { + key: "readMessageHistory", + get: function get() { + return this.getBit(16); + }, + set: function set(val) { + this.setBit(16, val); + } + }, { + key: "mentionEveryone", + get: function get() { + return this.getBit(17); + }, + set: function set(val) { + this.setBit(17, val); + } + }, { + key: "voiceConnect", + get: function get() { + return this.getBit(20); + }, + set: function set(val) { + this.setBit(20, val); + } + }, { + key: "voiceSpeak", + get: function get() { + return this.getBit(21); + }, + set: function set(val) { + this.setBit(21, val); + } + }, { + key: "voiceMuteMembers", + get: function get() { + return this.getBit(22); + }, + set: function set(val) { + this.setBit(22, val); + } + }, { + key: "voiceDeafenMembers", + get: function get() { + return this.getBit(23); + }, + set: function set(val) { + this.setBit(23, val); + } + }, { + key: "voiceMoveMembers", + get: function get() { + return this.getBit(24); + }, + set: function set(val) { + this.setBit(24, val); + } + }, { + key: "voiceUseVoiceActivation", + get: function get() { + return this.getBit(25); + }, + set: function set(val) { + this.setBit(25, val); + } }]); return ChannelPermissions; diff --git a/lib/EvaluatedPermissions.js b/lib/EvaluatedPermissions.js index 4c56d9e64..b441500cf 100644 --- a/lib/EvaluatedPermissions.js +++ b/lib/EvaluatedPermissions.js @@ -18,28 +18,6 @@ var EvaluatedPermissions = (function () { } this.packed = data; - - this.createInstantInvite = getBit(0); - //this.banMembers = getBit(1); - //this.kickMembers = getBit(2); - this.managePermissions = getBit(3); - this.manageChannels = getBit(4); - //this.manageServer = getBit(5); - this.readMessages = getBit(10); - this.sendMessages = getBit(11); - this.sendTTSMessages = getBit(12); - this.manageMessages = getBit(13); - this.embedLinks = getBit(14); - this.attachFiles = getBit(15); - this.readMessageHistory = getBit(16); - this.mentionEveryone = getBit(17); - - this.voiceConnect = getBit(20); - this.voiceSpeak = getBit(21); - this.voiceMuteMembers = getBit(22); - this.voiceDeafenMembers = getBit(23); - this.voiceMoveMembers = getBit(24); - this.voiceUseVoiceActivation = getBit(25); } _createClass(EvaluatedPermissions, [{ @@ -47,6 +25,145 @@ var EvaluatedPermissions = (function () { value: function getBit(x) { return (this.packed >>> x & 1) === 1; } + }, { + key: "setBit", + value: function setBit() {} + }, { + key: "createInstantInvite", + get: function get() { + return this.getBit(0); + }, + set: function set(val) { + this.setBit(0, val); + } + }, { + key: "manageRoles", + get: function get() { + return this.getBit(3); + }, + set: function set(val) { + this.setBit(3, val); + } + }, { + key: "manageChannels", + get: function get() { + return this.getBit(4); + }, + set: function set(val) { + this.setBit(4, val); + } + }, { + key: "readMessages", + get: function get() { + return this.getBit(10); + }, + set: function set(val) { + this.setBit(10, val); + } + }, { + key: "sendMessages", + get: function get() { + return this.getBit(11); + }, + set: function set(val) { + this.setBit(11, val); + } + }, { + key: "sendTTSMessages", + get: function get() { + return this.getBit(12); + }, + set: function set(val) { + this.setBit(12, val); + } + }, { + key: "manageMessages", + get: function get() { + return this.getBit(13); + }, + set: function set(val) { + this.setBit(13, val); + } + }, { + key: "embedLinks", + get: function get() { + return this.getBit(14); + }, + set: function set(val) { + this.setBit(14, val); + } + }, { + key: "attachFiles", + get: function get() { + return this.getBit(15); + }, + set: function set(val) { + this.setBit(15, val); + } + }, { + key: "readMessageHistory", + get: function get() { + return this.getBit(16); + }, + set: function set(val) { + this.setBit(16, val); + } + }, { + key: "mentionEveryone", + get: function get() { + return this.getBit(17); + }, + set: function set(val) { + this.setBit(17, val); + } + }, { + key: "voiceConnect", + get: function get() { + return this.getBit(20); + }, + set: function set(val) { + this.setBit(20, val); + } + }, { + key: "voiceSpeak", + get: function get() { + return this.getBit(21); + }, + set: function set(val) { + this.setBit(21, val); + } + }, { + key: "voiceMuteMembers", + get: function get() { + return this.getBit(22); + }, + set: function set(val) { + this.setBit(22, val); + } + }, { + key: "voiceDeafenMembers", + get: function get() { + return this.getBit(23); + }, + set: function set(val) { + this.setBit(23, val); + } + }, { + key: "voiceMoveMembers", + get: function get() { + return this.getBit(24); + }, + set: function set(val) { + this.setBit(24, val); + } + }, { + key: "voiceUseVoiceActivation", + get: function get() { + return this.getBit(25); + }, + set: function set(val) { + this.setBit(25, val); + } }]); return EvaluatedPermissions; diff --git a/lib/ServerPermissions.js b/lib/ServerPermissions.js index b96249b9d..73148ca06 100644 --- a/lib/ServerPermissions.js +++ b/lib/ServerPermissions.js @@ -17,27 +17,6 @@ var ServerPermissions = (function () { this.packed = data.permissions; this.name = data.name; this.id = data.id; - - this.banMembers = getBit(1); - this.kickMembers = getBit(2); - this.manageRoles = getBit(3); - this.manageChannels = getBit(4); - this.manageServer = getBit(5); - this.readMessages = getBit(10); - this.sendMessages = getBit(11); - this.sendTTSMessages = getBit(12); - this.manageMessages = getBit(13); - this.embedLinks = getBit(14); - this.attachFiles = getBit(15); - this.readMessageHistory = getBit(16); - this.mentionEveryone = getBit(17); - - this.voiceConnect = getBit(20); - this.voiceSpeak = getBit(21); - this.voiceMuteMembers = getBit(22); - this.voiceDeafenMembers = getBit(23); - this.voiceMoveMembers = getBit(24); - this.voiceUseVoiceActivation = getBit(25); } _createClass(ServerPermissions, [{ @@ -45,6 +24,11 @@ var ServerPermissions = (function () { value: function getBit(x) { return (this.packed >>> x & 1) === 1; } + }, { + key: "setBit", + value: function setBit() { + //dummy function for now + } }, { key: "toString", value: function toString() { @@ -58,6 +42,158 @@ var ServerPermissions = (function () { set: function set(val) { this.setBit(0, val); } + }, { + key: "banMembers", + get: function get() { + return this.getBit(1); + }, + set: function set(val) { + this.setBit(1, val); + } + }, { + key: "kickMembers", + get: function get() { + return this.getBit(2); + }, + set: function set(val) { + this.setBit(2, val); + } + }, { + key: "manageRoles", + get: function get() { + return this.getBit(3); + }, + set: function set(val) { + this.setBit(3, val); + } + }, { + key: "manageChannels", + get: function get() { + return this.getBit(4); + }, + set: function set(val) { + this.setBit(4, val); + } + }, { + key: "manageServer", + get: function get() { + return this.getBit(5); + }, + set: function set(val) { + this.setBit(5, val); + } + }, { + key: "readMessages", + get: function get() { + return this.getBit(10); + }, + set: function set(val) { + this.setBit(10, val); + } + }, { + key: "sendMessages", + get: function get() { + return this.getBit(11); + }, + set: function set(val) { + this.setBit(11, val); + } + }, { + key: "sendTTSMessages", + get: function get() { + return this.getBit(12); + }, + set: function set(val) { + this.setBit(12, val); + } + }, { + key: "manageMessages", + get: function get() { + return this.getBit(13); + }, + set: function set(val) { + this.setBit(13, val); + } + }, { + key: "embedLinks", + get: function get() { + return this.getBit(14); + }, + set: function set(val) { + this.setBit(14, val); + } + }, { + key: "attachFiles", + get: function get() { + return this.getBit(15); + }, + set: function set(val) { + this.setBit(15, val); + } + }, { + key: "readMessageHistory", + get: function get() { + return this.getBit(16); + }, + set: function set(val) { + this.setBit(16, val); + } + }, { + key: "mentionEveryone", + get: function get() { + return this.getBit(17); + }, + set: function set(val) { + this.setBit(17, val); + } + }, { + key: "voiceConnect", + get: function get() { + return this.getBit(20); + }, + set: function set(val) { + this.setBit(20, val); + } + }, { + key: "voiceSpeak", + get: function get() { + return this.getBit(21); + }, + set: function set(val) { + this.setBit(21, val); + } + }, { + key: "voiceMuteMembers", + get: function get() { + return this.getBit(22); + }, + set: function set(val) { + this.setBit(22, val); + } + }, { + key: "voiceDeafenMembers", + get: function get() { + return this.getBit(23); + }, + set: function set(val) { + this.setBit(23, val); + } + }, { + key: "voiceMoveMembers", + get: function get() { + return this.getBit(24); + }, + set: function set(val) { + this.setBit(24, val); + } + }, { + key: "voiceUseVoiceActivation", + get: function get() { + return this.getBit(25); + }, + set: function set(val) { + this.setBit(25, val); + } }]); return ServerPermissions; diff --git a/src/ChannelPermissions.js b/src/ChannelPermissions.js index aa70ed2a2..9d6dce2e4 100644 --- a/src/ChannelPermissions.js +++ b/src/ChannelPermissions.js @@ -22,33 +22,66 @@ class ChannelPermissions{ this.deny = data.deny; this.allow = data.allow; - this.createInstantInvite = getBit(0); - //this.banMembers = getBit(1); - //this.kickMembers = getBit(2); - this.managePermissions = getBit(3); - this.manageChannels = getBit(4); - //this.manageServer = getBit(5); - this.readMessages = getBit(10); - this.sendMessages = getBit(11); - this.sendTTSMessages = getBit(12); - this.manageMessages = getBit(13); - this.embedLinks = getBit(14); - this.attachFiles = getBit(15); - this.readMessageHistory = getBit(16); - this.mentionEveryone = getBit(17); - - this.voiceConnect = getBit(20); - this.voiceSpeak = getBit(21); - this.voiceMuteMembers = getBit(22); - this.voiceDeafenMembers = getBit(23); - this.voiceMoveMembers = getBit(24); - this.voiceUseVoiceActivation = getBit(25); - } + get createInstantInvite(){return this.getBit(0);} + set createInstantInvite(val){this.setBit(0, val);} + + get manageRoles(){return this.getBit(3);} + set manageRoles(val){this.setBit(3, val);} + + get manageChannels(){return this.getBit(4);} + set manageChannels(val){this.setBit(4, val);} + + get readMessages(){return this.getBit(10);} + set readMessages(val){this.setBit(10, val);} + + get sendMessages(){return this.getBit(11);} + set sendMessages(val){this.setBit(11, val);} + + get sendTTSMessages(){return this.getBit(12);} + set sendTTSMessages(val){this.setBit(12, val);} + + get manageMessages(){return this.getBit(13);} + set manageMessages(val){this.setBit(13, val);} + + get embedLinks(){return this.getBit(14);} + set embedLinks(val){this.setBit(14, val);} + + get attachFiles(){return this.getBit(15);} + set attachFiles(val){this.setBit(15, val);} + + get readMessageHistory(){return this.getBit(16);} + set readMessageHistory(val){this.setBit(16, val);} + + get mentionEveryone(){return this.getBit(17);} + set mentionEveryone(val){this.setBit(17, val);} + + get voiceConnect(){return this.getBit(20);} + set voiceConnect(val){this.setBit(20, val);} + + get voiceSpeak(){return this.getBit(21);} + set voiceSpeak(val){this.setBit(21, val);} + + get voiceMuteMembers(){return this.getBit(22);} + set voiceMuteMembers(val){this.setBit(22, val);} + + get voiceDeafenMembers(){return this.getBit(23);} + set voiceDeafenMembers(val){this.setBit(23, val);} + + get voiceMoveMembers(){return this.getBit(24);} + set voiceMoveMembers(val){this.setBit(24, val);} + + get voiceUseVoiceActivation(){return this.getBit(25);} + set voiceUseVoiceActivation(val){this.setBit(25, val);} + getBit(x) { return ((this.packed >>> x) & 1) === 1; } + + setBit() { + + } } module.exports = ChannelPermissions; \ No newline at end of file diff --git a/src/EvaluatedPermissions.js b/src/EvaluatedPermissions.js index ba71f8e85..5fef65fe9 100644 --- a/src/EvaluatedPermissions.js +++ b/src/EvaluatedPermissions.js @@ -1,44 +1,76 @@ -class EvaluatedPermissions{ - constructor(data){ - +class EvaluatedPermissions { + constructor(data) { + var self = this; - + function getBit(x) { - if(((self.packed >>> 3) & 1) === 1){ + if (((self.packed >>> 3) & 1) === 1) { return true; } return ((self.packed >>> x) & 1) === 1; } - + this.packed = data; - - this.createInstantInvite = getBit(0); - //this.banMembers = getBit(1); - //this.kickMembers = getBit(2); - this.managePermissions = getBit(3); - this.manageChannels = getBit(4); - //this.manageServer = getBit(5); - this.readMessages = getBit(10); - this.sendMessages = getBit(11); - this.sendTTSMessages = getBit(12); - this.manageMessages = getBit(13); - this.embedLinks = getBit(14); - this.attachFiles = getBit(15); - this.readMessageHistory = getBit(16); - this.mentionEveryone = getBit(17); - - this.voiceConnect = getBit(20); - this.voiceSpeak = getBit(21); - this.voiceMuteMembers = getBit(22); - this.voiceDeafenMembers = getBit(23); - this.voiceMoveMembers = getBit(24); - this.voiceUseVoiceActivation = getBit(25); - } - + + get createInstantInvite() { return this.getBit(0); } + set createInstantInvite(val) { this.setBit(0, val); } + + get manageRoles() { return this.getBit(3); } + set manageRoles(val) { this.setBit(3, val); } + + get manageChannels() { return this.getBit(4); } + set manageChannels(val) { this.setBit(4, val); } + + get readMessages() { return this.getBit(10); } + set readMessages(val) { this.setBit(10, val); } + + get sendMessages() { return this.getBit(11); } + set sendMessages(val) { this.setBit(11, val); } + + get sendTTSMessages() { return this.getBit(12); } + set sendTTSMessages(val) { this.setBit(12, val); } + + get manageMessages() { return this.getBit(13); } + set manageMessages(val) { this.setBit(13, val); } + + get embedLinks() { return this.getBit(14); } + set embedLinks(val) { this.setBit(14, val); } + + get attachFiles() { return this.getBit(15); } + set attachFiles(val) { this.setBit(15, val); } + + get readMessageHistory() { return this.getBit(16); } + set readMessageHistory(val) { this.setBit(16, val); } + + get mentionEveryone() { return this.getBit(17); } + set mentionEveryone(val) { this.setBit(17, val); } + + get voiceConnect() { return this.getBit(20); } + set voiceConnect(val) { this.setBit(20, val); } + + get voiceSpeak() { return this.getBit(21); } + set voiceSpeak(val) { this.setBit(21, val); } + + get voiceMuteMembers() { return this.getBit(22); } + set voiceMuteMembers(val) { this.setBit(22, val); } + + get voiceDeafenMembers() { return this.getBit(23); } + set voiceDeafenMembers(val) { this.setBit(23, val); } + + get voiceMoveMembers() { return this.getBit(24); } + set voiceMoveMembers(val) { this.setBit(24, val); } + + get voiceUseVoiceActivation() { return this.getBit(25); } + set voiceUseVoiceActivation(val) { this.setBit(25, val); } + getBit(x) { return ((this.packed >>> x) & 1) === 1; } + + setBit() { + + } } module.exports = EvaluatedPermissions; \ No newline at end of file diff --git a/src/ServerPermissions.js b/src/ServerPermissions.js index 7d4babd32..b3fd848ae 100644 --- a/src/ServerPermissions.js +++ b/src/ServerPermissions.js @@ -12,36 +12,76 @@ class ServerPermissions { this.name = data.name; this.id = data.id; - this.banMembers = getBit(1); - this.kickMembers = getBit(2); - this.manageRoles = getBit(3); - this.manageChannels = getBit(4); - this.manageServer = getBit(5); - this.readMessages = getBit(10); - this.sendMessages = getBit(11); - this.sendTTSMessages = getBit(12); - this.manageMessages = getBit(13); - this.embedLinks = getBit(14); - this.attachFiles = getBit(15); - this.readMessageHistory = getBit(16); - this.mentionEveryone = getBit(17); - - this.voiceConnect = getBit(20); - this.voiceSpeak = getBit(21); - this.voiceMuteMembers = getBit(22); - this.voiceDeafenMembers = getBit(23); - this.voiceMoveMembers = getBit(24); - this.voiceUseVoiceActivation = getBit(25); - } get createInstantInvite(){return this.getBit(0);} set createInstantInvite(val){this.setBit(0, val);} + + get banMembers(){return this.getBit(1);} + set banMembers(val){this.setBit(1, val);} + + get kickMembers(){return this.getBit(2);} + set kickMembers(val){this.setBit(2, val);} + + get manageRoles(){return this.getBit(3);} + set manageRoles(val){this.setBit(3, val);} + + get manageChannels(){return this.getBit(4);} + set manageChannels(val){this.setBit(4, val);} + + get manageServer(){return this.getBit(5);} + set manageServer(val){this.setBit(5, val);} + + get readMessages(){return this.getBit(10);} + set readMessages(val){this.setBit(10, val);} + + get sendMessages(){return this.getBit(11);} + set sendMessages(val){this.setBit(11, val);} + + get sendTTSMessages(){return this.getBit(12);} + set sendTTSMessages(val){this.setBit(12, val);} + + get manageMessages(){return this.getBit(13);} + set manageMessages(val){this.setBit(13, val);} + + get embedLinks(){return this.getBit(14);} + set embedLinks(val){this.setBit(14, val);} + + get attachFiles(){return this.getBit(15);} + set attachFiles(val){this.setBit(15, val);} + + get readMessageHistory(){return this.getBit(16);} + set readMessageHistory(val){this.setBit(16, val);} + + get mentionEveryone(){return this.getBit(17);} + set mentionEveryone(val){this.setBit(17, val);} + + get voiceConnect(){return this.getBit(20);} + set voiceConnect(val){this.setBit(20, val);} + + get voiceSpeak(){return this.getBit(21);} + set voiceSpeak(val){this.setBit(21, val);} + + get voiceMuteMembers(){return this.getBit(22);} + set voiceMuteMembers(val){this.setBit(22, val);} + + get voiceDeafenMembers(){return this.getBit(23);} + set voiceDeafenMembers(val){this.setBit(23, val);} + + get voiceMoveMembers(){return this.getBit(24);} + set voiceMoveMembers(val){this.setBit(24, val);} + + get voiceUseVoiceActivation(){return this.getBit(25);} + set voiceUseVoiceActivation(val){this.setBit(25, val);} getBit(x) { return ((this.packed >>> x) & 1) === 1; } + setBit(){ + //dummy function for now + } + toString(){ return this.name; } From b130b2400b218b93cb4627ea83baa5efca928d9c Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 4 Oct 2015 00:00:30 +0100 Subject: [PATCH 126/151] updated indexing --- lib/Client.js | 10 ++++++++++ lib/server.js | 6 ++++-- src/Client.js | 10 ++++++++++ src/server.js | 7 +++++-- test/bot.1.js | 6 +++++- 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 51454a9bb..b4f54294a 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1145,6 +1145,16 @@ var Client = (function () { break; + case "GUILD_ROLE_UPDATE": + + var server = self.getServer("id", data.guild_id); + var role = server.getRole(data.role.id); + var newRole = server.updateRole(data.role); + + self.trigger("serverRoleUpdate", server, role, newRole); + + break; + default: self.debug("received unknown packet"); self.trigger("unknown", dat); diff --git a/lib/server.js b/lib/server.js index cd6fddaad..9921a457c 100644 --- a/lib/server.js +++ b/lib/server.js @@ -128,8 +128,10 @@ var Server = (function () { if (oldRole) { - oldRole.packed = data.permissions; - oldRole.name = data.name; + var index = this.roles.indexOf(oldRole); + this.roles[index] = new ServerPermissions(permissionGroup); + + return this.roles[index]; } else { return false; } diff --git a/src/Client.js b/src/Client.js index 20d71f330..bede31c3e 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1053,6 +1053,16 @@ class Client { server.removeRole(role.id); break; + + case "GUILD_ROLE_UPDATE": + + var server = self.getServer("id", data.guild_id); + var role = server.getRole(data.role.id); + var newRole = server.updateRole(data.role); + + self.trigger("serverRoleUpdate", server, role, newRole); + + break; default: self.debug("received unknown packet"); diff --git a/src/server.js b/src/server.js index 92bbd970f..cd9342c0f 100644 --- a/src/server.js +++ b/src/server.js @@ -89,8 +89,11 @@ class Server { if(oldRole){ - oldRole.packed = data.permissions; - oldRole.name = data.name; + var index = this.roles.indexOf(oldRole); + this.roles[index] = new ServerPermissions(permissionGroup); + + + return this.roles[index]; }else{ return false; diff --git a/test/bot.1.js b/test/bot.1.js index 19caf0151..0aabfdb6c 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -24,7 +24,11 @@ mybot.on("message", function (message) { console.log("the ID is ", user.id); - mybot.reply(message, user + "'s evaluated permissions in this channel are " + JSON.stringify(message.channel.permissionsOf(user), null, 4).replace(/true/g, "**true**")); + for(key in message.channel.permissionsOf(user)){ + console.log(key); + } + + mybot.reply(message, user + "'s evaluated permissions in this channel are " + message.channel.permissionsOf(user).attachFiles); }); From 154300dfbd6cb0ba6e52bcde78cdacb46df20c6e Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 4 Oct 2015 00:23:19 +0100 Subject: [PATCH 127/151] Minor test, works --- lib/server.js | 2 +- src/server.js | 2 +- test/bot.1.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/server.js b/lib/server.js index 9921a457c..871e30928 100644 --- a/lib/server.js +++ b/lib/server.js @@ -129,7 +129,7 @@ var Server = (function () { if (oldRole) { var index = this.roles.indexOf(oldRole); - this.roles[index] = new ServerPermissions(permissionGroup); + this.roles[index] = new ServerPermissions(data); return this.roles[index]; } else { diff --git a/src/server.js b/src/server.js index cd9342c0f..458afa5e2 100644 --- a/src/server.js +++ b/src/server.js @@ -90,7 +90,7 @@ class Server { if(oldRole){ var index = this.roles.indexOf(oldRole); - this.roles[index] = new ServerPermissions(permissionGroup); + this.roles[index] = new ServerPermissions(data); return this.roles[index]; diff --git a/test/bot.1.js b/test/bot.1.js index 0aabfdb6c..9f324f719 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -28,7 +28,7 @@ mybot.on("message", function (message) { console.log(key); } - mybot.reply(message, user + "'s evaluated permissions in this channel are " + message.channel.permissionsOf(user).attachFiles); + mybot.reply(message, user + "'s evaluated permissions in this channel are " + message.channel.permissionsOf(user).sendTTSMessages); }); From 28cfbf7a783d67e86b97691900cd6c40243088c5 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 4 Oct 2015 15:11:00 +0100 Subject: [PATCH 128/151] Updated to EC6 --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 38c7f8c09..f2ce7157a 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ discord.js is a node module used as a way of interfacing with [Discord](https://discordapp.com/). It is a very useful module for creating bots. +**The examples in the repo are in EC6, either update your node or compile them down to babel yourself if you want to use them!** + ### Installation `npm install --save discord.js` From 3427b7f9e14a52aaff8da6a0864a9f068e6081cc Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 4 Oct 2015 15:12:08 +0100 Subject: [PATCH 129/151] stopping auth file from changing --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 693710211..84e9b6650 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ build/Release # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git node_modules test/auth.json +examples/auth.json From ef80255970f868b4710b181774c1572eeee22916 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 4 Oct 2015 15:15:04 +0100 Subject: [PATCH 130/151] Updated avatar example --- examples/avatar.js | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/examples/avatar.js b/examples/avatar.js index b0eb1bb27..da0fd4792 100644 --- a/examples/avatar.js +++ b/examples/avatar.js @@ -4,38 +4,28 @@ var Discord = require("../"); -// Get the email and password var AuthDetails = require("./auth.json"); var bot = new Discord.Client(); -bot.on("ready", function () { +bot.on("ready", () => { console.log("Ready to begin! Serving in " + bot.channels.length + " channels"); }); -bot.on("disconnected", function () { +bot.on("disconnected", () => { console.log("Disconnected!"); process.exit(1); //exit node.js with an error }); -bot.on("message", function (msg) { - if (msg.content === "$avatar") { - - //see if the user has an avatar - if( msg.sender.avatarURL ){ - bot.reply(msg, msg.sender.avatarURL); - }else{ - //using reply with a message automatically does: - // '@sender, ' for you! - bot.reply(msg, "you don't have an avatar!"); - } - - //alert the console - console.log("served " + msg.sender.username); - +bot.on("message", (msg) => { + + if( msg.content === "avatar" ){ + // if the message was avatar + bot.reply( msg, msg.sender.avatarURL ); } + }); bot.login(AuthDetails.email, AuthDetails.password); \ No newline at end of file From 395985c44b0f222c5e45a588325d5e0fedb7615e Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 4 Oct 2015 15:21:45 +0100 Subject: [PATCH 131/151] Added permissions example --- examples/permissions.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 examples/permissions.js diff --git a/examples/permissions.js b/examples/permissions.js new file mode 100644 index 000000000..e336eca2b --- /dev/null +++ b/examples/permissions.js @@ -0,0 +1,41 @@ +/* this bot will see if a user can send TTS messages */ + +var Discord = require("../"); + +var AuthDetails = require("./auth.json"); + +var bot = new Discord.Client(); + +bot.on("ready", () => { + console.log("Ready to begin!"); +}); + +bot.on("message", (msg) => { + + if(msg.content === "can I tts?"){ + + var user = msg.sender; + + // get the evaluated permissions for a user in the channel they asked + var permissions = msg.channel.permissionsOf(user); + + if(permissions.sendTTSMessages){ + + bot.reply(msg, "You *can* send TTS messages."); + + }else{ + + bot.reply(msg, "You *can't* send TTS messages."); + + } + + } + + /* + for a list of more permissions, go to + https://github.com/hydrabolt/discord.js/blob/master/src/EvaluatedPermissions.js + */ + +}) + +bot.login(AuthDetails.email, AuthDetails.password); \ No newline at end of file From 998e6aeca22702219bc165810bb5ab10e6298287 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 4 Oct 2015 15:22:48 +0100 Subject: [PATCH 132/151] removed cat api example --- examples/catapi.js | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 examples/catapi.js diff --git a/examples/catapi.js b/examples/catapi.js deleted file mode 100644 index ae5b7f6aa..000000000 --- a/examples/catapi.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - this bot will send an image of a cat to a channel. - may be slow depending on your internet connection. -*/ - -var Discord = require("../"); - -// Get the email and password -var AuthDetails = require("./auth.json"); - -var bot = new Discord.Client(); - -bot.on("ready", function () { - console.log("Ready to begin! Serving in " + bot.channels.length + " channels"); -}); - -bot.on("disconnected", function () { - - console.log("Disconnected!"); - process.exit(1); //exit node.js with an error - -}); - -bot.on("message", function (msg) { - if (msg.content === "$cat") { - - //send a message to the channel the ping message was sent in. - bot.sendMessage(msg.channel, "pong!"); - - //alert the console - console.log("pong-ed " + msg.sender.username); - - } -}); - -bot.login(AuthDetails.email, AuthDetails.password); \ No newline at end of file From c5d316f0bfe7ffd2c03b9b9302d6b6a0de46dd1f Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 4 Oct 2015 15:32:25 +0100 Subject: [PATCH 133/151] Added send files example --- examples/send-files.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/send-files.js diff --git a/examples/send-files.js b/examples/send-files.js new file mode 100644 index 000000000..419d77a36 --- /dev/null +++ b/examples/send-files.js @@ -0,0 +1,33 @@ +/* this bot will send an image to a channel */ + +var Discord = require("../"); + +var AuthDetails = require("./auth.json"); + +var bot = new Discord.Client(); + +bot.on("ready", () => { + console.log("Ready to begin!"); +}); + +bot.on("message", (msg) => { + + if (msg.content === "photos") { + + bot.sendFile( msg.channel, "./test/image.png", "photo.png", (err, msg) => { + if(err) + console.log("couldn't send image:", err); + }); + + } + + if( msg.content === "file" ) { + bot.sendFile( msg.channel, new Buffer("Text in a file!"), "file.txt", (err, msg) => { + if(err) + console.log("couldn't send file:", err); + }); + } + +}) + +bot.login(AuthDetails.email, AuthDetails.password); \ No newline at end of file From 083ed542744831c27e1ee3c8cf1b1d7aa627de31 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Wed, 7 Oct 2015 20:36:55 +0100 Subject: [PATCH 134/151] Fixed partial user bug --- lib/Client.js | 8 +++++++- src/Client.js | 8 +++++++- test/bot.1.js | 8 +------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index b4f54294a..49ed475a6 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1074,6 +1074,12 @@ var Client = (function () { if (userInCache) { //user exists + + data.user.username = data.user.username || userInCache.username; + data.user.id = data.user.id || userInCache.id; + data.user.discriminator = data.user.discriminator || userInCache.discriminator; + data.user.avatar = data.user.avatar || userInCache.avatar; + var presenceUser = new User(data.user); if (presenceUser.equalsStrict(userInCache)) { //they're exactly the same, an actual presence update @@ -1086,8 +1092,8 @@ var Client = (function () { }); } else { //one of their details changed. - self.trigger("userUpdate", userInCache, presenceUser); self.userCache[self.userCache.indexOf(userInCache)] = presenceUser; + self.trigger("userUpdate", userInCache, presenceUser); } } diff --git a/src/Client.js b/src/Client.js index bede31c3e..8b4e122d6 100644 --- a/src/Client.js +++ b/src/Client.js @@ -983,6 +983,12 @@ class Client { if (userInCache) { //user exists + + data.user.username = data.user.username || userInCache.username; + data.user.id = data.user.id || userInCache.id; + data.user.discriminator = data.user.discriminator || userInCache.discriminator; + data.user.avatar = data.user.avatar || userInCache.avatar; + var presenceUser = new User(data.user); if (presenceUser.equalsStrict(userInCache)) { //they're exactly the same, an actual presence update @@ -995,8 +1001,8 @@ class Client { }); } else { //one of their details changed. - self.trigger("userUpdate", userInCache, presenceUser); self.userCache[self.userCache.indexOf(userInCache)] = presenceUser; + self.trigger("userUpdate", userInCache, presenceUser); } } diff --git a/test/bot.1.js b/test/bot.1.js index 9f324f719..55c57651a 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -44,7 +44,7 @@ mybot.on("ready", function () { }); mybot.on("debug", function(info){ - console.log(info); + }) mybot.on("unknown", function(info){ @@ -55,12 +55,6 @@ mybot.on("channelUpdate", function(oldChan, newChan){ }); -mybot.on("startTyping", function(user, channel){ - console.log("start", user); -}); -mybot.on("stopTyping", function(user, channel){ - console.log("stop", user); -}); function dump(msg) { console.log(msg); From eb539015ca97e7cde519f2af795d74b98842c3d1 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 9 Oct 2015 18:02:45 +0100 Subject: [PATCH 135/151] added .oldStatus to presence update --- lib/Client.js | 3 ++- src/Client.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 49ed475a6..f02f8f1d6 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1083,13 +1083,14 @@ var Client = (function () { var presenceUser = new User(data.user); if (presenceUser.equalsStrict(userInCache)) { //they're exactly the same, an actual presence update - userInCache.status = data.status; self.trigger("presence", { user: userInCache, + oldStatus: userInCache.status, status: data.status, server: self.getServer("id", data.guild_id), gameId: data.game_id }); + userInCache.status = data.status; } else { //one of their details changed. self.userCache[self.userCache.indexOf(userInCache)] = presenceUser; diff --git a/src/Client.js b/src/Client.js index 8b4e122d6..1900642f7 100644 --- a/src/Client.js +++ b/src/Client.js @@ -992,13 +992,14 @@ class Client { var presenceUser = new User(data.user); if (presenceUser.equalsStrict(userInCache)) { //they're exactly the same, an actual presence update - userInCache.status = data.status; self.trigger("presence", { user: userInCache, + oldStatus : userInCache.status, status: data.status, server: self.getServer("id", data.guild_id), gameId: data.game_id }); + userInCache.status = data.status; } else { //one of their details changed. self.userCache[self.userCache.indexOf(userInCache)] = presenceUser; From 15b78b0108e1a6668970e9efb64801dd0001d9ba Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Fri, 9 Oct 2015 18:04:05 +0100 Subject: [PATCH 136/151] 3.8.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f7bac9516..b7cd03391 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.8.0", + "version": "3.8.1", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From 35781789419cfd87f48a2f0273bfa3eb3a607bc4 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 10 Oct 2015 11:43:31 +0100 Subject: [PATCH 137/151] Fixed PM Channel bug, 3.8.2 Clients no longer crashed when receiving PM channel messages. --- lib/PMChannel.js | 1 + lib/channel.js | 40 ++++++++++++++++++++-------------------- lib/message.js | 8 +++++++- package.json | 2 +- src/PMChannel.js | 1 + src/channel.js | 9 ++++----- src/message.js | 8 +++++++- test/bot.1.js | 8 ++------ 8 files changed, 43 insertions(+), 34 deletions(-) diff --git a/lib/PMChannel.js b/lib/PMChannel.js index 0dbc0405e..f777d342c 100644 --- a/lib/PMChannel.js +++ b/lib/PMChannel.js @@ -11,6 +11,7 @@ var PMChannel = (function () { this.user = client.getUser("id", data.recipient.id); this.id = data.id; this.messages = []; + this.client = client; } _createClass(PMChannel, [{ diff --git a/lib/channel.js b/lib/channel.js index fbaa8ce4c..4ff1e673c 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -18,32 +18,32 @@ var Channel = (function () { this.messages = []; this.roles = []; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; + if (data.permission_overwrites) { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; - try { - for (var _iterator = data.permission_overwrites[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var role = _step.value; - - this.roles.push(new ChannelPermissions(role, this)); - } - - //this.isPrivate = isPrivate; //not sure about the implementation of this... - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); + for (var _iterator = data.permission_overwrites[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var role = _step.value; + + this.roles.push(new ChannelPermissions(role, this)); } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; } finally { - if (_didIteratorError) { - throw _iteratorError; + try { + if (!_iteratorNormalCompletion && _iterator["return"]) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } } } - } + } //this.isPrivate = isPrivate; //not sure about the implementation of this... } _createClass(Channel, [{ diff --git a/lib/message.js b/lib/message.js index 2e2ddd69d..a156acc81 100644 --- a/lib/message.js +++ b/lib/message.js @@ -20,7 +20,13 @@ var Message = (function () { this.editedTimestamp = data.edited_timestamp; this.content = data.content.trim(); this.channel = channel; - this.author = this.channel.server.getMember("id", author.id); + + if (this.isPrivate) { + this.author = this.channel.client.getUser("id", author.id); + } else { + this.author = this.channel.server.getMember("id", author.id) || this.channel.client.getUser("id", author.id); + } + this.attachments = data.attachments; } diff --git a/package.json b/package.json index b7cd03391..16c7552a3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.8.1", + "version": "3.8.2", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { diff --git a/src/PMChannel.js b/src/PMChannel.js index d7985f9c4..d2814afe5 100644 --- a/src/PMChannel.js +++ b/src/PMChannel.js @@ -3,6 +3,7 @@ class PMChannel { this.user = client.getUser("id", data.recipient.id); this.id = data.id; this.messages = []; + this.client = client; } addMessage(data){ diff --git a/src/channel.js b/src/channel.js index 6e3b2ef99..e5bef86e2 100644 --- a/src/channel.js +++ b/src/channel.js @@ -11,11 +11,10 @@ class Channel { this.messages = []; this.roles = []; - for (var role of data.permission_overwrites) { - - this.roles.push( new ChannelPermissions(role, this) ); - - } + if(data.permission_overwrites) + for (var role of data.permission_overwrites) { + this.roles.push( new ChannelPermissions(role, this) ); + } //this.isPrivate = isPrivate; //not sure about the implementation of this... } diff --git a/src/message.js b/src/message.js index 1cbc8be7e..991ae7677 100644 --- a/src/message.js +++ b/src/message.js @@ -12,7 +12,13 @@ class Message{ this.editedTimestamp = data.edited_timestamp; this.content = data.content.trim(); this.channel = channel; - this.author = this.channel.server.getMember("id", author.id); + + if(this.isPrivate){ + this.author = this.channel.client.getUser("id", author.id); + }else{ + this.author = this.channel.server.getMember("id", author.id) || this.channel.client.getUser("id", author.id); + } + this.attachments = data.attachments; } diff --git a/test/bot.1.js b/test/bot.1.js index 55c57651a..97ca23558 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -22,13 +22,9 @@ mybot.on("message", function (message) { user = message.sender; } - console.log("the ID is ", user.id); + console.log( mybot.getUser("username", "meew0") ); - for(key in message.channel.permissionsOf(user)){ - console.log(key); - } - - mybot.reply(message, user + "'s evaluated permissions in this channel are " + message.channel.permissionsOf(user).sendTTSMessages); + mybot.reply(message, JSON.stringify(message.mentions, null, 4)); }); From 0c5caefa9f4e53ab9d02eb91b8c1a467dda26096 Mon Sep 17 00:00:00 2001 From: Neto Becker Date: Thu, 15 Oct 2015 11:41:18 -0300 Subject: [PATCH 138/151] store gameId on user object --- lib/ChannelPermissions.js | 2 +- lib/Client.js | 7 +++++-- lib/Endpoints.js | 2 +- lib/EvaluatedPermissions.js | 2 +- lib/Member.js | 2 +- lib/PMChannel.js | 2 +- lib/ServerPermissions.js | 2 +- lib/channel.js | 2 +- lib/index.js | 2 +- lib/internal.js | 2 +- lib/invite.js | 2 +- lib/message.js | 2 +- lib/server.js | 2 +- lib/user.js | 3 ++- src/Client.js | 5 ++++- src/user.js | 1 + 16 files changed, 24 insertions(+), 16 deletions(-) diff --git a/lib/ChannelPermissions.js b/lib/ChannelPermissions.js index bbc8545db..71d7da55d 100644 --- a/lib/ChannelPermissions.js +++ b/lib/ChannelPermissions.js @@ -179,4 +179,4 @@ var ChannelPermissions = (function () { return ChannelPermissions; })(); -module.exports = ChannelPermissions; \ No newline at end of file +module.exports = ChannelPermissions; diff --git a/lib/Client.js b/lib/Client.js index f02f8f1d6..2d0ba4a34 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1091,6 +1091,7 @@ var Client = (function () { gameId: data.game_id }); userInCache.status = data.status; + userInCache.gameId = data.game_id; } else { //one of their details changed. self.userCache[self.userCache.indexOf(userInCache)] = presenceUser; @@ -1288,7 +1289,9 @@ var Client = (function () { for (var _iterator9 = data.presences[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) { var presence = _step9.value; - self.getUser("id", presence.user.id).status = presence.status; + var user = self.getUser("id", presence.user.id); + user.status = presence.status; + user.gameId = presence.game_id; } } catch (err) { _didIteratorError9 = true; @@ -1864,4 +1867,4 @@ var Client = (function () { return Client; })(); -module.exports = Client; \ No newline at end of file +module.exports = Client; diff --git a/lib/Endpoints.js b/lib/Endpoints.js index 271b465eb..e55f0f580 100644 --- a/lib/Endpoints.js +++ b/lib/Endpoints.js @@ -10,4 +10,4 @@ exports.LOGIN = exports.AUTH + "/login"; exports.LOGOUT = exports.AUTH + "/logout"; exports.USERS = exports.API + "/users"; exports.SERVERS = exports.API + "/guilds"; -exports.CHANNELS = exports.API + "/channels"; \ No newline at end of file +exports.CHANNELS = exports.API + "/channels"; diff --git a/lib/EvaluatedPermissions.js b/lib/EvaluatedPermissions.js index b441500cf..ed213ac6e 100644 --- a/lib/EvaluatedPermissions.js +++ b/lib/EvaluatedPermissions.js @@ -169,4 +169,4 @@ var EvaluatedPermissions = (function () { return EvaluatedPermissions; })(); -module.exports = EvaluatedPermissions; \ No newline at end of file +module.exports = EvaluatedPermissions; diff --git a/lib/Member.js b/lib/Member.js index ba29467db..e2596b7ea 100644 --- a/lib/Member.js +++ b/lib/Member.js @@ -222,4 +222,4 @@ var Member = (function (_User) { return Member; })(User); -module.exports = Member; \ No newline at end of file +module.exports = Member; diff --git a/lib/PMChannel.js b/lib/PMChannel.js index f777d342c..0f4bb36ba 100644 --- a/lib/PMChannel.js +++ b/lib/PMChannel.js @@ -69,4 +69,4 @@ var PMChannel = (function () { return PMChannel; })(); -module.exports = PMChannel; \ No newline at end of file +module.exports = PMChannel; diff --git a/lib/ServerPermissions.js b/lib/ServerPermissions.js index 73148ca06..e730fcd42 100644 --- a/lib/ServerPermissions.js +++ b/lib/ServerPermissions.js @@ -199,4 +199,4 @@ var ServerPermissions = (function () { return ServerPermissions; })(); -module.exports = ServerPermissions; \ No newline at end of file +module.exports = ServerPermissions; diff --git a/lib/channel.js b/lib/channel.js index 4ff1e673c..42e701b10 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -149,4 +149,4 @@ var Channel = (function () { return Channel; })(); -module.exports = Channel; \ No newline at end of file +module.exports = Channel; diff --git a/lib/index.js b/lib/index.js index 6a2f82f05..f0c3c0ab7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -9,4 +9,4 @@ var Discord = { Client: Client }; -module.exports = Discord; \ No newline at end of file +module.exports = Discord; diff --git a/lib/internal.js b/lib/internal.js index 3acf5940b..e8b3385da 100644 --- a/lib/internal.js +++ b/lib/internal.js @@ -200,4 +200,4 @@ Internal.XHR.setUsername = function (token, avatar, email, newPassword, password }); }; -exports.Internal = Internal; \ No newline at end of file +exports.Internal = Internal; diff --git a/lib/invite.js b/lib/invite.js index 5f51dc1a9..7bc8204bd 100644 --- a/lib/invite.js +++ b/lib/invite.js @@ -32,4 +32,4 @@ var Invite = (function () { return Invite; })(); -module.exports = Invite; \ No newline at end of file +module.exports = Invite; diff --git a/lib/message.js b/lib/message.js index a156acc81..7152b1d0f 100644 --- a/lib/message.js +++ b/lib/message.js @@ -82,4 +82,4 @@ var Message = (function () { return Message; })(); -module.exports = Message; \ No newline at end of file +module.exports = Message; diff --git a/lib/server.js b/lib/server.js index 871e30928..4b225584a 100644 --- a/lib/server.js +++ b/lib/server.js @@ -341,4 +341,4 @@ var Server = (function () { return Server; })(); -module.exports = Server; \ No newline at end of file +module.exports = Server; diff --git a/lib/user.js b/lib/user.js index 9a3d64c88..cb6663852 100644 --- a/lib/user.js +++ b/lib/user.js @@ -13,6 +13,7 @@ var User = (function () { this.id = data.id; this.avatar = data.avatar; this.status = data.status || "offline"; + this.gameId = data.game_id || null; } // access using user.avatarURL; @@ -54,4 +55,4 @@ var User = (function () { return User; })(); -module.exports = User; \ No newline at end of file +module.exports = User; diff --git a/src/Client.js b/src/Client.js index 1900642f7..79da43ec1 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1000,6 +1000,7 @@ class Client { gameId: data.game_id }); userInCache.status = data.status; + userInCache.gameId = data.game_id; } else { //one of their details changed. self.userCache[self.userCache.indexOf(userInCache)] = presenceUser; @@ -1168,7 +1169,9 @@ class Client { } for (var presence of data.presences) { - self.getUser("id", presence.user.id).status = presence.status; + var user = self.getUser("id", presence.user.id); + user.status = presence.status; + user.gameId = presence.game_id; } return server; diff --git a/src/user.js b/src/user.js index 9686fed27..30af4f3e6 100644 --- a/src/user.js +++ b/src/user.js @@ -5,6 +5,7 @@ class User{ this.id = data.id; this.avatar = data.avatar; this.status = data.status || "offline"; + this.gameId = data.game_id || null; } // access using user.avatarURL; From 0e8264c9cee8113baff4b2fc72bdfc988dd4c6ee Mon Sep 17 00:00:00 2001 From: Neto Becker Date: Thu, 15 Oct 2015 11:45:21 -0300 Subject: [PATCH 139/151] fix private messages --- lib/Client.js | 9 +++++++-- src/Client.js | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 2d0ba4a34..cc86f6f87 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1013,7 +1013,12 @@ var Client = (function () { if (!channel) { - var chann = self.addChannel(data, data.guild_id); + var chann; + if (data.is_private) { + chann = self.addPMChannel(data); + } else { + chann = self.addChannel(data, data.guild_id); + } var srv = self.getServer("id", data.guild_id); if (srv) { srv.addChannel(chann); @@ -1507,7 +1512,7 @@ var Client = (function () { for (var _iterator14 = self.pmChannelCache[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) { var pmc = _step14.value; - if (pmc.user.equals(destination)) { + if (pmc.user && pmc.user.equals(destination)) { resolve(pmc.id); return; } diff --git a/src/Client.js b/src/Client.js index 79da43ec1..ad9b33524 100644 --- a/src/Client.js +++ b/src/Client.js @@ -920,7 +920,12 @@ class Client { if (!channel) { - var chann = self.addChannel(data, data.guild_id); + var chann; + if (data.is_private) { + chann = self.addPMChannel(data); + } else { + chann = self.addChannel(data, data.guild_id); + } var srv = self.getServer("id", data.guild_id); if (srv) { srv.addChannel(chann); @@ -1268,7 +1273,7 @@ class Client { //check if we have a PM for (var pmc of self.pmChannelCache) { - if (pmc.user.equals(destination)) { + if (pmc.user && pmc.user.equals(destination)) { resolve(pmc.id); return; } From 23fae86ccb8c061706ee2847bccb239ecac1b3c8 Mon Sep 17 00:00:00 2001 From: Neto Becker Date: Thu, 15 Oct 2015 11:55:18 -0300 Subject: [PATCH 140/151] removed new line on end of files --- lib/ChannelPermissions.js | 2 +- lib/Client.js | 2 +- lib/Endpoints.js | 2 +- lib/EvaluatedPermissions.js | 2 +- lib/Member.js | 2 +- lib/PMChannel.js | 2 +- lib/ServerPermissions.js | 2 +- lib/channel.js | 2 +- lib/index.js | 2 +- lib/internal.js | 2 +- lib/invite.js | 2 +- lib/message.js | 2 +- lib/server.js | 2 +- lib/user.js | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/ChannelPermissions.js b/lib/ChannelPermissions.js index 71d7da55d..bbc8545db 100644 --- a/lib/ChannelPermissions.js +++ b/lib/ChannelPermissions.js @@ -179,4 +179,4 @@ var ChannelPermissions = (function () { return ChannelPermissions; })(); -module.exports = ChannelPermissions; +module.exports = ChannelPermissions; \ No newline at end of file diff --git a/lib/Client.js b/lib/Client.js index cc86f6f87..7cf2e0ec6 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1872,4 +1872,4 @@ var Client = (function () { return Client; })(); -module.exports = Client; +module.exports = Client; \ No newline at end of file diff --git a/lib/Endpoints.js b/lib/Endpoints.js index e55f0f580..271b465eb 100644 --- a/lib/Endpoints.js +++ b/lib/Endpoints.js @@ -10,4 +10,4 @@ exports.LOGIN = exports.AUTH + "/login"; exports.LOGOUT = exports.AUTH + "/logout"; exports.USERS = exports.API + "/users"; exports.SERVERS = exports.API + "/guilds"; -exports.CHANNELS = exports.API + "/channels"; +exports.CHANNELS = exports.API + "/channels"; \ No newline at end of file diff --git a/lib/EvaluatedPermissions.js b/lib/EvaluatedPermissions.js index ed213ac6e..b441500cf 100644 --- a/lib/EvaluatedPermissions.js +++ b/lib/EvaluatedPermissions.js @@ -169,4 +169,4 @@ var EvaluatedPermissions = (function () { return EvaluatedPermissions; })(); -module.exports = EvaluatedPermissions; +module.exports = EvaluatedPermissions; \ No newline at end of file diff --git a/lib/Member.js b/lib/Member.js index e2596b7ea..ba29467db 100644 --- a/lib/Member.js +++ b/lib/Member.js @@ -222,4 +222,4 @@ var Member = (function (_User) { return Member; })(User); -module.exports = Member; +module.exports = Member; \ No newline at end of file diff --git a/lib/PMChannel.js b/lib/PMChannel.js index 0f4bb36ba..f777d342c 100644 --- a/lib/PMChannel.js +++ b/lib/PMChannel.js @@ -69,4 +69,4 @@ var PMChannel = (function () { return PMChannel; })(); -module.exports = PMChannel; +module.exports = PMChannel; \ No newline at end of file diff --git a/lib/ServerPermissions.js b/lib/ServerPermissions.js index e730fcd42..73148ca06 100644 --- a/lib/ServerPermissions.js +++ b/lib/ServerPermissions.js @@ -199,4 +199,4 @@ var ServerPermissions = (function () { return ServerPermissions; })(); -module.exports = ServerPermissions; +module.exports = ServerPermissions; \ No newline at end of file diff --git a/lib/channel.js b/lib/channel.js index 42e701b10..4ff1e673c 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -149,4 +149,4 @@ var Channel = (function () { return Channel; })(); -module.exports = Channel; +module.exports = Channel; \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index f0c3c0ab7..6a2f82f05 100644 --- a/lib/index.js +++ b/lib/index.js @@ -9,4 +9,4 @@ var Discord = { Client: Client }; -module.exports = Discord; +module.exports = Discord; \ No newline at end of file diff --git a/lib/internal.js b/lib/internal.js index e8b3385da..3acf5940b 100644 --- a/lib/internal.js +++ b/lib/internal.js @@ -200,4 +200,4 @@ Internal.XHR.setUsername = function (token, avatar, email, newPassword, password }); }; -exports.Internal = Internal; +exports.Internal = Internal; \ No newline at end of file diff --git a/lib/invite.js b/lib/invite.js index 7bc8204bd..5f51dc1a9 100644 --- a/lib/invite.js +++ b/lib/invite.js @@ -32,4 +32,4 @@ var Invite = (function () { return Invite; })(); -module.exports = Invite; +module.exports = Invite; \ No newline at end of file diff --git a/lib/message.js b/lib/message.js index 7152b1d0f..a156acc81 100644 --- a/lib/message.js +++ b/lib/message.js @@ -82,4 +82,4 @@ var Message = (function () { return Message; })(); -module.exports = Message; +module.exports = Message; \ No newline at end of file diff --git a/lib/server.js b/lib/server.js index 4b225584a..871e30928 100644 --- a/lib/server.js +++ b/lib/server.js @@ -341,4 +341,4 @@ var Server = (function () { return Server; })(); -module.exports = Server; +module.exports = Server; \ No newline at end of file diff --git a/lib/user.js b/lib/user.js index cb6663852..1f0fb0eed 100644 --- a/lib/user.js +++ b/lib/user.js @@ -55,4 +55,4 @@ var User = (function () { return User; })(); -module.exports = User; +module.exports = User; \ No newline at end of file From 72385494cba6ea2abefee8b5f23c59a92528889e Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 17 Oct 2015 11:00:45 +0100 Subject: [PATCH 141/151] 3.8.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 16c7552a3..379bc779a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.8.2", + "version": "3.8.3", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From f0ae575aa03015db984fc38622a838174c4f59e0 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 25 Oct 2015 17:52:29 +0000 Subject: [PATCH 142/151] Updated grunt build file Will now work on Electron between files (compiled in loose mode) --- gruntfile.js | 4 + lib/ChannelPermissions.js | 184 +--- lib/Client.js | 1946 ++------------------------------- lib/Endpoints.js | 14 +- lib/EvaluatedPermissions.js | 173 +-- lib/Member.js | 229 +--- lib/PMChannel.js | 73 +- lib/channel.js | 154 +-- lib/index.js | 13 +- lib/internal.js | 204 +--- lib/invite.js | 36 +- lib/message.js | 88 +- package.json | 2 +- web-dist/discord.3.8.4.js | 1534 ++++++++++++++++++++++++++ web-dist/discord.min.3.8.4.js | 3 + 15 files changed, 1632 insertions(+), 3025 deletions(-) create mode 100644 web-dist/discord.3.8.4.js create mode 100644 web-dist/discord.min.3.8.4.js diff --git a/gruntfile.js b/gruntfile.js index 298e8c7c9..eab691c49 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -6,6 +6,10 @@ module.exports = function (grunt) { pkg: grunt.file.readJSON("package.json"), // define source files and their destinations babel: { + options: { + loose: "all", + compact: true + }, dist: { files: [{ expand: true, diff --git a/lib/ChannelPermissions.js b/lib/ChannelPermissions.js index bbc8545db..e5fe374b5 100644 --- a/lib/ChannelPermissions.js +++ b/lib/ChannelPermissions.js @@ -1,182 +1,2 @@ -"use strict"; - -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var ChannelPermissions = (function () { - function ChannelPermissions(data, channel) { - _classCallCheck(this, ChannelPermissions); - - var self = this; - - function getBit(x) { - return (self.packed >>> x & 1) === 1; - } - - this.type = data.type; //either member or role - this.id = data.id; - - if (this.type === "member") { - this.packed = channel.server.getMember("id", data.id).evalPerms.packed; - } else { - this.packed = channel.server.getRole(data.id).packed; - } - - this.packed = this.packed & ~data.deny; - this.packed = this.packed | data.allow; - - this.deny = data.deny; - this.allow = data.allow; - } - - _createClass(ChannelPermissions, [{ - key: "getBit", - value: function getBit(x) { - return (this.packed >>> x & 1) === 1; - } - }, { - key: "setBit", - value: function setBit() {} - }, { - key: "createInstantInvite", - get: function get() { - return this.getBit(0); - }, - set: function set(val) { - this.setBit(0, val); - } - }, { - key: "manageRoles", - get: function get() { - return this.getBit(3); - }, - set: function set(val) { - this.setBit(3, val); - } - }, { - key: "manageChannels", - get: function get() { - return this.getBit(4); - }, - set: function set(val) { - this.setBit(4, val); - } - }, { - key: "readMessages", - get: function get() { - return this.getBit(10); - }, - set: function set(val) { - this.setBit(10, val); - } - }, { - key: "sendMessages", - get: function get() { - return this.getBit(11); - }, - set: function set(val) { - this.setBit(11, val); - } - }, { - key: "sendTTSMessages", - get: function get() { - return this.getBit(12); - }, - set: function set(val) { - this.setBit(12, val); - } - }, { - key: "manageMessages", - get: function get() { - return this.getBit(13); - }, - set: function set(val) { - this.setBit(13, val); - } - }, { - key: "embedLinks", - get: function get() { - return this.getBit(14); - }, - set: function set(val) { - this.setBit(14, val); - } - }, { - key: "attachFiles", - get: function get() { - return this.getBit(15); - }, - set: function set(val) { - this.setBit(15, val); - } - }, { - key: "readMessageHistory", - get: function get() { - return this.getBit(16); - }, - set: function set(val) { - this.setBit(16, val); - } - }, { - key: "mentionEveryone", - get: function get() { - return this.getBit(17); - }, - set: function set(val) { - this.setBit(17, val); - } - }, { - key: "voiceConnect", - get: function get() { - return this.getBit(20); - }, - set: function set(val) { - this.setBit(20, val); - } - }, { - key: "voiceSpeak", - get: function get() { - return this.getBit(21); - }, - set: function set(val) { - this.setBit(21, val); - } - }, { - key: "voiceMuteMembers", - get: function get() { - return this.getBit(22); - }, - set: function set(val) { - this.setBit(22, val); - } - }, { - key: "voiceDeafenMembers", - get: function get() { - return this.getBit(23); - }, - set: function set(val) { - this.setBit(23, val); - } - }, { - key: "voiceMoveMembers", - get: function get() { - return this.getBit(24); - }, - set: function set(val) { - this.setBit(24, val); - } - }, { - key: "voiceUseVoiceActivation", - get: function get() { - return this.getBit(25); - }, - set: function set(val) { - this.setBit(25, val); - } - }]); - - return ChannelPermissions; -})(); - -module.exports = ChannelPermissions; \ No newline at end of file +"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var ChannelPermissions=(function(){function ChannelPermissions(data,channel){_classCallCheck(this,ChannelPermissions);var self=this;function getBit(x){return (self.packed >>> x & 1) === 1;}this.type = data.type; //either member or role +this.id = data.id;if(this.type === "member"){this.packed = channel.server.getMember("id",data.id).evalPerms.packed;}else {this.packed = channel.server.getRole(data.id).packed;}this.packed = this.packed & ~data.deny;this.packed = this.packed | data.allow;this.deny = data.deny;this.allow = data.allow;}ChannelPermissions.prototype.getBit = function getBit(x){return (this.packed >>> x & 1) === 1;};ChannelPermissions.prototype.setBit = function setBit(){};_createClass(ChannelPermissions,[{key:"createInstantInvite",get:function get(){return this.getBit(0);},set:function set(val){this.setBit(0,val);}},{key:"manageRoles",get:function get(){return this.getBit(3);},set:function set(val){this.setBit(3,val);}},{key:"manageChannels",get:function get(){return this.getBit(4);},set:function set(val){this.setBit(4,val);}},{key:"readMessages",get:function get(){return this.getBit(10);},set:function set(val){this.setBit(10,val);}},{key:"sendMessages",get:function get(){return this.getBit(11);},set:function set(val){this.setBit(11,val);}},{key:"sendTTSMessages",get:function get(){return this.getBit(12);},set:function set(val){this.setBit(12,val);}},{key:"manageMessages",get:function get(){return this.getBit(13);},set:function set(val){this.setBit(13,val);}},{key:"embedLinks",get:function get(){return this.getBit(14);},set:function set(val){this.setBit(14,val);}},{key:"attachFiles",get:function get(){return this.getBit(15);},set:function set(val){this.setBit(15,val);}},{key:"readMessageHistory",get:function get(){return this.getBit(16);},set:function set(val){this.setBit(16,val);}},{key:"mentionEveryone",get:function get(){return this.getBit(17);},set:function set(val){this.setBit(17,val);}},{key:"voiceConnect",get:function get(){return this.getBit(20);},set:function set(val){this.setBit(20,val);}},{key:"voiceSpeak",get:function get(){return this.getBit(21);},set:function set(val){this.setBit(21,val);}},{key:"voiceMuteMembers",get:function get(){return this.getBit(22);},set:function set(val){this.setBit(22,val);}},{key:"voiceDeafenMembers",get:function get(){return this.getBit(23);},set:function set(val){this.setBit(23,val);}},{key:"voiceMoveMembers",get:function get(){return this.getBit(24);},set:function set(val){this.setBit(24,val);}},{key:"voiceUseVoiceActivation",get:function get(){return this.getBit(25);},set:function set(val){this.setBit(25,val);}}]);return ChannelPermissions;})();module.exports = ChannelPermissions; diff --git a/lib/Client.js b/lib/Client.js index 7cf2e0ec6..335061bd6 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1,1875 +1,75 @@ //discord.js modules -"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 Endpoints = require("./Endpoints.js"); -var User = require("./user.js"); -var Server = require("./server.js"); -var Channel = require("./channel.js"); -var Message = require("./message.js"); -var Invite = require("./invite.js"); -var PMChannel = require("./PMChannel.js"); - -var gameMap = require("../ref/gameMap.json"); - -//node modules -var request = require("superagent"); -var WebSocket = require("ws"); -var fs = require("fs"); - -var defaultOptions = { - queue: false -}; - -var Client = (function () { - function Client() { - var options = arguments.length <= 0 || arguments[0] === undefined ? defaultOptions : arguments[0]; - var token = arguments.length <= 1 || arguments[1] === undefined ? undefined : arguments[1]; - - _classCallCheck(this, Client); - - /* - When created, if a token is specified the Client will - try connecting with it. If the token is incorrect, no - further efforts will be made to connect. - */ - this.options = options; - this.options.queue = this.options.queue; - this.token = token; - this.state = 0; - this.websocket = null; - this.events = {}; - this.user = null; - this.alreadySentData = false; - this.serverCreateListener = {}; - this.typingIntervals = {}; - this.email = "abc"; - this.password = "abc"; - - /* - State values: - 0 - idle - 1 - logging in - 2 - logged in - 3 - ready - 4 - disconnected - */ - - this.userCache = []; - this.channelCache = []; - this.serverCache = []; - this.pmChannelCache = []; - this.readyTime = null; - this.checkingQueue = {}; - this.userTypingListener = {}; - this.queue = {}; - - this.__idleTime = null; - this.__gameId = null; - } - - _createClass(Client, [{ - key: "sendPacket", - value: function sendPacket(JSONObject) { - if (this.websocket.readyState === 1) { - this.websocket.send(JSON.stringify(JSONObject)); - } - } - - //def debug - }, { - key: "debug", - value: function debug(message) { - this.trigger("debug", message); - } - }, { - key: "on", - value: function on(event, fn) { - this.events[event] = fn; - } - }, { - key: "off", - value: function off(event) { - this.events[event] = null; - } - }, { - key: "keepAlive", - value: function keepAlive() { - this.debug("keep alive triggered"); - this.sendPacket({ - op: 1, - d: Date.now() - }); - } - - //def trigger - }, { - key: "trigger", - value: function trigger(event) { - var args = []; - for (var arg in arguments) { - args.push(arguments[arg]); - } - var evt = this.events[event]; - if (evt) { - evt.apply(this, args.slice(1)); - } - } - - //def login - }, { - key: "login", - value: function login() { - var email = arguments.length <= 0 || arguments[0] === undefined ? "foo@bar.com" : arguments[0]; - var password = arguments.length <= 1 || arguments[1] === undefined ? "pass1234" : arguments[1]; - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, token) {} : arguments[2]; - - var self = this; - - return new Promise(function (resolve, reject) { - if (self.state === 0 || self.state === 4) { - - self.state = 1; //set the state to logging in - - self.email = email; - self.password = password; - - request.post(Endpoints.LOGIN).send({ - email: email, - password: password - }).end(function (err, res) { - - if (err) { - self.state = 4; //set state to disconnected - self.trigger("disconnected"); - if (self.websocket) { - self.websocket.close(); - } - callback(err); - reject(err); - } else { - self.state = 2; //set state to logged in (not yet ready) - self.token = res.body.token; //set our token - - self.getGateway().then(function (url) { - self.createws(url); - callback(null, self.token); - resolve(self.token); - })["catch"](function (err) { - callback(err); - reject(err); - }); +"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 Endpoints=require("./Endpoints.js");var User=require("./user.js");var Server=require("./server.js");var Channel=require("./channel.js");var Message=require("./message.js");var Invite=require("./invite.js");var PMChannel=require("./PMChannel.js");var gameMap=require("../ref/gameMap.json"); //node modules +var request=require("superagent");var WebSocket=require("ws");var fs=require("fs");var defaultOptions={queue:false};var Client=(function(){function Client(){var options=arguments.length <= 0 || arguments[0] === undefined?defaultOptions:arguments[0];var token=arguments.length <= 1 || arguments[1] === undefined?undefined:arguments[1];_classCallCheck(this,Client); /* + When created, if a token is specified the Client will + try connecting with it. If the token is incorrect, no + further efforts will be made to connect. + */this.options = options;this.options.queue = this.options.queue;this.token = token;this.state = 0;this.websocket = null;this.events = {};this.user = null;this.alreadySentData = false;this.serverCreateListener = {};this.typingIntervals = {};this.email = "abc";this.password = "abc"; /* + State values: + 0 - idle + 1 - logging in + 2 - logged in + 3 - ready + 4 - disconnected + */this.userCache = [];this.channelCache = [];this.serverCache = [];this.pmChannelCache = [];this.readyTime = null;this.checkingQueue = {};this.userTypingListener = {};this.queue = {};this.__idleTime = null;this.__gameId = null;}Client.prototype.sendPacket = function sendPacket(JSONObject){if(this.websocket.readyState === 1){this.websocket.send(JSON.stringify(JSONObject));}}; //def debug +Client.prototype.debug = function debug(message){this.trigger("debug",message);};Client.prototype.on = function on(event,fn){this.events[event] = fn;};Client.prototype.off = function off(event){this.events[event] = null;};Client.prototype.keepAlive = function keepAlive(){this.debug("keep alive triggered");this.sendPacket({op:1,d:Date.now()});}; //def trigger +Client.prototype.trigger = function trigger(event){var args=[];for(var arg in arguments) {args.push(arguments[arg]);}var evt=this.events[event];if(evt){evt.apply(this,args.slice(1));}}; //def login +Client.prototype.login = function login(){var email=arguments.length <= 0 || arguments[0] === undefined?"foo@bar.com":arguments[0];var password=arguments.length <= 1 || arguments[1] === undefined?"pass1234":arguments[1];var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,token){}:arguments[2];var self=this;return new Promise(function(resolve,reject){if(self.state === 0 || self.state === 4){self.state = 1; //set the state to logging in +self.email = email;self.password = password;request.post(Endpoints.LOGIN).send({email:email,password:password}).end(function(err,res){if(err){self.state = 4; //set state to disconnected +self.trigger("disconnected");if(self.websocket){self.websocket.close();}callback(err);reject(err);}else {self.state = 2; //set state to logged in (not yet ready) +self.token = res.body.token; //set our token +self.getGateway().then(function(url){self.createws(url);callback(null,self.token);resolve(self.token);})["catch"](function(err){callback(err);reject(err);});}});}else {reject(new Error("Client already logging in or ready"));}});};Client.prototype.logout = function logout(){var callback=arguments.length <= 0 || arguments[0] === undefined?function(err){}:arguments[0];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.LOGOUT).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {self.websocket.close();self.state = 4;callback();resolve();}});});};Client.prototype.createServer = function createServer(name,region){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,server){}:arguments[2];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.SERVERS).set("authorization",self.token).send({name:name,region:region}).end(function(err,res){if(err){callback(err);reject(err);}else { // potentially redundant in future +// creating here does NOT give us the channels of the server +// so we must wait for the guild_create event. +self.serverCreateListener[res.body.id] = [resolve,callback]; /*var srv = self.addServer(res.body); + callback(null, srv); + resolve(srv);*/}});});};Client.prototype.createChannel = function createChannel(server,channelName,channelType){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,chann){}:arguments[3];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.SERVERS + "/" + self.resolveServerID(server) + "/channels").set("authorization",self.token).send({name:channelName,type:channelType}).end(function(err,res){if(err){callback(err);reject(err);}else {var server=self.getServer("id",res.body.guild_id);var chann=self.addChannel(res.body,res.body.guild_id);server.addChannel(chann);callback(null,chann);resolve(chann);}});});};Client.prototype.leaveServer = function leaveServer(server){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,server){}:arguments[1];var self=this;return new Promise(function(resolve,reject){request.del(Endpoints.SERVERS + "/" + self.resolveServerID(server)).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {self.serverCache.splice(self.serverCache.indexOf(server),1);callback(null);resolve();}});});};Client.prototype.createInvite = function createInvite(serverOrChannel,options){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,invite){}:arguments[2];var self=this;return new Promise(function(resolve,reject){var destination;if(serverOrChannel instanceof Server){destination = serverOrChannel.id;}else if(serverOrChannel instanceof Channel){destination = serverOrChannel.id;}else {destination = serverOrChannel;}options = options || {};options.max_age = options.maxAge || 0;options.max_uses = options.maxUses || 0;options.temporary = options.temporary || false;options.xkcdpass = options.xkcd || false;request.post(Endpoints.CHANNELS + "/" + destination + "/invites").set("authorization",self.token).send(options).end(function(err,res){if(err){callback(err);reject(err);}else {var inv=new Invite(res.body,self);callback(null,inv);resolve(inv);}});});};Client.prototype.startPM = function startPM(user){var self=this;return new Promise(function(resolve,reject){var userId=user;if(user instanceof User){userId = user.id;}request.post(Endpoints.USERS + "/" + self.user.id + "/channels").set("authorization",self.token).send({recipient_id:userId}).end(function(err,res){if(err){reject(err);}else {resolve(self.addPMChannel(res.body));}});});};Client.prototype.reply = function reply(destination,message,tts){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var self=this;return new Promise(function(response,reject){if(typeof tts === "function"){ // tts is a function, which means the developer wants this to be the callback +callback = tts;tts = false;}var user=destination.sender;self.sendMessage(destination,message,tts,callback,user + ", ").then(response)["catch"](reject);});};Client.prototype.deleteMessage = function deleteMessage(message,timeout){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,msg){}:arguments[2];var self=this;return new Promise(function(resolve,reject){if(timeout){setTimeout(remove,timeout);}else {remove();}function remove(){request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization",self.token).end(function(err,res){if(err){bad();}else {good();}});}function good(){callback();resolve();}function bad(err){callback(err);reject(err);}});};Client.prototype.updateMessage = function updateMessage(message,content){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,msg){}:arguments[2];var self=this;var prom=new Promise(function(resolve,reject){content = content instanceof Array?content.join("\n"):content;if(self.options.queue){if(!self.queue[message.channel.id]){self.queue[message.channel.id] = [];}self.queue[message.channel.id].push({action:"updateMessage",message:message,content:content,then:good,error:bad});self.checkQueue(message.channel.id);}else {self._updateMessage(message,content).then(good)["catch"](bad);}function good(msg){prom.message = msg;callback(null,msg);resolve(msg);}function bad(error){prom.error = error;callback(error);reject(error);}});return prom;};Client.prototype.setUsername = function setUsername(newName){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){request.patch(Endpoints.API + "/users/@me").set("authorization",self.token).send({avatar:self.user.avatar,email:self.email,new_password:null,password:self.password,username:newName}).end(function(err){callback(err);if(err)reject(err);else resolve();});});};Client.prototype.getChannelLogs = function getChannelLogs(channel){var amount=arguments.length <= 1 || arguments[1] === undefined?500:arguments[1];var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,logs){}:arguments[2];var self=this;return new Promise(function(resolve,reject){var channelID=channel;if(channel instanceof Channel){channelID = channel.id;}request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {var logs=[];var channel=self.getChannel("id",channelID);for(var _iterator=res.body,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var message=_ref;var mentions=[];for(var _iterator2=message.mentions,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var mention=_ref2;mentions.push(self.addUser(mention));}var author=self.addUser(message.author);logs.push(new Message(message,channel,mentions,author));}callback(null,logs);resolve(logs);}});});};Client.prototype.deleteChannel = function deleteChannel(channel){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){var channelID=channel;if(channel instanceof Channel){channelID = channel.id;}request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization",self.token).end(function(err){if(err){callback(err);reject(err);}else {callback(null);resolve();}});});};Client.prototype.joinServer = function joinServer(invite){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,server){}:arguments[1];var self=this;return new Promise(function(resolve,reject){var id=invite instanceof Invite?invite.code:invite;request.post(Endpoints.API + "/invite/" + id).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {if(self.getServer("id",res.body.guild.id)){resolve(self.getServer("id",res.body.guild.id));}else {self.serverCreateListener[res.body.guild.id] = [resolve,callback];}}});});};Client.prototype.sendFile = function sendFile(destination,file){var fileName=arguments.length <= 2 || arguments[2] === undefined?"image.png":arguments[2];var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var self=this;var prom=new Promise(function(resolve,reject){var fstream;if(typeof file === "string" || file instanceof String){fstream = fs.createReadStream(file);fileName = file;}else {fstream = file;}self.resolveDestination(destination).then(send)["catch"](bad);function send(destination){if(self.options.queue){ //queue send file too +if(!self.queue[destination]){self.queue[destination] = [];}self.queue[destination].push({action:"sendFile",attachment:fstream,attachmentName:fileName,then:good,error:bad});self.checkQueue(destination);}else { //not queue +self._sendFile(destination,fstream,fileName).then(good)["catch"](bad);}}function good(msg){prom.message = msg;callback(null,msg);resolve(msg);}function bad(err){prom.error = err;callback(err);reject(err);}});return prom;};Client.prototype.sendMessage = function sendMessage(destination,message,tts){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var premessage=arguments.length <= 4 || arguments[4] === undefined?"":arguments[4];var self=this;var prom=new Promise(function(resolve,reject){if(typeof tts === "function"){ // tts is a function, which means the developer wants this to be the callback +callback = tts;tts = false;}message = premessage + resolveMessage(message);var mentions=resolveMentions();self.resolveDestination(destination).then(send)["catch"](error);function error(err){callback(err);reject(err);}function send(destination){if(self.options.queue){ //we're QUEUEING messages, so sending them sequentially based on servers. +if(!self.queue[destination]){self.queue[destination] = [];}self.queue[destination].push({action:"sendMessage",content:message,mentions:mentions,tts:!!tts, //incase it's not a boolean +then:mgood,error:mbad});self.checkQueue(destination);}else {self._sendMessage(destination,message,tts,mentions).then(mgood)["catch"](mbad);}}function mgood(msg){prom.message = msg;callback(null,msg);resolve(msg);}function mbad(error){prom.error = error;callback(error);reject(error);}function resolveMessage(){var msg=message;if(message instanceof Array){msg = message.join("\n");}return msg;}function resolveMentions(){var _mentions=[];for(var _iterator3=message.match(/<@[^>]*>/g) || [],_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[Symbol.iterator]();;) {var _ref3;if(_isArray3){if(_i3 >= _iterator3.length)break;_ref3 = _iterator3[_i3++];}else {_i3 = _iterator3.next();if(_i3.done)break;_ref3 = _i3.value;}var mention=_ref3;_mentions.push(mention.substring(2,mention.length - 1));}return _mentions;}});return prom;}; //def createws +Client.prototype.createws = function createws(url){if(this.websocket)return false;var self=this; //good to go +this.websocket = new WebSocket(url); //open +this.websocket.onopen = function(){self.trySendConnData(); //try connecting +}; //close +this.websocket.onclose = function(){self.trigger("disconnected");}; //message +this.websocket.onmessage = function(e){var dat=false,data={};try{dat = JSON.parse(e.data);data = dat.d;}catch(err) {self.trigger("error",err,e);return;}self.trigger("raw",dat); //valid message +switch(dat.t){case "READY":self.debug("received ready packet");self.user = self.addUser(data.user);for(var _iterator4=data.guilds,_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[Symbol.iterator]();;) {var _ref4;if(_isArray4){if(_i4 >= _iterator4.length)break;_ref4 = _iterator4[_i4++];}else {_i4 = _iterator4.next();if(_i4.done)break;_ref4 = _i4.value;}var _server=_ref4;var server=self.addServer(_server);}for(var _iterator5=data.private_channels,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var _pmc=_ref5;var pmc=self.addPMChannel(_pmc);}self.trigger("ready");self.readyTime = Date.now();self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users.");self.state = 3;setInterval(function(){self.keepAlive.apply(self);},data.heartbeat_interval);break;case "MESSAGE_CREATE":self.debug("received message");var mentions=[];data.mentions = data.mentions || []; //for some reason this was not defined at some point? +for(var _iterator6=data.mentions,_isArray6=Array.isArray(_iterator6),_i6=0,_iterator6=_isArray6?_iterator6:_iterator6[Symbol.iterator]();;) {var _ref6;if(_isArray6){if(_i6 >= _iterator6.length)break;_ref6 = _iterator6[_i6++];}else {_i6 = _iterator6.next();if(_i6.done)break;_ref6 = _i6.value;}var mention=_ref6;mentions.push(self.addUser(mention));}var channel=self.getChannel("id",data.channel_id);if(channel){var msg=channel.addMessage(new Message(data,channel,mentions,self.addUser(data.author)));self.trigger("message",msg);}break;case "MESSAGE_DELETE":self.debug("message deleted");var channel=self.getChannel("id",data.channel_id);var message=channel.getMessage("id",data.id);if(message){self.trigger("messageDelete",channel,message);channel.messages.splice(channel.messages.indexOf(message),1);}else { //don't have the cache of that message ;( +self.trigger("messageDelete",channel);}break;case "MESSAGE_UPDATE":self.debug("message updated");var channel=self.getChannel("id",data.channel_id);var formerMessage=channel.getMessage("id",data.id);if(formerMessage){ //new message might be partial, so we need to fill it with whatever the old message was. +var info={};for(var key in formerMessage) {info[key] = formerMessage[key];}for(var key in data) {info[key] = data[key];}var mentions=[];for(var _iterator7=info.mentions,_isArray7=Array.isArray(_iterator7),_i7=0,_iterator7=_isArray7?_iterator7:_iterator7[Symbol.iterator]();;) {var _ref7;if(_isArray7){if(_i7 >= _iterator7.length)break;_ref7 = _iterator7[_i7++];}else {_i7 = _iterator7.next();if(_i7.done)break;_ref7 = _i7.value;}var mention=_ref7;mentions.push(self.addUser(mention));}var newMessage=new Message(info,channel,mentions,formerMessage.author);self.trigger("messageUpdate",newMessage,formerMessage);channel.messages[channel.messages.indexOf(formerMessage)] = newMessage;} // message isn't in cache, and if it's a partial it could cause +// all hell to break loose... best to just act as if nothing happened +break;case "GUILD_DELETE":var server=self.getServer("id",data.id);if(server){self.serverCache.splice(self.serverCache.indexOf(server),1);self.trigger("serverDelete",server);}break;case "CHANNEL_DELETE":var channel=self.getChannel("id",data.id);if(channel){var server=channel.server;if(server){server.channels.splice(server.channels.indexOf(channel),1);}self.trigger("channelDelete",channel);self.serverCache.splice(self.serverCache.indexOf(channel),1);}break;case "GUILD_CREATE":var server=self.getServer("id",data.id);if(!server){ //if server doesn't already exist because duh +server = self.addServer(data);} /*else if(server.channels.length === 0){ + + var srv = new Server(data, self); + for(channel of data.channels){ + srv.channels.push(new Channel(channel, data.id)); } - }); - } else { - reject(new Error("Client already logging in or ready")); - } - }); - } - }, { - key: "logout", - value: function logout() { - var callback = arguments.length <= 0 || arguments[0] === undefined ? function (err) {} : arguments[0]; - - var self = this; - - return new Promise(function (resolve, reject) { - - request.post(Endpoints.LOGOUT).set("authorization", self.token).end(function (err, res) { - - if (err) { - callback(err); - reject(err); - } else { - self.websocket.close(); - self.state = 4; - callback(); - resolve(); - } - }); - }); - } - }, { - key: "createServer", - value: function createServer(name, region) { - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, server) {} : arguments[2]; - - var self = this; - return new Promise(function (resolve, reject) { - - request.post(Endpoints.SERVERS).set("authorization", self.token).send({ - name: name, - region: region - }).end(function (err, res) { - if (err) { - callback(err); - reject(err); - } else { - // potentially redundant in future - // creating here does NOT give us the channels of the server - // so we must wait for the guild_create event. - self.serverCreateListener[res.body.id] = [resolve, callback]; - /*var srv = self.addServer(res.body); - callback(null, srv); - resolve(srv);*/ - } - }); - }); - } - }, { - key: "createChannel", - value: function createChannel(server, channelName, channelType) { - var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, chann) {} : arguments[3]; - - var self = this; - - return new Promise(function (resolve, reject) { - - request.post(Endpoints.SERVERS + "/" + self.resolveServerID(server) + "/channels").set("authorization", self.token).send({ - name: channelName, - type: channelType - }).end(function (err, res) { - - if (err) { - callback(err); - reject(err); - } else { - var server = self.getServer("id", res.body.guild_id); - var chann = self.addChannel(res.body, res.body.guild_id); - server.addChannel(chann); - callback(null, chann); - resolve(chann); - } - }); - }); - } - }, { - key: "leaveServer", - value: function leaveServer(server) { - var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, server) {} : arguments[1]; - - var self = this; - - return new Promise(function (resolve, reject) { - - request.del(Endpoints.SERVERS + "/" + self.resolveServerID(server)).set("authorization", self.token).end(function (err, res) { - - if (err) { - callback(err); - reject(err); - } else { - self.serverCache.splice(self.serverCache.indexOf(server), 1); - callback(null); - resolve(); - } - }); - }); - } - }, { - key: "createInvite", - value: function createInvite(serverOrChannel, options) { - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, invite) {} : arguments[2]; - - var self = this; - - return new Promise(function (resolve, reject) { - - var destination; - - if (serverOrChannel instanceof Server) { - destination = serverOrChannel.id; - } else if (serverOrChannel instanceof Channel) { - destination = serverOrChannel.id; - } else { - destination = serverOrChannel; - } - - options = options || {}; - options.max_age = options.maxAge || 0; - options.max_uses = options.maxUses || 0; - options.temporary = options.temporary || false; - options.xkcdpass = options.xkcd || false; - - request.post(Endpoints.CHANNELS + "/" + destination + "/invites").set("authorization", self.token).send(options).end(function (err, res) { - if (err) { - callback(err); - reject(err); - } else { - var inv = new Invite(res.body, self); - callback(null, inv); - resolve(inv); - } - }); - }); - } - }, { - key: "startPM", - value: function startPM(user) { - - var self = this; - - return new Promise(function (resolve, reject) { - var userId = user; - if (user instanceof User) { - userId = user.id; - } - request.post(Endpoints.USERS + "/" + self.user.id + "/channels").set("authorization", self.token).send({ - recipient_id: userId - }).end(function (err, res) { - if (err) { - reject(err); - } else { - resolve(self.addPMChannel(res.body)); - } - }); - }); - } - }, { - key: "reply", - value: function reply(destination, message, tts) { - var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; - - var self = this; - - return new Promise(function (response, reject) { - - if (typeof tts === "function") { - // tts is a function, which means the developer wants this to be the callback - callback = tts; - tts = false; - } - - var user = destination.sender; - self.sendMessage(destination, message, tts, callback, user + ", ").then(response)["catch"](reject); - }); - } - }, { - key: "deleteMessage", - value: function deleteMessage(message, timeout) { - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, msg) {} : arguments[2]; - - var self = this; - - return new Promise(function (resolve, reject) { - if (timeout) { - setTimeout(remove, timeout); - } else { - remove(); - } - - function remove() { - request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).end(function (err, res) { - if (err) { - bad(); - } else { - good(); - } - }); - } - - function good() { - callback(); - resolve(); - } - - function bad(err) { - callback(err); - reject(err); - } - }); - } - }, { - key: "updateMessage", - value: function updateMessage(message, content) { - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, msg) {} : arguments[2]; - - var self = this; - - var prom = new Promise(function (resolve, reject) { - - content = content instanceof Array ? content.join("\n") : content; - - if (self.options.queue) { - if (!self.queue[message.channel.id]) { - self.queue[message.channel.id] = []; - } - self.queue[message.channel.id].push({ - action: "updateMessage", - message: message, - content: content, - then: good, - error: bad - }); - - self.checkQueue(message.channel.id); - } else { - self._updateMessage(message, content).then(good)["catch"](bad); - } - - function good(msg) { - prom.message = msg; - callback(null, msg); - resolve(msg); - } - - function bad(error) { - prom.error = error; - callback(error); - reject(error); - } - }); - - return prom; - } - }, { - key: "setUsername", - value: function setUsername(newName) { - var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; - - var self = this; - - return new Promise(function (resolve, reject) { - request.patch(Endpoints.API + "/users/@me").set("authorization", self.token).send({ - avatar: self.user.avatar, - email: self.email, - new_password: null, - password: self.password, - username: newName - }).end(function (err) { - callback(err); - if (err) reject(err);else resolve(); - }); - }); - } - }, { - key: "getChannelLogs", - value: function getChannelLogs(channel) { - var amount = arguments.length <= 1 || arguments[1] === undefined ? 500 : arguments[1]; - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, logs) {} : arguments[2]; - - var self = this; - - return new Promise(function (resolve, reject) { - - var channelID = channel; - if (channel instanceof Channel) { - channelID = channel.id; - } - - request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization", self.token).end(function (err, res) { - - if (err) { - callback(err); - reject(err); - } else { - var logs = []; - - var channel = self.getChannel("id", channelID); - - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = res.body[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var message = _step.value; - - var mentions = []; - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; - - try { - for (var _iterator2 = message.mentions[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var mention = _step2.value; - - mentions.push(self.addUser(mention)); - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { - try { - if (!_iteratorNormalCompletion2 && _iterator2["return"]) { - _iterator2["return"](); - } - } finally { - if (_didIteratorError2) { - throw _iteratorError2; - } - } - } - - var author = self.addUser(message.author); - - logs.push(new Message(message, channel, mentions, author)); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - - callback(null, logs); - resolve(logs); - } - }); - }); - } - }, { - key: "deleteChannel", - value: function deleteChannel(channel) { - var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; - - var self = this; - - return new Promise(function (resolve, reject) { - - var channelID = channel; - if (channel instanceof Channel) { - channelID = channel.id; - } - - request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization", self.token).end(function (err) { - if (err) { - callback(err); - reject(err); - } else { - callback(null); - resolve(); - } - }); - }); - } - }, { - key: "joinServer", - value: function joinServer(invite) { - var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, server) {} : arguments[1]; - - var self = this; - - return new Promise(function (resolve, reject) { - - var id = invite instanceof Invite ? invite.code : invite; - - request.post(Endpoints.API + "/invite/" + id).set("authorization", self.token).end(function (err, res) { - if (err) { - callback(err); - reject(err); - } else { - if (self.getServer("id", res.body.guild.id)) { - resolve(self.getServer("id", res.body.guild.id)); - } else { - self.serverCreateListener[res.body.guild.id] = [resolve, callback]; - } - } - }); - }); - } - }, { - key: "sendFile", - value: function sendFile(destination, file) { - var fileName = arguments.length <= 2 || arguments[2] === undefined ? "image.png" : arguments[2]; - var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; - - var self = this; - - var prom = new Promise(function (resolve, reject) { - - var fstream; - - if (typeof file === "string" || file instanceof String) { - fstream = fs.createReadStream(file); - fileName = file; - } else { - fstream = file; - } - - self.resolveDestination(destination).then(send)["catch"](bad); - - function send(destination) { - if (self.options.queue) { - //queue send file too - if (!self.queue[destination]) { - self.queue[destination] = []; - } - - self.queue[destination].push({ - action: "sendFile", - attachment: fstream, - attachmentName: fileName, - then: good, - error: bad - }); - - self.checkQueue(destination); - } else { - //not queue - self._sendFile(destination, fstream, fileName).then(good)["catch"](bad); - } - } - - function good(msg) { - prom.message = msg; - callback(null, msg); - resolve(msg); - } - - function bad(err) { - prom.error = err; - callback(err); - reject(err); - } - }); - - return prom; - } - }, { - key: "sendMessage", - value: function sendMessage(destination, message, tts) { - var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; - var premessage = arguments.length <= 4 || arguments[4] === undefined ? "" : arguments[4]; - - var self = this; - - var prom = new Promise(function (resolve, reject) { - - if (typeof tts === "function") { - // tts is a function, which means the developer wants this to be the callback - callback = tts; - tts = false; - } - - message = premessage + resolveMessage(message); - var mentions = resolveMentions(); - self.resolveDestination(destination).then(send)["catch"](error); - - function error(err) { - callback(err); - reject(err); - } - - function send(destination) { - if (self.options.queue) { - //we're QUEUEING messages, so sending them sequentially based on servers. - if (!self.queue[destination]) { - self.queue[destination] = []; - } - - self.queue[destination].push({ - action: "sendMessage", - content: message, - mentions: mentions, - tts: !!tts, //incase it's not a boolean - then: mgood, - error: mbad - }); - - self.checkQueue(destination); - } else { - self._sendMessage(destination, message, tts, mentions).then(mgood)["catch"](mbad); - } - } - - function mgood(msg) { - prom.message = msg; - callback(null, msg); - resolve(msg); - } - - function mbad(error) { - prom.error = error; - callback(error); - reject(error); - } - - function resolveMessage() { - var msg = message; - if (message instanceof Array) { - msg = message.join("\n"); - } - return msg; - } - - function resolveMentions() { - var _mentions = []; - var _iteratorNormalCompletion3 = true; - var _didIteratorError3 = false; - var _iteratorError3 = undefined; - - try { - for (var _iterator3 = (message.match(/<@[^>]*>/g) || [])[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { - var mention = _step3.value; - - _mentions.push(mention.substring(2, mention.length - 1)); - } - } catch (err) { - _didIteratorError3 = true; - _iteratorError3 = err; - } finally { - try { - if (!_iteratorNormalCompletion3 && _iterator3["return"]) { - _iterator3["return"](); - } - } finally { - if (_didIteratorError3) { - throw _iteratorError3; - } - } - } - - return _mentions; - } - }); - - return prom; - } - - //def createws - }, { - key: "createws", - value: function createws(url) { - if (this.websocket) return false; - - var self = this; - - //good to go - this.websocket = new WebSocket(url); - - //open - this.websocket.onopen = function () { - self.trySendConnData(); //try connecting - }; - - //close - this.websocket.onclose = function () { - self.trigger("disconnected"); - }; - - //message - this.websocket.onmessage = function (e) { - - var dat = false, - data = {}; - - try { - dat = JSON.parse(e.data); - data = dat.d; - } catch (err) { - self.trigger("error", err, e); - return; - } - - self.trigger("raw", dat); - - //valid message - switch (dat.t) { - - case "READY": - self.debug("received ready packet"); - - self.user = self.addUser(data.user); - - var _iteratorNormalCompletion4 = true; - var _didIteratorError4 = false; - var _iteratorError4 = undefined; - - try { - for (var _iterator4 = data.guilds[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { - var _server = _step4.value; - - var server = self.addServer(_server); - } - } catch (err) { - _didIteratorError4 = true; - _iteratorError4 = err; - } finally { - try { - if (!_iteratorNormalCompletion4 && _iterator4["return"]) { - _iterator4["return"](); - } - } finally { - if (_didIteratorError4) { - throw _iteratorError4; - } - } - } - - var _iteratorNormalCompletion5 = true; - var _didIteratorError5 = false; - var _iteratorError5 = undefined; - - try { - for (var _iterator5 = data.private_channels[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { - var _pmc = _step5.value; - - var pmc = self.addPMChannel(_pmc); - } - } catch (err) { - _didIteratorError5 = true; - _iteratorError5 = err; - } finally { - try { - if (!_iteratorNormalCompletion5 && _iterator5["return"]) { - _iterator5["return"](); - } - } finally { - if (_didIteratorError5) { - throw _iteratorError5; - } - } - } - - self.trigger("ready"); - self.readyTime = Date.now(); - self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users."); - self.state = 3; - setInterval(function () { - self.keepAlive.apply(self); - }, data.heartbeat_interval); - - break; - case "MESSAGE_CREATE": - self.debug("received message"); - - var mentions = []; - data.mentions = data.mentions || []; //for some reason this was not defined at some point? - var _iteratorNormalCompletion6 = true; - var _didIteratorError6 = false; - var _iteratorError6 = undefined; - - try { - for (var _iterator6 = data.mentions[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { - var mention = _step6.value; - - mentions.push(self.addUser(mention)); - } - } catch (err) { - _didIteratorError6 = true; - _iteratorError6 = err; - } finally { - try { - if (!_iteratorNormalCompletion6 && _iterator6["return"]) { - _iterator6["return"](); - } - } finally { - if (_didIteratorError6) { - throw _iteratorError6; - } - } - } - - var channel = self.getChannel("id", data.channel_id); - if (channel) { - var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); - self.trigger("message", msg); - } - - break; - case "MESSAGE_DELETE": - self.debug("message deleted"); - - var channel = self.getChannel("id", data.channel_id); - var message = channel.getMessage("id", data.id); - if (message) { - self.trigger("messageDelete", channel, message); - channel.messages.splice(channel.messages.indexOf(message), 1); - } else { - //don't have the cache of that message ;( - self.trigger("messageDelete", channel); - } - break; - case "MESSAGE_UPDATE": - self.debug("message updated"); - - var channel = self.getChannel("id", data.channel_id); - var formerMessage = channel.getMessage("id", data.id); - - if (formerMessage) { - - //new message might be partial, so we need to fill it with whatever the old message was. - var info = {}; - - for (var key in formerMessage) { - info[key] = formerMessage[key]; - } - - for (var key in data) { - info[key] = data[key]; - } - - var mentions = []; - var _iteratorNormalCompletion7 = true; - var _didIteratorError7 = false; - var _iteratorError7 = undefined; - - try { - for (var _iterator7 = info.mentions[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { - var mention = _step7.value; - - mentions.push(self.addUser(mention)); - } - } catch (err) { - _didIteratorError7 = true; - _iteratorError7 = err; - } finally { - try { - if (!_iteratorNormalCompletion7 && _iterator7["return"]) { - _iterator7["return"](); - } - } finally { - if (_didIteratorError7) { - throw _iteratorError7; - } - } - } - - var newMessage = new Message(info, channel, mentions, formerMessage.author); - - self.trigger("messageUpdate", newMessage, formerMessage); - - channel.messages[channel.messages.indexOf(formerMessage)] = newMessage; - } - - // message isn't in cache, and if it's a partial it could cause - // all hell to break loose... best to just act as if nothing happened - - break; - - case "GUILD_DELETE": - - var server = self.getServer("id", data.id); - - if (server) { - self.serverCache.splice(self.serverCache.indexOf(server), 1); - self.trigger("serverDelete", server); - } - - break; - - case "CHANNEL_DELETE": - - var channel = self.getChannel("id", data.id); - - if (channel) { - - var server = channel.server; - - if (server) { - - server.channels.splice(server.channels.indexOf(channel), 1); - } - - self.trigger("channelDelete", channel); - - self.serverCache.splice(self.serverCache.indexOf(channel), 1); - } - - break; - - case "GUILD_CREATE": - - var server = self.getServer("id", data.id); - - if (!server) { - //if server doesn't already exist because duh - server = self.addServer(data); - } /*else if(server.channels.length === 0){ - - var srv = new Server(data, self); - for(channel of data.channels){ - srv.channels.push(new Channel(channel, data.id)); - } - self.serverCache[self.serverCache.indexOf(server)] = srv; - - }*/ - - if (self.serverCreateListener[data.id]) { - var cbs = self.serverCreateListener[data.id]; - cbs[0](server); //promise then callback - cbs[1](null, server); //legacy callback - self.serverCreateListener[data.id] = null; - } - - self.trigger("serverCreate", server); - - break; - - case "CHANNEL_CREATE": - - var channel = self.getChannel("id", data.id); - - if (!channel) { - - var chann; - if (data.is_private) { - chann = self.addPMChannel(data); - } else { - chann = self.addChannel(data, data.guild_id); - } - var srv = self.getServer("id", data.guild_id); - if (srv) { - srv.addChannel(chann); - } - self.trigger("channelCreate", chann); - } - - break; - - case "GUILD_MEMBER_ADD": - - var server = self.getServer("id", data.guild_id); - - if (server) { - - var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. - - self.trigger("serverNewMember", server.addMember(user, data.roles), server); - } - - break; - - case "GUILD_MEMBER_REMOVE": - - var server = self.getServer("id", data.guild_id); - - if (server) { - - var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. - - server.removeMember("id", user.id); - - self.trigger("serverRemoveMember", user, server); - } - - break; - - case "USER_UPDATE": - - if (self.user && data.id === self.user.id) { - - var newUser = new User(data); //not actually adding to the cache - - self.trigger("userUpdate", newUser, self.user); - - if (~self.userCache.indexOf(self.user)) { - self.userCache[self.userCache.indexOf(self.user)] = newUser; - } - - self.user = newUser; - } - - break; - - case "PRESENCE_UPDATE": - - var userInCache = self.getUser("id", data.user.id); - - if (userInCache) { - //user exists - - data.user.username = data.user.username || userInCache.username; - data.user.id = data.user.id || userInCache.id; - data.user.discriminator = data.user.discriminator || userInCache.discriminator; - data.user.avatar = data.user.avatar || userInCache.avatar; - - var presenceUser = new User(data.user); - if (presenceUser.equalsStrict(userInCache)) { - //they're exactly the same, an actual presence update - self.trigger("presence", { - user: userInCache, - oldStatus: userInCache.status, - status: data.status, - server: self.getServer("id", data.guild_id), - gameId: data.game_id - }); - userInCache.status = data.status; - userInCache.gameId = data.game_id; - } else { - //one of their details changed. - self.userCache[self.userCache.indexOf(userInCache)] = presenceUser; - self.trigger("userUpdate", userInCache, presenceUser); - } - } - - break; - - case "CHANNEL_UPDATE": - - var channelInCache = self.getChannel("id", data.id), - serverInCache = self.getServer("id", data.guild_id); - - if (channelInCache && serverInCache) { - - var newChann = new Channel(data, serverInCache); - newChann.messages = channelInCache.messages; - - self.trigger("channelUpdate", channelInCache, newChann); - - self.channelCache[self.channelCache.indexOf(channelInCache)] = newChann; - } - - break; - - case "TYPING_START": - - var userInCache = self.getUser("id", data.user_id); - var channelInCache = self.getChannel("id", data.channel_id); - - if (!self.userTypingListener[data.user_id] || self.userTypingListener[data.user_id] === -1) { - self.trigger("startTyping", userInCache, channelInCache); - } - - self.userTypingListener[data.user_id] = Date.now(); - - setTimeout(function () { - if (self.userTypingListener[data.user_id] === -1) { - return; - } - if (Date.now() - self.userTypingListener[data.user_id] > 6000) { - // stopped typing - self.trigger("stopTyping", userInCache, channelInCache); - self.userTypingListener[data.user_id] = -1; - } - }, 6000); - - break; - - case "GUILD_ROLE_DELETE": - - var server = self.getServer("id", data.guild_id); - var role = server.getRole(data.role_id); - - self.trigger("serverRoleDelete", server, role); - - server.removeRole(role.id); - - break; - - case "GUILD_ROLE_UPDATE": - - var server = self.getServer("id", data.guild_id); - var role = server.getRole(data.role.id); - var newRole = server.updateRole(data.role); - - self.trigger("serverRoleUpdate", server, role, newRole); - - break; - - default: - self.debug("received unknown packet"); - self.trigger("unknown", dat); - break; - - } - }; - } - - //def addUser - }, { - key: "addUser", - value: function addUser(data) { - if (!this.getUser("id", data.id)) { - this.userCache.push(new User(data)); - } - return this.getUser("id", data.id); - } - - //def addChannel - }, { - key: "addChannel", - value: function addChannel(data, serverId) { - if (!this.getChannel("id", data.id)) { - this.channelCache.push(new Channel(data, this.getServer("id", serverId))); - } - return this.getChannel("id", data.id); - } - }, { - key: "addPMChannel", - value: function addPMChannel(data) { - if (!this.getPMChannel("id", data.id)) { - this.pmChannelCache.push(new PMChannel(data, this)); - } - return this.getPMChannel("id", data.id); - } - }, { - key: "setTopic", - value: function setTopic(channel, topic) { - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2]; - - var self = this; - - return new Promise(function (resolve, reject) { - - self.resolveDestination(channel).then(next)["catch"](error); - - function error(e) { - callback(e); - reject(e); - } - - function next(destination) { - - var asChan = self.getChannel("id", destination); - - request.patch(Endpoints.CHANNELS + "/" + destination).set("authorization", self.token).send({ - name: asChan.name, - position: 0, - topic: topic - }).end(function (err, res) { - if (err) { - error(err); - } else { - asChan.topic = res.body.topic; - resolve(); - callback(); - } - }); - } - }); - } - - //def addServer - }, { - key: "addServer", - value: function addServer(data) { - - var self = this; - var server = this.getServer("id", data.id); - - if (data.unavailable) { - self.trigger("unavailable", data); - self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached."); - return; - } - - if (!server) { - server = new Server(data, this); - this.serverCache.push(server); - if (data.channels) { - var _iteratorNormalCompletion8 = true; - var _didIteratorError8 = false; - var _iteratorError8 = undefined; - - try { - for (var _iterator8 = data.channels[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) { - var channel = _step8.value; - - server.channels.push(this.addChannel(channel, server.id)); - } - } catch (err) { - _didIteratorError8 = true; - _iteratorError8 = err; - } finally { - try { - if (!_iteratorNormalCompletion8 && _iterator8["return"]) { - _iterator8["return"](); - } - } finally { - if (_didIteratorError8) { - throw _iteratorError8; - } - } - } - } - } - - var _iteratorNormalCompletion9 = true; - var _didIteratorError9 = false; - var _iteratorError9 = undefined; - - try { - for (var _iterator9 = data.presences[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) { - var presence = _step9.value; - - var user = self.getUser("id", presence.user.id); - user.status = presence.status; - user.gameId = presence.game_id; - } - } catch (err) { - _didIteratorError9 = true; - _iteratorError9 = err; - } finally { - try { - if (!_iteratorNormalCompletion9 && _iterator9["return"]) { - _iterator9["return"](); - } - } finally { - if (_didIteratorError9) { - throw _iteratorError9; - } - } - } - - return server; - } - - //def getUser - }, { - key: "getUser", - value: function getUser(key, value) { - var _iteratorNormalCompletion10 = true; - var _didIteratorError10 = false; - var _iteratorError10 = undefined; - - try { - for (var _iterator10 = this.userCache[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) { - var user = _step10.value; - - if (user[key] === value) { - return user; - } - } - } catch (err) { - _didIteratorError10 = true; - _iteratorError10 = err; - } finally { - try { - if (!_iteratorNormalCompletion10 && _iterator10["return"]) { - _iterator10["return"](); - } - } finally { - if (_didIteratorError10) { - throw _iteratorError10; - } - } - } - - return null; - } - - //def getChannel - }, { - key: "getChannel", - value: function getChannel(key, value) { - var _iteratorNormalCompletion11 = true; - var _didIteratorError11 = false; - var _iteratorError11 = undefined; - - try { - for (var _iterator11 = this.channelCache[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) { - var channel = _step11.value; - - if (channel[key] === value) { - return channel; - } - } - } catch (err) { - _didIteratorError11 = true; - _iteratorError11 = err; - } finally { - try { - if (!_iteratorNormalCompletion11 && _iterator11["return"]) { - _iterator11["return"](); - } - } finally { - if (_didIteratorError11) { - throw _iteratorError11; - } - } - } - - return this.getPMChannel(key, value); //might be a PM - } - }, { - key: "getPMChannel", - value: function getPMChannel(key, value) { - var _iteratorNormalCompletion12 = true; - var _didIteratorError12 = false; - var _iteratorError12 = undefined; - - try { - for (var _iterator12 = this.pmChannelCache[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) { - var channel = _step12.value; - - if (channel[key] === value) { - return channel; - } - } - } catch (err) { - _didIteratorError12 = true; - _iteratorError12 = err; - } finally { - try { - if (!_iteratorNormalCompletion12 && _iterator12["return"]) { - _iterator12["return"](); - } - } finally { - if (_didIteratorError12) { - throw _iteratorError12; - } - } - } - - return null; - } - - //def getServer - }, { - key: "getServer", - value: function getServer(key, value) { - var _iteratorNormalCompletion13 = true; - var _didIteratorError13 = false; - var _iteratorError13 = undefined; - - try { - for (var _iterator13 = this.serverCache[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) { - var server = _step13.value; - - if (server[key] === value) { - return server; - } - } - } catch (err) { - _didIteratorError13 = true; - _iteratorError13 = err; - } finally { - try { - if (!_iteratorNormalCompletion13 && _iterator13["return"]) { - _iterator13["return"](); - } - } finally { - if (_didIteratorError13) { - throw _iteratorError13; - } - } - } - - return null; - } - - //def trySendConnData - }, { - key: "trySendConnData", - value: function trySendConnData() { - - if (this.token && !this.alreadySentData) { - - this.alreadySentData = true; - - var data = { - op: 2, - d: { - token: this.token, - v: 3, - properties: { - "$os": "discord.js", - "$browser": "discord.js", - "$device": "discord.js", - "$referrer": "", - "$referring_domain": "" - } - } - }; - this.websocket.send(JSON.stringify(data)); - } - } - }, { - key: "resolveServerID", - value: function resolveServerID(resource) { - - if (resource instanceof Server) { - return resource.id; - } else if (!isNaN(resource) && resource.length && resource.length === 17) { - return resource; - } - } - }, { - key: "resolveDestination", - value: function resolveDestination(destination) { - var channId = false; - var self = this; - - return new Promise(function (resolve, reject) { - if (destination instanceof Server) { - channId = destination.id; //general is the same as server id - } else if (destination instanceof Channel) { - channId = destination.id; - } else if (destination instanceof Message) { - channId = destination.channel.id; - } else if (destination instanceof PMChannel) { - channId = destination.id; - } else if (destination instanceof User) { - - //check if we have a PM - var _iteratorNormalCompletion14 = true; - var _didIteratorError14 = false; - var _iteratorError14 = undefined; - - try { - for (var _iterator14 = self.pmChannelCache[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) { - var pmc = _step14.value; - - if (pmc.user && pmc.user.equals(destination)) { - resolve(pmc.id); - return; - } - } - - //we don't, at this point we're late - } catch (err) { - _didIteratorError14 = true; - _iteratorError14 = err; - } finally { - try { - if (!_iteratorNormalCompletion14 && _iterator14["return"]) { - _iterator14["return"](); - } - } finally { - if (_didIteratorError14) { - throw _iteratorError14; - } - } - } - - self.startPM(destination).then(function (pmc) { - resolve(pmc.id); - })["catch"](reject); - } else { - channId = destination; - } - if (channId) resolve(channId);else reject(); - }); - } - }, { - key: "_sendMessage", - value: function _sendMessage(destination, content, tts, mentions) { - - var self = this; - - return new Promise(function (resolve, reject) { - request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).send({ - content: content, - mentions: mentions, - tts: tts - }).end(function (err, res) { - - if (err) { - reject(err); - } else { - var data = res.body; - - var mentions = []; - - data.mentions = data.mentions || []; //for some reason this was not defined at some point? - - var _iteratorNormalCompletion15 = true; - var _didIteratorError15 = false; - var _iteratorError15 = undefined; - - try { - for (var _iterator15 = data.mentions[Symbol.iterator](), _step15; !(_iteratorNormalCompletion15 = (_step15 = _iterator15.next()).done); _iteratorNormalCompletion15 = true) { - var mention = _step15.value; - - mentions.push(self.addUser(mention)); - } - } catch (err) { - _didIteratorError15 = true; - _iteratorError15 = err; - } finally { - try { - if (!_iteratorNormalCompletion15 && _iterator15["return"]) { - _iterator15["return"](); - } - } finally { - if (_didIteratorError15) { - throw _iteratorError15; - } - } - } - - var channel = self.getChannel("id", data.channel_id); - if (channel) { - var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); - resolve(msg); - } - } - }); - }); - } - }, { - key: "_sendFile", - value: function _sendFile(destination, attachment) { - var attachmentName = arguments.length <= 2 || arguments[2] === undefined ? "DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png" : arguments[2]; - - var self = this; - - return new Promise(function (resolve, reject) { - request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).attach("file", attachment, attachmentName).end(function (err, res) { - - if (err) { - reject(err); - } else { - - var chann = self.getChannel("id", destination); - if (chann) { - var msg = chann.addMessage(new Message(res.body, chann, [], self.user)); - resolve(msg); - } - } - }); - }); - } - }, { - key: "_updateMessage", - value: function _updateMessage(message, content) { - var self = this; - return new Promise(function (resolve, reject) { - request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).send({ - content: content, - mentions: [] - }).end(function (err, res) { - if (err) { - reject(err); - } else { - var msg = new Message(res.body, message.channel, message.mentions, message.sender); - resolve(msg); - message.channel.messages[message.channel.messages.indexOf(message)] = msg; - } - }); - }); - } - }, { - key: "getGateway", - value: function getGateway() { - var self = this; - return new Promise(function (resolve, reject) { - request.get(Endpoints.API + "/gateway").set("authorization", self.token).end(function (err, res) { - if (err) { - reject(err); - } else { - resolve(res.body.url); - } - }); - }); - } - }, { - key: "setStatusIdle", - value: function setStatusIdle() { - this.setStatus("idle"); - } - }, { - key: "setStatusOnline", - value: function setStatusOnline() { - this.setStatus("online"); - } - }, { - key: "setStatusActive", - value: function setStatusActive() { - this.setStatusOnline(); - } - }, { - key: "setStatusHere", - value: function setStatusHere() { - this.setStatusOnline(); - } - }, { - key: "setStatusAway", - value: function setStatusAway() { - this.setStatusIdle(); - } - }, { - key: "startTyping", - value: function startTyping(chann, stopTypeTime) { - var self = this; - - this.resolveDestination(chann).then(next); - - function next(channel) { - if (self.typingIntervals[channel]) { - return; - } - - var fn = function fn() { - request.post(Endpoints.CHANNELS + "/" + channel + "/typing").set("authorization", self.token).end(); - }; - - fn(); - - var interval = setInterval(fn, 3000); - - self.typingIntervals[channel] = interval; - - if (stopTypeTime) { - setTimeout(function () { - self.stopTyping(channel); - }, stopTypeTime); - } - } - } - }, { - key: "stopTyping", - value: function stopTyping(chann) { - var self = this; - - this.resolveDestination(chann).then(next); - - function next(channel) { - if (!self.typingIntervals[channel]) { - return; - } - - clearInterval(self.typingIntervals[channel]); - - delete self.typingIntervals[channel]; - } - } - }, { - key: "setStatus", - value: function setStatus(stat) { - - var idleTime = stat === "online" ? null : Date.now(); - - this.__idleTime = idleTime; - - this.websocket.send(JSON.stringify({ - op: 3, - d: { - idle_since: this.__idleTime, - game_id: this.__gameId - } - })); - } - }, { - key: "setPlayingGame", - value: function setPlayingGame(id) { - - if (id instanceof String || typeof id === "string") { - - // working on names - var gid = id.trim().toUpperCase(); - - id = null; - - var _iteratorNormalCompletion16 = true; - var _didIteratorError16 = false; - var _iteratorError16 = undefined; - - try { - for (var _iterator16 = gameMap[Symbol.iterator](), _step16; !(_iteratorNormalCompletion16 = (_step16 = _iterator16.next()).done); _iteratorNormalCompletion16 = true) { - var game = _step16.value; - - if (game.name.trim().toUpperCase() === gid) { - - id = game.id; - break; - } - } - } catch (err) { - _didIteratorError16 = true; - _iteratorError16 = err; - } finally { - try { - if (!_iteratorNormalCompletion16 && _iterator16["return"]) { - _iterator16["return"](); - } - } finally { - if (_didIteratorError16) { - throw _iteratorError16; - } - } - } - } - - this.__gameId = id; - - this.websocket.send(JSON.stringify({ - op: 3, - d: { - idle_since: this.__idleTime, - game_id: this.__gameId - } - })); - } - }, { - key: "playGame", - value: function playGame(id) { - this.setPlayingGame(id); - } - }, { - key: "playingGame", - value: function playingGame(id) { - - this.setPlayingGame(id); - } - }, { - key: "uptime", - get: function get() { - - return this.readyTime ? Date.now() - this.readyTime : null; - } - }, { - key: "ready", - get: function get() { - return this.state === 3; - } - }, { - key: "servers", - get: function get() { - return this.serverCache; - } - }, { - key: "channels", - get: function get() { - return this.channelCache; - } - }, { - key: "users", - get: function get() { - return this.userCache; - } - }, { - key: "PMChannels", - get: function get() { - return this.pmChannelCache; - } - }, { - key: "messages", - get: function get() { - - var msgs = []; - var _iteratorNormalCompletion17 = true; - var _didIteratorError17 = false; - var _iteratorError17 = undefined; - - try { - for (var _iterator17 = this.channelCache[Symbol.iterator](), _step17; !(_iteratorNormalCompletion17 = (_step17 = _iterator17.next()).done); _iteratorNormalCompletion17 = true) { - var channel = _step17.value; - - msgs = msgs.concat(channel.messages); - } - } catch (err) { - _didIteratorError17 = true; - _iteratorError17 = err; - } finally { - try { - if (!_iteratorNormalCompletion17 && _iterator17["return"]) { - _iterator17["return"](); - } - } finally { - if (_didIteratorError17) { - throw _iteratorError17; - } - } - } - - return msgs; - } - }]); - - return Client; -})(); - -module.exports = Client; \ No newline at end of file + self.serverCache[self.serverCache.indexOf(server)] = srv; + + }*/if(self.serverCreateListener[data.id]){var cbs=self.serverCreateListener[data.id];cbs[0](server); //promise then callback +cbs[1](null,server); //legacy callback +self.serverCreateListener[data.id] = null;}self.trigger("serverCreate",server);break;case "CHANNEL_CREATE":var channel=self.getChannel("id",data.id);if(!channel){var chann;if(data.is_private){chann = self.addPMChannel(data);}else {chann = self.addChannel(data,data.guild_id);}var srv=self.getServer("id",data.guild_id);if(srv){srv.addChannel(chann);}self.trigger("channelCreate",chann);}break;case "GUILD_MEMBER_ADD":var server=self.getServer("id",data.guild_id);if(server){var user=self.addUser(data.user); //if for whatever reason it doesn't exist.. +self.trigger("serverNewMember",server.addMember(user,data.roles),server);}break;case "GUILD_MEMBER_REMOVE":var server=self.getServer("id",data.guild_id);if(server){var user=self.addUser(data.user); //if for whatever reason it doesn't exist.. +server.removeMember("id",user.id);self.trigger("serverRemoveMember",user,server);}break;case "USER_UPDATE":if(self.user && data.id === self.user.id){var newUser=new User(data); //not actually adding to the cache +self.trigger("userUpdate",newUser,self.user);if(~self.userCache.indexOf(self.user)){self.userCache[self.userCache.indexOf(self.user)] = newUser;}self.user = newUser;}break;case "PRESENCE_UPDATE":var userInCache=self.getUser("id",data.user.id);if(userInCache){ //user exists +data.user.username = data.user.username || userInCache.username;data.user.id = data.user.id || userInCache.id;data.user.discriminator = data.user.discriminator || userInCache.discriminator;data.user.avatar = data.user.avatar || userInCache.avatar;var presenceUser=new User(data.user);if(presenceUser.equalsStrict(userInCache)){ //they're exactly the same, an actual presence update +self.trigger("presence",{user:userInCache,oldStatus:userInCache.status,status:data.status,server:self.getServer("id",data.guild_id),gameId:data.game_id});userInCache.status = data.status;userInCache.gameId = data.game_id;}else { //one of their details changed. +self.userCache[self.userCache.indexOf(userInCache)] = presenceUser;self.trigger("userUpdate",userInCache,presenceUser);}}break;case "CHANNEL_UPDATE":var channelInCache=self.getChannel("id",data.id),serverInCache=self.getServer("id",data.guild_id);if(channelInCache && serverInCache){var newChann=new Channel(data,serverInCache);newChann.messages = channelInCache.messages;self.trigger("channelUpdate",channelInCache,newChann);self.channelCache[self.channelCache.indexOf(channelInCache)] = newChann;}break;case "TYPING_START":var userInCache=self.getUser("id",data.user_id);var channelInCache=self.getChannel("id",data.channel_id);if(!self.userTypingListener[data.user_id] || self.userTypingListener[data.user_id] === -1){self.trigger("startTyping",userInCache,channelInCache);}self.userTypingListener[data.user_id] = Date.now();setTimeout(function(){if(self.userTypingListener[data.user_id] === -1){return;}if(Date.now() - self.userTypingListener[data.user_id] > 6000){ // stopped typing +self.trigger("stopTyping",userInCache,channelInCache);self.userTypingListener[data.user_id] = -1;}},6000);break;case "GUILD_ROLE_DELETE":var server=self.getServer("id",data.guild_id);var role=server.getRole(data.role_id);self.trigger("serverRoleDelete",server,role);server.removeRole(role.id);break;case "GUILD_ROLE_UPDATE":var server=self.getServer("id",data.guild_id);var role=server.getRole(data.role.id);var newRole=server.updateRole(data.role);self.trigger("serverRoleUpdate",server,role,newRole);break;default:self.debug("received unknown packet");self.trigger("unknown",dat);break;}};}; //def addUser +Client.prototype.addUser = function addUser(data){if(!this.getUser("id",data.id)){this.userCache.push(new User(data));}return this.getUser("id",data.id);}; //def addChannel +Client.prototype.addChannel = function addChannel(data,serverId){if(!this.getChannel("id",data.id)){this.channelCache.push(new Channel(data,this.getServer("id",serverId)));}return this.getChannel("id",data.id);};Client.prototype.addPMChannel = function addPMChannel(data){if(!this.getPMChannel("id",data.id)){this.pmChannelCache.push(new PMChannel(data,this));}return this.getPMChannel("id",data.id);};Client.prototype.setTopic = function setTopic(channel,topic){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err){}:arguments[2];var self=this;return new Promise(function(resolve,reject){self.resolveDestination(channel).then(next)["catch"](error);function error(e){callback(e);reject(e);}function next(destination){var asChan=self.getChannel("id",destination);request.patch(Endpoints.CHANNELS + "/" + destination).set("authorization",self.token).send({name:asChan.name,position:0,topic:topic}).end(function(err,res){if(err){error(err);}else {asChan.topic = res.body.topic;resolve();callback();}});}});}; //def addServer +Client.prototype.addServer = function addServer(data){var self=this;var server=this.getServer("id",data.id);if(data.unavailable){self.trigger("unavailable",data);self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached.");return;}if(!server){server = new Server(data,this);this.serverCache.push(server);if(data.channels){for(var _iterator8=data.channels,_isArray8=Array.isArray(_iterator8),_i8=0,_iterator8=_isArray8?_iterator8:_iterator8[Symbol.iterator]();;) {var _ref8;if(_isArray8){if(_i8 >= _iterator8.length)break;_ref8 = _iterator8[_i8++];}else {_i8 = _iterator8.next();if(_i8.done)break;_ref8 = _i8.value;}var channel=_ref8;server.channels.push(this.addChannel(channel,server.id));}}}for(var _iterator9=data.presences,_isArray9=Array.isArray(_iterator9),_i9=0,_iterator9=_isArray9?_iterator9:_iterator9[Symbol.iterator]();;) {var _ref9;if(_isArray9){if(_i9 >= _iterator9.length)break;_ref9 = _iterator9[_i9++];}else {_i9 = _iterator9.next();if(_i9.done)break;_ref9 = _i9.value;}var presence=_ref9;var user=self.getUser("id",presence.user.id);user.status = presence.status;user.gameId = presence.game_id;}return server;}; //def getUser +Client.prototype.getUser = function getUser(key,value){for(var _iterator10=this.userCache,_isArray10=Array.isArray(_iterator10),_i10=0,_iterator10=_isArray10?_iterator10:_iterator10[Symbol.iterator]();;) {var _ref10;if(_isArray10){if(_i10 >= _iterator10.length)break;_ref10 = _iterator10[_i10++];}else {_i10 = _iterator10.next();if(_i10.done)break;_ref10 = _i10.value;}var user=_ref10;if(user[key] === value){return user;}}return null;}; //def getChannel +Client.prototype.getChannel = function getChannel(key,value){for(var _iterator11=this.channelCache,_isArray11=Array.isArray(_iterator11),_i11=0,_iterator11=_isArray11?_iterator11:_iterator11[Symbol.iterator]();;) {var _ref11;if(_isArray11){if(_i11 >= _iterator11.length)break;_ref11 = _iterator11[_i11++];}else {_i11 = _iterator11.next();if(_i11.done)break;_ref11 = _i11.value;}var channel=_ref11;if(channel[key] === value){return channel;}}return this.getPMChannel(key,value); //might be a PM +};Client.prototype.getPMChannel = function getPMChannel(key,value){for(var _iterator12=this.pmChannelCache,_isArray12=Array.isArray(_iterator12),_i12=0,_iterator12=_isArray12?_iterator12:_iterator12[Symbol.iterator]();;) {var _ref12;if(_isArray12){if(_i12 >= _iterator12.length)break;_ref12 = _iterator12[_i12++];}else {_i12 = _iterator12.next();if(_i12.done)break;_ref12 = _i12.value;}var channel=_ref12;if(channel[key] === value){return channel;}}return null;}; //def getServer +Client.prototype.getServer = function getServer(key,value){for(var _iterator13=this.serverCache,_isArray13=Array.isArray(_iterator13),_i13=0,_iterator13=_isArray13?_iterator13:_iterator13[Symbol.iterator]();;) {var _ref13;if(_isArray13){if(_i13 >= _iterator13.length)break;_ref13 = _iterator13[_i13++];}else {_i13 = _iterator13.next();if(_i13.done)break;_ref13 = _i13.value;}var server=_ref13;if(server[key] === value){return server;}}return null;}; //def trySendConnData +Client.prototype.trySendConnData = function trySendConnData(){if(this.token && !this.alreadySentData){this.alreadySentData = true;var data={op:2,d:{token:this.token,v:3,properties:{"$os":"discord.js","$browser":"discord.js","$device":"discord.js","$referrer":"","$referring_domain":""}}};this.websocket.send(JSON.stringify(data));}};Client.prototype.resolveServerID = function resolveServerID(resource){if(resource instanceof Server){return resource.id;}else if(!isNaN(resource) && resource.length && resource.length === 17){return resource;}};Client.prototype.resolveDestination = function resolveDestination(destination){var channId=false;var self=this;return new Promise(function(resolve,reject){if(destination instanceof Server){channId = destination.id; //general is the same as server id +}else if(destination instanceof Channel){channId = destination.id;}else if(destination instanceof Message){channId = destination.channel.id;}else if(destination instanceof PMChannel){channId = destination.id;}else if(destination instanceof User){ //check if we have a PM +for(var _iterator14=self.pmChannelCache,_isArray14=Array.isArray(_iterator14),_i14=0,_iterator14=_isArray14?_iterator14:_iterator14[Symbol.iterator]();;) {var _ref14;if(_isArray14){if(_i14 >= _iterator14.length)break;_ref14 = _iterator14[_i14++];}else {_i14 = _iterator14.next();if(_i14.done)break;_ref14 = _i14.value;}var pmc=_ref14;if(pmc.user && pmc.user.equals(destination)){resolve(pmc.id);return;}} //we don't, at this point we're late +self.startPM(destination).then(function(pmc){resolve(pmc.id);})["catch"](reject);}else {channId = destination;}if(channId)resolve(channId);else reject();});};Client.prototype._sendMessage = function _sendMessage(destination,content,tts,mentions){var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization",self.token).send({content:content,mentions:mentions,tts:tts}).end(function(err,res){if(err){reject(err);}else {var data=res.body;var mentions=[];data.mentions = data.mentions || []; //for some reason this was not defined at some point? +for(var _iterator15=data.mentions,_isArray15=Array.isArray(_iterator15),_i15=0,_iterator15=_isArray15?_iterator15:_iterator15[Symbol.iterator]();;) {var _ref15;if(_isArray15){if(_i15 >= _iterator15.length)break;_ref15 = _iterator15[_i15++];}else {_i15 = _iterator15.next();if(_i15.done)break;_ref15 = _i15.value;}var mention=_ref15;mentions.push(self.addUser(mention));}var channel=self.getChannel("id",data.channel_id);if(channel){var msg=channel.addMessage(new Message(data,channel,mentions,self.addUser(data.author)));resolve(msg);}}});});};Client.prototype._sendFile = function _sendFile(destination,attachment){var attachmentName=arguments.length <= 2 || arguments[2] === undefined?"DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png":arguments[2];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization",self.token).attach("file",attachment,attachmentName).end(function(err,res){if(err){reject(err);}else {var chann=self.getChannel("id",destination);if(chann){var msg=chann.addMessage(new Message(res.body,chann,[],self.user));resolve(msg);}}});});};Client.prototype._updateMessage = function _updateMessage(message,content){var self=this;return new Promise(function(resolve,reject){request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization",self.token).send({content:content,mentions:[]}).end(function(err,res){if(err){reject(err);}else {var msg=new Message(res.body,message.channel,message.mentions,message.sender);resolve(msg);message.channel.messages[message.channel.messages.indexOf(message)] = msg;}});});};Client.prototype.getGateway = function getGateway(){var self=this;return new Promise(function(resolve,reject){request.get(Endpoints.API + "/gateway").set("authorization",self.token).end(function(err,res){if(err){reject(err);}else {resolve(res.body.url);}});});};Client.prototype.setStatusIdle = function setStatusIdle(){this.setStatus("idle");};Client.prototype.setStatusOnline = function setStatusOnline(){this.setStatus("online");};Client.prototype.setStatusActive = function setStatusActive(){this.setStatusOnline();};Client.prototype.setStatusHere = function setStatusHere(){this.setStatusOnline();};Client.prototype.setStatusAway = function setStatusAway(){this.setStatusIdle();};Client.prototype.startTyping = function startTyping(chann,stopTypeTime){var self=this;this.resolveDestination(chann).then(next);function next(channel){if(self.typingIntervals[channel]){return;}var fn=function fn(){request.post(Endpoints.CHANNELS + "/" + channel + "/typing").set("authorization",self.token).end();};fn();var interval=setInterval(fn,3000);self.typingIntervals[channel] = interval;if(stopTypeTime){setTimeout(function(){self.stopTyping(channel);},stopTypeTime);}}};Client.prototype.stopTyping = function stopTyping(chann){var self=this;this.resolveDestination(chann).then(next);function next(channel){if(!self.typingIntervals[channel]){return;}clearInterval(self.typingIntervals[channel]);delete self.typingIntervals[channel];}};Client.prototype.setStatus = function setStatus(stat){var idleTime=stat === "online"?null:Date.now();this.__idleTime = idleTime;this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}));};Client.prototype.setPlayingGame = function setPlayingGame(id){if(id instanceof String || typeof id === "string"){ // working on names +var gid=id.trim().toUpperCase();id = null;for(var _iterator16=gameMap,_isArray16=Array.isArray(_iterator16),_i16=0,_iterator16=_isArray16?_iterator16:_iterator16[Symbol.iterator]();;) {var _ref16;if(_isArray16){if(_i16 >= _iterator16.length)break;_ref16 = _iterator16[_i16++];}else {_i16 = _iterator16.next();if(_i16.done)break;_ref16 = _i16.value;}var game=_ref16;if(game.name.trim().toUpperCase() === gid){id = game.id;break;}}}this.__gameId = id;this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}));};Client.prototype.playGame = function playGame(id){this.setPlayingGame(id);};Client.prototype.playingGame = function playingGame(id){this.setPlayingGame(id);};_createClass(Client,[{key:"uptime",get:function get(){return this.readyTime?Date.now() - this.readyTime:null;}},{key:"ready",get:function get(){return this.state === 3;}},{key:"servers",get:function get(){return this.serverCache;}},{key:"channels",get:function get(){return this.channelCache;}},{key:"users",get:function get(){return this.userCache;}},{key:"PMChannels",get:function get(){return this.pmChannelCache;}},{key:"messages",get:function get(){var msgs=[];for(var _iterator17=this.channelCache,_isArray17=Array.isArray(_iterator17),_i17=0,_iterator17=_isArray17?_iterator17:_iterator17[Symbol.iterator]();;) {var _ref17;if(_isArray17){if(_i17 >= _iterator17.length)break;_ref17 = _iterator17[_i17++];}else {_i17 = _iterator17.next();if(_i17.done)break;_ref17 = _i17.value;}var channel=_ref17;msgs = msgs.concat(channel.messages);}return msgs;}}]);return Client;})();module.exports = Client; diff --git a/lib/Endpoints.js b/lib/Endpoints.js index 271b465eb..60cd7925c 100644 --- a/lib/Endpoints.js +++ b/lib/Endpoints.js @@ -1,13 +1 @@ -"use strict"; - -exports.BASE_DOMAIN = "discordapp.com"; -exports.BASE = "https://" + exports.BASE_DOMAIN; -exports.WEBSOCKET_HUB = "wss://" + exports.BASE_DOMAIN + "/hub"; - -exports.API = exports.BASE + "/api"; -exports.AUTH = exports.API + "/auth"; -exports.LOGIN = exports.AUTH + "/login"; -exports.LOGOUT = exports.AUTH + "/logout"; -exports.USERS = exports.API + "/users"; -exports.SERVERS = exports.API + "/guilds"; -exports.CHANNELS = exports.API + "/channels"; \ No newline at end of file +"use strict";exports.BASE_DOMAIN = "discordapp.com";exports.BASE = "https://" + exports.BASE_DOMAIN;exports.WEBSOCKET_HUB = "wss://" + exports.BASE_DOMAIN + "/hub";exports.API = exports.BASE + "/api";exports.AUTH = exports.API + "/auth";exports.LOGIN = exports.AUTH + "/login";exports.LOGOUT = exports.AUTH + "/logout";exports.USERS = exports.API + "/users";exports.SERVERS = exports.API + "/guilds";exports.CHANNELS = exports.API + "/channels"; diff --git a/lib/EvaluatedPermissions.js b/lib/EvaluatedPermissions.js index b441500cf..947063410 100644 --- a/lib/EvaluatedPermissions.js +++ b/lib/EvaluatedPermissions.js @@ -1,172 +1 @@ -"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 EvaluatedPermissions = (function () { - function EvaluatedPermissions(data) { - _classCallCheck(this, EvaluatedPermissions); - - var self = this; - - function getBit(x) { - if ((self.packed >>> 3 & 1) === 1) { - return true; - } - return (self.packed >>> x & 1) === 1; - } - - this.packed = data; - } - - _createClass(EvaluatedPermissions, [{ - key: "getBit", - value: function getBit(x) { - return (this.packed >>> x & 1) === 1; - } - }, { - key: "setBit", - value: function setBit() {} - }, { - key: "createInstantInvite", - get: function get() { - return this.getBit(0); - }, - set: function set(val) { - this.setBit(0, val); - } - }, { - key: "manageRoles", - get: function get() { - return this.getBit(3); - }, - set: function set(val) { - this.setBit(3, val); - } - }, { - key: "manageChannels", - get: function get() { - return this.getBit(4); - }, - set: function set(val) { - this.setBit(4, val); - } - }, { - key: "readMessages", - get: function get() { - return this.getBit(10); - }, - set: function set(val) { - this.setBit(10, val); - } - }, { - key: "sendMessages", - get: function get() { - return this.getBit(11); - }, - set: function set(val) { - this.setBit(11, val); - } - }, { - key: "sendTTSMessages", - get: function get() { - return this.getBit(12); - }, - set: function set(val) { - this.setBit(12, val); - } - }, { - key: "manageMessages", - get: function get() { - return this.getBit(13); - }, - set: function set(val) { - this.setBit(13, val); - } - }, { - key: "embedLinks", - get: function get() { - return this.getBit(14); - }, - set: function set(val) { - this.setBit(14, val); - } - }, { - key: "attachFiles", - get: function get() { - return this.getBit(15); - }, - set: function set(val) { - this.setBit(15, val); - } - }, { - key: "readMessageHistory", - get: function get() { - return this.getBit(16); - }, - set: function set(val) { - this.setBit(16, val); - } - }, { - key: "mentionEveryone", - get: function get() { - return this.getBit(17); - }, - set: function set(val) { - this.setBit(17, val); - } - }, { - key: "voiceConnect", - get: function get() { - return this.getBit(20); - }, - set: function set(val) { - this.setBit(20, val); - } - }, { - key: "voiceSpeak", - get: function get() { - return this.getBit(21); - }, - set: function set(val) { - this.setBit(21, val); - } - }, { - key: "voiceMuteMembers", - get: function get() { - return this.getBit(22); - }, - set: function set(val) { - this.setBit(22, val); - } - }, { - key: "voiceDeafenMembers", - get: function get() { - return this.getBit(23); - }, - set: function set(val) { - this.setBit(23, val); - } - }, { - key: "voiceMoveMembers", - get: function get() { - return this.getBit(24); - }, - set: function set(val) { - this.setBit(24, val); - } - }, { - key: "voiceUseVoiceActivation", - get: function get() { - return this.getBit(25); - }, - set: function set(val) { - this.setBit(25, val); - } - }]); - - return EvaluatedPermissions; -})(); - -module.exports = EvaluatedPermissions; \ No newline at end of file +"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 EvaluatedPermissions=(function(){function EvaluatedPermissions(data){_classCallCheck(this,EvaluatedPermissions);var self=this;function getBit(x){if((self.packed >>> 3 & 1) === 1){return true;}return (self.packed >>> x & 1) === 1;}this.packed = data;}EvaluatedPermissions.prototype.getBit = function getBit(x){return (this.packed >>> x & 1) === 1;};EvaluatedPermissions.prototype.setBit = function setBit(){};_createClass(EvaluatedPermissions,[{key:"createInstantInvite",get:function get(){return this.getBit(0);},set:function set(val){this.setBit(0,val);}},{key:"manageRoles",get:function get(){return this.getBit(3);},set:function set(val){this.setBit(3,val);}},{key:"manageChannels",get:function get(){return this.getBit(4);},set:function set(val){this.setBit(4,val);}},{key:"readMessages",get:function get(){return this.getBit(10);},set:function set(val){this.setBit(10,val);}},{key:"sendMessages",get:function get(){return this.getBit(11);},set:function set(val){this.setBit(11,val);}},{key:"sendTTSMessages",get:function get(){return this.getBit(12);},set:function set(val){this.setBit(12,val);}},{key:"manageMessages",get:function get(){return this.getBit(13);},set:function set(val){this.setBit(13,val);}},{key:"embedLinks",get:function get(){return this.getBit(14);},set:function set(val){this.setBit(14,val);}},{key:"attachFiles",get:function get(){return this.getBit(15);},set:function set(val){this.setBit(15,val);}},{key:"readMessageHistory",get:function get(){return this.getBit(16);},set:function set(val){this.setBit(16,val);}},{key:"mentionEveryone",get:function get(){return this.getBit(17);},set:function set(val){this.setBit(17,val);}},{key:"voiceConnect",get:function get(){return this.getBit(20);},set:function set(val){this.setBit(20,val);}},{key:"voiceSpeak",get:function get(){return this.getBit(21);},set:function set(val){this.setBit(21,val);}},{key:"voiceMuteMembers",get:function get(){return this.getBit(22);},set:function set(val){this.setBit(22,val);}},{key:"voiceDeafenMembers",get:function get(){return this.getBit(23);},set:function set(val){this.setBit(23,val);}},{key:"voiceMoveMembers",get:function get(){return this.getBit(24);},set:function set(val){this.setBit(24,val);}},{key:"voiceUseVoiceActivation",get:function get(){return this.getBit(25);},set:function set(val){this.setBit(25,val);}}]);return EvaluatedPermissions;})();module.exports = EvaluatedPermissions; diff --git a/lib/Member.js b/lib/Member.js index ba29467db..36b583a87 100644 --- a/lib/Member.js +++ b/lib/Member.js @@ -1,225 +1,4 @@ -"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; }; })(); - -var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; - -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 User = require("./user.js"); -var ServerPermissions = require("./ServerPermissions.js"); -var EvaluatedPermissions = require("./EvaluatedPermissions.js"); - -var Member = (function (_User) { - _inherits(Member, _User); - - function Member(user, server, roles) { - _classCallCheck(this, Member); - - _get(Object.getPrototypeOf(Member.prototype), "constructor", this).call(this, user); // should work, we are basically creating a Member that has the same properties as user and a few more - this.server = server; - this.rawRoles = roles; - } - - _createClass(Member, [{ - key: "permissionsIn", - value: function permissionsIn(channel) { - - if (channel.server.ownerID === this.id) { - return new EvaluatedPermissions(4294967295); //all perms - } - - var affectingOverwrites = []; - var affectingMemberOverwrites = []; - - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = channel.roles[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var overwrite = _step.value; - - if (overwrite.id === this.id && overwrite.type === "member") { - affectingMemberOverwrites.push(overwrite); - } else if (this.rawRoles.indexOf(overwrite.id) !== -1) { - affectingOverwrites.push(overwrite); - } - } - } 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 = affectingOverwrites[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var perm = _step2.value; - - console.log("hey", perm.attachFiles); - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { - try { - if (!_iteratorNormalCompletion2 && _iterator2["return"]) { - _iterator2["return"](); - } - } finally { - if (_didIteratorError2) { - throw _iteratorError2; - } - } - } - - if (affectingOverwrites.length === 0 && affectingMemberOverwrites.length === 0) { - return new EvaluatedPermissions(this.evalPerms.packed); - } - - var finalPacked = affectingOverwrites.length !== 0 ? affectingOverwrites[0].packed : affectingMemberOverwrites[0].packed; - - var _iteratorNormalCompletion3 = true; - var _didIteratorError3 = false; - var _iteratorError3 = undefined; - - try { - for (var _iterator3 = affectingOverwrites[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { - var overwrite = _step3.value; - - finalPacked = finalPacked & ~overwrite.deny; - finalPacked = finalPacked | overwrite.allow; - } - } catch (err) { - _didIteratorError3 = true; - _iteratorError3 = err; - } finally { - try { - if (!_iteratorNormalCompletion3 && _iterator3["return"]) { - _iterator3["return"](); - } - } finally { - if (_didIteratorError3) { - throw _iteratorError3; - } - } - } - - var _iteratorNormalCompletion4 = true; - var _didIteratorError4 = false; - var _iteratorError4 = undefined; - - try { - for (var _iterator4 = affectingMemberOverwrites[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { - var overwrite = _step4.value; - - finalPacked = finalPacked & ~overwrite.deny; - finalPacked = finalPacked | overwrite.allow; - } - } catch (err) { - _didIteratorError4 = true; - _iteratorError4 = err; - } finally { - try { - if (!_iteratorNormalCompletion4 && _iterator4["return"]) { - _iterator4["return"](); - } - } finally { - if (_didIteratorError4) { - throw _iteratorError4; - } - } - } - - return new EvaluatedPermissions(finalPacked); - } - }, { - key: "roles", - get: function get() { - - var ufRoles = [this.server.getRole(this.server.id)]; - - var _iteratorNormalCompletion5 = true; - var _didIteratorError5 = false; - var _iteratorError5 = undefined; - - try { - for (var _iterator5 = this.rawRoles[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { - var rawRole = _step5.value; - - ufRoles.push(this.server.getRole(rawRole)); - } - } catch (err) { - _didIteratorError5 = true; - _iteratorError5 = err; - } finally { - try { - if (!_iteratorNormalCompletion5 && _iterator5["return"]) { - _iterator5["return"](); - } - } finally { - if (_didIteratorError5) { - throw _iteratorError5; - } - } - } - - return ufRoles; - } - }, { - key: "evalPerms", - get: function get() { - var basePerms = this.roles, - //cache roles as it can be slightly expensive - basePerm = basePerms[0].packed; - - var _iteratorNormalCompletion6 = true; - var _didIteratorError6 = false; - var _iteratorError6 = undefined; - - try { - for (var _iterator6 = basePerms[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { - var perm = _step6.value; - - basePerm = basePerm | perm.packed; - } - } catch (err) { - _didIteratorError6 = true; - _iteratorError6 = err; - } finally { - try { - if (!_iteratorNormalCompletion6 && _iterator6["return"]) { - _iterator6["return"](); - } - } finally { - if (_didIteratorError6) { - throw _iteratorError6; - } - } - } - - return new ServerPermissions({ - permissions: basePerm - }); - } - }]); - - return Member; -})(User); - -module.exports = Member; \ No newline at end of file +"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 User=require("./user.js");var ServerPermissions=require("./ServerPermissions.js");var EvaluatedPermissions=require("./EvaluatedPermissions.js");var Member=(function(_User){_inherits(Member,_User);function Member(user,server,roles){_classCallCheck(this,Member);_User.call(this,user); // should work, we are basically creating a Member that has the same properties as user and a few more +this.server = server;this.rawRoles = roles;}Member.prototype.permissionsIn = function permissionsIn(channel){if(channel.server.ownerID === this.id){return new EvaluatedPermissions(4294967295); //all perms +}var affectingOverwrites=[];var affectingMemberOverwrites=[];for(var _iterator=channel.roles,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var overwrite=_ref;if(overwrite.id === this.id && overwrite.type === "member"){affectingMemberOverwrites.push(overwrite);}else if(this.rawRoles.indexOf(overwrite.id) !== -1){affectingOverwrites.push(overwrite);}}for(var _iterator2=affectingOverwrites,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var perm=_ref2;console.log("hey",perm.attachFiles);}if(affectingOverwrites.length === 0 && affectingMemberOverwrites.length === 0){return new EvaluatedPermissions(this.evalPerms.packed);}var finalPacked=affectingOverwrites.length !== 0?affectingOverwrites[0].packed:affectingMemberOverwrites[0].packed;for(var _iterator3=affectingOverwrites,_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[Symbol.iterator]();;) {var _ref3;if(_isArray3){if(_i3 >= _iterator3.length)break;_ref3 = _iterator3[_i3++];}else {_i3 = _iterator3.next();if(_i3.done)break;_ref3 = _i3.value;}var overwrite=_ref3;finalPacked = finalPacked & ~overwrite.deny;finalPacked = finalPacked | overwrite.allow;}for(var _iterator4=affectingMemberOverwrites,_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[Symbol.iterator]();;) {var _ref4;if(_isArray4){if(_i4 >= _iterator4.length)break;_ref4 = _iterator4[_i4++];}else {_i4 = _iterator4.next();if(_i4.done)break;_ref4 = _i4.value;}var overwrite=_ref4;finalPacked = finalPacked & ~overwrite.deny;finalPacked = finalPacked | overwrite.allow;}return new EvaluatedPermissions(finalPacked);};_createClass(Member,[{key:"roles",get:function get(){var ufRoles=[this.server.getRole(this.server.id)];for(var _iterator5=this.rawRoles,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var rawRole=_ref5;ufRoles.push(this.server.getRole(rawRole));}return ufRoles;}},{key:"evalPerms",get:function get(){var basePerms=this.roles, //cache roles as it can be slightly expensive +basePerm=basePerms[0].packed;for(var _iterator6=basePerms,_isArray6=Array.isArray(_iterator6),_i6=0,_iterator6=_isArray6?_iterator6:_iterator6[Symbol.iterator]();;) {var _ref6;if(_isArray6){if(_i6 >= _iterator6.length)break;_ref6 = _iterator6[_i6++];}else {_i6 = _iterator6.next();if(_i6.done)break;_ref6 = _i6.value;}var perm=_ref6;basePerm = basePerm | perm.packed;}return new ServerPermissions({permissions:basePerm});}}]);return Member;})(User);module.exports = Member; diff --git a/lib/PMChannel.js b/lib/PMChannel.js index f777d342c..8d90dade1 100644 --- a/lib/PMChannel.js +++ b/lib/PMChannel.js @@ -1,72 +1 @@ -"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 PMChannel = (function () { - function PMChannel(data, client) { - _classCallCheck(this, PMChannel); - - this.user = client.getUser("id", data.recipient.id); - this.id = data.id; - this.messages = []; - this.client = client; - } - - _createClass(PMChannel, [{ - key: "addMessage", - value: function addMessage(data) { - if (!this.getMessage("id", data.id)) { - this.messages.push(data); - } - return this.getMessage("id", data.id); - } - }, { - key: "getMessage", - value: function getMessage(key, value) { - - if (this.messages.length > 1000) { - this.messages.splice(0, 1); - } - - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = this.messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var message = _step.value; - - if (message[key] === value) { - return message; - } - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - - return null; - } - }, { - key: "isPrivate", - get: function get() { - return true; - } - }]); - - return PMChannel; -})(); - -module.exports = PMChannel; \ No newline at end of file +"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 PMChannel=(function(){function PMChannel(data,client){_classCallCheck(this,PMChannel);this.user = client.getUser("id",data.recipient.id);this.id = data.id;this.messages = [];this.client = client;}PMChannel.prototype.addMessage = function addMessage(data){if(!this.getMessage("id",data.id)){this.messages.push(data);}return this.getMessage("id",data.id);};PMChannel.prototype.getMessage = function getMessage(key,value){if(this.messages.length > 1000){this.messages.splice(0,1);}for(var _iterator=this.messages,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var message=_ref;if(message[key] === value){return message;}}return null;};_createClass(PMChannel,[{key:"isPrivate",get:function get(){return true;}}]);return PMChannel;})();module.exports = PMChannel; diff --git a/lib/channel.js b/lib/channel.js index 4ff1e673c..04c363943 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -1,152 +1,2 @@ -"use strict"; - -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var ChannelPermissions = require("./ChannelPermissions.js"); - -var Channel = (function () { - function Channel(data, server) { - _classCallCheck(this, Channel); - - this.server = server; - this.name = data.name; - this.type = data.type; - this.topic = data.topic; - this.id = data.id; - this.messages = []; - this.roles = []; - - if (data.permission_overwrites) { - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = data.permission_overwrites[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var role = _step.value; - - this.roles.push(new ChannelPermissions(role, this)); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - } //this.isPrivate = isPrivate; //not sure about the implementation of this... - } - - _createClass(Channel, [{ - key: "permissionsOf", - value: function permissionsOf(member) { - - var mem = this.server.getMember("id", member.id); - - if (mem) { - return mem.permissionsIn(this); - } else { - return null; - } - } - }, { - key: "equals", - value: function equals(object) { - return object && object.id === this.id; - } - }, { - key: "addMessage", - value: function addMessage(data) { - - if (this.messages.length > 1000) { - this.messages.splice(0, 1); - } - - if (!this.getMessage("id", data.id)) { - this.messages.push(data); - } - - return this.getMessage("id", data.id); - } - }, { - key: "getMessage", - value: function getMessage(key, value) { - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; - - try { - for (var _iterator2 = this.messages[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var message = _step2.value; - - if (message[key] === value) { - return message; - } - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { - try { - if (!_iteratorNormalCompletion2 && _iterator2["return"]) { - _iterator2["return"](); - } - } finally { - if (_didIteratorError2) { - throw _iteratorError2; - } - } - } - - return null; - } - }, { - key: "toString", - value: function toString() { - return "<#" + this.id + ">"; - } - }, { - key: "permissionOverwrites", - get: function get() { - return this.roles; - } - }, { - key: "permissions", - get: function get() { - return this.roles; - } - }, { - key: "client", - get: function get() { - return this.server.client; - } - }, { - key: "isPrivate", - get: function get() { - return false; - } - }, { - key: "users", - get: function get() { - return this.server.members; - } - }, { - key: "members", - get: function get() { - return this.server.members; - } - }]); - - return Channel; -})(); - -module.exports = Channel; \ No newline at end of file +"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var ChannelPermissions=require("./ChannelPermissions.js");var Channel=(function(){function Channel(data,server){_classCallCheck(this,Channel);this.server = server;this.name = data.name;this.type = data.type;this.topic = data.topic;this.id = data.id;this.messages = [];this.roles = [];if(data.permission_overwrites)for(var _iterator=data.permission_overwrites,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var role=_ref;this.roles.push(new ChannelPermissions(role,this));} //this.isPrivate = isPrivate; //not sure about the implementation of this... +}Channel.prototype.permissionsOf = function permissionsOf(member){var mem=this.server.getMember("id",member.id);if(mem){return mem.permissionsIn(this);}else {return null;}};Channel.prototype.equals = function equals(object){return object && object.id === this.id;};Channel.prototype.addMessage = function addMessage(data){if(this.messages.length > 1000){this.messages.splice(0,1);}if(!this.getMessage("id",data.id)){this.messages.push(data);}return this.getMessage("id",data.id);};Channel.prototype.getMessage = function getMessage(key,value){for(var _iterator2=this.messages,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var message=_ref2;if(message[key] === value){return message;}}return null;};Channel.prototype.toString = function toString(){return "<#" + this.id + ">";};_createClass(Channel,[{key:"permissionOverwrites",get:function get(){return this.roles;}},{key:"permissions",get:function get(){return this.roles;}},{key:"client",get:function get(){return this.server.client;}},{key:"isPrivate",get:function get(){return false;}},{key:"users",get:function get(){return this.server.members;}},{key:"members",get:function get(){return this.server.members;}}]);return Channel;})();module.exports = Channel; diff --git a/lib/index.js b/lib/index.js index 6a2f82f05..9eabba0ae 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,12 +1 @@ -"use strict"; - -var request = require("superagent"); -var Endpoints = require("./Endpoints.js"); -var Client = require("./Client.js"); - -var Discord = { - Endpoints: Endpoints, - Client: Client -}; - -module.exports = Discord; \ No newline at end of file +"use strict";var request=require("superagent");var Endpoints=require("./Endpoints.js");var Client=require("./Client.js");var Discord={Endpoints:Endpoints,Client:Client};module.exports = Discord; diff --git a/lib/internal.js b/lib/internal.js index 3acf5940b..b91c38597 100644 --- a/lib/internal.js +++ b/lib/internal.js @@ -1,203 +1 @@ -"use strict"; - -var request = require("superagent"); -var Endpoints = require("./endpoints.js"); - -var Internal = {}; - -Internal.XHR = {}; -Internal.WebSocket = {}; - -Internal.WebSocket.properties = { - "$os": "discord.js", - "$browser": "discord.js", - "$device": "discord.js", - "$referrer": "", - "$referring_domain": "" -}; - -Internal.XHR.login = function (email, password, callback) { - - request.post(Endpoints.LOGIN).send({ - email: email, - password: password - }).end(function (err, res) { - if (err) { - callback(err); - } else { - callback(null, res.body.token); - } - }); -}; - -Internal.XHR.logout = function (token, callback) { - - request.post(Endpoints.LOGOUT).end(function (err, res) { - - err ? callback(err) : callback(null); - }); -}; - -Internal.XHR.createServer = function (token, name, region, callback) { - - request.post(Endpoints.SERVERS).set("authorization", token).send({ - name: name, - region: region - }).end(function (err, res) { - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.leaveServer = function (token, serverId, callback) { - - request.del(Endpoints.SERVERS + "/" + serverId).set("authorization", token).end(function (err, res) { - - err ? callback(err) : callback(null); - }); -}; - -Internal.XHR.createInvite = function (token, channelId, options, callback) { - request.post(Endpoints.CHANNELS + "/" + channelId + "/invites").set("authorization", token).send(options).end(function (err, res) { - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.startPM = function (token, selfID, userID, callback) { - - request.post(Endpoints.USERS + "/" + selfID + "/channels").set("authorization", token).send({ - recipient_id: userID - }).end(function (err, res) { - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.sendMessage = function (token, channelID, messageParameters, callback) { - request.post(Endpoints.CHANNELS + "/" + channelID + "/messages").set("authorization", token).send(messageParameters).end(function (err, res) { - - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.sendFile = function (token, channelID, file, fileName, callback) { - request.post(Endpoints.CHANNELS + "/" + channelID + "/messages").set("authorization", token).attach("file", file, fileName).end(function (err, res) { - - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.deleteMessage = function (token, channelID, messageID, callback) { - request.del(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID).set("authorization", token).end(function (err) { - err ? callback(err) : callback(null); - }); -}; - -Internal.XHR.updateMessage = function (token, channelID, messageID, messageParameters, callback) { - - request.patch(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID).set("authorization", token).send(messageParameters).end(function (err, res) { - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.getChannelLogs = function (token, channelID, amount, callback) { - request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization", token).end(function (err, res) { - - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.createChannel = function (token, serverID, name, type, callback) { - request.post(Endpoints.SERVERS + "/" + serverID + "/channels").set("authorization", token).send({ - name: name, - type: type - }).end(function (err, res) { - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.deleteChannel = function (token, channelID, callback) { - - request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization", token).end(function (err) { - err ? callback(err) : callback(null); - }); -}; -Internal.XHR.deleteServer = function (token, serverID, callback) { - request.del(Endpoints.SERVERS + "/" + serverID).set("authorization", token).end(function (err) { - err ? callback(err) : callback(null); - }); -}; - -Internal.XHR.getChannels = function (token, serverID, callback) { - request.get(Endpoints.SERVERS + "/" + serverID + "/channels").set("authorization", token).end(function (err) { - err ? callback(err) : callback(null); - }); -}; - -Internal.XHR.getServer = function (token, serverID, callback) { - - request.get(Endpoints.SERVERS + "/" + serverID).set("authorization", token).end(function (err, res) { - - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.acceptInvite = function (token, inviteID, callback) { - - request.post(Endpoints.API + "/invite/" + inviteID).set("authorization", token).end(function (err, res) { - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.setUsername = function (token, avatar, email, newPassword, password, username, callback) { - - request.patch(Endpoints.API + "/users/@me").set("authorization", token).send({ - avatar: avatar, - email: email, - new_password: newPassword, - password: password, - username: username - }).end(function (err) { - callback(err); - }); -}; - -exports.Internal = Internal; \ No newline at end of file +"use strict";var request=require("superagent");var Endpoints=require("./endpoints.js");var Internal={};Internal.XHR = {};Internal.WebSocket = {};Internal.WebSocket.properties = {"$os":"discord.js","$browser":"discord.js","$device":"discord.js","$referrer":"","$referring_domain":""};Internal.XHR.login = function(email,password,callback){request.post(Endpoints.LOGIN).send({email:email,password:password}).end(function(err,res){if(err){callback(err);}else {callback(null,res.body.token);}});};Internal.XHR.logout = function(token,callback){request.post(Endpoints.LOGOUT).end(function(err,res){err?callback(err):callback(null);});};Internal.XHR.createServer = function(token,name,region,callback){request.post(Endpoints.SERVERS).set("authorization",token).send({name:name,region:region}).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.leaveServer = function(token,serverId,callback){request.del(Endpoints.SERVERS + "/" + serverId).set("authorization",token).end(function(err,res){err?callback(err):callback(null);});};Internal.XHR.createInvite = function(token,channelId,options,callback){request.post(Endpoints.CHANNELS + "/" + channelId + "/invites").set("authorization",token).send(options).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.startPM = function(token,selfID,userID,callback){request.post(Endpoints.USERS + "/" + selfID + "/channels").set("authorization",token).send({recipient_id:userID}).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.sendMessage = function(token,channelID,messageParameters,callback){request.post(Endpoints.CHANNELS + "/" + channelID + "/messages").set("authorization",token).send(messageParameters).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.sendFile = function(token,channelID,file,fileName,callback){request.post(Endpoints.CHANNELS + "/" + channelID + "/messages").set("authorization",token).attach("file",file,fileName).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.deleteMessage = function(token,channelID,messageID,callback){request.del(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID).set("authorization",token).end(function(err){err?callback(err):callback(null);});};Internal.XHR.updateMessage = function(token,channelID,messageID,messageParameters,callback){request.patch(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID).set("authorization",token).send(messageParameters).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.getChannelLogs = function(token,channelID,amount,callback){request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization",token).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.createChannel = function(token,serverID,name,type,callback){request.post(Endpoints.SERVERS + "/" + serverID + "/channels").set("authorization",token).send({name:name,type:type}).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.deleteChannel = function(token,channelID,callback){request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization",token).end(function(err){err?callback(err):callback(null);});};Internal.XHR.deleteServer = function(token,serverID,callback){request.del(Endpoints.SERVERS + "/" + serverID).set("authorization",token).end(function(err){err?callback(err):callback(null);});};Internal.XHR.getChannels = function(token,serverID,callback){request.get(Endpoints.SERVERS + "/" + serverID + "/channels").set("authorization",token).end(function(err){err?callback(err):callback(null);});};Internal.XHR.getServer = function(token,serverID,callback){request.get(Endpoints.SERVERS + "/" + serverID).set("authorization",token).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.acceptInvite = function(token,inviteID,callback){request.post(Endpoints.API + "/invite/" + inviteID).set("authorization",token).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.setUsername = function(token,avatar,email,newPassword,password,username,callback){request.patch(Endpoints.API + "/users/@me").set("authorization",token).send({avatar:avatar,email:email,new_password:newPassword,password:password,username:username}).end(function(err){callback(err);});};exports.Internal = Internal; diff --git a/lib/invite.js b/lib/invite.js index 5f51dc1a9..5ff2ddf15 100644 --- a/lib/invite.js +++ b/lib/invite.js @@ -1,35 +1 @@ -"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 Invite = (function () { - function Invite(data, client) { - _classCallCheck(this, Invite); - - this.max_age = data.max_age; - this.code = data.code; - this.server = client.getServer("id", data.guild.id); - this.revoked = data.revoked; - this.created_at = Date.parse(data.created_at); - this.temporary = data.temporary; - this.uses = data.uses; - this.max_uses = data.uses; - this.inviter = client.addUser(data.inviter); - this.xkcd = data.xkcdpass; - this.channel = client.getChannel("id", data.channel.id); - } - - _createClass(Invite, [{ - key: "URL", - get: function get() { - var code = this.xkcd ? this.xkcdpass : this.code; - return "https://discord.gg/" + code; - } - }]); - - return Invite; -})(); - -module.exports = Invite; \ No newline at end of file +"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 Invite=(function(){function Invite(data,client){_classCallCheck(this,Invite);this.max_age = data.max_age;this.code = data.code;this.server = client.getServer("id",data.guild.id);this.revoked = data.revoked;this.created_at = Date.parse(data.created_at);this.temporary = data.temporary;this.uses = data.uses;this.max_uses = data.uses;this.inviter = client.addUser(data.inviter);this.xkcd = data.xkcdpass;this.channel = client.getChannel("id",data.channel.id);}_createClass(Invite,[{key:"URL",get:function get(){var code=this.xkcd?this.xkcdpass:this.code;return "https://discord.gg/" + code;}}]);return Invite;})();module.exports = Invite; diff --git a/lib/message.js b/lib/message.js index a156acc81..26d9e4f69 100644 --- a/lib/message.js +++ b/lib/message.js @@ -1,85 +1,3 @@ -"use strict"; - -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var PMChannel = require("./PMChannel.js"); - -var Message = (function () { - function Message(data, channel, mentions, author) { - _classCallCheck(this, Message); - - this.tts = data.tts; - this.timestamp = Date.parse(data.timestamp); - this.nonce = data.nonce; - this.mentions = mentions; - this.everyoneMentioned = data.mention_everyone; - this.id = data.id; - this.embeds = data.embeds; - this.editedTimestamp = data.edited_timestamp; - this.content = data.content.trim(); - this.channel = channel; - - if (this.isPrivate) { - this.author = this.channel.client.getUser("id", author.id); - } else { - this.author = this.channel.server.getMember("id", author.id) || this.channel.client.getUser("id", author.id); - } - - this.attachments = data.attachments; - } - - /*exports.Message.prototype.isPM = function() { - return ( this.channel instanceof PMChannel ); - }*/ - - _createClass(Message, [{ - key: "isMentioned", - value: function isMentioned(user) { - var id = user.id ? user.id : user; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = this.mentions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var mention = _step.value; - - if (mention.id === id) { - return true; - } - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - - return false; - } - }, { - key: "sender", - get: function get() { - return this.author; - } - }, { - key: "isPrivate", - get: function get() { - return this.channel.isPrivate; - } - }]); - - return Message; -})(); - -module.exports = Message; \ No newline at end of file +"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 PMChannel=require("./PMChannel.js");var Message=(function(){function Message(data,channel,mentions,author){_classCallCheck(this,Message);this.tts = data.tts;this.timestamp = Date.parse(data.timestamp);this.nonce = data.nonce;this.mentions = mentions;this.everyoneMentioned = data.mention_everyone;this.id = data.id;this.embeds = data.embeds;this.editedTimestamp = data.edited_timestamp;this.content = data.content.trim();this.channel = channel;if(this.isPrivate){this.author = this.channel.client.getUser("id",author.id);}else {this.author = this.channel.server.getMember("id",author.id) || this.channel.client.getUser("id",author.id);}this.attachments = data.attachments;} /*exports.Message.prototype.isPM = function() { + return ( this.channel instanceof PMChannel ); +}*/Message.prototype.isMentioned = function isMentioned(user){var id=user.id?user.id:user;for(var _iterator=this.mentions,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var mention=_ref;if(mention.id === id){return true;}}return false;};_createClass(Message,[{key:"sender",get:function get(){return this.author;}},{key:"isPrivate",get:function get(){return this.channel.isPrivate;}}]);return Message;})();module.exports = Message; diff --git a/package.json b/package.json index 379bc779a..503109720 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.8.3", + "version": "3.8.4", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { diff --git a/web-dist/discord.3.8.4.js b/web-dist/discord.3.8.4.js new file mode 100644 index 000000000..f05aef245 --- /dev/null +++ b/web-dist/discord.3.8.4.js @@ -0,0 +1,1534 @@ +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Discord = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o>> x & 1) === 1;}this.type = data.type; //either member or role +this.id = data.id;if(this.type === "member"){this.packed = channel.server.getMember("id",data.id).evalPerms.packed;}else {this.packed = channel.server.getRole(data.id).packed;}this.packed = this.packed & ~data.deny;this.packed = this.packed | data.allow;this.deny = data.deny;this.allow = data.allow;}ChannelPermissions.prototype.getBit = function getBit(x){return (this.packed >>> x & 1) === 1;};ChannelPermissions.prototype.setBit = function setBit(){};_createClass(ChannelPermissions,[{key:"createInstantInvite",get:function get(){return this.getBit(0);},set:function set(val){this.setBit(0,val);}},{key:"manageRoles",get:function get(){return this.getBit(3);},set:function set(val){this.setBit(3,val);}},{key:"manageChannels",get:function get(){return this.getBit(4);},set:function set(val){this.setBit(4,val);}},{key:"readMessages",get:function get(){return this.getBit(10);},set:function set(val){this.setBit(10,val);}},{key:"sendMessages",get:function get(){return this.getBit(11);},set:function set(val){this.setBit(11,val);}},{key:"sendTTSMessages",get:function get(){return this.getBit(12);},set:function set(val){this.setBit(12,val);}},{key:"manageMessages",get:function get(){return this.getBit(13);},set:function set(val){this.setBit(13,val);}},{key:"embedLinks",get:function get(){return this.getBit(14);},set:function set(val){this.setBit(14,val);}},{key:"attachFiles",get:function get(){return this.getBit(15);},set:function set(val){this.setBit(15,val);}},{key:"readMessageHistory",get:function get(){return this.getBit(16);},set:function set(val){this.setBit(16,val);}},{key:"mentionEveryone",get:function get(){return this.getBit(17);},set:function set(val){this.setBit(17,val);}},{key:"voiceConnect",get:function get(){return this.getBit(20);},set:function set(val){this.setBit(20,val);}},{key:"voiceSpeak",get:function get(){return this.getBit(21);},set:function set(val){this.setBit(21,val);}},{key:"voiceMuteMembers",get:function get(){return this.getBit(22);},set:function set(val){this.setBit(22,val);}},{key:"voiceDeafenMembers",get:function get(){return this.getBit(23);},set:function set(val){this.setBit(23,val);}},{key:"voiceMoveMembers",get:function get(){return this.getBit(24);},set:function set(val){this.setBit(24,val);}},{key:"voiceUseVoiceActivation",get:function get(){return this.getBit(25);},set:function set(val){this.setBit(25,val);}}]);return ChannelPermissions;})();module.exports = ChannelPermissions; + +},{}],2:[function(require,module,exports){ +//discord.js modules +"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 Endpoints=require("./Endpoints.js");var User=require("./user.js");var Server=require("./server.js");var Channel=require("./channel.js");var Message=require("./message.js");var Invite=require("./invite.js");var PMChannel=require("./PMChannel.js");var gameMap=require("../ref/gameMap.json"); //node modules +var request=require("superagent");var WebSocket=require("ws");var fs=require("fs");var defaultOptions={queue:false};var Client=(function(){function Client(){var options=arguments.length <= 0 || arguments[0] === undefined?defaultOptions:arguments[0];var token=arguments.length <= 1 || arguments[1] === undefined?undefined:arguments[1];_classCallCheck(this,Client); /* + When created, if a token is specified the Client will + try connecting with it. If the token is incorrect, no + further efforts will be made to connect. + */this.options = options;this.options.queue = this.options.queue;this.token = token;this.state = 0;this.websocket = null;this.events = {};this.user = null;this.alreadySentData = false;this.serverCreateListener = {};this.typingIntervals = {};this.email = "abc";this.password = "abc"; /* + State values: + 0 - idle + 1 - logging in + 2 - logged in + 3 - ready + 4 - disconnected + */this.userCache = [];this.channelCache = [];this.serverCache = [];this.pmChannelCache = [];this.readyTime = null;this.checkingQueue = {};this.userTypingListener = {};this.queue = {};this.__idleTime = null;this.__gameId = null;}Client.prototype.sendPacket = function sendPacket(JSONObject){if(this.websocket.readyState === 1){this.websocket.send(JSON.stringify(JSONObject));}}; //def debug +Client.prototype.debug = function debug(message){this.trigger("debug",message);};Client.prototype.on = function on(event,fn){this.events[event] = fn;};Client.prototype.off = function off(event){this.events[event] = null;};Client.prototype.keepAlive = function keepAlive(){this.debug("keep alive triggered");this.sendPacket({op:1,d:Date.now()});}; //def trigger +Client.prototype.trigger = function trigger(event){var args=[];for(var arg in arguments) {args.push(arguments[arg]);}var evt=this.events[event];if(evt){evt.apply(this,args.slice(1));}}; //def login +Client.prototype.login = function login(){var email=arguments.length <= 0 || arguments[0] === undefined?"foo@bar.com":arguments[0];var password=arguments.length <= 1 || arguments[1] === undefined?"pass1234":arguments[1];var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,token){}:arguments[2];var self=this;return new Promise(function(resolve,reject){if(self.state === 0 || self.state === 4){self.state = 1; //set the state to logging in +self.email = email;self.password = password;request.post(Endpoints.LOGIN).send({email:email,password:password}).end(function(err,res){if(err){self.state = 4; //set state to disconnected +self.trigger("disconnected");if(self.websocket){self.websocket.close();}callback(err);reject(err);}else {self.state = 2; //set state to logged in (not yet ready) +self.token = res.body.token; //set our token +self.getGateway().then(function(url){self.createws(url);callback(null,self.token);resolve(self.token);})["catch"](function(err){callback(err);reject(err);});}});}else {reject(new Error("Client already logging in or ready"));}});};Client.prototype.logout = function logout(){var callback=arguments.length <= 0 || arguments[0] === undefined?function(err){}:arguments[0];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.LOGOUT).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {self.websocket.close();self.state = 4;callback();resolve();}});});};Client.prototype.createServer = function createServer(name,region){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,server){}:arguments[2];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.SERVERS).set("authorization",self.token).send({name:name,region:region}).end(function(err,res){if(err){callback(err);reject(err);}else { // potentially redundant in future +// creating here does NOT give us the channels of the server +// so we must wait for the guild_create event. +self.serverCreateListener[res.body.id] = [resolve,callback]; /*var srv = self.addServer(res.body); + callback(null, srv); + resolve(srv);*/}});});};Client.prototype.createChannel = function createChannel(server,channelName,channelType){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,chann){}:arguments[3];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.SERVERS + "/" + self.resolveServerID(server) + "/channels").set("authorization",self.token).send({name:channelName,type:channelType}).end(function(err,res){if(err){callback(err);reject(err);}else {var server=self.getServer("id",res.body.guild_id);var chann=self.addChannel(res.body,res.body.guild_id);server.addChannel(chann);callback(null,chann);resolve(chann);}});});};Client.prototype.leaveServer = function leaveServer(server){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,server){}:arguments[1];var self=this;return new Promise(function(resolve,reject){request.del(Endpoints.SERVERS + "/" + self.resolveServerID(server)).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {self.serverCache.splice(self.serverCache.indexOf(server),1);callback(null);resolve();}});});};Client.prototype.createInvite = function createInvite(serverOrChannel,options){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,invite){}:arguments[2];var self=this;return new Promise(function(resolve,reject){var destination;if(serverOrChannel instanceof Server){destination = serverOrChannel.id;}else if(serverOrChannel instanceof Channel){destination = serverOrChannel.id;}else {destination = serverOrChannel;}options = options || {};options.max_age = options.maxAge || 0;options.max_uses = options.maxUses || 0;options.temporary = options.temporary || false;options.xkcdpass = options.xkcd || false;request.post(Endpoints.CHANNELS + "/" + destination + "/invites").set("authorization",self.token).send(options).end(function(err,res){if(err){callback(err);reject(err);}else {var inv=new Invite(res.body,self);callback(null,inv);resolve(inv);}});});};Client.prototype.startPM = function startPM(user){var self=this;return new Promise(function(resolve,reject){var userId=user;if(user instanceof User){userId = user.id;}request.post(Endpoints.USERS + "/" + self.user.id + "/channels").set("authorization",self.token).send({recipient_id:userId}).end(function(err,res){if(err){reject(err);}else {resolve(self.addPMChannel(res.body));}});});};Client.prototype.reply = function reply(destination,message,tts){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var self=this;return new Promise(function(response,reject){if(typeof tts === "function"){ // tts is a function, which means the developer wants this to be the callback +callback = tts;tts = false;}var user=destination.sender;self.sendMessage(destination,message,tts,callback,user + ", ").then(response)["catch"](reject);});};Client.prototype.deleteMessage = function deleteMessage(message,timeout){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,msg){}:arguments[2];var self=this;return new Promise(function(resolve,reject){if(timeout){setTimeout(remove,timeout);}else {remove();}function remove(){request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization",self.token).end(function(err,res){if(err){bad();}else {good();}});}function good(){callback();resolve();}function bad(err){callback(err);reject(err);}});};Client.prototype.updateMessage = function updateMessage(message,content){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,msg){}:arguments[2];var self=this;var prom=new Promise(function(resolve,reject){content = content instanceof Array?content.join("\n"):content;if(self.options.queue){if(!self.queue[message.channel.id]){self.queue[message.channel.id] = [];}self.queue[message.channel.id].push({action:"updateMessage",message:message,content:content,then:good,error:bad});self.checkQueue(message.channel.id);}else {self._updateMessage(message,content).then(good)["catch"](bad);}function good(msg){prom.message = msg;callback(null,msg);resolve(msg);}function bad(error){prom.error = error;callback(error);reject(error);}});return prom;};Client.prototype.setUsername = function setUsername(newName){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){request.patch(Endpoints.API + "/users/@me").set("authorization",self.token).send({avatar:self.user.avatar,email:self.email,new_password:null,password:self.password,username:newName}).end(function(err){callback(err);if(err)reject(err);else resolve();});});};Client.prototype.getChannelLogs = function getChannelLogs(channel){var amount=arguments.length <= 1 || arguments[1] === undefined?500:arguments[1];var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,logs){}:arguments[2];var self=this;return new Promise(function(resolve,reject){var channelID=channel;if(channel instanceof Channel){channelID = channel.id;}request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {var logs=[];var channel=self.getChannel("id",channelID);for(var _iterator=res.body,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var message=_ref;var mentions=[];for(var _iterator2=message.mentions,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var mention=_ref2;mentions.push(self.addUser(mention));}var author=self.addUser(message.author);logs.push(new Message(message,channel,mentions,author));}callback(null,logs);resolve(logs);}});});};Client.prototype.deleteChannel = function deleteChannel(channel){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){var channelID=channel;if(channel instanceof Channel){channelID = channel.id;}request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization",self.token).end(function(err){if(err){callback(err);reject(err);}else {callback(null);resolve();}});});};Client.prototype.joinServer = function joinServer(invite){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,server){}:arguments[1];var self=this;return new Promise(function(resolve,reject){var id=invite instanceof Invite?invite.code:invite;request.post(Endpoints.API + "/invite/" + id).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {if(self.getServer("id",res.body.guild.id)){resolve(self.getServer("id",res.body.guild.id));}else {self.serverCreateListener[res.body.guild.id] = [resolve,callback];}}});});};Client.prototype.sendFile = function sendFile(destination,file){var fileName=arguments.length <= 2 || arguments[2] === undefined?"image.png":arguments[2];var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var self=this;var prom=new Promise(function(resolve,reject){var fstream;if(typeof file === "string" || file instanceof String){fstream = fs.createReadStream(file);fileName = file;}else {fstream = file;}self.resolveDestination(destination).then(send)["catch"](bad);function send(destination){if(self.options.queue){ //queue send file too +if(!self.queue[destination]){self.queue[destination] = [];}self.queue[destination].push({action:"sendFile",attachment:fstream,attachmentName:fileName,then:good,error:bad});self.checkQueue(destination);}else { //not queue +self._sendFile(destination,fstream,fileName).then(good)["catch"](bad);}}function good(msg){prom.message = msg;callback(null,msg);resolve(msg);}function bad(err){prom.error = err;callback(err);reject(err);}});return prom;};Client.prototype.sendMessage = function sendMessage(destination,message,tts){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var premessage=arguments.length <= 4 || arguments[4] === undefined?"":arguments[4];var self=this;var prom=new Promise(function(resolve,reject){if(typeof tts === "function"){ // tts is a function, which means the developer wants this to be the callback +callback = tts;tts = false;}message = premessage + resolveMessage(message);var mentions=resolveMentions();self.resolveDestination(destination).then(send)["catch"](error);function error(err){callback(err);reject(err);}function send(destination){if(self.options.queue){ //we're QUEUEING messages, so sending them sequentially based on servers. +if(!self.queue[destination]){self.queue[destination] = [];}self.queue[destination].push({action:"sendMessage",content:message,mentions:mentions,tts:!!tts, //incase it's not a boolean +then:mgood,error:mbad});self.checkQueue(destination);}else {self._sendMessage(destination,message,tts,mentions).then(mgood)["catch"](mbad);}}function mgood(msg){prom.message = msg;callback(null,msg);resolve(msg);}function mbad(error){prom.error = error;callback(error);reject(error);}function resolveMessage(){var msg=message;if(message instanceof Array){msg = message.join("\n");}return msg;}function resolveMentions(){var _mentions=[];for(var _iterator3=message.match(/<@[^>]*>/g) || [],_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[Symbol.iterator]();;) {var _ref3;if(_isArray3){if(_i3 >= _iterator3.length)break;_ref3 = _iterator3[_i3++];}else {_i3 = _iterator3.next();if(_i3.done)break;_ref3 = _i3.value;}var mention=_ref3;_mentions.push(mention.substring(2,mention.length - 1));}return _mentions;}});return prom;}; //def createws +Client.prototype.createws = function createws(url){if(this.websocket)return false;var self=this; //good to go +this.websocket = new WebSocket(url); //open +this.websocket.onopen = function(){self.trySendConnData(); //try connecting +}; //close +this.websocket.onclose = function(){self.trigger("disconnected");}; //message +this.websocket.onmessage = function(e){var dat=false,data={};try{dat = JSON.parse(e.data);data = dat.d;}catch(err) {self.trigger("error",err,e);return;}self.trigger("raw",dat); //valid message +switch(dat.t){case "READY":self.debug("received ready packet");self.user = self.addUser(data.user);for(var _iterator4=data.guilds,_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[Symbol.iterator]();;) {var _ref4;if(_isArray4){if(_i4 >= _iterator4.length)break;_ref4 = _iterator4[_i4++];}else {_i4 = _iterator4.next();if(_i4.done)break;_ref4 = _i4.value;}var _server=_ref4;var server=self.addServer(_server);}for(var _iterator5=data.private_channels,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var _pmc=_ref5;var pmc=self.addPMChannel(_pmc);}self.trigger("ready");self.readyTime = Date.now();self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users.");self.state = 3;setInterval(function(){self.keepAlive.apply(self);},data.heartbeat_interval);break;case "MESSAGE_CREATE":self.debug("received message");var mentions=[];data.mentions = data.mentions || []; //for some reason this was not defined at some point? +for(var _iterator6=data.mentions,_isArray6=Array.isArray(_iterator6),_i6=0,_iterator6=_isArray6?_iterator6:_iterator6[Symbol.iterator]();;) {var _ref6;if(_isArray6){if(_i6 >= _iterator6.length)break;_ref6 = _iterator6[_i6++];}else {_i6 = _iterator6.next();if(_i6.done)break;_ref6 = _i6.value;}var mention=_ref6;mentions.push(self.addUser(mention));}var channel=self.getChannel("id",data.channel_id);if(channel){var msg=channel.addMessage(new Message(data,channel,mentions,self.addUser(data.author)));self.trigger("message",msg);}break;case "MESSAGE_DELETE":self.debug("message deleted");var channel=self.getChannel("id",data.channel_id);var message=channel.getMessage("id",data.id);if(message){self.trigger("messageDelete",channel,message);channel.messages.splice(channel.messages.indexOf(message),1);}else { //don't have the cache of that message ;( +self.trigger("messageDelete",channel);}break;case "MESSAGE_UPDATE":self.debug("message updated");var channel=self.getChannel("id",data.channel_id);var formerMessage=channel.getMessage("id",data.id);if(formerMessage){ //new message might be partial, so we need to fill it with whatever the old message was. +var info={};for(var key in formerMessage) {info[key] = formerMessage[key];}for(var key in data) {info[key] = data[key];}var mentions=[];for(var _iterator7=info.mentions,_isArray7=Array.isArray(_iterator7),_i7=0,_iterator7=_isArray7?_iterator7:_iterator7[Symbol.iterator]();;) {var _ref7;if(_isArray7){if(_i7 >= _iterator7.length)break;_ref7 = _iterator7[_i7++];}else {_i7 = _iterator7.next();if(_i7.done)break;_ref7 = _i7.value;}var mention=_ref7;mentions.push(self.addUser(mention));}var newMessage=new Message(info,channel,mentions,formerMessage.author);self.trigger("messageUpdate",newMessage,formerMessage);channel.messages[channel.messages.indexOf(formerMessage)] = newMessage;} // message isn't in cache, and if it's a partial it could cause +// all hell to break loose... best to just act as if nothing happened +break;case "GUILD_DELETE":var server=self.getServer("id",data.id);if(server){self.serverCache.splice(self.serverCache.indexOf(server),1);self.trigger("serverDelete",server);}break;case "CHANNEL_DELETE":var channel=self.getChannel("id",data.id);if(channel){var server=channel.server;if(server){server.channels.splice(server.channels.indexOf(channel),1);}self.trigger("channelDelete",channel);self.serverCache.splice(self.serverCache.indexOf(channel),1);}break;case "GUILD_CREATE":var server=self.getServer("id",data.id);if(!server){ //if server doesn't already exist because duh +server = self.addServer(data);} /*else if(server.channels.length === 0){ + + var srv = new Server(data, self); + for(channel of data.channels){ + srv.channels.push(new Channel(channel, data.id)); + } + self.serverCache[self.serverCache.indexOf(server)] = srv; + + }*/if(self.serverCreateListener[data.id]){var cbs=self.serverCreateListener[data.id];cbs[0](server); //promise then callback +cbs[1](null,server); //legacy callback +self.serverCreateListener[data.id] = null;}self.trigger("serverCreate",server);break;case "CHANNEL_CREATE":var channel=self.getChannel("id",data.id);if(!channel){var chann;if(data.is_private){chann = self.addPMChannel(data);}else {chann = self.addChannel(data,data.guild_id);}var srv=self.getServer("id",data.guild_id);if(srv){srv.addChannel(chann);}self.trigger("channelCreate",chann);}break;case "GUILD_MEMBER_ADD":var server=self.getServer("id",data.guild_id);if(server){var user=self.addUser(data.user); //if for whatever reason it doesn't exist.. +self.trigger("serverNewMember",server.addMember(user,data.roles),server);}break;case "GUILD_MEMBER_REMOVE":var server=self.getServer("id",data.guild_id);if(server){var user=self.addUser(data.user); //if for whatever reason it doesn't exist.. +server.removeMember("id",user.id);self.trigger("serverRemoveMember",user,server);}break;case "USER_UPDATE":if(self.user && data.id === self.user.id){var newUser=new User(data); //not actually adding to the cache +self.trigger("userUpdate",newUser,self.user);if(~self.userCache.indexOf(self.user)){self.userCache[self.userCache.indexOf(self.user)] = newUser;}self.user = newUser;}break;case "PRESENCE_UPDATE":var userInCache=self.getUser("id",data.user.id);if(userInCache){ //user exists +data.user.username = data.user.username || userInCache.username;data.user.id = data.user.id || userInCache.id;data.user.discriminator = data.user.discriminator || userInCache.discriminator;data.user.avatar = data.user.avatar || userInCache.avatar;var presenceUser=new User(data.user);if(presenceUser.equalsStrict(userInCache)){ //they're exactly the same, an actual presence update +self.trigger("presence",{user:userInCache,oldStatus:userInCache.status,status:data.status,server:self.getServer("id",data.guild_id),gameId:data.game_id});userInCache.status = data.status;userInCache.gameId = data.game_id;}else { //one of their details changed. +self.userCache[self.userCache.indexOf(userInCache)] = presenceUser;self.trigger("userUpdate",userInCache,presenceUser);}}break;case "CHANNEL_UPDATE":var channelInCache=self.getChannel("id",data.id),serverInCache=self.getServer("id",data.guild_id);if(channelInCache && serverInCache){var newChann=new Channel(data,serverInCache);newChann.messages = channelInCache.messages;self.trigger("channelUpdate",channelInCache,newChann);self.channelCache[self.channelCache.indexOf(channelInCache)] = newChann;}break;case "TYPING_START":var userInCache=self.getUser("id",data.user_id);var channelInCache=self.getChannel("id",data.channel_id);if(!self.userTypingListener[data.user_id] || self.userTypingListener[data.user_id] === -1){self.trigger("startTyping",userInCache,channelInCache);}self.userTypingListener[data.user_id] = Date.now();setTimeout(function(){if(self.userTypingListener[data.user_id] === -1){return;}if(Date.now() - self.userTypingListener[data.user_id] > 6000){ // stopped typing +self.trigger("stopTyping",userInCache,channelInCache);self.userTypingListener[data.user_id] = -1;}},6000);break;case "GUILD_ROLE_DELETE":var server=self.getServer("id",data.guild_id);var role=server.getRole(data.role_id);self.trigger("serverRoleDelete",server,role);server.removeRole(role.id);break;case "GUILD_ROLE_UPDATE":var server=self.getServer("id",data.guild_id);var role=server.getRole(data.role.id);var newRole=server.updateRole(data.role);self.trigger("serverRoleUpdate",server,role,newRole);break;default:self.debug("received unknown packet");self.trigger("unknown",dat);break;}};}; //def addUser +Client.prototype.addUser = function addUser(data){if(!this.getUser("id",data.id)){this.userCache.push(new User(data));}return this.getUser("id",data.id);}; //def addChannel +Client.prototype.addChannel = function addChannel(data,serverId){if(!this.getChannel("id",data.id)){this.channelCache.push(new Channel(data,this.getServer("id",serverId)));}return this.getChannel("id",data.id);};Client.prototype.addPMChannel = function addPMChannel(data){if(!this.getPMChannel("id",data.id)){this.pmChannelCache.push(new PMChannel(data,this));}return this.getPMChannel("id",data.id);};Client.prototype.setTopic = function setTopic(channel,topic){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err){}:arguments[2];var self=this;return new Promise(function(resolve,reject){self.resolveDestination(channel).then(next)["catch"](error);function error(e){callback(e);reject(e);}function next(destination){var asChan=self.getChannel("id",destination);request.patch(Endpoints.CHANNELS + "/" + destination).set("authorization",self.token).send({name:asChan.name,position:0,topic:topic}).end(function(err,res){if(err){error(err);}else {asChan.topic = res.body.topic;resolve();callback();}});}});}; //def addServer +Client.prototype.addServer = function addServer(data){var self=this;var server=this.getServer("id",data.id);if(data.unavailable){self.trigger("unavailable",data);self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached.");return;}if(!server){server = new Server(data,this);this.serverCache.push(server);if(data.channels){for(var _iterator8=data.channels,_isArray8=Array.isArray(_iterator8),_i8=0,_iterator8=_isArray8?_iterator8:_iterator8[Symbol.iterator]();;) {var _ref8;if(_isArray8){if(_i8 >= _iterator8.length)break;_ref8 = _iterator8[_i8++];}else {_i8 = _iterator8.next();if(_i8.done)break;_ref8 = _i8.value;}var channel=_ref8;server.channels.push(this.addChannel(channel,server.id));}}}for(var _iterator9=data.presences,_isArray9=Array.isArray(_iterator9),_i9=0,_iterator9=_isArray9?_iterator9:_iterator9[Symbol.iterator]();;) {var _ref9;if(_isArray9){if(_i9 >= _iterator9.length)break;_ref9 = _iterator9[_i9++];}else {_i9 = _iterator9.next();if(_i9.done)break;_ref9 = _i9.value;}var presence=_ref9;var user=self.getUser("id",presence.user.id);user.status = presence.status;user.gameId = presence.game_id;}return server;}; //def getUser +Client.prototype.getUser = function getUser(key,value){for(var _iterator10=this.userCache,_isArray10=Array.isArray(_iterator10),_i10=0,_iterator10=_isArray10?_iterator10:_iterator10[Symbol.iterator]();;) {var _ref10;if(_isArray10){if(_i10 >= _iterator10.length)break;_ref10 = _iterator10[_i10++];}else {_i10 = _iterator10.next();if(_i10.done)break;_ref10 = _i10.value;}var user=_ref10;if(user[key] === value){return user;}}return null;}; //def getChannel +Client.prototype.getChannel = function getChannel(key,value){for(var _iterator11=this.channelCache,_isArray11=Array.isArray(_iterator11),_i11=0,_iterator11=_isArray11?_iterator11:_iterator11[Symbol.iterator]();;) {var _ref11;if(_isArray11){if(_i11 >= _iterator11.length)break;_ref11 = _iterator11[_i11++];}else {_i11 = _iterator11.next();if(_i11.done)break;_ref11 = _i11.value;}var channel=_ref11;if(channel[key] === value){return channel;}}return this.getPMChannel(key,value); //might be a PM +};Client.prototype.getPMChannel = function getPMChannel(key,value){for(var _iterator12=this.pmChannelCache,_isArray12=Array.isArray(_iterator12),_i12=0,_iterator12=_isArray12?_iterator12:_iterator12[Symbol.iterator]();;) {var _ref12;if(_isArray12){if(_i12 >= _iterator12.length)break;_ref12 = _iterator12[_i12++];}else {_i12 = _iterator12.next();if(_i12.done)break;_ref12 = _i12.value;}var channel=_ref12;if(channel[key] === value){return channel;}}return null;}; //def getServer +Client.prototype.getServer = function getServer(key,value){for(var _iterator13=this.serverCache,_isArray13=Array.isArray(_iterator13),_i13=0,_iterator13=_isArray13?_iterator13:_iterator13[Symbol.iterator]();;) {var _ref13;if(_isArray13){if(_i13 >= _iterator13.length)break;_ref13 = _iterator13[_i13++];}else {_i13 = _iterator13.next();if(_i13.done)break;_ref13 = _i13.value;}var server=_ref13;if(server[key] === value){return server;}}return null;}; //def trySendConnData +Client.prototype.trySendConnData = function trySendConnData(){if(this.token && !this.alreadySentData){this.alreadySentData = true;var data={op:2,d:{token:this.token,v:3,properties:{"$os":"discord.js","$browser":"discord.js","$device":"discord.js","$referrer":"","$referring_domain":""}}};this.websocket.send(JSON.stringify(data));}};Client.prototype.resolveServerID = function resolveServerID(resource){if(resource instanceof Server){return resource.id;}else if(!isNaN(resource) && resource.length && resource.length === 17){return resource;}};Client.prototype.resolveDestination = function resolveDestination(destination){var channId=false;var self=this;return new Promise(function(resolve,reject){if(destination instanceof Server){channId = destination.id; //general is the same as server id +}else if(destination instanceof Channel){channId = destination.id;}else if(destination instanceof Message){channId = destination.channel.id;}else if(destination instanceof PMChannel){channId = destination.id;}else if(destination instanceof User){ //check if we have a PM +for(var _iterator14=self.pmChannelCache,_isArray14=Array.isArray(_iterator14),_i14=0,_iterator14=_isArray14?_iterator14:_iterator14[Symbol.iterator]();;) {var _ref14;if(_isArray14){if(_i14 >= _iterator14.length)break;_ref14 = _iterator14[_i14++];}else {_i14 = _iterator14.next();if(_i14.done)break;_ref14 = _i14.value;}var pmc=_ref14;if(pmc.user && pmc.user.equals(destination)){resolve(pmc.id);return;}} //we don't, at this point we're late +self.startPM(destination).then(function(pmc){resolve(pmc.id);})["catch"](reject);}else {channId = destination;}if(channId)resolve(channId);else reject();});};Client.prototype._sendMessage = function _sendMessage(destination,content,tts,mentions){var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization",self.token).send({content:content,mentions:mentions,tts:tts}).end(function(err,res){if(err){reject(err);}else {var data=res.body;var mentions=[];data.mentions = data.mentions || []; //for some reason this was not defined at some point? +for(var _iterator15=data.mentions,_isArray15=Array.isArray(_iterator15),_i15=0,_iterator15=_isArray15?_iterator15:_iterator15[Symbol.iterator]();;) {var _ref15;if(_isArray15){if(_i15 >= _iterator15.length)break;_ref15 = _iterator15[_i15++];}else {_i15 = _iterator15.next();if(_i15.done)break;_ref15 = _i15.value;}var mention=_ref15;mentions.push(self.addUser(mention));}var channel=self.getChannel("id",data.channel_id);if(channel){var msg=channel.addMessage(new Message(data,channel,mentions,self.addUser(data.author)));resolve(msg);}}});});};Client.prototype._sendFile = function _sendFile(destination,attachment){var attachmentName=arguments.length <= 2 || arguments[2] === undefined?"DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png":arguments[2];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization",self.token).attach("file",attachment,attachmentName).end(function(err,res){if(err){reject(err);}else {var chann=self.getChannel("id",destination);if(chann){var msg=chann.addMessage(new Message(res.body,chann,[],self.user));resolve(msg);}}});});};Client.prototype._updateMessage = function _updateMessage(message,content){var self=this;return new Promise(function(resolve,reject){request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization",self.token).send({content:content,mentions:[]}).end(function(err,res){if(err){reject(err);}else {var msg=new Message(res.body,message.channel,message.mentions,message.sender);resolve(msg);message.channel.messages[message.channel.messages.indexOf(message)] = msg;}});});};Client.prototype.getGateway = function getGateway(){var self=this;return new Promise(function(resolve,reject){request.get(Endpoints.API + "/gateway").set("authorization",self.token).end(function(err,res){if(err){reject(err);}else {resolve(res.body.url);}});});};Client.prototype.setStatusIdle = function setStatusIdle(){this.setStatus("idle");};Client.prototype.setStatusOnline = function setStatusOnline(){this.setStatus("online");};Client.prototype.setStatusActive = function setStatusActive(){this.setStatusOnline();};Client.prototype.setStatusHere = function setStatusHere(){this.setStatusOnline();};Client.prototype.setStatusAway = function setStatusAway(){this.setStatusIdle();};Client.prototype.startTyping = function startTyping(chann,stopTypeTime){var self=this;this.resolveDestination(chann).then(next);function next(channel){if(self.typingIntervals[channel]){return;}var fn=function fn(){request.post(Endpoints.CHANNELS + "/" + channel + "/typing").set("authorization",self.token).end();};fn();var interval=setInterval(fn,3000);self.typingIntervals[channel] = interval;if(stopTypeTime){setTimeout(function(){self.stopTyping(channel);},stopTypeTime);}}};Client.prototype.stopTyping = function stopTyping(chann){var self=this;this.resolveDestination(chann).then(next);function next(channel){if(!self.typingIntervals[channel]){return;}clearInterval(self.typingIntervals[channel]);delete self.typingIntervals[channel];}};Client.prototype.setStatus = function setStatus(stat){var idleTime=stat === "online"?null:Date.now();this.__idleTime = idleTime;this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}));};Client.prototype.setPlayingGame = function setPlayingGame(id){if(id instanceof String || typeof id === "string"){ // working on names +var gid=id.trim().toUpperCase();id = null;for(var _iterator16=gameMap,_isArray16=Array.isArray(_iterator16),_i16=0,_iterator16=_isArray16?_iterator16:_iterator16[Symbol.iterator]();;) {var _ref16;if(_isArray16){if(_i16 >= _iterator16.length)break;_ref16 = _iterator16[_i16++];}else {_i16 = _iterator16.next();if(_i16.done)break;_ref16 = _i16.value;}var game=_ref16;if(game.name.trim().toUpperCase() === gid){id = game.id;break;}}}this.__gameId = id;this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}));};Client.prototype.playGame = function playGame(id){this.setPlayingGame(id);};Client.prototype.playingGame = function playingGame(id){this.setPlayingGame(id);};_createClass(Client,[{key:"uptime",get:function get(){return this.readyTime?Date.now() - this.readyTime:null;}},{key:"ready",get:function get(){return this.state === 3;}},{key:"servers",get:function get(){return this.serverCache;}},{key:"channels",get:function get(){return this.channelCache;}},{key:"users",get:function get(){return this.userCache;}},{key:"PMChannels",get:function get(){return this.pmChannelCache;}},{key:"messages",get:function get(){var msgs=[];for(var _iterator17=this.channelCache,_isArray17=Array.isArray(_iterator17),_i17=0,_iterator17=_isArray17?_iterator17:_iterator17[Symbol.iterator]();;) {var _ref17;if(_isArray17){if(_i17 >= _iterator17.length)break;_ref17 = _iterator17[_i17++];}else {_i17 = _iterator17.next();if(_i17.done)break;_ref17 = _i17.value;}var channel=_ref17;msgs = msgs.concat(channel.messages);}return msgs;}}]);return Client;})();module.exports = Client; + +},{"../ref/gameMap.json":19,"./Endpoints.js":3,"./PMChannel.js":6,"./channel.js":8,"./invite.js":10,"./message.js":11,"./server.js":12,"./user.js":13,"fs":14,"superagent":15,"ws":18}],3:[function(require,module,exports){ +"use strict";exports.BASE_DOMAIN = "discordapp.com";exports.BASE = "https://" + exports.BASE_DOMAIN;exports.WEBSOCKET_HUB = "wss://" + exports.BASE_DOMAIN + "/hub";exports.API = exports.BASE + "/api";exports.AUTH = exports.API + "/auth";exports.LOGIN = exports.AUTH + "/login";exports.LOGOUT = exports.AUTH + "/logout";exports.USERS = exports.API + "/users";exports.SERVERS = exports.API + "/guilds";exports.CHANNELS = exports.API + "/channels"; + +},{}],4:[function(require,module,exports){ +"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 EvaluatedPermissions=(function(){function EvaluatedPermissions(data){_classCallCheck(this,EvaluatedPermissions);var self=this;function getBit(x){if((self.packed >>> 3 & 1) === 1){return true;}return (self.packed >>> x & 1) === 1;}this.packed = data;}EvaluatedPermissions.prototype.getBit = function getBit(x){return (this.packed >>> x & 1) === 1;};EvaluatedPermissions.prototype.setBit = function setBit(){};_createClass(EvaluatedPermissions,[{key:"createInstantInvite",get:function get(){return this.getBit(0);},set:function set(val){this.setBit(0,val);}},{key:"manageRoles",get:function get(){return this.getBit(3);},set:function set(val){this.setBit(3,val);}},{key:"manageChannels",get:function get(){return this.getBit(4);},set:function set(val){this.setBit(4,val);}},{key:"readMessages",get:function get(){return this.getBit(10);},set:function set(val){this.setBit(10,val);}},{key:"sendMessages",get:function get(){return this.getBit(11);},set:function set(val){this.setBit(11,val);}},{key:"sendTTSMessages",get:function get(){return this.getBit(12);},set:function set(val){this.setBit(12,val);}},{key:"manageMessages",get:function get(){return this.getBit(13);},set:function set(val){this.setBit(13,val);}},{key:"embedLinks",get:function get(){return this.getBit(14);},set:function set(val){this.setBit(14,val);}},{key:"attachFiles",get:function get(){return this.getBit(15);},set:function set(val){this.setBit(15,val);}},{key:"readMessageHistory",get:function get(){return this.getBit(16);},set:function set(val){this.setBit(16,val);}},{key:"mentionEveryone",get:function get(){return this.getBit(17);},set:function set(val){this.setBit(17,val);}},{key:"voiceConnect",get:function get(){return this.getBit(20);},set:function set(val){this.setBit(20,val);}},{key:"voiceSpeak",get:function get(){return this.getBit(21);},set:function set(val){this.setBit(21,val);}},{key:"voiceMuteMembers",get:function get(){return this.getBit(22);},set:function set(val){this.setBit(22,val);}},{key:"voiceDeafenMembers",get:function get(){return this.getBit(23);},set:function set(val){this.setBit(23,val);}},{key:"voiceMoveMembers",get:function get(){return this.getBit(24);},set:function set(val){this.setBit(24,val);}},{key:"voiceUseVoiceActivation",get:function get(){return this.getBit(25);},set:function set(val){this.setBit(25,val);}}]);return EvaluatedPermissions;})();module.exports = EvaluatedPermissions; + +},{}],5:[function(require,module,exports){ +"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 User=require("./user.js");var ServerPermissions=require("./ServerPermissions.js");var EvaluatedPermissions=require("./EvaluatedPermissions.js");var Member=(function(_User){_inherits(Member,_User);function Member(user,server,roles){_classCallCheck(this,Member);_User.call(this,user); // should work, we are basically creating a Member that has the same properties as user and a few more +this.server = server;this.rawRoles = roles;}Member.prototype.permissionsIn = function permissionsIn(channel){if(channel.server.ownerID === this.id){return new EvaluatedPermissions(4294967295); //all perms +}var affectingOverwrites=[];var affectingMemberOverwrites=[];for(var _iterator=channel.roles,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var overwrite=_ref;if(overwrite.id === this.id && overwrite.type === "member"){affectingMemberOverwrites.push(overwrite);}else if(this.rawRoles.indexOf(overwrite.id) !== -1){affectingOverwrites.push(overwrite);}}for(var _iterator2=affectingOverwrites,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var perm=_ref2;console.log("hey",perm.attachFiles);}if(affectingOverwrites.length === 0 && affectingMemberOverwrites.length === 0){return new EvaluatedPermissions(this.evalPerms.packed);}var finalPacked=affectingOverwrites.length !== 0?affectingOverwrites[0].packed:affectingMemberOverwrites[0].packed;for(var _iterator3=affectingOverwrites,_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[Symbol.iterator]();;) {var _ref3;if(_isArray3){if(_i3 >= _iterator3.length)break;_ref3 = _iterator3[_i3++];}else {_i3 = _iterator3.next();if(_i3.done)break;_ref3 = _i3.value;}var overwrite=_ref3;finalPacked = finalPacked & ~overwrite.deny;finalPacked = finalPacked | overwrite.allow;}for(var _iterator4=affectingMemberOverwrites,_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[Symbol.iterator]();;) {var _ref4;if(_isArray4){if(_i4 >= _iterator4.length)break;_ref4 = _iterator4[_i4++];}else {_i4 = _iterator4.next();if(_i4.done)break;_ref4 = _i4.value;}var overwrite=_ref4;finalPacked = finalPacked & ~overwrite.deny;finalPacked = finalPacked | overwrite.allow;}return new EvaluatedPermissions(finalPacked);};_createClass(Member,[{key:"roles",get:function get(){var ufRoles=[this.server.getRole(this.server.id)];for(var _iterator5=this.rawRoles,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var rawRole=_ref5;ufRoles.push(this.server.getRole(rawRole));}return ufRoles;}},{key:"evalPerms",get:function get(){var basePerms=this.roles, //cache roles as it can be slightly expensive +basePerm=basePerms[0].packed;for(var _iterator6=basePerms,_isArray6=Array.isArray(_iterator6),_i6=0,_iterator6=_isArray6?_iterator6:_iterator6[Symbol.iterator]();;) {var _ref6;if(_isArray6){if(_i6 >= _iterator6.length)break;_ref6 = _iterator6[_i6++];}else {_i6 = _iterator6.next();if(_i6.done)break;_ref6 = _i6.value;}var perm=_ref6;basePerm = basePerm | perm.packed;}return new ServerPermissions({permissions:basePerm});}}]);return Member;})(User);module.exports = Member; + +},{"./EvaluatedPermissions.js":4,"./ServerPermissions.js":7,"./user.js":13}],6:[function(require,module,exports){ +"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 PMChannel=(function(){function PMChannel(data,client){_classCallCheck(this,PMChannel);this.user = client.getUser("id",data.recipient.id);this.id = data.id;this.messages = [];this.client = client;}PMChannel.prototype.addMessage = function addMessage(data){if(!this.getMessage("id",data.id)){this.messages.push(data);}return this.getMessage("id",data.id);};PMChannel.prototype.getMessage = function getMessage(key,value){if(this.messages.length > 1000){this.messages.splice(0,1);}for(var _iterator=this.messages,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var message=_ref;if(message[key] === value){return message;}}return null;};_createClass(PMChannel,[{key:"isPrivate",get:function get(){return true;}}]);return PMChannel;})();module.exports = PMChannel; + +},{}],7:[function(require,module,exports){ +"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 ServerPermissions=(function(){function ServerPermissions(data){_classCallCheck(this,ServerPermissions);var self=this;function getBit(x){return (self.packed >>> x & 1) === 1;}this.packed = data.permissions;this.name = data.name;this.id = data.id;}ServerPermissions.prototype.getBit = function getBit(x){return (this.packed >>> x & 1) === 1;};ServerPermissions.prototype.setBit = function setBit(){ //dummy function for now +};ServerPermissions.prototype.toString = function toString(){return this.name;};_createClass(ServerPermissions,[{key:"createInstantInvite",get:function get(){return this.getBit(0);},set:function set(val){this.setBit(0,val);}},{key:"banMembers",get:function get(){return this.getBit(1);},set:function set(val){this.setBit(1,val);}},{key:"kickMembers",get:function get(){return this.getBit(2);},set:function set(val){this.setBit(2,val);}},{key:"manageRoles",get:function get(){return this.getBit(3);},set:function set(val){this.setBit(3,val);}},{key:"manageChannels",get:function get(){return this.getBit(4);},set:function set(val){this.setBit(4,val);}},{key:"manageServer",get:function get(){return this.getBit(5);},set:function set(val){this.setBit(5,val);}},{key:"readMessages",get:function get(){return this.getBit(10);},set:function set(val){this.setBit(10,val);}},{key:"sendMessages",get:function get(){return this.getBit(11);},set:function set(val){this.setBit(11,val);}},{key:"sendTTSMessages",get:function get(){return this.getBit(12);},set:function set(val){this.setBit(12,val);}},{key:"manageMessages",get:function get(){return this.getBit(13);},set:function set(val){this.setBit(13,val);}},{key:"embedLinks",get:function get(){return this.getBit(14);},set:function set(val){this.setBit(14,val);}},{key:"attachFiles",get:function get(){return this.getBit(15);},set:function set(val){this.setBit(15,val);}},{key:"readMessageHistory",get:function get(){return this.getBit(16);},set:function set(val){this.setBit(16,val);}},{key:"mentionEveryone",get:function get(){return this.getBit(17);},set:function set(val){this.setBit(17,val);}},{key:"voiceConnect",get:function get(){return this.getBit(20);},set:function set(val){this.setBit(20,val);}},{key:"voiceSpeak",get:function get(){return this.getBit(21);},set:function set(val){this.setBit(21,val);}},{key:"voiceMuteMembers",get:function get(){return this.getBit(22);},set:function set(val){this.setBit(22,val);}},{key:"voiceDeafenMembers",get:function get(){return this.getBit(23);},set:function set(val){this.setBit(23,val);}},{key:"voiceMoveMembers",get:function get(){return this.getBit(24);},set:function set(val){this.setBit(24,val);}},{key:"voiceUseVoiceActivation",get:function get(){return this.getBit(25);},set:function set(val){this.setBit(25,val);}}]);return ServerPermissions;})();module.exports = ServerPermissions; + +},{}],8:[function(require,module,exports){ +"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var ChannelPermissions=require("./ChannelPermissions.js");var Channel=(function(){function Channel(data,server){_classCallCheck(this,Channel);this.server = server;this.name = data.name;this.type = data.type;this.topic = data.topic;this.id = data.id;this.messages = [];this.roles = [];if(data.permission_overwrites)for(var _iterator=data.permission_overwrites,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var role=_ref;this.roles.push(new ChannelPermissions(role,this));} //this.isPrivate = isPrivate; //not sure about the implementation of this... +}Channel.prototype.permissionsOf = function permissionsOf(member){var mem=this.server.getMember("id",member.id);if(mem){return mem.permissionsIn(this);}else {return null;}};Channel.prototype.equals = function equals(object){return object && object.id === this.id;};Channel.prototype.addMessage = function addMessage(data){if(this.messages.length > 1000){this.messages.splice(0,1);}if(!this.getMessage("id",data.id)){this.messages.push(data);}return this.getMessage("id",data.id);};Channel.prototype.getMessage = function getMessage(key,value){for(var _iterator2=this.messages,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var message=_ref2;if(message[key] === value){return message;}}return null;};Channel.prototype.toString = function toString(){return "<#" + this.id + ">";};_createClass(Channel,[{key:"permissionOverwrites",get:function get(){return this.roles;}},{key:"permissions",get:function get(){return this.roles;}},{key:"client",get:function get(){return this.server.client;}},{key:"isPrivate",get:function get(){return false;}},{key:"users",get:function get(){return this.server.members;}},{key:"members",get:function get(){return this.server.members;}}]);return Channel;})();module.exports = Channel; + +},{"./ChannelPermissions.js":1}],9:[function(require,module,exports){ +"use strict";var request=require("superagent");var Endpoints=require("./Endpoints.js");var Client=require("./Client.js");var Discord={Endpoints:Endpoints,Client:Client};module.exports = Discord; + +},{"./Client.js":2,"./Endpoints.js":3,"superagent":15}],10:[function(require,module,exports){ +"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 Invite=(function(){function Invite(data,client){_classCallCheck(this,Invite);this.max_age = data.max_age;this.code = data.code;this.server = client.getServer("id",data.guild.id);this.revoked = data.revoked;this.created_at = Date.parse(data.created_at);this.temporary = data.temporary;this.uses = data.uses;this.max_uses = data.uses;this.inviter = client.addUser(data.inviter);this.xkcd = data.xkcdpass;this.channel = client.getChannel("id",data.channel.id);}_createClass(Invite,[{key:"URL",get:function get(){var code=this.xkcd?this.xkcdpass:this.code;return "https://discord.gg/" + code;}}]);return Invite;})();module.exports = Invite; + +},{}],11:[function(require,module,exports){ +"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 PMChannel=require("./PMChannel.js");var Message=(function(){function Message(data,channel,mentions,author){_classCallCheck(this,Message);this.tts = data.tts;this.timestamp = Date.parse(data.timestamp);this.nonce = data.nonce;this.mentions = mentions;this.everyoneMentioned = data.mention_everyone;this.id = data.id;this.embeds = data.embeds;this.editedTimestamp = data.edited_timestamp;this.content = data.content.trim();this.channel = channel;if(this.isPrivate){this.author = this.channel.client.getUser("id",author.id);}else {this.author = this.channel.server.getMember("id",author.id) || this.channel.client.getUser("id",author.id);}this.attachments = data.attachments;} /*exports.Message.prototype.isPM = function() { + return ( this.channel instanceof PMChannel ); +}*/Message.prototype.isMentioned = function isMentioned(user){var id=user.id?user.id:user;for(var _iterator=this.mentions,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var mention=_ref;if(mention.id === id){return true;}}return false;};_createClass(Message,[{key:"sender",get:function get(){return this.author;}},{key:"isPrivate",get:function get(){return this.channel.isPrivate;}}]);return Message;})();module.exports = Message; + +},{"./PMChannel.js":6}],12:[function(require,module,exports){ +"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 ServerPermissions=require("./ServerPermissions.js");var Member=require("./Member.js");var Server=(function(){function Server(data,client){_classCallCheck(this,Server);this.client = client;this.region = data.region;this.ownerID = data.owner_id;this.name = data.name;this.id = data.id;this.members = [];this.channels = [];this.icon = data.icon;this.afkTimeout = data.afk_timeout;this.afkChannelId = data.afk_channel_id;this.roles = [];for(var _iterator=data.roles,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var permissionGroup=_ref;this.roles.push(new ServerPermissions(permissionGroup));}if(!data.members){data.members = [client.user];return;}for(var _iterator2=data.members,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var member=_ref2; // first we cache the user in our Discord Client, +// then we add it to our list. This way when we +// get a user from this server's member list, +// it will be identical (unless an async change occurred) +// to the client's cache. +if(member.user)this.addMember(client.addUser(member.user),member.roles);}} // get/set +Server.prototype.getRole = function getRole(id){for(var _iterator3=this.roles,_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[Symbol.iterator]();;) {var _ref3;if(_isArray3){if(_i3 >= _iterator3.length)break;_ref3 = _iterator3[_i3++];}else {_i3 = _iterator3.next();if(_i3.done)break;_ref3 = _i3.value;}var role=_ref3;if(role.id === id){return role;}}return null;};Server.prototype.updateRole = function updateRole(data){var oldRole=this.getRole(data.id);if(oldRole){var index=this.roles.indexOf(oldRole);this.roles[index] = new ServerPermissions(data);return this.roles[index];}else {return false;}};Server.prototype.removeRole = function removeRole(id){for(var roleId in this.roles) {if(this.roles[roleId].id === id){this.roles.splice(roleId,1);}}for(var _iterator4=this.members,_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[Symbol.iterator]();;) {var _ref4;if(_isArray4){if(_i4 >= _iterator4.length)break;_ref4 = _iterator4[_i4++];}else {_i4 = _iterator4.next();if(_i4.done)break;_ref4 = _i4.value;}var member=_ref4;for(var roleId in member.rawRoles) {if(member.rawRoles[roleId] === id){member.rawRoles.splice(roleId,1);}}}};Server.prototype.getChannel = function getChannel(key,value){for(var _iterator5=this.channels,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var channel=_ref5;if(channel[key] === value){return channel;}}return null;};Server.prototype.getMember = function getMember(key,value){for(var _iterator6=this.members,_isArray6=Array.isArray(_iterator6),_i6=0,_iterator6=_isArray6?_iterator6:_iterator6[Symbol.iterator]();;) {var _ref6;if(_isArray6){if(_i6 >= _iterator6.length)break;_ref6 = _iterator6[_i6++];}else {_i6 = _iterator6.next();if(_i6.done)break;_ref6 = _i6.value;}var member=_ref6;if(member[key] === value){return member;}}return null;};Server.prototype.removeMember = function removeMember(key,value){for(var _iterator7=this.members,_isArray7=Array.isArray(_iterator7),_i7=0,_iterator7=_isArray7?_iterator7:_iterator7[Symbol.iterator]();;) {var _ref7;if(_isArray7){if(_i7 >= _iterator7.length)break;_ref7 = _iterator7[_i7++];}else {_i7 = _iterator7.next();if(_i7.done)break;_ref7 = _i7.value;}var member=_ref7;if(member[key] === value){this.members.splice(key,1);return member;}}return false;};Server.prototype.addChannel = function addChannel(chann){if(!this.getChannel("id",chann.id)){this.channels.push(chann);}return chann;};Server.prototype.addMember = function addMember(user,roles){if(!this.getMember("id",user.id)){var mem=new Member(user,this,roles);this.members.push(mem);}return mem;};Server.prototype.toString = function toString(){return this.name;};Server.prototype.equals = function equals(object){return object.id === this.id;};_createClass(Server,[{key:"permissionGroups",get:function get(){return this.roles;}},{key:"permissions",get:function get(){return this.roles;}},{key:"iconURL",get:function get(){if(!this.icon)return null;return "https://discordapp.com/api/guilds/" + this.id + "/icons/" + this.icon + ".jpg";}},{key:"afkChannel",get:function get(){if(!this.afkChannelId)return false;return this.getChannel("id",this.afkChannelId);}},{key:"defaultChannel",get:function get(){return this.getChannel("name","general");}},{key:"owner",get:function get(){return this.client.getUser("id",this.ownerID);}},{key:"users",get:function get(){return this.members;}}]);return Server;})();module.exports = Server; + +},{"./Member.js":5,"./ServerPermissions.js":7}],13:[function(require,module,exports){ +"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 User=(function(){function User(data){_classCallCheck(this,User);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;} // access using user.avatarURL; +User.prototype.mention = function mention(){return "<@" + this.id + ">";};User.prototype.toString = function toString(){ /* + if we embed a user in a String - like so: + "Yo " + user + " what's up?" + It would generate something along the lines of: + "Yo @hydrabolt what's up?" + */return this.mention();};User.prototype.equals = function equals(object){return object.id === this.id;};User.prototype.equalsStrict = function equalsStrict(object){return object.id === this.id && object.avatar === this.avatar && object.username === this.username && object.discriminator === this.discriminator;};_createClass(User,[{key:"avatarURL",get:function get(){if(!this.avatar)return null;return "https://discordapp.com/api/users/" + this.id + "/avatars/" + this.avatar + ".jpg";}}]);return User;})();module.exports = User; + +},{}],14:[function(require,module,exports){ + +},{}],15:[function(require,module,exports){ +/** + * Module dependencies. + */ + +var Emitter = require('emitter'); +var reduce = require('reduce'); + +/** + * Root reference for iframes. + */ + +var root; +if (typeof window !== 'undefined') { // Browser window + root = window; +} else if (typeof self !== 'undefined') { // Web Worker + root = self; +} else { // Other environments + root = this; +} + +/** + * Noop. + */ + +function noop(){}; + +/** + * Check if `obj` is a host object, + * we don't want to serialize these :) + * + * TODO: future proof, move to compoent land + * + * @param {Object} obj + * @return {Boolean} + * @api private + */ + +function isHost(obj) { + var str = {}.toString.call(obj); + + switch (str) { + case '[object File]': + case '[object Blob]': + case '[object FormData]': + return true; + default: + return false; + } +} + +/** + * Determine XHR. + */ + +request.getXHR = function () { + if (root.XMLHttpRequest + && (!root.location || 'file:' != root.location.protocol + || !root.ActiveXObject)) { + return new XMLHttpRequest; + } else { + try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {} + } + return false; +}; + +/** + * Removes leading and trailing whitespace, added to support IE. + * + * @param {String} s + * @return {String} + * @api private + */ + +var trim = ''.trim + ? function(s) { return s.trim(); } + : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); }; + +/** + * Check if `obj` is an object. + * + * @param {Object} obj + * @return {Boolean} + * @api private + */ + +function isObject(obj) { + return obj === Object(obj); +} + +/** + * Serialize the given `obj`. + * + * @param {Object} obj + * @return {String} + * @api private + */ + +function serialize(obj) { + if (!isObject(obj)) return obj; + var pairs = []; + for (var key in obj) { + if (null != obj[key]) { + pairs.push(encodeURIComponent(key) + + '=' + encodeURIComponent(obj[key])); + } + } + return pairs.join('&'); +} + +/** + * Expose serialization method. + */ + + request.serializeObject = serialize; + + /** + * Parse the given x-www-form-urlencoded `str`. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function parseString(str) { + var obj = {}; + var pairs = str.split('&'); + var parts; + var pair; + + for (var i = 0, len = pairs.length; i < len; ++i) { + pair = pairs[i]; + parts = pair.split('='); + obj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]); + } + + return obj; +} + +/** + * Expose parser. + */ + +request.parseString = parseString; + +/** + * Default MIME type map. + * + * superagent.types.xml = 'application/xml'; + * + */ + +request.types = { + html: 'text/html', + json: 'application/json', + xml: 'application/xml', + urlencoded: 'application/x-www-form-urlencoded', + 'form': 'application/x-www-form-urlencoded', + 'form-data': 'application/x-www-form-urlencoded' +}; + +/** + * Default serialization map. + * + * superagent.serialize['application/xml'] = function(obj){ + * return 'generated xml here'; + * }; + * + */ + + request.serialize = { + 'application/x-www-form-urlencoded': serialize, + 'application/json': JSON.stringify + }; + + /** + * Default parsers. + * + * superagent.parse['application/xml'] = function(str){ + * return { object parsed from str }; + * }; + * + */ + +request.parse = { + 'application/x-www-form-urlencoded': parseString, + 'application/json': JSON.parse +}; + +/** + * Parse the given header `str` into + * an object containing the mapped fields. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function parseHeader(str) { + var lines = str.split(/\r?\n/); + var fields = {}; + var index; + var line; + var field; + var val; + + lines.pop(); // trailing CRLF + + for (var i = 0, len = lines.length; i < len; ++i) { + line = lines[i]; + index = line.indexOf(':'); + field = line.slice(0, index).toLowerCase(); + val = trim(line.slice(index + 1)); + fields[field] = val; + } + + return fields; +} + +/** + * Return the mime type for the given `str`. + * + * @param {String} str + * @return {String} + * @api private + */ + +function type(str){ + return str.split(/ *; */).shift(); +}; + +/** + * Return header field parameters. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function params(str){ + return reduce(str.split(/ *; */), function(obj, str){ + var parts = str.split(/ *= */) + , key = parts.shift() + , val = parts.shift(); + + if (key && val) obj[key] = val; + return obj; + }, {}); +}; + +/** + * Initialize a new `Response` with the given `xhr`. + * + * - set flags (.ok, .error, etc) + * - parse header + * + * Examples: + * + * Aliasing `superagent` as `request` is nice: + * + * request = superagent; + * + * We can use the promise-like API, or pass callbacks: + * + * request.get('/').end(function(res){}); + * request.get('/', function(res){}); + * + * Sending data can be chained: + * + * request + * .post('/user') + * .send({ name: 'tj' }) + * .end(function(res){}); + * + * Or passed to `.send()`: + * + * request + * .post('/user') + * .send({ name: 'tj' }, function(res){}); + * + * Or passed to `.post()`: + * + * request + * .post('/user', { name: 'tj' }) + * .end(function(res){}); + * + * Or further reduced to a single call for simple cases: + * + * request + * .post('/user', { name: 'tj' }, function(res){}); + * + * @param {XMLHTTPRequest} xhr + * @param {Object} options + * @api private + */ + +function Response(req, options) { + options = options || {}; + this.req = req; + this.xhr = this.req.xhr; + // responseText is accessible only if responseType is '' or 'text' and on older browsers + this.text = ((this.req.method !='HEAD' && (this.xhr.responseType === '' || this.xhr.responseType === 'text')) || typeof this.xhr.responseType === 'undefined') + ? this.xhr.responseText + : null; + this.statusText = this.req.xhr.statusText; + this.setStatusProperties(this.xhr.status); + this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders()); + // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but + // getResponseHeader still works. so we get content-type even if getting + // other headers fails. + this.header['content-type'] = this.xhr.getResponseHeader('content-type'); + this.setHeaderProperties(this.header); + this.body = this.req.method != 'HEAD' + ? this.parseBody(this.text ? this.text : this.xhr.response) + : null; +} + +/** + * Get case-insensitive `field` value. + * + * @param {String} field + * @return {String} + * @api public + */ + +Response.prototype.get = function(field){ + return this.header[field.toLowerCase()]; +}; + +/** + * Set header related properties: + * + * - `.type` the content type without params + * + * A response of "Content-Type: text/plain; charset=utf-8" + * will provide you with a `.type` of "text/plain". + * + * @param {Object} header + * @api private + */ + +Response.prototype.setHeaderProperties = function(header){ + // content-type + var ct = this.header['content-type'] || ''; + this.type = type(ct); + + // params + var obj = params(ct); + for (var key in obj) this[key] = obj[key]; +}; + +/** + * Force given parser + * + * Sets the body parser no matter type. + * + * @param {Function} + * @api public + */ + +Response.prototype.parse = function(fn){ + this.parser = fn; + return this; +}; + +/** + * Parse the given body `str`. + * + * Used for auto-parsing of bodies. Parsers + * are defined on the `superagent.parse` object. + * + * @param {String} str + * @return {Mixed} + * @api private + */ + +Response.prototype.parseBody = function(str){ + var parse = this.parser || request.parse[this.type]; + return parse && str && (str.length || str instanceof Object) + ? parse(str) + : null; +}; + +/** + * Set flags such as `.ok` based on `status`. + * + * For example a 2xx response will give you a `.ok` of __true__ + * whereas 5xx will be __false__ and `.error` will be __true__. The + * `.clientError` and `.serverError` are also available to be more + * specific, and `.statusType` is the class of error ranging from 1..5 + * sometimes useful for mapping respond colors etc. + * + * "sugar" properties are also defined for common cases. Currently providing: + * + * - .noContent + * - .badRequest + * - .unauthorized + * - .notAcceptable + * - .notFound + * + * @param {Number} status + * @api private + */ + +Response.prototype.setStatusProperties = function(status){ + // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request + if (status === 1223) { + status = 204; + } + + var type = status / 100 | 0; + + // status / class + this.status = this.statusCode = status; + this.statusType = type; + + // basics + this.info = 1 == type; + this.ok = 2 == type; + this.clientError = 4 == type; + this.serverError = 5 == type; + this.error = (4 == type || 5 == type) + ? this.toError() + : false; + + // sugar + this.accepted = 202 == status; + this.noContent = 204 == status; + this.badRequest = 400 == status; + this.unauthorized = 401 == status; + this.notAcceptable = 406 == status; + this.notFound = 404 == status; + this.forbidden = 403 == status; +}; + +/** + * Return an `Error` representative of this response. + * + * @return {Error} + * @api public + */ + +Response.prototype.toError = function(){ + var req = this.req; + var method = req.method; + var url = req.url; + + var msg = 'cannot ' + method + ' ' + url + ' (' + this.status + ')'; + var err = new Error(msg); + err.status = this.status; + err.method = method; + err.url = url; + + return err; +}; + +/** + * Expose `Response`. + */ + +request.Response = Response; + +/** + * Initialize a new `Request` with the given `method` and `url`. + * + * @param {String} method + * @param {String} url + * @api public + */ + +function Request(method, url) { + var self = this; + Emitter.call(this); + this._query = this._query || []; + this.method = method; + this.url = url; + this.header = {}; + this._header = {}; + this.on('end', function(){ + var err = null; + var res = null; + + try { + res = new Response(self); + } catch(e) { + err = new Error('Parser is unable to parse the response'); + err.parse = true; + err.original = e; + return self.callback(err); + } + + self.emit('response', res); + + if (err) { + return self.callback(err, res); + } + + if (res.status >= 200 && res.status < 300) { + return self.callback(err, res); + } + + var new_err = new Error(res.statusText || 'Unsuccessful HTTP response'); + new_err.original = err; + new_err.response = res; + new_err.status = res.status; + + self.callback(new_err, res); + }); +} + +/** + * Mixin `Emitter`. + */ + +Emitter(Request.prototype); + +/** + * Allow for extension + */ + +Request.prototype.use = function(fn) { + fn(this); + return this; +} + +/** + * Set timeout to `ms`. + * + * @param {Number} ms + * @return {Request} for chaining + * @api public + */ + +Request.prototype.timeout = function(ms){ + this._timeout = ms; + return this; +}; + +/** + * Clear previous timeout. + * + * @return {Request} for chaining + * @api public + */ + +Request.prototype.clearTimeout = function(){ + this._timeout = 0; + clearTimeout(this._timer); + return this; +}; + +/** + * Abort the request, and clear potential timeout. + * + * @return {Request} + * @api public + */ + +Request.prototype.abort = function(){ + if (this.aborted) return; + this.aborted = true; + this.xhr.abort(); + this.clearTimeout(); + this.emit('abort'); + return this; +}; + +/** + * Set header `field` to `val`, or multiple fields with one object. + * + * Examples: + * + * req.get('/') + * .set('Accept', 'application/json') + * .set('X-API-Key', 'foobar') + * .end(callback); + * + * req.get('/') + * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' }) + * .end(callback); + * + * @param {String|Object} field + * @param {String} val + * @return {Request} for chaining + * @api public + */ + +Request.prototype.set = function(field, val){ + if (isObject(field)) { + for (var key in field) { + this.set(key, field[key]); + } + return this; + } + this._header[field.toLowerCase()] = val; + this.header[field] = val; + return this; +}; + +/** + * Remove header `field`. + * + * Example: + * + * req.get('/') + * .unset('User-Agent') + * .end(callback); + * + * @param {String} field + * @return {Request} for chaining + * @api public + */ + +Request.prototype.unset = function(field){ + delete this._header[field.toLowerCase()]; + delete this.header[field]; + return this; +}; + +/** + * Get case-insensitive header `field` value. + * + * @param {String} field + * @return {String} + * @api private + */ + +Request.prototype.getHeader = function(field){ + return this._header[field.toLowerCase()]; +}; + +/** + * Set Content-Type to `type`, mapping values from `request.types`. + * + * Examples: + * + * superagent.types.xml = 'application/xml'; + * + * request.post('/') + * .type('xml') + * .send(xmlstring) + * .end(callback); + * + * request.post('/') + * .type('application/xml') + * .send(xmlstring) + * .end(callback); + * + * @param {String} type + * @return {Request} for chaining + * @api public + */ + +Request.prototype.type = function(type){ + this.set('Content-Type', request.types[type] || type); + return this; +}; + +/** + * Set Accept to `type`, mapping values from `request.types`. + * + * Examples: + * + * superagent.types.json = 'application/json'; + * + * request.get('/agent') + * .accept('json') + * .end(callback); + * + * request.get('/agent') + * .accept('application/json') + * .end(callback); + * + * @param {String} accept + * @return {Request} for chaining + * @api public + */ + +Request.prototype.accept = function(type){ + this.set('Accept', request.types[type] || type); + return this; +}; + +/** + * Set Authorization field value with `user` and `pass`. + * + * @param {String} user + * @param {String} pass + * @return {Request} for chaining + * @api public + */ + +Request.prototype.auth = function(user, pass){ + var str = btoa(user + ':' + pass); + this.set('Authorization', 'Basic ' + str); + return this; +}; + +/** +* Add query-string `val`. +* +* Examples: +* +* request.get('/shoes') +* .query('size=10') +* .query({ color: 'blue' }) +* +* @param {Object|String} val +* @return {Request} for chaining +* @api public +*/ + +Request.prototype.query = function(val){ + if ('string' != typeof val) val = serialize(val); + if (val) this._query.push(val); + return this; +}; + +/** + * Write the field `name` and `val` for "multipart/form-data" + * request bodies. + * + * ``` js + * request.post('/upload') + * .field('foo', 'bar') + * .end(callback); + * ``` + * + * @param {String} name + * @param {String|Blob|File} val + * @return {Request} for chaining + * @api public + */ + +Request.prototype.field = function(name, val){ + if (!this._formData) this._formData = new root.FormData(); + this._formData.append(name, val); + return this; +}; + +/** + * Queue the given `file` as an attachment to the specified `field`, + * with optional `filename`. + * + * ``` js + * request.post('/upload') + * .attach(new Blob(['hey!'], { type: "text/html"})) + * .end(callback); + * ``` + * + * @param {String} field + * @param {Blob|File} file + * @param {String} filename + * @return {Request} for chaining + * @api public + */ + +Request.prototype.attach = function(field, file, filename){ + if (!this._formData) this._formData = new root.FormData(); + this._formData.append(field, file, filename); + return this; +}; + +/** + * Send `data`, defaulting the `.type()` to "json" when + * an object is given. + * + * Examples: + * + * // querystring + * request.get('/search') + * .end(callback) + * + * // multiple data "writes" + * request.get('/search') + * .send({ search: 'query' }) + * .send({ range: '1..5' }) + * .send({ order: 'desc' }) + * .end(callback) + * + * // manual json + * request.post('/user') + * .type('json') + * .send('{"name":"tj"}) + * .end(callback) + * + * // auto json + * request.post('/user') + * .send({ name: 'tj' }) + * .end(callback) + * + * // manual x-www-form-urlencoded + * request.post('/user') + * .type('form') + * .send('name=tj') + * .end(callback) + * + * // auto x-www-form-urlencoded + * request.post('/user') + * .type('form') + * .send({ name: 'tj' }) + * .end(callback) + * + * // defaults to x-www-form-urlencoded + * request.post('/user') + * .send('name=tobi') + * .send('species=ferret') + * .end(callback) + * + * @param {String|Object} data + * @return {Request} for chaining + * @api public + */ + +Request.prototype.send = function(data){ + var obj = isObject(data); + var type = this.getHeader('Content-Type'); + + // merge + if (obj && isObject(this._data)) { + for (var key in data) { + this._data[key] = data[key]; + } + } else if ('string' == typeof data) { + if (!type) this.type('form'); + type = this.getHeader('Content-Type'); + if ('application/x-www-form-urlencoded' == type) { + this._data = this._data + ? this._data + '&' + data + : data; + } else { + this._data = (this._data || '') + data; + } + } else { + this._data = data; + } + + if (!obj || isHost(data)) return this; + if (!type) this.type('json'); + return this; +}; + +/** + * Invoke the callback with `err` and `res` + * and handle arity check. + * + * @param {Error} err + * @param {Response} res + * @api private + */ + +Request.prototype.callback = function(err, res){ + var fn = this._callback; + this.clearTimeout(); + fn(err, res); +}; + +/** + * Invoke callback with x-domain error. + * + * @api private + */ + +Request.prototype.crossDomainError = function(){ + var err = new Error('Origin is not allowed by Access-Control-Allow-Origin'); + err.crossDomain = true; + this.callback(err); +}; + +/** + * Invoke callback with timeout error. + * + * @api private + */ + +Request.prototype.timeoutError = function(){ + var timeout = this._timeout; + var err = new Error('timeout of ' + timeout + 'ms exceeded'); + err.timeout = timeout; + this.callback(err); +}; + +/** + * Enable transmission of cookies with x-domain requests. + * + * Note that for this to work the origin must not be + * using "Access-Control-Allow-Origin" with a wildcard, + * and also must set "Access-Control-Allow-Credentials" + * to "true". + * + * @api public + */ + +Request.prototype.withCredentials = function(){ + this._withCredentials = true; + return this; +}; + +/** + * Initiate request, invoking callback `fn(res)` + * with an instanceof `Response`. + * + * @param {Function} fn + * @return {Request} for chaining + * @api public + */ + +Request.prototype.end = function(fn){ + var self = this; + var xhr = this.xhr = request.getXHR(); + var query = this._query.join('&'); + var timeout = this._timeout; + var data = this._formData || this._data; + + // store callback + this._callback = fn || noop; + + // state change + xhr.onreadystatechange = function(){ + if (4 != xhr.readyState) return; + + // In IE9, reads to any property (e.g. status) off of an aborted XHR will + // result in the error "Could not complete the operation due to error c00c023f" + var status; + try { status = xhr.status } catch(e) { status = 0; } + + if (0 == status) { + if (self.timedout) return self.timeoutError(); + if (self.aborted) return; + return self.crossDomainError(); + } + self.emit('end'); + }; + + // progress + var handleProgress = function(e){ + if (e.total > 0) { + e.percent = e.loaded / e.total * 100; + } + self.emit('progress', e); + }; + if (this.hasListeners('progress')) { + xhr.onprogress = handleProgress; + } + try { + if (xhr.upload && this.hasListeners('progress')) { + xhr.upload.onprogress = handleProgress; + } + } catch(e) { + // Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist. + // Reported here: + // https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context + } + + // timeout + if (timeout && !this._timer) { + this._timer = setTimeout(function(){ + self.timedout = true; + self.abort(); + }, timeout); + } + + // querystring + if (query) { + query = request.serializeObject(query); + this.url += ~this.url.indexOf('?') + ? '&' + query + : '?' + query; + } + + // initiate request + xhr.open(this.method, this.url, true); + + // CORS + if (this._withCredentials) xhr.withCredentials = true; + + // body + if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) { + // serialize stuff + var contentType = this.getHeader('Content-Type'); + var serialize = request.serialize[contentType ? contentType.split(';')[0] : '']; + if (serialize) data = serialize(data); + } + + // set header fields + for (var field in this.header) { + if (null == this.header[field]) continue; + xhr.setRequestHeader(field, this.header[field]); + } + + // send stuff + this.emit('request', this); + xhr.send(data); + return this; +}; + +/** + * Faux promise support + * + * @param {Function} fulfill + * @param {Function} reject + * @return {Request} + */ + +Request.prototype.then = function (fulfill, reject) { + return this.end(function(err, res) { + err ? reject(err) : fulfill(res); + }); +} + +/** + * Expose `Request`. + */ + +request.Request = Request; + +/** + * Issue a request: + * + * Examples: + * + * request('GET', '/users').end(callback) + * request('/users').end(callback) + * request('/users', callback) + * + * @param {String} method + * @param {String|Function} url or callback + * @return {Request} + * @api public + */ + +function request(method, url) { + // callback + if ('function' == typeof url) { + return new Request('GET', method).end(url); + } + + // url first + if (1 == arguments.length) { + return new Request('GET', method); + } + + return new Request(method, url); +} + +/** + * GET `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.get = function(url, data, fn){ + var req = request('GET', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.query(data); + if (fn) req.end(fn); + return req; +}; + +/** + * HEAD `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.head = function(url, data, fn){ + var req = request('HEAD', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * DELETE `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.del = function(url, fn){ + var req = request('DELETE', url); + if (fn) req.end(fn); + return req; +}; + +/** + * PATCH `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed} data + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.patch = function(url, data, fn){ + var req = request('PATCH', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * POST `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed} data + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.post = function(url, data, fn){ + var req = request('POST', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * PUT `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.put = function(url, data, fn){ + var req = request('PUT', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * Expose `request`. + */ + +module.exports = request; + +},{"emitter":16,"reduce":17}],16:[function(require,module,exports){ + +/** + * Expose `Emitter`. + */ + +module.exports = Emitter; + +/** + * Initialize a new `Emitter`. + * + * @api public + */ + +function Emitter(obj) { + if (obj) return mixin(obj); +}; + +/** + * Mixin the emitter properties. + * + * @param {Object} obj + * @return {Object} + * @api private + */ + +function mixin(obj) { + for (var key in Emitter.prototype) { + obj[key] = Emitter.prototype[key]; + } + return obj; +} + +/** + * Listen on the given `event` with `fn`. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.on = +Emitter.prototype.addEventListener = function(event, fn){ + this._callbacks = this._callbacks || {}; + (this._callbacks[event] = this._callbacks[event] || []) + .push(fn); + return this; +}; + +/** + * Adds an `event` listener that will be invoked a single + * time then automatically removed. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.once = function(event, fn){ + var self = this; + this._callbacks = this._callbacks || {}; + + function on() { + self.off(event, on); + fn.apply(this, arguments); + } + + on.fn = fn; + this.on(event, on); + return this; +}; + +/** + * Remove the given callback for `event` or all + * registered callbacks. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.off = +Emitter.prototype.removeListener = +Emitter.prototype.removeAllListeners = +Emitter.prototype.removeEventListener = function(event, fn){ + this._callbacks = this._callbacks || {}; + + // all + if (0 == arguments.length) { + this._callbacks = {}; + return this; + } + + // specific event + var callbacks = this._callbacks[event]; + if (!callbacks) return this; + + // remove all handlers + if (1 == arguments.length) { + delete this._callbacks[event]; + return this; + } + + // remove specific handler + var cb; + for (var i = 0; i < callbacks.length; i++) { + cb = callbacks[i]; + if (cb === fn || cb.fn === fn) { + callbacks.splice(i, 1); + break; + } + } + return this; +}; + +/** + * Emit `event` with the given args. + * + * @param {String} event + * @param {Mixed} ... + * @return {Emitter} + */ + +Emitter.prototype.emit = function(event){ + this._callbacks = this._callbacks || {}; + var args = [].slice.call(arguments, 1) + , callbacks = this._callbacks[event]; + + if (callbacks) { + callbacks = callbacks.slice(0); + for (var i = 0, len = callbacks.length; i < len; ++i) { + callbacks[i].apply(this, args); + } + } + + return this; +}; + +/** + * Return array of callbacks for `event`. + * + * @param {String} event + * @return {Array} + * @api public + */ + +Emitter.prototype.listeners = function(event){ + this._callbacks = this._callbacks || {}; + return this._callbacks[event] || []; +}; + +/** + * Check if this emitter has `event` handlers. + * + * @param {String} event + * @return {Boolean} + * @api public + */ + +Emitter.prototype.hasListeners = function(event){ + return !! this.listeners(event).length; +}; + +},{}],17:[function(require,module,exports){ + +/** + * Reduce `arr` with `fn`. + * + * @param {Array} arr + * @param {Function} fn + * @param {Mixed} initial + * + * TODO: combatible error handling? + */ + +module.exports = function(arr, fn, initial){ + var idx = 0; + var len = arr.length; + var curr = arguments.length == 3 + ? initial + : arr[idx++]; + + while (idx < len) { + curr = fn.call(null, curr, arr[idx], ++idx, arr); + } + + return curr; +}; +},{}],18:[function(require,module,exports){ + +/** + * Module dependencies. + */ + +var global = (function() { return this; })(); + +/** + * WebSocket constructor. + */ + +var WebSocket = global.WebSocket || global.MozWebSocket; + +/** + * Module exports. + */ + +module.exports = WebSocket ? ws : null; + +/** + * WebSocket constructor. + * + * The third `opts` options object gets ignored in web browsers, since it's + * non-standard, and throws a TypeError if passed to the constructor. + * See: https://github.com/einaros/ws/issues/227 + * + * @param {String} uri + * @param {Array} protocols (optional) + * @param {Object) opts (optional) + * @api public + */ + +function ws(uri, protocols, opts) { + var instance; + if (protocols) { + instance = new WebSocket(uri, protocols); + } else { + instance = new WebSocket(uri); + } + return instance; +} + +if (WebSocket) ws.prototype = WebSocket.prototype; + +},{}],19:[function(require,module,exports){ +module.exports=[{"executables":{"win32":["pol.exe"]},"id":0,"name":"FINAL FANTASY XI"},{"executables":{"win32":["ffxiv.exe","ffxiv_dx11.exe"]},"id":1,"name":"FINAL FANTASY XIV"},{"executables":{"win32":["Wow.exe","Wow-64.exe"]},"id":3,"name":"World of Warcraft"},{"executables":{"darwin":["LoLLauncher.app"],"win32":["LolClient.exe","League of Legends.exe"]},"id":4,"name":"League of Legends"},{"executables":{"darwin":["Diablo%20III.app"],"win32":["Diablo III.exe"]},"id":5,"name":"Diablo 3"},{"executables":{"darwin":["dota_osx.app"],"win32":["dota2.exe"]},"id":6,"name":"DOTA 2"},{"executables":{"darwin":["Heroes.app"],"win32":["Heroes of the Storm.exe","HeroesOfTheStorm_x64.exe","HeroesOfTheStorm.exe"]},"id":7,"name":"Heroes of the Storm"},{"executables":{"darwin":["Hearthstone.app"],"win32":["Hearthstone.exe"]},"id":8,"name":"Hearthstone"},{"executables":{"win32":["csgo.exe"]},"id":9,"name":"Counter-Strike: Global Offensive"},{"executables":{"win32":["WorldOfTanks.exe"]},"id":10,"name":"World of Tanks"},{"executables":{"darwin":["gw2.app"],"win32":["gw2.exe"]},"id":11,"name":"Guild Wars 2"},{"executables":{"win32":["dayz.exe"]},"id":12,"name":"Day Z"},{"executables":{"darwin":["starcraft%20ii.app"],"win32":["starcraft ii.exe","SC2_x64.exe","SC2.exe"]},"id":13,"name":"Starcraft II"},{"executables":{"win32":["diablo.exe"]},"id":14,"name":"Diablo"},{"executables":{"win32":["diablo ii.exe"]},"id":15,"name":"Diablo 2"},{"executables":{"win32":["left4dead.exe"]},"id":17,"name":"Left 4 Dead"},{"executables":{"darwin":["minecraft.app"],"win32":["minecraft.exe"]},"id":18,"name":"Minecraft"},{"executables":{"win32":["smite.exe"]},"id":19,"name":"Smite"},{"executables":{"win32":["bf4.exe"]},"id":20,"name":"Battlefield 4"},{"executables":{"win32":["AoK HD.exe","empires2.exe"]},"id":101,"name":"Age of Empire II"},{"executables":{"win32":["age3y.exe"]},"id":102,"name":"Age of Empire III"},{"executables":{"win32":["AlanWake.exe"]},"id":104,"name":"Alan Wake"},{"executables":{"win32":["alan_wakes_american_nightmare.exe"]},"id":105,"name":"Alan Wake's American Nightmare"},{"executables":{"win32":["AlienBreed2Assault.exe"]},"id":106,"name":"Alien Breed 2: Assault"},{"executables":{"win32":["Amnesia.exe"]},"id":107,"name":"Amnesia: The Dark Descent"},{"executables":{"win32":["UDK.exe"]},"id":108,"name":"Antichamber"},{"executables":{"win32":["ArcheAge.exe"]},"id":109,"name":"ArcheAge"},{"executables":{"win32":["arma3.exe"]},"id":110,"name":"Arma III"},{"executables":{"win32":["AC3SP.exe"]},"id":111,"name":"Assassin's Creed 3"},{"executables":{"win32":["Bastion.exe"]},"id":112,"name":"Bastion"},{"executables":{"win32":["BF2.exe"]},"id":113,"name":"Battlefield 2"},{"executables":{"win32":["bf3.exe"]},"id":114,"name":"Battlefield 3"},{"executables":{"win32":["Besiege.exe"]},"id":116,"name":"Besiege"},{"executables":{"win32":["Bioshock.exe"]},"id":117,"name":"Bioshock"},{"executables":{"win32":["Bioshock2.exe"]},"id":118,"name":"BioShock II"},{"executables":{"win32":["BioShockInfinite.exe"]},"id":119,"name":"BioShock Infinite"},{"executables":{"win32":["Borderlands2.exe"]},"id":122,"name":"Borderlands 2"},{"executables":{"win32":["braid.exe"]},"id":123,"name":"Braid"},{"executables":{"win32":["ShippingPC-StormGame.exe"]},"id":124,"name":"Bulletstorm"},{"executables":{},"id":125,"name":"Cabal 2"},{"executables":{"win32":["CabalMain.exe"]},"id":126,"name":"Cabal Online"},{"executables":{"win32":["iw4mp.exe","iw4sp.exe"]},"id":127,"name":"Call of Duty: Modern Warfare 2"},{"executables":{"win32":["t6sp.exe"]},"id":128,"name":"Call of Duty: Black Ops"},{"executables":{"win32":["iw5mp.exe"]},"id":129,"name":"Call of Duty: Modern Warfare 3"},{"executables":{"win32":["RelicCOH.exe"]},"id":132,"name":"Company of Heroes"},{"executables":{"win32":["Crysis64.exe"]},"id":135,"name":"Crysis"},{"executables":{"win32":["Crysis2.exe"]},"id":136,"name":"Crysis 2"},{"executables":{"win32":["Crysis3.exe"]},"id":137,"name":"Crysis 3"},{"executables":{"win32":["Crysis.exe"]},"id":138,"name":"Crysis 4 "},{"executables":{"win32":["DATA.exe"]},"id":140,"name":"Dark Souls"},{"executables":{"win32":["DarkSoulsII.exe"]},"id":141,"name":"Dark Souls II"},{"executables":{"win32":["dfuw.exe"]},"id":142,"name":"Darkfall: Unholy Wars"},{"executables":{"win32":["DCGAME.exe"]},"id":144,"name":"DC Universe Online"},{"executables":{"win32":["DeadIslandGame.exe"]},"id":145,"name":"Dead Island"},{"executables":{"win32":["deadspace2.exe"]},"id":146,"name":"Dead Space 2"},{"executables":{"win32":["LOTDGame.exe"]},"id":147,"name":"Deadlight"},{"executables":{"win32":["dxhr.exe"]},"id":148,"name":"Deus Ex: Human Revolution"},{"executables":{"win32":["DeviMayCry4.exe"]},"id":149,"name":"Devil May Cry 4"},{"executables":{"win32":["DMC-DevilMayCry.exe"]},"id":150,"name":"DmC Devil May Cry"},{"executables":{"win32":["dirt2_game.exe"]},"id":154,"name":"DiRT 2"},{"executables":{"win32":["dirt3_game.exe"]},"id":155,"name":"DiRT 3"},{"executables":{"win32":["dota.exe"]},"id":156,"name":"DOTA"},{"executables":{"win32":["DoubleDragon.exe"]},"id":158,"name":"Double Dragon Neon"},{"executables":{"win32":["DragonAge2.exe"]},"id":159,"name":"Dragon Age II"},{"executables":{"win32":["DragonAgeInquisition.exe"]},"id":160,"name":"Dragon Age: Inquisition"},{"executables":{"win32":["daorigins.exe"]},"id":161,"name":"Dragon Age: Origins"},{"executables":{"win32":["DBXV.exe"]},"id":162,"name":"Dragon Ball XenoVerse"},{"executables":{"win32":["DukeForever.exe"]},"id":163,"name":"Duke Nukem Forever"},{"executables":{"darwin":["Dustforce.app"],"win32":["dustforce.exe"]},"id":164,"name":"Dustforce"},{"executables":{"win32":["EliteDangerous32.exe"]},"id":165,"name":"Elite: Dangerous"},{"executables":{"win32":["exefile.exe"]},"id":166,"name":"Eve Online"},{"executables":{"win32":["eqgame.exe"]},"id":167,"name":"EverQuest"},{"executables":{"win32":["EverQuest2.exe"]},"id":168,"name":"EverQuest II"},{"executables":{},"id":169,"name":"EverQuest Next"},{"executables":{"win32":["Engine.exe"]},"id":170,"name":"F.E.A.R."},{"executables":{"win32":["FEAR2.exe"]},"id":171,"name":"F.E.A.R. 2: Project Origin"},{"executables":{"win32":["fallout3.exe"]},"id":172,"name":"Fallout 3"},{"executables":{"win32":["FalloutNV.exe"]},"id":174,"name":"Fallout: New Vegas"},{"executables":{"win32":["farcry3.exe"]},"id":175,"name":"Far Cry 3"},{"executables":{"win32":["fifa15.exe"]},"id":176,"name":"FIFA 15"},{"executables":{"win32":["FTLGame.exe"]},"id":180,"name":"FTL: Faster Than Light"},{"executables":{"win32":["GTAIV.exe"]},"id":181,"name":"Grand Theft Auto 4"},{"executables":{"win32":["GTA5.exe"]},"id":182,"name":"Grand Theft Auto 5"},{"executables":{"win32":["Gw.exe"]},"id":183,"name":"Guild Wars"},{"executables":{"win32":["H1Z1.exe"]},"id":186,"name":"H1Z1"},{"executables":{"win32":["HL2HL2.exe","hl2.exe"]},"id":188,"name":"Half Life 2"},{"executables":{"win32":["HOMEFRONT.exe"]},"id":195,"name":"Homefront"},{"executables":{"win32":["invisibleinc.exe"]},"id":196,"name":"Invisible Inc."},{"executables":{"win32":["LANoire.exe"]},"id":197,"name":"L.A. Noire"},{"executables":{"win32":["Landmark64.exe"]},"id":198,"name":"Landmark"},{"executables":{"win32":["left4dead2.exe"]},"id":201,"name":"Left 4 Dead 2"},{"executables":{"win32":["lineage.exe"]},"id":203,"name":"Lineage"},{"executables":{"win32":["Magicka.exe"]},"id":206,"name":"Magicka"},{"executables":{"win32":["MapleStory.exe"]},"id":208,"name":"MapleStory"},{"executables":{},"id":209,"name":"Mark of the Ninja"},{"executables":{"win32":["MassEffect.exe"]},"id":210,"name":"Mass Effect"},{"executables":{"win32":["MassEffect2.exe"]},"id":211,"name":"Mass Effect 2"},{"executables":{"win32":["MassEffect3Demo.exe"]},"id":212,"name":"Mass Effect 3"},{"executables":{"win32":["METAL GEAR RISING REVENGEANCE.exe"]},"id":214,"name":"Metal Gear Rising: Revengeance"},{"executables":{"win32":["metro2033.exe"]},"id":215,"name":"Metro 2033"},{"executables":{"win32":["MetroLL.exe"]},"id":216,"name":"Metro Last Light"},{"executables":{"win32":["MK10.exe"]},"id":218,"name":"Mortal Kombat X"},{"executables":{"win32":["speed.exe"]},"id":219,"name":"Need For Speed Most Wanted"},{"executables":{},"id":220,"name":"Neverwinder"},{"executables":{"darwin":["Outlast.app"],"win32":["OLGame.exe"]},"id":221,"name":"Outlast"},{"executables":{"win32":["PapersPlease.exe"]},"id":222,"name":"Papers, Please"},{"executables":{"win32":["payday_win32_release.exe"]},"id":223,"name":"PAYDAY"},{"executables":{"win32":["payday2_win32_release.exe"]},"id":224,"name":"PAYDAY2"},{"executables":{"win32":["PillarsOfEternity.exe"]},"id":225,"name":"Pillars of Eternity"},{"executables":{"win32":["PA.exe"]},"id":226,"name":"Planetary Annihilation"},{"executables":{"win32":["planetside2_x86.exe"]},"id":227,"name":"Planetside 2"},{"executables":{"win32":["hl2P.exe"]},"id":228,"name":"Portal"},{"executables":{"win32":["portal2.exe"]},"id":229,"name":"Portal 2"},{"executables":{"win32":["PrimalCarnageGame.exe"]},"id":231,"name":"Primal Cargnage"},{"executables":{"win32":["pCARS.exe"]},"id":232,"name":"Project Cars"},{"executables":{"win32":["RaceTheSun.exe"]},"id":233,"name":"Race The Sun"},{"executables":{"win32":["Rage.exe"]},"id":234,"name":"RAGE"},{"executables":{"win32":["ragexe.exe"]},"id":235,"name":"Ragnarok Online"},{"executables":{"win32":["rift.exe"]},"id":236,"name":"Rift"},{"executables":{"win32":["Rocksmith2014.exe"]},"id":237,"name":"Rocksmith 2014"},{"executables":{"win32":["SwiftKit-RS.exe","JagexLauncher.exe"]},"id":238,"name":"RuneScape"},{"executables":{"win32":["Shadowgrounds.exe"]},"id":239,"name":"Shadowgrounds"},{"executables":{"win32":["survivor.exe"]},"id":240,"name":"Shadowgrounds: Survivor"},{"executables":{"win32":["ShovelKnight.exe"]},"id":241,"name":"Shovel Knight"},{"executables":{"win32":["SimCity.exe"]},"id":242,"name":"SimCity"},{"executables":{"win32":["SporeApp.exe"]},"id":245,"name":"Spore"},{"executables":{"win32":["StarCitizen.exe"]},"id":246,"name":"Star Citizen"},{"executables":{},"id":247,"name":"Star Trek Online"},{"executables":{"win32":["battlefront.exe"]},"id":248,"name":"Star Wars Battlefront"},{"executables":{"win32":["swtor.exe"]},"id":249,"name":"Star Wars: The Old Republic"},{"executables":{"win32":["starbound.exe","starbound_opengl.exe"]},"id":250,"name":"Starbound"},{"executables":{"win32":["starcraft.exe"]},"id":251,"name":"Starcraft"},{"executables":{"win32":["SSFIV.exe"]},"id":253,"name":"Ultra Street Fighter IV"},{"executables":{"win32":["superhexagon.exe"]},"id":254,"name":"Super Hexagon"},{"executables":{"win32":["swordandsworcery_pc.exe"]},"id":255,"name":"Superbrothers: Sword & Sworcery EP"},{"executables":{"win32":["hl2TF.exe"]},"id":256,"name":"Team Fortress 2"},{"executables":{"win32":["TERA.exe"]},"id":258,"name":"TERA"},{"executables":{"win32":["Terraria.exe"]},"id":259,"name":"Terraria"},{"executables":{"win32":["Bethesda.net_Launcher.exe"]},"id":260,"name":"The Elder Scrolls Online"},{"executables":{"win32":["TESV.exe"]},"id":261,"name":"The Elder Scrolls V: Skyrim"},{"executables":{"win32":["TheSecretWorld.exe"]},"id":262,"name":"The Secret World"},{"executables":{"win32":["TS3.exe","ts3w.exe"]},"id":264,"name":"The Sims 3"},{"executables":{"win32":["WALKINGDEAD101.EXE"]},"id":265,"name":"The Walking Dead"},{"executables":{"win32":["TheWalkingDead2.exe"]},"id":266,"name":"The Walking Dead Season Two"},{"executables":{"win32":["witcher3.exe"]},"id":267,"name":"The Witcher 3"},{"executables":{"win32":["Future Soldier.exe"]},"id":268,"name":"Tom Clancy's Ghost Recon: Future Solider"},{"executables":{"win32":["TombRaider.exe"]},"id":269,"name":"Tomb Raider (2013)"},{"executables":{"win32":["Torchlight.exe"]},"id":271,"name":"Torchlight"},{"executables":{"win32":["Torchlight2.exe"]},"id":272,"name":"Torchlight 2"},{"executables":{"win32":["Shogun2.exe"]},"id":273,"name":"Total War: Shogun 2"},{"executables":{"win32":["Transistor.exe"]},"id":274,"name":"Transistor"},{"executables":{"win32":["trine.exe"]},"id":275,"name":"Trine"},{"executables":{"win32":["trine2_32bit.exe"]},"id":276,"name":"Trine 2"},{"executables":{"win32":["UOKR.exe"]},"id":277,"name":"Ultima Online"},{"executables":{"win32":["aces.exe"]},"id":279,"name":"War Thunder"},{"executables":{"win32":["Warcraft III.exe","wc3.exe"]},"id":281,"name":"Warcraft 3: Reign of Chaos"},{"executables":{"win32":["Warcraft II BNE.exe"]},"id":282,"name":"Warcraft II"},{"executables":{"win32":["Warframe.x64.exe","Warframe.exe"]},"id":283,"name":"Warframe"},{"executables":{"win32":["watch_dogs.exe"]},"id":284,"name":"Watch Dogs"},{"executables":{"win32":["WildStar64.exe"]},"id":285,"name":"WildStar"},{"executables":{"win32":["XComGame.exe"]},"id":288,"name":"XCOM: Enemy Unknown"},{"executables":{"win32":["DFO.exe","dfo.exe"]},"id":289,"name":"Dungeon Fighter Online"},{"executables":{"win32":["aclauncher.exe","acclient.exe"]},"id":290,"name":"Asheron's Call"},{"executables":{"win32":["MapleStory2.exe"]},"id":291,"name":"MapleStory 2"},{"executables":{"win32":["ksp.exe"]},"id":292,"name":"Kerbal Space Program"},{"executables":{"win32":["PINBALL.EXE"]},"id":293,"name":"3D Pinball: Space Cadet"},{"executables":{"win32":["dave.exe"]},"id":294,"name":"Dangerous Dave"},{"executables":{"win32":["iwbtgbeta(slomo).exe","iwbtgbeta(fs).exe"]},"id":295,"name":"I Wanna Be The Guy"},{"executables":{"win32":["MechWarriorOnline.exe "]},"id":296,"name":"Mech Warrior Online"},{"executables":{"win32":["dontstarve_steam.exe"]},"id":297,"name":"Don't Starve"},{"executables":{"win32":["GalCiv3.exe"]},"id":298,"name":"Galactic Civilization 3"},{"executables":{"win32":["Risk of Rain.exe"]},"id":299,"name":"Risk of Rain"},{"executables":{"win32":["Binding_of_Isaac.exe","Isaac-ng.exe"]},"id":300,"name":"The Binding of Isaac"},{"executables":{"win32":["RustClient.exe"]},"id":301,"name":"Rust"},{"executables":{"win32":["Clicker Heroes.exe"]},"id":302,"name":"Clicker Heroes"},{"executables":{"win32":["Brawlhalla.exe"]},"id":303,"name":"Brawlhalla"},{"executables":{"win32":["TownOfSalem.exe"]},"id":304,"name":"Town of Salem"},{"executables":{"win32":["osu!.exe"]},"id":305,"name":"osu!"},{"executables":{"win32":["PathOfExileSteam.exe","PathOfExile.exe"]},"id":306,"name":"Path of Exile"},{"executables":{"win32":["Dolphin.exe"]},"id":307,"name":"Dolphin"},{"executables":{"win32":["RocketLeague.exe"]},"id":308,"name":"Rocket League"},{"executables":{"win32":["TJPP.exe"]},"id":309,"name":"Jackbox Party Pack"},{"executables":{"win32":["KFGame.exe"]},"id":310,"name":"Killing Floor 2"},{"executables":{"win32":["ShooterGame.exe"]},"id":311,"name":"Ark: Survival Evolved"},{"executables":{"win32":["LifeIsStrange.exe"]},"id":312,"name":"Life Is Strange"},{"executables":{"win32":["Client_tos.exe"]},"id":313,"name":"Tree of Savior"},{"executables":{"win32":["olliolli2.exe"]},"id":314,"name":"OlliOlli2"},{"executables":{"win32":["cw.exe"]},"id":315,"name":"Closers Dimension Conflict"},{"executables":{"win32":["ESSTEAM.exe","elsword.exe","x2.exe"]},"id":316,"name":"Elsword"},{"executables":{"win32":["ori.exe"]},"id":317,"name":"Ori and the Blind Forest"},{"executables":{"win32":["Skyforge.exe"]},"id":318,"name":"Skyforge"},{"executables":{"win32":["projectzomboid64.exe","projectzomboid32.exe"]},"id":319,"name":"Project Zomboid"},{"executables":{"win32":["From_The_Depths.exe"]},"id":320,"name":"The Depths"},{"executables":{"win32":["TheCrew.exe"]},"id":321,"name":"The Crew"},{"executables":{"win32":["MarvelHeroes2015.exe"]},"id":322,"name":"Marvel Heroes 2015"},{"executables":{"win32":["timeclickers.exe"]},"id":324,"name":"Time Clickers"},{"executables":{"win32":["eurotrucks2.exe"]},"id":325,"name":"Euro Truck Simulator 2"},{"executables":{"win32":["FarmingSimulator2015Game.exe"]},"id":326,"name":"Farming Simulator 15"},{"executables":{"win32":["strife.exe"]},"id":327,"name":"Strife"},{"executables":{"win32":["Awesomenauts.exe"]},"id":328,"name":"Awesomenauts"},{"executables":{"win32":["Dofus.exe"]},"id":329,"name":"Dofus"},{"executables":{"win32":["Boid.exe"]},"id":330,"name":"Boid"},{"executables":{"win32":["adventure-capitalist.exe"]},"id":331,"name":"AdVenture Capitalist"},{"executables":{"win32":["OrcsMustDie2.exe"]},"id":332,"name":"Orcs Must Die! 2"},{"executables":{"win32":["Mountain.exe"]},"id":333,"name":"Mountain"},{"executables":{"win32":["Valkyria.exe"]},"id":335,"name":"Valkyria Chronicles"},{"executables":{"win32":["ffxiiiimg.exe"]},"id":336,"name":"Final Fantasy XIII"},{"executables":{"win32":["TLR.exe"]},"id":337,"name":"The Last Remnant"},{"executables":{"win32":["Cities.exe"]},"id":339,"name":"Cities Skylines"},{"executables":{"win32":["worldofwarships.exe","WoWSLauncher.exe"]},"id":341,"name":"World of Warships"},{"executables":{"win32":["spacegame-Win64-shipping.exe"]},"id":342,"name":"Fractured Space"},{"executables":{"win32":["thespacegame.exe"]},"id":343,"name":"Ascent - The Space Game"},{"executables":{"win32":["DuckGame.exe"]},"id":344,"name":"Duck Game"},{"executables":{"win32":["PPSSPPWindows.exe"]},"id":345,"name":"PPSSPP"},{"executables":{"win32":["MBAA.exe"]},"id":346,"name":"Melty Blood Actress Again: Current Code"},{"executables":{"win32":["TheWolfAmongUs.exe"]},"id":347,"name":"The Wolf Among Us"},{"executables":{"win32":["SpaceEngineers.exe"]},"id":348,"name":"Space Engineers"},{"executables":{"win32":["Borderlands.exe"]},"id":349,"name":"Borderlands"},{"executables":{"win32":["100orange.exe"]},"id":351,"name":"100% Orange Juice"},{"executables":{"win32":["reflex.exe"]},"id":354,"name":"Reflex"},{"executables":{"win32":["pso2.exe"]},"id":355,"name":"Phantasy Star Online 2"},{"executables":{"win32":["AssettoCorsa.exe"]},"id":356,"name":"Assetto Corsa"},{"executables":{"win32":["iw3mp.exe","iw3sp.exe"]},"id":357,"name":"Call of Duty 4: Modern Warfare"},{"executables":{"win32":["WolfOldBlood_x64.exe"]},"id":358,"name":"Wolfenstein: The Old Blood"},{"executables":{"win32":["castle.exe"]},"id":359,"name":"Castle Crashers"},{"executables":{"win32":["vindictus.exe"]},"id":360,"name":"Vindictus"},{"executables":{"win32":["ShooterGame-Win32-Shipping.exe"]},"id":361,"name":"Dirty Bomb"},{"executables":{"win32":["BatmanAK.exe"]},"id":362,"name":"Batman Arkham Knight"},{"executables":{"win32":["drt.exe"]},"id":363,"name":"Dirt Rally"},{"executables":{"win32":["rFactor.exe"]},"id":364,"name":"rFactor"},{"executables":{"win32":["clonk.exe"]},"id":365,"name":"Clonk Rage"},{"executables":{"win32":["SRHK.exe"]},"id":366,"name":"Shadowrun: Hong Kong"},{"executables":{"win32":["Insurgency.exe"]},"id":367,"name":"Insurgency"},{"executables":{"win32":["StepMania.exe"]},"id":368,"name":"Step Mania"},{"executables":{"win32":["FirefallCLient.exe"]},"id":369,"name":"Firefall"},{"executables":{"win32":["mirrorsedge.exe"]},"id":370,"name":"Mirrors Edge"},{"executables":{"win32":["MgsGroundZeroes.exe"]},"id":371,"name":"Metal Gear Solid V: Ground Zeroes"},{"executables":{"win32":["mgsvtpp.exe"]},"id":372,"name":"Metal Gear Solid V: The Phantom Pain"},{"executables":{"win32":["tld.exe"]},"id":373,"name":"The Long Dark"},{"executables":{"win32":["TKOM.exe"]},"id":374,"name":"Take On Mars"},{"executables":{"win32":["robloxplayerlauncher.exe","Roblox.exe"]},"id":375,"name":"Roblox"},{"executables":{"win32":["eu4.exe"]},"id":376,"name":"Europa Universalis 4"},{"executables":{"win32":["APB.exe"]},"id":377,"name":"APB Reloaded"},{"executables":{"win32":["Robocraft.exe"]},"id":378,"name":"Robocraft"},{"executables":{"win32":["Unity.exe"]},"id":379,"name":"Unity"},{"executables":{"win32":["Simpsons.exe"]},"id":380,"name":"The Simpsons: Hit & Run"},{"executables":{"win32":["Dnlauncher.exe","DragonNest.exe"]},"id":381,"name":"Dragon Nest"},{"executables":{"win32":["Trove.exe"]},"id":382,"name":"Trove"},{"executables":{"win32":["EndlessLegend.exe"]},"id":383,"name":"Endless Legend"},{"executables":{"win32":["TurbineLauncher.exe","dndclient.exe"]},"id":384,"name":"Dungeons & Dragons Online"},{"executables":{"win32":["quakelive.exe","quakelive_steam.exe"]},"id":385,"name":"Quake Live"},{"executables":{"win32":["7DaysToDie.exe"]},"id":386,"name":"7DaysToDie"},{"executables":{"win32":["SpeedRunners.exe"]},"id":387,"name":"SpeedRunners"},{"executables":{"win32":["gamemd.exe"]},"id":388,"name":"Command & Conquer: Red Alert 2"},{"executables":{"win32":["generals.exe"]},"id":389,"name":"Command & Conquer Generals: Zero Hour"},{"executables":{"win32":["Oblivion.exe"]},"id":390,"name":"The Elder Scrolls 4: Oblivion"},{"executables":{"win32":["mgsi.exe"]},"id":391,"name":"Metal Gear Solid"},{"executables":{"win32":["EoCApp.exe"]},"id":392,"name":"Divinity - Original Sin"},{"executables":{"win32":["Torment.exe"]},"id":393,"name":"Planescape: Torment"},{"executables":{"win32":["HexPatch.exe"]},"id":394,"name":"Hex: Shards of Fate"},{"executables":{"win32":["NS3FB.exe"]},"id":395,"name":"Naruto Shippuden Ultimate Ninja Storm 3 Full Burst"},{"executables":{"win32":["NSUNSR.exe"]},"id":396,"name":"Naruto Shippuden Ultimate Ninja Storm Revolution"},{"executables":{"win32":["SaintsRowIV.exe"]},"id":397,"name":"Saints Row IV"},{"executables":{"win32":["Shadowrun.exe"]},"id":398,"name":"Shadowrun"},{"executables":{"win32":["DungeonoftheEndless.exe"]},"id":399,"name":"Dungeon of the Endless"},{"executables":{"win32":["Hon.exe"]},"id":400,"name":"Heroes of Newerth"},{"executables":{"win32":["mabinogi.exe"]},"id":401,"name":"Mabinogi"},{"executables":{"win32":["CoD2MP_s.exe","CoDSP_s.exe"]},"id":402,"name":"Call of Duty 2:"},{"executables":{"win32":["CoDWaWmp.exe","CoDWaw.exe"]},"id":403,"name":"Call of Duty: World at War"},{"executables":{"win32":["heroes.exe"]},"id":404,"name":"Mabinogi Heroes (Vindictus) "},{"executables":{"win32":["KanColleViewer.exe"]},"id":405,"name":"KanColle "},{"executables":{"win32":["cyphers.exe"]},"id":406,"name":"Cyphers"},{"executables":{"win32":["RelicCoH2.exe"]},"id":407,"name":"Company of Heroes 2"},{"executables":{"win32":["MJ.exe"]},"id":408,"name":"セガNET麻雀MJ"},{"executables":{"win32":["ge.exe"]},"id":409,"name":"Granado Espada"},{"executables":{"win32":["NovaRO.exe"]},"id":410,"name":"Nova Ragnarok Online"},{"executables":{"win32":["RivalsofAether.exe"]},"id":411,"name":"Rivals of Aether"},{"executables":{"win32":["bfh.exe"]},"id":412,"name":"Battlefield Hardline"},{"executables":{"win32":["GrowHome.exe"]},"id":413,"name":"Grow Home"},{"executables":{"win32":["patriots.exe"]},"id":414,"name":"Rise of Nations Extended"},{"executables":{"win32":["Railroads.exe"]},"id":415,"name":"Sid Meier's Railroads!"},{"executables":{"win32":["Empire.exe"]},"id":416,"name":"Empire: Total War"},{"executables":{"win32":["Napoleon.exe"]},"id":417,"name":"Napoleon: Total War"},{"executables":{"win32":["gta_sa.exe"]},"id":418,"name":"Grand Theft Auto: San Andreas"},{"executables":{"win32":["MadMax.exe"]},"id":419,"name":"Mad Max"},{"executables":{"win32":["Titanfall.exe"]},"id":420,"name":"Titanfall"},{"executables":{"win32":["age2_x1.exe"]},"id":421,"name":"Age of Empires II: The Conquerors"},{"executables":{"win32":["Rome2.exe"]},"id":422,"name":"Total War: ROME 2"},{"executables":{"win32":["ShadowOfMordor.exe"]},"id":423,"name":"Middle-earth: Shadow of Mordor"},{"executables":{"win32":["Subnautica.exe"]},"id":424,"name":"Subnautica"},{"executables":{"win32":["anno5.exe"]},"id":425,"name":"Anno 2070"},{"executables":{"win32":["carrier.exe"]},"id":426,"name":"Carrier Command Gaea Mission"},{"executables":{"win32":["DarksidersPC.exe"]},"id":427,"name":"Darksiders"},{"executables":{"win32":["Darksiders2.exe"]},"id":428,"name":"Darksiders 2"},{"executables":{"win32":["mudlet.exe"]},"id":429,"name":"Mudlet"},{"executables":{"win32":["DunDefLauncher.exe"]},"id":430,"name":"Dungeon Defenders II"},{"executables":{"win32":["hng.exe"]},"id":431,"name":"Heroes and Generals"},{"executables":{"win32":["WFTOGame.exe"]},"id":432,"name":"War of the Overworld"},{"executables":{"win32":["Talisman.exe"]},"id":433,"name":"Talisman: Digital Edition"},{"executables":{"win32":["limbo.exe"]},"id":434,"name":"Limbo"},{"executables":{"win32":["ibbobb.exe"]},"id":435,"name":"ibb & obb"},{"executables":{"win32":["BattleBlockTheater.exe"]},"id":436,"name":"BattleBlock Theater"},{"executables":{"win32":["iracinglauncher.exe","iracingsim.exe","iracingsim64.exe"]},"id":437,"name":"iRacing"},{"executables":{"win32":["CivilizationV_DX11.exe"]},"id":438,"name":"Civilization V"}] +},{}]},{},[9])(9) +}); \ No newline at end of file diff --git a/web-dist/discord.min.3.8.4.js b/web-dist/discord.min.3.8.4.js new file mode 100644 index 000000000..6d0ae74a4 --- /dev/null +++ b/web-dist/discord.min.3.8.4.js @@ -0,0 +1,3 @@ +!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Discord=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g>>a&1)},a.prototype.setBit=function(){},e(a,[{key:"createInstantInvite",get:function(){return this.getBit(0)},set:function(a){this.setBit(0,a)}},{key:"manageRoles",get:function(){return this.getBit(3)},set:function(a){this.setBit(3,a)}},{key:"manageChannels",get:function(){return this.getBit(4)},set:function(a){this.setBit(4,a)}},{key:"readMessages",get:function(){return this.getBit(10)},set:function(a){this.setBit(10,a)}},{key:"sendMessages",get:function(){return this.getBit(11)},set:function(a){this.setBit(11,a)}},{key:"sendTTSMessages",get:function(){return this.getBit(12)},set:function(a){this.setBit(12,a)}},{key:"manageMessages",get:function(){return this.getBit(13)},set:function(a){this.setBit(13,a)}},{key:"embedLinks",get:function(){return this.getBit(14)},set:function(a){this.setBit(14,a)}},{key:"attachFiles",get:function(){return this.getBit(15)},set:function(a){this.setBit(15,a)}},{key:"readMessageHistory",get:function(){return this.getBit(16)},set:function(a){this.setBit(16,a)}},{key:"mentionEveryone",get:function(){return this.getBit(17)},set:function(a){this.setBit(17,a)}},{key:"voiceConnect",get:function(){return this.getBit(20)},set:function(a){this.setBit(20,a)}},{key:"voiceSpeak",get:function(){return this.getBit(21)},set:function(a){this.setBit(21,a)}},{key:"voiceMuteMembers",get:function(){return this.getBit(22)},set:function(a){this.setBit(22,a)}},{key:"voiceDeafenMembers",get:function(){return this.getBit(23)},set:function(a){this.setBit(23,a)}},{key:"voiceMoveMembers",get:function(){return this.getBit(24)},set:function(a){this.setBit(24,a)}},{key:"voiceUseVoiceActivation",get:function(){return this.getBit(25)},set:function(a){this.setBit(25,a)}}]),a}();b.exports=f},{}],2:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c=k.length)break;n=k[m++]}else{if(m=k.next(),m.done)break;n=m.value}for(var o=n,p=[],q=o.mentions,r=Array.isArray(q),s=0,q=r?q:q[Symbol.iterator]();;){var t;if(r){if(s>=q.length)break;t=q[s++]}else{if(s=q.next(),s.done)break;t=s.value}var u=t;p.push(d.addUser(u))}var v=d.addUser(o.author);f.push(new j(o,i,p,v))}c(null,f),e(f)}})})},a.prototype.deleteChannel=function(a){var b=arguments.length<=1||void 0===arguments[1]?function(a){}:arguments[1],c=this;return new Promise(function(d,e){var g=a;a instanceof i&&(g=a.id),n.del(f.CHANNELS+"/"+g).set("authorization",c.token).end(function(a){a?(b(a),e(a)):(b(null),d())})})},a.prototype.joinServer=function(a){var b=arguments.length<=1||void 0===arguments[1]?function(a,b){}:arguments[1],c=this;return new Promise(function(d,e){var g=a instanceof k?a.code:a;n.post(f.API+"/invite/"+g).set("authorization",c.token).end(function(a,f){a?(b(a),e(a)):c.getServer("id",f.body.guild.id)?d(c.getServer("id",f.body.guild.id)):c.serverCreateListener[f.body.guild.id]=[d,b]})})},a.prototype.sendFile=function(a,b){var c=arguments.length<=2||void 0===arguments[2]?"image.png":arguments[2],d=arguments.length<=3||void 0===arguments[3]?function(a,b){}:arguments[3],e=this,f=new Promise(function(g,h){function i(a){e.options.queue?(e.queue[a]||(e.queue[a]=[]),e.queue[a].push({action:"sendFile",attachment:l,attachmentName:c,then:j,error:k}),e.checkQueue(a)):e._sendFile(a,l,c).then(j)["catch"](k)}function j(a){f.message=a,d(null,a),g(a)}function k(a){f.error=a,d(a),h(a)}var l;"string"==typeof b||b instanceof String?(l=p.createReadStream(b),c=b):l=b,e.resolveDestination(a).then(i)["catch"](k)});return f},a.prototype.sendMessage=function(a,b,c){var d=arguments.length<=3||void 0===arguments[3]?function(a,b){}:arguments[3],e=arguments.length<=4||void 0===arguments[4]?"":arguments[4],f=this,g=new Promise(function(h,i){function j(a){d(a),i(a)}function k(a){f.options.queue?(f.queue[a]||(f.queue[a]=[]),f.queue[a].push({action:"sendMessage",content:b,mentions:p,tts:!!c,then:l,error:m}),f.checkQueue(a)):f._sendMessage(a,b,c,p).then(l)["catch"](m)}function l(a){g.message=a,d(null,a),h(a)}function m(a){g.error=a,d(a),i(a)}function n(){var a=b;return b instanceof Array&&(a=b.join("\n")),a}function o(){for(var a=[],c=b.match(/<@[^>]*>/g)||[],d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;a.push(g.substring(2,g.length-1))}return a}"function"==typeof c&&(d=c,c=!1),b=e+n(b);var p=o();f.resolveDestination(a).then(k)["catch"](j)});return g},a.prototype.createws=function(a){if(this.websocket)return!1;var b=this;this.websocket=new o(a),this.websocket.onopen=function(){b.trySendConnData()},this.websocket.onclose=function(){b.trigger("disconnected")},this.websocket.onmessage=function(a){var c=!1,d={};try{c=JSON.parse(a.data),d=c.d}catch(e){return void b.trigger("error",e,a)}switch(b.trigger("raw",c),c.t){case"READY":b.debug("received ready packet"),b.user=b.addUser(d.user);for(var f=d.guilds,h=Array.isArray(f),k=0,f=h?f:f[Symbol.iterator]();;){var l;if(h){if(k>=f.length)break;l=f[k++]}else{if(k=f.next(),k.done)break;l=k.value}var m=l,n=b.addServer(m)}for(var o=d.private_channels,p=Array.isArray(o),q=0,o=p?o:o[Symbol.iterator]();;){var r;if(p){if(q>=o.length)break;r=o[q++]}else{if(q=o.next(),q.done)break;r=q.value}var s=r;b.addPMChannel(s)}b.trigger("ready"),b.readyTime=Date.now(),b.debug("cached "+b.serverCache.length+" servers, "+b.channelCache.length+" channels, "+b.pmChannelCache.length+" PMs and "+b.userCache.length+" users."),b.state=3,setInterval(function(){b.keepAlive.apply(b)},d.heartbeat_interval);break;case"MESSAGE_CREATE":b.debug("received message");var t=[];d.mentions=d.mentions||[];for(var u=d.mentions,v=Array.isArray(u),w=0,u=v?u:u[Symbol.iterator]();;){var x;if(v){if(w>=u.length)break;x=u[w++]}else{if(w=u.next(),w.done)break;x=w.value}var y=x;t.push(b.addUser(y))}var z=b.getChannel("id",d.channel_id);if(z){var A=z.addMessage(new j(d,z,t,b.addUser(d.author)));b.trigger("message",A)}break;case"MESSAGE_DELETE":b.debug("message deleted");var z=b.getChannel("id",d.channel_id),B=z.getMessage("id",d.id);B?(b.trigger("messageDelete",z,B),z.messages.splice(z.messages.indexOf(B),1)):b.trigger("messageDelete",z);break;case"MESSAGE_UPDATE":b.debug("message updated");var z=b.getChannel("id",d.channel_id),C=z.getMessage("id",d.id);if(C){var D={};for(var E in C)D[E]=C[E];for(var E in d)D[E]=d[E];for(var t=[],F=D.mentions,G=Array.isArray(F),H=0,F=G?F:F[Symbol.iterator]();;){var I;if(G){if(H>=F.length)break;I=F[H++]}else{if(H=F.next(),H.done)break;I=H.value}var y=I;t.push(b.addUser(y))}var J=new j(D,z,t,C.author);b.trigger("messageUpdate",J,C),z.messages[z.messages.indexOf(C)]=J}break;case"GUILD_DELETE":var n=b.getServer("id",d.id);n&&(b.serverCache.splice(b.serverCache.indexOf(n),1),b.trigger("serverDelete",n));break;case"CHANNEL_DELETE":var z=b.getChannel("id",d.id);if(z){var n=z.server;n&&n.channels.splice(n.channels.indexOf(z),1),b.trigger("channelDelete",z),b.serverCache.splice(b.serverCache.indexOf(z),1)}break;case"GUILD_CREATE":var n=b.getServer("id",d.id);if(n||(n=b.addServer(d)),b.serverCreateListener[d.id]){var K=b.serverCreateListener[d.id];K[0](n),K[1](null,n),b.serverCreateListener[d.id]=null}b.trigger("serverCreate",n);break;case"CHANNEL_CREATE":var z=b.getChannel("id",d.id);if(!z){var L;L=d.is_private?b.addPMChannel(d):b.addChannel(d,d.guild_id);var M=b.getServer("id",d.guild_id);M&&M.addChannel(L),b.trigger("channelCreate",L)}break;case"GUILD_MEMBER_ADD":var n=b.getServer("id",d.guild_id);if(n){var N=b.addUser(d.user);b.trigger("serverNewMember",n.addMember(N,d.roles),n)}break;case"GUILD_MEMBER_REMOVE":var n=b.getServer("id",d.guild_id);if(n){var N=b.addUser(d.user);n.removeMember("id",N.id),b.trigger("serverRemoveMember",N,n)}break;case"USER_UPDATE":if(b.user&&d.id===b.user.id){var O=new g(d);b.trigger("userUpdate",O,b.user),~b.userCache.indexOf(b.user)&&(b.userCache[b.userCache.indexOf(b.user)]=O),b.user=O}break;case"PRESENCE_UPDATE":var P=b.getUser("id",d.user.id);if(P){d.user.username=d.user.username||P.username,d.user.id=d.user.id||P.id,d.user.discriminator=d.user.discriminator||P.discriminator,d.user.avatar=d.user.avatar||P.avatar;var Q=new g(d.user);Q.equalsStrict(P)?(b.trigger("presence",{user:P,oldStatus:P.status,status:d.status,server:b.getServer("id",d.guild_id),gameId:d.game_id}),P.status=d.status,P.gameId=d.game_id):(b.userCache[b.userCache.indexOf(P)]=Q,b.trigger("userUpdate",P,Q))}break;case"CHANNEL_UPDATE":var R=b.getChannel("id",d.id),S=b.getServer("id",d.guild_id);if(R&&S){var T=new i(d,S);T.messages=R.messages,b.trigger("channelUpdate",R,T),b.channelCache[b.channelCache.indexOf(R)]=T}break;case"TYPING_START":var P=b.getUser("id",d.user_id),R=b.getChannel("id",d.channel_id);b.userTypingListener[d.user_id]&&-1!==b.userTypingListener[d.user_id]||b.trigger("startTyping",P,R),b.userTypingListener[d.user_id]=Date.now(),setTimeout(function(){-1!==b.userTypingListener[d.user_id]&&Date.now()-b.userTypingListener[d.user_id]>6e3&&(b.trigger("stopTyping",P,R),b.userTypingListener[d.user_id]=-1)},6e3);break;case"GUILD_ROLE_DELETE":var n=b.getServer("id",d.guild_id),U=n.getRole(d.role_id);b.trigger("serverRoleDelete",n,U),n.removeRole(U.id);break;case"GUILD_ROLE_UPDATE":var n=b.getServer("id",d.guild_id),U=n.getRole(d.role.id),V=n.updateRole(d.role);b.trigger("serverRoleUpdate",n,U,V);break;default:b.debug("received unknown packet"),b.trigger("unknown",c)}}},a.prototype.addUser=function(a){return this.getUser("id",a.id)||this.userCache.push(new g(a)),this.getUser("id",a.id)},a.prototype.addChannel=function(a,b){return this.getChannel("id",a.id)||this.channelCache.push(new i(a,this.getServer("id",b))),this.getChannel("id",a.id)},a.prototype.addPMChannel=function(a){return this.getPMChannel("id",a.id)||this.pmChannelCache.push(new l(a,this)),this.getPMChannel("id",a.id)},a.prototype.setTopic=function(a,b){var c=arguments.length<=2||void 0===arguments[2]?function(a){}:arguments[2],d=this;return new Promise(function(e,g){function h(a){c(a),g(a)}function i(a){var g=d.getChannel("id",a);n.patch(f.CHANNELS+"/"+a).set("authorization",d.token).send({name:g.name,position:0,topic:b}).end(function(a,b){a?h(a):(g.topic=b.body.topic,e(),c())})}d.resolveDestination(a).then(i)["catch"](h)})},a.prototype.addServer=function(a){var b=this,c=this.getServer("id",a.id);if(a.unavailable)return b.trigger("unavailable",a),void b.debug("Server ID "+a.id+" has been marked unavailable by Discord. It was not cached.");if(!c&&(c=new h(a,this),this.serverCache.push(c),a.channels))for(var d=a.channels,e=Array.isArray(d),f=0,d=e?d:d[Symbol.iterator]();;){var g;if(e){if(f>=d.length)break;g=d[f++]}else{if(f=d.next(),f.done)break;g=f.value}var i=g;c.channels.push(this.addChannel(i,c.id))}for(var j=a.presences,k=Array.isArray(j),l=0,j=k?j:j[Symbol.iterator]();;){var m;if(k){if(l>=j.length)break;m=j[l++]}else{if(l=j.next(),l.done)break;m=l.value}var n=m,o=b.getUser("id",n.user.id);o.status=n.status,o.gameId=n.game_id}return c},a.prototype.getUser=function(a,b){for(var c=this.userCache,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.getChannel=function(a,b){for(var c=this.channelCache,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return this.getPMChannel(a,b)},a.prototype.getPMChannel=function(a,b){for(var c=this.pmChannelCache,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.getServer=function(a,b){for(var c=this.serverCache,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.trySendConnData=function(){if(this.token&&!this.alreadySentData){this.alreadySentData=!0;var a={op:2,d:{token:this.token,v:3,properties:{$os:"discord.js",$browser:"discord.js",$device:"discord.js",$referrer:"",$referring_domain:""}}};this.websocket.send(JSON.stringify(a))}},a.prototype.resolveServerID=function(a){return a instanceof h?a.id:!isNaN(a)&&a.length&&17===a.length?a:void 0},a.prototype.resolveDestination=function(a){var b=!1,c=this;return new Promise(function(d,e){if(a instanceof h)b=a.id;else if(a instanceof i)b=a.id;else if(a instanceof j)b=a.channel.id;else if(a instanceof l)b=a.id;else if(a instanceof g){for(var f=c.pmChannelCache,k=Array.isArray(f),m=0,f=k?f:f[Symbol.iterator]();;){var n;if(k){if(m>=f.length)break;n=f[m++]}else{if(m=f.next(),m.done)break;n=m.value}var o=n;if(o.user&&o.user.equals(a))return void d(o.id)}c.startPM(a).then(function(a){d(a.id)})["catch"](e)}else b=a;b?d(b):e()})},a.prototype._sendMessage=function(a,b,c,d){var e=this;return new Promise(function(g,h){n.post(f.CHANNELS+"/"+a+"/messages").set("authorization",e.token).send({content:b,mentions:d,tts:c}).end(function(a,b){if(a)h(a);else{var c=b.body,d=[];c.mentions=c.mentions||[];for(var f=c.mentions,i=Array.isArray(f),k=0,f=i?f:f[Symbol.iterator]();;){var l;if(i){if(k>=f.length)break;l=f[k++]}else{if(k=f.next(),k.done)break;l=k.value}var m=l;d.push(e.addUser(m))}var n=e.getChannel("id",c.channel_id);if(n){var o=n.addMessage(new j(c,n,d,e.addUser(c.author)));g(o)}}})})},a.prototype._sendFile=function(a,b){var c=arguments.length<=2||void 0===arguments[2]?"DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png":arguments[2],d=this;return new Promise(function(e,g){n.post(f.CHANNELS+"/"+a+"/messages").set("authorization",d.token).attach("file",b,c).end(function(b,c){if(b)g(b);else{var f=d.getChannel("id",a);if(f){var h=f.addMessage(new j(c.body,f,[],d.user));e(h)}}})})},a.prototype._updateMessage=function(a,b){var c=this;return new Promise(function(d,e){n.patch(f.CHANNELS+"/"+a.channel.id+"/messages/"+a.id).set("authorization",c.token).send({content:b,mentions:[]}).end(function(b,c){if(b)e(b);else{var f=new j(c.body,a.channel,a.mentions,a.sender);d(f),a.channel.messages[a.channel.messages.indexOf(a)]=f}})})},a.prototype.getGateway=function(){var a=this;return new Promise(function(b,c){n.get(f.API+"/gateway").set("authorization",a.token).end(function(a,d){a?c(a):b(d.body.url)})})},a.prototype.setStatusIdle=function(){this.setStatus("idle")},a.prototype.setStatusOnline=function(){this.setStatus("online")},a.prototype.setStatusActive=function(){this.setStatusOnline()},a.prototype.setStatusHere=function(){this.setStatusOnline()},a.prototype.setStatusAway=function(){this.setStatusIdle()},a.prototype.startTyping=function(a,b){function c(a){if(!d.typingIntervals[a]){var c=function(){n.post(f.CHANNELS+"/"+a+"/typing").set("authorization",d.token).end()};c();var e=setInterval(c,3e3);d.typingIntervals[a]=e,b&&setTimeout(function(){d.stopTyping(a)},b)}}var d=this;this.resolveDestination(a).then(c)},a.prototype.stopTyping=function(a){function b(a){c.typingIntervals[a]&&(clearInterval(c.typingIntervals[a]),delete c.typingIntervals[a])}var c=this;this.resolveDestination(a).then(b)},a.prototype.setStatus=function(a){var b="online"===a?null:Date.now();this.__idleTime=b,this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}))},a.prototype.setPlayingGame=function(a){if(a instanceof String||"string"==typeof a){var b=a.trim().toUpperCase();a=null;for(var c=m,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g.name.trim().toUpperCase()===b){a=g.id;break}}}this.__gameId=a,this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}))},a.prototype.playGame=function(a){this.setPlayingGame(a)},a.prototype.playingGame=function(a){this.setPlayingGame(a)},e(a,[{key:"uptime",get:function(){return this.readyTime?Date.now()-this.readyTime:null}},{key:"ready",get:function(){return 3===this.state}},{key:"servers",get:function(){return this.serverCache}},{key:"channels",get:function(){return this.channelCache}},{key:"users",get:function(){return this.userCache}},{key:"PMChannels",get:function(){return this.pmChannelCache}},{key:"messages",get:function(){for(var a=[],b=this.channelCache,c=Array.isArray(b),d=0,b=c?b:b[Symbol.iterator]();;){var e;if(c){if(d>=b.length)break;e=b[d++]}else{if(d=b.next(),d.done)break;e=d.value}var f=e;a=a.concat(f.messages)}return a}}]),a}();b.exports=r},{"../ref/gameMap.json":19,"./Endpoints.js":3,"./PMChannel.js":6,"./channel.js":8,"./invite.js":10,"./message.js":11,"./server.js":12,"./user.js":13,fs:14,superagent:15,ws:18}],3:[function(a,b,c){"use strict";c.BASE_DOMAIN="discordapp.com",c.BASE="https://"+c.BASE_DOMAIN,c.WEBSOCKET_HUB="wss://"+c.BASE_DOMAIN+"/hub",c.API=c.BASE+"/api",c.AUTH=c.API+"/auth",c.LOGIN=c.AUTH+"/login",c.LOGOUT=c.AUTH+"/logout",c.USERS=c.API+"/users",c.SERVERS=c.API+"/guilds",c.CHANNELS=c.API+"/channels"},{}],4:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c>>a&1)},a.prototype.setBit=function(){},e(a,[{key:"createInstantInvite",get:function(){return this.getBit(0)},set:function(a){this.setBit(0,a)}},{key:"manageRoles",get:function(){return this.getBit(3)},set:function(a){this.setBit(3,a)}},{key:"manageChannels",get:function(){return this.getBit(4)},set:function(a){this.setBit(4,a)}},{key:"readMessages",get:function(){return this.getBit(10)},set:function(a){this.setBit(10,a)}},{key:"sendMessages",get:function(){return this.getBit(11)},set:function(a){this.setBit(11,a)}},{key:"sendTTSMessages",get:function(){return this.getBit(12)},set:function(a){this.setBit(12,a)}},{key:"manageMessages",get:function(){return this.getBit(13)},set:function(a){this.setBit(13,a)}},{key:"embedLinks",get:function(){return this.getBit(14)},set:function(a){this.setBit(14,a)}},{key:"attachFiles",get:function(){return this.getBit(15)},set:function(a){this.setBit(15,a)}},{key:"readMessageHistory",get:function(){return this.getBit(16)},set:function(a){this.setBit(16,a)}},{key:"mentionEveryone",get:function(){return this.getBit(17)},set:function(a){this.setBit(17,a)}},{key:"voiceConnect",get:function(){return this.getBit(20)},set:function(a){this.setBit(20,a)}},{key:"voiceSpeak",get:function(){return this.getBit(21)},set:function(a){this.setBit(21,a)}},{key:"voiceMuteMembers",get:function(){return this.getBit(22)},set:function(a){this.setBit(22,a)}},{key:"voiceDeafenMembers",get:function(){return this.getBit(23)},set:function(a){this.setBit(23,a)}},{key:"voiceMoveMembers",get:function(){return this.getBit(24)},set:function(a){this.setBit(24,a)}},{key:"voiceUseVoiceActivation",get:function(){return this.getBit(25)},set:function(a){this.setBit(25,a)}}]),a}();b.exports=f},{}],5:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function e(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(Object.setPrototypeOf?Object.setPrototypeOf(a,b):a.__proto__=b)}var f=function(){function a(a,b){for(var c=0;c=d.length)break;g=d[f++]}else{if(f=d.next(),f.done)break;g=f.value}var h=g;h.id===this.id&&"member"===h.type?c.push(h):-1!==this.rawRoles.indexOf(h.id)&&b.push(h)}for(var j=b,k=Array.isArray(j),l=0,j=k?j:j[Symbol.iterator]();;){var m;if(k){if(l>=j.length)break;m=j[l++]}else{if(l=j.next(),l.done)break;m=l.value}var n=m;console.log("hey",n.attachFiles)}if(0===b.length&&0===c.length)return new i(this.evalPerms.packed);for(var o=0!==b.length?b[0].packed:c[0].packed,p=b,q=Array.isArray(p),r=0,p=q?p:p[Symbol.iterator]();;){var s;if(q){if(r>=p.length)break;s=p[r++]}else{if(r=p.next(),r.done)break;s=r.value}var h=s;o&=~h.deny,o|=h.allow}for(var t=c,u=Array.isArray(t),v=0,t=u?t:t[Symbol.iterator]();;){var w;if(u){if(v>=t.length)break;w=t[v++]}else{if(v=t.next(),v.done)break;w=v.value}var h=w;o&=~h.deny,o|=h.allow}return new i(o)},f(b,[{key:"roles",get:function(){for(var a=[this.server.getRole(this.server.id)],b=this.rawRoles,c=Array.isArray(b),d=0,b=c?b:b[Symbol.iterator]();;){var e;if(c){if(d>=b.length)break;e=b[d++]}else{if(d=b.next(),d.done)break;e=d.value}var f=e;a.push(this.server.getRole(f))}return a}},{key:"evalPerms",get:function(){for(var a=this.roles,b=a[0].packed,c=a,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;b|=g.packed}return new h({permissions:b})}}]),b}(g);b.exports=j},{"./EvaluatedPermissions.js":4,"./ServerPermissions.js":7,"./user.js":13}],6:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c1e3&&this.messages.splice(0,1);for(var c=this.messages,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},e(a,[{key:"isPrivate",get:function(){return!0}}]),a}();b.exports=f},{}],7:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c>>a&1)},a.prototype.setBit=function(){},a.prototype.toString=function(){return this.name},e(a,[{key:"createInstantInvite",get:function(){return this.getBit(0)},set:function(a){this.setBit(0,a)}},{key:"banMembers",get:function(){return this.getBit(1)},set:function(a){this.setBit(1,a)}},{key:"kickMembers",get:function(){return this.getBit(2)},set:function(a){this.setBit(2,a)}},{key:"manageRoles",get:function(){return this.getBit(3)},set:function(a){this.setBit(3,a)}},{key:"manageChannels",get:function(){return this.getBit(4)},set:function(a){this.setBit(4,a)}},{key:"manageServer",get:function(){return this.getBit(5)},set:function(a){this.setBit(5,a)}},{key:"readMessages",get:function(){return this.getBit(10)},set:function(a){this.setBit(10,a)}},{key:"sendMessages",get:function(){return this.getBit(11)},set:function(a){this.setBit(11,a)}},{key:"sendTTSMessages",get:function(){return this.getBit(12)},set:function(a){this.setBit(12,a)}},{key:"manageMessages",get:function(){return this.getBit(13)},set:function(a){this.setBit(13,a)}},{key:"embedLinks", +get:function(){return this.getBit(14)},set:function(a){this.setBit(14,a)}},{key:"attachFiles",get:function(){return this.getBit(15)},set:function(a){this.setBit(15,a)}},{key:"readMessageHistory",get:function(){return this.getBit(16)},set:function(a){this.setBit(16,a)}},{key:"mentionEveryone",get:function(){return this.getBit(17)},set:function(a){this.setBit(17,a)}},{key:"voiceConnect",get:function(){return this.getBit(20)},set:function(a){this.setBit(20,a)}},{key:"voiceSpeak",get:function(){return this.getBit(21)},set:function(a){this.setBit(21,a)}},{key:"voiceMuteMembers",get:function(){return this.getBit(22)},set:function(a){this.setBit(22,a)}},{key:"voiceDeafenMembers",get:function(){return this.getBit(23)},set:function(a){this.setBit(23,a)}},{key:"voiceMoveMembers",get:function(){return this.getBit(24)},set:function(a){this.setBit(24,a)}},{key:"voiceUseVoiceActivation",get:function(){return this.getBit(25)},set:function(a){this.setBit(25,a)}}]),a}();b.exports=f},{}],8:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c=e.length)break;i=e[h++]}else{if(h=e.next(),h.done)break;i=h.value}var j=i;this.roles.push(new f(j,this))}}return a.prototype.permissionsOf=function(a){var b=this.server.getMember("id",a.id);return b?b.permissionsIn(this):null},a.prototype.equals=function(a){return a&&a.id===this.id},a.prototype.addMessage=function(a){return this.messages.length>1e3&&this.messages.splice(0,1),this.getMessage("id",a.id)||this.messages.push(a),this.getMessage("id",a.id)},a.prototype.getMessage=function(a,b){for(var c=this.messages,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.toString=function(){return"<#"+this.id+">"},e(a,[{key:"permissionOverwrites",get:function(){return this.roles}},{key:"permissions",get:function(){return this.roles}},{key:"client",get:function(){return this.server.client}},{key:"isPrivate",get:function(){return!1}},{key:"users",get:function(){return this.server.members}},{key:"members",get:function(){return this.server.members}}]),a}();b.exports=g},{"./ChannelPermissions.js":1}],9:[function(a,b,c){"use strict";var d=(a("superagent"),a("./Endpoints.js")),e=a("./Client.js"),f={Endpoints:d,Client:e};b.exports=f},{"./Client.js":2,"./Endpoints.js":3,superagent:15}],10:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g.id===b)return!0}return!1},e(a,[{key:"sender",get:function(){return this.author}},{key:"isPrivate",get:function(){return this.channel.isPrivate}}]),a}());b.exports=f},{"./PMChannel.js":6}],12:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c=e.length)break;i=e[h++]}else{if(h=e.next(),h.done)break;i=h.value}var j=i;this.roles.push(new f(j))}if(!b.members)return void(b.members=[c.user]);for(var k=b.members,l=Array.isArray(k),m=0,k=l?k:k[Symbol.iterator]();;){var n;if(l){if(m>=k.length)break;n=k[m++]}else{if(m=k.next(),m.done)break;n=m.value}var o=n;o.user&&this.addMember(c.addUser(o.user),o.roles)}}return a.prototype.getRole=function(a){for(var b=this.roles,c=Array.isArray(b),d=0,b=c?b:b[Symbol.iterator]();;){var e;if(c){if(d>=b.length)break;e=b[d++]}else{if(d=b.next(),d.done)break;e=d.value}var f=e;if(f.id===a)return f}return null},a.prototype.updateRole=function(a){var b=this.getRole(a.id);if(b){var c=this.roles.indexOf(b);return this.roles[c]=new f(a),this.roles[c]}return!1},a.prototype.removeRole=function(a){for(var b in this.roles)this.roles[b].id===a&&this.roles.splice(b,1);for(var c=this.members,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;for(var b in g.rawRoles)g.rawRoles[b]===a&&g.rawRoles.splice(b,1)}},a.prototype.getChannel=function(a,b){for(var c=this.channels,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.getMember=function(a,b){for(var c=this.members,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.removeMember=function(a,b){for(var c=this.members,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return this.members.splice(a,1),g}return!1},a.prototype.addChannel=function(a){return this.getChannel("id",a.id)||this.channels.push(a),a},a.prototype.addMember=function(a,b){if(!this.getMember("id",a.id)){var c=new g(a,this,b);this.members.push(c)}return c},a.prototype.toString=function(){return this.name},a.prototype.equals=function(a){return a.id===this.id},e(a,[{key:"permissionGroups",get:function(){return this.roles}},{key:"permissions",get:function(){return this.roles}},{key:"iconURL",get:function(){return this.icon?"https://discordapp.com/api/guilds/"+this.id+"/icons/"+this.icon+".jpg":null}},{key:"afkChannel",get:function(){return this.afkChannelId?this.getChannel("id",this.afkChannelId):!1}},{key:"defaultChannel",get:function(){return this.getChannel("name","general")}},{key:"owner",get:function(){return this.client.getUser("id",this.ownerID)}},{key:"users",get:function(){return this.members}}]),a}();b.exports=h},{"./Member.js":5,"./ServerPermissions.js":7}],13:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c"},a.prototype.toString=function(){return this.mention()},a.prototype.equals=function(a){return a.id===this.id},a.prototype.equalsStrict=function(a){return a.id===this.id&&a.avatar===this.avatar&&a.username===this.username&&a.discriminator===this.discriminator},e(a,[{key:"avatarURL",get:function(){return this.avatar?"https://discordapp.com/api/users/"+this.id+"/avatars/"+this.avatar+".jpg":null}}]),a}();b.exports=f},{}],14:[function(a,b,c){},{}],15:[function(a,b,c){function d(){}function e(a){var b={}.toString.call(a);switch(b){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function f(a){return a===Object(a)}function g(a){if(!f(a))return a;var b=[];for(var c in a)null!=a[c]&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")}function h(a){for(var b,c,d={},e=a.split("&"),f=0,g=e.length;g>f;++f)c=e[f],b=c.split("="),d[decodeURIComponent(b[0])]=decodeURIComponent(b[1]);return d}function i(a){var b,c,d,e,f=a.split(/\r?\n/),g={};f.pop();for(var h=0,i=f.length;i>h;++h)c=f[h],b=c.indexOf(":"),d=c.slice(0,b).toLowerCase(),e=r(c.slice(b+1)),g[d]=e;return g}function j(a){return a.split(/ *; */).shift()}function k(a){return q(a.split(/ *; */),function(a,b){var c=b.split(/ *= */),d=c.shift(),e=c.shift();return d&&e&&(a[d]=e),a},{})}function l(a,b){b=b||{},this.req=a,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||"undefined"==typeof this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText,this.setStatusProperties(this.xhr.status),this.header=this.headers=i(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body="HEAD"!=this.req.method?this.parseBody(this.text?this.text:this.xhr.response):null}function m(a,b){var c=this;p.call(this),this._query=this._query||[],this.method=a,this.url=b,this.header={},this._header={},this.on("end",function(){var a=null,b=null;try{b=new l(c)}catch(d){return a=new Error("Parser is unable to parse the response"),a.parse=!0,a.original=d,c.callback(a)}if(c.emit("response",b),a)return c.callback(a,b);if(b.status>=200&&b.status<300)return c.callback(a,b);var e=new Error(b.statusText||"Unsuccessful HTTP response");e.original=a,e.response=b,e.status=b.status,c.callback(e,b)})}function n(a,b){return"function"==typeof b?new m("GET",a).end(b):1==arguments.length?new m("GET",a):new m(a,b)}var o,p=a("emitter"),q=a("reduce");o="undefined"!=typeof window?window:"undefined"!=typeof self?self:this,n.getXHR=function(){if(!(!o.XMLHttpRequest||o.location&&"file:"==o.location.protocol&&o.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(a){}return!1};var r="".trim?function(a){return a.trim()}:function(a){return a.replace(/(^\s*|\s*$)/g,"")};n.serializeObject=g,n.parseString=h,n.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},n.serialize={"application/x-www-form-urlencoded":g,"application/json":JSON.stringify},n.parse={"application/x-www-form-urlencoded":h,"application/json":JSON.parse},l.prototype.get=function(a){return this.header[a.toLowerCase()]},l.prototype.setHeaderProperties=function(a){var b=this.header["content-type"]||"";this.type=j(b);var c=k(b);for(var d in c)this[d]=c[d]},l.prototype.parse=function(a){return this.parser=a,this},l.prototype.parseBody=function(a){var b=this.parser||n.parse[this.type];return b&&a&&(a.length||a instanceof Object)?b(a):null},l.prototype.setStatusProperties=function(a){1223===a&&(a=204);var b=a/100|0;this.status=this.statusCode=a,this.statusType=b,this.info=1==b,this.ok=2==b,this.clientError=4==b,this.serverError=5==b,this.error=4==b||5==b?this.toError():!1,this.accepted=202==a,this.noContent=204==a,this.badRequest=400==a,this.unauthorized=401==a,this.notAcceptable=406==a,this.notFound=404==a,this.forbidden=403==a},l.prototype.toError=function(){var a=this.req,b=a.method,c=a.url,d="cannot "+b+" "+c+" ("+this.status+")",e=new Error(d);return e.status=this.status,e.method=b,e.url=c,e},n.Response=l,p(m.prototype),m.prototype.use=function(a){return a(this),this},m.prototype.timeout=function(a){return this._timeout=a,this},m.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},m.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(),this.clearTimeout(),this.emit("abort"),this)},m.prototype.set=function(a,b){if(f(a)){for(var c in a)this.set(c,a[c]);return this}return this._header[a.toLowerCase()]=b,this.header[a]=b,this},m.prototype.unset=function(a){return delete this._header[a.toLowerCase()],delete this.header[a],this},m.prototype.getHeader=function(a){return this._header[a.toLowerCase()]},m.prototype.type=function(a){return this.set("Content-Type",n.types[a]||a),this},m.prototype.accept=function(a){return this.set("Accept",n.types[a]||a),this},m.prototype.auth=function(a,b){var c=btoa(a+":"+b);return this.set("Authorization","Basic "+c),this},m.prototype.query=function(a){return"string"!=typeof a&&(a=g(a)),a&&this._query.push(a),this},m.prototype.field=function(a,b){return this._formData||(this._formData=new o.FormData),this._formData.append(a,b),this},m.prototype.attach=function(a,b,c){return this._formData||(this._formData=new o.FormData),this._formData.append(a,b,c),this},m.prototype.send=function(a){var b=f(a),c=this.getHeader("Content-Type");if(b&&f(this._data))for(var d in a)this._data[d]=a[d];else"string"==typeof a?(c||this.type("form"),c=this.getHeader("Content-Type"),"application/x-www-form-urlencoded"==c?this._data=this._data?this._data+"&"+a:a:this._data=(this._data||"")+a):this._data=a;return!b||e(a)?this:(c||this.type("json"),this)},m.prototype.callback=function(a,b){var c=this._callback;this.clearTimeout(),c(a,b)},m.prototype.crossDomainError=function(){var a=new Error("Origin is not allowed by Access-Control-Allow-Origin");a.crossDomain=!0,this.callback(a)},m.prototype.timeoutError=function(){var a=this._timeout,b=new Error("timeout of "+a+"ms exceeded");b.timeout=a,this.callback(b)},m.prototype.withCredentials=function(){return this._withCredentials=!0,this},m.prototype.end=function(a){var b=this,c=this.xhr=n.getXHR(),f=this._query.join("&"),g=this._timeout,h=this._formData||this._data;this._callback=a||d,c.onreadystatechange=function(){if(4==c.readyState){var a;try{a=c.status}catch(d){a=0}if(0==a){if(b.timedout)return b.timeoutError();if(b.aborted)return;return b.crossDomainError()}b.emit("end")}};var i=function(a){a.total>0&&(a.percent=a.loaded/a.total*100),b.emit("progress",a)};this.hasListeners("progress")&&(c.onprogress=i);try{c.upload&&this.hasListeners("progress")&&(c.upload.onprogress=i)}catch(j){}if(g&&!this._timer&&(this._timer=setTimeout(function(){b.timedout=!0,b.abort()},g)),f&&(f=n.serializeObject(f),this.url+=~this.url.indexOf("?")?"&"+f:"?"+f),c.open(this.method,this.url,!0),this._withCredentials&&(c.withCredentials=!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof h&&!e(h)){var k=this.getHeader("Content-Type"),l=n.serialize[k?k.split(";")[0]:""];l&&(h=l(h))}for(var m in this.header)null!=this.header[m]&&c.setRequestHeader(m,this.header[m]);return this.emit("request",this),c.send(h),this},m.prototype.then=function(a,b){return this.end(function(c,d){c?b(c):a(d)})},n.Request=m,n.get=function(a,b,c){var d=n("GET",a);return"function"==typeof b&&(c=b,b=null),b&&d.query(b),c&&d.end(c),d},n.head=function(a,b,c){var d=n("HEAD",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.del=function(a,b){var c=n("DELETE",a);return b&&c.end(b),c},n.patch=function(a,b,c){var d=n("PATCH",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.post=function(a,b,c){var d=n("POST",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.put=function(a,b,c){var d=n("PUT",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},b.exports=n},{emitter:16,reduce:17}],16:[function(a,b,c){function d(a){return a?e(a):void 0}function e(a){for(var b in d.prototype)a[b]=d.prototype[b];return a}b.exports=d,d.prototype.on=d.prototype.addEventListener=function(a,b){return this._callbacks=this._callbacks||{},(this._callbacks[a]=this._callbacks[a]||[]).push(b),this},d.prototype.once=function(a,b){function c(){d.off(a,c),b.apply(this,arguments)}var d=this;return this._callbacks=this._callbacks||{},c.fn=b,this.on(a,c),this},d.prototype.off=d.prototype.removeListener=d.prototype.removeAllListeners=d.prototype.removeEventListener=function(a,b){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var c=this._callbacks[a];if(!c)return this;if(1==arguments.length)return delete this._callbacks[a],this;for(var d,e=0;ed;++d)c[d].apply(this,b)}return this},d.prototype.listeners=function(a){return this._callbacks=this._callbacks||{},this._callbacks[a]||[]},d.prototype.hasListeners=function(a){return!!this.listeners(a).length}},{}],17:[function(a,b,c){b.exports=function(a,b,c){for(var d=0,e=a.length,f=3==arguments.length?c:a[d++];e>d;)f=b.call(null,f,a[d],++d,a);return f}},{}],18:[function(a,b,c){function d(a,b,c){var d;return d=b?new f(a,b):new f(a)}var e=function(){return this}(),f=e.WebSocket||e.MozWebSocket;b.exports=f?d:null,f&&(d.prototype=f.prototype)},{}],19:[function(a,b,c){b.exports=[{executables:{win32:["pol.exe"]},id:0,name:"FINAL FANTASY XI"},{executables:{win32:["ffxiv.exe","ffxiv_dx11.exe"]},id:1,name:"FINAL FANTASY XIV"},{executables:{win32:["Wow.exe","Wow-64.exe"]},id:3,name:"World of Warcraft"},{executables:{darwin:["LoLLauncher.app"],win32:["LolClient.exe","League of Legends.exe"]},id:4,name:"League of Legends"},{executables:{darwin:["Diablo%20III.app"],win32:["Diablo III.exe"]},id:5,name:"Diablo 3"},{executables:{darwin:["dota_osx.app"],win32:["dota2.exe"]},id:6,name:"DOTA 2"},{executables:{darwin:["Heroes.app"],win32:["Heroes of the Storm.exe","HeroesOfTheStorm_x64.exe","HeroesOfTheStorm.exe"]},id:7,name:"Heroes of the Storm"},{executables:{darwin:["Hearthstone.app"],win32:["Hearthstone.exe"]},id:8,name:"Hearthstone"},{executables:{win32:["csgo.exe"]},id:9,name:"Counter-Strike: Global Offensive"},{executables:{win32:["WorldOfTanks.exe"]},id:10,name:"World of Tanks"},{executables:{darwin:["gw2.app"],win32:["gw2.exe"]},id:11,name:"Guild Wars 2"},{executables:{win32:["dayz.exe"]},id:12,name:"Day Z"},{executables:{darwin:["starcraft%20ii.app"],win32:["starcraft ii.exe","SC2_x64.exe","SC2.exe"]},id:13,name:"Starcraft II"},{executables:{win32:["diablo.exe"]},id:14,name:"Diablo"},{executables:{win32:["diablo ii.exe"]},id:15,name:"Diablo 2"},{executables:{win32:["left4dead.exe"]},id:17,name:"Left 4 Dead"},{executables:{darwin:["minecraft.app"],win32:["minecraft.exe"]},id:18,name:"Minecraft"},{executables:{win32:["smite.exe"]},id:19,name:"Smite"},{executables:{win32:["bf4.exe"]},id:20,name:"Battlefield 4"},{executables:{win32:["AoK HD.exe","empires2.exe"]},id:101,name:"Age of Empire II"},{executables:{win32:["age3y.exe"]},id:102,name:"Age of Empire III"},{executables:{win32:["AlanWake.exe"]},id:104,name:"Alan Wake"},{executables:{win32:["alan_wakes_american_nightmare.exe"]},id:105,name:"Alan Wake's American Nightmare"},{executables:{win32:["AlienBreed2Assault.exe"]},id:106,name:"Alien Breed 2: Assault"},{executables:{win32:["Amnesia.exe"]},id:107,name:"Amnesia: The Dark Descent"},{executables:{win32:["UDK.exe"]},id:108,name:"Antichamber"},{executables:{win32:["ArcheAge.exe"]},id:109,name:"ArcheAge"},{executables:{win32:["arma3.exe"]},id:110,name:"Arma III"},{executables:{win32:["AC3SP.exe"]},id:111,name:"Assassin's Creed 3"},{executables:{win32:["Bastion.exe"]},id:112,name:"Bastion"},{executables:{win32:["BF2.exe"]},id:113,name:"Battlefield 2"},{executables:{win32:["bf3.exe"]},id:114,name:"Battlefield 3"},{executables:{win32:["Besiege.exe"]},id:116,name:"Besiege"},{executables:{win32:["Bioshock.exe"]},id:117,name:"Bioshock"},{executables:{win32:["Bioshock2.exe"]},id:118,name:"BioShock II"},{executables:{win32:["BioShockInfinite.exe"]},id:119,name:"BioShock Infinite"},{executables:{win32:["Borderlands2.exe"]},id:122,name:"Borderlands 2"},{executables:{win32:["braid.exe"]},id:123,name:"Braid"},{executables:{win32:["ShippingPC-StormGame.exe"]},id:124,name:"Bulletstorm"},{executables:{},id:125,name:"Cabal 2"},{executables:{win32:["CabalMain.exe"]},id:126,name:"Cabal Online"},{executables:{win32:["iw4mp.exe","iw4sp.exe"]},id:127,name:"Call of Duty: Modern Warfare 2"},{executables:{win32:["t6sp.exe"]},id:128,name:"Call of Duty: Black Ops"},{executables:{win32:["iw5mp.exe"]},id:129,name:"Call of Duty: Modern Warfare 3"},{executables:{win32:["RelicCOH.exe"]},id:132,name:"Company of Heroes"},{executables:{win32:["Crysis64.exe"]},id:135,name:"Crysis"},{executables:{win32:["Crysis2.exe"]},id:136,name:"Crysis 2"},{executables:{win32:["Crysis3.exe"]},id:137,name:"Crysis 3"},{executables:{win32:["Crysis.exe"]},id:138,name:"Crysis 4 "},{executables:{win32:["DATA.exe"]},id:140,name:"Dark Souls"},{executables:{win32:["DarkSoulsII.exe"]},id:141,name:"Dark Souls II"},{executables:{win32:["dfuw.exe"]},id:142,name:"Darkfall: Unholy Wars"},{executables:{win32:["DCGAME.exe"]},id:144,name:"DC Universe Online"},{executables:{win32:["DeadIslandGame.exe"]},id:145,name:"Dead Island"},{executables:{win32:["deadspace2.exe"]},id:146,name:"Dead Space 2"},{executables:{win32:["LOTDGame.exe"]},id:147,name:"Deadlight"},{executables:{win32:["dxhr.exe"]},id:148,name:"Deus Ex: Human Revolution"},{executables:{win32:["DeviMayCry4.exe"]},id:149,name:"Devil May Cry 4"},{executables:{win32:["DMC-DevilMayCry.exe"]},id:150,name:"DmC Devil May Cry"},{executables:{win32:["dirt2_game.exe"]},id:154,name:"DiRT 2"},{executables:{win32:["dirt3_game.exe"]},id:155,name:"DiRT 3"},{executables:{win32:["dota.exe"]},id:156,name:"DOTA"},{executables:{win32:["DoubleDragon.exe"]},id:158,name:"Double Dragon Neon"},{executables:{win32:["DragonAge2.exe"]},id:159,name:"Dragon Age II"},{executables:{win32:["DragonAgeInquisition.exe"]},id:160,name:"Dragon Age: Inquisition"},{executables:{win32:["daorigins.exe"]},id:161,name:"Dragon Age: Origins"},{executables:{win32:["DBXV.exe"]},id:162,name:"Dragon Ball XenoVerse"},{executables:{win32:["DukeForever.exe"]},id:163,name:"Duke Nukem Forever"},{executables:{darwin:["Dustforce.app"],win32:["dustforce.exe"]},id:164,name:"Dustforce"},{executables:{win32:["EliteDangerous32.exe"]},id:165,name:"Elite: Dangerous"},{executables:{win32:["exefile.exe"]},id:166,name:"Eve Online"},{executables:{win32:["eqgame.exe"]},id:167,name:"EverQuest"},{executables:{win32:["EverQuest2.exe"]},id:168,name:"EverQuest II"},{executables:{},id:169,name:"EverQuest Next"},{executables:{win32:["Engine.exe"]},id:170,name:"F.E.A.R."},{executables:{win32:["FEAR2.exe"]},id:171,name:"F.E.A.R. 2: Project Origin"},{executables:{win32:["fallout3.exe"]},id:172,name:"Fallout 3"},{executables:{win32:["FalloutNV.exe"]},id:174,name:"Fallout: New Vegas"},{executables:{win32:["farcry3.exe"]},id:175,name:"Far Cry 3"},{executables:{win32:["fifa15.exe"]},id:176,name:"FIFA 15"},{executables:{win32:["FTLGame.exe"]},id:180,name:"FTL: Faster Than Light"},{executables:{win32:["GTAIV.exe"]},id:181,name:"Grand Theft Auto 4"},{executables:{win32:["GTA5.exe"]},id:182,name:"Grand Theft Auto 5"},{executables:{win32:["Gw.exe"]},id:183,name:"Guild Wars"},{executables:{win32:["H1Z1.exe"]},id:186,name:"H1Z1"},{executables:{win32:["HL2HL2.exe","hl2.exe"]},id:188,name:"Half Life 2"},{executables:{win32:["HOMEFRONT.exe"]},id:195,name:"Homefront"},{executables:{win32:["invisibleinc.exe"]},id:196,name:"Invisible Inc."},{executables:{win32:["LANoire.exe"]},id:197,name:"L.A. Noire"},{executables:{win32:["Landmark64.exe"]},id:198,name:"Landmark"},{executables:{win32:["left4dead2.exe"]},id:201,name:"Left 4 Dead 2"},{executables:{win32:["lineage.exe"]},id:203,name:"Lineage"},{executables:{win32:["Magicka.exe"]},id:206,name:"Magicka"},{executables:{win32:["MapleStory.exe"]},id:208,name:"MapleStory"},{executables:{},id:209,name:"Mark of the Ninja"},{executables:{win32:["MassEffect.exe"]},id:210,name:"Mass Effect"},{executables:{win32:["MassEffect2.exe"]},id:211,name:"Mass Effect 2"},{executables:{win32:["MassEffect3Demo.exe"]},id:212,name:"Mass Effect 3"},{executables:{win32:["METAL GEAR RISING REVENGEANCE.exe"]},id:214,name:"Metal Gear Rising: Revengeance"},{executables:{win32:["metro2033.exe"]},id:215,name:"Metro 2033"},{executables:{win32:["MetroLL.exe"]},id:216,name:"Metro Last Light"},{executables:{win32:["MK10.exe"]},id:218,name:"Mortal Kombat X"},{executables:{win32:["speed.exe"]},id:219,name:"Need For Speed Most Wanted"},{executables:{},id:220,name:"Neverwinder"},{executables:{darwin:["Outlast.app"],win32:["OLGame.exe"]},id:221,name:"Outlast"},{executables:{win32:["PapersPlease.exe"]},id:222,name:"Papers, Please"},{executables:{win32:["payday_win32_release.exe"]},id:223,name:"PAYDAY"},{executables:{win32:["payday2_win32_release.exe"]},id:224,name:"PAYDAY2"},{executables:{win32:["PillarsOfEternity.exe"]},id:225,name:"Pillars of Eternity"},{executables:{win32:["PA.exe"]},id:226,name:"Planetary Annihilation"},{executables:{win32:["planetside2_x86.exe"]},id:227,name:"Planetside 2"},{executables:{win32:["hl2P.exe"]},id:228,name:"Portal"},{executables:{win32:["portal2.exe"]},id:229,name:"Portal 2"},{executables:{win32:["PrimalCarnageGame.exe"]},id:231,name:"Primal Cargnage"},{executables:{win32:["pCARS.exe"]},id:232,name:"Project Cars"},{executables:{win32:["RaceTheSun.exe"]},id:233,name:"Race The Sun"},{executables:{win32:["Rage.exe"]},id:234,name:"RAGE"},{executables:{win32:["ragexe.exe"]},id:235,name:"Ragnarok Online"},{executables:{win32:["rift.exe"]},id:236,name:"Rift"},{executables:{win32:["Rocksmith2014.exe"]},id:237,name:"Rocksmith 2014"},{executables:{win32:["SwiftKit-RS.exe","JagexLauncher.exe"]},id:238,name:"RuneScape"},{executables:{win32:["Shadowgrounds.exe"]},id:239,name:"Shadowgrounds"},{executables:{win32:["survivor.exe"]},id:240,name:"Shadowgrounds: Survivor"},{executables:{win32:["ShovelKnight.exe"]},id:241,name:"Shovel Knight"},{executables:{win32:["SimCity.exe"]},id:242,name:"SimCity"},{executables:{win32:["SporeApp.exe"]},id:245,name:"Spore"},{executables:{win32:["StarCitizen.exe"]},id:246,name:"Star Citizen"},{executables:{},id:247,name:"Star Trek Online"},{executables:{win32:["battlefront.exe"]},id:248,name:"Star Wars Battlefront"},{executables:{win32:["swtor.exe"]},id:249,name:"Star Wars: The Old Republic"},{executables:{win32:["starbound.exe","starbound_opengl.exe"]},id:250,name:"Starbound"},{executables:{win32:["starcraft.exe"]},id:251,name:"Starcraft"},{executables:{win32:["SSFIV.exe"]},id:253,name:"Ultra Street Fighter IV"},{executables:{win32:["superhexagon.exe"]},id:254,name:"Super Hexagon"},{executables:{win32:["swordandsworcery_pc.exe"]},id:255,name:"Superbrothers: Sword & Sworcery EP"},{executables:{win32:["hl2TF.exe"]},id:256,name:"Team Fortress 2"},{executables:{win32:["TERA.exe"]},id:258,name:"TERA"},{executables:{win32:["Terraria.exe"]},id:259,name:"Terraria"},{executables:{win32:["Bethesda.net_Launcher.exe"]},id:260,name:"The Elder Scrolls Online"},{executables:{win32:["TESV.exe"]},id:261,name:"The Elder Scrolls V: Skyrim"},{executables:{win32:["TheSecretWorld.exe"]},id:262,name:"The Secret World"},{executables:{win32:["TS3.exe","ts3w.exe"]},id:264,name:"The Sims 3"},{executables:{win32:["WALKINGDEAD101.EXE"]},id:265,name:"The Walking Dead"},{executables:{win32:["TheWalkingDead2.exe"]},id:266,name:"The Walking Dead Season Two"},{executables:{win32:["witcher3.exe"]},id:267,name:"The Witcher 3"},{executables:{win32:["Future Soldier.exe"]},id:268,name:"Tom Clancy's Ghost Recon: Future Solider"},{executables:{win32:["TombRaider.exe"]},id:269,name:"Tomb Raider (2013)"},{executables:{win32:["Torchlight.exe"]},id:271,name:"Torchlight"},{executables:{win32:["Torchlight2.exe"]},id:272,name:"Torchlight 2"},{executables:{win32:["Shogun2.exe"]},id:273,name:"Total War: Shogun 2"},{executables:{win32:["Transistor.exe"]},id:274,name:"Transistor"},{executables:{win32:["trine.exe"]},id:275,name:"Trine"},{executables:{win32:["trine2_32bit.exe"]},id:276,name:"Trine 2"},{executables:{win32:["UOKR.exe"]},id:277,name:"Ultima Online"},{executables:{win32:["aces.exe"]},id:279,name:"War Thunder"},{executables:{win32:["Warcraft III.exe","wc3.exe"]},id:281,name:"Warcraft 3: Reign of Chaos"},{executables:{win32:["Warcraft II BNE.exe"]},id:282,name:"Warcraft II"},{executables:{win32:["Warframe.x64.exe","Warframe.exe"]},id:283,name:"Warframe"},{executables:{win32:["watch_dogs.exe"]},id:284,name:"Watch Dogs"},{executables:{win32:["WildStar64.exe"]},id:285,name:"WildStar"},{executables:{win32:["XComGame.exe"]},id:288,name:"XCOM: Enemy Unknown"},{executables:{win32:["DFO.exe","dfo.exe"]},id:289,name:"Dungeon Fighter Online"},{executables:{win32:["aclauncher.exe","acclient.exe"]},id:290,name:"Asheron's Call"},{executables:{win32:["MapleStory2.exe"]},id:291,name:"MapleStory 2"},{executables:{win32:["ksp.exe"]},id:292,name:"Kerbal Space Program"},{executables:{win32:["PINBALL.EXE"]},id:293,name:"3D Pinball: Space Cadet"},{executables:{win32:["dave.exe"]},id:294,name:"Dangerous Dave"},{executables:{win32:["iwbtgbeta(slomo).exe","iwbtgbeta(fs).exe"]},id:295,name:"I Wanna Be The Guy"},{executables:{win32:["MechWarriorOnline.exe "]},id:296,name:"Mech Warrior Online"},{executables:{win32:["dontstarve_steam.exe"]},id:297,name:"Don't Starve"},{executables:{win32:["GalCiv3.exe"]},id:298,name:"Galactic Civilization 3"},{executables:{win32:["Risk of Rain.exe"]},id:299,name:"Risk of Rain"},{executables:{win32:["Binding_of_Isaac.exe","Isaac-ng.exe"]},id:300,name:"The Binding of Isaac"},{executables:{win32:["RustClient.exe"]},id:301,name:"Rust"},{executables:{win32:["Clicker Heroes.exe"]},id:302,name:"Clicker Heroes"},{executables:{win32:["Brawlhalla.exe"]},id:303,name:"Brawlhalla"},{executables:{win32:["TownOfSalem.exe"]},id:304,name:"Town of Salem"},{executables:{win32:["osu!.exe"]},id:305,name:"osu!"},{executables:{win32:["PathOfExileSteam.exe","PathOfExile.exe"] +},id:306,name:"Path of Exile"},{executables:{win32:["Dolphin.exe"]},id:307,name:"Dolphin"},{executables:{win32:["RocketLeague.exe"]},id:308,name:"Rocket League"},{executables:{win32:["TJPP.exe"]},id:309,name:"Jackbox Party Pack"},{executables:{win32:["KFGame.exe"]},id:310,name:"Killing Floor 2"},{executables:{win32:["ShooterGame.exe"]},id:311,name:"Ark: Survival Evolved"},{executables:{win32:["LifeIsStrange.exe"]},id:312,name:"Life Is Strange"},{executables:{win32:["Client_tos.exe"]},id:313,name:"Tree of Savior"},{executables:{win32:["olliolli2.exe"]},id:314,name:"OlliOlli2"},{executables:{win32:["cw.exe"]},id:315,name:"Closers Dimension Conflict"},{executables:{win32:["ESSTEAM.exe","elsword.exe","x2.exe"]},id:316,name:"Elsword"},{executables:{win32:["ori.exe"]},id:317,name:"Ori and the Blind Forest"},{executables:{win32:["Skyforge.exe"]},id:318,name:"Skyforge"},{executables:{win32:["projectzomboid64.exe","projectzomboid32.exe"]},id:319,name:"Project Zomboid"},{executables:{win32:["From_The_Depths.exe"]},id:320,name:"The Depths"},{executables:{win32:["TheCrew.exe"]},id:321,name:"The Crew"},{executables:{win32:["MarvelHeroes2015.exe"]},id:322,name:"Marvel Heroes 2015"},{executables:{win32:["timeclickers.exe"]},id:324,name:"Time Clickers"},{executables:{win32:["eurotrucks2.exe"]},id:325,name:"Euro Truck Simulator 2"},{executables:{win32:["FarmingSimulator2015Game.exe"]},id:326,name:"Farming Simulator 15"},{executables:{win32:["strife.exe"]},id:327,name:"Strife"},{executables:{win32:["Awesomenauts.exe"]},id:328,name:"Awesomenauts"},{executables:{win32:["Dofus.exe"]},id:329,name:"Dofus"},{executables:{win32:["Boid.exe"]},id:330,name:"Boid"},{executables:{win32:["adventure-capitalist.exe"]},id:331,name:"AdVenture Capitalist"},{executables:{win32:["OrcsMustDie2.exe"]},id:332,name:"Orcs Must Die! 2"},{executables:{win32:["Mountain.exe"]},id:333,name:"Mountain"},{executables:{win32:["Valkyria.exe"]},id:335,name:"Valkyria Chronicles"},{executables:{win32:["ffxiiiimg.exe"]},id:336,name:"Final Fantasy XIII"},{executables:{win32:["TLR.exe"]},id:337,name:"The Last Remnant"},{executables:{win32:["Cities.exe"]},id:339,name:"Cities Skylines"},{executables:{win32:["worldofwarships.exe","WoWSLauncher.exe"]},id:341,name:"World of Warships"},{executables:{win32:["spacegame-Win64-shipping.exe"]},id:342,name:"Fractured Space"},{executables:{win32:["thespacegame.exe"]},id:343,name:"Ascent - The Space Game"},{executables:{win32:["DuckGame.exe"]},id:344,name:"Duck Game"},{executables:{win32:["PPSSPPWindows.exe"]},id:345,name:"PPSSPP"},{executables:{win32:["MBAA.exe"]},id:346,name:"Melty Blood Actress Again: Current Code"},{executables:{win32:["TheWolfAmongUs.exe"]},id:347,name:"The Wolf Among Us"},{executables:{win32:["SpaceEngineers.exe"]},id:348,name:"Space Engineers"},{executables:{win32:["Borderlands.exe"]},id:349,name:"Borderlands"},{executables:{win32:["100orange.exe"]},id:351,name:"100% Orange Juice"},{executables:{win32:["reflex.exe"]},id:354,name:"Reflex"},{executables:{win32:["pso2.exe"]},id:355,name:"Phantasy Star Online 2"},{executables:{win32:["AssettoCorsa.exe"]},id:356,name:"Assetto Corsa"},{executables:{win32:["iw3mp.exe","iw3sp.exe"]},id:357,name:"Call of Duty 4: Modern Warfare"},{executables:{win32:["WolfOldBlood_x64.exe"]},id:358,name:"Wolfenstein: The Old Blood"},{executables:{win32:["castle.exe"]},id:359,name:"Castle Crashers"},{executables:{win32:["vindictus.exe"]},id:360,name:"Vindictus"},{executables:{win32:["ShooterGame-Win32-Shipping.exe"]},id:361,name:"Dirty Bomb"},{executables:{win32:["BatmanAK.exe"]},id:362,name:"Batman Arkham Knight"},{executables:{win32:["drt.exe"]},id:363,name:"Dirt Rally"},{executables:{win32:["rFactor.exe"]},id:364,name:"rFactor"},{executables:{win32:["clonk.exe"]},id:365,name:"Clonk Rage"},{executables:{win32:["SRHK.exe"]},id:366,name:"Shadowrun: Hong Kong"},{executables:{win32:["Insurgency.exe"]},id:367,name:"Insurgency"},{executables:{win32:["StepMania.exe"]},id:368,name:"Step Mania"},{executables:{win32:["FirefallCLient.exe"]},id:369,name:"Firefall"},{executables:{win32:["mirrorsedge.exe"]},id:370,name:"Mirrors Edge"},{executables:{win32:["MgsGroundZeroes.exe"]},id:371,name:"Metal Gear Solid V: Ground Zeroes"},{executables:{win32:["mgsvtpp.exe"]},id:372,name:"Metal Gear Solid V: The Phantom Pain"},{executables:{win32:["tld.exe"]},id:373,name:"The Long Dark"},{executables:{win32:["TKOM.exe"]},id:374,name:"Take On Mars"},{executables:{win32:["robloxplayerlauncher.exe","Roblox.exe"]},id:375,name:"Roblox"},{executables:{win32:["eu4.exe"]},id:376,name:"Europa Universalis 4"},{executables:{win32:["APB.exe"]},id:377,name:"APB Reloaded"},{executables:{win32:["Robocraft.exe"]},id:378,name:"Robocraft"},{executables:{win32:["Unity.exe"]},id:379,name:"Unity"},{executables:{win32:["Simpsons.exe"]},id:380,name:"The Simpsons: Hit & Run"},{executables:{win32:["Dnlauncher.exe","DragonNest.exe"]},id:381,name:"Dragon Nest"},{executables:{win32:["Trove.exe"]},id:382,name:"Trove"},{executables:{win32:["EndlessLegend.exe"]},id:383,name:"Endless Legend"},{executables:{win32:["TurbineLauncher.exe","dndclient.exe"]},id:384,name:"Dungeons & Dragons Online"},{executables:{win32:["quakelive.exe","quakelive_steam.exe"]},id:385,name:"Quake Live"},{executables:{win32:["7DaysToDie.exe"]},id:386,name:"7DaysToDie"},{executables:{win32:["SpeedRunners.exe"]},id:387,name:"SpeedRunners"},{executables:{win32:["gamemd.exe"]},id:388,name:"Command & Conquer: Red Alert 2"},{executables:{win32:["generals.exe"]},id:389,name:"Command & Conquer Generals: Zero Hour"},{executables:{win32:["Oblivion.exe"]},id:390,name:"The Elder Scrolls 4: Oblivion"},{executables:{win32:["mgsi.exe"]},id:391,name:"Metal Gear Solid"},{executables:{win32:["EoCApp.exe"]},id:392,name:"Divinity - Original Sin"},{executables:{win32:["Torment.exe"]},id:393,name:"Planescape: Torment"},{executables:{win32:["HexPatch.exe"]},id:394,name:"Hex: Shards of Fate"},{executables:{win32:["NS3FB.exe"]},id:395,name:"Naruto Shippuden Ultimate Ninja Storm 3 Full Burst"},{executables:{win32:["NSUNSR.exe"]},id:396,name:"Naruto Shippuden Ultimate Ninja Storm Revolution"},{executables:{win32:["SaintsRowIV.exe"]},id:397,name:"Saints Row IV"},{executables:{win32:["Shadowrun.exe"]},id:398,name:"Shadowrun"},{executables:{win32:["DungeonoftheEndless.exe"]},id:399,name:"Dungeon of the Endless"},{executables:{win32:["Hon.exe"]},id:400,name:"Heroes of Newerth"},{executables:{win32:["mabinogi.exe"]},id:401,name:"Mabinogi"},{executables:{win32:["CoD2MP_s.exe","CoDSP_s.exe"]},id:402,name:"Call of Duty 2:"},{executables:{win32:["CoDWaWmp.exe","CoDWaw.exe"]},id:403,name:"Call of Duty: World at War"},{executables:{win32:["heroes.exe"]},id:404,name:"Mabinogi Heroes (Vindictus) "},{executables:{win32:["KanColleViewer.exe"]},id:405,name:"KanColle "},{executables:{win32:["cyphers.exe"]},id:406,name:"Cyphers"},{executables:{win32:["RelicCoH2.exe"]},id:407,name:"Company of Heroes 2"},{executables:{win32:["MJ.exe"]},id:408,name:"セガNET麻雀MJ"},{executables:{win32:["ge.exe"]},id:409,name:"Granado Espada"},{executables:{win32:["NovaRO.exe"]},id:410,name:"Nova Ragnarok Online"},{executables:{win32:["RivalsofAether.exe"]},id:411,name:"Rivals of Aether"},{executables:{win32:["bfh.exe"]},id:412,name:"Battlefield Hardline"},{executables:{win32:["GrowHome.exe"]},id:413,name:"Grow Home"},{executables:{win32:["patriots.exe"]},id:414,name:"Rise of Nations Extended"},{executables:{win32:["Railroads.exe"]},id:415,name:"Sid Meier's Railroads!"},{executables:{win32:["Empire.exe"]},id:416,name:"Empire: Total War"},{executables:{win32:["Napoleon.exe"]},id:417,name:"Napoleon: Total War"},{executables:{win32:["gta_sa.exe"]},id:418,name:"Grand Theft Auto: San Andreas"},{executables:{win32:["MadMax.exe"]},id:419,name:"Mad Max"},{executables:{win32:["Titanfall.exe"]},id:420,name:"Titanfall"},{executables:{win32:["age2_x1.exe"]},id:421,name:"Age of Empires II: The Conquerors"},{executables:{win32:["Rome2.exe"]},id:422,name:"Total War: ROME 2"},{executables:{win32:["ShadowOfMordor.exe"]},id:423,name:"Middle-earth: Shadow of Mordor"},{executables:{win32:["Subnautica.exe"]},id:424,name:"Subnautica"},{executables:{win32:["anno5.exe"]},id:425,name:"Anno 2070"},{executables:{win32:["carrier.exe"]},id:426,name:"Carrier Command Gaea Mission"},{executables:{win32:["DarksidersPC.exe"]},id:427,name:"Darksiders"},{executables:{win32:["Darksiders2.exe"]},id:428,name:"Darksiders 2"},{executables:{win32:["mudlet.exe"]},id:429,name:"Mudlet"},{executables:{win32:["DunDefLauncher.exe"]},id:430,name:"Dungeon Defenders II"},{executables:{win32:["hng.exe"]},id:431,name:"Heroes and Generals"},{executables:{win32:["WFTOGame.exe"]},id:432,name:"War of the Overworld"},{executables:{win32:["Talisman.exe"]},id:433,name:"Talisman: Digital Edition"},{executables:{win32:["limbo.exe"]},id:434,name:"Limbo"},{executables:{win32:["ibbobb.exe"]},id:435,name:"ibb & obb"},{executables:{win32:["BattleBlockTheater.exe"]},id:436,name:"BattleBlock Theater"},{executables:{win32:["iracinglauncher.exe","iracingsim.exe","iracingsim64.exe"]},id:437,name:"iRacing"},{executables:{win32:["CivilizationV_DX11.exe"]},id:438,name:"Civilization V"}]},{}]},{},[9])(9)}); \ No newline at end of file From 2de37a8fbbfe19eb01ddcf9192b2d32063316762 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 25 Oct 2015 18:36:03 +0000 Subject: [PATCH 143/151] Fixed permissions --- .vscode/tasks.json | 2 +- lib/ChannelPermissions.js | 182 +++- lib/Client.js | 1752 +++++++++++++++++++++++++++++++++-- lib/Endpoints.js | 14 +- lib/EvaluatedPermissions.js | 188 +++- lib/Member.js | 178 +++- lib/PMChannel.js | 62 +- lib/ServerPermissions.js | 27 +- lib/channel.js | 132 ++- lib/index.js | 13 +- lib/internal.js | 204 +++- lib/invite.js | 36 +- lib/message.js | 78 +- lib/server.js | 417 ++++----- src/EvaluatedPermissions.js | 34 +- test/bot.1.js | 7 +- 16 files changed, 2969 insertions(+), 357 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 95c321163..7606560da 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -19,7 +19,7 @@ "isBuildCommand": true, "isWatching": true, "args": [ - "src", "--out-dir", "lib", "-w" + "src", "--out-dir", "lib", "-w", "--loose=all" ] } ] diff --git a/lib/ChannelPermissions.js b/lib/ChannelPermissions.js index e5fe374b5..5193b5938 100644 --- a/lib/ChannelPermissions.js +++ b/lib/ChannelPermissions.js @@ -1,2 +1,180 @@ -"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var ChannelPermissions=(function(){function ChannelPermissions(data,channel){_classCallCheck(this,ChannelPermissions);var self=this;function getBit(x){return (self.packed >>> x & 1) === 1;}this.type = data.type; //either member or role -this.id = data.id;if(this.type === "member"){this.packed = channel.server.getMember("id",data.id).evalPerms.packed;}else {this.packed = channel.server.getRole(data.id).packed;}this.packed = this.packed & ~data.deny;this.packed = this.packed | data.allow;this.deny = data.deny;this.allow = data.allow;}ChannelPermissions.prototype.getBit = function getBit(x){return (this.packed >>> x & 1) === 1;};ChannelPermissions.prototype.setBit = function setBit(){};_createClass(ChannelPermissions,[{key:"createInstantInvite",get:function get(){return this.getBit(0);},set:function set(val){this.setBit(0,val);}},{key:"manageRoles",get:function get(){return this.getBit(3);},set:function set(val){this.setBit(3,val);}},{key:"manageChannels",get:function get(){return this.getBit(4);},set:function set(val){this.setBit(4,val);}},{key:"readMessages",get:function get(){return this.getBit(10);},set:function set(val){this.setBit(10,val);}},{key:"sendMessages",get:function get(){return this.getBit(11);},set:function set(val){this.setBit(11,val);}},{key:"sendTTSMessages",get:function get(){return this.getBit(12);},set:function set(val){this.setBit(12,val);}},{key:"manageMessages",get:function get(){return this.getBit(13);},set:function set(val){this.setBit(13,val);}},{key:"embedLinks",get:function get(){return this.getBit(14);},set:function set(val){this.setBit(14,val);}},{key:"attachFiles",get:function get(){return this.getBit(15);},set:function set(val){this.setBit(15,val);}},{key:"readMessageHistory",get:function get(){return this.getBit(16);},set:function set(val){this.setBit(16,val);}},{key:"mentionEveryone",get:function get(){return this.getBit(17);},set:function set(val){this.setBit(17,val);}},{key:"voiceConnect",get:function get(){return this.getBit(20);},set:function set(val){this.setBit(20,val);}},{key:"voiceSpeak",get:function get(){return this.getBit(21);},set:function set(val){this.setBit(21,val);}},{key:"voiceMuteMembers",get:function get(){return this.getBit(22);},set:function set(val){this.setBit(22,val);}},{key:"voiceDeafenMembers",get:function get(){return this.getBit(23);},set:function set(val){this.setBit(23,val);}},{key:"voiceMoveMembers",get:function get(){return this.getBit(24);},set:function set(val){this.setBit(24,val);}},{key:"voiceUseVoiceActivation",get:function get(){return this.getBit(25);},set:function set(val){this.setBit(25,val);}}]);return ChannelPermissions;})();module.exports = ChannelPermissions; +"use strict"; + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var ChannelPermissions = (function () { + function ChannelPermissions(data, channel) { + _classCallCheck(this, ChannelPermissions); + + var self = this; + + function getBit(x) { + return (self.packed >>> x & 1) === 1; + } + + this.type = data.type; //either member or role + this.id = data.id; + + if (this.type === "member") { + this.packed = channel.server.getMember("id", data.id).evalPerms.packed; + } else { + this.packed = channel.server.getRole(data.id).packed; + } + + this.packed = this.packed & ~data.deny; + this.packed = this.packed | data.allow; + + this.deny = data.deny; + this.allow = data.allow; + } + + ChannelPermissions.prototype.getBit = function getBit(x) { + return (this.packed >>> x & 1) === 1; + }; + + ChannelPermissions.prototype.setBit = function setBit() {}; + + _createClass(ChannelPermissions, [{ + key: "createInstantInvite", + get: function get() { + return this.getBit(0); + }, + set: function set(val) { + this.setBit(0, val); + } + }, { + key: "manageRoles", + get: function get() { + return this.getBit(3); + }, + set: function set(val) { + this.setBit(3, val); + } + }, { + key: "manageChannels", + get: function get() { + return this.getBit(4); + }, + set: function set(val) { + this.setBit(4, val); + } + }, { + key: "readMessages", + get: function get() { + return this.getBit(10); + }, + set: function set(val) { + this.setBit(10, val); + } + }, { + key: "sendMessages", + get: function get() { + return this.getBit(11); + }, + set: function set(val) { + this.setBit(11, val); + } + }, { + key: "sendTTSMessages", + get: function get() { + return this.getBit(12); + }, + set: function set(val) { + this.setBit(12, val); + } + }, { + key: "manageMessages", + get: function get() { + return this.getBit(13); + }, + set: function set(val) { + this.setBit(13, val); + } + }, { + key: "embedLinks", + get: function get() { + return this.getBit(14); + }, + set: function set(val) { + this.setBit(14, val); + } + }, { + key: "attachFiles", + get: function get() { + return this.getBit(15); + }, + set: function set(val) { + this.setBit(15, val); + } + }, { + key: "readMessageHistory", + get: function get() { + return this.getBit(16); + }, + set: function set(val) { + this.setBit(16, val); + } + }, { + key: "mentionEveryone", + get: function get() { + return this.getBit(17); + }, + set: function set(val) { + this.setBit(17, val); + } + }, { + key: "voiceConnect", + get: function get() { + return this.getBit(20); + }, + set: function set(val) { + this.setBit(20, val); + } + }, { + key: "voiceSpeak", + get: function get() { + return this.getBit(21); + }, + set: function set(val) { + this.setBit(21, val); + } + }, { + key: "voiceMuteMembers", + get: function get() { + return this.getBit(22); + }, + set: function set(val) { + this.setBit(22, val); + } + }, { + key: "voiceDeafenMembers", + get: function get() { + return this.getBit(23); + }, + set: function set(val) { + this.setBit(23, val); + } + }, { + key: "voiceMoveMembers", + get: function get() { + return this.getBit(24); + }, + set: function set(val) { + this.setBit(24, val); + } + }, { + key: "voiceUseVoiceActivation", + get: function get() { + return this.getBit(25); + }, + set: function set(val) { + this.setBit(25, val); + } + }]); + + return ChannelPermissions; +})(); + +module.exports = ChannelPermissions; \ No newline at end of file diff --git a/lib/Client.js b/lib/Client.js index 335061bd6..fc69385e9 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1,75 +1,1681 @@ //discord.js modules -"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 Endpoints=require("./Endpoints.js");var User=require("./user.js");var Server=require("./server.js");var Channel=require("./channel.js");var Message=require("./message.js");var Invite=require("./invite.js");var PMChannel=require("./PMChannel.js");var gameMap=require("../ref/gameMap.json"); //node modules -var request=require("superagent");var WebSocket=require("ws");var fs=require("fs");var defaultOptions={queue:false};var Client=(function(){function Client(){var options=arguments.length <= 0 || arguments[0] === undefined?defaultOptions:arguments[0];var token=arguments.length <= 1 || arguments[1] === undefined?undefined:arguments[1];_classCallCheck(this,Client); /* - When created, if a token is specified the Client will - try connecting with it. If the token is incorrect, no - further efforts will be made to connect. - */this.options = options;this.options.queue = this.options.queue;this.token = token;this.state = 0;this.websocket = null;this.events = {};this.user = null;this.alreadySentData = false;this.serverCreateListener = {};this.typingIntervals = {};this.email = "abc";this.password = "abc"; /* - State values: - 0 - idle - 1 - logging in - 2 - logged in - 3 - ready - 4 - disconnected - */this.userCache = [];this.channelCache = [];this.serverCache = [];this.pmChannelCache = [];this.readyTime = null;this.checkingQueue = {};this.userTypingListener = {};this.queue = {};this.__idleTime = null;this.__gameId = null;}Client.prototype.sendPacket = function sendPacket(JSONObject){if(this.websocket.readyState === 1){this.websocket.send(JSON.stringify(JSONObject));}}; //def debug -Client.prototype.debug = function debug(message){this.trigger("debug",message);};Client.prototype.on = function on(event,fn){this.events[event] = fn;};Client.prototype.off = function off(event){this.events[event] = null;};Client.prototype.keepAlive = function keepAlive(){this.debug("keep alive triggered");this.sendPacket({op:1,d:Date.now()});}; //def trigger -Client.prototype.trigger = function trigger(event){var args=[];for(var arg in arguments) {args.push(arguments[arg]);}var evt=this.events[event];if(evt){evt.apply(this,args.slice(1));}}; //def login -Client.prototype.login = function login(){var email=arguments.length <= 0 || arguments[0] === undefined?"foo@bar.com":arguments[0];var password=arguments.length <= 1 || arguments[1] === undefined?"pass1234":arguments[1];var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,token){}:arguments[2];var self=this;return new Promise(function(resolve,reject){if(self.state === 0 || self.state === 4){self.state = 1; //set the state to logging in -self.email = email;self.password = password;request.post(Endpoints.LOGIN).send({email:email,password:password}).end(function(err,res){if(err){self.state = 4; //set state to disconnected -self.trigger("disconnected");if(self.websocket){self.websocket.close();}callback(err);reject(err);}else {self.state = 2; //set state to logged in (not yet ready) -self.token = res.body.token; //set our token -self.getGateway().then(function(url){self.createws(url);callback(null,self.token);resolve(self.token);})["catch"](function(err){callback(err);reject(err);});}});}else {reject(new Error("Client already logging in or ready"));}});};Client.prototype.logout = function logout(){var callback=arguments.length <= 0 || arguments[0] === undefined?function(err){}:arguments[0];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.LOGOUT).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {self.websocket.close();self.state = 4;callback();resolve();}});});};Client.prototype.createServer = function createServer(name,region){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,server){}:arguments[2];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.SERVERS).set("authorization",self.token).send({name:name,region:region}).end(function(err,res){if(err){callback(err);reject(err);}else { // potentially redundant in future -// creating here does NOT give us the channels of the server -// so we must wait for the guild_create event. -self.serverCreateListener[res.body.id] = [resolve,callback]; /*var srv = self.addServer(res.body); - callback(null, srv); - resolve(srv);*/}});});};Client.prototype.createChannel = function createChannel(server,channelName,channelType){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,chann){}:arguments[3];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.SERVERS + "/" + self.resolveServerID(server) + "/channels").set("authorization",self.token).send({name:channelName,type:channelType}).end(function(err,res){if(err){callback(err);reject(err);}else {var server=self.getServer("id",res.body.guild_id);var chann=self.addChannel(res.body,res.body.guild_id);server.addChannel(chann);callback(null,chann);resolve(chann);}});});};Client.prototype.leaveServer = function leaveServer(server){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,server){}:arguments[1];var self=this;return new Promise(function(resolve,reject){request.del(Endpoints.SERVERS + "/" + self.resolveServerID(server)).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {self.serverCache.splice(self.serverCache.indexOf(server),1);callback(null);resolve();}});});};Client.prototype.createInvite = function createInvite(serverOrChannel,options){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,invite){}:arguments[2];var self=this;return new Promise(function(resolve,reject){var destination;if(serverOrChannel instanceof Server){destination = serverOrChannel.id;}else if(serverOrChannel instanceof Channel){destination = serverOrChannel.id;}else {destination = serverOrChannel;}options = options || {};options.max_age = options.maxAge || 0;options.max_uses = options.maxUses || 0;options.temporary = options.temporary || false;options.xkcdpass = options.xkcd || false;request.post(Endpoints.CHANNELS + "/" + destination + "/invites").set("authorization",self.token).send(options).end(function(err,res){if(err){callback(err);reject(err);}else {var inv=new Invite(res.body,self);callback(null,inv);resolve(inv);}});});};Client.prototype.startPM = function startPM(user){var self=this;return new Promise(function(resolve,reject){var userId=user;if(user instanceof User){userId = user.id;}request.post(Endpoints.USERS + "/" + self.user.id + "/channels").set("authorization",self.token).send({recipient_id:userId}).end(function(err,res){if(err){reject(err);}else {resolve(self.addPMChannel(res.body));}});});};Client.prototype.reply = function reply(destination,message,tts){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var self=this;return new Promise(function(response,reject){if(typeof tts === "function"){ // tts is a function, which means the developer wants this to be the callback -callback = tts;tts = false;}var user=destination.sender;self.sendMessage(destination,message,tts,callback,user + ", ").then(response)["catch"](reject);});};Client.prototype.deleteMessage = function deleteMessage(message,timeout){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,msg){}:arguments[2];var self=this;return new Promise(function(resolve,reject){if(timeout){setTimeout(remove,timeout);}else {remove();}function remove(){request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization",self.token).end(function(err,res){if(err){bad();}else {good();}});}function good(){callback();resolve();}function bad(err){callback(err);reject(err);}});};Client.prototype.updateMessage = function updateMessage(message,content){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,msg){}:arguments[2];var self=this;var prom=new Promise(function(resolve,reject){content = content instanceof Array?content.join("\n"):content;if(self.options.queue){if(!self.queue[message.channel.id]){self.queue[message.channel.id] = [];}self.queue[message.channel.id].push({action:"updateMessage",message:message,content:content,then:good,error:bad});self.checkQueue(message.channel.id);}else {self._updateMessage(message,content).then(good)["catch"](bad);}function good(msg){prom.message = msg;callback(null,msg);resolve(msg);}function bad(error){prom.error = error;callback(error);reject(error);}});return prom;};Client.prototype.setUsername = function setUsername(newName){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){request.patch(Endpoints.API + "/users/@me").set("authorization",self.token).send({avatar:self.user.avatar,email:self.email,new_password:null,password:self.password,username:newName}).end(function(err){callback(err);if(err)reject(err);else resolve();});});};Client.prototype.getChannelLogs = function getChannelLogs(channel){var amount=arguments.length <= 1 || arguments[1] === undefined?500:arguments[1];var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,logs){}:arguments[2];var self=this;return new Promise(function(resolve,reject){var channelID=channel;if(channel instanceof Channel){channelID = channel.id;}request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {var logs=[];var channel=self.getChannel("id",channelID);for(var _iterator=res.body,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var message=_ref;var mentions=[];for(var _iterator2=message.mentions,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var mention=_ref2;mentions.push(self.addUser(mention));}var author=self.addUser(message.author);logs.push(new Message(message,channel,mentions,author));}callback(null,logs);resolve(logs);}});});};Client.prototype.deleteChannel = function deleteChannel(channel){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){var channelID=channel;if(channel instanceof Channel){channelID = channel.id;}request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization",self.token).end(function(err){if(err){callback(err);reject(err);}else {callback(null);resolve();}});});};Client.prototype.joinServer = function joinServer(invite){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,server){}:arguments[1];var self=this;return new Promise(function(resolve,reject){var id=invite instanceof Invite?invite.code:invite;request.post(Endpoints.API + "/invite/" + id).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {if(self.getServer("id",res.body.guild.id)){resolve(self.getServer("id",res.body.guild.id));}else {self.serverCreateListener[res.body.guild.id] = [resolve,callback];}}});});};Client.prototype.sendFile = function sendFile(destination,file){var fileName=arguments.length <= 2 || arguments[2] === undefined?"image.png":arguments[2];var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var self=this;var prom=new Promise(function(resolve,reject){var fstream;if(typeof file === "string" || file instanceof String){fstream = fs.createReadStream(file);fileName = file;}else {fstream = file;}self.resolveDestination(destination).then(send)["catch"](bad);function send(destination){if(self.options.queue){ //queue send file too -if(!self.queue[destination]){self.queue[destination] = [];}self.queue[destination].push({action:"sendFile",attachment:fstream,attachmentName:fileName,then:good,error:bad});self.checkQueue(destination);}else { //not queue -self._sendFile(destination,fstream,fileName).then(good)["catch"](bad);}}function good(msg){prom.message = msg;callback(null,msg);resolve(msg);}function bad(err){prom.error = err;callback(err);reject(err);}});return prom;};Client.prototype.sendMessage = function sendMessage(destination,message,tts){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var premessage=arguments.length <= 4 || arguments[4] === undefined?"":arguments[4];var self=this;var prom=new Promise(function(resolve,reject){if(typeof tts === "function"){ // tts is a function, which means the developer wants this to be the callback -callback = tts;tts = false;}message = premessage + resolveMessage(message);var mentions=resolveMentions();self.resolveDestination(destination).then(send)["catch"](error);function error(err){callback(err);reject(err);}function send(destination){if(self.options.queue){ //we're QUEUEING messages, so sending them sequentially based on servers. -if(!self.queue[destination]){self.queue[destination] = [];}self.queue[destination].push({action:"sendMessage",content:message,mentions:mentions,tts:!!tts, //incase it's not a boolean -then:mgood,error:mbad});self.checkQueue(destination);}else {self._sendMessage(destination,message,tts,mentions).then(mgood)["catch"](mbad);}}function mgood(msg){prom.message = msg;callback(null,msg);resolve(msg);}function mbad(error){prom.error = error;callback(error);reject(error);}function resolveMessage(){var msg=message;if(message instanceof Array){msg = message.join("\n");}return msg;}function resolveMentions(){var _mentions=[];for(var _iterator3=message.match(/<@[^>]*>/g) || [],_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[Symbol.iterator]();;) {var _ref3;if(_isArray3){if(_i3 >= _iterator3.length)break;_ref3 = _iterator3[_i3++];}else {_i3 = _iterator3.next();if(_i3.done)break;_ref3 = _i3.value;}var mention=_ref3;_mentions.push(mention.substring(2,mention.length - 1));}return _mentions;}});return prom;}; //def createws -Client.prototype.createws = function createws(url){if(this.websocket)return false;var self=this; //good to go -this.websocket = new WebSocket(url); //open -this.websocket.onopen = function(){self.trySendConnData(); //try connecting -}; //close -this.websocket.onclose = function(){self.trigger("disconnected");}; //message -this.websocket.onmessage = function(e){var dat=false,data={};try{dat = JSON.parse(e.data);data = dat.d;}catch(err) {self.trigger("error",err,e);return;}self.trigger("raw",dat); //valid message -switch(dat.t){case "READY":self.debug("received ready packet");self.user = self.addUser(data.user);for(var _iterator4=data.guilds,_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[Symbol.iterator]();;) {var _ref4;if(_isArray4){if(_i4 >= _iterator4.length)break;_ref4 = _iterator4[_i4++];}else {_i4 = _iterator4.next();if(_i4.done)break;_ref4 = _i4.value;}var _server=_ref4;var server=self.addServer(_server);}for(var _iterator5=data.private_channels,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var _pmc=_ref5;var pmc=self.addPMChannel(_pmc);}self.trigger("ready");self.readyTime = Date.now();self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users.");self.state = 3;setInterval(function(){self.keepAlive.apply(self);},data.heartbeat_interval);break;case "MESSAGE_CREATE":self.debug("received message");var mentions=[];data.mentions = data.mentions || []; //for some reason this was not defined at some point? -for(var _iterator6=data.mentions,_isArray6=Array.isArray(_iterator6),_i6=0,_iterator6=_isArray6?_iterator6:_iterator6[Symbol.iterator]();;) {var _ref6;if(_isArray6){if(_i6 >= _iterator6.length)break;_ref6 = _iterator6[_i6++];}else {_i6 = _iterator6.next();if(_i6.done)break;_ref6 = _i6.value;}var mention=_ref6;mentions.push(self.addUser(mention));}var channel=self.getChannel("id",data.channel_id);if(channel){var msg=channel.addMessage(new Message(data,channel,mentions,self.addUser(data.author)));self.trigger("message",msg);}break;case "MESSAGE_DELETE":self.debug("message deleted");var channel=self.getChannel("id",data.channel_id);var message=channel.getMessage("id",data.id);if(message){self.trigger("messageDelete",channel,message);channel.messages.splice(channel.messages.indexOf(message),1);}else { //don't have the cache of that message ;( -self.trigger("messageDelete",channel);}break;case "MESSAGE_UPDATE":self.debug("message updated");var channel=self.getChannel("id",data.channel_id);var formerMessage=channel.getMessage("id",data.id);if(formerMessage){ //new message might be partial, so we need to fill it with whatever the old message was. -var info={};for(var key in formerMessage) {info[key] = formerMessage[key];}for(var key in data) {info[key] = data[key];}var mentions=[];for(var _iterator7=info.mentions,_isArray7=Array.isArray(_iterator7),_i7=0,_iterator7=_isArray7?_iterator7:_iterator7[Symbol.iterator]();;) {var _ref7;if(_isArray7){if(_i7 >= _iterator7.length)break;_ref7 = _iterator7[_i7++];}else {_i7 = _iterator7.next();if(_i7.done)break;_ref7 = _i7.value;}var mention=_ref7;mentions.push(self.addUser(mention));}var newMessage=new Message(info,channel,mentions,formerMessage.author);self.trigger("messageUpdate",newMessage,formerMessage);channel.messages[channel.messages.indexOf(formerMessage)] = newMessage;} // message isn't in cache, and if it's a partial it could cause -// all hell to break loose... best to just act as if nothing happened -break;case "GUILD_DELETE":var server=self.getServer("id",data.id);if(server){self.serverCache.splice(self.serverCache.indexOf(server),1);self.trigger("serverDelete",server);}break;case "CHANNEL_DELETE":var channel=self.getChannel("id",data.id);if(channel){var server=channel.server;if(server){server.channels.splice(server.channels.indexOf(channel),1);}self.trigger("channelDelete",channel);self.serverCache.splice(self.serverCache.indexOf(channel),1);}break;case "GUILD_CREATE":var server=self.getServer("id",data.id);if(!server){ //if server doesn't already exist because duh -server = self.addServer(data);} /*else if(server.channels.length === 0){ - - var srv = new Server(data, self); - for(channel of data.channels){ - srv.channels.push(new Channel(channel, data.id)); +"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 Endpoints = require("./Endpoints.js"); +var User = require("./user.js"); +var Server = require("./server.js"); +var Channel = require("./channel.js"); +var Message = require("./message.js"); +var Invite = require("./invite.js"); +var PMChannel = require("./PMChannel.js"); + +var gameMap = require("../ref/gameMap.json"); + +//node modules +var request = require("superagent"); +var WebSocket = require("ws"); +var fs = require("fs"); + +var defaultOptions = { + queue: false +}; + +var Client = (function () { + function Client() { + var options = arguments.length <= 0 || arguments[0] === undefined ? defaultOptions : arguments[0]; + var token = arguments.length <= 1 || arguments[1] === undefined ? undefined : arguments[1]; + + _classCallCheck(this, Client); + + /* + When created, if a token is specified the Client will + try connecting with it. If the token is incorrect, no + further efforts will be made to connect. + */ + this.options = options; + this.options.queue = this.options.queue; + this.token = token; + this.state = 0; + this.websocket = null; + this.events = {}; + this.user = null; + this.alreadySentData = false; + this.serverCreateListener = {}; + this.typingIntervals = {}; + this.email = "abc"; + this.password = "abc"; + + /* + State values: + 0 - idle + 1 - logging in + 2 - logged in + 3 - ready + 4 - disconnected + */ + + this.userCache = []; + this.channelCache = []; + this.serverCache = []; + this.pmChannelCache = []; + this.readyTime = null; + this.checkingQueue = {}; + this.userTypingListener = {}; + this.queue = {}; + + this.__idleTime = null; + this.__gameId = null; + } + + Client.prototype.sendPacket = function sendPacket(JSONObject) { + if (this.websocket.readyState === 1) { + this.websocket.send(JSON.stringify(JSONObject)); + } + }; + + //def debug + + Client.prototype.debug = function debug(message) { + this.trigger("debug", message); + }; + + Client.prototype.on = function on(event, fn) { + this.events[event] = fn; + }; + + Client.prototype.off = function off(event) { + this.events[event] = null; + }; + + Client.prototype.keepAlive = function keepAlive() { + this.debug("keep alive triggered"); + this.sendPacket({ + op: 1, + d: Date.now() + }); + }; + + //def trigger + + Client.prototype.trigger = function trigger(event) { + var args = []; + for (var arg in arguments) { + args.push(arguments[arg]); + } + var evt = this.events[event]; + if (evt) { + evt.apply(this, args.slice(1)); + } + }; + + //def login + + Client.prototype.login = function login() { + var email = arguments.length <= 0 || arguments[0] === undefined ? "foo@bar.com" : arguments[0]; + var password = arguments.length <= 1 || arguments[1] === undefined ? "pass1234" : arguments[1]; + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, token) {} : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + if (self.state === 0 || self.state === 4) { + + self.state = 1; //set the state to logging in + + self.email = email; + self.password = password; + + request.post(Endpoints.LOGIN).send({ + email: email, + password: password + }).end(function (err, res) { + + if (err) { + self.state = 4; //set state to disconnected + self.trigger("disconnected"); + if (self.websocket) { + self.websocket.close(); } - self.serverCache[self.serverCache.indexOf(server)] = srv; - - }*/if(self.serverCreateListener[data.id]){var cbs=self.serverCreateListener[data.id];cbs[0](server); //promise then callback -cbs[1](null,server); //legacy callback -self.serverCreateListener[data.id] = null;}self.trigger("serverCreate",server);break;case "CHANNEL_CREATE":var channel=self.getChannel("id",data.id);if(!channel){var chann;if(data.is_private){chann = self.addPMChannel(data);}else {chann = self.addChannel(data,data.guild_id);}var srv=self.getServer("id",data.guild_id);if(srv){srv.addChannel(chann);}self.trigger("channelCreate",chann);}break;case "GUILD_MEMBER_ADD":var server=self.getServer("id",data.guild_id);if(server){var user=self.addUser(data.user); //if for whatever reason it doesn't exist.. -self.trigger("serverNewMember",server.addMember(user,data.roles),server);}break;case "GUILD_MEMBER_REMOVE":var server=self.getServer("id",data.guild_id);if(server){var user=self.addUser(data.user); //if for whatever reason it doesn't exist.. -server.removeMember("id",user.id);self.trigger("serverRemoveMember",user,server);}break;case "USER_UPDATE":if(self.user && data.id === self.user.id){var newUser=new User(data); //not actually adding to the cache -self.trigger("userUpdate",newUser,self.user);if(~self.userCache.indexOf(self.user)){self.userCache[self.userCache.indexOf(self.user)] = newUser;}self.user = newUser;}break;case "PRESENCE_UPDATE":var userInCache=self.getUser("id",data.user.id);if(userInCache){ //user exists -data.user.username = data.user.username || userInCache.username;data.user.id = data.user.id || userInCache.id;data.user.discriminator = data.user.discriminator || userInCache.discriminator;data.user.avatar = data.user.avatar || userInCache.avatar;var presenceUser=new User(data.user);if(presenceUser.equalsStrict(userInCache)){ //they're exactly the same, an actual presence update -self.trigger("presence",{user:userInCache,oldStatus:userInCache.status,status:data.status,server:self.getServer("id",data.guild_id),gameId:data.game_id});userInCache.status = data.status;userInCache.gameId = data.game_id;}else { //one of their details changed. -self.userCache[self.userCache.indexOf(userInCache)] = presenceUser;self.trigger("userUpdate",userInCache,presenceUser);}}break;case "CHANNEL_UPDATE":var channelInCache=self.getChannel("id",data.id),serverInCache=self.getServer("id",data.guild_id);if(channelInCache && serverInCache){var newChann=new Channel(data,serverInCache);newChann.messages = channelInCache.messages;self.trigger("channelUpdate",channelInCache,newChann);self.channelCache[self.channelCache.indexOf(channelInCache)] = newChann;}break;case "TYPING_START":var userInCache=self.getUser("id",data.user_id);var channelInCache=self.getChannel("id",data.channel_id);if(!self.userTypingListener[data.user_id] || self.userTypingListener[data.user_id] === -1){self.trigger("startTyping",userInCache,channelInCache);}self.userTypingListener[data.user_id] = Date.now();setTimeout(function(){if(self.userTypingListener[data.user_id] === -1){return;}if(Date.now() - self.userTypingListener[data.user_id] > 6000){ // stopped typing -self.trigger("stopTyping",userInCache,channelInCache);self.userTypingListener[data.user_id] = -1;}},6000);break;case "GUILD_ROLE_DELETE":var server=self.getServer("id",data.guild_id);var role=server.getRole(data.role_id);self.trigger("serverRoleDelete",server,role);server.removeRole(role.id);break;case "GUILD_ROLE_UPDATE":var server=self.getServer("id",data.guild_id);var role=server.getRole(data.role.id);var newRole=server.updateRole(data.role);self.trigger("serverRoleUpdate",server,role,newRole);break;default:self.debug("received unknown packet");self.trigger("unknown",dat);break;}};}; //def addUser -Client.prototype.addUser = function addUser(data){if(!this.getUser("id",data.id)){this.userCache.push(new User(data));}return this.getUser("id",data.id);}; //def addChannel -Client.prototype.addChannel = function addChannel(data,serverId){if(!this.getChannel("id",data.id)){this.channelCache.push(new Channel(data,this.getServer("id",serverId)));}return this.getChannel("id",data.id);};Client.prototype.addPMChannel = function addPMChannel(data){if(!this.getPMChannel("id",data.id)){this.pmChannelCache.push(new PMChannel(data,this));}return this.getPMChannel("id",data.id);};Client.prototype.setTopic = function setTopic(channel,topic){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err){}:arguments[2];var self=this;return new Promise(function(resolve,reject){self.resolveDestination(channel).then(next)["catch"](error);function error(e){callback(e);reject(e);}function next(destination){var asChan=self.getChannel("id",destination);request.patch(Endpoints.CHANNELS + "/" + destination).set("authorization",self.token).send({name:asChan.name,position:0,topic:topic}).end(function(err,res){if(err){error(err);}else {asChan.topic = res.body.topic;resolve();callback();}});}});}; //def addServer -Client.prototype.addServer = function addServer(data){var self=this;var server=this.getServer("id",data.id);if(data.unavailable){self.trigger("unavailable",data);self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached.");return;}if(!server){server = new Server(data,this);this.serverCache.push(server);if(data.channels){for(var _iterator8=data.channels,_isArray8=Array.isArray(_iterator8),_i8=0,_iterator8=_isArray8?_iterator8:_iterator8[Symbol.iterator]();;) {var _ref8;if(_isArray8){if(_i8 >= _iterator8.length)break;_ref8 = _iterator8[_i8++];}else {_i8 = _iterator8.next();if(_i8.done)break;_ref8 = _i8.value;}var channel=_ref8;server.channels.push(this.addChannel(channel,server.id));}}}for(var _iterator9=data.presences,_isArray9=Array.isArray(_iterator9),_i9=0,_iterator9=_isArray9?_iterator9:_iterator9[Symbol.iterator]();;) {var _ref9;if(_isArray9){if(_i9 >= _iterator9.length)break;_ref9 = _iterator9[_i9++];}else {_i9 = _iterator9.next();if(_i9.done)break;_ref9 = _i9.value;}var presence=_ref9;var user=self.getUser("id",presence.user.id);user.status = presence.status;user.gameId = presence.game_id;}return server;}; //def getUser -Client.prototype.getUser = function getUser(key,value){for(var _iterator10=this.userCache,_isArray10=Array.isArray(_iterator10),_i10=0,_iterator10=_isArray10?_iterator10:_iterator10[Symbol.iterator]();;) {var _ref10;if(_isArray10){if(_i10 >= _iterator10.length)break;_ref10 = _iterator10[_i10++];}else {_i10 = _iterator10.next();if(_i10.done)break;_ref10 = _i10.value;}var user=_ref10;if(user[key] === value){return user;}}return null;}; //def getChannel -Client.prototype.getChannel = function getChannel(key,value){for(var _iterator11=this.channelCache,_isArray11=Array.isArray(_iterator11),_i11=0,_iterator11=_isArray11?_iterator11:_iterator11[Symbol.iterator]();;) {var _ref11;if(_isArray11){if(_i11 >= _iterator11.length)break;_ref11 = _iterator11[_i11++];}else {_i11 = _iterator11.next();if(_i11.done)break;_ref11 = _i11.value;}var channel=_ref11;if(channel[key] === value){return channel;}}return this.getPMChannel(key,value); //might be a PM -};Client.prototype.getPMChannel = function getPMChannel(key,value){for(var _iterator12=this.pmChannelCache,_isArray12=Array.isArray(_iterator12),_i12=0,_iterator12=_isArray12?_iterator12:_iterator12[Symbol.iterator]();;) {var _ref12;if(_isArray12){if(_i12 >= _iterator12.length)break;_ref12 = _iterator12[_i12++];}else {_i12 = _iterator12.next();if(_i12.done)break;_ref12 = _i12.value;}var channel=_ref12;if(channel[key] === value){return channel;}}return null;}; //def getServer -Client.prototype.getServer = function getServer(key,value){for(var _iterator13=this.serverCache,_isArray13=Array.isArray(_iterator13),_i13=0,_iterator13=_isArray13?_iterator13:_iterator13[Symbol.iterator]();;) {var _ref13;if(_isArray13){if(_i13 >= _iterator13.length)break;_ref13 = _iterator13[_i13++];}else {_i13 = _iterator13.next();if(_i13.done)break;_ref13 = _i13.value;}var server=_ref13;if(server[key] === value){return server;}}return null;}; //def trySendConnData -Client.prototype.trySendConnData = function trySendConnData(){if(this.token && !this.alreadySentData){this.alreadySentData = true;var data={op:2,d:{token:this.token,v:3,properties:{"$os":"discord.js","$browser":"discord.js","$device":"discord.js","$referrer":"","$referring_domain":""}}};this.websocket.send(JSON.stringify(data));}};Client.prototype.resolveServerID = function resolveServerID(resource){if(resource instanceof Server){return resource.id;}else if(!isNaN(resource) && resource.length && resource.length === 17){return resource;}};Client.prototype.resolveDestination = function resolveDestination(destination){var channId=false;var self=this;return new Promise(function(resolve,reject){if(destination instanceof Server){channId = destination.id; //general is the same as server id -}else if(destination instanceof Channel){channId = destination.id;}else if(destination instanceof Message){channId = destination.channel.id;}else if(destination instanceof PMChannel){channId = destination.id;}else if(destination instanceof User){ //check if we have a PM -for(var _iterator14=self.pmChannelCache,_isArray14=Array.isArray(_iterator14),_i14=0,_iterator14=_isArray14?_iterator14:_iterator14[Symbol.iterator]();;) {var _ref14;if(_isArray14){if(_i14 >= _iterator14.length)break;_ref14 = _iterator14[_i14++];}else {_i14 = _iterator14.next();if(_i14.done)break;_ref14 = _i14.value;}var pmc=_ref14;if(pmc.user && pmc.user.equals(destination)){resolve(pmc.id);return;}} //we don't, at this point we're late -self.startPM(destination).then(function(pmc){resolve(pmc.id);})["catch"](reject);}else {channId = destination;}if(channId)resolve(channId);else reject();});};Client.prototype._sendMessage = function _sendMessage(destination,content,tts,mentions){var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization",self.token).send({content:content,mentions:mentions,tts:tts}).end(function(err,res){if(err){reject(err);}else {var data=res.body;var mentions=[];data.mentions = data.mentions || []; //for some reason this was not defined at some point? -for(var _iterator15=data.mentions,_isArray15=Array.isArray(_iterator15),_i15=0,_iterator15=_isArray15?_iterator15:_iterator15[Symbol.iterator]();;) {var _ref15;if(_isArray15){if(_i15 >= _iterator15.length)break;_ref15 = _iterator15[_i15++];}else {_i15 = _iterator15.next();if(_i15.done)break;_ref15 = _i15.value;}var mention=_ref15;mentions.push(self.addUser(mention));}var channel=self.getChannel("id",data.channel_id);if(channel){var msg=channel.addMessage(new Message(data,channel,mentions,self.addUser(data.author)));resolve(msg);}}});});};Client.prototype._sendFile = function _sendFile(destination,attachment){var attachmentName=arguments.length <= 2 || arguments[2] === undefined?"DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png":arguments[2];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization",self.token).attach("file",attachment,attachmentName).end(function(err,res){if(err){reject(err);}else {var chann=self.getChannel("id",destination);if(chann){var msg=chann.addMessage(new Message(res.body,chann,[],self.user));resolve(msg);}}});});};Client.prototype._updateMessage = function _updateMessage(message,content){var self=this;return new Promise(function(resolve,reject){request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization",self.token).send({content:content,mentions:[]}).end(function(err,res){if(err){reject(err);}else {var msg=new Message(res.body,message.channel,message.mentions,message.sender);resolve(msg);message.channel.messages[message.channel.messages.indexOf(message)] = msg;}});});};Client.prototype.getGateway = function getGateway(){var self=this;return new Promise(function(resolve,reject){request.get(Endpoints.API + "/gateway").set("authorization",self.token).end(function(err,res){if(err){reject(err);}else {resolve(res.body.url);}});});};Client.prototype.setStatusIdle = function setStatusIdle(){this.setStatus("idle");};Client.prototype.setStatusOnline = function setStatusOnline(){this.setStatus("online");};Client.prototype.setStatusActive = function setStatusActive(){this.setStatusOnline();};Client.prototype.setStatusHere = function setStatusHere(){this.setStatusOnline();};Client.prototype.setStatusAway = function setStatusAway(){this.setStatusIdle();};Client.prototype.startTyping = function startTyping(chann,stopTypeTime){var self=this;this.resolveDestination(chann).then(next);function next(channel){if(self.typingIntervals[channel]){return;}var fn=function fn(){request.post(Endpoints.CHANNELS + "/" + channel + "/typing").set("authorization",self.token).end();};fn();var interval=setInterval(fn,3000);self.typingIntervals[channel] = interval;if(stopTypeTime){setTimeout(function(){self.stopTyping(channel);},stopTypeTime);}}};Client.prototype.stopTyping = function stopTyping(chann){var self=this;this.resolveDestination(chann).then(next);function next(channel){if(!self.typingIntervals[channel]){return;}clearInterval(self.typingIntervals[channel]);delete self.typingIntervals[channel];}};Client.prototype.setStatus = function setStatus(stat){var idleTime=stat === "online"?null:Date.now();this.__idleTime = idleTime;this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}));};Client.prototype.setPlayingGame = function setPlayingGame(id){if(id instanceof String || typeof id === "string"){ // working on names -var gid=id.trim().toUpperCase();id = null;for(var _iterator16=gameMap,_isArray16=Array.isArray(_iterator16),_i16=0,_iterator16=_isArray16?_iterator16:_iterator16[Symbol.iterator]();;) {var _ref16;if(_isArray16){if(_i16 >= _iterator16.length)break;_ref16 = _iterator16[_i16++];}else {_i16 = _iterator16.next();if(_i16.done)break;_ref16 = _i16.value;}var game=_ref16;if(game.name.trim().toUpperCase() === gid){id = game.id;break;}}}this.__gameId = id;this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}));};Client.prototype.playGame = function playGame(id){this.setPlayingGame(id);};Client.prototype.playingGame = function playingGame(id){this.setPlayingGame(id);};_createClass(Client,[{key:"uptime",get:function get(){return this.readyTime?Date.now() - this.readyTime:null;}},{key:"ready",get:function get(){return this.state === 3;}},{key:"servers",get:function get(){return this.serverCache;}},{key:"channels",get:function get(){return this.channelCache;}},{key:"users",get:function get(){return this.userCache;}},{key:"PMChannels",get:function get(){return this.pmChannelCache;}},{key:"messages",get:function get(){var msgs=[];for(var _iterator17=this.channelCache,_isArray17=Array.isArray(_iterator17),_i17=0,_iterator17=_isArray17?_iterator17:_iterator17[Symbol.iterator]();;) {var _ref17;if(_isArray17){if(_i17 >= _iterator17.length)break;_ref17 = _iterator17[_i17++];}else {_i17 = _iterator17.next();if(_i17.done)break;_ref17 = _i17.value;}var channel=_ref17;msgs = msgs.concat(channel.messages);}return msgs;}}]);return Client;})();module.exports = Client; + callback(err); + reject(err); + } else { + self.state = 2; //set state to logged in (not yet ready) + self.token = res.body.token; //set our token + + self.getGateway().then(function (url) { + self.createws(url); + callback(null, self.token); + resolve(self.token); + })["catch"](function (err) { + callback(err); + reject(err); + }); + } + }); + } else { + reject(new Error("Client already logging in or ready")); + } + }); + }; + + Client.prototype.logout = function logout() { + var callback = arguments.length <= 0 || arguments[0] === undefined ? function (err) {} : arguments[0]; + + var self = this; + + return new Promise(function (resolve, reject) { + + request.post(Endpoints.LOGOUT).set("authorization", self.token).end(function (err, res) { + + if (err) { + callback(err); + reject(err); + } else { + self.websocket.close(); + self.state = 4; + callback(); + resolve(); + } + }); + }); + }; + + Client.prototype.createServer = function createServer(name, region) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, server) {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + + request.post(Endpoints.SERVERS).set("authorization", self.token).send({ + name: name, + region: region + }).end(function (err, res) { + if (err) { + callback(err); + reject(err); + } else { + // potentially redundant in future + // creating here does NOT give us the channels of the server + // so we must wait for the guild_create event. + self.serverCreateListener[res.body.id] = [resolve, callback]; + /*var srv = self.addServer(res.body); + callback(null, srv); + resolve(srv);*/ + } + }); + }); + }; + + Client.prototype.createChannel = function createChannel(server, channelName, channelType) { + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, chann) {} : arguments[3]; + + var self = this; + + return new Promise(function (resolve, reject) { + + request.post(Endpoints.SERVERS + "/" + self.resolveServerID(server) + "/channels").set("authorization", self.token).send({ + name: channelName, + type: channelType + }).end(function (err, res) { + + if (err) { + callback(err); + reject(err); + } else { + var server = self.getServer("id", res.body.guild_id); + var chann = self.addChannel(res.body, res.body.guild_id); + server.addChannel(chann); + callback(null, chann); + resolve(chann); + } + }); + }); + }; + + Client.prototype.leaveServer = function leaveServer(server) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, server) {} : arguments[1]; + + var self = this; + + return new Promise(function (resolve, reject) { + + request.del(Endpoints.SERVERS + "/" + self.resolveServerID(server)).set("authorization", self.token).end(function (err, res) { + + if (err) { + callback(err); + reject(err); + } else { + self.serverCache.splice(self.serverCache.indexOf(server), 1); + callback(null); + resolve(); + } + }); + }); + }; + + Client.prototype.createInvite = function createInvite(serverOrChannel, options) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, invite) {} : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + + var destination; + + if (serverOrChannel instanceof Server) { + destination = serverOrChannel.id; + } else if (serverOrChannel instanceof Channel) { + destination = serverOrChannel.id; + } else { + destination = serverOrChannel; + } + + options = options || {}; + options.max_age = options.maxAge || 0; + options.max_uses = options.maxUses || 0; + options.temporary = options.temporary || false; + options.xkcdpass = options.xkcd || false; + + request.post(Endpoints.CHANNELS + "/" + destination + "/invites").set("authorization", self.token).send(options).end(function (err, res) { + if (err) { + callback(err); + reject(err); + } else { + var inv = new Invite(res.body, self); + callback(null, inv); + resolve(inv); + } + }); + }); + }; + + Client.prototype.startPM = function startPM(user) { + + var self = this; + + return new Promise(function (resolve, reject) { + var userId = user; + if (user instanceof User) { + userId = user.id; + } + request.post(Endpoints.USERS + "/" + self.user.id + "/channels").set("authorization", self.token).send({ + recipient_id: userId + }).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(self.addPMChannel(res.body)); + } + }); + }); + }; + + Client.prototype.reply = function reply(destination, message, tts) { + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; + + var self = this; + + return new Promise(function (response, reject) { + + if (typeof tts === "function") { + // tts is a function, which means the developer wants this to be the callback + callback = tts; + tts = false; + } + + var user = destination.sender; + self.sendMessage(destination, message, tts, callback, user + ", ").then(response)["catch"](reject); + }); + }; + + Client.prototype.deleteMessage = function deleteMessage(message, timeout) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, msg) {} : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + if (timeout) { + setTimeout(remove, timeout); + } else { + remove(); + } + + function remove() { + request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).end(function (err, res) { + if (err) { + bad(); + } else { + good(); + } + }); + } + + function good() { + callback(); + resolve(); + } + + function bad(err) { + callback(err); + reject(err); + } + }); + }; + + Client.prototype.updateMessage = function updateMessage(message, content) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, msg) {} : arguments[2]; + + var self = this; + + var prom = new Promise(function (resolve, reject) { + + content = content instanceof Array ? content.join("\n") : content; + + if (self.options.queue) { + if (!self.queue[message.channel.id]) { + self.queue[message.channel.id] = []; + } + self.queue[message.channel.id].push({ + action: "updateMessage", + message: message, + content: content, + then: good, + error: bad + }); + + self.checkQueue(message.channel.id); + } else { + self._updateMessage(message, content).then(good)["catch"](bad); + } + + function good(msg) { + prom.message = msg; + callback(null, msg); + resolve(msg); + } + + function bad(error) { + prom.error = error; + callback(error); + reject(error); + } + }); + + return prom; + }; + + Client.prototype.setUsername = function setUsername(newName) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; + + var self = this; + + return new Promise(function (resolve, reject) { + request.patch(Endpoints.API + "/users/@me").set("authorization", self.token).send({ + avatar: self.user.avatar, + email: self.email, + new_password: null, + password: self.password, + username: newName + }).end(function (err) { + callback(err); + if (err) reject(err);else resolve(); + }); + }); + }; + + Client.prototype.getChannelLogs = function getChannelLogs(channel) { + var amount = arguments.length <= 1 || arguments[1] === undefined ? 500 : arguments[1]; + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, logs) {} : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + + var channelID = channel; + if (channel instanceof Channel) { + channelID = channel.id; + } + + request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization", self.token).end(function (err, res) { + + if (err) { + callback(err); + reject(err); + } else { + var logs = []; + + var channel = self.getChannel("id", channelID); + + for (var _iterator = res.body, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + var message = _ref; + + var mentions = []; + for (var _iterator2 = message.mentions, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { + var _ref2; + + if (_isArray2) { + if (_i2 >= _iterator2.length) break; + _ref2 = _iterator2[_i2++]; + } else { + _i2 = _iterator2.next(); + if (_i2.done) break; + _ref2 = _i2.value; + } + + var mention = _ref2; + + mentions.push(self.addUser(mention)); + } + + var author = self.addUser(message.author); + + logs.push(new Message(message, channel, mentions, author)); + } + callback(null, logs); + resolve(logs); + } + }); + }); + }; + + Client.prototype.deleteChannel = function deleteChannel(channel) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; + + var self = this; + + return new Promise(function (resolve, reject) { + + var channelID = channel; + if (channel instanceof Channel) { + channelID = channel.id; + } + + request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization", self.token).end(function (err) { + if (err) { + callback(err); + reject(err); + } else { + callback(null); + resolve(); + } + }); + }); + }; + + Client.prototype.joinServer = function joinServer(invite) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, server) {} : arguments[1]; + + var self = this; + + return new Promise(function (resolve, reject) { + + var id = invite instanceof Invite ? invite.code : invite; + + request.post(Endpoints.API + "/invite/" + id).set("authorization", self.token).end(function (err, res) { + if (err) { + callback(err); + reject(err); + } else { + if (self.getServer("id", res.body.guild.id)) { + resolve(self.getServer("id", res.body.guild.id)); + } else { + self.serverCreateListener[res.body.guild.id] = [resolve, callback]; + } + } + }); + }); + }; + + Client.prototype.sendFile = function sendFile(destination, file) { + var fileName = arguments.length <= 2 || arguments[2] === undefined ? "image.png" : arguments[2]; + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; + + var self = this; + + var prom = new Promise(function (resolve, reject) { + + var fstream; + + if (typeof file === "string" || file instanceof String) { + fstream = fs.createReadStream(file); + fileName = file; + } else { + fstream = file; + } + + self.resolveDestination(destination).then(send)["catch"](bad); + + function send(destination) { + if (self.options.queue) { + //queue send file too + if (!self.queue[destination]) { + self.queue[destination] = []; + } + + self.queue[destination].push({ + action: "sendFile", + attachment: fstream, + attachmentName: fileName, + then: good, + error: bad + }); + + self.checkQueue(destination); + } else { + //not queue + self._sendFile(destination, fstream, fileName).then(good)["catch"](bad); + } + } + + function good(msg) { + prom.message = msg; + callback(null, msg); + resolve(msg); + } + + function bad(err) { + prom.error = err; + callback(err); + reject(err); + } + }); + + return prom; + }; + + Client.prototype.sendMessage = function sendMessage(destination, message, tts) { + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; + var premessage = arguments.length <= 4 || arguments[4] === undefined ? "" : arguments[4]; + + var self = this; + + var prom = new Promise(function (resolve, reject) { + + if (typeof tts === "function") { + // tts is a function, which means the developer wants this to be the callback + callback = tts; + tts = false; + } + + message = premessage + resolveMessage(message); + var mentions = resolveMentions(); + self.resolveDestination(destination).then(send)["catch"](error); + + function error(err) { + callback(err); + reject(err); + } + + function send(destination) { + if (self.options.queue) { + //we're QUEUEING messages, so sending them sequentially based on servers. + if (!self.queue[destination]) { + self.queue[destination] = []; + } + + self.queue[destination].push({ + action: "sendMessage", + content: message, + mentions: mentions, + tts: !!tts, //incase it's not a boolean + then: mgood, + error: mbad + }); + + self.checkQueue(destination); + } else { + self._sendMessage(destination, message, tts, mentions).then(mgood)["catch"](mbad); + } + } + + function mgood(msg) { + prom.message = msg; + callback(null, msg); + resolve(msg); + } + + function mbad(error) { + prom.error = error; + callback(error); + reject(error); + } + + function resolveMessage() { + var msg = message; + if (message instanceof Array) { + msg = message.join("\n"); + } + return msg; + } + + function resolveMentions() { + var _mentions = []; + for (var _iterator3 = message.match(/<@[^>]*>/g) || [], _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { + var _ref3; + + if (_isArray3) { + if (_i3 >= _iterator3.length) break; + _ref3 = _iterator3[_i3++]; + } else { + _i3 = _iterator3.next(); + if (_i3.done) break; + _ref3 = _i3.value; + } + + var mention = _ref3; + + _mentions.push(mention.substring(2, mention.length - 1)); + } + return _mentions; + } + }); + + return prom; + }; + + //def createws + + Client.prototype.createws = function createws(url) { + if (this.websocket) return false; + + var self = this; + + //good to go + this.websocket = new WebSocket(url); + + //open + this.websocket.onopen = function () { + self.trySendConnData(); //try connecting + }; + + //close + this.websocket.onclose = function () { + self.trigger("disconnected"); + }; + + //message + this.websocket.onmessage = function (e) { + + var dat = false, + data = {}; + + try { + dat = JSON.parse(e.data); + data = dat.d; + } catch (err) { + self.trigger("error", err, e); + return; + } + + self.trigger("raw", dat); + + //valid message + switch (dat.t) { + + case "READY": + self.debug("received ready packet"); + + self.user = self.addUser(data.user); + + for (var _iterator4 = data.guilds, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { + var _ref4; + + if (_isArray4) { + if (_i4 >= _iterator4.length) break; + _ref4 = _iterator4[_i4++]; + } else { + _i4 = _iterator4.next(); + if (_i4.done) break; + _ref4 = _i4.value; + } + + var _server = _ref4; + + var server = self.addServer(_server); + } + + for (var _iterator5 = data.private_channels, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { + var _ref5; + + if (_isArray5) { + if (_i5 >= _iterator5.length) break; + _ref5 = _iterator5[_i5++]; + } else { + _i5 = _iterator5.next(); + if (_i5.done) break; + _ref5 = _i5.value; + } + + var _pmc = _ref5; + + var pmc = self.addPMChannel(_pmc); + } + + self.trigger("ready"); + self.readyTime = Date.now(); + self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users."); + self.state = 3; + setInterval(function () { + self.keepAlive.apply(self); + }, data.heartbeat_interval); + + break; + case "MESSAGE_CREATE": + self.debug("received message"); + + var mentions = []; + data.mentions = data.mentions || []; //for some reason this was not defined at some point? + for (var _iterator6 = data.mentions, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { + var _ref6; + + if (_isArray6) { + if (_i6 >= _iterator6.length) break; + _ref6 = _iterator6[_i6++]; + } else { + _i6 = _iterator6.next(); + if (_i6.done) break; + _ref6 = _i6.value; + } + + var mention = _ref6; + + mentions.push(self.addUser(mention)); + } + + var channel = self.getChannel("id", data.channel_id); + if (channel) { + var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); + self.trigger("message", msg); + } + + break; + case "MESSAGE_DELETE": + self.debug("message deleted"); + + var channel = self.getChannel("id", data.channel_id); + var message = channel.getMessage("id", data.id); + if (message) { + self.trigger("messageDelete", channel, message); + channel.messages.splice(channel.messages.indexOf(message), 1); + } else { + //don't have the cache of that message ;( + self.trigger("messageDelete", channel); + } + break; + case "MESSAGE_UPDATE": + self.debug("message updated"); + + var channel = self.getChannel("id", data.channel_id); + var formerMessage = channel.getMessage("id", data.id); + + if (formerMessage) { + + //new message might be partial, so we need to fill it with whatever the old message was. + var info = {}; + + for (var key in formerMessage) { + info[key] = formerMessage[key]; + } + + for (var key in data) { + info[key] = data[key]; + } + + var mentions = []; + for (var _iterator7 = info.mentions, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) { + var _ref7; + + if (_isArray7) { + if (_i7 >= _iterator7.length) break; + _ref7 = _iterator7[_i7++]; + } else { + _i7 = _iterator7.next(); + if (_i7.done) break; + _ref7 = _i7.value; + } + + var mention = _ref7; + + mentions.push(self.addUser(mention)); + } + + var newMessage = new Message(info, channel, mentions, formerMessage.author); + + self.trigger("messageUpdate", newMessage, formerMessage); + + channel.messages[channel.messages.indexOf(formerMessage)] = newMessage; + } + + // message isn't in cache, and if it's a partial it could cause + // all hell to break loose... best to just act as if nothing happened + + break; + + case "GUILD_DELETE": + + var server = self.getServer("id", data.id); + + if (server) { + self.serverCache.splice(self.serverCache.indexOf(server), 1); + self.trigger("serverDelete", server); + } + + break; + + case "CHANNEL_DELETE": + + var channel = self.getChannel("id", data.id); + + if (channel) { + + var server = channel.server; + + if (server) { + + server.channels.splice(server.channels.indexOf(channel), 1); + } + + self.trigger("channelDelete", channel); + + self.serverCache.splice(self.serverCache.indexOf(channel), 1); + } + + break; + + case "GUILD_CREATE": + + var server = self.getServer("id", data.id); + + if (!server) { + //if server doesn't already exist because duh + server = self.addServer(data); + } /*else if(server.channels.length === 0){ + + var srv = new Server(data, self); + for(channel of data.channels){ + srv.channels.push(new Channel(channel, data.id)); + } + self.serverCache[self.serverCache.indexOf(server)] = srv; + + }*/ + + if (self.serverCreateListener[data.id]) { + var cbs = self.serverCreateListener[data.id]; + cbs[0](server); //promise then callback + cbs[1](null, server); //legacy callback + self.serverCreateListener[data.id] = null; + } + + self.trigger("serverCreate", server); + + break; + + case "CHANNEL_CREATE": + + var channel = self.getChannel("id", data.id); + + if (!channel) { + + var chann; + if (data.is_private) { + chann = self.addPMChannel(data); + } else { + chann = self.addChannel(data, data.guild_id); + } + var srv = self.getServer("id", data.guild_id); + if (srv) { + srv.addChannel(chann); + } + self.trigger("channelCreate", chann); + } + + break; + + case "GUILD_MEMBER_ADD": + + var server = self.getServer("id", data.guild_id); + + if (server) { + + var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. + + self.trigger("serverNewMember", server.addMember(user, data.roles), server); + } + + break; + + case "GUILD_MEMBER_REMOVE": + + var server = self.getServer("id", data.guild_id); + + if (server) { + + var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. + + server.removeMember("id", user.id); + + self.trigger("serverRemoveMember", user, server); + } + + break; + + case "USER_UPDATE": + + if (self.user && data.id === self.user.id) { + + var newUser = new User(data); //not actually adding to the cache + + self.trigger("userUpdate", newUser, self.user); + + if (~self.userCache.indexOf(self.user)) { + self.userCache[self.userCache.indexOf(self.user)] = newUser; + } + + self.user = newUser; + } + + break; + + case "PRESENCE_UPDATE": + + var userInCache = self.getUser("id", data.user.id); + + if (userInCache) { + //user exists + + data.user.username = data.user.username || userInCache.username; + data.user.id = data.user.id || userInCache.id; + data.user.discriminator = data.user.discriminator || userInCache.discriminator; + data.user.avatar = data.user.avatar || userInCache.avatar; + + var presenceUser = new User(data.user); + if (presenceUser.equalsStrict(userInCache)) { + //they're exactly the same, an actual presence update + self.trigger("presence", { + user: userInCache, + oldStatus: userInCache.status, + status: data.status, + server: self.getServer("id", data.guild_id), + gameId: data.game_id + }); + userInCache.status = data.status; + userInCache.gameId = data.game_id; + } else { + //one of their details changed. + self.userCache[self.userCache.indexOf(userInCache)] = presenceUser; + self.trigger("userUpdate", userInCache, presenceUser); + } + } + + break; + + case "CHANNEL_UPDATE": + + var channelInCache = self.getChannel("id", data.id), + serverInCache = self.getServer("id", data.guild_id); + + if (channelInCache && serverInCache) { + + var newChann = new Channel(data, serverInCache); + newChann.messages = channelInCache.messages; + + self.trigger("channelUpdate", channelInCache, newChann); + + self.channelCache[self.channelCache.indexOf(channelInCache)] = newChann; + } + + break; + + case "TYPING_START": + + var userInCache = self.getUser("id", data.user_id); + var channelInCache = self.getChannel("id", data.channel_id); + + if (!self.userTypingListener[data.user_id] || self.userTypingListener[data.user_id] === -1) { + self.trigger("startTyping", userInCache, channelInCache); + } + + self.userTypingListener[data.user_id] = Date.now(); + + setTimeout(function () { + if (self.userTypingListener[data.user_id] === -1) { + return; + } + if (Date.now() - self.userTypingListener[data.user_id] > 6000) { + // stopped typing + self.trigger("stopTyping", userInCache, channelInCache); + self.userTypingListener[data.user_id] = -1; + } + }, 6000); + + break; + + case "GUILD_ROLE_DELETE": + + var server = self.getServer("id", data.guild_id); + var role = server.getRole(data.role_id); + + self.trigger("serverRoleDelete", server, role); + + server.removeRole(role.id); + + break; + + case "GUILD_ROLE_UPDATE": + + var server = self.getServer("id", data.guild_id); + var role = server.getRole(data.role.id); + var newRole = server.updateRole(data.role); + + self.trigger("serverRoleUpdate", server, role, newRole); + + break; + + default: + self.debug("received unknown packet"); + self.trigger("unknown", dat); + break; + + } + }; + }; + + //def addUser + + Client.prototype.addUser = function addUser(data) { + if (!this.getUser("id", data.id)) { + this.userCache.push(new User(data)); + } + return this.getUser("id", data.id); + }; + + //def addChannel + + Client.prototype.addChannel = function addChannel(data, serverId) { + if (!this.getChannel("id", data.id)) { + this.channelCache.push(new Channel(data, this.getServer("id", serverId))); + } + return this.getChannel("id", data.id); + }; + + Client.prototype.addPMChannel = function addPMChannel(data) { + if (!this.getPMChannel("id", data.id)) { + this.pmChannelCache.push(new PMChannel(data, this)); + } + return this.getPMChannel("id", data.id); + }; + + Client.prototype.setTopic = function setTopic(channel, topic) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + + self.resolveDestination(channel).then(next)["catch"](error); + + function error(e) { + callback(e); + reject(e); + } + + function next(destination) { + + var asChan = self.getChannel("id", destination); + + request.patch(Endpoints.CHANNELS + "/" + destination).set("authorization", self.token).send({ + name: asChan.name, + position: 0, + topic: topic + }).end(function (err, res) { + if (err) { + error(err); + } else { + asChan.topic = res.body.topic; + resolve(); + callback(); + } + }); + } + }); + }; + + //def addServer + + Client.prototype.addServer = function addServer(data) { + + var self = this; + var server = this.getServer("id", data.id); + + if (data.unavailable) { + self.trigger("unavailable", data); + self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached."); + return; + } + + if (!server) { + server = new Server(data, this); + this.serverCache.push(server); + if (data.channels) { + for (var _iterator8 = data.channels, _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) { + var _ref8; + + if (_isArray8) { + if (_i8 >= _iterator8.length) break; + _ref8 = _iterator8[_i8++]; + } else { + _i8 = _iterator8.next(); + if (_i8.done) break; + _ref8 = _i8.value; + } + + var channel = _ref8; + + server.channels.push(this.addChannel(channel, server.id)); + } + } + } + + for (var _iterator9 = data.presences, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) { + var _ref9; + + if (_isArray9) { + if (_i9 >= _iterator9.length) break; + _ref9 = _iterator9[_i9++]; + } else { + _i9 = _iterator9.next(); + if (_i9.done) break; + _ref9 = _i9.value; + } + + var presence = _ref9; + + var user = self.getUser("id", presence.user.id); + user.status = presence.status; + user.gameId = presence.game_id; + } + + return server; + }; + + //def getUser + + Client.prototype.getUser = function getUser(key, value) { + for (var _iterator10 = this.userCache, _isArray10 = Array.isArray(_iterator10), _i10 = 0, _iterator10 = _isArray10 ? _iterator10 : _iterator10[Symbol.iterator]();;) { + var _ref10; + + if (_isArray10) { + if (_i10 >= _iterator10.length) break; + _ref10 = _iterator10[_i10++]; + } else { + _i10 = _iterator10.next(); + if (_i10.done) break; + _ref10 = _i10.value; + } + + var user = _ref10; + + if (user[key] === value) { + return user; + } + } + return null; + }; + + //def getChannel + + Client.prototype.getChannel = function getChannel(key, value) { + for (var _iterator11 = this.channelCache, _isArray11 = Array.isArray(_iterator11), _i11 = 0, _iterator11 = _isArray11 ? _iterator11 : _iterator11[Symbol.iterator]();;) { + var _ref11; + + if (_isArray11) { + if (_i11 >= _iterator11.length) break; + _ref11 = _iterator11[_i11++]; + } else { + _i11 = _iterator11.next(); + if (_i11.done) break; + _ref11 = _i11.value; + } + + var channel = _ref11; + + if (channel[key] === value) { + return channel; + } + } + return this.getPMChannel(key, value); //might be a PM + }; + + Client.prototype.getPMChannel = function getPMChannel(key, value) { + for (var _iterator12 = this.pmChannelCache, _isArray12 = Array.isArray(_iterator12), _i12 = 0, _iterator12 = _isArray12 ? _iterator12 : _iterator12[Symbol.iterator]();;) { + var _ref12; + + if (_isArray12) { + if (_i12 >= _iterator12.length) break; + _ref12 = _iterator12[_i12++]; + } else { + _i12 = _iterator12.next(); + if (_i12.done) break; + _ref12 = _i12.value; + } + + var channel = _ref12; + + if (channel[key] === value) { + return channel; + } + } + return null; + }; + + //def getServer + + Client.prototype.getServer = function getServer(key, value) { + for (var _iterator13 = this.serverCache, _isArray13 = Array.isArray(_iterator13), _i13 = 0, _iterator13 = _isArray13 ? _iterator13 : _iterator13[Symbol.iterator]();;) { + var _ref13; + + if (_isArray13) { + if (_i13 >= _iterator13.length) break; + _ref13 = _iterator13[_i13++]; + } else { + _i13 = _iterator13.next(); + if (_i13.done) break; + _ref13 = _i13.value; + } + + var server = _ref13; + + if (server[key] === value) { + return server; + } + } + return null; + }; + + //def trySendConnData + + Client.prototype.trySendConnData = function trySendConnData() { + + if (this.token && !this.alreadySentData) { + + this.alreadySentData = true; + + var data = { + op: 2, + d: { + token: this.token, + v: 3, + properties: { + "$os": "discord.js", + "$browser": "discord.js", + "$device": "discord.js", + "$referrer": "", + "$referring_domain": "" + } + } + }; + this.websocket.send(JSON.stringify(data)); + } + }; + + Client.prototype.resolveServerID = function resolveServerID(resource) { + + if (resource instanceof Server) { + return resource.id; + } else if (!isNaN(resource) && resource.length && resource.length === 17) { + return resource; + } + }; + + Client.prototype.resolveDestination = function resolveDestination(destination) { + var channId = false; + var self = this; + + return new Promise(function (resolve, reject) { + if (destination instanceof Server) { + channId = destination.id; //general is the same as server id + } else if (destination instanceof Channel) { + channId = destination.id; + } else if (destination instanceof Message) { + channId = destination.channel.id; + } else if (destination instanceof PMChannel) { + channId = destination.id; + } else if (destination instanceof User) { + + //check if we have a PM + for (var _iterator14 = self.pmChannelCache, _isArray14 = Array.isArray(_iterator14), _i14 = 0, _iterator14 = _isArray14 ? _iterator14 : _iterator14[Symbol.iterator]();;) { + var _ref14; + + if (_isArray14) { + if (_i14 >= _iterator14.length) break; + _ref14 = _iterator14[_i14++]; + } else { + _i14 = _iterator14.next(); + if (_i14.done) break; + _ref14 = _i14.value; + } + + var pmc = _ref14; + + if (pmc.user && pmc.user.equals(destination)) { + resolve(pmc.id); + return; + } + } + + //we don't, at this point we're late + self.startPM(destination).then(function (pmc) { + resolve(pmc.id); + })["catch"](reject); + } else { + channId = destination; + } + if (channId) resolve(channId);else reject(); + }); + }; + + Client.prototype._sendMessage = function _sendMessage(destination, content, tts, mentions) { + + var self = this; + + return new Promise(function (resolve, reject) { + request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).send({ + content: content, + mentions: mentions, + tts: tts + }).end(function (err, res) { + + if (err) { + reject(err); + } else { + var data = res.body; + + var mentions = []; + + data.mentions = data.mentions || []; //for some reason this was not defined at some point? + + for (var _iterator15 = data.mentions, _isArray15 = Array.isArray(_iterator15), _i15 = 0, _iterator15 = _isArray15 ? _iterator15 : _iterator15[Symbol.iterator]();;) { + var _ref15; + + if (_isArray15) { + if (_i15 >= _iterator15.length) break; + _ref15 = _iterator15[_i15++]; + } else { + _i15 = _iterator15.next(); + if (_i15.done) break; + _ref15 = _i15.value; + } + + var mention = _ref15; + + mentions.push(self.addUser(mention)); + } + + var channel = self.getChannel("id", data.channel_id); + if (channel) { + var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); + resolve(msg); + } + } + }); + }); + }; + + Client.prototype._sendFile = function _sendFile(destination, attachment) { + var attachmentName = arguments.length <= 2 || arguments[2] === undefined ? "DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png" : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).attach("file", attachment, attachmentName).end(function (err, res) { + + if (err) { + reject(err); + } else { + + var chann = self.getChannel("id", destination); + if (chann) { + var msg = chann.addMessage(new Message(res.body, chann, [], self.user)); + resolve(msg); + } + } + }); + }); + }; + + Client.prototype._updateMessage = function _updateMessage(message, content) { + var self = this; + return new Promise(function (resolve, reject) { + request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).send({ + content: content, + mentions: [] + }).end(function (err, res) { + if (err) { + reject(err); + } else { + var msg = new Message(res.body, message.channel, message.mentions, message.sender); + resolve(msg); + message.channel.messages[message.channel.messages.indexOf(message)] = msg; + } + }); + }); + }; + + Client.prototype.getGateway = function getGateway() { + var self = this; + return new Promise(function (resolve, reject) { + request.get(Endpoints.API + "/gateway").set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(res.body.url); + } + }); + }); + }; + + Client.prototype.setStatusIdle = function setStatusIdle() { + this.setStatus("idle"); + }; + + Client.prototype.setStatusOnline = function setStatusOnline() { + this.setStatus("online"); + }; + + Client.prototype.setStatusActive = function setStatusActive() { + this.setStatusOnline(); + }; + + Client.prototype.setStatusHere = function setStatusHere() { + this.setStatusOnline(); + }; + + Client.prototype.setStatusAway = function setStatusAway() { + this.setStatusIdle(); + }; + + Client.prototype.startTyping = function startTyping(chann, stopTypeTime) { + var self = this; + + this.resolveDestination(chann).then(next); + + function next(channel) { + if (self.typingIntervals[channel]) { + return; + } + + var fn = function fn() { + request.post(Endpoints.CHANNELS + "/" + channel + "/typing").set("authorization", self.token).end(); + }; + + fn(); + + var interval = setInterval(fn, 3000); + + self.typingIntervals[channel] = interval; + + if (stopTypeTime) { + setTimeout(function () { + self.stopTyping(channel); + }, stopTypeTime); + } + } + }; + + Client.prototype.stopTyping = function stopTyping(chann) { + var self = this; + + this.resolveDestination(chann).then(next); + + function next(channel) { + if (!self.typingIntervals[channel]) { + return; + } + + clearInterval(self.typingIntervals[channel]); + + delete self.typingIntervals[channel]; + } + }; + + Client.prototype.setStatus = function setStatus(stat) { + + var idleTime = stat === "online" ? null : Date.now(); + + this.__idleTime = idleTime; + + this.websocket.send(JSON.stringify({ + op: 3, + d: { + idle_since: this.__idleTime, + game_id: this.__gameId + } + })); + }; + + Client.prototype.setPlayingGame = function setPlayingGame(id) { + + if (id instanceof String || typeof id === "string") { + + // working on names + var gid = id.trim().toUpperCase(); + + id = null; + + for (var _iterator16 = gameMap, _isArray16 = Array.isArray(_iterator16), _i16 = 0, _iterator16 = _isArray16 ? _iterator16 : _iterator16[Symbol.iterator]();;) { + var _ref16; + + if (_isArray16) { + if (_i16 >= _iterator16.length) break; + _ref16 = _iterator16[_i16++]; + } else { + _i16 = _iterator16.next(); + if (_i16.done) break; + _ref16 = _i16.value; + } + + var game = _ref16; + + if (game.name.trim().toUpperCase() === gid) { + + id = game.id; + break; + } + } + } + + this.__gameId = id; + + this.websocket.send(JSON.stringify({ + op: 3, + d: { + idle_since: this.__idleTime, + game_id: this.__gameId + } + })); + }; + + Client.prototype.playGame = function playGame(id) { + this.setPlayingGame(id); + }; + + Client.prototype.playingGame = function playingGame(id) { + + this.setPlayingGame(id); + }; + + _createClass(Client, [{ + key: "uptime", + get: function get() { + + return this.readyTime ? Date.now() - this.readyTime : null; + } + }, { + key: "ready", + get: function get() { + return this.state === 3; + } + }, { + key: "servers", + get: function get() { + return this.serverCache; + } + }, { + key: "channels", + get: function get() { + return this.channelCache; + } + }, { + key: "users", + get: function get() { + return this.userCache; + } + }, { + key: "PMChannels", + get: function get() { + return this.pmChannelCache; + } + }, { + key: "messages", + get: function get() { + + var msgs = []; + for (var _iterator17 = this.channelCache, _isArray17 = Array.isArray(_iterator17), _i17 = 0, _iterator17 = _isArray17 ? _iterator17 : _iterator17[Symbol.iterator]();;) { + var _ref17; + + if (_isArray17) { + if (_i17 >= _iterator17.length) break; + _ref17 = _iterator17[_i17++]; + } else { + _i17 = _iterator17.next(); + if (_i17.done) break; + _ref17 = _i17.value; + } + + var channel = _ref17; + + msgs = msgs.concat(channel.messages); + } + return msgs; + } + }]); + + return Client; +})(); + +module.exports = Client; \ No newline at end of file diff --git a/lib/Endpoints.js b/lib/Endpoints.js index 60cd7925c..271b465eb 100644 --- a/lib/Endpoints.js +++ b/lib/Endpoints.js @@ -1 +1,13 @@ -"use strict";exports.BASE_DOMAIN = "discordapp.com";exports.BASE = "https://" + exports.BASE_DOMAIN;exports.WEBSOCKET_HUB = "wss://" + exports.BASE_DOMAIN + "/hub";exports.API = exports.BASE + "/api";exports.AUTH = exports.API + "/auth";exports.LOGIN = exports.AUTH + "/login";exports.LOGOUT = exports.AUTH + "/logout";exports.USERS = exports.API + "/users";exports.SERVERS = exports.API + "/guilds";exports.CHANNELS = exports.API + "/channels"; +"use strict"; + +exports.BASE_DOMAIN = "discordapp.com"; +exports.BASE = "https://" + exports.BASE_DOMAIN; +exports.WEBSOCKET_HUB = "wss://" + exports.BASE_DOMAIN + "/hub"; + +exports.API = exports.BASE + "/api"; +exports.AUTH = exports.API + "/auth"; +exports.LOGIN = exports.AUTH + "/login"; +exports.LOGOUT = exports.AUTH + "/logout"; +exports.USERS = exports.API + "/users"; +exports.SERVERS = exports.API + "/guilds"; +exports.CHANNELS = exports.API + "/channels"; \ No newline at end of file diff --git a/lib/EvaluatedPermissions.js b/lib/EvaluatedPermissions.js index 947063410..c4720c46b 100644 --- a/lib/EvaluatedPermissions.js +++ b/lib/EvaluatedPermissions.js @@ -1 +1,187 @@ -"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 EvaluatedPermissions=(function(){function EvaluatedPermissions(data){_classCallCheck(this,EvaluatedPermissions);var self=this;function getBit(x){if((self.packed >>> 3 & 1) === 1){return true;}return (self.packed >>> x & 1) === 1;}this.packed = data;}EvaluatedPermissions.prototype.getBit = function getBit(x){return (this.packed >>> x & 1) === 1;};EvaluatedPermissions.prototype.setBit = function setBit(){};_createClass(EvaluatedPermissions,[{key:"createInstantInvite",get:function get(){return this.getBit(0);},set:function set(val){this.setBit(0,val);}},{key:"manageRoles",get:function get(){return this.getBit(3);},set:function set(val){this.setBit(3,val);}},{key:"manageChannels",get:function get(){return this.getBit(4);},set:function set(val){this.setBit(4,val);}},{key:"readMessages",get:function get(){return this.getBit(10);},set:function set(val){this.setBit(10,val);}},{key:"sendMessages",get:function get(){return this.getBit(11);},set:function set(val){this.setBit(11,val);}},{key:"sendTTSMessages",get:function get(){return this.getBit(12);},set:function set(val){this.setBit(12,val);}},{key:"manageMessages",get:function get(){return this.getBit(13);},set:function set(val){this.setBit(13,val);}},{key:"embedLinks",get:function get(){return this.getBit(14);},set:function set(val){this.setBit(14,val);}},{key:"attachFiles",get:function get(){return this.getBit(15);},set:function set(val){this.setBit(15,val);}},{key:"readMessageHistory",get:function get(){return this.getBit(16);},set:function set(val){this.setBit(16,val);}},{key:"mentionEveryone",get:function get(){return this.getBit(17);},set:function set(val){this.setBit(17,val);}},{key:"voiceConnect",get:function get(){return this.getBit(20);},set:function set(val){this.setBit(20,val);}},{key:"voiceSpeak",get:function get(){return this.getBit(21);},set:function set(val){this.setBit(21,val);}},{key:"voiceMuteMembers",get:function get(){return this.getBit(22);},set:function set(val){this.setBit(22,val);}},{key:"voiceDeafenMembers",get:function get(){return this.getBit(23);},set:function set(val){this.setBit(23,val);}},{key:"voiceMoveMembers",get:function get(){return this.getBit(24);},set:function set(val){this.setBit(24,val);}},{key:"voiceUseVoiceActivation",get:function get(){return this.getBit(25);},set:function set(val){this.setBit(25,val);}}]);return EvaluatedPermissions;})();module.exports = EvaluatedPermissions; +"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 EvaluatedPermissions = (function () { + function EvaluatedPermissions(data) { + _classCallCheck(this, EvaluatedPermissions); + + var self = this; + + this.packed = data; + + if (this.getBit(3)) this.packed = 4294967295; + } + + EvaluatedPermissions.prototype.serialise = function serialise() { + return { + createInstantInvite: this.createInstantInvite, + manageRoles: this.manageRoles, + manageChannels: this.manageChannels, + readMessages: this.readMessages, + sendMessages: this.sendMessage, + sendTTSMessages: this.sendTTSMessages, + manageMessages: this.manageMessages, + embedLinks: this.embedLinks, + attachFiles: this.attachFiles, + readMessageHistory: this.readMessageHistory, + mentionEveryone: this.mentionEveryone, + voiceConnect: this.voiceConnect, + voiceSpeak: this.voiceSpeak, + voiceMuteMembers: this.voiceMuteMembers, + voiceDeafenMembers: this.voiceDeafenMembers, + voiceMoveMember: this.voiceMoveMembers, + voiceUseVoiceActivation: this.voiceUseVoiceActivation + }; + }; + + EvaluatedPermissions.prototype.getBit = function getBit(x) { + return (this.packed >>> x & 1) === 1; + }; + + EvaluatedPermissions.prototype.setBit = function setBit() {}; + + _createClass(EvaluatedPermissions, [{ + key: "createInstantInvite", + get: function get() { + return this.getBit(0); + }, + set: function set(val) { + this.setBit(0, val); + } + }, { + key: "manageRoles", + get: function get() { + return this.getBit(3); + }, + set: function set(val) { + this.setBit(3, val); + } + }, { + key: "manageChannels", + get: function get() { + return this.getBit(4); + }, + set: function set(val) { + this.setBit(4, val); + } + }, { + key: "readMessages", + get: function get() { + return this.getBit(10); + }, + set: function set(val) { + this.setBit(10, val); + } + }, { + key: "sendMessages", + get: function get() { + return this.getBit(11); + }, + set: function set(val) { + this.setBit(11, val); + } + }, { + key: "sendTTSMessages", + get: function get() { + return this.getBit(12); + }, + set: function set(val) { + this.setBit(12, val); + } + }, { + key: "manageMessages", + get: function get() { + return this.getBit(13); + }, + set: function set(val) { + this.setBit(13, val); + } + }, { + key: "embedLinks", + get: function get() { + return this.getBit(14); + }, + set: function set(val) { + this.setBit(14, val); + } + }, { + key: "attachFiles", + get: function get() { + return this.getBit(15); + }, + set: function set(val) { + this.setBit(15, val); + } + }, { + key: "readMessageHistory", + get: function get() { + return this.getBit(16); + }, + set: function set(val) { + this.setBit(16, val); + } + }, { + key: "mentionEveryone", + get: function get() { + return this.getBit(17); + }, + set: function set(val) { + this.setBit(17, val); + } + }, { + key: "voiceConnect", + get: function get() { + return this.getBit(20); + }, + set: function set(val) { + this.setBit(20, val); + } + }, { + key: "voiceSpeak", + get: function get() { + return this.getBit(21); + }, + set: function set(val) { + this.setBit(21, val); + } + }, { + key: "voiceMuteMembers", + get: function get() { + return this.getBit(22); + }, + set: function set(val) { + this.setBit(22, val); + } + }, { + key: "voiceDeafenMembers", + get: function get() { + return this.getBit(23); + }, + set: function set(val) { + this.setBit(23, val); + } + }, { + key: "voiceMoveMembers", + get: function get() { + return this.getBit(24); + }, + set: function set(val) { + this.setBit(24, val); + } + }, { + key: "voiceUseVoiceActivation", + get: function get() { + return this.getBit(25); + }, + set: function set(val) { + this.setBit(25, val); + } + }]); + + return EvaluatedPermissions; +})(); + +module.exports = EvaluatedPermissions; \ No newline at end of file diff --git a/lib/Member.js b/lib/Member.js index 36b583a87..e7b1df1bd 100644 --- a/lib/Member.js +++ b/lib/Member.js @@ -1,4 +1,174 @@ -"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 User=require("./user.js");var ServerPermissions=require("./ServerPermissions.js");var EvaluatedPermissions=require("./EvaluatedPermissions.js");var Member=(function(_User){_inherits(Member,_User);function Member(user,server,roles){_classCallCheck(this,Member);_User.call(this,user); // should work, we are basically creating a Member that has the same properties as user and a few more -this.server = server;this.rawRoles = roles;}Member.prototype.permissionsIn = function permissionsIn(channel){if(channel.server.ownerID === this.id){return new EvaluatedPermissions(4294967295); //all perms -}var affectingOverwrites=[];var affectingMemberOverwrites=[];for(var _iterator=channel.roles,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var overwrite=_ref;if(overwrite.id === this.id && overwrite.type === "member"){affectingMemberOverwrites.push(overwrite);}else if(this.rawRoles.indexOf(overwrite.id) !== -1){affectingOverwrites.push(overwrite);}}for(var _iterator2=affectingOverwrites,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var perm=_ref2;console.log("hey",perm.attachFiles);}if(affectingOverwrites.length === 0 && affectingMemberOverwrites.length === 0){return new EvaluatedPermissions(this.evalPerms.packed);}var finalPacked=affectingOverwrites.length !== 0?affectingOverwrites[0].packed:affectingMemberOverwrites[0].packed;for(var _iterator3=affectingOverwrites,_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[Symbol.iterator]();;) {var _ref3;if(_isArray3){if(_i3 >= _iterator3.length)break;_ref3 = _iterator3[_i3++];}else {_i3 = _iterator3.next();if(_i3.done)break;_ref3 = _i3.value;}var overwrite=_ref3;finalPacked = finalPacked & ~overwrite.deny;finalPacked = finalPacked | overwrite.allow;}for(var _iterator4=affectingMemberOverwrites,_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[Symbol.iterator]();;) {var _ref4;if(_isArray4){if(_i4 >= _iterator4.length)break;_ref4 = _iterator4[_i4++];}else {_i4 = _iterator4.next();if(_i4.done)break;_ref4 = _i4.value;}var overwrite=_ref4;finalPacked = finalPacked & ~overwrite.deny;finalPacked = finalPacked | overwrite.allow;}return new EvaluatedPermissions(finalPacked);};_createClass(Member,[{key:"roles",get:function get(){var ufRoles=[this.server.getRole(this.server.id)];for(var _iterator5=this.rawRoles,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var rawRole=_ref5;ufRoles.push(this.server.getRole(rawRole));}return ufRoles;}},{key:"evalPerms",get:function get(){var basePerms=this.roles, //cache roles as it can be slightly expensive -basePerm=basePerms[0].packed;for(var _iterator6=basePerms,_isArray6=Array.isArray(_iterator6),_i6=0,_iterator6=_isArray6?_iterator6:_iterator6[Symbol.iterator]();;) {var _ref6;if(_isArray6){if(_i6 >= _iterator6.length)break;_ref6 = _iterator6[_i6++];}else {_i6 = _iterator6.next();if(_i6.done)break;_ref6 = _i6.value;}var perm=_ref6;basePerm = basePerm | perm.packed;}return new ServerPermissions({permissions:basePerm});}}]);return Member;})(User);module.exports = Member; +"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 User = require("./user.js"); +var ServerPermissions = require("./ServerPermissions.js"); +var EvaluatedPermissions = require("./EvaluatedPermissions.js"); + +var Member = (function (_User) { + _inherits(Member, _User); + + function Member(user, server, roles) { + _classCallCheck(this, Member); + + _User.call(this, user); // should work, we are basically creating a Member that has the same properties as user and a few more + this.server = server; + this.rawRoles = roles; + } + + Member.prototype.permissionsIn = function permissionsIn(channel) { + + if (channel.server.ownerID === this.id) { + return new EvaluatedPermissions(4294967295); //all perms + } + + var affectingOverwrites = []; + var affectingMemberOverwrites = []; + + for (var _iterator = channel.roles, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + var overwrite = _ref; + + if (overwrite.id === this.id && overwrite.type === "member") { + affectingMemberOverwrites.push(overwrite); + } else if (this.rawRoles.indexOf(overwrite.id) !== -1) { + affectingOverwrites.push(overwrite); + } + } + + for (var _iterator2 = affectingOverwrites, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { + var _ref2; + + if (_isArray2) { + if (_i2 >= _iterator2.length) break; + _ref2 = _iterator2[_i2++]; + } else { + _i2 = _iterator2.next(); + if (_i2.done) break; + _ref2 = _i2.value; + } + + var perm = _ref2; + + console.log("hey", perm.attachFiles); + } + + if (affectingOverwrites.length === 0 && affectingMemberOverwrites.length === 0) { + return new EvaluatedPermissions(this.evalPerms.packed); + } + + var finalPacked = affectingOverwrites.length !== 0 ? affectingOverwrites[0].packed : affectingMemberOverwrites[0].packed; + + for (var _iterator3 = affectingOverwrites, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { + var _ref3; + + if (_isArray3) { + if (_i3 >= _iterator3.length) break; + _ref3 = _iterator3[_i3++]; + } else { + _i3 = _iterator3.next(); + if (_i3.done) break; + _ref3 = _i3.value; + } + + var overwrite = _ref3; + + finalPacked = finalPacked & ~overwrite.deny; + finalPacked = finalPacked | overwrite.allow; + } + + for (var _iterator4 = affectingMemberOverwrites, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { + var _ref4; + + if (_isArray4) { + if (_i4 >= _iterator4.length) break; + _ref4 = _iterator4[_i4++]; + } else { + _i4 = _iterator4.next(); + if (_i4.done) break; + _ref4 = _i4.value; + } + + var overwrite = _ref4; + + finalPacked = finalPacked & ~overwrite.deny; + finalPacked = finalPacked | overwrite.allow; + } + + return new EvaluatedPermissions(finalPacked); + }; + + _createClass(Member, [{ + key: "roles", + get: function get() { + + var ufRoles = [this.server.getRole(this.server.id)]; + + for (var _iterator5 = this.rawRoles, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { + var _ref5; + + if (_isArray5) { + if (_i5 >= _iterator5.length) break; + _ref5 = _iterator5[_i5++]; + } else { + _i5 = _iterator5.next(); + if (_i5.done) break; + _ref5 = _i5.value; + } + + var rawRole = _ref5; + + ufRoles.push(this.server.getRole(rawRole)); + } + + return ufRoles; + } + }, { + key: "evalPerms", + get: function get() { + var basePerms = this.roles, + //cache roles as it can be slightly expensive + basePerm = basePerms[0].packed; + + for (var _iterator6 = basePerms, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { + var _ref6; + + if (_isArray6) { + if (_i6 >= _iterator6.length) break; + _ref6 = _iterator6[_i6++]; + } else { + _i6 = _iterator6.next(); + if (_i6.done) break; + _ref6 = _i6.value; + } + + var perm = _ref6; + + basePerm = basePerm | perm.packed; + } + + return new ServerPermissions({ + permissions: basePerm + }); + } + }]); + + return Member; +})(User); + +module.exports = Member; \ No newline at end of file diff --git a/lib/PMChannel.js b/lib/PMChannel.js index 8d90dade1..06d1c120b 100644 --- a/lib/PMChannel.js +++ b/lib/PMChannel.js @@ -1 +1,61 @@ -"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 PMChannel=(function(){function PMChannel(data,client){_classCallCheck(this,PMChannel);this.user = client.getUser("id",data.recipient.id);this.id = data.id;this.messages = [];this.client = client;}PMChannel.prototype.addMessage = function addMessage(data){if(!this.getMessage("id",data.id)){this.messages.push(data);}return this.getMessage("id",data.id);};PMChannel.prototype.getMessage = function getMessage(key,value){if(this.messages.length > 1000){this.messages.splice(0,1);}for(var _iterator=this.messages,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var message=_ref;if(message[key] === value){return message;}}return null;};_createClass(PMChannel,[{key:"isPrivate",get:function get(){return true;}}]);return PMChannel;})();module.exports = PMChannel; +"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 PMChannel = (function () { + function PMChannel(data, client) { + _classCallCheck(this, PMChannel); + + this.user = client.getUser("id", data.recipient.id); + this.id = data.id; + this.messages = []; + this.client = client; + } + + PMChannel.prototype.addMessage = function addMessage(data) { + if (!this.getMessage("id", data.id)) { + this.messages.push(data); + } + return this.getMessage("id", data.id); + }; + + PMChannel.prototype.getMessage = function getMessage(key, value) { + + if (this.messages.length > 1000) { + this.messages.splice(0, 1); + } + + for (var _iterator = this.messages, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + var message = _ref; + + if (message[key] === value) { + return message; + } + } + return null; + }; + + _createClass(PMChannel, [{ + key: "isPrivate", + get: function get() { + return true; + } + }]); + + return PMChannel; +})(); + +module.exports = PMChannel; \ No newline at end of file diff --git a/lib/ServerPermissions.js b/lib/ServerPermissions.js index 73148ca06..6384f759b 100644 --- a/lib/ServerPermissions.js +++ b/lib/ServerPermissions.js @@ -19,22 +19,19 @@ var ServerPermissions = (function () { this.id = data.id; } + ServerPermissions.prototype.getBit = function getBit(x) { + return (this.packed >>> x & 1) === 1; + }; + + ServerPermissions.prototype.setBit = function setBit() { + //dummy function for now + }; + + ServerPermissions.prototype.toString = function toString() { + return this.name; + }; + _createClass(ServerPermissions, [{ - key: "getBit", - value: function getBit(x) { - return (this.packed >>> x & 1) === 1; - } - }, { - key: "setBit", - value: function setBit() { - //dummy function for now - } - }, { - key: "toString", - value: function toString() { - return this.name; - } - }, { key: "createInstantInvite", get: function get() { return this.getBit(0); diff --git a/lib/channel.js b/lib/channel.js index 04c363943..7b8b1c027 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -1,2 +1,130 @@ -"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var ChannelPermissions=require("./ChannelPermissions.js");var Channel=(function(){function Channel(data,server){_classCallCheck(this,Channel);this.server = server;this.name = data.name;this.type = data.type;this.topic = data.topic;this.id = data.id;this.messages = [];this.roles = [];if(data.permission_overwrites)for(var _iterator=data.permission_overwrites,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var role=_ref;this.roles.push(new ChannelPermissions(role,this));} //this.isPrivate = isPrivate; //not sure about the implementation of this... -}Channel.prototype.permissionsOf = function permissionsOf(member){var mem=this.server.getMember("id",member.id);if(mem){return mem.permissionsIn(this);}else {return null;}};Channel.prototype.equals = function equals(object){return object && object.id === this.id;};Channel.prototype.addMessage = function addMessage(data){if(this.messages.length > 1000){this.messages.splice(0,1);}if(!this.getMessage("id",data.id)){this.messages.push(data);}return this.getMessage("id",data.id);};Channel.prototype.getMessage = function getMessage(key,value){for(var _iterator2=this.messages,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var message=_ref2;if(message[key] === value){return message;}}return null;};Channel.prototype.toString = function toString(){return "<#" + this.id + ">";};_createClass(Channel,[{key:"permissionOverwrites",get:function get(){return this.roles;}},{key:"permissions",get:function get(){return this.roles;}},{key:"client",get:function get(){return this.server.client;}},{key:"isPrivate",get:function get(){return false;}},{key:"users",get:function get(){return this.server.members;}},{key:"members",get:function get(){return this.server.members;}}]);return Channel;})();module.exports = Channel; +"use strict"; + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var ChannelPermissions = require("./ChannelPermissions.js"); + +var Channel = (function () { + function Channel(data, server) { + _classCallCheck(this, Channel); + + this.server = server; + this.name = data.name; + this.type = data.type; + this.topic = data.topic; + this.id = data.id; + this.messages = []; + this.roles = []; + + if (data.permission_overwrites) for (var _iterator = data.permission_overwrites, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + var role = _ref; + + this.roles.push(new ChannelPermissions(role, this)); + } + + //this.isPrivate = isPrivate; //not sure about the implementation of this... + } + + Channel.prototype.permissionsOf = function permissionsOf(member) { + + var mem = this.server.getMember("id", member.id); + + if (mem) { + return mem.permissionsIn(this); + } else { + return null; + } + }; + + Channel.prototype.equals = function equals(object) { + return object && object.id === this.id; + }; + + Channel.prototype.addMessage = function addMessage(data) { + + if (this.messages.length > 1000) { + this.messages.splice(0, 1); + } + + if (!this.getMessage("id", data.id)) { + this.messages.push(data); + } + + return this.getMessage("id", data.id); + }; + + Channel.prototype.getMessage = function getMessage(key, value) { + for (var _iterator2 = this.messages, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { + var _ref2; + + if (_isArray2) { + if (_i2 >= _iterator2.length) break; + _ref2 = _iterator2[_i2++]; + } else { + _i2 = _iterator2.next(); + if (_i2.done) break; + _ref2 = _i2.value; + } + + var message = _ref2; + + if (message[key] === value) { + return message; + } + } + return null; + }; + + Channel.prototype.toString = function toString() { + return "<#" + this.id + ">"; + }; + + _createClass(Channel, [{ + key: "permissionOverwrites", + get: function get() { + return this.roles; + } + }, { + key: "permissions", + get: function get() { + return this.roles; + } + }, { + key: "client", + get: function get() { + return this.server.client; + } + }, { + key: "isPrivate", + get: function get() { + return false; + } + }, { + key: "users", + get: function get() { + return this.server.members; + } + }, { + key: "members", + get: function get() { + return this.server.members; + } + }]); + + return Channel; +})(); + +module.exports = Channel; \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index 9eabba0ae..6a2f82f05 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1 +1,12 @@ -"use strict";var request=require("superagent");var Endpoints=require("./Endpoints.js");var Client=require("./Client.js");var Discord={Endpoints:Endpoints,Client:Client};module.exports = Discord; +"use strict"; + +var request = require("superagent"); +var Endpoints = require("./Endpoints.js"); +var Client = require("./Client.js"); + +var Discord = { + Endpoints: Endpoints, + Client: Client +}; + +module.exports = Discord; \ No newline at end of file diff --git a/lib/internal.js b/lib/internal.js index b91c38597..3acf5940b 100644 --- a/lib/internal.js +++ b/lib/internal.js @@ -1 +1,203 @@ -"use strict";var request=require("superagent");var Endpoints=require("./endpoints.js");var Internal={};Internal.XHR = {};Internal.WebSocket = {};Internal.WebSocket.properties = {"$os":"discord.js","$browser":"discord.js","$device":"discord.js","$referrer":"","$referring_domain":""};Internal.XHR.login = function(email,password,callback){request.post(Endpoints.LOGIN).send({email:email,password:password}).end(function(err,res){if(err){callback(err);}else {callback(null,res.body.token);}});};Internal.XHR.logout = function(token,callback){request.post(Endpoints.LOGOUT).end(function(err,res){err?callback(err):callback(null);});};Internal.XHR.createServer = function(token,name,region,callback){request.post(Endpoints.SERVERS).set("authorization",token).send({name:name,region:region}).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.leaveServer = function(token,serverId,callback){request.del(Endpoints.SERVERS + "/" + serverId).set("authorization",token).end(function(err,res){err?callback(err):callback(null);});};Internal.XHR.createInvite = function(token,channelId,options,callback){request.post(Endpoints.CHANNELS + "/" + channelId + "/invites").set("authorization",token).send(options).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.startPM = function(token,selfID,userID,callback){request.post(Endpoints.USERS + "/" + selfID + "/channels").set("authorization",token).send({recipient_id:userID}).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.sendMessage = function(token,channelID,messageParameters,callback){request.post(Endpoints.CHANNELS + "/" + channelID + "/messages").set("authorization",token).send(messageParameters).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.sendFile = function(token,channelID,file,fileName,callback){request.post(Endpoints.CHANNELS + "/" + channelID + "/messages").set("authorization",token).attach("file",file,fileName).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.deleteMessage = function(token,channelID,messageID,callback){request.del(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID).set("authorization",token).end(function(err){err?callback(err):callback(null);});};Internal.XHR.updateMessage = function(token,channelID,messageID,messageParameters,callback){request.patch(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID).set("authorization",token).send(messageParameters).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.getChannelLogs = function(token,channelID,amount,callback){request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization",token).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.createChannel = function(token,serverID,name,type,callback){request.post(Endpoints.SERVERS + "/" + serverID + "/channels").set("authorization",token).send({name:name,type:type}).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.deleteChannel = function(token,channelID,callback){request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization",token).end(function(err){err?callback(err):callback(null);});};Internal.XHR.deleteServer = function(token,serverID,callback){request.del(Endpoints.SERVERS + "/" + serverID).set("authorization",token).end(function(err){err?callback(err):callback(null);});};Internal.XHR.getChannels = function(token,serverID,callback){request.get(Endpoints.SERVERS + "/" + serverID + "/channels").set("authorization",token).end(function(err){err?callback(err):callback(null);});};Internal.XHR.getServer = function(token,serverID,callback){request.get(Endpoints.SERVERS + "/" + serverID).set("authorization",token).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.acceptInvite = function(token,inviteID,callback){request.post(Endpoints.API + "/invite/" + inviteID).set("authorization",token).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.setUsername = function(token,avatar,email,newPassword,password,username,callback){request.patch(Endpoints.API + "/users/@me").set("authorization",token).send({avatar:avatar,email:email,new_password:newPassword,password:password,username:username}).end(function(err){callback(err);});};exports.Internal = Internal; +"use strict"; + +var request = require("superagent"); +var Endpoints = require("./endpoints.js"); + +var Internal = {}; + +Internal.XHR = {}; +Internal.WebSocket = {}; + +Internal.WebSocket.properties = { + "$os": "discord.js", + "$browser": "discord.js", + "$device": "discord.js", + "$referrer": "", + "$referring_domain": "" +}; + +Internal.XHR.login = function (email, password, callback) { + + request.post(Endpoints.LOGIN).send({ + email: email, + password: password + }).end(function (err, res) { + if (err) { + callback(err); + } else { + callback(null, res.body.token); + } + }); +}; + +Internal.XHR.logout = function (token, callback) { + + request.post(Endpoints.LOGOUT).end(function (err, res) { + + err ? callback(err) : callback(null); + }); +}; + +Internal.XHR.createServer = function (token, name, region, callback) { + + request.post(Endpoints.SERVERS).set("authorization", token).send({ + name: name, + region: region + }).end(function (err, res) { + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.leaveServer = function (token, serverId, callback) { + + request.del(Endpoints.SERVERS + "/" + serverId).set("authorization", token).end(function (err, res) { + + err ? callback(err) : callback(null); + }); +}; + +Internal.XHR.createInvite = function (token, channelId, options, callback) { + request.post(Endpoints.CHANNELS + "/" + channelId + "/invites").set("authorization", token).send(options).end(function (err, res) { + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.startPM = function (token, selfID, userID, callback) { + + request.post(Endpoints.USERS + "/" + selfID + "/channels").set("authorization", token).send({ + recipient_id: userID + }).end(function (err, res) { + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.sendMessage = function (token, channelID, messageParameters, callback) { + request.post(Endpoints.CHANNELS + "/" + channelID + "/messages").set("authorization", token).send(messageParameters).end(function (err, res) { + + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.sendFile = function (token, channelID, file, fileName, callback) { + request.post(Endpoints.CHANNELS + "/" + channelID + "/messages").set("authorization", token).attach("file", file, fileName).end(function (err, res) { + + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.deleteMessage = function (token, channelID, messageID, callback) { + request.del(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID).set("authorization", token).end(function (err) { + err ? callback(err) : callback(null); + }); +}; + +Internal.XHR.updateMessage = function (token, channelID, messageID, messageParameters, callback) { + + request.patch(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID).set("authorization", token).send(messageParameters).end(function (err, res) { + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.getChannelLogs = function (token, channelID, amount, callback) { + request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization", token).end(function (err, res) { + + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.createChannel = function (token, serverID, name, type, callback) { + request.post(Endpoints.SERVERS + "/" + serverID + "/channels").set("authorization", token).send({ + name: name, + type: type + }).end(function (err, res) { + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.deleteChannel = function (token, channelID, callback) { + + request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization", token).end(function (err) { + err ? callback(err) : callback(null); + }); +}; +Internal.XHR.deleteServer = function (token, serverID, callback) { + request.del(Endpoints.SERVERS + "/" + serverID).set("authorization", token).end(function (err) { + err ? callback(err) : callback(null); + }); +}; + +Internal.XHR.getChannels = function (token, serverID, callback) { + request.get(Endpoints.SERVERS + "/" + serverID + "/channels").set("authorization", token).end(function (err) { + err ? callback(err) : callback(null); + }); +}; + +Internal.XHR.getServer = function (token, serverID, callback) { + + request.get(Endpoints.SERVERS + "/" + serverID).set("authorization", token).end(function (err, res) { + + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.acceptInvite = function (token, inviteID, callback) { + + request.post(Endpoints.API + "/invite/" + inviteID).set("authorization", token).end(function (err, res) { + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.setUsername = function (token, avatar, email, newPassword, password, username, callback) { + + request.patch(Endpoints.API + "/users/@me").set("authorization", token).send({ + avatar: avatar, + email: email, + new_password: newPassword, + password: password, + username: username + }).end(function (err) { + callback(err); + }); +}; + +exports.Internal = Internal; \ No newline at end of file diff --git a/lib/invite.js b/lib/invite.js index 5ff2ddf15..5f51dc1a9 100644 --- a/lib/invite.js +++ b/lib/invite.js @@ -1 +1,35 @@ -"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 Invite=(function(){function Invite(data,client){_classCallCheck(this,Invite);this.max_age = data.max_age;this.code = data.code;this.server = client.getServer("id",data.guild.id);this.revoked = data.revoked;this.created_at = Date.parse(data.created_at);this.temporary = data.temporary;this.uses = data.uses;this.max_uses = data.uses;this.inviter = client.addUser(data.inviter);this.xkcd = data.xkcdpass;this.channel = client.getChannel("id",data.channel.id);}_createClass(Invite,[{key:"URL",get:function get(){var code=this.xkcd?this.xkcdpass:this.code;return "https://discord.gg/" + code;}}]);return Invite;})();module.exports = Invite; +"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 Invite = (function () { + function Invite(data, client) { + _classCallCheck(this, Invite); + + this.max_age = data.max_age; + this.code = data.code; + this.server = client.getServer("id", data.guild.id); + this.revoked = data.revoked; + this.created_at = Date.parse(data.created_at); + this.temporary = data.temporary; + this.uses = data.uses; + this.max_uses = data.uses; + this.inviter = client.addUser(data.inviter); + this.xkcd = data.xkcdpass; + this.channel = client.getChannel("id", data.channel.id); + } + + _createClass(Invite, [{ + key: "URL", + get: function get() { + var code = this.xkcd ? this.xkcdpass : this.code; + return "https://discord.gg/" + code; + } + }]); + + return Invite; +})(); + +module.exports = Invite; \ No newline at end of file diff --git a/lib/message.js b/lib/message.js index 26d9e4f69..72c1eb7f2 100644 --- a/lib/message.js +++ b/lib/message.js @@ -1,3 +1,75 @@ -"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 PMChannel=require("./PMChannel.js");var Message=(function(){function Message(data,channel,mentions,author){_classCallCheck(this,Message);this.tts = data.tts;this.timestamp = Date.parse(data.timestamp);this.nonce = data.nonce;this.mentions = mentions;this.everyoneMentioned = data.mention_everyone;this.id = data.id;this.embeds = data.embeds;this.editedTimestamp = data.edited_timestamp;this.content = data.content.trim();this.channel = channel;if(this.isPrivate){this.author = this.channel.client.getUser("id",author.id);}else {this.author = this.channel.server.getMember("id",author.id) || this.channel.client.getUser("id",author.id);}this.attachments = data.attachments;} /*exports.Message.prototype.isPM = function() { - return ( this.channel instanceof PMChannel ); -}*/Message.prototype.isMentioned = function isMentioned(user){var id=user.id?user.id:user;for(var _iterator=this.mentions,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var mention=_ref;if(mention.id === id){return true;}}return false;};_createClass(Message,[{key:"sender",get:function get(){return this.author;}},{key:"isPrivate",get:function get(){return this.channel.isPrivate;}}]);return Message;})();module.exports = Message; +"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 PMChannel = require("./PMChannel.js"); + +var Message = (function () { + function Message(data, channel, mentions, author) { + _classCallCheck(this, Message); + + this.tts = data.tts; + this.timestamp = Date.parse(data.timestamp); + this.nonce = data.nonce; + this.mentions = mentions; + this.everyoneMentioned = data.mention_everyone; + this.id = data.id; + this.embeds = data.embeds; + this.editedTimestamp = data.edited_timestamp; + this.content = data.content.trim(); + this.channel = channel; + + if (this.isPrivate) { + this.author = this.channel.client.getUser("id", author.id); + } else { + this.author = this.channel.server.getMember("id", author.id) || this.channel.client.getUser("id", author.id); + } + + this.attachments = data.attachments; + } + + /*exports.Message.prototype.isPM = function() { + return ( this.channel instanceof PMChannel ); + }*/ + + Message.prototype.isMentioned = function isMentioned(user) { + var id = user.id ? user.id : user; + for (var _iterator = this.mentions, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + var mention = _ref; + + if (mention.id === id) { + return true; + } + } + return false; + }; + + _createClass(Message, [{ + key: "sender", + get: function get() { + return this.author; + } + }, { + key: "isPrivate", + get: function get() { + return this.channel.isPrivate; + } + }]); + + return Message; +})(); + +module.exports = Message; \ No newline at end of file diff --git a/lib/server.js b/lib/server.js index 871e30928..46676d5eb 100644 --- a/lib/server.js +++ b/lib/server.js @@ -24,29 +24,21 @@ var Server = (function () { this.roles = []; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; + for (var _iterator = data.roles, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; - try { - for (var _iterator = data.roles[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var permissionGroup = _step.value; + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } - this.roles.push(new ServerPermissions(permissionGroup)); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } + var permissionGroup = _ref; + + this.roles.push(new ServerPermissions(permissionGroup)); } if (!data.members) { @@ -54,251 +46,192 @@ var Server = (function () { return; } - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; + for (var _iterator2 = data.members, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { + var _ref2; - try { - for (var _iterator2 = data.members[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var member = _step2.value; + if (_isArray2) { + if (_i2 >= _iterator2.length) break; + _ref2 = _iterator2[_i2++]; + } else { + _i2 = _iterator2.next(); + if (_i2.done) break; + _ref2 = _i2.value; + } - // first we cache the user in our Discord Client, - // then we add it to our list. This way when we - // get a user from this server's member list, - // it will be identical (unless an async change occurred) - // to the client's cache. - if (member.user) this.addMember(client.addUser(member.user), member.roles); - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { - try { - if (!_iteratorNormalCompletion2 && _iterator2["return"]) { - _iterator2["return"](); - } - } finally { - if (_didIteratorError2) { - throw _iteratorError2; - } - } + var member = _ref2; + + // first we cache the user in our Discord Client, + // then we add it to our list. This way when we + // get a user from this server's member list, + // it will be identical (unless an async change occurred) + // to the client's cache. + if (member.user) this.addMember(client.addUser(member.user), member.roles); } } - _createClass(Server, [{ - key: "getRole", + // get/set - // get/set + Server.prototype.getRole = function getRole(id) { + for (var _iterator3 = this.roles, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { + var _ref3; - value: function getRole(id) { - var _iteratorNormalCompletion3 = true; - var _didIteratorError3 = false; - var _iteratorError3 = undefined; - - try { - for (var _iterator3 = this.roles[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { - var role = _step3.value; - - if (role.id === id) { - return role; - } - } - } catch (err) { - _didIteratorError3 = true; - _iteratorError3 = err; - } finally { - try { - if (!_iteratorNormalCompletion3 && _iterator3["return"]) { - _iterator3["return"](); - } - } finally { - if (_didIteratorError3) { - throw _iteratorError3; - } - } - } - - return null; - } - }, { - key: "updateRole", - value: function updateRole(data) { - - var oldRole = this.getRole(data.id); - - if (oldRole) { - - var index = this.roles.indexOf(oldRole); - this.roles[index] = new ServerPermissions(data); - - return this.roles[index]; + if (_isArray3) { + if (_i3 >= _iterator3.length) break; + _ref3 = _iterator3[_i3++]; } else { - return false; + _i3 = _iterator3.next(); + if (_i3.done) break; + _ref3 = _i3.value; + } + + var role = _ref3; + + if (role.id === id) { + return role; } } - }, { - key: "removeRole", - value: function removeRole(id) { - for (var roleId in this.roles) { - if (this.roles[roleId].id === id) { - this.roles.splice(roleId, 1); - } - } - var _iteratorNormalCompletion4 = true; - var _didIteratorError4 = false; - var _iteratorError4 = undefined; + return null; + }; - try { - for (var _iterator4 = this.members[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { - var member = _step4.value; + Server.prototype.updateRole = function updateRole(data) { - for (var roleId in member.rawRoles) { - if (member.rawRoles[roleId] === id) { - member.rawRoles.splice(roleId, 1); - } - } - } - } catch (err) { - _didIteratorError4 = true; - _iteratorError4 = err; - } finally { - try { - if (!_iteratorNormalCompletion4 && _iterator4["return"]) { - _iterator4["return"](); - } - } finally { - if (_didIteratorError4) { - throw _iteratorError4; - } - } - } - } - }, { - key: "getChannel", - value: function getChannel(key, value) { - var _iteratorNormalCompletion5 = true; - var _didIteratorError5 = false; - var _iteratorError5 = undefined; + var oldRole = this.getRole(data.id); - try { - for (var _iterator5 = this.channels[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { - var channel = _step5.value; + if (oldRole) { - if (channel[key] === value) { - return channel; - } - } - } catch (err) { - _didIteratorError5 = true; - _iteratorError5 = err; - } finally { - try { - if (!_iteratorNormalCompletion5 && _iterator5["return"]) { - _iterator5["return"](); - } - } finally { - if (_didIteratorError5) { - throw _iteratorError5; - } - } - } - - return null; - } - }, { - key: "getMember", - value: function getMember(key, value) { - var _iteratorNormalCompletion6 = true; - var _didIteratorError6 = false; - var _iteratorError6 = undefined; - - try { - for (var _iterator6 = this.members[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { - var member = _step6.value; - - if (member[key] === value) { - return member; - } - } - } catch (err) { - _didIteratorError6 = true; - _iteratorError6 = err; - } finally { - try { - if (!_iteratorNormalCompletion6 && _iterator6["return"]) { - _iterator6["return"](); - } - } finally { - if (_didIteratorError6) { - throw _iteratorError6; - } - } - } - - return null; - } - }, { - key: "removeMember", - value: function removeMember(key, value) { - var _iteratorNormalCompletion7 = true; - var _didIteratorError7 = false; - var _iteratorError7 = undefined; - - try { - for (var _iterator7 = this.members[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { - var member = _step7.value; - - if (member[key] === value) { - this.members.splice(key, 1); - return member; - } - } - } catch (err) { - _didIteratorError7 = true; - _iteratorError7 = err; - } finally { - try { - if (!_iteratorNormalCompletion7 && _iterator7["return"]) { - _iterator7["return"](); - } - } finally { - if (_didIteratorError7) { - throw _iteratorError7; - } - } - } + var index = this.roles.indexOf(oldRole); + this.roles[index] = new ServerPermissions(data); + return this.roles[index]; + } else { return false; } - }, { - key: "addChannel", - value: function addChannel(chann) { - if (!this.getChannel("id", chann.id)) { - this.channels.push(chann); + }; + + Server.prototype.removeRole = function removeRole(id) { + for (var roleId in this.roles) { + if (this.roles[roleId].id === id) { + this.roles.splice(roleId, 1); } - return chann; } - }, { - key: "addMember", - value: function addMember(user, roles) { - if (!this.getMember("id", user.id)) { - var mem = new Member(user, this, roles); - this.members.push(mem); + + for (var _iterator4 = this.members, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { + var _ref4; + + if (_isArray4) { + if (_i4 >= _iterator4.length) break; + _ref4 = _iterator4[_i4++]; + } else { + _i4 = _iterator4.next(); + if (_i4.done) break; + _ref4 = _i4.value; + } + + var member = _ref4; + + for (var roleId in member.rawRoles) { + if (member.rawRoles[roleId] === id) { + member.rawRoles.splice(roleId, 1); + } } - return mem; } - }, { - key: "toString", - value: function toString() { - return this.name; + }; + + Server.prototype.getChannel = function getChannel(key, value) { + for (var _iterator5 = this.channels, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { + var _ref5; + + if (_isArray5) { + if (_i5 >= _iterator5.length) break; + _ref5 = _iterator5[_i5++]; + } else { + _i5 = _iterator5.next(); + if (_i5.done) break; + _ref5 = _i5.value; + } + + var channel = _ref5; + + if (channel[key] === value) { + return channel; + } } - }, { - key: "equals", - value: function equals(object) { - return object.id === this.id; + + return null; + }; + + Server.prototype.getMember = function getMember(key, value) { + for (var _iterator6 = this.members, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { + var _ref6; + + if (_isArray6) { + if (_i6 >= _iterator6.length) break; + _ref6 = _iterator6[_i6++]; + } else { + _i6 = _iterator6.next(); + if (_i6.done) break; + _ref6 = _i6.value; + } + + var member = _ref6; + + if (member[key] === value) { + return member; + } } - }, { + + return null; + }; + + Server.prototype.removeMember = function removeMember(key, value) { + for (var _iterator7 = this.members, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) { + var _ref7; + + if (_isArray7) { + if (_i7 >= _iterator7.length) break; + _ref7 = _iterator7[_i7++]; + } else { + _i7 = _iterator7.next(); + if (_i7.done) break; + _ref7 = _i7.value; + } + + var member = _ref7; + + if (member[key] === value) { + this.members.splice(key, 1); + return member; + } + } + + return false; + }; + + Server.prototype.addChannel = function addChannel(chann) { + if (!this.getChannel("id", chann.id)) { + this.channels.push(chann); + } + return chann; + }; + + Server.prototype.addMember = function addMember(user, roles) { + if (!this.getMember("id", user.id)) { + var mem = new Member(user, this, roles); + this.members.push(mem); + } + return mem; + }; + + Server.prototype.toString = function toString() { + return this.name; + }; + + Server.prototype.equals = function equals(object) { + return object.id === this.id; + }; + + _createClass(Server, [{ key: "permissionGroups", get: function get() { return this.roles; diff --git a/src/EvaluatedPermissions.js b/src/EvaluatedPermissions.js index 5fef65fe9..b7ccd1dde 100644 --- a/src/EvaluatedPermissions.js +++ b/src/EvaluatedPermissions.js @@ -2,15 +2,33 @@ class EvaluatedPermissions { constructor(data) { var self = this; - - function getBit(x) { - if (((self.packed >>> 3) & 1) === 1) { - return true; - } - return ((self.packed >>> x) & 1) === 1; - } - + this.packed = data; + + if(this.getBit(3)) + this.packed = 4294967295; + } + + serialise() { + return { + createInstantInvite : this.createInstantInvite, + manageRoles : this.manageRoles, + manageChannels : this.manageChannels, + readMessages : this.readMessages, + sendMessages : this.sendMessage, + sendTTSMessages : this.sendTTSMessages, + manageMessages : this.manageMessages, + embedLinks : this.embedLinks, + attachFiles : this.attachFiles, + readMessageHistory : this.readMessageHistory, + mentionEveryone : this.mentionEveryone, + voiceConnect : this.voiceConnect, + voiceSpeak : this.voiceSpeak, + voiceMuteMembers : this.voiceMuteMembers, + voiceDeafenMembers : this.voiceDeafenMembers, + voiceMoveMember : this.voiceMoveMembers, + voiceUseVoiceActivation : this.voiceUseVoiceActivation + } } get createInstantInvite() { return this.getBit(0); } diff --git a/test/bot.1.js b/test/bot.1.js index 97ca23558..308b1202a 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -24,7 +24,12 @@ mybot.on("message", function (message) { console.log( mybot.getUser("username", "meew0") ); - mybot.reply(message, JSON.stringify(message.mentions, null, 4)); + var perms = JSON.stringify(message.channel.permissionsOf(user).serialise(), null, 4); + perms = JSON.parse(perms); + + mybot.sendMessage(message, + JSON.stringify(perms, null, 4).replace(new RegExp("true", "g"), "**true**") + ); }); From f9679879f2096c6b45f7ce242eee644f9d6f0198 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 25 Oct 2015 18:40:25 +0000 Subject: [PATCH 144/151] Updated user class --- lib/user.js | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/lib/user.js b/lib/user.js index 1f0fb0eed..2234f030f 100644 --- a/lib/user.js +++ b/lib/user.js @@ -18,33 +18,29 @@ var User = (function () { // access using user.avatarURL; + User.prototype.mention = function mention() { + return "<@" + this.id + ">"; + }; + + User.prototype.toString = function toString() { + /* + if we embed a user in a String - like so: + "Yo " + user + " what's up?" + It would generate something along the lines of: + "Yo @hydrabolt what's up?" + */ + return this.mention(); + }; + + User.prototype.equals = function equals(object) { + return object.id === this.id; + }; + + User.prototype.equalsStrict = function equalsStrict(object) { + return object.id === this.id && object.avatar === this.avatar && object.username === this.username && object.discriminator === this.discriminator; + }; + _createClass(User, [{ - key: "mention", - value: function mention() { - return "<@" + this.id + ">"; - } - }, { - key: "toString", - value: function toString() { - /* - if we embed a user in a String - like so: - "Yo " + user + " what's up?" - It would generate something along the lines of: - "Yo @hydrabolt what's up?" - */ - return this.mention(); - } - }, { - key: "equals", - value: function equals(object) { - return object.id === this.id; - } - }, { - key: "equalsStrict", - value: function equalsStrict(object) { - return object.id === this.id && object.avatar === this.avatar && object.username === this.username && object.discriminator === this.discriminator; - } - }, { key: "avatarURL", get: function get() { if (!this.avatar) return null; From b61c64fa48c378f049b307f2ab0f739eed867c75 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 25 Oct 2015 19:27:43 +0000 Subject: [PATCH 145/151] 3.9.0, chainable string modifiers --- README.md | 27 +++++++++++++++++++ lib/Member.js | 73 ++++++++++++++++++++------------------------------- lib/index.js | 23 ++++++++++++++++ package.json | 2 +- src/Member.js | 3 --- test/bot.1.js | 4 ++- 6 files changed, 82 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index f2ce7157a..9412f2a87 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,33 @@ mybot.login("email", "password"); ``` --- +### What's new in 3.9.0? + +Amongst some fixes to web distribution creation, you can now opt for easier string formatting! However, it does modify String globally so you'll have to run: + +```js +Discord.patchStrings() +``` + +After you have run this, you can do: +``` + +"message".bold.underline.italic +// generates "*__**message**__*" + +``` + +A full list of modifiers (all chainable): + +* bold `**` +* italic `*` +* underline `__` +* strike `~` +* code ` ` ` +* codeblock` ``` ` + +--- + ### Related Projects Here is a list of other Discord APIs: diff --git a/lib/Member.js b/lib/Member.js index e7b1df1bd..813acda1b 100644 --- a/lib/Member.js +++ b/lib/Member.js @@ -51,6 +51,12 @@ var Member = (function (_User) { } } + if (affectingOverwrites.length === 0 && affectingMemberOverwrites.length === 0) { + return new EvaluatedPermissions(this.evalPerms.packed); + } + + var finalPacked = affectingOverwrites.length !== 0 ? affectingOverwrites[0].packed : affectingMemberOverwrites[0].packed; + for (var _iterator2 = affectingOverwrites, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { var _ref2; @@ -63,18 +69,13 @@ var Member = (function (_User) { _ref2 = _i2.value; } - var perm = _ref2; + var overwrite = _ref2; - console.log("hey", perm.attachFiles); + finalPacked = finalPacked & ~overwrite.deny; + finalPacked = finalPacked | overwrite.allow; } - if (affectingOverwrites.length === 0 && affectingMemberOverwrites.length === 0) { - return new EvaluatedPermissions(this.evalPerms.packed); - } - - var finalPacked = affectingOverwrites.length !== 0 ? affectingOverwrites[0].packed : affectingMemberOverwrites[0].packed; - - for (var _iterator3 = affectingOverwrites, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { + for (var _iterator3 = affectingMemberOverwrites, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { var _ref3; if (_isArray3) { @@ -92,24 +93,6 @@ var Member = (function (_User) { finalPacked = finalPacked | overwrite.allow; } - for (var _iterator4 = affectingMemberOverwrites, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { - var _ref4; - - if (_isArray4) { - if (_i4 >= _iterator4.length) break; - _ref4 = _iterator4[_i4++]; - } else { - _i4 = _iterator4.next(); - if (_i4.done) break; - _ref4 = _i4.value; - } - - var overwrite = _ref4; - - finalPacked = finalPacked & ~overwrite.deny; - finalPacked = finalPacked | overwrite.allow; - } - return new EvaluatedPermissions(finalPacked); }; @@ -119,19 +102,19 @@ var Member = (function (_User) { var ufRoles = [this.server.getRole(this.server.id)]; - for (var _iterator5 = this.rawRoles, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { - var _ref5; + for (var _iterator4 = this.rawRoles, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { + var _ref4; - if (_isArray5) { - if (_i5 >= _iterator5.length) break; - _ref5 = _iterator5[_i5++]; + if (_isArray4) { + if (_i4 >= _iterator4.length) break; + _ref4 = _iterator4[_i4++]; } else { - _i5 = _iterator5.next(); - if (_i5.done) break; - _ref5 = _i5.value; + _i4 = _iterator4.next(); + if (_i4.done) break; + _ref4 = _i4.value; } - var rawRole = _ref5; + var rawRole = _ref4; ufRoles.push(this.server.getRole(rawRole)); } @@ -145,19 +128,19 @@ var Member = (function (_User) { //cache roles as it can be slightly expensive basePerm = basePerms[0].packed; - for (var _iterator6 = basePerms, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { - var _ref6; + for (var _iterator5 = basePerms, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { + var _ref5; - if (_isArray6) { - if (_i6 >= _iterator6.length) break; - _ref6 = _iterator6[_i6++]; + if (_isArray5) { + if (_i5 >= _iterator5.length) break; + _ref5 = _iterator5[_i5++]; } else { - _i6 = _iterator6.next(); - if (_i6.done) break; - _ref6 = _i6.value; + _i5 = _iterator5.next(); + if (_i5.done) break; + _ref5 = _i5.value; } - var perm = _ref6; + var perm = _ref5; basePerm = basePerm | perm.packed; } diff --git a/lib/index.js b/lib/index.js index 6a2f82f05..aa5cc93e6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -9,4 +9,27 @@ var Discord = { Client: Client }; +Discord.patchStrings = function () { + + defineProperty("bold", "**"); + defineProperty("underline", "__"); + defineProperty("strike", "~~"); + defineProperty("code", "`"); + defineProperty("codeblock", "```"); + + Object.defineProperty(String.prototype, "italic", { + get: function () { + return "*" + this + "*"; + } + }); + + function defineProperty(name, joiner) { + Object.defineProperty(String.prototype, name, { + get: function () { + return joiner + this + joiner; + } + }); + } +} + module.exports = Discord; \ No newline at end of file diff --git a/package.json b/package.json index 503109720..37b9644d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.8.4", + "version": "3.9.0", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { diff --git a/src/Member.js b/src/Member.js index 9ac6c644b..aa48d0327 100644 --- a/src/Member.js +++ b/src/Member.js @@ -52,9 +52,6 @@ class Member extends User{ } } - for(var perm of affectingOverwrites){ - console.log("hey", perm.attachFiles); - } if(affectingOverwrites.length === 0 && affectingMemberOverwrites.length === 0){ return new EvaluatedPermissions(this.evalPerms.packed); diff --git a/test/bot.1.js b/test/bot.1.js index 308b1202a..c7676e505 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -2,6 +2,8 @@ var Discord = require("../"); var mybot = new Discord.Client(); var fs = require("fs"); +Discord.patchStrings(); + var server, channel, message, sentMessage = false; counter = 1; @@ -28,7 +30,7 @@ mybot.on("message", function (message) { perms = JSON.parse(perms); mybot.sendMessage(message, - JSON.stringify(perms, null, 4).replace(new RegExp("true", "g"), "**true**") + "one" + "two".italic + "three" ); }); From 91bc1b2d1ea145103a73cd4a46e6a73ce3973f23 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 25 Oct 2015 19:34:23 +0000 Subject: [PATCH 146/151] added newline modifier --- lib/index.js | 1 + test/bot.1.js | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index aa5cc93e6..2763c3b6c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -16,6 +16,7 @@ Discord.patchStrings = function () { defineProperty("strike", "~~"); defineProperty("code", "`"); defineProperty("codeblock", "```"); + defineProperty("newline", "\n"); Object.defineProperty(String.prototype, "italic", { get: function () { diff --git a/test/bot.1.js b/test/bot.1.js index c7676e505..4917e0f93 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -30,7 +30,12 @@ mybot.on("message", function (message) { perms = JSON.parse(perms); mybot.sendMessage(message, - "one" + "two".italic + "three" + "bold".bold.newline + + "italic".italic.newline + + "underline".underline.newline + + "strike".strike.newline + + "code".code.newline + + "codeblock".codeblock.newline ); }); From 26a1850f013bcdf1e2f1dd13fbe25f4226d22816 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 25 Oct 2015 19:36:35 +0000 Subject: [PATCH 147/151] Added 3.9.0 web dist --- lib/ChannelPermissions.js | 182 +--- lib/Client.js | 1752 ++------------------------------- lib/Endpoints.js | 14 +- lib/EvaluatedPermissions.js | 188 +--- lib/Member.js | 161 +-- lib/PMChannel.js | 62 +- lib/ServerPermissions.js | 201 +--- lib/channel.js | 132 +-- lib/index.js | 37 +- lib/internal.js | 204 +--- lib/invite.js | 36 +- lib/message.js | 78 +- lib/server.js | 284 +----- lib/user.js | 61 +- web-dist/discord.3.9.0.js | 1534 +++++++++++++++++++++++++++++ web-dist/discord.min.3.9.0.js | 3 + 16 files changed, 1643 insertions(+), 3286 deletions(-) create mode 100644 web-dist/discord.3.9.0.js create mode 100644 web-dist/discord.min.3.9.0.js diff --git a/lib/ChannelPermissions.js b/lib/ChannelPermissions.js index 5193b5938..e5fe374b5 100644 --- a/lib/ChannelPermissions.js +++ b/lib/ChannelPermissions.js @@ -1,180 +1,2 @@ -"use strict"; - -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var ChannelPermissions = (function () { - function ChannelPermissions(data, channel) { - _classCallCheck(this, ChannelPermissions); - - var self = this; - - function getBit(x) { - return (self.packed >>> x & 1) === 1; - } - - this.type = data.type; //either member or role - this.id = data.id; - - if (this.type === "member") { - this.packed = channel.server.getMember("id", data.id).evalPerms.packed; - } else { - this.packed = channel.server.getRole(data.id).packed; - } - - this.packed = this.packed & ~data.deny; - this.packed = this.packed | data.allow; - - this.deny = data.deny; - this.allow = data.allow; - } - - ChannelPermissions.prototype.getBit = function getBit(x) { - return (this.packed >>> x & 1) === 1; - }; - - ChannelPermissions.prototype.setBit = function setBit() {}; - - _createClass(ChannelPermissions, [{ - key: "createInstantInvite", - get: function get() { - return this.getBit(0); - }, - set: function set(val) { - this.setBit(0, val); - } - }, { - key: "manageRoles", - get: function get() { - return this.getBit(3); - }, - set: function set(val) { - this.setBit(3, val); - } - }, { - key: "manageChannels", - get: function get() { - return this.getBit(4); - }, - set: function set(val) { - this.setBit(4, val); - } - }, { - key: "readMessages", - get: function get() { - return this.getBit(10); - }, - set: function set(val) { - this.setBit(10, val); - } - }, { - key: "sendMessages", - get: function get() { - return this.getBit(11); - }, - set: function set(val) { - this.setBit(11, val); - } - }, { - key: "sendTTSMessages", - get: function get() { - return this.getBit(12); - }, - set: function set(val) { - this.setBit(12, val); - } - }, { - key: "manageMessages", - get: function get() { - return this.getBit(13); - }, - set: function set(val) { - this.setBit(13, val); - } - }, { - key: "embedLinks", - get: function get() { - return this.getBit(14); - }, - set: function set(val) { - this.setBit(14, val); - } - }, { - key: "attachFiles", - get: function get() { - return this.getBit(15); - }, - set: function set(val) { - this.setBit(15, val); - } - }, { - key: "readMessageHistory", - get: function get() { - return this.getBit(16); - }, - set: function set(val) { - this.setBit(16, val); - } - }, { - key: "mentionEveryone", - get: function get() { - return this.getBit(17); - }, - set: function set(val) { - this.setBit(17, val); - } - }, { - key: "voiceConnect", - get: function get() { - return this.getBit(20); - }, - set: function set(val) { - this.setBit(20, val); - } - }, { - key: "voiceSpeak", - get: function get() { - return this.getBit(21); - }, - set: function set(val) { - this.setBit(21, val); - } - }, { - key: "voiceMuteMembers", - get: function get() { - return this.getBit(22); - }, - set: function set(val) { - this.setBit(22, val); - } - }, { - key: "voiceDeafenMembers", - get: function get() { - return this.getBit(23); - }, - set: function set(val) { - this.setBit(23, val); - } - }, { - key: "voiceMoveMembers", - get: function get() { - return this.getBit(24); - }, - set: function set(val) { - this.setBit(24, val); - } - }, { - key: "voiceUseVoiceActivation", - get: function get() { - return this.getBit(25); - }, - set: function set(val) { - this.setBit(25, val); - } - }]); - - return ChannelPermissions; -})(); - -module.exports = ChannelPermissions; \ No newline at end of file +"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var ChannelPermissions=(function(){function ChannelPermissions(data,channel){_classCallCheck(this,ChannelPermissions);var self=this;function getBit(x){return (self.packed >>> x & 1) === 1;}this.type = data.type; //either member or role +this.id = data.id;if(this.type === "member"){this.packed = channel.server.getMember("id",data.id).evalPerms.packed;}else {this.packed = channel.server.getRole(data.id).packed;}this.packed = this.packed & ~data.deny;this.packed = this.packed | data.allow;this.deny = data.deny;this.allow = data.allow;}ChannelPermissions.prototype.getBit = function getBit(x){return (this.packed >>> x & 1) === 1;};ChannelPermissions.prototype.setBit = function setBit(){};_createClass(ChannelPermissions,[{key:"createInstantInvite",get:function get(){return this.getBit(0);},set:function set(val){this.setBit(0,val);}},{key:"manageRoles",get:function get(){return this.getBit(3);},set:function set(val){this.setBit(3,val);}},{key:"manageChannels",get:function get(){return this.getBit(4);},set:function set(val){this.setBit(4,val);}},{key:"readMessages",get:function get(){return this.getBit(10);},set:function set(val){this.setBit(10,val);}},{key:"sendMessages",get:function get(){return this.getBit(11);},set:function set(val){this.setBit(11,val);}},{key:"sendTTSMessages",get:function get(){return this.getBit(12);},set:function set(val){this.setBit(12,val);}},{key:"manageMessages",get:function get(){return this.getBit(13);},set:function set(val){this.setBit(13,val);}},{key:"embedLinks",get:function get(){return this.getBit(14);},set:function set(val){this.setBit(14,val);}},{key:"attachFiles",get:function get(){return this.getBit(15);},set:function set(val){this.setBit(15,val);}},{key:"readMessageHistory",get:function get(){return this.getBit(16);},set:function set(val){this.setBit(16,val);}},{key:"mentionEveryone",get:function get(){return this.getBit(17);},set:function set(val){this.setBit(17,val);}},{key:"voiceConnect",get:function get(){return this.getBit(20);},set:function set(val){this.setBit(20,val);}},{key:"voiceSpeak",get:function get(){return this.getBit(21);},set:function set(val){this.setBit(21,val);}},{key:"voiceMuteMembers",get:function get(){return this.getBit(22);},set:function set(val){this.setBit(22,val);}},{key:"voiceDeafenMembers",get:function get(){return this.getBit(23);},set:function set(val){this.setBit(23,val);}},{key:"voiceMoveMembers",get:function get(){return this.getBit(24);},set:function set(val){this.setBit(24,val);}},{key:"voiceUseVoiceActivation",get:function get(){return this.getBit(25);},set:function set(val){this.setBit(25,val);}}]);return ChannelPermissions;})();module.exports = ChannelPermissions; diff --git a/lib/Client.js b/lib/Client.js index fc69385e9..335061bd6 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1,1681 +1,75 @@ //discord.js modules -"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 Endpoints = require("./Endpoints.js"); -var User = require("./user.js"); -var Server = require("./server.js"); -var Channel = require("./channel.js"); -var Message = require("./message.js"); -var Invite = require("./invite.js"); -var PMChannel = require("./PMChannel.js"); - -var gameMap = require("../ref/gameMap.json"); - -//node modules -var request = require("superagent"); -var WebSocket = require("ws"); -var fs = require("fs"); - -var defaultOptions = { - queue: false -}; - -var Client = (function () { - function Client() { - var options = arguments.length <= 0 || arguments[0] === undefined ? defaultOptions : arguments[0]; - var token = arguments.length <= 1 || arguments[1] === undefined ? undefined : arguments[1]; - - _classCallCheck(this, Client); - - /* - When created, if a token is specified the Client will - try connecting with it. If the token is incorrect, no - further efforts will be made to connect. - */ - this.options = options; - this.options.queue = this.options.queue; - this.token = token; - this.state = 0; - this.websocket = null; - this.events = {}; - this.user = null; - this.alreadySentData = false; - this.serverCreateListener = {}; - this.typingIntervals = {}; - this.email = "abc"; - this.password = "abc"; - - /* - State values: - 0 - idle - 1 - logging in - 2 - logged in - 3 - ready - 4 - disconnected - */ - - this.userCache = []; - this.channelCache = []; - this.serverCache = []; - this.pmChannelCache = []; - this.readyTime = null; - this.checkingQueue = {}; - this.userTypingListener = {}; - this.queue = {}; - - this.__idleTime = null; - this.__gameId = null; - } - - Client.prototype.sendPacket = function sendPacket(JSONObject) { - if (this.websocket.readyState === 1) { - this.websocket.send(JSON.stringify(JSONObject)); - } - }; - - //def debug - - Client.prototype.debug = function debug(message) { - this.trigger("debug", message); - }; - - Client.prototype.on = function on(event, fn) { - this.events[event] = fn; - }; - - Client.prototype.off = function off(event) { - this.events[event] = null; - }; - - Client.prototype.keepAlive = function keepAlive() { - this.debug("keep alive triggered"); - this.sendPacket({ - op: 1, - d: Date.now() - }); - }; - - //def trigger - - Client.prototype.trigger = function trigger(event) { - var args = []; - for (var arg in arguments) { - args.push(arguments[arg]); - } - var evt = this.events[event]; - if (evt) { - evt.apply(this, args.slice(1)); - } - }; - - //def login - - Client.prototype.login = function login() { - var email = arguments.length <= 0 || arguments[0] === undefined ? "foo@bar.com" : arguments[0]; - var password = arguments.length <= 1 || arguments[1] === undefined ? "pass1234" : arguments[1]; - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, token) {} : arguments[2]; - - var self = this; - - return new Promise(function (resolve, reject) { - if (self.state === 0 || self.state === 4) { - - self.state = 1; //set the state to logging in - - self.email = email; - self.password = password; - - request.post(Endpoints.LOGIN).send({ - email: email, - password: password - }).end(function (err, res) { - - if (err) { - self.state = 4; //set state to disconnected - self.trigger("disconnected"); - if (self.websocket) { - self.websocket.close(); +"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 Endpoints=require("./Endpoints.js");var User=require("./user.js");var Server=require("./server.js");var Channel=require("./channel.js");var Message=require("./message.js");var Invite=require("./invite.js");var PMChannel=require("./PMChannel.js");var gameMap=require("../ref/gameMap.json"); //node modules +var request=require("superagent");var WebSocket=require("ws");var fs=require("fs");var defaultOptions={queue:false};var Client=(function(){function Client(){var options=arguments.length <= 0 || arguments[0] === undefined?defaultOptions:arguments[0];var token=arguments.length <= 1 || arguments[1] === undefined?undefined:arguments[1];_classCallCheck(this,Client); /* + When created, if a token is specified the Client will + try connecting with it. If the token is incorrect, no + further efforts will be made to connect. + */this.options = options;this.options.queue = this.options.queue;this.token = token;this.state = 0;this.websocket = null;this.events = {};this.user = null;this.alreadySentData = false;this.serverCreateListener = {};this.typingIntervals = {};this.email = "abc";this.password = "abc"; /* + State values: + 0 - idle + 1 - logging in + 2 - logged in + 3 - ready + 4 - disconnected + */this.userCache = [];this.channelCache = [];this.serverCache = [];this.pmChannelCache = [];this.readyTime = null;this.checkingQueue = {};this.userTypingListener = {};this.queue = {};this.__idleTime = null;this.__gameId = null;}Client.prototype.sendPacket = function sendPacket(JSONObject){if(this.websocket.readyState === 1){this.websocket.send(JSON.stringify(JSONObject));}}; //def debug +Client.prototype.debug = function debug(message){this.trigger("debug",message);};Client.prototype.on = function on(event,fn){this.events[event] = fn;};Client.prototype.off = function off(event){this.events[event] = null;};Client.prototype.keepAlive = function keepAlive(){this.debug("keep alive triggered");this.sendPacket({op:1,d:Date.now()});}; //def trigger +Client.prototype.trigger = function trigger(event){var args=[];for(var arg in arguments) {args.push(arguments[arg]);}var evt=this.events[event];if(evt){evt.apply(this,args.slice(1));}}; //def login +Client.prototype.login = function login(){var email=arguments.length <= 0 || arguments[0] === undefined?"foo@bar.com":arguments[0];var password=arguments.length <= 1 || arguments[1] === undefined?"pass1234":arguments[1];var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,token){}:arguments[2];var self=this;return new Promise(function(resolve,reject){if(self.state === 0 || self.state === 4){self.state = 1; //set the state to logging in +self.email = email;self.password = password;request.post(Endpoints.LOGIN).send({email:email,password:password}).end(function(err,res){if(err){self.state = 4; //set state to disconnected +self.trigger("disconnected");if(self.websocket){self.websocket.close();}callback(err);reject(err);}else {self.state = 2; //set state to logged in (not yet ready) +self.token = res.body.token; //set our token +self.getGateway().then(function(url){self.createws(url);callback(null,self.token);resolve(self.token);})["catch"](function(err){callback(err);reject(err);});}});}else {reject(new Error("Client already logging in or ready"));}});};Client.prototype.logout = function logout(){var callback=arguments.length <= 0 || arguments[0] === undefined?function(err){}:arguments[0];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.LOGOUT).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {self.websocket.close();self.state = 4;callback();resolve();}});});};Client.prototype.createServer = function createServer(name,region){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,server){}:arguments[2];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.SERVERS).set("authorization",self.token).send({name:name,region:region}).end(function(err,res){if(err){callback(err);reject(err);}else { // potentially redundant in future +// creating here does NOT give us the channels of the server +// so we must wait for the guild_create event. +self.serverCreateListener[res.body.id] = [resolve,callback]; /*var srv = self.addServer(res.body); + callback(null, srv); + resolve(srv);*/}});});};Client.prototype.createChannel = function createChannel(server,channelName,channelType){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,chann){}:arguments[3];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.SERVERS + "/" + self.resolveServerID(server) + "/channels").set("authorization",self.token).send({name:channelName,type:channelType}).end(function(err,res){if(err){callback(err);reject(err);}else {var server=self.getServer("id",res.body.guild_id);var chann=self.addChannel(res.body,res.body.guild_id);server.addChannel(chann);callback(null,chann);resolve(chann);}});});};Client.prototype.leaveServer = function leaveServer(server){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,server){}:arguments[1];var self=this;return new Promise(function(resolve,reject){request.del(Endpoints.SERVERS + "/" + self.resolveServerID(server)).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {self.serverCache.splice(self.serverCache.indexOf(server),1);callback(null);resolve();}});});};Client.prototype.createInvite = function createInvite(serverOrChannel,options){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,invite){}:arguments[2];var self=this;return new Promise(function(resolve,reject){var destination;if(serverOrChannel instanceof Server){destination = serverOrChannel.id;}else if(serverOrChannel instanceof Channel){destination = serverOrChannel.id;}else {destination = serverOrChannel;}options = options || {};options.max_age = options.maxAge || 0;options.max_uses = options.maxUses || 0;options.temporary = options.temporary || false;options.xkcdpass = options.xkcd || false;request.post(Endpoints.CHANNELS + "/" + destination + "/invites").set("authorization",self.token).send(options).end(function(err,res){if(err){callback(err);reject(err);}else {var inv=new Invite(res.body,self);callback(null,inv);resolve(inv);}});});};Client.prototype.startPM = function startPM(user){var self=this;return new Promise(function(resolve,reject){var userId=user;if(user instanceof User){userId = user.id;}request.post(Endpoints.USERS + "/" + self.user.id + "/channels").set("authorization",self.token).send({recipient_id:userId}).end(function(err,res){if(err){reject(err);}else {resolve(self.addPMChannel(res.body));}});});};Client.prototype.reply = function reply(destination,message,tts){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var self=this;return new Promise(function(response,reject){if(typeof tts === "function"){ // tts is a function, which means the developer wants this to be the callback +callback = tts;tts = false;}var user=destination.sender;self.sendMessage(destination,message,tts,callback,user + ", ").then(response)["catch"](reject);});};Client.prototype.deleteMessage = function deleteMessage(message,timeout){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,msg){}:arguments[2];var self=this;return new Promise(function(resolve,reject){if(timeout){setTimeout(remove,timeout);}else {remove();}function remove(){request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization",self.token).end(function(err,res){if(err){bad();}else {good();}});}function good(){callback();resolve();}function bad(err){callback(err);reject(err);}});};Client.prototype.updateMessage = function updateMessage(message,content){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,msg){}:arguments[2];var self=this;var prom=new Promise(function(resolve,reject){content = content instanceof Array?content.join("\n"):content;if(self.options.queue){if(!self.queue[message.channel.id]){self.queue[message.channel.id] = [];}self.queue[message.channel.id].push({action:"updateMessage",message:message,content:content,then:good,error:bad});self.checkQueue(message.channel.id);}else {self._updateMessage(message,content).then(good)["catch"](bad);}function good(msg){prom.message = msg;callback(null,msg);resolve(msg);}function bad(error){prom.error = error;callback(error);reject(error);}});return prom;};Client.prototype.setUsername = function setUsername(newName){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){request.patch(Endpoints.API + "/users/@me").set("authorization",self.token).send({avatar:self.user.avatar,email:self.email,new_password:null,password:self.password,username:newName}).end(function(err){callback(err);if(err)reject(err);else resolve();});});};Client.prototype.getChannelLogs = function getChannelLogs(channel){var amount=arguments.length <= 1 || arguments[1] === undefined?500:arguments[1];var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,logs){}:arguments[2];var self=this;return new Promise(function(resolve,reject){var channelID=channel;if(channel instanceof Channel){channelID = channel.id;}request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {var logs=[];var channel=self.getChannel("id",channelID);for(var _iterator=res.body,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var message=_ref;var mentions=[];for(var _iterator2=message.mentions,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var mention=_ref2;mentions.push(self.addUser(mention));}var author=self.addUser(message.author);logs.push(new Message(message,channel,mentions,author));}callback(null,logs);resolve(logs);}});});};Client.prototype.deleteChannel = function deleteChannel(channel){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){var channelID=channel;if(channel instanceof Channel){channelID = channel.id;}request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization",self.token).end(function(err){if(err){callback(err);reject(err);}else {callback(null);resolve();}});});};Client.prototype.joinServer = function joinServer(invite){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,server){}:arguments[1];var self=this;return new Promise(function(resolve,reject){var id=invite instanceof Invite?invite.code:invite;request.post(Endpoints.API + "/invite/" + id).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {if(self.getServer("id",res.body.guild.id)){resolve(self.getServer("id",res.body.guild.id));}else {self.serverCreateListener[res.body.guild.id] = [resolve,callback];}}});});};Client.prototype.sendFile = function sendFile(destination,file){var fileName=arguments.length <= 2 || arguments[2] === undefined?"image.png":arguments[2];var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var self=this;var prom=new Promise(function(resolve,reject){var fstream;if(typeof file === "string" || file instanceof String){fstream = fs.createReadStream(file);fileName = file;}else {fstream = file;}self.resolveDestination(destination).then(send)["catch"](bad);function send(destination){if(self.options.queue){ //queue send file too +if(!self.queue[destination]){self.queue[destination] = [];}self.queue[destination].push({action:"sendFile",attachment:fstream,attachmentName:fileName,then:good,error:bad});self.checkQueue(destination);}else { //not queue +self._sendFile(destination,fstream,fileName).then(good)["catch"](bad);}}function good(msg){prom.message = msg;callback(null,msg);resolve(msg);}function bad(err){prom.error = err;callback(err);reject(err);}});return prom;};Client.prototype.sendMessage = function sendMessage(destination,message,tts){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var premessage=arguments.length <= 4 || arguments[4] === undefined?"":arguments[4];var self=this;var prom=new Promise(function(resolve,reject){if(typeof tts === "function"){ // tts is a function, which means the developer wants this to be the callback +callback = tts;tts = false;}message = premessage + resolveMessage(message);var mentions=resolveMentions();self.resolveDestination(destination).then(send)["catch"](error);function error(err){callback(err);reject(err);}function send(destination){if(self.options.queue){ //we're QUEUEING messages, so sending them sequentially based on servers. +if(!self.queue[destination]){self.queue[destination] = [];}self.queue[destination].push({action:"sendMessage",content:message,mentions:mentions,tts:!!tts, //incase it's not a boolean +then:mgood,error:mbad});self.checkQueue(destination);}else {self._sendMessage(destination,message,tts,mentions).then(mgood)["catch"](mbad);}}function mgood(msg){prom.message = msg;callback(null,msg);resolve(msg);}function mbad(error){prom.error = error;callback(error);reject(error);}function resolveMessage(){var msg=message;if(message instanceof Array){msg = message.join("\n");}return msg;}function resolveMentions(){var _mentions=[];for(var _iterator3=message.match(/<@[^>]*>/g) || [],_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[Symbol.iterator]();;) {var _ref3;if(_isArray3){if(_i3 >= _iterator3.length)break;_ref3 = _iterator3[_i3++];}else {_i3 = _iterator3.next();if(_i3.done)break;_ref3 = _i3.value;}var mention=_ref3;_mentions.push(mention.substring(2,mention.length - 1));}return _mentions;}});return prom;}; //def createws +Client.prototype.createws = function createws(url){if(this.websocket)return false;var self=this; //good to go +this.websocket = new WebSocket(url); //open +this.websocket.onopen = function(){self.trySendConnData(); //try connecting +}; //close +this.websocket.onclose = function(){self.trigger("disconnected");}; //message +this.websocket.onmessage = function(e){var dat=false,data={};try{dat = JSON.parse(e.data);data = dat.d;}catch(err) {self.trigger("error",err,e);return;}self.trigger("raw",dat); //valid message +switch(dat.t){case "READY":self.debug("received ready packet");self.user = self.addUser(data.user);for(var _iterator4=data.guilds,_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[Symbol.iterator]();;) {var _ref4;if(_isArray4){if(_i4 >= _iterator4.length)break;_ref4 = _iterator4[_i4++];}else {_i4 = _iterator4.next();if(_i4.done)break;_ref4 = _i4.value;}var _server=_ref4;var server=self.addServer(_server);}for(var _iterator5=data.private_channels,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var _pmc=_ref5;var pmc=self.addPMChannel(_pmc);}self.trigger("ready");self.readyTime = Date.now();self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users.");self.state = 3;setInterval(function(){self.keepAlive.apply(self);},data.heartbeat_interval);break;case "MESSAGE_CREATE":self.debug("received message");var mentions=[];data.mentions = data.mentions || []; //for some reason this was not defined at some point? +for(var _iterator6=data.mentions,_isArray6=Array.isArray(_iterator6),_i6=0,_iterator6=_isArray6?_iterator6:_iterator6[Symbol.iterator]();;) {var _ref6;if(_isArray6){if(_i6 >= _iterator6.length)break;_ref6 = _iterator6[_i6++];}else {_i6 = _iterator6.next();if(_i6.done)break;_ref6 = _i6.value;}var mention=_ref6;mentions.push(self.addUser(mention));}var channel=self.getChannel("id",data.channel_id);if(channel){var msg=channel.addMessage(new Message(data,channel,mentions,self.addUser(data.author)));self.trigger("message",msg);}break;case "MESSAGE_DELETE":self.debug("message deleted");var channel=self.getChannel("id",data.channel_id);var message=channel.getMessage("id",data.id);if(message){self.trigger("messageDelete",channel,message);channel.messages.splice(channel.messages.indexOf(message),1);}else { //don't have the cache of that message ;( +self.trigger("messageDelete",channel);}break;case "MESSAGE_UPDATE":self.debug("message updated");var channel=self.getChannel("id",data.channel_id);var formerMessage=channel.getMessage("id",data.id);if(formerMessage){ //new message might be partial, so we need to fill it with whatever the old message was. +var info={};for(var key in formerMessage) {info[key] = formerMessage[key];}for(var key in data) {info[key] = data[key];}var mentions=[];for(var _iterator7=info.mentions,_isArray7=Array.isArray(_iterator7),_i7=0,_iterator7=_isArray7?_iterator7:_iterator7[Symbol.iterator]();;) {var _ref7;if(_isArray7){if(_i7 >= _iterator7.length)break;_ref7 = _iterator7[_i7++];}else {_i7 = _iterator7.next();if(_i7.done)break;_ref7 = _i7.value;}var mention=_ref7;mentions.push(self.addUser(mention));}var newMessage=new Message(info,channel,mentions,formerMessage.author);self.trigger("messageUpdate",newMessage,formerMessage);channel.messages[channel.messages.indexOf(formerMessage)] = newMessage;} // message isn't in cache, and if it's a partial it could cause +// all hell to break loose... best to just act as if nothing happened +break;case "GUILD_DELETE":var server=self.getServer("id",data.id);if(server){self.serverCache.splice(self.serverCache.indexOf(server),1);self.trigger("serverDelete",server);}break;case "CHANNEL_DELETE":var channel=self.getChannel("id",data.id);if(channel){var server=channel.server;if(server){server.channels.splice(server.channels.indexOf(channel),1);}self.trigger("channelDelete",channel);self.serverCache.splice(self.serverCache.indexOf(channel),1);}break;case "GUILD_CREATE":var server=self.getServer("id",data.id);if(!server){ //if server doesn't already exist because duh +server = self.addServer(data);} /*else if(server.channels.length === 0){ + + var srv = new Server(data, self); + for(channel of data.channels){ + srv.channels.push(new Channel(channel, data.id)); } - callback(err); - reject(err); - } else { - self.state = 2; //set state to logged in (not yet ready) - self.token = res.body.token; //set our token - - self.getGateway().then(function (url) { - self.createws(url); - callback(null, self.token); - resolve(self.token); - })["catch"](function (err) { - callback(err); - reject(err); - }); - } - }); - } else { - reject(new Error("Client already logging in or ready")); - } - }); - }; - - Client.prototype.logout = function logout() { - var callback = arguments.length <= 0 || arguments[0] === undefined ? function (err) {} : arguments[0]; - - var self = this; - - return new Promise(function (resolve, reject) { - - request.post(Endpoints.LOGOUT).set("authorization", self.token).end(function (err, res) { - - if (err) { - callback(err); - reject(err); - } else { - self.websocket.close(); - self.state = 4; - callback(); - resolve(); - } - }); - }); - }; - - Client.prototype.createServer = function createServer(name, region) { - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, server) {} : arguments[2]; - - var self = this; - return new Promise(function (resolve, reject) { - - request.post(Endpoints.SERVERS).set("authorization", self.token).send({ - name: name, - region: region - }).end(function (err, res) { - if (err) { - callback(err); - reject(err); - } else { - // potentially redundant in future - // creating here does NOT give us the channels of the server - // so we must wait for the guild_create event. - self.serverCreateListener[res.body.id] = [resolve, callback]; - /*var srv = self.addServer(res.body); - callback(null, srv); - resolve(srv);*/ - } - }); - }); - }; - - Client.prototype.createChannel = function createChannel(server, channelName, channelType) { - var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, chann) {} : arguments[3]; - - var self = this; - - return new Promise(function (resolve, reject) { - - request.post(Endpoints.SERVERS + "/" + self.resolveServerID(server) + "/channels").set("authorization", self.token).send({ - name: channelName, - type: channelType - }).end(function (err, res) { - - if (err) { - callback(err); - reject(err); - } else { - var server = self.getServer("id", res.body.guild_id); - var chann = self.addChannel(res.body, res.body.guild_id); - server.addChannel(chann); - callback(null, chann); - resolve(chann); - } - }); - }); - }; - - Client.prototype.leaveServer = function leaveServer(server) { - var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, server) {} : arguments[1]; - - var self = this; - - return new Promise(function (resolve, reject) { - - request.del(Endpoints.SERVERS + "/" + self.resolveServerID(server)).set("authorization", self.token).end(function (err, res) { - - if (err) { - callback(err); - reject(err); - } else { - self.serverCache.splice(self.serverCache.indexOf(server), 1); - callback(null); - resolve(); - } - }); - }); - }; - - Client.prototype.createInvite = function createInvite(serverOrChannel, options) { - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, invite) {} : arguments[2]; - - var self = this; - - return new Promise(function (resolve, reject) { - - var destination; - - if (serverOrChannel instanceof Server) { - destination = serverOrChannel.id; - } else if (serverOrChannel instanceof Channel) { - destination = serverOrChannel.id; - } else { - destination = serverOrChannel; - } - - options = options || {}; - options.max_age = options.maxAge || 0; - options.max_uses = options.maxUses || 0; - options.temporary = options.temporary || false; - options.xkcdpass = options.xkcd || false; - - request.post(Endpoints.CHANNELS + "/" + destination + "/invites").set("authorization", self.token).send(options).end(function (err, res) { - if (err) { - callback(err); - reject(err); - } else { - var inv = new Invite(res.body, self); - callback(null, inv); - resolve(inv); - } - }); - }); - }; - - Client.prototype.startPM = function startPM(user) { - - var self = this; - - return new Promise(function (resolve, reject) { - var userId = user; - if (user instanceof User) { - userId = user.id; - } - request.post(Endpoints.USERS + "/" + self.user.id + "/channels").set("authorization", self.token).send({ - recipient_id: userId - }).end(function (err, res) { - if (err) { - reject(err); - } else { - resolve(self.addPMChannel(res.body)); - } - }); - }); - }; - - Client.prototype.reply = function reply(destination, message, tts) { - var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; - - var self = this; - - return new Promise(function (response, reject) { - - if (typeof tts === "function") { - // tts is a function, which means the developer wants this to be the callback - callback = tts; - tts = false; - } - - var user = destination.sender; - self.sendMessage(destination, message, tts, callback, user + ", ").then(response)["catch"](reject); - }); - }; - - Client.prototype.deleteMessage = function deleteMessage(message, timeout) { - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, msg) {} : arguments[2]; - - var self = this; - - return new Promise(function (resolve, reject) { - if (timeout) { - setTimeout(remove, timeout); - } else { - remove(); - } - - function remove() { - request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).end(function (err, res) { - if (err) { - bad(); - } else { - good(); - } - }); - } - - function good() { - callback(); - resolve(); - } - - function bad(err) { - callback(err); - reject(err); - } - }); - }; - - Client.prototype.updateMessage = function updateMessage(message, content) { - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, msg) {} : arguments[2]; - - var self = this; - - var prom = new Promise(function (resolve, reject) { - - content = content instanceof Array ? content.join("\n") : content; - - if (self.options.queue) { - if (!self.queue[message.channel.id]) { - self.queue[message.channel.id] = []; - } - self.queue[message.channel.id].push({ - action: "updateMessage", - message: message, - content: content, - then: good, - error: bad - }); - - self.checkQueue(message.channel.id); - } else { - self._updateMessage(message, content).then(good)["catch"](bad); - } - - function good(msg) { - prom.message = msg; - callback(null, msg); - resolve(msg); - } - - function bad(error) { - prom.error = error; - callback(error); - reject(error); - } - }); - - return prom; - }; - - Client.prototype.setUsername = function setUsername(newName) { - var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; - - var self = this; - - return new Promise(function (resolve, reject) { - request.patch(Endpoints.API + "/users/@me").set("authorization", self.token).send({ - avatar: self.user.avatar, - email: self.email, - new_password: null, - password: self.password, - username: newName - }).end(function (err) { - callback(err); - if (err) reject(err);else resolve(); - }); - }); - }; - - Client.prototype.getChannelLogs = function getChannelLogs(channel) { - var amount = arguments.length <= 1 || arguments[1] === undefined ? 500 : arguments[1]; - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, logs) {} : arguments[2]; - - var self = this; - - return new Promise(function (resolve, reject) { - - var channelID = channel; - if (channel instanceof Channel) { - channelID = channel.id; - } - - request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization", self.token).end(function (err, res) { - - if (err) { - callback(err); - reject(err); - } else { - var logs = []; - - var channel = self.getChannel("id", channelID); - - for (var _iterator = res.body, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { - var _ref; - - if (_isArray) { - if (_i >= _iterator.length) break; - _ref = _iterator[_i++]; - } else { - _i = _iterator.next(); - if (_i.done) break; - _ref = _i.value; - } - - var message = _ref; - - var mentions = []; - for (var _iterator2 = message.mentions, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { - var _ref2; - - if (_isArray2) { - if (_i2 >= _iterator2.length) break; - _ref2 = _iterator2[_i2++]; - } else { - _i2 = _iterator2.next(); - if (_i2.done) break; - _ref2 = _i2.value; - } - - var mention = _ref2; - - mentions.push(self.addUser(mention)); - } - - var author = self.addUser(message.author); - - logs.push(new Message(message, channel, mentions, author)); - } - callback(null, logs); - resolve(logs); - } - }); - }); - }; - - Client.prototype.deleteChannel = function deleteChannel(channel) { - var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; - - var self = this; - - return new Promise(function (resolve, reject) { - - var channelID = channel; - if (channel instanceof Channel) { - channelID = channel.id; - } - - request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization", self.token).end(function (err) { - if (err) { - callback(err); - reject(err); - } else { - callback(null); - resolve(); - } - }); - }); - }; - - Client.prototype.joinServer = function joinServer(invite) { - var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, server) {} : arguments[1]; - - var self = this; - - return new Promise(function (resolve, reject) { - - var id = invite instanceof Invite ? invite.code : invite; - - request.post(Endpoints.API + "/invite/" + id).set("authorization", self.token).end(function (err, res) { - if (err) { - callback(err); - reject(err); - } else { - if (self.getServer("id", res.body.guild.id)) { - resolve(self.getServer("id", res.body.guild.id)); - } else { - self.serverCreateListener[res.body.guild.id] = [resolve, callback]; - } - } - }); - }); - }; - - Client.prototype.sendFile = function sendFile(destination, file) { - var fileName = arguments.length <= 2 || arguments[2] === undefined ? "image.png" : arguments[2]; - var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; - - var self = this; - - var prom = new Promise(function (resolve, reject) { - - var fstream; - - if (typeof file === "string" || file instanceof String) { - fstream = fs.createReadStream(file); - fileName = file; - } else { - fstream = file; - } - - self.resolveDestination(destination).then(send)["catch"](bad); - - function send(destination) { - if (self.options.queue) { - //queue send file too - if (!self.queue[destination]) { - self.queue[destination] = []; - } - - self.queue[destination].push({ - action: "sendFile", - attachment: fstream, - attachmentName: fileName, - then: good, - error: bad - }); - - self.checkQueue(destination); - } else { - //not queue - self._sendFile(destination, fstream, fileName).then(good)["catch"](bad); - } - } - - function good(msg) { - prom.message = msg; - callback(null, msg); - resolve(msg); - } - - function bad(err) { - prom.error = err; - callback(err); - reject(err); - } - }); - - return prom; - }; - - Client.prototype.sendMessage = function sendMessage(destination, message, tts) { - var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; - var premessage = arguments.length <= 4 || arguments[4] === undefined ? "" : arguments[4]; - - var self = this; - - var prom = new Promise(function (resolve, reject) { - - if (typeof tts === "function") { - // tts is a function, which means the developer wants this to be the callback - callback = tts; - tts = false; - } - - message = premessage + resolveMessage(message); - var mentions = resolveMentions(); - self.resolveDestination(destination).then(send)["catch"](error); - - function error(err) { - callback(err); - reject(err); - } - - function send(destination) { - if (self.options.queue) { - //we're QUEUEING messages, so sending them sequentially based on servers. - if (!self.queue[destination]) { - self.queue[destination] = []; - } - - self.queue[destination].push({ - action: "sendMessage", - content: message, - mentions: mentions, - tts: !!tts, //incase it's not a boolean - then: mgood, - error: mbad - }); - - self.checkQueue(destination); - } else { - self._sendMessage(destination, message, tts, mentions).then(mgood)["catch"](mbad); - } - } - - function mgood(msg) { - prom.message = msg; - callback(null, msg); - resolve(msg); - } - - function mbad(error) { - prom.error = error; - callback(error); - reject(error); - } - - function resolveMessage() { - var msg = message; - if (message instanceof Array) { - msg = message.join("\n"); - } - return msg; - } - - function resolveMentions() { - var _mentions = []; - for (var _iterator3 = message.match(/<@[^>]*>/g) || [], _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { - var _ref3; - - if (_isArray3) { - if (_i3 >= _iterator3.length) break; - _ref3 = _iterator3[_i3++]; - } else { - _i3 = _iterator3.next(); - if (_i3.done) break; - _ref3 = _i3.value; - } - - var mention = _ref3; - - _mentions.push(mention.substring(2, mention.length - 1)); - } - return _mentions; - } - }); - - return prom; - }; - - //def createws - - Client.prototype.createws = function createws(url) { - if (this.websocket) return false; - - var self = this; - - //good to go - this.websocket = new WebSocket(url); - - //open - this.websocket.onopen = function () { - self.trySendConnData(); //try connecting - }; - - //close - this.websocket.onclose = function () { - self.trigger("disconnected"); - }; - - //message - this.websocket.onmessage = function (e) { - - var dat = false, - data = {}; - - try { - dat = JSON.parse(e.data); - data = dat.d; - } catch (err) { - self.trigger("error", err, e); - return; - } - - self.trigger("raw", dat); - - //valid message - switch (dat.t) { - - case "READY": - self.debug("received ready packet"); - - self.user = self.addUser(data.user); - - for (var _iterator4 = data.guilds, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { - var _ref4; - - if (_isArray4) { - if (_i4 >= _iterator4.length) break; - _ref4 = _iterator4[_i4++]; - } else { - _i4 = _iterator4.next(); - if (_i4.done) break; - _ref4 = _i4.value; - } - - var _server = _ref4; - - var server = self.addServer(_server); - } - - for (var _iterator5 = data.private_channels, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { - var _ref5; - - if (_isArray5) { - if (_i5 >= _iterator5.length) break; - _ref5 = _iterator5[_i5++]; - } else { - _i5 = _iterator5.next(); - if (_i5.done) break; - _ref5 = _i5.value; - } - - var _pmc = _ref5; - - var pmc = self.addPMChannel(_pmc); - } - - self.trigger("ready"); - self.readyTime = Date.now(); - self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users."); - self.state = 3; - setInterval(function () { - self.keepAlive.apply(self); - }, data.heartbeat_interval); - - break; - case "MESSAGE_CREATE": - self.debug("received message"); - - var mentions = []; - data.mentions = data.mentions || []; //for some reason this was not defined at some point? - for (var _iterator6 = data.mentions, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { - var _ref6; - - if (_isArray6) { - if (_i6 >= _iterator6.length) break; - _ref6 = _iterator6[_i6++]; - } else { - _i6 = _iterator6.next(); - if (_i6.done) break; - _ref6 = _i6.value; - } - - var mention = _ref6; - - mentions.push(self.addUser(mention)); - } - - var channel = self.getChannel("id", data.channel_id); - if (channel) { - var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); - self.trigger("message", msg); - } - - break; - case "MESSAGE_DELETE": - self.debug("message deleted"); - - var channel = self.getChannel("id", data.channel_id); - var message = channel.getMessage("id", data.id); - if (message) { - self.trigger("messageDelete", channel, message); - channel.messages.splice(channel.messages.indexOf(message), 1); - } else { - //don't have the cache of that message ;( - self.trigger("messageDelete", channel); - } - break; - case "MESSAGE_UPDATE": - self.debug("message updated"); - - var channel = self.getChannel("id", data.channel_id); - var formerMessage = channel.getMessage("id", data.id); - - if (formerMessage) { - - //new message might be partial, so we need to fill it with whatever the old message was. - var info = {}; - - for (var key in formerMessage) { - info[key] = formerMessage[key]; - } - - for (var key in data) { - info[key] = data[key]; - } - - var mentions = []; - for (var _iterator7 = info.mentions, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) { - var _ref7; - - if (_isArray7) { - if (_i7 >= _iterator7.length) break; - _ref7 = _iterator7[_i7++]; - } else { - _i7 = _iterator7.next(); - if (_i7.done) break; - _ref7 = _i7.value; - } - - var mention = _ref7; - - mentions.push(self.addUser(mention)); - } - - var newMessage = new Message(info, channel, mentions, formerMessage.author); - - self.trigger("messageUpdate", newMessage, formerMessage); - - channel.messages[channel.messages.indexOf(formerMessage)] = newMessage; - } - - // message isn't in cache, and if it's a partial it could cause - // all hell to break loose... best to just act as if nothing happened - - break; - - case "GUILD_DELETE": - - var server = self.getServer("id", data.id); - - if (server) { - self.serverCache.splice(self.serverCache.indexOf(server), 1); - self.trigger("serverDelete", server); - } - - break; - - case "CHANNEL_DELETE": - - var channel = self.getChannel("id", data.id); - - if (channel) { - - var server = channel.server; - - if (server) { - - server.channels.splice(server.channels.indexOf(channel), 1); - } - - self.trigger("channelDelete", channel); - - self.serverCache.splice(self.serverCache.indexOf(channel), 1); - } - - break; - - case "GUILD_CREATE": - - var server = self.getServer("id", data.id); - - if (!server) { - //if server doesn't already exist because duh - server = self.addServer(data); - } /*else if(server.channels.length === 0){ - - var srv = new Server(data, self); - for(channel of data.channels){ - srv.channels.push(new Channel(channel, data.id)); - } - self.serverCache[self.serverCache.indexOf(server)] = srv; - - }*/ - - if (self.serverCreateListener[data.id]) { - var cbs = self.serverCreateListener[data.id]; - cbs[0](server); //promise then callback - cbs[1](null, server); //legacy callback - self.serverCreateListener[data.id] = null; - } - - self.trigger("serverCreate", server); - - break; - - case "CHANNEL_CREATE": - - var channel = self.getChannel("id", data.id); - - if (!channel) { - - var chann; - if (data.is_private) { - chann = self.addPMChannel(data); - } else { - chann = self.addChannel(data, data.guild_id); - } - var srv = self.getServer("id", data.guild_id); - if (srv) { - srv.addChannel(chann); - } - self.trigger("channelCreate", chann); - } - - break; - - case "GUILD_MEMBER_ADD": - - var server = self.getServer("id", data.guild_id); - - if (server) { - - var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. - - self.trigger("serverNewMember", server.addMember(user, data.roles), server); - } - - break; - - case "GUILD_MEMBER_REMOVE": - - var server = self.getServer("id", data.guild_id); - - if (server) { - - var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. - - server.removeMember("id", user.id); - - self.trigger("serverRemoveMember", user, server); - } - - break; - - case "USER_UPDATE": - - if (self.user && data.id === self.user.id) { - - var newUser = new User(data); //not actually adding to the cache - - self.trigger("userUpdate", newUser, self.user); - - if (~self.userCache.indexOf(self.user)) { - self.userCache[self.userCache.indexOf(self.user)] = newUser; - } - - self.user = newUser; - } - - break; - - case "PRESENCE_UPDATE": - - var userInCache = self.getUser("id", data.user.id); - - if (userInCache) { - //user exists - - data.user.username = data.user.username || userInCache.username; - data.user.id = data.user.id || userInCache.id; - data.user.discriminator = data.user.discriminator || userInCache.discriminator; - data.user.avatar = data.user.avatar || userInCache.avatar; - - var presenceUser = new User(data.user); - if (presenceUser.equalsStrict(userInCache)) { - //they're exactly the same, an actual presence update - self.trigger("presence", { - user: userInCache, - oldStatus: userInCache.status, - status: data.status, - server: self.getServer("id", data.guild_id), - gameId: data.game_id - }); - userInCache.status = data.status; - userInCache.gameId = data.game_id; - } else { - //one of their details changed. - self.userCache[self.userCache.indexOf(userInCache)] = presenceUser; - self.trigger("userUpdate", userInCache, presenceUser); - } - } - - break; - - case "CHANNEL_UPDATE": - - var channelInCache = self.getChannel("id", data.id), - serverInCache = self.getServer("id", data.guild_id); - - if (channelInCache && serverInCache) { - - var newChann = new Channel(data, serverInCache); - newChann.messages = channelInCache.messages; - - self.trigger("channelUpdate", channelInCache, newChann); - - self.channelCache[self.channelCache.indexOf(channelInCache)] = newChann; - } - - break; - - case "TYPING_START": - - var userInCache = self.getUser("id", data.user_id); - var channelInCache = self.getChannel("id", data.channel_id); - - if (!self.userTypingListener[data.user_id] || self.userTypingListener[data.user_id] === -1) { - self.trigger("startTyping", userInCache, channelInCache); - } - - self.userTypingListener[data.user_id] = Date.now(); - - setTimeout(function () { - if (self.userTypingListener[data.user_id] === -1) { - return; - } - if (Date.now() - self.userTypingListener[data.user_id] > 6000) { - // stopped typing - self.trigger("stopTyping", userInCache, channelInCache); - self.userTypingListener[data.user_id] = -1; - } - }, 6000); - - break; - - case "GUILD_ROLE_DELETE": - - var server = self.getServer("id", data.guild_id); - var role = server.getRole(data.role_id); - - self.trigger("serverRoleDelete", server, role); - - server.removeRole(role.id); - - break; - - case "GUILD_ROLE_UPDATE": - - var server = self.getServer("id", data.guild_id); - var role = server.getRole(data.role.id); - var newRole = server.updateRole(data.role); - - self.trigger("serverRoleUpdate", server, role, newRole); - - break; - - default: - self.debug("received unknown packet"); - self.trigger("unknown", dat); - break; - - } - }; - }; - - //def addUser - - Client.prototype.addUser = function addUser(data) { - if (!this.getUser("id", data.id)) { - this.userCache.push(new User(data)); - } - return this.getUser("id", data.id); - }; - - //def addChannel - - Client.prototype.addChannel = function addChannel(data, serverId) { - if (!this.getChannel("id", data.id)) { - this.channelCache.push(new Channel(data, this.getServer("id", serverId))); - } - return this.getChannel("id", data.id); - }; - - Client.prototype.addPMChannel = function addPMChannel(data) { - if (!this.getPMChannel("id", data.id)) { - this.pmChannelCache.push(new PMChannel(data, this)); - } - return this.getPMChannel("id", data.id); - }; - - Client.prototype.setTopic = function setTopic(channel, topic) { - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2]; - - var self = this; - - return new Promise(function (resolve, reject) { - - self.resolveDestination(channel).then(next)["catch"](error); - - function error(e) { - callback(e); - reject(e); - } - - function next(destination) { - - var asChan = self.getChannel("id", destination); - - request.patch(Endpoints.CHANNELS + "/" + destination).set("authorization", self.token).send({ - name: asChan.name, - position: 0, - topic: topic - }).end(function (err, res) { - if (err) { - error(err); - } else { - asChan.topic = res.body.topic; - resolve(); - callback(); - } - }); - } - }); - }; - - //def addServer - - Client.prototype.addServer = function addServer(data) { - - var self = this; - var server = this.getServer("id", data.id); - - if (data.unavailable) { - self.trigger("unavailable", data); - self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached."); - return; - } - - if (!server) { - server = new Server(data, this); - this.serverCache.push(server); - if (data.channels) { - for (var _iterator8 = data.channels, _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) { - var _ref8; - - if (_isArray8) { - if (_i8 >= _iterator8.length) break; - _ref8 = _iterator8[_i8++]; - } else { - _i8 = _iterator8.next(); - if (_i8.done) break; - _ref8 = _i8.value; - } - - var channel = _ref8; - - server.channels.push(this.addChannel(channel, server.id)); - } - } - } - - for (var _iterator9 = data.presences, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) { - var _ref9; - - if (_isArray9) { - if (_i9 >= _iterator9.length) break; - _ref9 = _iterator9[_i9++]; - } else { - _i9 = _iterator9.next(); - if (_i9.done) break; - _ref9 = _i9.value; - } - - var presence = _ref9; - - var user = self.getUser("id", presence.user.id); - user.status = presence.status; - user.gameId = presence.game_id; - } - - return server; - }; - - //def getUser - - Client.prototype.getUser = function getUser(key, value) { - for (var _iterator10 = this.userCache, _isArray10 = Array.isArray(_iterator10), _i10 = 0, _iterator10 = _isArray10 ? _iterator10 : _iterator10[Symbol.iterator]();;) { - var _ref10; - - if (_isArray10) { - if (_i10 >= _iterator10.length) break; - _ref10 = _iterator10[_i10++]; - } else { - _i10 = _iterator10.next(); - if (_i10.done) break; - _ref10 = _i10.value; - } - - var user = _ref10; - - if (user[key] === value) { - return user; - } - } - return null; - }; - - //def getChannel - - Client.prototype.getChannel = function getChannel(key, value) { - for (var _iterator11 = this.channelCache, _isArray11 = Array.isArray(_iterator11), _i11 = 0, _iterator11 = _isArray11 ? _iterator11 : _iterator11[Symbol.iterator]();;) { - var _ref11; - - if (_isArray11) { - if (_i11 >= _iterator11.length) break; - _ref11 = _iterator11[_i11++]; - } else { - _i11 = _iterator11.next(); - if (_i11.done) break; - _ref11 = _i11.value; - } - - var channel = _ref11; - - if (channel[key] === value) { - return channel; - } - } - return this.getPMChannel(key, value); //might be a PM - }; - - Client.prototype.getPMChannel = function getPMChannel(key, value) { - for (var _iterator12 = this.pmChannelCache, _isArray12 = Array.isArray(_iterator12), _i12 = 0, _iterator12 = _isArray12 ? _iterator12 : _iterator12[Symbol.iterator]();;) { - var _ref12; - - if (_isArray12) { - if (_i12 >= _iterator12.length) break; - _ref12 = _iterator12[_i12++]; - } else { - _i12 = _iterator12.next(); - if (_i12.done) break; - _ref12 = _i12.value; - } - - var channel = _ref12; - - if (channel[key] === value) { - return channel; - } - } - return null; - }; - - //def getServer - - Client.prototype.getServer = function getServer(key, value) { - for (var _iterator13 = this.serverCache, _isArray13 = Array.isArray(_iterator13), _i13 = 0, _iterator13 = _isArray13 ? _iterator13 : _iterator13[Symbol.iterator]();;) { - var _ref13; - - if (_isArray13) { - if (_i13 >= _iterator13.length) break; - _ref13 = _iterator13[_i13++]; - } else { - _i13 = _iterator13.next(); - if (_i13.done) break; - _ref13 = _i13.value; - } - - var server = _ref13; - - if (server[key] === value) { - return server; - } - } - return null; - }; - - //def trySendConnData - - Client.prototype.trySendConnData = function trySendConnData() { - - if (this.token && !this.alreadySentData) { - - this.alreadySentData = true; - - var data = { - op: 2, - d: { - token: this.token, - v: 3, - properties: { - "$os": "discord.js", - "$browser": "discord.js", - "$device": "discord.js", - "$referrer": "", - "$referring_domain": "" - } - } - }; - this.websocket.send(JSON.stringify(data)); - } - }; - - Client.prototype.resolveServerID = function resolveServerID(resource) { - - if (resource instanceof Server) { - return resource.id; - } else if (!isNaN(resource) && resource.length && resource.length === 17) { - return resource; - } - }; - - Client.prototype.resolveDestination = function resolveDestination(destination) { - var channId = false; - var self = this; - - return new Promise(function (resolve, reject) { - if (destination instanceof Server) { - channId = destination.id; //general is the same as server id - } else if (destination instanceof Channel) { - channId = destination.id; - } else if (destination instanceof Message) { - channId = destination.channel.id; - } else if (destination instanceof PMChannel) { - channId = destination.id; - } else if (destination instanceof User) { - - //check if we have a PM - for (var _iterator14 = self.pmChannelCache, _isArray14 = Array.isArray(_iterator14), _i14 = 0, _iterator14 = _isArray14 ? _iterator14 : _iterator14[Symbol.iterator]();;) { - var _ref14; - - if (_isArray14) { - if (_i14 >= _iterator14.length) break; - _ref14 = _iterator14[_i14++]; - } else { - _i14 = _iterator14.next(); - if (_i14.done) break; - _ref14 = _i14.value; - } - - var pmc = _ref14; - - if (pmc.user && pmc.user.equals(destination)) { - resolve(pmc.id); - return; - } - } - - //we don't, at this point we're late - self.startPM(destination).then(function (pmc) { - resolve(pmc.id); - })["catch"](reject); - } else { - channId = destination; - } - if (channId) resolve(channId);else reject(); - }); - }; - - Client.prototype._sendMessage = function _sendMessage(destination, content, tts, mentions) { - - var self = this; - - return new Promise(function (resolve, reject) { - request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).send({ - content: content, - mentions: mentions, - tts: tts - }).end(function (err, res) { - - if (err) { - reject(err); - } else { - var data = res.body; - - var mentions = []; - - data.mentions = data.mentions || []; //for some reason this was not defined at some point? - - for (var _iterator15 = data.mentions, _isArray15 = Array.isArray(_iterator15), _i15 = 0, _iterator15 = _isArray15 ? _iterator15 : _iterator15[Symbol.iterator]();;) { - var _ref15; - - if (_isArray15) { - if (_i15 >= _iterator15.length) break; - _ref15 = _iterator15[_i15++]; - } else { - _i15 = _iterator15.next(); - if (_i15.done) break; - _ref15 = _i15.value; - } - - var mention = _ref15; - - mentions.push(self.addUser(mention)); - } - - var channel = self.getChannel("id", data.channel_id); - if (channel) { - var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); - resolve(msg); - } - } - }); - }); - }; - - Client.prototype._sendFile = function _sendFile(destination, attachment) { - var attachmentName = arguments.length <= 2 || arguments[2] === undefined ? "DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png" : arguments[2]; - - var self = this; - - return new Promise(function (resolve, reject) { - request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).attach("file", attachment, attachmentName).end(function (err, res) { - - if (err) { - reject(err); - } else { - - var chann = self.getChannel("id", destination); - if (chann) { - var msg = chann.addMessage(new Message(res.body, chann, [], self.user)); - resolve(msg); - } - } - }); - }); - }; - - Client.prototype._updateMessage = function _updateMessage(message, content) { - var self = this; - return new Promise(function (resolve, reject) { - request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).send({ - content: content, - mentions: [] - }).end(function (err, res) { - if (err) { - reject(err); - } else { - var msg = new Message(res.body, message.channel, message.mentions, message.sender); - resolve(msg); - message.channel.messages[message.channel.messages.indexOf(message)] = msg; - } - }); - }); - }; - - Client.prototype.getGateway = function getGateway() { - var self = this; - return new Promise(function (resolve, reject) { - request.get(Endpoints.API + "/gateway").set("authorization", self.token).end(function (err, res) { - if (err) { - reject(err); - } else { - resolve(res.body.url); - } - }); - }); - }; - - Client.prototype.setStatusIdle = function setStatusIdle() { - this.setStatus("idle"); - }; - - Client.prototype.setStatusOnline = function setStatusOnline() { - this.setStatus("online"); - }; - - Client.prototype.setStatusActive = function setStatusActive() { - this.setStatusOnline(); - }; - - Client.prototype.setStatusHere = function setStatusHere() { - this.setStatusOnline(); - }; - - Client.prototype.setStatusAway = function setStatusAway() { - this.setStatusIdle(); - }; - - Client.prototype.startTyping = function startTyping(chann, stopTypeTime) { - var self = this; - - this.resolveDestination(chann).then(next); - - function next(channel) { - if (self.typingIntervals[channel]) { - return; - } - - var fn = function fn() { - request.post(Endpoints.CHANNELS + "/" + channel + "/typing").set("authorization", self.token).end(); - }; - - fn(); - - var interval = setInterval(fn, 3000); - - self.typingIntervals[channel] = interval; - - if (stopTypeTime) { - setTimeout(function () { - self.stopTyping(channel); - }, stopTypeTime); - } - } - }; - - Client.prototype.stopTyping = function stopTyping(chann) { - var self = this; - - this.resolveDestination(chann).then(next); - - function next(channel) { - if (!self.typingIntervals[channel]) { - return; - } - - clearInterval(self.typingIntervals[channel]); - - delete self.typingIntervals[channel]; - } - }; - - Client.prototype.setStatus = function setStatus(stat) { - - var idleTime = stat === "online" ? null : Date.now(); - - this.__idleTime = idleTime; - - this.websocket.send(JSON.stringify({ - op: 3, - d: { - idle_since: this.__idleTime, - game_id: this.__gameId - } - })); - }; - - Client.prototype.setPlayingGame = function setPlayingGame(id) { - - if (id instanceof String || typeof id === "string") { - - // working on names - var gid = id.trim().toUpperCase(); - - id = null; - - for (var _iterator16 = gameMap, _isArray16 = Array.isArray(_iterator16), _i16 = 0, _iterator16 = _isArray16 ? _iterator16 : _iterator16[Symbol.iterator]();;) { - var _ref16; - - if (_isArray16) { - if (_i16 >= _iterator16.length) break; - _ref16 = _iterator16[_i16++]; - } else { - _i16 = _iterator16.next(); - if (_i16.done) break; - _ref16 = _i16.value; - } - - var game = _ref16; - - if (game.name.trim().toUpperCase() === gid) { - - id = game.id; - break; - } - } - } - - this.__gameId = id; - - this.websocket.send(JSON.stringify({ - op: 3, - d: { - idle_since: this.__idleTime, - game_id: this.__gameId - } - })); - }; - - Client.prototype.playGame = function playGame(id) { - this.setPlayingGame(id); - }; - - Client.prototype.playingGame = function playingGame(id) { - - this.setPlayingGame(id); - }; - - _createClass(Client, [{ - key: "uptime", - get: function get() { - - return this.readyTime ? Date.now() - this.readyTime : null; - } - }, { - key: "ready", - get: function get() { - return this.state === 3; - } - }, { - key: "servers", - get: function get() { - return this.serverCache; - } - }, { - key: "channels", - get: function get() { - return this.channelCache; - } - }, { - key: "users", - get: function get() { - return this.userCache; - } - }, { - key: "PMChannels", - get: function get() { - return this.pmChannelCache; - } - }, { - key: "messages", - get: function get() { - - var msgs = []; - for (var _iterator17 = this.channelCache, _isArray17 = Array.isArray(_iterator17), _i17 = 0, _iterator17 = _isArray17 ? _iterator17 : _iterator17[Symbol.iterator]();;) { - var _ref17; - - if (_isArray17) { - if (_i17 >= _iterator17.length) break; - _ref17 = _iterator17[_i17++]; - } else { - _i17 = _iterator17.next(); - if (_i17.done) break; - _ref17 = _i17.value; - } - - var channel = _ref17; - - msgs = msgs.concat(channel.messages); - } - return msgs; - } - }]); - - return Client; -})(); - -module.exports = Client; \ No newline at end of file + self.serverCache[self.serverCache.indexOf(server)] = srv; + + }*/if(self.serverCreateListener[data.id]){var cbs=self.serverCreateListener[data.id];cbs[0](server); //promise then callback +cbs[1](null,server); //legacy callback +self.serverCreateListener[data.id] = null;}self.trigger("serverCreate",server);break;case "CHANNEL_CREATE":var channel=self.getChannel("id",data.id);if(!channel){var chann;if(data.is_private){chann = self.addPMChannel(data);}else {chann = self.addChannel(data,data.guild_id);}var srv=self.getServer("id",data.guild_id);if(srv){srv.addChannel(chann);}self.trigger("channelCreate",chann);}break;case "GUILD_MEMBER_ADD":var server=self.getServer("id",data.guild_id);if(server){var user=self.addUser(data.user); //if for whatever reason it doesn't exist.. +self.trigger("serverNewMember",server.addMember(user,data.roles),server);}break;case "GUILD_MEMBER_REMOVE":var server=self.getServer("id",data.guild_id);if(server){var user=self.addUser(data.user); //if for whatever reason it doesn't exist.. +server.removeMember("id",user.id);self.trigger("serverRemoveMember",user,server);}break;case "USER_UPDATE":if(self.user && data.id === self.user.id){var newUser=new User(data); //not actually adding to the cache +self.trigger("userUpdate",newUser,self.user);if(~self.userCache.indexOf(self.user)){self.userCache[self.userCache.indexOf(self.user)] = newUser;}self.user = newUser;}break;case "PRESENCE_UPDATE":var userInCache=self.getUser("id",data.user.id);if(userInCache){ //user exists +data.user.username = data.user.username || userInCache.username;data.user.id = data.user.id || userInCache.id;data.user.discriminator = data.user.discriminator || userInCache.discriminator;data.user.avatar = data.user.avatar || userInCache.avatar;var presenceUser=new User(data.user);if(presenceUser.equalsStrict(userInCache)){ //they're exactly the same, an actual presence update +self.trigger("presence",{user:userInCache,oldStatus:userInCache.status,status:data.status,server:self.getServer("id",data.guild_id),gameId:data.game_id});userInCache.status = data.status;userInCache.gameId = data.game_id;}else { //one of their details changed. +self.userCache[self.userCache.indexOf(userInCache)] = presenceUser;self.trigger("userUpdate",userInCache,presenceUser);}}break;case "CHANNEL_UPDATE":var channelInCache=self.getChannel("id",data.id),serverInCache=self.getServer("id",data.guild_id);if(channelInCache && serverInCache){var newChann=new Channel(data,serverInCache);newChann.messages = channelInCache.messages;self.trigger("channelUpdate",channelInCache,newChann);self.channelCache[self.channelCache.indexOf(channelInCache)] = newChann;}break;case "TYPING_START":var userInCache=self.getUser("id",data.user_id);var channelInCache=self.getChannel("id",data.channel_id);if(!self.userTypingListener[data.user_id] || self.userTypingListener[data.user_id] === -1){self.trigger("startTyping",userInCache,channelInCache);}self.userTypingListener[data.user_id] = Date.now();setTimeout(function(){if(self.userTypingListener[data.user_id] === -1){return;}if(Date.now() - self.userTypingListener[data.user_id] > 6000){ // stopped typing +self.trigger("stopTyping",userInCache,channelInCache);self.userTypingListener[data.user_id] = -1;}},6000);break;case "GUILD_ROLE_DELETE":var server=self.getServer("id",data.guild_id);var role=server.getRole(data.role_id);self.trigger("serverRoleDelete",server,role);server.removeRole(role.id);break;case "GUILD_ROLE_UPDATE":var server=self.getServer("id",data.guild_id);var role=server.getRole(data.role.id);var newRole=server.updateRole(data.role);self.trigger("serverRoleUpdate",server,role,newRole);break;default:self.debug("received unknown packet");self.trigger("unknown",dat);break;}};}; //def addUser +Client.prototype.addUser = function addUser(data){if(!this.getUser("id",data.id)){this.userCache.push(new User(data));}return this.getUser("id",data.id);}; //def addChannel +Client.prototype.addChannel = function addChannel(data,serverId){if(!this.getChannel("id",data.id)){this.channelCache.push(new Channel(data,this.getServer("id",serverId)));}return this.getChannel("id",data.id);};Client.prototype.addPMChannel = function addPMChannel(data){if(!this.getPMChannel("id",data.id)){this.pmChannelCache.push(new PMChannel(data,this));}return this.getPMChannel("id",data.id);};Client.prototype.setTopic = function setTopic(channel,topic){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err){}:arguments[2];var self=this;return new Promise(function(resolve,reject){self.resolveDestination(channel).then(next)["catch"](error);function error(e){callback(e);reject(e);}function next(destination){var asChan=self.getChannel("id",destination);request.patch(Endpoints.CHANNELS + "/" + destination).set("authorization",self.token).send({name:asChan.name,position:0,topic:topic}).end(function(err,res){if(err){error(err);}else {asChan.topic = res.body.topic;resolve();callback();}});}});}; //def addServer +Client.prototype.addServer = function addServer(data){var self=this;var server=this.getServer("id",data.id);if(data.unavailable){self.trigger("unavailable",data);self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached.");return;}if(!server){server = new Server(data,this);this.serverCache.push(server);if(data.channels){for(var _iterator8=data.channels,_isArray8=Array.isArray(_iterator8),_i8=0,_iterator8=_isArray8?_iterator8:_iterator8[Symbol.iterator]();;) {var _ref8;if(_isArray8){if(_i8 >= _iterator8.length)break;_ref8 = _iterator8[_i8++];}else {_i8 = _iterator8.next();if(_i8.done)break;_ref8 = _i8.value;}var channel=_ref8;server.channels.push(this.addChannel(channel,server.id));}}}for(var _iterator9=data.presences,_isArray9=Array.isArray(_iterator9),_i9=0,_iterator9=_isArray9?_iterator9:_iterator9[Symbol.iterator]();;) {var _ref9;if(_isArray9){if(_i9 >= _iterator9.length)break;_ref9 = _iterator9[_i9++];}else {_i9 = _iterator9.next();if(_i9.done)break;_ref9 = _i9.value;}var presence=_ref9;var user=self.getUser("id",presence.user.id);user.status = presence.status;user.gameId = presence.game_id;}return server;}; //def getUser +Client.prototype.getUser = function getUser(key,value){for(var _iterator10=this.userCache,_isArray10=Array.isArray(_iterator10),_i10=0,_iterator10=_isArray10?_iterator10:_iterator10[Symbol.iterator]();;) {var _ref10;if(_isArray10){if(_i10 >= _iterator10.length)break;_ref10 = _iterator10[_i10++];}else {_i10 = _iterator10.next();if(_i10.done)break;_ref10 = _i10.value;}var user=_ref10;if(user[key] === value){return user;}}return null;}; //def getChannel +Client.prototype.getChannel = function getChannel(key,value){for(var _iterator11=this.channelCache,_isArray11=Array.isArray(_iterator11),_i11=0,_iterator11=_isArray11?_iterator11:_iterator11[Symbol.iterator]();;) {var _ref11;if(_isArray11){if(_i11 >= _iterator11.length)break;_ref11 = _iterator11[_i11++];}else {_i11 = _iterator11.next();if(_i11.done)break;_ref11 = _i11.value;}var channel=_ref11;if(channel[key] === value){return channel;}}return this.getPMChannel(key,value); //might be a PM +};Client.prototype.getPMChannel = function getPMChannel(key,value){for(var _iterator12=this.pmChannelCache,_isArray12=Array.isArray(_iterator12),_i12=0,_iterator12=_isArray12?_iterator12:_iterator12[Symbol.iterator]();;) {var _ref12;if(_isArray12){if(_i12 >= _iterator12.length)break;_ref12 = _iterator12[_i12++];}else {_i12 = _iterator12.next();if(_i12.done)break;_ref12 = _i12.value;}var channel=_ref12;if(channel[key] === value){return channel;}}return null;}; //def getServer +Client.prototype.getServer = function getServer(key,value){for(var _iterator13=this.serverCache,_isArray13=Array.isArray(_iterator13),_i13=0,_iterator13=_isArray13?_iterator13:_iterator13[Symbol.iterator]();;) {var _ref13;if(_isArray13){if(_i13 >= _iterator13.length)break;_ref13 = _iterator13[_i13++];}else {_i13 = _iterator13.next();if(_i13.done)break;_ref13 = _i13.value;}var server=_ref13;if(server[key] === value){return server;}}return null;}; //def trySendConnData +Client.prototype.trySendConnData = function trySendConnData(){if(this.token && !this.alreadySentData){this.alreadySentData = true;var data={op:2,d:{token:this.token,v:3,properties:{"$os":"discord.js","$browser":"discord.js","$device":"discord.js","$referrer":"","$referring_domain":""}}};this.websocket.send(JSON.stringify(data));}};Client.prototype.resolveServerID = function resolveServerID(resource){if(resource instanceof Server){return resource.id;}else if(!isNaN(resource) && resource.length && resource.length === 17){return resource;}};Client.prototype.resolveDestination = function resolveDestination(destination){var channId=false;var self=this;return new Promise(function(resolve,reject){if(destination instanceof Server){channId = destination.id; //general is the same as server id +}else if(destination instanceof Channel){channId = destination.id;}else if(destination instanceof Message){channId = destination.channel.id;}else if(destination instanceof PMChannel){channId = destination.id;}else if(destination instanceof User){ //check if we have a PM +for(var _iterator14=self.pmChannelCache,_isArray14=Array.isArray(_iterator14),_i14=0,_iterator14=_isArray14?_iterator14:_iterator14[Symbol.iterator]();;) {var _ref14;if(_isArray14){if(_i14 >= _iterator14.length)break;_ref14 = _iterator14[_i14++];}else {_i14 = _iterator14.next();if(_i14.done)break;_ref14 = _i14.value;}var pmc=_ref14;if(pmc.user && pmc.user.equals(destination)){resolve(pmc.id);return;}} //we don't, at this point we're late +self.startPM(destination).then(function(pmc){resolve(pmc.id);})["catch"](reject);}else {channId = destination;}if(channId)resolve(channId);else reject();});};Client.prototype._sendMessage = function _sendMessage(destination,content,tts,mentions){var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization",self.token).send({content:content,mentions:mentions,tts:tts}).end(function(err,res){if(err){reject(err);}else {var data=res.body;var mentions=[];data.mentions = data.mentions || []; //for some reason this was not defined at some point? +for(var _iterator15=data.mentions,_isArray15=Array.isArray(_iterator15),_i15=0,_iterator15=_isArray15?_iterator15:_iterator15[Symbol.iterator]();;) {var _ref15;if(_isArray15){if(_i15 >= _iterator15.length)break;_ref15 = _iterator15[_i15++];}else {_i15 = _iterator15.next();if(_i15.done)break;_ref15 = _i15.value;}var mention=_ref15;mentions.push(self.addUser(mention));}var channel=self.getChannel("id",data.channel_id);if(channel){var msg=channel.addMessage(new Message(data,channel,mentions,self.addUser(data.author)));resolve(msg);}}});});};Client.prototype._sendFile = function _sendFile(destination,attachment){var attachmentName=arguments.length <= 2 || arguments[2] === undefined?"DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png":arguments[2];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization",self.token).attach("file",attachment,attachmentName).end(function(err,res){if(err){reject(err);}else {var chann=self.getChannel("id",destination);if(chann){var msg=chann.addMessage(new Message(res.body,chann,[],self.user));resolve(msg);}}});});};Client.prototype._updateMessage = function _updateMessage(message,content){var self=this;return new Promise(function(resolve,reject){request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization",self.token).send({content:content,mentions:[]}).end(function(err,res){if(err){reject(err);}else {var msg=new Message(res.body,message.channel,message.mentions,message.sender);resolve(msg);message.channel.messages[message.channel.messages.indexOf(message)] = msg;}});});};Client.prototype.getGateway = function getGateway(){var self=this;return new Promise(function(resolve,reject){request.get(Endpoints.API + "/gateway").set("authorization",self.token).end(function(err,res){if(err){reject(err);}else {resolve(res.body.url);}});});};Client.prototype.setStatusIdle = function setStatusIdle(){this.setStatus("idle");};Client.prototype.setStatusOnline = function setStatusOnline(){this.setStatus("online");};Client.prototype.setStatusActive = function setStatusActive(){this.setStatusOnline();};Client.prototype.setStatusHere = function setStatusHere(){this.setStatusOnline();};Client.prototype.setStatusAway = function setStatusAway(){this.setStatusIdle();};Client.prototype.startTyping = function startTyping(chann,stopTypeTime){var self=this;this.resolveDestination(chann).then(next);function next(channel){if(self.typingIntervals[channel]){return;}var fn=function fn(){request.post(Endpoints.CHANNELS + "/" + channel + "/typing").set("authorization",self.token).end();};fn();var interval=setInterval(fn,3000);self.typingIntervals[channel] = interval;if(stopTypeTime){setTimeout(function(){self.stopTyping(channel);},stopTypeTime);}}};Client.prototype.stopTyping = function stopTyping(chann){var self=this;this.resolveDestination(chann).then(next);function next(channel){if(!self.typingIntervals[channel]){return;}clearInterval(self.typingIntervals[channel]);delete self.typingIntervals[channel];}};Client.prototype.setStatus = function setStatus(stat){var idleTime=stat === "online"?null:Date.now();this.__idleTime = idleTime;this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}));};Client.prototype.setPlayingGame = function setPlayingGame(id){if(id instanceof String || typeof id === "string"){ // working on names +var gid=id.trim().toUpperCase();id = null;for(var _iterator16=gameMap,_isArray16=Array.isArray(_iterator16),_i16=0,_iterator16=_isArray16?_iterator16:_iterator16[Symbol.iterator]();;) {var _ref16;if(_isArray16){if(_i16 >= _iterator16.length)break;_ref16 = _iterator16[_i16++];}else {_i16 = _iterator16.next();if(_i16.done)break;_ref16 = _i16.value;}var game=_ref16;if(game.name.trim().toUpperCase() === gid){id = game.id;break;}}}this.__gameId = id;this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}));};Client.prototype.playGame = function playGame(id){this.setPlayingGame(id);};Client.prototype.playingGame = function playingGame(id){this.setPlayingGame(id);};_createClass(Client,[{key:"uptime",get:function get(){return this.readyTime?Date.now() - this.readyTime:null;}},{key:"ready",get:function get(){return this.state === 3;}},{key:"servers",get:function get(){return this.serverCache;}},{key:"channels",get:function get(){return this.channelCache;}},{key:"users",get:function get(){return this.userCache;}},{key:"PMChannels",get:function get(){return this.pmChannelCache;}},{key:"messages",get:function get(){var msgs=[];for(var _iterator17=this.channelCache,_isArray17=Array.isArray(_iterator17),_i17=0,_iterator17=_isArray17?_iterator17:_iterator17[Symbol.iterator]();;) {var _ref17;if(_isArray17){if(_i17 >= _iterator17.length)break;_ref17 = _iterator17[_i17++];}else {_i17 = _iterator17.next();if(_i17.done)break;_ref17 = _i17.value;}var channel=_ref17;msgs = msgs.concat(channel.messages);}return msgs;}}]);return Client;})();module.exports = Client; diff --git a/lib/Endpoints.js b/lib/Endpoints.js index 271b465eb..60cd7925c 100644 --- a/lib/Endpoints.js +++ b/lib/Endpoints.js @@ -1,13 +1 @@ -"use strict"; - -exports.BASE_DOMAIN = "discordapp.com"; -exports.BASE = "https://" + exports.BASE_DOMAIN; -exports.WEBSOCKET_HUB = "wss://" + exports.BASE_DOMAIN + "/hub"; - -exports.API = exports.BASE + "/api"; -exports.AUTH = exports.API + "/auth"; -exports.LOGIN = exports.AUTH + "/login"; -exports.LOGOUT = exports.AUTH + "/logout"; -exports.USERS = exports.API + "/users"; -exports.SERVERS = exports.API + "/guilds"; -exports.CHANNELS = exports.API + "/channels"; \ No newline at end of file +"use strict";exports.BASE_DOMAIN = "discordapp.com";exports.BASE = "https://" + exports.BASE_DOMAIN;exports.WEBSOCKET_HUB = "wss://" + exports.BASE_DOMAIN + "/hub";exports.API = exports.BASE + "/api";exports.AUTH = exports.API + "/auth";exports.LOGIN = exports.AUTH + "/login";exports.LOGOUT = exports.AUTH + "/logout";exports.USERS = exports.API + "/users";exports.SERVERS = exports.API + "/guilds";exports.CHANNELS = exports.API + "/channels"; diff --git a/lib/EvaluatedPermissions.js b/lib/EvaluatedPermissions.js index c4720c46b..efda9971a 100644 --- a/lib/EvaluatedPermissions.js +++ b/lib/EvaluatedPermissions.js @@ -1,187 +1 @@ -"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 EvaluatedPermissions = (function () { - function EvaluatedPermissions(data) { - _classCallCheck(this, EvaluatedPermissions); - - var self = this; - - this.packed = data; - - if (this.getBit(3)) this.packed = 4294967295; - } - - EvaluatedPermissions.prototype.serialise = function serialise() { - return { - createInstantInvite: this.createInstantInvite, - manageRoles: this.manageRoles, - manageChannels: this.manageChannels, - readMessages: this.readMessages, - sendMessages: this.sendMessage, - sendTTSMessages: this.sendTTSMessages, - manageMessages: this.manageMessages, - embedLinks: this.embedLinks, - attachFiles: this.attachFiles, - readMessageHistory: this.readMessageHistory, - mentionEveryone: this.mentionEveryone, - voiceConnect: this.voiceConnect, - voiceSpeak: this.voiceSpeak, - voiceMuteMembers: this.voiceMuteMembers, - voiceDeafenMembers: this.voiceDeafenMembers, - voiceMoveMember: this.voiceMoveMembers, - voiceUseVoiceActivation: this.voiceUseVoiceActivation - }; - }; - - EvaluatedPermissions.prototype.getBit = function getBit(x) { - return (this.packed >>> x & 1) === 1; - }; - - EvaluatedPermissions.prototype.setBit = function setBit() {}; - - _createClass(EvaluatedPermissions, [{ - key: "createInstantInvite", - get: function get() { - return this.getBit(0); - }, - set: function set(val) { - this.setBit(0, val); - } - }, { - key: "manageRoles", - get: function get() { - return this.getBit(3); - }, - set: function set(val) { - this.setBit(3, val); - } - }, { - key: "manageChannels", - get: function get() { - return this.getBit(4); - }, - set: function set(val) { - this.setBit(4, val); - } - }, { - key: "readMessages", - get: function get() { - return this.getBit(10); - }, - set: function set(val) { - this.setBit(10, val); - } - }, { - key: "sendMessages", - get: function get() { - return this.getBit(11); - }, - set: function set(val) { - this.setBit(11, val); - } - }, { - key: "sendTTSMessages", - get: function get() { - return this.getBit(12); - }, - set: function set(val) { - this.setBit(12, val); - } - }, { - key: "manageMessages", - get: function get() { - return this.getBit(13); - }, - set: function set(val) { - this.setBit(13, val); - } - }, { - key: "embedLinks", - get: function get() { - return this.getBit(14); - }, - set: function set(val) { - this.setBit(14, val); - } - }, { - key: "attachFiles", - get: function get() { - return this.getBit(15); - }, - set: function set(val) { - this.setBit(15, val); - } - }, { - key: "readMessageHistory", - get: function get() { - return this.getBit(16); - }, - set: function set(val) { - this.setBit(16, val); - } - }, { - key: "mentionEveryone", - get: function get() { - return this.getBit(17); - }, - set: function set(val) { - this.setBit(17, val); - } - }, { - key: "voiceConnect", - get: function get() { - return this.getBit(20); - }, - set: function set(val) { - this.setBit(20, val); - } - }, { - key: "voiceSpeak", - get: function get() { - return this.getBit(21); - }, - set: function set(val) { - this.setBit(21, val); - } - }, { - key: "voiceMuteMembers", - get: function get() { - return this.getBit(22); - }, - set: function set(val) { - this.setBit(22, val); - } - }, { - key: "voiceDeafenMembers", - get: function get() { - return this.getBit(23); - }, - set: function set(val) { - this.setBit(23, val); - } - }, { - key: "voiceMoveMembers", - get: function get() { - return this.getBit(24); - }, - set: function set(val) { - this.setBit(24, val); - } - }, { - key: "voiceUseVoiceActivation", - get: function get() { - return this.getBit(25); - }, - set: function set(val) { - this.setBit(25, val); - } - }]); - - return EvaluatedPermissions; -})(); - -module.exports = EvaluatedPermissions; \ No newline at end of file +"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 EvaluatedPermissions=(function(){function EvaluatedPermissions(data){_classCallCheck(this,EvaluatedPermissions);var self=this;this.packed = data;if(this.getBit(3))this.packed = 4294967295;}EvaluatedPermissions.prototype.serialise = function serialise(){return {createInstantInvite:this.createInstantInvite,manageRoles:this.manageRoles,manageChannels:this.manageChannels,readMessages:this.readMessages,sendMessages:this.sendMessage,sendTTSMessages:this.sendTTSMessages,manageMessages:this.manageMessages,embedLinks:this.embedLinks,attachFiles:this.attachFiles,readMessageHistory:this.readMessageHistory,mentionEveryone:this.mentionEveryone,voiceConnect:this.voiceConnect,voiceSpeak:this.voiceSpeak,voiceMuteMembers:this.voiceMuteMembers,voiceDeafenMembers:this.voiceDeafenMembers,voiceMoveMember:this.voiceMoveMembers,voiceUseVoiceActivation:this.voiceUseVoiceActivation};};EvaluatedPermissions.prototype.getBit = function getBit(x){return (this.packed >>> x & 1) === 1;};EvaluatedPermissions.prototype.setBit = function setBit(){};_createClass(EvaluatedPermissions,[{key:"createInstantInvite",get:function get(){return this.getBit(0);},set:function set(val){this.setBit(0,val);}},{key:"manageRoles",get:function get(){return this.getBit(3);},set:function set(val){this.setBit(3,val);}},{key:"manageChannels",get:function get(){return this.getBit(4);},set:function set(val){this.setBit(4,val);}},{key:"readMessages",get:function get(){return this.getBit(10);},set:function set(val){this.setBit(10,val);}},{key:"sendMessages",get:function get(){return this.getBit(11);},set:function set(val){this.setBit(11,val);}},{key:"sendTTSMessages",get:function get(){return this.getBit(12);},set:function set(val){this.setBit(12,val);}},{key:"manageMessages",get:function get(){return this.getBit(13);},set:function set(val){this.setBit(13,val);}},{key:"embedLinks",get:function get(){return this.getBit(14);},set:function set(val){this.setBit(14,val);}},{key:"attachFiles",get:function get(){return this.getBit(15);},set:function set(val){this.setBit(15,val);}},{key:"readMessageHistory",get:function get(){return this.getBit(16);},set:function set(val){this.setBit(16,val);}},{key:"mentionEveryone",get:function get(){return this.getBit(17);},set:function set(val){this.setBit(17,val);}},{key:"voiceConnect",get:function get(){return this.getBit(20);},set:function set(val){this.setBit(20,val);}},{key:"voiceSpeak",get:function get(){return this.getBit(21);},set:function set(val){this.setBit(21,val);}},{key:"voiceMuteMembers",get:function get(){return this.getBit(22);},set:function set(val){this.setBit(22,val);}},{key:"voiceDeafenMembers",get:function get(){return this.getBit(23);},set:function set(val){this.setBit(23,val);}},{key:"voiceMoveMembers",get:function get(){return this.getBit(24);},set:function set(val){this.setBit(24,val);}},{key:"voiceUseVoiceActivation",get:function get(){return this.getBit(25);},set:function set(val){this.setBit(25,val);}}]);return EvaluatedPermissions;})();module.exports = EvaluatedPermissions; diff --git a/lib/Member.js b/lib/Member.js index 813acda1b..fd41c7dce 100644 --- a/lib/Member.js +++ b/lib/Member.js @@ -1,157 +1,4 @@ -"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 User = require("./user.js"); -var ServerPermissions = require("./ServerPermissions.js"); -var EvaluatedPermissions = require("./EvaluatedPermissions.js"); - -var Member = (function (_User) { - _inherits(Member, _User); - - function Member(user, server, roles) { - _classCallCheck(this, Member); - - _User.call(this, user); // should work, we are basically creating a Member that has the same properties as user and a few more - this.server = server; - this.rawRoles = roles; - } - - Member.prototype.permissionsIn = function permissionsIn(channel) { - - if (channel.server.ownerID === this.id) { - return new EvaluatedPermissions(4294967295); //all perms - } - - var affectingOverwrites = []; - var affectingMemberOverwrites = []; - - for (var _iterator = channel.roles, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { - var _ref; - - if (_isArray) { - if (_i >= _iterator.length) break; - _ref = _iterator[_i++]; - } else { - _i = _iterator.next(); - if (_i.done) break; - _ref = _i.value; - } - - var overwrite = _ref; - - if (overwrite.id === this.id && overwrite.type === "member") { - affectingMemberOverwrites.push(overwrite); - } else if (this.rawRoles.indexOf(overwrite.id) !== -1) { - affectingOverwrites.push(overwrite); - } - } - - if (affectingOverwrites.length === 0 && affectingMemberOverwrites.length === 0) { - return new EvaluatedPermissions(this.evalPerms.packed); - } - - var finalPacked = affectingOverwrites.length !== 0 ? affectingOverwrites[0].packed : affectingMemberOverwrites[0].packed; - - for (var _iterator2 = affectingOverwrites, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { - var _ref2; - - if (_isArray2) { - if (_i2 >= _iterator2.length) break; - _ref2 = _iterator2[_i2++]; - } else { - _i2 = _iterator2.next(); - if (_i2.done) break; - _ref2 = _i2.value; - } - - var overwrite = _ref2; - - finalPacked = finalPacked & ~overwrite.deny; - finalPacked = finalPacked | overwrite.allow; - } - - for (var _iterator3 = affectingMemberOverwrites, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { - var _ref3; - - if (_isArray3) { - if (_i3 >= _iterator3.length) break; - _ref3 = _iterator3[_i3++]; - } else { - _i3 = _iterator3.next(); - if (_i3.done) break; - _ref3 = _i3.value; - } - - var overwrite = _ref3; - - finalPacked = finalPacked & ~overwrite.deny; - finalPacked = finalPacked | overwrite.allow; - } - - return new EvaluatedPermissions(finalPacked); - }; - - _createClass(Member, [{ - key: "roles", - get: function get() { - - var ufRoles = [this.server.getRole(this.server.id)]; - - for (var _iterator4 = this.rawRoles, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { - var _ref4; - - if (_isArray4) { - if (_i4 >= _iterator4.length) break; - _ref4 = _iterator4[_i4++]; - } else { - _i4 = _iterator4.next(); - if (_i4.done) break; - _ref4 = _i4.value; - } - - var rawRole = _ref4; - - ufRoles.push(this.server.getRole(rawRole)); - } - - return ufRoles; - } - }, { - key: "evalPerms", - get: function get() { - var basePerms = this.roles, - //cache roles as it can be slightly expensive - basePerm = basePerms[0].packed; - - for (var _iterator5 = basePerms, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { - var _ref5; - - if (_isArray5) { - if (_i5 >= _iterator5.length) break; - _ref5 = _iterator5[_i5++]; - } else { - _i5 = _iterator5.next(); - if (_i5.done) break; - _ref5 = _i5.value; - } - - var perm = _ref5; - - basePerm = basePerm | perm.packed; - } - - return new ServerPermissions({ - permissions: basePerm - }); - } - }]); - - return Member; -})(User); - -module.exports = Member; \ No newline at end of file +"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 User=require("./user.js");var ServerPermissions=require("./ServerPermissions.js");var EvaluatedPermissions=require("./EvaluatedPermissions.js");var Member=(function(_User){_inherits(Member,_User);function Member(user,server,roles){_classCallCheck(this,Member);_User.call(this,user); // should work, we are basically creating a Member that has the same properties as user and a few more +this.server = server;this.rawRoles = roles;}Member.prototype.permissionsIn = function permissionsIn(channel){if(channel.server.ownerID === this.id){return new EvaluatedPermissions(4294967295); //all perms +}var affectingOverwrites=[];var affectingMemberOverwrites=[];for(var _iterator=channel.roles,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var overwrite=_ref;if(overwrite.id === this.id && overwrite.type === "member"){affectingMemberOverwrites.push(overwrite);}else if(this.rawRoles.indexOf(overwrite.id) !== -1){affectingOverwrites.push(overwrite);}}if(affectingOverwrites.length === 0 && affectingMemberOverwrites.length === 0){return new EvaluatedPermissions(this.evalPerms.packed);}var finalPacked=affectingOverwrites.length !== 0?affectingOverwrites[0].packed:affectingMemberOverwrites[0].packed;for(var _iterator2=affectingOverwrites,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var overwrite=_ref2;finalPacked = finalPacked & ~overwrite.deny;finalPacked = finalPacked | overwrite.allow;}for(var _iterator3=affectingMemberOverwrites,_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[Symbol.iterator]();;) {var _ref3;if(_isArray3){if(_i3 >= _iterator3.length)break;_ref3 = _iterator3[_i3++];}else {_i3 = _iterator3.next();if(_i3.done)break;_ref3 = _i3.value;}var overwrite=_ref3;finalPacked = finalPacked & ~overwrite.deny;finalPacked = finalPacked | overwrite.allow;}return new EvaluatedPermissions(finalPacked);};_createClass(Member,[{key:"roles",get:function get(){var ufRoles=[this.server.getRole(this.server.id)];for(var _iterator4=this.rawRoles,_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[Symbol.iterator]();;) {var _ref4;if(_isArray4){if(_i4 >= _iterator4.length)break;_ref4 = _iterator4[_i4++];}else {_i4 = _iterator4.next();if(_i4.done)break;_ref4 = _i4.value;}var rawRole=_ref4;ufRoles.push(this.server.getRole(rawRole));}return ufRoles;}},{key:"evalPerms",get:function get(){var basePerms=this.roles, //cache roles as it can be slightly expensive +basePerm=basePerms[0].packed;for(var _iterator5=basePerms,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var perm=_ref5;basePerm = basePerm | perm.packed;}return new ServerPermissions({permissions:basePerm});}}]);return Member;})(User);module.exports = Member; diff --git a/lib/PMChannel.js b/lib/PMChannel.js index 06d1c120b..8d90dade1 100644 --- a/lib/PMChannel.js +++ b/lib/PMChannel.js @@ -1,61 +1 @@ -"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 PMChannel = (function () { - function PMChannel(data, client) { - _classCallCheck(this, PMChannel); - - this.user = client.getUser("id", data.recipient.id); - this.id = data.id; - this.messages = []; - this.client = client; - } - - PMChannel.prototype.addMessage = function addMessage(data) { - if (!this.getMessage("id", data.id)) { - this.messages.push(data); - } - return this.getMessage("id", data.id); - }; - - PMChannel.prototype.getMessage = function getMessage(key, value) { - - if (this.messages.length > 1000) { - this.messages.splice(0, 1); - } - - for (var _iterator = this.messages, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { - var _ref; - - if (_isArray) { - if (_i >= _iterator.length) break; - _ref = _iterator[_i++]; - } else { - _i = _iterator.next(); - if (_i.done) break; - _ref = _i.value; - } - - var message = _ref; - - if (message[key] === value) { - return message; - } - } - return null; - }; - - _createClass(PMChannel, [{ - key: "isPrivate", - get: function get() { - return true; - } - }]); - - return PMChannel; -})(); - -module.exports = PMChannel; \ No newline at end of file +"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 PMChannel=(function(){function PMChannel(data,client){_classCallCheck(this,PMChannel);this.user = client.getUser("id",data.recipient.id);this.id = data.id;this.messages = [];this.client = client;}PMChannel.prototype.addMessage = function addMessage(data){if(!this.getMessage("id",data.id)){this.messages.push(data);}return this.getMessage("id",data.id);};PMChannel.prototype.getMessage = function getMessage(key,value){if(this.messages.length > 1000){this.messages.splice(0,1);}for(var _iterator=this.messages,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var message=_ref;if(message[key] === value){return message;}}return null;};_createClass(PMChannel,[{key:"isPrivate",get:function get(){return true;}}]);return PMChannel;})();module.exports = PMChannel; diff --git a/lib/ServerPermissions.js b/lib/ServerPermissions.js index 6384f759b..c4ad8cefb 100644 --- a/lib/ServerPermissions.js +++ b/lib/ServerPermissions.js @@ -1,199 +1,2 @@ -"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 ServerPermissions = (function () { - function ServerPermissions(data) { - _classCallCheck(this, ServerPermissions); - - var self = this; - - function getBit(x) { - return (self.packed >>> x & 1) === 1; - } - - this.packed = data.permissions; - this.name = data.name; - this.id = data.id; - } - - ServerPermissions.prototype.getBit = function getBit(x) { - return (this.packed >>> x & 1) === 1; - }; - - ServerPermissions.prototype.setBit = function setBit() { - //dummy function for now - }; - - ServerPermissions.prototype.toString = function toString() { - return this.name; - }; - - _createClass(ServerPermissions, [{ - key: "createInstantInvite", - get: function get() { - return this.getBit(0); - }, - set: function set(val) { - this.setBit(0, val); - } - }, { - key: "banMembers", - get: function get() { - return this.getBit(1); - }, - set: function set(val) { - this.setBit(1, val); - } - }, { - key: "kickMembers", - get: function get() { - return this.getBit(2); - }, - set: function set(val) { - this.setBit(2, val); - } - }, { - key: "manageRoles", - get: function get() { - return this.getBit(3); - }, - set: function set(val) { - this.setBit(3, val); - } - }, { - key: "manageChannels", - get: function get() { - return this.getBit(4); - }, - set: function set(val) { - this.setBit(4, val); - } - }, { - key: "manageServer", - get: function get() { - return this.getBit(5); - }, - set: function set(val) { - this.setBit(5, val); - } - }, { - key: "readMessages", - get: function get() { - return this.getBit(10); - }, - set: function set(val) { - this.setBit(10, val); - } - }, { - key: "sendMessages", - get: function get() { - return this.getBit(11); - }, - set: function set(val) { - this.setBit(11, val); - } - }, { - key: "sendTTSMessages", - get: function get() { - return this.getBit(12); - }, - set: function set(val) { - this.setBit(12, val); - } - }, { - key: "manageMessages", - get: function get() { - return this.getBit(13); - }, - set: function set(val) { - this.setBit(13, val); - } - }, { - key: "embedLinks", - get: function get() { - return this.getBit(14); - }, - set: function set(val) { - this.setBit(14, val); - } - }, { - key: "attachFiles", - get: function get() { - return this.getBit(15); - }, - set: function set(val) { - this.setBit(15, val); - } - }, { - key: "readMessageHistory", - get: function get() { - return this.getBit(16); - }, - set: function set(val) { - this.setBit(16, val); - } - }, { - key: "mentionEveryone", - get: function get() { - return this.getBit(17); - }, - set: function set(val) { - this.setBit(17, val); - } - }, { - key: "voiceConnect", - get: function get() { - return this.getBit(20); - }, - set: function set(val) { - this.setBit(20, val); - } - }, { - key: "voiceSpeak", - get: function get() { - return this.getBit(21); - }, - set: function set(val) { - this.setBit(21, val); - } - }, { - key: "voiceMuteMembers", - get: function get() { - return this.getBit(22); - }, - set: function set(val) { - this.setBit(22, val); - } - }, { - key: "voiceDeafenMembers", - get: function get() { - return this.getBit(23); - }, - set: function set(val) { - this.setBit(23, val); - } - }, { - key: "voiceMoveMembers", - get: function get() { - return this.getBit(24); - }, - set: function set(val) { - this.setBit(24, val); - } - }, { - key: "voiceUseVoiceActivation", - get: function get() { - return this.getBit(25); - }, - set: function set(val) { - this.setBit(25, val); - } - }]); - - return ServerPermissions; -})(); - -module.exports = ServerPermissions; \ No newline at end of file +"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 ServerPermissions=(function(){function ServerPermissions(data){_classCallCheck(this,ServerPermissions);var self=this;function getBit(x){return (self.packed >>> x & 1) === 1;}this.packed = data.permissions;this.name = data.name;this.id = data.id;}ServerPermissions.prototype.getBit = function getBit(x){return (this.packed >>> x & 1) === 1;};ServerPermissions.prototype.setBit = function setBit(){ //dummy function for now +};ServerPermissions.prototype.toString = function toString(){return this.name;};_createClass(ServerPermissions,[{key:"createInstantInvite",get:function get(){return this.getBit(0);},set:function set(val){this.setBit(0,val);}},{key:"banMembers",get:function get(){return this.getBit(1);},set:function set(val){this.setBit(1,val);}},{key:"kickMembers",get:function get(){return this.getBit(2);},set:function set(val){this.setBit(2,val);}},{key:"manageRoles",get:function get(){return this.getBit(3);},set:function set(val){this.setBit(3,val);}},{key:"manageChannels",get:function get(){return this.getBit(4);},set:function set(val){this.setBit(4,val);}},{key:"manageServer",get:function get(){return this.getBit(5);},set:function set(val){this.setBit(5,val);}},{key:"readMessages",get:function get(){return this.getBit(10);},set:function set(val){this.setBit(10,val);}},{key:"sendMessages",get:function get(){return this.getBit(11);},set:function set(val){this.setBit(11,val);}},{key:"sendTTSMessages",get:function get(){return this.getBit(12);},set:function set(val){this.setBit(12,val);}},{key:"manageMessages",get:function get(){return this.getBit(13);},set:function set(val){this.setBit(13,val);}},{key:"embedLinks",get:function get(){return this.getBit(14);},set:function set(val){this.setBit(14,val);}},{key:"attachFiles",get:function get(){return this.getBit(15);},set:function set(val){this.setBit(15,val);}},{key:"readMessageHistory",get:function get(){return this.getBit(16);},set:function set(val){this.setBit(16,val);}},{key:"mentionEveryone",get:function get(){return this.getBit(17);},set:function set(val){this.setBit(17,val);}},{key:"voiceConnect",get:function get(){return this.getBit(20);},set:function set(val){this.setBit(20,val);}},{key:"voiceSpeak",get:function get(){return this.getBit(21);},set:function set(val){this.setBit(21,val);}},{key:"voiceMuteMembers",get:function get(){return this.getBit(22);},set:function set(val){this.setBit(22,val);}},{key:"voiceDeafenMembers",get:function get(){return this.getBit(23);},set:function set(val){this.setBit(23,val);}},{key:"voiceMoveMembers",get:function get(){return this.getBit(24);},set:function set(val){this.setBit(24,val);}},{key:"voiceUseVoiceActivation",get:function get(){return this.getBit(25);},set:function set(val){this.setBit(25,val);}}]);return ServerPermissions;})();module.exports = ServerPermissions; diff --git a/lib/channel.js b/lib/channel.js index 7b8b1c027..04c363943 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -1,130 +1,2 @@ -"use strict"; - -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var ChannelPermissions = require("./ChannelPermissions.js"); - -var Channel = (function () { - function Channel(data, server) { - _classCallCheck(this, Channel); - - this.server = server; - this.name = data.name; - this.type = data.type; - this.topic = data.topic; - this.id = data.id; - this.messages = []; - this.roles = []; - - if (data.permission_overwrites) for (var _iterator = data.permission_overwrites, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { - var _ref; - - if (_isArray) { - if (_i >= _iterator.length) break; - _ref = _iterator[_i++]; - } else { - _i = _iterator.next(); - if (_i.done) break; - _ref = _i.value; - } - - var role = _ref; - - this.roles.push(new ChannelPermissions(role, this)); - } - - //this.isPrivate = isPrivate; //not sure about the implementation of this... - } - - Channel.prototype.permissionsOf = function permissionsOf(member) { - - var mem = this.server.getMember("id", member.id); - - if (mem) { - return mem.permissionsIn(this); - } else { - return null; - } - }; - - Channel.prototype.equals = function equals(object) { - return object && object.id === this.id; - }; - - Channel.prototype.addMessage = function addMessage(data) { - - if (this.messages.length > 1000) { - this.messages.splice(0, 1); - } - - if (!this.getMessage("id", data.id)) { - this.messages.push(data); - } - - return this.getMessage("id", data.id); - }; - - Channel.prototype.getMessage = function getMessage(key, value) { - for (var _iterator2 = this.messages, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { - var _ref2; - - if (_isArray2) { - if (_i2 >= _iterator2.length) break; - _ref2 = _iterator2[_i2++]; - } else { - _i2 = _iterator2.next(); - if (_i2.done) break; - _ref2 = _i2.value; - } - - var message = _ref2; - - if (message[key] === value) { - return message; - } - } - return null; - }; - - Channel.prototype.toString = function toString() { - return "<#" + this.id + ">"; - }; - - _createClass(Channel, [{ - key: "permissionOverwrites", - get: function get() { - return this.roles; - } - }, { - key: "permissions", - get: function get() { - return this.roles; - } - }, { - key: "client", - get: function get() { - return this.server.client; - } - }, { - key: "isPrivate", - get: function get() { - return false; - } - }, { - key: "users", - get: function get() { - return this.server.members; - } - }, { - key: "members", - get: function get() { - return this.server.members; - } - }]); - - return Channel; -})(); - -module.exports = Channel; \ No newline at end of file +"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var ChannelPermissions=require("./ChannelPermissions.js");var Channel=(function(){function Channel(data,server){_classCallCheck(this,Channel);this.server = server;this.name = data.name;this.type = data.type;this.topic = data.topic;this.id = data.id;this.messages = [];this.roles = [];if(data.permission_overwrites)for(var _iterator=data.permission_overwrites,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var role=_ref;this.roles.push(new ChannelPermissions(role,this));} //this.isPrivate = isPrivate; //not sure about the implementation of this... +}Channel.prototype.permissionsOf = function permissionsOf(member){var mem=this.server.getMember("id",member.id);if(mem){return mem.permissionsIn(this);}else {return null;}};Channel.prototype.equals = function equals(object){return object && object.id === this.id;};Channel.prototype.addMessage = function addMessage(data){if(this.messages.length > 1000){this.messages.splice(0,1);}if(!this.getMessage("id",data.id)){this.messages.push(data);}return this.getMessage("id",data.id);};Channel.prototype.getMessage = function getMessage(key,value){for(var _iterator2=this.messages,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var message=_ref2;if(message[key] === value){return message;}}return null;};Channel.prototype.toString = function toString(){return "<#" + this.id + ">";};_createClass(Channel,[{key:"permissionOverwrites",get:function get(){return this.roles;}},{key:"permissions",get:function get(){return this.roles;}},{key:"client",get:function get(){return this.server.client;}},{key:"isPrivate",get:function get(){return false;}},{key:"users",get:function get(){return this.server.members;}},{key:"members",get:function get(){return this.server.members;}}]);return Channel;})();module.exports = Channel; diff --git a/lib/index.js b/lib/index.js index 2763c3b6c..9eabba0ae 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,36 +1 @@ -"use strict"; - -var request = require("superagent"); -var Endpoints = require("./Endpoints.js"); -var Client = require("./Client.js"); - -var Discord = { - Endpoints: Endpoints, - Client: Client -}; - -Discord.patchStrings = function () { - - defineProperty("bold", "**"); - defineProperty("underline", "__"); - defineProperty("strike", "~~"); - defineProperty("code", "`"); - defineProperty("codeblock", "```"); - defineProperty("newline", "\n"); - - Object.defineProperty(String.prototype, "italic", { - get: function () { - return "*" + this + "*"; - } - }); - - function defineProperty(name, joiner) { - Object.defineProperty(String.prototype, name, { - get: function () { - return joiner + this + joiner; - } - }); - } -} - -module.exports = Discord; \ No newline at end of file +"use strict";var request=require("superagent");var Endpoints=require("./Endpoints.js");var Client=require("./Client.js");var Discord={Endpoints:Endpoints,Client:Client};module.exports = Discord; diff --git a/lib/internal.js b/lib/internal.js index 3acf5940b..b91c38597 100644 --- a/lib/internal.js +++ b/lib/internal.js @@ -1,203 +1 @@ -"use strict"; - -var request = require("superagent"); -var Endpoints = require("./endpoints.js"); - -var Internal = {}; - -Internal.XHR = {}; -Internal.WebSocket = {}; - -Internal.WebSocket.properties = { - "$os": "discord.js", - "$browser": "discord.js", - "$device": "discord.js", - "$referrer": "", - "$referring_domain": "" -}; - -Internal.XHR.login = function (email, password, callback) { - - request.post(Endpoints.LOGIN).send({ - email: email, - password: password - }).end(function (err, res) { - if (err) { - callback(err); - } else { - callback(null, res.body.token); - } - }); -}; - -Internal.XHR.logout = function (token, callback) { - - request.post(Endpoints.LOGOUT).end(function (err, res) { - - err ? callback(err) : callback(null); - }); -}; - -Internal.XHR.createServer = function (token, name, region, callback) { - - request.post(Endpoints.SERVERS).set("authorization", token).send({ - name: name, - region: region - }).end(function (err, res) { - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.leaveServer = function (token, serverId, callback) { - - request.del(Endpoints.SERVERS + "/" + serverId).set("authorization", token).end(function (err, res) { - - err ? callback(err) : callback(null); - }); -}; - -Internal.XHR.createInvite = function (token, channelId, options, callback) { - request.post(Endpoints.CHANNELS + "/" + channelId + "/invites").set("authorization", token).send(options).end(function (err, res) { - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.startPM = function (token, selfID, userID, callback) { - - request.post(Endpoints.USERS + "/" + selfID + "/channels").set("authorization", token).send({ - recipient_id: userID - }).end(function (err, res) { - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.sendMessage = function (token, channelID, messageParameters, callback) { - request.post(Endpoints.CHANNELS + "/" + channelID + "/messages").set("authorization", token).send(messageParameters).end(function (err, res) { - - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.sendFile = function (token, channelID, file, fileName, callback) { - request.post(Endpoints.CHANNELS + "/" + channelID + "/messages").set("authorization", token).attach("file", file, fileName).end(function (err, res) { - - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.deleteMessage = function (token, channelID, messageID, callback) { - request.del(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID).set("authorization", token).end(function (err) { - err ? callback(err) : callback(null); - }); -}; - -Internal.XHR.updateMessage = function (token, channelID, messageID, messageParameters, callback) { - - request.patch(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID).set("authorization", token).send(messageParameters).end(function (err, res) { - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.getChannelLogs = function (token, channelID, amount, callback) { - request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization", token).end(function (err, res) { - - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.createChannel = function (token, serverID, name, type, callback) { - request.post(Endpoints.SERVERS + "/" + serverID + "/channels").set("authorization", token).send({ - name: name, - type: type - }).end(function (err, res) { - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.deleteChannel = function (token, channelID, callback) { - - request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization", token).end(function (err) { - err ? callback(err) : callback(null); - }); -}; -Internal.XHR.deleteServer = function (token, serverID, callback) { - request.del(Endpoints.SERVERS + "/" + serverID).set("authorization", token).end(function (err) { - err ? callback(err) : callback(null); - }); -}; - -Internal.XHR.getChannels = function (token, serverID, callback) { - request.get(Endpoints.SERVERS + "/" + serverID + "/channels").set("authorization", token).end(function (err) { - err ? callback(err) : callback(null); - }); -}; - -Internal.XHR.getServer = function (token, serverID, callback) { - - request.get(Endpoints.SERVERS + "/" + serverID).set("authorization", token).end(function (err, res) { - - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.acceptInvite = function (token, inviteID, callback) { - - request.post(Endpoints.API + "/invite/" + inviteID).set("authorization", token).end(function (err, res) { - if (err) { - callback(err); - } else { - callback(null, res.body); - } - }); -}; - -Internal.XHR.setUsername = function (token, avatar, email, newPassword, password, username, callback) { - - request.patch(Endpoints.API + "/users/@me").set("authorization", token).send({ - avatar: avatar, - email: email, - new_password: newPassword, - password: password, - username: username - }).end(function (err) { - callback(err); - }); -}; - -exports.Internal = Internal; \ No newline at end of file +"use strict";var request=require("superagent");var Endpoints=require("./endpoints.js");var Internal={};Internal.XHR = {};Internal.WebSocket = {};Internal.WebSocket.properties = {"$os":"discord.js","$browser":"discord.js","$device":"discord.js","$referrer":"","$referring_domain":""};Internal.XHR.login = function(email,password,callback){request.post(Endpoints.LOGIN).send({email:email,password:password}).end(function(err,res){if(err){callback(err);}else {callback(null,res.body.token);}});};Internal.XHR.logout = function(token,callback){request.post(Endpoints.LOGOUT).end(function(err,res){err?callback(err):callback(null);});};Internal.XHR.createServer = function(token,name,region,callback){request.post(Endpoints.SERVERS).set("authorization",token).send({name:name,region:region}).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.leaveServer = function(token,serverId,callback){request.del(Endpoints.SERVERS + "/" + serverId).set("authorization",token).end(function(err,res){err?callback(err):callback(null);});};Internal.XHR.createInvite = function(token,channelId,options,callback){request.post(Endpoints.CHANNELS + "/" + channelId + "/invites").set("authorization",token).send(options).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.startPM = function(token,selfID,userID,callback){request.post(Endpoints.USERS + "/" + selfID + "/channels").set("authorization",token).send({recipient_id:userID}).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.sendMessage = function(token,channelID,messageParameters,callback){request.post(Endpoints.CHANNELS + "/" + channelID + "/messages").set("authorization",token).send(messageParameters).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.sendFile = function(token,channelID,file,fileName,callback){request.post(Endpoints.CHANNELS + "/" + channelID + "/messages").set("authorization",token).attach("file",file,fileName).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.deleteMessage = function(token,channelID,messageID,callback){request.del(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID).set("authorization",token).end(function(err){err?callback(err):callback(null);});};Internal.XHR.updateMessage = function(token,channelID,messageID,messageParameters,callback){request.patch(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID).set("authorization",token).send(messageParameters).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.getChannelLogs = function(token,channelID,amount,callback){request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization",token).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.createChannel = function(token,serverID,name,type,callback){request.post(Endpoints.SERVERS + "/" + serverID + "/channels").set("authorization",token).send({name:name,type:type}).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.deleteChannel = function(token,channelID,callback){request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization",token).end(function(err){err?callback(err):callback(null);});};Internal.XHR.deleteServer = function(token,serverID,callback){request.del(Endpoints.SERVERS + "/" + serverID).set("authorization",token).end(function(err){err?callback(err):callback(null);});};Internal.XHR.getChannels = function(token,serverID,callback){request.get(Endpoints.SERVERS + "/" + serverID + "/channels").set("authorization",token).end(function(err){err?callback(err):callback(null);});};Internal.XHR.getServer = function(token,serverID,callback){request.get(Endpoints.SERVERS + "/" + serverID).set("authorization",token).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.acceptInvite = function(token,inviteID,callback){request.post(Endpoints.API + "/invite/" + inviteID).set("authorization",token).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.setUsername = function(token,avatar,email,newPassword,password,username,callback){request.patch(Endpoints.API + "/users/@me").set("authorization",token).send({avatar:avatar,email:email,new_password:newPassword,password:password,username:username}).end(function(err){callback(err);});};exports.Internal = Internal; diff --git a/lib/invite.js b/lib/invite.js index 5f51dc1a9..5ff2ddf15 100644 --- a/lib/invite.js +++ b/lib/invite.js @@ -1,35 +1 @@ -"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 Invite = (function () { - function Invite(data, client) { - _classCallCheck(this, Invite); - - this.max_age = data.max_age; - this.code = data.code; - this.server = client.getServer("id", data.guild.id); - this.revoked = data.revoked; - this.created_at = Date.parse(data.created_at); - this.temporary = data.temporary; - this.uses = data.uses; - this.max_uses = data.uses; - this.inviter = client.addUser(data.inviter); - this.xkcd = data.xkcdpass; - this.channel = client.getChannel("id", data.channel.id); - } - - _createClass(Invite, [{ - key: "URL", - get: function get() { - var code = this.xkcd ? this.xkcdpass : this.code; - return "https://discord.gg/" + code; - } - }]); - - return Invite; -})(); - -module.exports = Invite; \ No newline at end of file +"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 Invite=(function(){function Invite(data,client){_classCallCheck(this,Invite);this.max_age = data.max_age;this.code = data.code;this.server = client.getServer("id",data.guild.id);this.revoked = data.revoked;this.created_at = Date.parse(data.created_at);this.temporary = data.temporary;this.uses = data.uses;this.max_uses = data.uses;this.inviter = client.addUser(data.inviter);this.xkcd = data.xkcdpass;this.channel = client.getChannel("id",data.channel.id);}_createClass(Invite,[{key:"URL",get:function get(){var code=this.xkcd?this.xkcdpass:this.code;return "https://discord.gg/" + code;}}]);return Invite;})();module.exports = Invite; diff --git a/lib/message.js b/lib/message.js index 72c1eb7f2..26d9e4f69 100644 --- a/lib/message.js +++ b/lib/message.js @@ -1,75 +1,3 @@ -"use strict"; - -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var PMChannel = require("./PMChannel.js"); - -var Message = (function () { - function Message(data, channel, mentions, author) { - _classCallCheck(this, Message); - - this.tts = data.tts; - this.timestamp = Date.parse(data.timestamp); - this.nonce = data.nonce; - this.mentions = mentions; - this.everyoneMentioned = data.mention_everyone; - this.id = data.id; - this.embeds = data.embeds; - this.editedTimestamp = data.edited_timestamp; - this.content = data.content.trim(); - this.channel = channel; - - if (this.isPrivate) { - this.author = this.channel.client.getUser("id", author.id); - } else { - this.author = this.channel.server.getMember("id", author.id) || this.channel.client.getUser("id", author.id); - } - - this.attachments = data.attachments; - } - - /*exports.Message.prototype.isPM = function() { - return ( this.channel instanceof PMChannel ); - }*/ - - Message.prototype.isMentioned = function isMentioned(user) { - var id = user.id ? user.id : user; - for (var _iterator = this.mentions, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { - var _ref; - - if (_isArray) { - if (_i >= _iterator.length) break; - _ref = _iterator[_i++]; - } else { - _i = _iterator.next(); - if (_i.done) break; - _ref = _i.value; - } - - var mention = _ref; - - if (mention.id === id) { - return true; - } - } - return false; - }; - - _createClass(Message, [{ - key: "sender", - get: function get() { - return this.author; - } - }, { - key: "isPrivate", - get: function get() { - return this.channel.isPrivate; - } - }]); - - return Message; -})(); - -module.exports = Message; \ No newline at end of file +"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 PMChannel=require("./PMChannel.js");var Message=(function(){function Message(data,channel,mentions,author){_classCallCheck(this,Message);this.tts = data.tts;this.timestamp = Date.parse(data.timestamp);this.nonce = data.nonce;this.mentions = mentions;this.everyoneMentioned = data.mention_everyone;this.id = data.id;this.embeds = data.embeds;this.editedTimestamp = data.edited_timestamp;this.content = data.content.trim();this.channel = channel;if(this.isPrivate){this.author = this.channel.client.getUser("id",author.id);}else {this.author = this.channel.server.getMember("id",author.id) || this.channel.client.getUser("id",author.id);}this.attachments = data.attachments;} /*exports.Message.prototype.isPM = function() { + return ( this.channel instanceof PMChannel ); +}*/Message.prototype.isMentioned = function isMentioned(user){var id=user.id?user.id:user;for(var _iterator=this.mentions,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var mention=_ref;if(mention.id === id){return true;}}return false;};_createClass(Message,[{key:"sender",get:function get(){return this.author;}},{key:"isPrivate",get:function get(){return this.channel.isPrivate;}}]);return Message;})();module.exports = Message; diff --git a/lib/server.js b/lib/server.js index 46676d5eb..b2fc6353a 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1,277 +1,7 @@ -"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 ServerPermissions = require("./ServerPermissions.js"); -var Member = require("./Member.js"); - -var Server = (function () { - function Server(data, client) { - _classCallCheck(this, Server); - - this.client = client; - this.region = data.region; - this.ownerID = data.owner_id; - this.name = data.name; - this.id = data.id; - this.members = []; - this.channels = []; - this.icon = data.icon; - this.afkTimeout = data.afk_timeout; - this.afkChannelId = data.afk_channel_id; - - this.roles = []; - - for (var _iterator = data.roles, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { - var _ref; - - if (_isArray) { - if (_i >= _iterator.length) break; - _ref = _iterator[_i++]; - } else { - _i = _iterator.next(); - if (_i.done) break; - _ref = _i.value; - } - - var permissionGroup = _ref; - - this.roles.push(new ServerPermissions(permissionGroup)); - } - - if (!data.members) { - data.members = [client.user]; - return; - } - - for (var _iterator2 = data.members, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { - var _ref2; - - if (_isArray2) { - if (_i2 >= _iterator2.length) break; - _ref2 = _iterator2[_i2++]; - } else { - _i2 = _iterator2.next(); - if (_i2.done) break; - _ref2 = _i2.value; - } - - var member = _ref2; - - // first we cache the user in our Discord Client, - // then we add it to our list. This way when we - // get a user from this server's member list, - // it will be identical (unless an async change occurred) - // to the client's cache. - if (member.user) this.addMember(client.addUser(member.user), member.roles); - } - } - - // get/set - - Server.prototype.getRole = function getRole(id) { - for (var _iterator3 = this.roles, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { - var _ref3; - - if (_isArray3) { - if (_i3 >= _iterator3.length) break; - _ref3 = _iterator3[_i3++]; - } else { - _i3 = _iterator3.next(); - if (_i3.done) break; - _ref3 = _i3.value; - } - - var role = _ref3; - - if (role.id === id) { - return role; - } - } - - return null; - }; - - Server.prototype.updateRole = function updateRole(data) { - - var oldRole = this.getRole(data.id); - - if (oldRole) { - - var index = this.roles.indexOf(oldRole); - this.roles[index] = new ServerPermissions(data); - - return this.roles[index]; - } else { - return false; - } - }; - - Server.prototype.removeRole = function removeRole(id) { - for (var roleId in this.roles) { - if (this.roles[roleId].id === id) { - this.roles.splice(roleId, 1); - } - } - - for (var _iterator4 = this.members, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { - var _ref4; - - if (_isArray4) { - if (_i4 >= _iterator4.length) break; - _ref4 = _iterator4[_i4++]; - } else { - _i4 = _iterator4.next(); - if (_i4.done) break; - _ref4 = _i4.value; - } - - var member = _ref4; - - for (var roleId in member.rawRoles) { - if (member.rawRoles[roleId] === id) { - member.rawRoles.splice(roleId, 1); - } - } - } - }; - - Server.prototype.getChannel = function getChannel(key, value) { - for (var _iterator5 = this.channels, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { - var _ref5; - - if (_isArray5) { - if (_i5 >= _iterator5.length) break; - _ref5 = _iterator5[_i5++]; - } else { - _i5 = _iterator5.next(); - if (_i5.done) break; - _ref5 = _i5.value; - } - - var channel = _ref5; - - if (channel[key] === value) { - return channel; - } - } - - return null; - }; - - Server.prototype.getMember = function getMember(key, value) { - for (var _iterator6 = this.members, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { - var _ref6; - - if (_isArray6) { - if (_i6 >= _iterator6.length) break; - _ref6 = _iterator6[_i6++]; - } else { - _i6 = _iterator6.next(); - if (_i6.done) break; - _ref6 = _i6.value; - } - - var member = _ref6; - - if (member[key] === value) { - return member; - } - } - - return null; - }; - - Server.prototype.removeMember = function removeMember(key, value) { - for (var _iterator7 = this.members, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) { - var _ref7; - - if (_isArray7) { - if (_i7 >= _iterator7.length) break; - _ref7 = _iterator7[_i7++]; - } else { - _i7 = _iterator7.next(); - if (_i7.done) break; - _ref7 = _i7.value; - } - - var member = _ref7; - - if (member[key] === value) { - this.members.splice(key, 1); - return member; - } - } - - return false; - }; - - Server.prototype.addChannel = function addChannel(chann) { - if (!this.getChannel("id", chann.id)) { - this.channels.push(chann); - } - return chann; - }; - - Server.prototype.addMember = function addMember(user, roles) { - if (!this.getMember("id", user.id)) { - var mem = new Member(user, this, roles); - this.members.push(mem); - } - return mem; - }; - - Server.prototype.toString = function toString() { - return this.name; - }; - - Server.prototype.equals = function equals(object) { - return object.id === this.id; - }; - - _createClass(Server, [{ - key: "permissionGroups", - get: function get() { - return this.roles; - } - }, { - key: "permissions", - get: function get() { - return this.roles; - } - }, { - key: "iconURL", - get: function get() { - if (!this.icon) return null; - return "https://discordapp.com/api/guilds/" + this.id + "/icons/" + this.icon + ".jpg"; - } - }, { - key: "afkChannel", - get: function get() { - if (!this.afkChannelId) return false; - - return this.getChannel("id", this.afkChannelId); - } - }, { - key: "defaultChannel", - get: function get() { - return this.getChannel("name", "general"); - } - }, { - key: "owner", - get: function get() { - return this.client.getUser("id", this.ownerID); - } - }, { - key: "users", - get: function get() { - return this.members; - } - }]); - - return Server; -})(); - -module.exports = Server; \ No newline at end of file +"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 ServerPermissions=require("./ServerPermissions.js");var Member=require("./Member.js");var Server=(function(){function Server(data,client){_classCallCheck(this,Server);this.client = client;this.region = data.region;this.ownerID = data.owner_id;this.name = data.name;this.id = data.id;this.members = [];this.channels = [];this.icon = data.icon;this.afkTimeout = data.afk_timeout;this.afkChannelId = data.afk_channel_id;this.roles = [];for(var _iterator=data.roles,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var permissionGroup=_ref;this.roles.push(new ServerPermissions(permissionGroup));}if(!data.members){data.members = [client.user];return;}for(var _iterator2=data.members,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var member=_ref2; // first we cache the user in our Discord Client, +// then we add it to our list. This way when we +// get a user from this server's member list, +// it will be identical (unless an async change occurred) +// to the client's cache. +if(member.user)this.addMember(client.addUser(member.user),member.roles);}} // get/set +Server.prototype.getRole = function getRole(id){for(var _iterator3=this.roles,_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[Symbol.iterator]();;) {var _ref3;if(_isArray3){if(_i3 >= _iterator3.length)break;_ref3 = _iterator3[_i3++];}else {_i3 = _iterator3.next();if(_i3.done)break;_ref3 = _i3.value;}var role=_ref3;if(role.id === id){return role;}}return null;};Server.prototype.updateRole = function updateRole(data){var oldRole=this.getRole(data.id);if(oldRole){var index=this.roles.indexOf(oldRole);this.roles[index] = new ServerPermissions(data);return this.roles[index];}else {return false;}};Server.prototype.removeRole = function removeRole(id){for(var roleId in this.roles) {if(this.roles[roleId].id === id){this.roles.splice(roleId,1);}}for(var _iterator4=this.members,_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[Symbol.iterator]();;) {var _ref4;if(_isArray4){if(_i4 >= _iterator4.length)break;_ref4 = _iterator4[_i4++];}else {_i4 = _iterator4.next();if(_i4.done)break;_ref4 = _i4.value;}var member=_ref4;for(var roleId in member.rawRoles) {if(member.rawRoles[roleId] === id){member.rawRoles.splice(roleId,1);}}}};Server.prototype.getChannel = function getChannel(key,value){for(var _iterator5=this.channels,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var channel=_ref5;if(channel[key] === value){return channel;}}return null;};Server.prototype.getMember = function getMember(key,value){for(var _iterator6=this.members,_isArray6=Array.isArray(_iterator6),_i6=0,_iterator6=_isArray6?_iterator6:_iterator6[Symbol.iterator]();;) {var _ref6;if(_isArray6){if(_i6 >= _iterator6.length)break;_ref6 = _iterator6[_i6++];}else {_i6 = _iterator6.next();if(_i6.done)break;_ref6 = _i6.value;}var member=_ref6;if(member[key] === value){return member;}}return null;};Server.prototype.removeMember = function removeMember(key,value){for(var _iterator7=this.members,_isArray7=Array.isArray(_iterator7),_i7=0,_iterator7=_isArray7?_iterator7:_iterator7[Symbol.iterator]();;) {var _ref7;if(_isArray7){if(_i7 >= _iterator7.length)break;_ref7 = _iterator7[_i7++];}else {_i7 = _iterator7.next();if(_i7.done)break;_ref7 = _i7.value;}var member=_ref7;if(member[key] === value){this.members.splice(key,1);return member;}}return false;};Server.prototype.addChannel = function addChannel(chann){if(!this.getChannel("id",chann.id)){this.channels.push(chann);}return chann;};Server.prototype.addMember = function addMember(user,roles){if(!this.getMember("id",user.id)){var mem=new Member(user,this,roles);this.members.push(mem);}return mem;};Server.prototype.toString = function toString(){return this.name;};Server.prototype.equals = function equals(object){return object.id === this.id;};_createClass(Server,[{key:"permissionGroups",get:function get(){return this.roles;}},{key:"permissions",get:function get(){return this.roles;}},{key:"iconURL",get:function get(){if(!this.icon)return null;return "https://discordapp.com/api/guilds/" + this.id + "/icons/" + this.icon + ".jpg";}},{key:"afkChannel",get:function get(){if(!this.afkChannelId)return false;return this.getChannel("id",this.afkChannelId);}},{key:"defaultChannel",get:function get(){return this.getChannel("name","general");}},{key:"owner",get:function get(){return this.client.getUser("id",this.ownerID);}},{key:"users",get:function get(){return this.members;}}]);return Server;})();module.exports = Server; diff --git a/lib/user.js b/lib/user.js index 2234f030f..ed82a19dc 100644 --- a/lib/user.js +++ b/lib/user.js @@ -1,54 +1,7 @@ -"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 User = (function () { - function User(data) { - _classCallCheck(this, User); - - 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; - } - - // access using user.avatarURL; - - User.prototype.mention = function mention() { - return "<@" + this.id + ">"; - }; - - User.prototype.toString = function toString() { - /* - if we embed a user in a String - like so: - "Yo " + user + " what's up?" - It would generate something along the lines of: - "Yo @hydrabolt what's up?" - */ - return this.mention(); - }; - - User.prototype.equals = function equals(object) { - return object.id === this.id; - }; - - User.prototype.equalsStrict = function equalsStrict(object) { - return object.id === this.id && object.avatar === this.avatar && object.username === this.username && object.discriminator === this.discriminator; - }; - - _createClass(User, [{ - key: "avatarURL", - get: function get() { - if (!this.avatar) return null; - return "https://discordapp.com/api/users/" + this.id + "/avatars/" + this.avatar + ".jpg"; - } - }]); - - return User; -})(); - -module.exports = User; \ No newline at end of file +"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 User=(function(){function User(data){_classCallCheck(this,User);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;} // access using user.avatarURL; +User.prototype.mention = function mention(){return "<@" + this.id + ">";};User.prototype.toString = function toString(){ /* + if we embed a user in a String - like so: + "Yo " + user + " what's up?" + It would generate something along the lines of: + "Yo @hydrabolt what's up?" + */return this.mention();};User.prototype.equals = function equals(object){return object.id === this.id;};User.prototype.equalsStrict = function equalsStrict(object){return object.id === this.id && object.avatar === this.avatar && object.username === this.username && object.discriminator === this.discriminator;};_createClass(User,[{key:"avatarURL",get:function get(){if(!this.avatar)return null;return "https://discordapp.com/api/users/" + this.id + "/avatars/" + this.avatar + ".jpg";}}]);return User;})();module.exports = User; diff --git a/web-dist/discord.3.9.0.js b/web-dist/discord.3.9.0.js new file mode 100644 index 000000000..34d47857f --- /dev/null +++ b/web-dist/discord.3.9.0.js @@ -0,0 +1,1534 @@ +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Discord = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o>> x & 1) === 1;}this.type = data.type; //either member or role +this.id = data.id;if(this.type === "member"){this.packed = channel.server.getMember("id",data.id).evalPerms.packed;}else {this.packed = channel.server.getRole(data.id).packed;}this.packed = this.packed & ~data.deny;this.packed = this.packed | data.allow;this.deny = data.deny;this.allow = data.allow;}ChannelPermissions.prototype.getBit = function getBit(x){return (this.packed >>> x & 1) === 1;};ChannelPermissions.prototype.setBit = function setBit(){};_createClass(ChannelPermissions,[{key:"createInstantInvite",get:function get(){return this.getBit(0);},set:function set(val){this.setBit(0,val);}},{key:"manageRoles",get:function get(){return this.getBit(3);},set:function set(val){this.setBit(3,val);}},{key:"manageChannels",get:function get(){return this.getBit(4);},set:function set(val){this.setBit(4,val);}},{key:"readMessages",get:function get(){return this.getBit(10);},set:function set(val){this.setBit(10,val);}},{key:"sendMessages",get:function get(){return this.getBit(11);},set:function set(val){this.setBit(11,val);}},{key:"sendTTSMessages",get:function get(){return this.getBit(12);},set:function set(val){this.setBit(12,val);}},{key:"manageMessages",get:function get(){return this.getBit(13);},set:function set(val){this.setBit(13,val);}},{key:"embedLinks",get:function get(){return this.getBit(14);},set:function set(val){this.setBit(14,val);}},{key:"attachFiles",get:function get(){return this.getBit(15);},set:function set(val){this.setBit(15,val);}},{key:"readMessageHistory",get:function get(){return this.getBit(16);},set:function set(val){this.setBit(16,val);}},{key:"mentionEveryone",get:function get(){return this.getBit(17);},set:function set(val){this.setBit(17,val);}},{key:"voiceConnect",get:function get(){return this.getBit(20);},set:function set(val){this.setBit(20,val);}},{key:"voiceSpeak",get:function get(){return this.getBit(21);},set:function set(val){this.setBit(21,val);}},{key:"voiceMuteMembers",get:function get(){return this.getBit(22);},set:function set(val){this.setBit(22,val);}},{key:"voiceDeafenMembers",get:function get(){return this.getBit(23);},set:function set(val){this.setBit(23,val);}},{key:"voiceMoveMembers",get:function get(){return this.getBit(24);},set:function set(val){this.setBit(24,val);}},{key:"voiceUseVoiceActivation",get:function get(){return this.getBit(25);},set:function set(val){this.setBit(25,val);}}]);return ChannelPermissions;})();module.exports = ChannelPermissions; + +},{}],2:[function(require,module,exports){ +//discord.js modules +"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 Endpoints=require("./Endpoints.js");var User=require("./user.js");var Server=require("./server.js");var Channel=require("./channel.js");var Message=require("./message.js");var Invite=require("./invite.js");var PMChannel=require("./PMChannel.js");var gameMap=require("../ref/gameMap.json"); //node modules +var request=require("superagent");var WebSocket=require("ws");var fs=require("fs");var defaultOptions={queue:false};var Client=(function(){function Client(){var options=arguments.length <= 0 || arguments[0] === undefined?defaultOptions:arguments[0];var token=arguments.length <= 1 || arguments[1] === undefined?undefined:arguments[1];_classCallCheck(this,Client); /* + When created, if a token is specified the Client will + try connecting with it. If the token is incorrect, no + further efforts will be made to connect. + */this.options = options;this.options.queue = this.options.queue;this.token = token;this.state = 0;this.websocket = null;this.events = {};this.user = null;this.alreadySentData = false;this.serverCreateListener = {};this.typingIntervals = {};this.email = "abc";this.password = "abc"; /* + State values: + 0 - idle + 1 - logging in + 2 - logged in + 3 - ready + 4 - disconnected + */this.userCache = [];this.channelCache = [];this.serverCache = [];this.pmChannelCache = [];this.readyTime = null;this.checkingQueue = {};this.userTypingListener = {};this.queue = {};this.__idleTime = null;this.__gameId = null;}Client.prototype.sendPacket = function sendPacket(JSONObject){if(this.websocket.readyState === 1){this.websocket.send(JSON.stringify(JSONObject));}}; //def debug +Client.prototype.debug = function debug(message){this.trigger("debug",message);};Client.prototype.on = function on(event,fn){this.events[event] = fn;};Client.prototype.off = function off(event){this.events[event] = null;};Client.prototype.keepAlive = function keepAlive(){this.debug("keep alive triggered");this.sendPacket({op:1,d:Date.now()});}; //def trigger +Client.prototype.trigger = function trigger(event){var args=[];for(var arg in arguments) {args.push(arguments[arg]);}var evt=this.events[event];if(evt){evt.apply(this,args.slice(1));}}; //def login +Client.prototype.login = function login(){var email=arguments.length <= 0 || arguments[0] === undefined?"foo@bar.com":arguments[0];var password=arguments.length <= 1 || arguments[1] === undefined?"pass1234":arguments[1];var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,token){}:arguments[2];var self=this;return new Promise(function(resolve,reject){if(self.state === 0 || self.state === 4){self.state = 1; //set the state to logging in +self.email = email;self.password = password;request.post(Endpoints.LOGIN).send({email:email,password:password}).end(function(err,res){if(err){self.state = 4; //set state to disconnected +self.trigger("disconnected");if(self.websocket){self.websocket.close();}callback(err);reject(err);}else {self.state = 2; //set state to logged in (not yet ready) +self.token = res.body.token; //set our token +self.getGateway().then(function(url){self.createws(url);callback(null,self.token);resolve(self.token);})["catch"](function(err){callback(err);reject(err);});}});}else {reject(new Error("Client already logging in or ready"));}});};Client.prototype.logout = function logout(){var callback=arguments.length <= 0 || arguments[0] === undefined?function(err){}:arguments[0];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.LOGOUT).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {self.websocket.close();self.state = 4;callback();resolve();}});});};Client.prototype.createServer = function createServer(name,region){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,server){}:arguments[2];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.SERVERS).set("authorization",self.token).send({name:name,region:region}).end(function(err,res){if(err){callback(err);reject(err);}else { // potentially redundant in future +// creating here does NOT give us the channels of the server +// so we must wait for the guild_create event. +self.serverCreateListener[res.body.id] = [resolve,callback]; /*var srv = self.addServer(res.body); + callback(null, srv); + resolve(srv);*/}});});};Client.prototype.createChannel = function createChannel(server,channelName,channelType){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,chann){}:arguments[3];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.SERVERS + "/" + self.resolveServerID(server) + "/channels").set("authorization",self.token).send({name:channelName,type:channelType}).end(function(err,res){if(err){callback(err);reject(err);}else {var server=self.getServer("id",res.body.guild_id);var chann=self.addChannel(res.body,res.body.guild_id);server.addChannel(chann);callback(null,chann);resolve(chann);}});});};Client.prototype.leaveServer = function leaveServer(server){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,server){}:arguments[1];var self=this;return new Promise(function(resolve,reject){request.del(Endpoints.SERVERS + "/" + self.resolveServerID(server)).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {self.serverCache.splice(self.serverCache.indexOf(server),1);callback(null);resolve();}});});};Client.prototype.createInvite = function createInvite(serverOrChannel,options){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,invite){}:arguments[2];var self=this;return new Promise(function(resolve,reject){var destination;if(serverOrChannel instanceof Server){destination = serverOrChannel.id;}else if(serverOrChannel instanceof Channel){destination = serverOrChannel.id;}else {destination = serverOrChannel;}options = options || {};options.max_age = options.maxAge || 0;options.max_uses = options.maxUses || 0;options.temporary = options.temporary || false;options.xkcdpass = options.xkcd || false;request.post(Endpoints.CHANNELS + "/" + destination + "/invites").set("authorization",self.token).send(options).end(function(err,res){if(err){callback(err);reject(err);}else {var inv=new Invite(res.body,self);callback(null,inv);resolve(inv);}});});};Client.prototype.startPM = function startPM(user){var self=this;return new Promise(function(resolve,reject){var userId=user;if(user instanceof User){userId = user.id;}request.post(Endpoints.USERS + "/" + self.user.id + "/channels").set("authorization",self.token).send({recipient_id:userId}).end(function(err,res){if(err){reject(err);}else {resolve(self.addPMChannel(res.body));}});});};Client.prototype.reply = function reply(destination,message,tts){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var self=this;return new Promise(function(response,reject){if(typeof tts === "function"){ // tts is a function, which means the developer wants this to be the callback +callback = tts;tts = false;}var user=destination.sender;self.sendMessage(destination,message,tts,callback,user + ", ").then(response)["catch"](reject);});};Client.prototype.deleteMessage = function deleteMessage(message,timeout){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,msg){}:arguments[2];var self=this;return new Promise(function(resolve,reject){if(timeout){setTimeout(remove,timeout);}else {remove();}function remove(){request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization",self.token).end(function(err,res){if(err){bad();}else {good();}});}function good(){callback();resolve();}function bad(err){callback(err);reject(err);}});};Client.prototype.updateMessage = function updateMessage(message,content){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,msg){}:arguments[2];var self=this;var prom=new Promise(function(resolve,reject){content = content instanceof Array?content.join("\n"):content;if(self.options.queue){if(!self.queue[message.channel.id]){self.queue[message.channel.id] = [];}self.queue[message.channel.id].push({action:"updateMessage",message:message,content:content,then:good,error:bad});self.checkQueue(message.channel.id);}else {self._updateMessage(message,content).then(good)["catch"](bad);}function good(msg){prom.message = msg;callback(null,msg);resolve(msg);}function bad(error){prom.error = error;callback(error);reject(error);}});return prom;};Client.prototype.setUsername = function setUsername(newName){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){request.patch(Endpoints.API + "/users/@me").set("authorization",self.token).send({avatar:self.user.avatar,email:self.email,new_password:null,password:self.password,username:newName}).end(function(err){callback(err);if(err)reject(err);else resolve();});});};Client.prototype.getChannelLogs = function getChannelLogs(channel){var amount=arguments.length <= 1 || arguments[1] === undefined?500:arguments[1];var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,logs){}:arguments[2];var self=this;return new Promise(function(resolve,reject){var channelID=channel;if(channel instanceof Channel){channelID = channel.id;}request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {var logs=[];var channel=self.getChannel("id",channelID);for(var _iterator=res.body,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var message=_ref;var mentions=[];for(var _iterator2=message.mentions,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var mention=_ref2;mentions.push(self.addUser(mention));}var author=self.addUser(message.author);logs.push(new Message(message,channel,mentions,author));}callback(null,logs);resolve(logs);}});});};Client.prototype.deleteChannel = function deleteChannel(channel){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){var channelID=channel;if(channel instanceof Channel){channelID = channel.id;}request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization",self.token).end(function(err){if(err){callback(err);reject(err);}else {callback(null);resolve();}});});};Client.prototype.joinServer = function joinServer(invite){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,server){}:arguments[1];var self=this;return new Promise(function(resolve,reject){var id=invite instanceof Invite?invite.code:invite;request.post(Endpoints.API + "/invite/" + id).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {if(self.getServer("id",res.body.guild.id)){resolve(self.getServer("id",res.body.guild.id));}else {self.serverCreateListener[res.body.guild.id] = [resolve,callback];}}});});};Client.prototype.sendFile = function sendFile(destination,file){var fileName=arguments.length <= 2 || arguments[2] === undefined?"image.png":arguments[2];var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var self=this;var prom=new Promise(function(resolve,reject){var fstream;if(typeof file === "string" || file instanceof String){fstream = fs.createReadStream(file);fileName = file;}else {fstream = file;}self.resolveDestination(destination).then(send)["catch"](bad);function send(destination){if(self.options.queue){ //queue send file too +if(!self.queue[destination]){self.queue[destination] = [];}self.queue[destination].push({action:"sendFile",attachment:fstream,attachmentName:fileName,then:good,error:bad});self.checkQueue(destination);}else { //not queue +self._sendFile(destination,fstream,fileName).then(good)["catch"](bad);}}function good(msg){prom.message = msg;callback(null,msg);resolve(msg);}function bad(err){prom.error = err;callback(err);reject(err);}});return prom;};Client.prototype.sendMessage = function sendMessage(destination,message,tts){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var premessage=arguments.length <= 4 || arguments[4] === undefined?"":arguments[4];var self=this;var prom=new Promise(function(resolve,reject){if(typeof tts === "function"){ // tts is a function, which means the developer wants this to be the callback +callback = tts;tts = false;}message = premessage + resolveMessage(message);var mentions=resolveMentions();self.resolveDestination(destination).then(send)["catch"](error);function error(err){callback(err);reject(err);}function send(destination){if(self.options.queue){ //we're QUEUEING messages, so sending them sequentially based on servers. +if(!self.queue[destination]){self.queue[destination] = [];}self.queue[destination].push({action:"sendMessage",content:message,mentions:mentions,tts:!!tts, //incase it's not a boolean +then:mgood,error:mbad});self.checkQueue(destination);}else {self._sendMessage(destination,message,tts,mentions).then(mgood)["catch"](mbad);}}function mgood(msg){prom.message = msg;callback(null,msg);resolve(msg);}function mbad(error){prom.error = error;callback(error);reject(error);}function resolveMessage(){var msg=message;if(message instanceof Array){msg = message.join("\n");}return msg;}function resolveMentions(){var _mentions=[];for(var _iterator3=message.match(/<@[^>]*>/g) || [],_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[Symbol.iterator]();;) {var _ref3;if(_isArray3){if(_i3 >= _iterator3.length)break;_ref3 = _iterator3[_i3++];}else {_i3 = _iterator3.next();if(_i3.done)break;_ref3 = _i3.value;}var mention=_ref3;_mentions.push(mention.substring(2,mention.length - 1));}return _mentions;}});return prom;}; //def createws +Client.prototype.createws = function createws(url){if(this.websocket)return false;var self=this; //good to go +this.websocket = new WebSocket(url); //open +this.websocket.onopen = function(){self.trySendConnData(); //try connecting +}; //close +this.websocket.onclose = function(){self.trigger("disconnected");}; //message +this.websocket.onmessage = function(e){var dat=false,data={};try{dat = JSON.parse(e.data);data = dat.d;}catch(err) {self.trigger("error",err,e);return;}self.trigger("raw",dat); //valid message +switch(dat.t){case "READY":self.debug("received ready packet");self.user = self.addUser(data.user);for(var _iterator4=data.guilds,_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[Symbol.iterator]();;) {var _ref4;if(_isArray4){if(_i4 >= _iterator4.length)break;_ref4 = _iterator4[_i4++];}else {_i4 = _iterator4.next();if(_i4.done)break;_ref4 = _i4.value;}var _server=_ref4;var server=self.addServer(_server);}for(var _iterator5=data.private_channels,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var _pmc=_ref5;var pmc=self.addPMChannel(_pmc);}self.trigger("ready");self.readyTime = Date.now();self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users.");self.state = 3;setInterval(function(){self.keepAlive.apply(self);},data.heartbeat_interval);break;case "MESSAGE_CREATE":self.debug("received message");var mentions=[];data.mentions = data.mentions || []; //for some reason this was not defined at some point? +for(var _iterator6=data.mentions,_isArray6=Array.isArray(_iterator6),_i6=0,_iterator6=_isArray6?_iterator6:_iterator6[Symbol.iterator]();;) {var _ref6;if(_isArray6){if(_i6 >= _iterator6.length)break;_ref6 = _iterator6[_i6++];}else {_i6 = _iterator6.next();if(_i6.done)break;_ref6 = _i6.value;}var mention=_ref6;mentions.push(self.addUser(mention));}var channel=self.getChannel("id",data.channel_id);if(channel){var msg=channel.addMessage(new Message(data,channel,mentions,self.addUser(data.author)));self.trigger("message",msg);}break;case "MESSAGE_DELETE":self.debug("message deleted");var channel=self.getChannel("id",data.channel_id);var message=channel.getMessage("id",data.id);if(message){self.trigger("messageDelete",channel,message);channel.messages.splice(channel.messages.indexOf(message),1);}else { //don't have the cache of that message ;( +self.trigger("messageDelete",channel);}break;case "MESSAGE_UPDATE":self.debug("message updated");var channel=self.getChannel("id",data.channel_id);var formerMessage=channel.getMessage("id",data.id);if(formerMessage){ //new message might be partial, so we need to fill it with whatever the old message was. +var info={};for(var key in formerMessage) {info[key] = formerMessage[key];}for(var key in data) {info[key] = data[key];}var mentions=[];for(var _iterator7=info.mentions,_isArray7=Array.isArray(_iterator7),_i7=0,_iterator7=_isArray7?_iterator7:_iterator7[Symbol.iterator]();;) {var _ref7;if(_isArray7){if(_i7 >= _iterator7.length)break;_ref7 = _iterator7[_i7++];}else {_i7 = _iterator7.next();if(_i7.done)break;_ref7 = _i7.value;}var mention=_ref7;mentions.push(self.addUser(mention));}var newMessage=new Message(info,channel,mentions,formerMessage.author);self.trigger("messageUpdate",newMessage,formerMessage);channel.messages[channel.messages.indexOf(formerMessage)] = newMessage;} // message isn't in cache, and if it's a partial it could cause +// all hell to break loose... best to just act as if nothing happened +break;case "GUILD_DELETE":var server=self.getServer("id",data.id);if(server){self.serverCache.splice(self.serverCache.indexOf(server),1);self.trigger("serverDelete",server);}break;case "CHANNEL_DELETE":var channel=self.getChannel("id",data.id);if(channel){var server=channel.server;if(server){server.channels.splice(server.channels.indexOf(channel),1);}self.trigger("channelDelete",channel);self.serverCache.splice(self.serverCache.indexOf(channel),1);}break;case "GUILD_CREATE":var server=self.getServer("id",data.id);if(!server){ //if server doesn't already exist because duh +server = self.addServer(data);} /*else if(server.channels.length === 0){ + + var srv = new Server(data, self); + for(channel of data.channels){ + srv.channels.push(new Channel(channel, data.id)); + } + self.serverCache[self.serverCache.indexOf(server)] = srv; + + }*/if(self.serverCreateListener[data.id]){var cbs=self.serverCreateListener[data.id];cbs[0](server); //promise then callback +cbs[1](null,server); //legacy callback +self.serverCreateListener[data.id] = null;}self.trigger("serverCreate",server);break;case "CHANNEL_CREATE":var channel=self.getChannel("id",data.id);if(!channel){var chann;if(data.is_private){chann = self.addPMChannel(data);}else {chann = self.addChannel(data,data.guild_id);}var srv=self.getServer("id",data.guild_id);if(srv){srv.addChannel(chann);}self.trigger("channelCreate",chann);}break;case "GUILD_MEMBER_ADD":var server=self.getServer("id",data.guild_id);if(server){var user=self.addUser(data.user); //if for whatever reason it doesn't exist.. +self.trigger("serverNewMember",server.addMember(user,data.roles),server);}break;case "GUILD_MEMBER_REMOVE":var server=self.getServer("id",data.guild_id);if(server){var user=self.addUser(data.user); //if for whatever reason it doesn't exist.. +server.removeMember("id",user.id);self.trigger("serverRemoveMember",user,server);}break;case "USER_UPDATE":if(self.user && data.id === self.user.id){var newUser=new User(data); //not actually adding to the cache +self.trigger("userUpdate",newUser,self.user);if(~self.userCache.indexOf(self.user)){self.userCache[self.userCache.indexOf(self.user)] = newUser;}self.user = newUser;}break;case "PRESENCE_UPDATE":var userInCache=self.getUser("id",data.user.id);if(userInCache){ //user exists +data.user.username = data.user.username || userInCache.username;data.user.id = data.user.id || userInCache.id;data.user.discriminator = data.user.discriminator || userInCache.discriminator;data.user.avatar = data.user.avatar || userInCache.avatar;var presenceUser=new User(data.user);if(presenceUser.equalsStrict(userInCache)){ //they're exactly the same, an actual presence update +self.trigger("presence",{user:userInCache,oldStatus:userInCache.status,status:data.status,server:self.getServer("id",data.guild_id),gameId:data.game_id});userInCache.status = data.status;userInCache.gameId = data.game_id;}else { //one of their details changed. +self.userCache[self.userCache.indexOf(userInCache)] = presenceUser;self.trigger("userUpdate",userInCache,presenceUser);}}break;case "CHANNEL_UPDATE":var channelInCache=self.getChannel("id",data.id),serverInCache=self.getServer("id",data.guild_id);if(channelInCache && serverInCache){var newChann=new Channel(data,serverInCache);newChann.messages = channelInCache.messages;self.trigger("channelUpdate",channelInCache,newChann);self.channelCache[self.channelCache.indexOf(channelInCache)] = newChann;}break;case "TYPING_START":var userInCache=self.getUser("id",data.user_id);var channelInCache=self.getChannel("id",data.channel_id);if(!self.userTypingListener[data.user_id] || self.userTypingListener[data.user_id] === -1){self.trigger("startTyping",userInCache,channelInCache);}self.userTypingListener[data.user_id] = Date.now();setTimeout(function(){if(self.userTypingListener[data.user_id] === -1){return;}if(Date.now() - self.userTypingListener[data.user_id] > 6000){ // stopped typing +self.trigger("stopTyping",userInCache,channelInCache);self.userTypingListener[data.user_id] = -1;}},6000);break;case "GUILD_ROLE_DELETE":var server=self.getServer("id",data.guild_id);var role=server.getRole(data.role_id);self.trigger("serverRoleDelete",server,role);server.removeRole(role.id);break;case "GUILD_ROLE_UPDATE":var server=self.getServer("id",data.guild_id);var role=server.getRole(data.role.id);var newRole=server.updateRole(data.role);self.trigger("serverRoleUpdate",server,role,newRole);break;default:self.debug("received unknown packet");self.trigger("unknown",dat);break;}};}; //def addUser +Client.prototype.addUser = function addUser(data){if(!this.getUser("id",data.id)){this.userCache.push(new User(data));}return this.getUser("id",data.id);}; //def addChannel +Client.prototype.addChannel = function addChannel(data,serverId){if(!this.getChannel("id",data.id)){this.channelCache.push(new Channel(data,this.getServer("id",serverId)));}return this.getChannel("id",data.id);};Client.prototype.addPMChannel = function addPMChannel(data){if(!this.getPMChannel("id",data.id)){this.pmChannelCache.push(new PMChannel(data,this));}return this.getPMChannel("id",data.id);};Client.prototype.setTopic = function setTopic(channel,topic){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err){}:arguments[2];var self=this;return new Promise(function(resolve,reject){self.resolveDestination(channel).then(next)["catch"](error);function error(e){callback(e);reject(e);}function next(destination){var asChan=self.getChannel("id",destination);request.patch(Endpoints.CHANNELS + "/" + destination).set("authorization",self.token).send({name:asChan.name,position:0,topic:topic}).end(function(err,res){if(err){error(err);}else {asChan.topic = res.body.topic;resolve();callback();}});}});}; //def addServer +Client.prototype.addServer = function addServer(data){var self=this;var server=this.getServer("id",data.id);if(data.unavailable){self.trigger("unavailable",data);self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached.");return;}if(!server){server = new Server(data,this);this.serverCache.push(server);if(data.channels){for(var _iterator8=data.channels,_isArray8=Array.isArray(_iterator8),_i8=0,_iterator8=_isArray8?_iterator8:_iterator8[Symbol.iterator]();;) {var _ref8;if(_isArray8){if(_i8 >= _iterator8.length)break;_ref8 = _iterator8[_i8++];}else {_i8 = _iterator8.next();if(_i8.done)break;_ref8 = _i8.value;}var channel=_ref8;server.channels.push(this.addChannel(channel,server.id));}}}for(var _iterator9=data.presences,_isArray9=Array.isArray(_iterator9),_i9=0,_iterator9=_isArray9?_iterator9:_iterator9[Symbol.iterator]();;) {var _ref9;if(_isArray9){if(_i9 >= _iterator9.length)break;_ref9 = _iterator9[_i9++];}else {_i9 = _iterator9.next();if(_i9.done)break;_ref9 = _i9.value;}var presence=_ref9;var user=self.getUser("id",presence.user.id);user.status = presence.status;user.gameId = presence.game_id;}return server;}; //def getUser +Client.prototype.getUser = function getUser(key,value){for(var _iterator10=this.userCache,_isArray10=Array.isArray(_iterator10),_i10=0,_iterator10=_isArray10?_iterator10:_iterator10[Symbol.iterator]();;) {var _ref10;if(_isArray10){if(_i10 >= _iterator10.length)break;_ref10 = _iterator10[_i10++];}else {_i10 = _iterator10.next();if(_i10.done)break;_ref10 = _i10.value;}var user=_ref10;if(user[key] === value){return user;}}return null;}; //def getChannel +Client.prototype.getChannel = function getChannel(key,value){for(var _iterator11=this.channelCache,_isArray11=Array.isArray(_iterator11),_i11=0,_iterator11=_isArray11?_iterator11:_iterator11[Symbol.iterator]();;) {var _ref11;if(_isArray11){if(_i11 >= _iterator11.length)break;_ref11 = _iterator11[_i11++];}else {_i11 = _iterator11.next();if(_i11.done)break;_ref11 = _i11.value;}var channel=_ref11;if(channel[key] === value){return channel;}}return this.getPMChannel(key,value); //might be a PM +};Client.prototype.getPMChannel = function getPMChannel(key,value){for(var _iterator12=this.pmChannelCache,_isArray12=Array.isArray(_iterator12),_i12=0,_iterator12=_isArray12?_iterator12:_iterator12[Symbol.iterator]();;) {var _ref12;if(_isArray12){if(_i12 >= _iterator12.length)break;_ref12 = _iterator12[_i12++];}else {_i12 = _iterator12.next();if(_i12.done)break;_ref12 = _i12.value;}var channel=_ref12;if(channel[key] === value){return channel;}}return null;}; //def getServer +Client.prototype.getServer = function getServer(key,value){for(var _iterator13=this.serverCache,_isArray13=Array.isArray(_iterator13),_i13=0,_iterator13=_isArray13?_iterator13:_iterator13[Symbol.iterator]();;) {var _ref13;if(_isArray13){if(_i13 >= _iterator13.length)break;_ref13 = _iterator13[_i13++];}else {_i13 = _iterator13.next();if(_i13.done)break;_ref13 = _i13.value;}var server=_ref13;if(server[key] === value){return server;}}return null;}; //def trySendConnData +Client.prototype.trySendConnData = function trySendConnData(){if(this.token && !this.alreadySentData){this.alreadySentData = true;var data={op:2,d:{token:this.token,v:3,properties:{"$os":"discord.js","$browser":"discord.js","$device":"discord.js","$referrer":"","$referring_domain":""}}};this.websocket.send(JSON.stringify(data));}};Client.prototype.resolveServerID = function resolveServerID(resource){if(resource instanceof Server){return resource.id;}else if(!isNaN(resource) && resource.length && resource.length === 17){return resource;}};Client.prototype.resolveDestination = function resolveDestination(destination){var channId=false;var self=this;return new Promise(function(resolve,reject){if(destination instanceof Server){channId = destination.id; //general is the same as server id +}else if(destination instanceof Channel){channId = destination.id;}else if(destination instanceof Message){channId = destination.channel.id;}else if(destination instanceof PMChannel){channId = destination.id;}else if(destination instanceof User){ //check if we have a PM +for(var _iterator14=self.pmChannelCache,_isArray14=Array.isArray(_iterator14),_i14=0,_iterator14=_isArray14?_iterator14:_iterator14[Symbol.iterator]();;) {var _ref14;if(_isArray14){if(_i14 >= _iterator14.length)break;_ref14 = _iterator14[_i14++];}else {_i14 = _iterator14.next();if(_i14.done)break;_ref14 = _i14.value;}var pmc=_ref14;if(pmc.user && pmc.user.equals(destination)){resolve(pmc.id);return;}} //we don't, at this point we're late +self.startPM(destination).then(function(pmc){resolve(pmc.id);})["catch"](reject);}else {channId = destination;}if(channId)resolve(channId);else reject();});};Client.prototype._sendMessage = function _sendMessage(destination,content,tts,mentions){var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization",self.token).send({content:content,mentions:mentions,tts:tts}).end(function(err,res){if(err){reject(err);}else {var data=res.body;var mentions=[];data.mentions = data.mentions || []; //for some reason this was not defined at some point? +for(var _iterator15=data.mentions,_isArray15=Array.isArray(_iterator15),_i15=0,_iterator15=_isArray15?_iterator15:_iterator15[Symbol.iterator]();;) {var _ref15;if(_isArray15){if(_i15 >= _iterator15.length)break;_ref15 = _iterator15[_i15++];}else {_i15 = _iterator15.next();if(_i15.done)break;_ref15 = _i15.value;}var mention=_ref15;mentions.push(self.addUser(mention));}var channel=self.getChannel("id",data.channel_id);if(channel){var msg=channel.addMessage(new Message(data,channel,mentions,self.addUser(data.author)));resolve(msg);}}});});};Client.prototype._sendFile = function _sendFile(destination,attachment){var attachmentName=arguments.length <= 2 || arguments[2] === undefined?"DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png":arguments[2];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization",self.token).attach("file",attachment,attachmentName).end(function(err,res){if(err){reject(err);}else {var chann=self.getChannel("id",destination);if(chann){var msg=chann.addMessage(new Message(res.body,chann,[],self.user));resolve(msg);}}});});};Client.prototype._updateMessage = function _updateMessage(message,content){var self=this;return new Promise(function(resolve,reject){request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization",self.token).send({content:content,mentions:[]}).end(function(err,res){if(err){reject(err);}else {var msg=new Message(res.body,message.channel,message.mentions,message.sender);resolve(msg);message.channel.messages[message.channel.messages.indexOf(message)] = msg;}});});};Client.prototype.getGateway = function getGateway(){var self=this;return new Promise(function(resolve,reject){request.get(Endpoints.API + "/gateway").set("authorization",self.token).end(function(err,res){if(err){reject(err);}else {resolve(res.body.url);}});});};Client.prototype.setStatusIdle = function setStatusIdle(){this.setStatus("idle");};Client.prototype.setStatusOnline = function setStatusOnline(){this.setStatus("online");};Client.prototype.setStatusActive = function setStatusActive(){this.setStatusOnline();};Client.prototype.setStatusHere = function setStatusHere(){this.setStatusOnline();};Client.prototype.setStatusAway = function setStatusAway(){this.setStatusIdle();};Client.prototype.startTyping = function startTyping(chann,stopTypeTime){var self=this;this.resolveDestination(chann).then(next);function next(channel){if(self.typingIntervals[channel]){return;}var fn=function fn(){request.post(Endpoints.CHANNELS + "/" + channel + "/typing").set("authorization",self.token).end();};fn();var interval=setInterval(fn,3000);self.typingIntervals[channel] = interval;if(stopTypeTime){setTimeout(function(){self.stopTyping(channel);},stopTypeTime);}}};Client.prototype.stopTyping = function stopTyping(chann){var self=this;this.resolveDestination(chann).then(next);function next(channel){if(!self.typingIntervals[channel]){return;}clearInterval(self.typingIntervals[channel]);delete self.typingIntervals[channel];}};Client.prototype.setStatus = function setStatus(stat){var idleTime=stat === "online"?null:Date.now();this.__idleTime = idleTime;this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}));};Client.prototype.setPlayingGame = function setPlayingGame(id){if(id instanceof String || typeof id === "string"){ // working on names +var gid=id.trim().toUpperCase();id = null;for(var _iterator16=gameMap,_isArray16=Array.isArray(_iterator16),_i16=0,_iterator16=_isArray16?_iterator16:_iterator16[Symbol.iterator]();;) {var _ref16;if(_isArray16){if(_i16 >= _iterator16.length)break;_ref16 = _iterator16[_i16++];}else {_i16 = _iterator16.next();if(_i16.done)break;_ref16 = _i16.value;}var game=_ref16;if(game.name.trim().toUpperCase() === gid){id = game.id;break;}}}this.__gameId = id;this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}));};Client.prototype.playGame = function playGame(id){this.setPlayingGame(id);};Client.prototype.playingGame = function playingGame(id){this.setPlayingGame(id);};_createClass(Client,[{key:"uptime",get:function get(){return this.readyTime?Date.now() - this.readyTime:null;}},{key:"ready",get:function get(){return this.state === 3;}},{key:"servers",get:function get(){return this.serverCache;}},{key:"channels",get:function get(){return this.channelCache;}},{key:"users",get:function get(){return this.userCache;}},{key:"PMChannels",get:function get(){return this.pmChannelCache;}},{key:"messages",get:function get(){var msgs=[];for(var _iterator17=this.channelCache,_isArray17=Array.isArray(_iterator17),_i17=0,_iterator17=_isArray17?_iterator17:_iterator17[Symbol.iterator]();;) {var _ref17;if(_isArray17){if(_i17 >= _iterator17.length)break;_ref17 = _iterator17[_i17++];}else {_i17 = _iterator17.next();if(_i17.done)break;_ref17 = _i17.value;}var channel=_ref17;msgs = msgs.concat(channel.messages);}return msgs;}}]);return Client;})();module.exports = Client; + +},{"../ref/gameMap.json":19,"./Endpoints.js":3,"./PMChannel.js":6,"./channel.js":8,"./invite.js":10,"./message.js":11,"./server.js":12,"./user.js":13,"fs":14,"superagent":15,"ws":18}],3:[function(require,module,exports){ +"use strict";exports.BASE_DOMAIN = "discordapp.com";exports.BASE = "https://" + exports.BASE_DOMAIN;exports.WEBSOCKET_HUB = "wss://" + exports.BASE_DOMAIN + "/hub";exports.API = exports.BASE + "/api";exports.AUTH = exports.API + "/auth";exports.LOGIN = exports.AUTH + "/login";exports.LOGOUT = exports.AUTH + "/logout";exports.USERS = exports.API + "/users";exports.SERVERS = exports.API + "/guilds";exports.CHANNELS = exports.API + "/channels"; + +},{}],4:[function(require,module,exports){ +"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 EvaluatedPermissions=(function(){function EvaluatedPermissions(data){_classCallCheck(this,EvaluatedPermissions);var self=this;this.packed = data;if(this.getBit(3))this.packed = 4294967295;}EvaluatedPermissions.prototype.serialise = function serialise(){return {createInstantInvite:this.createInstantInvite,manageRoles:this.manageRoles,manageChannels:this.manageChannels,readMessages:this.readMessages,sendMessages:this.sendMessage,sendTTSMessages:this.sendTTSMessages,manageMessages:this.manageMessages,embedLinks:this.embedLinks,attachFiles:this.attachFiles,readMessageHistory:this.readMessageHistory,mentionEveryone:this.mentionEveryone,voiceConnect:this.voiceConnect,voiceSpeak:this.voiceSpeak,voiceMuteMembers:this.voiceMuteMembers,voiceDeafenMembers:this.voiceDeafenMembers,voiceMoveMember:this.voiceMoveMembers,voiceUseVoiceActivation:this.voiceUseVoiceActivation};};EvaluatedPermissions.prototype.getBit = function getBit(x){return (this.packed >>> x & 1) === 1;};EvaluatedPermissions.prototype.setBit = function setBit(){};_createClass(EvaluatedPermissions,[{key:"createInstantInvite",get:function get(){return this.getBit(0);},set:function set(val){this.setBit(0,val);}},{key:"manageRoles",get:function get(){return this.getBit(3);},set:function set(val){this.setBit(3,val);}},{key:"manageChannels",get:function get(){return this.getBit(4);},set:function set(val){this.setBit(4,val);}},{key:"readMessages",get:function get(){return this.getBit(10);},set:function set(val){this.setBit(10,val);}},{key:"sendMessages",get:function get(){return this.getBit(11);},set:function set(val){this.setBit(11,val);}},{key:"sendTTSMessages",get:function get(){return this.getBit(12);},set:function set(val){this.setBit(12,val);}},{key:"manageMessages",get:function get(){return this.getBit(13);},set:function set(val){this.setBit(13,val);}},{key:"embedLinks",get:function get(){return this.getBit(14);},set:function set(val){this.setBit(14,val);}},{key:"attachFiles",get:function get(){return this.getBit(15);},set:function set(val){this.setBit(15,val);}},{key:"readMessageHistory",get:function get(){return this.getBit(16);},set:function set(val){this.setBit(16,val);}},{key:"mentionEveryone",get:function get(){return this.getBit(17);},set:function set(val){this.setBit(17,val);}},{key:"voiceConnect",get:function get(){return this.getBit(20);},set:function set(val){this.setBit(20,val);}},{key:"voiceSpeak",get:function get(){return this.getBit(21);},set:function set(val){this.setBit(21,val);}},{key:"voiceMuteMembers",get:function get(){return this.getBit(22);},set:function set(val){this.setBit(22,val);}},{key:"voiceDeafenMembers",get:function get(){return this.getBit(23);},set:function set(val){this.setBit(23,val);}},{key:"voiceMoveMembers",get:function get(){return this.getBit(24);},set:function set(val){this.setBit(24,val);}},{key:"voiceUseVoiceActivation",get:function get(){return this.getBit(25);},set:function set(val){this.setBit(25,val);}}]);return EvaluatedPermissions;})();module.exports = EvaluatedPermissions; + +},{}],5:[function(require,module,exports){ +"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 User=require("./user.js");var ServerPermissions=require("./ServerPermissions.js");var EvaluatedPermissions=require("./EvaluatedPermissions.js");var Member=(function(_User){_inherits(Member,_User);function Member(user,server,roles){_classCallCheck(this,Member);_User.call(this,user); // should work, we are basically creating a Member that has the same properties as user and a few more +this.server = server;this.rawRoles = roles;}Member.prototype.permissionsIn = function permissionsIn(channel){if(channel.server.ownerID === this.id){return new EvaluatedPermissions(4294967295); //all perms +}var affectingOverwrites=[];var affectingMemberOverwrites=[];for(var _iterator=channel.roles,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var overwrite=_ref;if(overwrite.id === this.id && overwrite.type === "member"){affectingMemberOverwrites.push(overwrite);}else if(this.rawRoles.indexOf(overwrite.id) !== -1){affectingOverwrites.push(overwrite);}}if(affectingOverwrites.length === 0 && affectingMemberOverwrites.length === 0){return new EvaluatedPermissions(this.evalPerms.packed);}var finalPacked=affectingOverwrites.length !== 0?affectingOverwrites[0].packed:affectingMemberOverwrites[0].packed;for(var _iterator2=affectingOverwrites,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var overwrite=_ref2;finalPacked = finalPacked & ~overwrite.deny;finalPacked = finalPacked | overwrite.allow;}for(var _iterator3=affectingMemberOverwrites,_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[Symbol.iterator]();;) {var _ref3;if(_isArray3){if(_i3 >= _iterator3.length)break;_ref3 = _iterator3[_i3++];}else {_i3 = _iterator3.next();if(_i3.done)break;_ref3 = _i3.value;}var overwrite=_ref3;finalPacked = finalPacked & ~overwrite.deny;finalPacked = finalPacked | overwrite.allow;}return new EvaluatedPermissions(finalPacked);};_createClass(Member,[{key:"roles",get:function get(){var ufRoles=[this.server.getRole(this.server.id)];for(var _iterator4=this.rawRoles,_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[Symbol.iterator]();;) {var _ref4;if(_isArray4){if(_i4 >= _iterator4.length)break;_ref4 = _iterator4[_i4++];}else {_i4 = _iterator4.next();if(_i4.done)break;_ref4 = _i4.value;}var rawRole=_ref4;ufRoles.push(this.server.getRole(rawRole));}return ufRoles;}},{key:"evalPerms",get:function get(){var basePerms=this.roles, //cache roles as it can be slightly expensive +basePerm=basePerms[0].packed;for(var _iterator5=basePerms,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var perm=_ref5;basePerm = basePerm | perm.packed;}return new ServerPermissions({permissions:basePerm});}}]);return Member;})(User);module.exports = Member; + +},{"./EvaluatedPermissions.js":4,"./ServerPermissions.js":7,"./user.js":13}],6:[function(require,module,exports){ +"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 PMChannel=(function(){function PMChannel(data,client){_classCallCheck(this,PMChannel);this.user = client.getUser("id",data.recipient.id);this.id = data.id;this.messages = [];this.client = client;}PMChannel.prototype.addMessage = function addMessage(data){if(!this.getMessage("id",data.id)){this.messages.push(data);}return this.getMessage("id",data.id);};PMChannel.prototype.getMessage = function getMessage(key,value){if(this.messages.length > 1000){this.messages.splice(0,1);}for(var _iterator=this.messages,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var message=_ref;if(message[key] === value){return message;}}return null;};_createClass(PMChannel,[{key:"isPrivate",get:function get(){return true;}}]);return PMChannel;})();module.exports = PMChannel; + +},{}],7:[function(require,module,exports){ +"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 ServerPermissions=(function(){function ServerPermissions(data){_classCallCheck(this,ServerPermissions);var self=this;function getBit(x){return (self.packed >>> x & 1) === 1;}this.packed = data.permissions;this.name = data.name;this.id = data.id;}ServerPermissions.prototype.getBit = function getBit(x){return (this.packed >>> x & 1) === 1;};ServerPermissions.prototype.setBit = function setBit(){ //dummy function for now +};ServerPermissions.prototype.toString = function toString(){return this.name;};_createClass(ServerPermissions,[{key:"createInstantInvite",get:function get(){return this.getBit(0);},set:function set(val){this.setBit(0,val);}},{key:"banMembers",get:function get(){return this.getBit(1);},set:function set(val){this.setBit(1,val);}},{key:"kickMembers",get:function get(){return this.getBit(2);},set:function set(val){this.setBit(2,val);}},{key:"manageRoles",get:function get(){return this.getBit(3);},set:function set(val){this.setBit(3,val);}},{key:"manageChannels",get:function get(){return this.getBit(4);},set:function set(val){this.setBit(4,val);}},{key:"manageServer",get:function get(){return this.getBit(5);},set:function set(val){this.setBit(5,val);}},{key:"readMessages",get:function get(){return this.getBit(10);},set:function set(val){this.setBit(10,val);}},{key:"sendMessages",get:function get(){return this.getBit(11);},set:function set(val){this.setBit(11,val);}},{key:"sendTTSMessages",get:function get(){return this.getBit(12);},set:function set(val){this.setBit(12,val);}},{key:"manageMessages",get:function get(){return this.getBit(13);},set:function set(val){this.setBit(13,val);}},{key:"embedLinks",get:function get(){return this.getBit(14);},set:function set(val){this.setBit(14,val);}},{key:"attachFiles",get:function get(){return this.getBit(15);},set:function set(val){this.setBit(15,val);}},{key:"readMessageHistory",get:function get(){return this.getBit(16);},set:function set(val){this.setBit(16,val);}},{key:"mentionEveryone",get:function get(){return this.getBit(17);},set:function set(val){this.setBit(17,val);}},{key:"voiceConnect",get:function get(){return this.getBit(20);},set:function set(val){this.setBit(20,val);}},{key:"voiceSpeak",get:function get(){return this.getBit(21);},set:function set(val){this.setBit(21,val);}},{key:"voiceMuteMembers",get:function get(){return this.getBit(22);},set:function set(val){this.setBit(22,val);}},{key:"voiceDeafenMembers",get:function get(){return this.getBit(23);},set:function set(val){this.setBit(23,val);}},{key:"voiceMoveMembers",get:function get(){return this.getBit(24);},set:function set(val){this.setBit(24,val);}},{key:"voiceUseVoiceActivation",get:function get(){return this.getBit(25);},set:function set(val){this.setBit(25,val);}}]);return ServerPermissions;})();module.exports = ServerPermissions; + +},{}],8:[function(require,module,exports){ +"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var ChannelPermissions=require("./ChannelPermissions.js");var Channel=(function(){function Channel(data,server){_classCallCheck(this,Channel);this.server = server;this.name = data.name;this.type = data.type;this.topic = data.topic;this.id = data.id;this.messages = [];this.roles = [];if(data.permission_overwrites)for(var _iterator=data.permission_overwrites,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var role=_ref;this.roles.push(new ChannelPermissions(role,this));} //this.isPrivate = isPrivate; //not sure about the implementation of this... +}Channel.prototype.permissionsOf = function permissionsOf(member){var mem=this.server.getMember("id",member.id);if(mem){return mem.permissionsIn(this);}else {return null;}};Channel.prototype.equals = function equals(object){return object && object.id === this.id;};Channel.prototype.addMessage = function addMessage(data){if(this.messages.length > 1000){this.messages.splice(0,1);}if(!this.getMessage("id",data.id)){this.messages.push(data);}return this.getMessage("id",data.id);};Channel.prototype.getMessage = function getMessage(key,value){for(var _iterator2=this.messages,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var message=_ref2;if(message[key] === value){return message;}}return null;};Channel.prototype.toString = function toString(){return "<#" + this.id + ">";};_createClass(Channel,[{key:"permissionOverwrites",get:function get(){return this.roles;}},{key:"permissions",get:function get(){return this.roles;}},{key:"client",get:function get(){return this.server.client;}},{key:"isPrivate",get:function get(){return false;}},{key:"users",get:function get(){return this.server.members;}},{key:"members",get:function get(){return this.server.members;}}]);return Channel;})();module.exports = Channel; + +},{"./ChannelPermissions.js":1}],9:[function(require,module,exports){ +"use strict";var request=require("superagent");var Endpoints=require("./Endpoints.js");var Client=require("./Client.js");var Discord={Endpoints:Endpoints,Client:Client};module.exports = Discord; + +},{"./Client.js":2,"./Endpoints.js":3,"superagent":15}],10:[function(require,module,exports){ +"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 Invite=(function(){function Invite(data,client){_classCallCheck(this,Invite);this.max_age = data.max_age;this.code = data.code;this.server = client.getServer("id",data.guild.id);this.revoked = data.revoked;this.created_at = Date.parse(data.created_at);this.temporary = data.temporary;this.uses = data.uses;this.max_uses = data.uses;this.inviter = client.addUser(data.inviter);this.xkcd = data.xkcdpass;this.channel = client.getChannel("id",data.channel.id);}_createClass(Invite,[{key:"URL",get:function get(){var code=this.xkcd?this.xkcdpass:this.code;return "https://discord.gg/" + code;}}]);return Invite;})();module.exports = Invite; + +},{}],11:[function(require,module,exports){ +"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 PMChannel=require("./PMChannel.js");var Message=(function(){function Message(data,channel,mentions,author){_classCallCheck(this,Message);this.tts = data.tts;this.timestamp = Date.parse(data.timestamp);this.nonce = data.nonce;this.mentions = mentions;this.everyoneMentioned = data.mention_everyone;this.id = data.id;this.embeds = data.embeds;this.editedTimestamp = data.edited_timestamp;this.content = data.content.trim();this.channel = channel;if(this.isPrivate){this.author = this.channel.client.getUser("id",author.id);}else {this.author = this.channel.server.getMember("id",author.id) || this.channel.client.getUser("id",author.id);}this.attachments = data.attachments;} /*exports.Message.prototype.isPM = function() { + return ( this.channel instanceof PMChannel ); +}*/Message.prototype.isMentioned = function isMentioned(user){var id=user.id?user.id:user;for(var _iterator=this.mentions,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var mention=_ref;if(mention.id === id){return true;}}return false;};_createClass(Message,[{key:"sender",get:function get(){return this.author;}},{key:"isPrivate",get:function get(){return this.channel.isPrivate;}}]);return Message;})();module.exports = Message; + +},{"./PMChannel.js":6}],12:[function(require,module,exports){ +"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 ServerPermissions=require("./ServerPermissions.js");var Member=require("./Member.js");var Server=(function(){function Server(data,client){_classCallCheck(this,Server);this.client = client;this.region = data.region;this.ownerID = data.owner_id;this.name = data.name;this.id = data.id;this.members = [];this.channels = [];this.icon = data.icon;this.afkTimeout = data.afk_timeout;this.afkChannelId = data.afk_channel_id;this.roles = [];for(var _iterator=data.roles,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var permissionGroup=_ref;this.roles.push(new ServerPermissions(permissionGroup));}if(!data.members){data.members = [client.user];return;}for(var _iterator2=data.members,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var member=_ref2; // first we cache the user in our Discord Client, +// then we add it to our list. This way when we +// get a user from this server's member list, +// it will be identical (unless an async change occurred) +// to the client's cache. +if(member.user)this.addMember(client.addUser(member.user),member.roles);}} // get/set +Server.prototype.getRole = function getRole(id){for(var _iterator3=this.roles,_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[Symbol.iterator]();;) {var _ref3;if(_isArray3){if(_i3 >= _iterator3.length)break;_ref3 = _iterator3[_i3++];}else {_i3 = _iterator3.next();if(_i3.done)break;_ref3 = _i3.value;}var role=_ref3;if(role.id === id){return role;}}return null;};Server.prototype.updateRole = function updateRole(data){var oldRole=this.getRole(data.id);if(oldRole){var index=this.roles.indexOf(oldRole);this.roles[index] = new ServerPermissions(data);return this.roles[index];}else {return false;}};Server.prototype.removeRole = function removeRole(id){for(var roleId in this.roles) {if(this.roles[roleId].id === id){this.roles.splice(roleId,1);}}for(var _iterator4=this.members,_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[Symbol.iterator]();;) {var _ref4;if(_isArray4){if(_i4 >= _iterator4.length)break;_ref4 = _iterator4[_i4++];}else {_i4 = _iterator4.next();if(_i4.done)break;_ref4 = _i4.value;}var member=_ref4;for(var roleId in member.rawRoles) {if(member.rawRoles[roleId] === id){member.rawRoles.splice(roleId,1);}}}};Server.prototype.getChannel = function getChannel(key,value){for(var _iterator5=this.channels,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var channel=_ref5;if(channel[key] === value){return channel;}}return null;};Server.prototype.getMember = function getMember(key,value){for(var _iterator6=this.members,_isArray6=Array.isArray(_iterator6),_i6=0,_iterator6=_isArray6?_iterator6:_iterator6[Symbol.iterator]();;) {var _ref6;if(_isArray6){if(_i6 >= _iterator6.length)break;_ref6 = _iterator6[_i6++];}else {_i6 = _iterator6.next();if(_i6.done)break;_ref6 = _i6.value;}var member=_ref6;if(member[key] === value){return member;}}return null;};Server.prototype.removeMember = function removeMember(key,value){for(var _iterator7=this.members,_isArray7=Array.isArray(_iterator7),_i7=0,_iterator7=_isArray7?_iterator7:_iterator7[Symbol.iterator]();;) {var _ref7;if(_isArray7){if(_i7 >= _iterator7.length)break;_ref7 = _iterator7[_i7++];}else {_i7 = _iterator7.next();if(_i7.done)break;_ref7 = _i7.value;}var member=_ref7;if(member[key] === value){this.members.splice(key,1);return member;}}return false;};Server.prototype.addChannel = function addChannel(chann){if(!this.getChannel("id",chann.id)){this.channels.push(chann);}return chann;};Server.prototype.addMember = function addMember(user,roles){if(!this.getMember("id",user.id)){var mem=new Member(user,this,roles);this.members.push(mem);}return mem;};Server.prototype.toString = function toString(){return this.name;};Server.prototype.equals = function equals(object){return object.id === this.id;};_createClass(Server,[{key:"permissionGroups",get:function get(){return this.roles;}},{key:"permissions",get:function get(){return this.roles;}},{key:"iconURL",get:function get(){if(!this.icon)return null;return "https://discordapp.com/api/guilds/" + this.id + "/icons/" + this.icon + ".jpg";}},{key:"afkChannel",get:function get(){if(!this.afkChannelId)return false;return this.getChannel("id",this.afkChannelId);}},{key:"defaultChannel",get:function get(){return this.getChannel("name","general");}},{key:"owner",get:function get(){return this.client.getUser("id",this.ownerID);}},{key:"users",get:function get(){return this.members;}}]);return Server;})();module.exports = Server; + +},{"./Member.js":5,"./ServerPermissions.js":7}],13:[function(require,module,exports){ +"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 User=(function(){function User(data){_classCallCheck(this,User);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;} // access using user.avatarURL; +User.prototype.mention = function mention(){return "<@" + this.id + ">";};User.prototype.toString = function toString(){ /* + if we embed a user in a String - like so: + "Yo " + user + " what's up?" + It would generate something along the lines of: + "Yo @hydrabolt what's up?" + */return this.mention();};User.prototype.equals = function equals(object){return object.id === this.id;};User.prototype.equalsStrict = function equalsStrict(object){return object.id === this.id && object.avatar === this.avatar && object.username === this.username && object.discriminator === this.discriminator;};_createClass(User,[{key:"avatarURL",get:function get(){if(!this.avatar)return null;return "https://discordapp.com/api/users/" + this.id + "/avatars/" + this.avatar + ".jpg";}}]);return User;})();module.exports = User; + +},{}],14:[function(require,module,exports){ + +},{}],15:[function(require,module,exports){ +/** + * Module dependencies. + */ + +var Emitter = require('emitter'); +var reduce = require('reduce'); + +/** + * Root reference for iframes. + */ + +var root; +if (typeof window !== 'undefined') { // Browser window + root = window; +} else if (typeof self !== 'undefined') { // Web Worker + root = self; +} else { // Other environments + root = this; +} + +/** + * Noop. + */ + +function noop(){}; + +/** + * Check if `obj` is a host object, + * we don't want to serialize these :) + * + * TODO: future proof, move to compoent land + * + * @param {Object} obj + * @return {Boolean} + * @api private + */ + +function isHost(obj) { + var str = {}.toString.call(obj); + + switch (str) { + case '[object File]': + case '[object Blob]': + case '[object FormData]': + return true; + default: + return false; + } +} + +/** + * Determine XHR. + */ + +request.getXHR = function () { + if (root.XMLHttpRequest + && (!root.location || 'file:' != root.location.protocol + || !root.ActiveXObject)) { + return new XMLHttpRequest; + } else { + try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch(e) {} + try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {} + } + return false; +}; + +/** + * Removes leading and trailing whitespace, added to support IE. + * + * @param {String} s + * @return {String} + * @api private + */ + +var trim = ''.trim + ? function(s) { return s.trim(); } + : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); }; + +/** + * Check if `obj` is an object. + * + * @param {Object} obj + * @return {Boolean} + * @api private + */ + +function isObject(obj) { + return obj === Object(obj); +} + +/** + * Serialize the given `obj`. + * + * @param {Object} obj + * @return {String} + * @api private + */ + +function serialize(obj) { + if (!isObject(obj)) return obj; + var pairs = []; + for (var key in obj) { + if (null != obj[key]) { + pairs.push(encodeURIComponent(key) + + '=' + encodeURIComponent(obj[key])); + } + } + return pairs.join('&'); +} + +/** + * Expose serialization method. + */ + + request.serializeObject = serialize; + + /** + * Parse the given x-www-form-urlencoded `str`. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function parseString(str) { + var obj = {}; + var pairs = str.split('&'); + var parts; + var pair; + + for (var i = 0, len = pairs.length; i < len; ++i) { + pair = pairs[i]; + parts = pair.split('='); + obj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]); + } + + return obj; +} + +/** + * Expose parser. + */ + +request.parseString = parseString; + +/** + * Default MIME type map. + * + * superagent.types.xml = 'application/xml'; + * + */ + +request.types = { + html: 'text/html', + json: 'application/json', + xml: 'application/xml', + urlencoded: 'application/x-www-form-urlencoded', + 'form': 'application/x-www-form-urlencoded', + 'form-data': 'application/x-www-form-urlencoded' +}; + +/** + * Default serialization map. + * + * superagent.serialize['application/xml'] = function(obj){ + * return 'generated xml here'; + * }; + * + */ + + request.serialize = { + 'application/x-www-form-urlencoded': serialize, + 'application/json': JSON.stringify + }; + + /** + * Default parsers. + * + * superagent.parse['application/xml'] = function(str){ + * return { object parsed from str }; + * }; + * + */ + +request.parse = { + 'application/x-www-form-urlencoded': parseString, + 'application/json': JSON.parse +}; + +/** + * Parse the given header `str` into + * an object containing the mapped fields. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function parseHeader(str) { + var lines = str.split(/\r?\n/); + var fields = {}; + var index; + var line; + var field; + var val; + + lines.pop(); // trailing CRLF + + for (var i = 0, len = lines.length; i < len; ++i) { + line = lines[i]; + index = line.indexOf(':'); + field = line.slice(0, index).toLowerCase(); + val = trim(line.slice(index + 1)); + fields[field] = val; + } + + return fields; +} + +/** + * Return the mime type for the given `str`. + * + * @param {String} str + * @return {String} + * @api private + */ + +function type(str){ + return str.split(/ *; */).shift(); +}; + +/** + * Return header field parameters. + * + * @param {String} str + * @return {Object} + * @api private + */ + +function params(str){ + return reduce(str.split(/ *; */), function(obj, str){ + var parts = str.split(/ *= */) + , key = parts.shift() + , val = parts.shift(); + + if (key && val) obj[key] = val; + return obj; + }, {}); +}; + +/** + * Initialize a new `Response` with the given `xhr`. + * + * - set flags (.ok, .error, etc) + * - parse header + * + * Examples: + * + * Aliasing `superagent` as `request` is nice: + * + * request = superagent; + * + * We can use the promise-like API, or pass callbacks: + * + * request.get('/').end(function(res){}); + * request.get('/', function(res){}); + * + * Sending data can be chained: + * + * request + * .post('/user') + * .send({ name: 'tj' }) + * .end(function(res){}); + * + * Or passed to `.send()`: + * + * request + * .post('/user') + * .send({ name: 'tj' }, function(res){}); + * + * Or passed to `.post()`: + * + * request + * .post('/user', { name: 'tj' }) + * .end(function(res){}); + * + * Or further reduced to a single call for simple cases: + * + * request + * .post('/user', { name: 'tj' }, function(res){}); + * + * @param {XMLHTTPRequest} xhr + * @param {Object} options + * @api private + */ + +function Response(req, options) { + options = options || {}; + this.req = req; + this.xhr = this.req.xhr; + // responseText is accessible only if responseType is '' or 'text' and on older browsers + this.text = ((this.req.method !='HEAD' && (this.xhr.responseType === '' || this.xhr.responseType === 'text')) || typeof this.xhr.responseType === 'undefined') + ? this.xhr.responseText + : null; + this.statusText = this.req.xhr.statusText; + this.setStatusProperties(this.xhr.status); + this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders()); + // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but + // getResponseHeader still works. so we get content-type even if getting + // other headers fails. + this.header['content-type'] = this.xhr.getResponseHeader('content-type'); + this.setHeaderProperties(this.header); + this.body = this.req.method != 'HEAD' + ? this.parseBody(this.text ? this.text : this.xhr.response) + : null; +} + +/** + * Get case-insensitive `field` value. + * + * @param {String} field + * @return {String} + * @api public + */ + +Response.prototype.get = function(field){ + return this.header[field.toLowerCase()]; +}; + +/** + * Set header related properties: + * + * - `.type` the content type without params + * + * A response of "Content-Type: text/plain; charset=utf-8" + * will provide you with a `.type` of "text/plain". + * + * @param {Object} header + * @api private + */ + +Response.prototype.setHeaderProperties = function(header){ + // content-type + var ct = this.header['content-type'] || ''; + this.type = type(ct); + + // params + var obj = params(ct); + for (var key in obj) this[key] = obj[key]; +}; + +/** + * Force given parser + * + * Sets the body parser no matter type. + * + * @param {Function} + * @api public + */ + +Response.prototype.parse = function(fn){ + this.parser = fn; + return this; +}; + +/** + * Parse the given body `str`. + * + * Used for auto-parsing of bodies. Parsers + * are defined on the `superagent.parse` object. + * + * @param {String} str + * @return {Mixed} + * @api private + */ + +Response.prototype.parseBody = function(str){ + var parse = this.parser || request.parse[this.type]; + return parse && str && (str.length || str instanceof Object) + ? parse(str) + : null; +}; + +/** + * Set flags such as `.ok` based on `status`. + * + * For example a 2xx response will give you a `.ok` of __true__ + * whereas 5xx will be __false__ and `.error` will be __true__. The + * `.clientError` and `.serverError` are also available to be more + * specific, and `.statusType` is the class of error ranging from 1..5 + * sometimes useful for mapping respond colors etc. + * + * "sugar" properties are also defined for common cases. Currently providing: + * + * - .noContent + * - .badRequest + * - .unauthorized + * - .notAcceptable + * - .notFound + * + * @param {Number} status + * @api private + */ + +Response.prototype.setStatusProperties = function(status){ + // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request + if (status === 1223) { + status = 204; + } + + var type = status / 100 | 0; + + // status / class + this.status = this.statusCode = status; + this.statusType = type; + + // basics + this.info = 1 == type; + this.ok = 2 == type; + this.clientError = 4 == type; + this.serverError = 5 == type; + this.error = (4 == type || 5 == type) + ? this.toError() + : false; + + // sugar + this.accepted = 202 == status; + this.noContent = 204 == status; + this.badRequest = 400 == status; + this.unauthorized = 401 == status; + this.notAcceptable = 406 == status; + this.notFound = 404 == status; + this.forbidden = 403 == status; +}; + +/** + * Return an `Error` representative of this response. + * + * @return {Error} + * @api public + */ + +Response.prototype.toError = function(){ + var req = this.req; + var method = req.method; + var url = req.url; + + var msg = 'cannot ' + method + ' ' + url + ' (' + this.status + ')'; + var err = new Error(msg); + err.status = this.status; + err.method = method; + err.url = url; + + return err; +}; + +/** + * Expose `Response`. + */ + +request.Response = Response; + +/** + * Initialize a new `Request` with the given `method` and `url`. + * + * @param {String} method + * @param {String} url + * @api public + */ + +function Request(method, url) { + var self = this; + Emitter.call(this); + this._query = this._query || []; + this.method = method; + this.url = url; + this.header = {}; + this._header = {}; + this.on('end', function(){ + var err = null; + var res = null; + + try { + res = new Response(self); + } catch(e) { + err = new Error('Parser is unable to parse the response'); + err.parse = true; + err.original = e; + return self.callback(err); + } + + self.emit('response', res); + + if (err) { + return self.callback(err, res); + } + + if (res.status >= 200 && res.status < 300) { + return self.callback(err, res); + } + + var new_err = new Error(res.statusText || 'Unsuccessful HTTP response'); + new_err.original = err; + new_err.response = res; + new_err.status = res.status; + + self.callback(new_err, res); + }); +} + +/** + * Mixin `Emitter`. + */ + +Emitter(Request.prototype); + +/** + * Allow for extension + */ + +Request.prototype.use = function(fn) { + fn(this); + return this; +} + +/** + * Set timeout to `ms`. + * + * @param {Number} ms + * @return {Request} for chaining + * @api public + */ + +Request.prototype.timeout = function(ms){ + this._timeout = ms; + return this; +}; + +/** + * Clear previous timeout. + * + * @return {Request} for chaining + * @api public + */ + +Request.prototype.clearTimeout = function(){ + this._timeout = 0; + clearTimeout(this._timer); + return this; +}; + +/** + * Abort the request, and clear potential timeout. + * + * @return {Request} + * @api public + */ + +Request.prototype.abort = function(){ + if (this.aborted) return; + this.aborted = true; + this.xhr.abort(); + this.clearTimeout(); + this.emit('abort'); + return this; +}; + +/** + * Set header `field` to `val`, or multiple fields with one object. + * + * Examples: + * + * req.get('/') + * .set('Accept', 'application/json') + * .set('X-API-Key', 'foobar') + * .end(callback); + * + * req.get('/') + * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' }) + * .end(callback); + * + * @param {String|Object} field + * @param {String} val + * @return {Request} for chaining + * @api public + */ + +Request.prototype.set = function(field, val){ + if (isObject(field)) { + for (var key in field) { + this.set(key, field[key]); + } + return this; + } + this._header[field.toLowerCase()] = val; + this.header[field] = val; + return this; +}; + +/** + * Remove header `field`. + * + * Example: + * + * req.get('/') + * .unset('User-Agent') + * .end(callback); + * + * @param {String} field + * @return {Request} for chaining + * @api public + */ + +Request.prototype.unset = function(field){ + delete this._header[field.toLowerCase()]; + delete this.header[field]; + return this; +}; + +/** + * Get case-insensitive header `field` value. + * + * @param {String} field + * @return {String} + * @api private + */ + +Request.prototype.getHeader = function(field){ + return this._header[field.toLowerCase()]; +}; + +/** + * Set Content-Type to `type`, mapping values from `request.types`. + * + * Examples: + * + * superagent.types.xml = 'application/xml'; + * + * request.post('/') + * .type('xml') + * .send(xmlstring) + * .end(callback); + * + * request.post('/') + * .type('application/xml') + * .send(xmlstring) + * .end(callback); + * + * @param {String} type + * @return {Request} for chaining + * @api public + */ + +Request.prototype.type = function(type){ + this.set('Content-Type', request.types[type] || type); + return this; +}; + +/** + * Set Accept to `type`, mapping values from `request.types`. + * + * Examples: + * + * superagent.types.json = 'application/json'; + * + * request.get('/agent') + * .accept('json') + * .end(callback); + * + * request.get('/agent') + * .accept('application/json') + * .end(callback); + * + * @param {String} accept + * @return {Request} for chaining + * @api public + */ + +Request.prototype.accept = function(type){ + this.set('Accept', request.types[type] || type); + return this; +}; + +/** + * Set Authorization field value with `user` and `pass`. + * + * @param {String} user + * @param {String} pass + * @return {Request} for chaining + * @api public + */ + +Request.prototype.auth = function(user, pass){ + var str = btoa(user + ':' + pass); + this.set('Authorization', 'Basic ' + str); + return this; +}; + +/** +* Add query-string `val`. +* +* Examples: +* +* request.get('/shoes') +* .query('size=10') +* .query({ color: 'blue' }) +* +* @param {Object|String} val +* @return {Request} for chaining +* @api public +*/ + +Request.prototype.query = function(val){ + if ('string' != typeof val) val = serialize(val); + if (val) this._query.push(val); + return this; +}; + +/** + * Write the field `name` and `val` for "multipart/form-data" + * request bodies. + * + * ``` js + * request.post('/upload') + * .field('foo', 'bar') + * .end(callback); + * ``` + * + * @param {String} name + * @param {String|Blob|File} val + * @return {Request} for chaining + * @api public + */ + +Request.prototype.field = function(name, val){ + if (!this._formData) this._formData = new root.FormData(); + this._formData.append(name, val); + return this; +}; + +/** + * Queue the given `file` as an attachment to the specified `field`, + * with optional `filename`. + * + * ``` js + * request.post('/upload') + * .attach(new Blob(['hey!'], { type: "text/html"})) + * .end(callback); + * ``` + * + * @param {String} field + * @param {Blob|File} file + * @param {String} filename + * @return {Request} for chaining + * @api public + */ + +Request.prototype.attach = function(field, file, filename){ + if (!this._formData) this._formData = new root.FormData(); + this._formData.append(field, file, filename); + return this; +}; + +/** + * Send `data`, defaulting the `.type()` to "json" when + * an object is given. + * + * Examples: + * + * // querystring + * request.get('/search') + * .end(callback) + * + * // multiple data "writes" + * request.get('/search') + * .send({ search: 'query' }) + * .send({ range: '1..5' }) + * .send({ order: 'desc' }) + * .end(callback) + * + * // manual json + * request.post('/user') + * .type('json') + * .send('{"name":"tj"}) + * .end(callback) + * + * // auto json + * request.post('/user') + * .send({ name: 'tj' }) + * .end(callback) + * + * // manual x-www-form-urlencoded + * request.post('/user') + * .type('form') + * .send('name=tj') + * .end(callback) + * + * // auto x-www-form-urlencoded + * request.post('/user') + * .type('form') + * .send({ name: 'tj' }) + * .end(callback) + * + * // defaults to x-www-form-urlencoded + * request.post('/user') + * .send('name=tobi') + * .send('species=ferret') + * .end(callback) + * + * @param {String|Object} data + * @return {Request} for chaining + * @api public + */ + +Request.prototype.send = function(data){ + var obj = isObject(data); + var type = this.getHeader('Content-Type'); + + // merge + if (obj && isObject(this._data)) { + for (var key in data) { + this._data[key] = data[key]; + } + } else if ('string' == typeof data) { + if (!type) this.type('form'); + type = this.getHeader('Content-Type'); + if ('application/x-www-form-urlencoded' == type) { + this._data = this._data + ? this._data + '&' + data + : data; + } else { + this._data = (this._data || '') + data; + } + } else { + this._data = data; + } + + if (!obj || isHost(data)) return this; + if (!type) this.type('json'); + return this; +}; + +/** + * Invoke the callback with `err` and `res` + * and handle arity check. + * + * @param {Error} err + * @param {Response} res + * @api private + */ + +Request.prototype.callback = function(err, res){ + var fn = this._callback; + this.clearTimeout(); + fn(err, res); +}; + +/** + * Invoke callback with x-domain error. + * + * @api private + */ + +Request.prototype.crossDomainError = function(){ + var err = new Error('Origin is not allowed by Access-Control-Allow-Origin'); + err.crossDomain = true; + this.callback(err); +}; + +/** + * Invoke callback with timeout error. + * + * @api private + */ + +Request.prototype.timeoutError = function(){ + var timeout = this._timeout; + var err = new Error('timeout of ' + timeout + 'ms exceeded'); + err.timeout = timeout; + this.callback(err); +}; + +/** + * Enable transmission of cookies with x-domain requests. + * + * Note that for this to work the origin must not be + * using "Access-Control-Allow-Origin" with a wildcard, + * and also must set "Access-Control-Allow-Credentials" + * to "true". + * + * @api public + */ + +Request.prototype.withCredentials = function(){ + this._withCredentials = true; + return this; +}; + +/** + * Initiate request, invoking callback `fn(res)` + * with an instanceof `Response`. + * + * @param {Function} fn + * @return {Request} for chaining + * @api public + */ + +Request.prototype.end = function(fn){ + var self = this; + var xhr = this.xhr = request.getXHR(); + var query = this._query.join('&'); + var timeout = this._timeout; + var data = this._formData || this._data; + + // store callback + this._callback = fn || noop; + + // state change + xhr.onreadystatechange = function(){ + if (4 != xhr.readyState) return; + + // In IE9, reads to any property (e.g. status) off of an aborted XHR will + // result in the error "Could not complete the operation due to error c00c023f" + var status; + try { status = xhr.status } catch(e) { status = 0; } + + if (0 == status) { + if (self.timedout) return self.timeoutError(); + if (self.aborted) return; + return self.crossDomainError(); + } + self.emit('end'); + }; + + // progress + var handleProgress = function(e){ + if (e.total > 0) { + e.percent = e.loaded / e.total * 100; + } + self.emit('progress', e); + }; + if (this.hasListeners('progress')) { + xhr.onprogress = handleProgress; + } + try { + if (xhr.upload && this.hasListeners('progress')) { + xhr.upload.onprogress = handleProgress; + } + } catch(e) { + // Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist. + // Reported here: + // https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context + } + + // timeout + if (timeout && !this._timer) { + this._timer = setTimeout(function(){ + self.timedout = true; + self.abort(); + }, timeout); + } + + // querystring + if (query) { + query = request.serializeObject(query); + this.url += ~this.url.indexOf('?') + ? '&' + query + : '?' + query; + } + + // initiate request + xhr.open(this.method, this.url, true); + + // CORS + if (this._withCredentials) xhr.withCredentials = true; + + // body + if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) { + // serialize stuff + var contentType = this.getHeader('Content-Type'); + var serialize = request.serialize[contentType ? contentType.split(';')[0] : '']; + if (serialize) data = serialize(data); + } + + // set header fields + for (var field in this.header) { + if (null == this.header[field]) continue; + xhr.setRequestHeader(field, this.header[field]); + } + + // send stuff + this.emit('request', this); + xhr.send(data); + return this; +}; + +/** + * Faux promise support + * + * @param {Function} fulfill + * @param {Function} reject + * @return {Request} + */ + +Request.prototype.then = function (fulfill, reject) { + return this.end(function(err, res) { + err ? reject(err) : fulfill(res); + }); +} + +/** + * Expose `Request`. + */ + +request.Request = Request; + +/** + * Issue a request: + * + * Examples: + * + * request('GET', '/users').end(callback) + * request('/users').end(callback) + * request('/users', callback) + * + * @param {String} method + * @param {String|Function} url or callback + * @return {Request} + * @api public + */ + +function request(method, url) { + // callback + if ('function' == typeof url) { + return new Request('GET', method).end(url); + } + + // url first + if (1 == arguments.length) { + return new Request('GET', method); + } + + return new Request(method, url); +} + +/** + * GET `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.get = function(url, data, fn){ + var req = request('GET', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.query(data); + if (fn) req.end(fn); + return req; +}; + +/** + * HEAD `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.head = function(url, data, fn){ + var req = request('HEAD', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * DELETE `url` with optional callback `fn(res)`. + * + * @param {String} url + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.del = function(url, fn){ + var req = request('DELETE', url); + if (fn) req.end(fn); + return req; +}; + +/** + * PATCH `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed} data + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.patch = function(url, data, fn){ + var req = request('PATCH', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * POST `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed} data + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.post = function(url, data, fn){ + var req = request('POST', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * PUT `url` with optional `data` and callback `fn(res)`. + * + * @param {String} url + * @param {Mixed|Function} data or fn + * @param {Function} fn + * @return {Request} + * @api public + */ + +request.put = function(url, data, fn){ + var req = request('PUT', url); + if ('function' == typeof data) fn = data, data = null; + if (data) req.send(data); + if (fn) req.end(fn); + return req; +}; + +/** + * Expose `request`. + */ + +module.exports = request; + +},{"emitter":16,"reduce":17}],16:[function(require,module,exports){ + +/** + * Expose `Emitter`. + */ + +module.exports = Emitter; + +/** + * Initialize a new `Emitter`. + * + * @api public + */ + +function Emitter(obj) { + if (obj) return mixin(obj); +}; + +/** + * Mixin the emitter properties. + * + * @param {Object} obj + * @return {Object} + * @api private + */ + +function mixin(obj) { + for (var key in Emitter.prototype) { + obj[key] = Emitter.prototype[key]; + } + return obj; +} + +/** + * Listen on the given `event` with `fn`. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.on = +Emitter.prototype.addEventListener = function(event, fn){ + this._callbacks = this._callbacks || {}; + (this._callbacks[event] = this._callbacks[event] || []) + .push(fn); + return this; +}; + +/** + * Adds an `event` listener that will be invoked a single + * time then automatically removed. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.once = function(event, fn){ + var self = this; + this._callbacks = this._callbacks || {}; + + function on() { + self.off(event, on); + fn.apply(this, arguments); + } + + on.fn = fn; + this.on(event, on); + return this; +}; + +/** + * Remove the given callback for `event` or all + * registered callbacks. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + +Emitter.prototype.off = +Emitter.prototype.removeListener = +Emitter.prototype.removeAllListeners = +Emitter.prototype.removeEventListener = function(event, fn){ + this._callbacks = this._callbacks || {}; + + // all + if (0 == arguments.length) { + this._callbacks = {}; + return this; + } + + // specific event + var callbacks = this._callbacks[event]; + if (!callbacks) return this; + + // remove all handlers + if (1 == arguments.length) { + delete this._callbacks[event]; + return this; + } + + // remove specific handler + var cb; + for (var i = 0; i < callbacks.length; i++) { + cb = callbacks[i]; + if (cb === fn || cb.fn === fn) { + callbacks.splice(i, 1); + break; + } + } + return this; +}; + +/** + * Emit `event` with the given args. + * + * @param {String} event + * @param {Mixed} ... + * @return {Emitter} + */ + +Emitter.prototype.emit = function(event){ + this._callbacks = this._callbacks || {}; + var args = [].slice.call(arguments, 1) + , callbacks = this._callbacks[event]; + + if (callbacks) { + callbacks = callbacks.slice(0); + for (var i = 0, len = callbacks.length; i < len; ++i) { + callbacks[i].apply(this, args); + } + } + + return this; +}; + +/** + * Return array of callbacks for `event`. + * + * @param {String} event + * @return {Array} + * @api public + */ + +Emitter.prototype.listeners = function(event){ + this._callbacks = this._callbacks || {}; + return this._callbacks[event] || []; +}; + +/** + * Check if this emitter has `event` handlers. + * + * @param {String} event + * @return {Boolean} + * @api public + */ + +Emitter.prototype.hasListeners = function(event){ + return !! this.listeners(event).length; +}; + +},{}],17:[function(require,module,exports){ + +/** + * Reduce `arr` with `fn`. + * + * @param {Array} arr + * @param {Function} fn + * @param {Mixed} initial + * + * TODO: combatible error handling? + */ + +module.exports = function(arr, fn, initial){ + var idx = 0; + var len = arr.length; + var curr = arguments.length == 3 + ? initial + : arr[idx++]; + + while (idx < len) { + curr = fn.call(null, curr, arr[idx], ++idx, arr); + } + + return curr; +}; +},{}],18:[function(require,module,exports){ + +/** + * Module dependencies. + */ + +var global = (function() { return this; })(); + +/** + * WebSocket constructor. + */ + +var WebSocket = global.WebSocket || global.MozWebSocket; + +/** + * Module exports. + */ + +module.exports = WebSocket ? ws : null; + +/** + * WebSocket constructor. + * + * The third `opts` options object gets ignored in web browsers, since it's + * non-standard, and throws a TypeError if passed to the constructor. + * See: https://github.com/einaros/ws/issues/227 + * + * @param {String} uri + * @param {Array} protocols (optional) + * @param {Object) opts (optional) + * @api public + */ + +function ws(uri, protocols, opts) { + var instance; + if (protocols) { + instance = new WebSocket(uri, protocols); + } else { + instance = new WebSocket(uri); + } + return instance; +} + +if (WebSocket) ws.prototype = WebSocket.prototype; + +},{}],19:[function(require,module,exports){ +module.exports=[{"executables":{"win32":["pol.exe"]},"id":0,"name":"FINAL FANTASY XI"},{"executables":{"win32":["ffxiv.exe","ffxiv_dx11.exe"]},"id":1,"name":"FINAL FANTASY XIV"},{"executables":{"win32":["Wow.exe","Wow-64.exe"]},"id":3,"name":"World of Warcraft"},{"executables":{"darwin":["LoLLauncher.app"],"win32":["LolClient.exe","League of Legends.exe"]},"id":4,"name":"League of Legends"},{"executables":{"darwin":["Diablo%20III.app"],"win32":["Diablo III.exe"]},"id":5,"name":"Diablo 3"},{"executables":{"darwin":["dota_osx.app"],"win32":["dota2.exe"]},"id":6,"name":"DOTA 2"},{"executables":{"darwin":["Heroes.app"],"win32":["Heroes of the Storm.exe","HeroesOfTheStorm_x64.exe","HeroesOfTheStorm.exe"]},"id":7,"name":"Heroes of the Storm"},{"executables":{"darwin":["Hearthstone.app"],"win32":["Hearthstone.exe"]},"id":8,"name":"Hearthstone"},{"executables":{"win32":["csgo.exe"]},"id":9,"name":"Counter-Strike: Global Offensive"},{"executables":{"win32":["WorldOfTanks.exe"]},"id":10,"name":"World of Tanks"},{"executables":{"darwin":["gw2.app"],"win32":["gw2.exe"]},"id":11,"name":"Guild Wars 2"},{"executables":{"win32":["dayz.exe"]},"id":12,"name":"Day Z"},{"executables":{"darwin":["starcraft%20ii.app"],"win32":["starcraft ii.exe","SC2_x64.exe","SC2.exe"]},"id":13,"name":"Starcraft II"},{"executables":{"win32":["diablo.exe"]},"id":14,"name":"Diablo"},{"executables":{"win32":["diablo ii.exe"]},"id":15,"name":"Diablo 2"},{"executables":{"win32":["left4dead.exe"]},"id":17,"name":"Left 4 Dead"},{"executables":{"darwin":["minecraft.app"],"win32":["minecraft.exe"]},"id":18,"name":"Minecraft"},{"executables":{"win32":["smite.exe"]},"id":19,"name":"Smite"},{"executables":{"win32":["bf4.exe"]},"id":20,"name":"Battlefield 4"},{"executables":{"win32":["AoK HD.exe","empires2.exe"]},"id":101,"name":"Age of Empire II"},{"executables":{"win32":["age3y.exe"]},"id":102,"name":"Age of Empire III"},{"executables":{"win32":["AlanWake.exe"]},"id":104,"name":"Alan Wake"},{"executables":{"win32":["alan_wakes_american_nightmare.exe"]},"id":105,"name":"Alan Wake's American Nightmare"},{"executables":{"win32":["AlienBreed2Assault.exe"]},"id":106,"name":"Alien Breed 2: Assault"},{"executables":{"win32":["Amnesia.exe"]},"id":107,"name":"Amnesia: The Dark Descent"},{"executables":{"win32":["UDK.exe"]},"id":108,"name":"Antichamber"},{"executables":{"win32":["ArcheAge.exe"]},"id":109,"name":"ArcheAge"},{"executables":{"win32":["arma3.exe"]},"id":110,"name":"Arma III"},{"executables":{"win32":["AC3SP.exe"]},"id":111,"name":"Assassin's Creed 3"},{"executables":{"win32":["Bastion.exe"]},"id":112,"name":"Bastion"},{"executables":{"win32":["BF2.exe"]},"id":113,"name":"Battlefield 2"},{"executables":{"win32":["bf3.exe"]},"id":114,"name":"Battlefield 3"},{"executables":{"win32":["Besiege.exe"]},"id":116,"name":"Besiege"},{"executables":{"win32":["Bioshock.exe"]},"id":117,"name":"Bioshock"},{"executables":{"win32":["Bioshock2.exe"]},"id":118,"name":"BioShock II"},{"executables":{"win32":["BioShockInfinite.exe"]},"id":119,"name":"BioShock Infinite"},{"executables":{"win32":["Borderlands2.exe"]},"id":122,"name":"Borderlands 2"},{"executables":{"win32":["braid.exe"]},"id":123,"name":"Braid"},{"executables":{"win32":["ShippingPC-StormGame.exe"]},"id":124,"name":"Bulletstorm"},{"executables":{},"id":125,"name":"Cabal 2"},{"executables":{"win32":["CabalMain.exe"]},"id":126,"name":"Cabal Online"},{"executables":{"win32":["iw4mp.exe","iw4sp.exe"]},"id":127,"name":"Call of Duty: Modern Warfare 2"},{"executables":{"win32":["t6sp.exe"]},"id":128,"name":"Call of Duty: Black Ops"},{"executables":{"win32":["iw5mp.exe"]},"id":129,"name":"Call of Duty: Modern Warfare 3"},{"executables":{"win32":["RelicCOH.exe"]},"id":132,"name":"Company of Heroes"},{"executables":{"win32":["Crysis64.exe"]},"id":135,"name":"Crysis"},{"executables":{"win32":["Crysis2.exe"]},"id":136,"name":"Crysis 2"},{"executables":{"win32":["Crysis3.exe"]},"id":137,"name":"Crysis 3"},{"executables":{"win32":["Crysis.exe"]},"id":138,"name":"Crysis 4 "},{"executables":{"win32":["DATA.exe"]},"id":140,"name":"Dark Souls"},{"executables":{"win32":["DarkSoulsII.exe"]},"id":141,"name":"Dark Souls II"},{"executables":{"win32":["dfuw.exe"]},"id":142,"name":"Darkfall: Unholy Wars"},{"executables":{"win32":["DCGAME.exe"]},"id":144,"name":"DC Universe Online"},{"executables":{"win32":["DeadIslandGame.exe"]},"id":145,"name":"Dead Island"},{"executables":{"win32":["deadspace2.exe"]},"id":146,"name":"Dead Space 2"},{"executables":{"win32":["LOTDGame.exe"]},"id":147,"name":"Deadlight"},{"executables":{"win32":["dxhr.exe"]},"id":148,"name":"Deus Ex: Human Revolution"},{"executables":{"win32":["DeviMayCry4.exe"]},"id":149,"name":"Devil May Cry 4"},{"executables":{"win32":["DMC-DevilMayCry.exe"]},"id":150,"name":"DmC Devil May Cry"},{"executables":{"win32":["dirt2_game.exe"]},"id":154,"name":"DiRT 2"},{"executables":{"win32":["dirt3_game.exe"]},"id":155,"name":"DiRT 3"},{"executables":{"win32":["dota.exe"]},"id":156,"name":"DOTA"},{"executables":{"win32":["DoubleDragon.exe"]},"id":158,"name":"Double Dragon Neon"},{"executables":{"win32":["DragonAge2.exe"]},"id":159,"name":"Dragon Age II"},{"executables":{"win32":["DragonAgeInquisition.exe"]},"id":160,"name":"Dragon Age: Inquisition"},{"executables":{"win32":["daorigins.exe"]},"id":161,"name":"Dragon Age: Origins"},{"executables":{"win32":["DBXV.exe"]},"id":162,"name":"Dragon Ball XenoVerse"},{"executables":{"win32":["DukeForever.exe"]},"id":163,"name":"Duke Nukem Forever"},{"executables":{"darwin":["Dustforce.app"],"win32":["dustforce.exe"]},"id":164,"name":"Dustforce"},{"executables":{"win32":["EliteDangerous32.exe"]},"id":165,"name":"Elite: Dangerous"},{"executables":{"win32":["exefile.exe"]},"id":166,"name":"Eve Online"},{"executables":{"win32":["eqgame.exe"]},"id":167,"name":"EverQuest"},{"executables":{"win32":["EverQuest2.exe"]},"id":168,"name":"EverQuest II"},{"executables":{},"id":169,"name":"EverQuest Next"},{"executables":{"win32":["Engine.exe"]},"id":170,"name":"F.E.A.R."},{"executables":{"win32":["FEAR2.exe"]},"id":171,"name":"F.E.A.R. 2: Project Origin"},{"executables":{"win32":["fallout3.exe"]},"id":172,"name":"Fallout 3"},{"executables":{"win32":["FalloutNV.exe"]},"id":174,"name":"Fallout: New Vegas"},{"executables":{"win32":["farcry3.exe"]},"id":175,"name":"Far Cry 3"},{"executables":{"win32":["fifa15.exe"]},"id":176,"name":"FIFA 15"},{"executables":{"win32":["FTLGame.exe"]},"id":180,"name":"FTL: Faster Than Light"},{"executables":{"win32":["GTAIV.exe"]},"id":181,"name":"Grand Theft Auto 4"},{"executables":{"win32":["GTA5.exe"]},"id":182,"name":"Grand Theft Auto 5"},{"executables":{"win32":["Gw.exe"]},"id":183,"name":"Guild Wars"},{"executables":{"win32":["H1Z1.exe"]},"id":186,"name":"H1Z1"},{"executables":{"win32":["HL2HL2.exe","hl2.exe"]},"id":188,"name":"Half Life 2"},{"executables":{"win32":["HOMEFRONT.exe"]},"id":195,"name":"Homefront"},{"executables":{"win32":["invisibleinc.exe"]},"id":196,"name":"Invisible Inc."},{"executables":{"win32":["LANoire.exe"]},"id":197,"name":"L.A. Noire"},{"executables":{"win32":["Landmark64.exe"]},"id":198,"name":"Landmark"},{"executables":{"win32":["left4dead2.exe"]},"id":201,"name":"Left 4 Dead 2"},{"executables":{"win32":["lineage.exe"]},"id":203,"name":"Lineage"},{"executables":{"win32":["Magicka.exe"]},"id":206,"name":"Magicka"},{"executables":{"win32":["MapleStory.exe"]},"id":208,"name":"MapleStory"},{"executables":{},"id":209,"name":"Mark of the Ninja"},{"executables":{"win32":["MassEffect.exe"]},"id":210,"name":"Mass Effect"},{"executables":{"win32":["MassEffect2.exe"]},"id":211,"name":"Mass Effect 2"},{"executables":{"win32":["MassEffect3Demo.exe"]},"id":212,"name":"Mass Effect 3"},{"executables":{"win32":["METAL GEAR RISING REVENGEANCE.exe"]},"id":214,"name":"Metal Gear Rising: Revengeance"},{"executables":{"win32":["metro2033.exe"]},"id":215,"name":"Metro 2033"},{"executables":{"win32":["MetroLL.exe"]},"id":216,"name":"Metro Last Light"},{"executables":{"win32":["MK10.exe"]},"id":218,"name":"Mortal Kombat X"},{"executables":{"win32":["speed.exe"]},"id":219,"name":"Need For Speed Most Wanted"},{"executables":{},"id":220,"name":"Neverwinder"},{"executables":{"darwin":["Outlast.app"],"win32":["OLGame.exe"]},"id":221,"name":"Outlast"},{"executables":{"win32":["PapersPlease.exe"]},"id":222,"name":"Papers, Please"},{"executables":{"win32":["payday_win32_release.exe"]},"id":223,"name":"PAYDAY"},{"executables":{"win32":["payday2_win32_release.exe"]},"id":224,"name":"PAYDAY2"},{"executables":{"win32":["PillarsOfEternity.exe"]},"id":225,"name":"Pillars of Eternity"},{"executables":{"win32":["PA.exe"]},"id":226,"name":"Planetary Annihilation"},{"executables":{"win32":["planetside2_x86.exe"]},"id":227,"name":"Planetside 2"},{"executables":{"win32":["hl2P.exe"]},"id":228,"name":"Portal"},{"executables":{"win32":["portal2.exe"]},"id":229,"name":"Portal 2"},{"executables":{"win32":["PrimalCarnageGame.exe"]},"id":231,"name":"Primal Cargnage"},{"executables":{"win32":["pCARS.exe"]},"id":232,"name":"Project Cars"},{"executables":{"win32":["RaceTheSun.exe"]},"id":233,"name":"Race The Sun"},{"executables":{"win32":["Rage.exe"]},"id":234,"name":"RAGE"},{"executables":{"win32":["ragexe.exe"]},"id":235,"name":"Ragnarok Online"},{"executables":{"win32":["rift.exe"]},"id":236,"name":"Rift"},{"executables":{"win32":["Rocksmith2014.exe"]},"id":237,"name":"Rocksmith 2014"},{"executables":{"win32":["SwiftKit-RS.exe","JagexLauncher.exe"]},"id":238,"name":"RuneScape"},{"executables":{"win32":["Shadowgrounds.exe"]},"id":239,"name":"Shadowgrounds"},{"executables":{"win32":["survivor.exe"]},"id":240,"name":"Shadowgrounds: Survivor"},{"executables":{"win32":["ShovelKnight.exe"]},"id":241,"name":"Shovel Knight"},{"executables":{"win32":["SimCity.exe"]},"id":242,"name":"SimCity"},{"executables":{"win32":["SporeApp.exe"]},"id":245,"name":"Spore"},{"executables":{"win32":["StarCitizen.exe"]},"id":246,"name":"Star Citizen"},{"executables":{},"id":247,"name":"Star Trek Online"},{"executables":{"win32":["battlefront.exe"]},"id":248,"name":"Star Wars Battlefront"},{"executables":{"win32":["swtor.exe"]},"id":249,"name":"Star Wars: The Old Republic"},{"executables":{"win32":["starbound.exe","starbound_opengl.exe"]},"id":250,"name":"Starbound"},{"executables":{"win32":["starcraft.exe"]},"id":251,"name":"Starcraft"},{"executables":{"win32":["SSFIV.exe"]},"id":253,"name":"Ultra Street Fighter IV"},{"executables":{"win32":["superhexagon.exe"]},"id":254,"name":"Super Hexagon"},{"executables":{"win32":["swordandsworcery_pc.exe"]},"id":255,"name":"Superbrothers: Sword & Sworcery EP"},{"executables":{"win32":["hl2TF.exe"]},"id":256,"name":"Team Fortress 2"},{"executables":{"win32":["TERA.exe"]},"id":258,"name":"TERA"},{"executables":{"win32":["Terraria.exe"]},"id":259,"name":"Terraria"},{"executables":{"win32":["Bethesda.net_Launcher.exe"]},"id":260,"name":"The Elder Scrolls Online"},{"executables":{"win32":["TESV.exe"]},"id":261,"name":"The Elder Scrolls V: Skyrim"},{"executables":{"win32":["TheSecretWorld.exe"]},"id":262,"name":"The Secret World"},{"executables":{"win32":["TS3.exe","ts3w.exe"]},"id":264,"name":"The Sims 3"},{"executables":{"win32":["WALKINGDEAD101.EXE"]},"id":265,"name":"The Walking Dead"},{"executables":{"win32":["TheWalkingDead2.exe"]},"id":266,"name":"The Walking Dead Season Two"},{"executables":{"win32":["witcher3.exe"]},"id":267,"name":"The Witcher 3"},{"executables":{"win32":["Future Soldier.exe"]},"id":268,"name":"Tom Clancy's Ghost Recon: Future Solider"},{"executables":{"win32":["TombRaider.exe"]},"id":269,"name":"Tomb Raider (2013)"},{"executables":{"win32":["Torchlight.exe"]},"id":271,"name":"Torchlight"},{"executables":{"win32":["Torchlight2.exe"]},"id":272,"name":"Torchlight 2"},{"executables":{"win32":["Shogun2.exe"]},"id":273,"name":"Total War: Shogun 2"},{"executables":{"win32":["Transistor.exe"]},"id":274,"name":"Transistor"},{"executables":{"win32":["trine.exe"]},"id":275,"name":"Trine"},{"executables":{"win32":["trine2_32bit.exe"]},"id":276,"name":"Trine 2"},{"executables":{"win32":["UOKR.exe"]},"id":277,"name":"Ultima Online"},{"executables":{"win32":["aces.exe"]},"id":279,"name":"War Thunder"},{"executables":{"win32":["Warcraft III.exe","wc3.exe"]},"id":281,"name":"Warcraft 3: Reign of Chaos"},{"executables":{"win32":["Warcraft II BNE.exe"]},"id":282,"name":"Warcraft II"},{"executables":{"win32":["Warframe.x64.exe","Warframe.exe"]},"id":283,"name":"Warframe"},{"executables":{"win32":["watch_dogs.exe"]},"id":284,"name":"Watch Dogs"},{"executables":{"win32":["WildStar64.exe"]},"id":285,"name":"WildStar"},{"executables":{"win32":["XComGame.exe"]},"id":288,"name":"XCOM: Enemy Unknown"},{"executables":{"win32":["DFO.exe","dfo.exe"]},"id":289,"name":"Dungeon Fighter Online"},{"executables":{"win32":["aclauncher.exe","acclient.exe"]},"id":290,"name":"Asheron's Call"},{"executables":{"win32":["MapleStory2.exe"]},"id":291,"name":"MapleStory 2"},{"executables":{"win32":["ksp.exe"]},"id":292,"name":"Kerbal Space Program"},{"executables":{"win32":["PINBALL.EXE"]},"id":293,"name":"3D Pinball: Space Cadet"},{"executables":{"win32":["dave.exe"]},"id":294,"name":"Dangerous Dave"},{"executables":{"win32":["iwbtgbeta(slomo).exe","iwbtgbeta(fs).exe"]},"id":295,"name":"I Wanna Be The Guy"},{"executables":{"win32":["MechWarriorOnline.exe "]},"id":296,"name":"Mech Warrior Online"},{"executables":{"win32":["dontstarve_steam.exe"]},"id":297,"name":"Don't Starve"},{"executables":{"win32":["GalCiv3.exe"]},"id":298,"name":"Galactic Civilization 3"},{"executables":{"win32":["Risk of Rain.exe"]},"id":299,"name":"Risk of Rain"},{"executables":{"win32":["Binding_of_Isaac.exe","Isaac-ng.exe"]},"id":300,"name":"The Binding of Isaac"},{"executables":{"win32":["RustClient.exe"]},"id":301,"name":"Rust"},{"executables":{"win32":["Clicker Heroes.exe"]},"id":302,"name":"Clicker Heroes"},{"executables":{"win32":["Brawlhalla.exe"]},"id":303,"name":"Brawlhalla"},{"executables":{"win32":["TownOfSalem.exe"]},"id":304,"name":"Town of Salem"},{"executables":{"win32":["osu!.exe"]},"id":305,"name":"osu!"},{"executables":{"win32":["PathOfExileSteam.exe","PathOfExile.exe"]},"id":306,"name":"Path of Exile"},{"executables":{"win32":["Dolphin.exe"]},"id":307,"name":"Dolphin"},{"executables":{"win32":["RocketLeague.exe"]},"id":308,"name":"Rocket League"},{"executables":{"win32":["TJPP.exe"]},"id":309,"name":"Jackbox Party Pack"},{"executables":{"win32":["KFGame.exe"]},"id":310,"name":"Killing Floor 2"},{"executables":{"win32":["ShooterGame.exe"]},"id":311,"name":"Ark: Survival Evolved"},{"executables":{"win32":["LifeIsStrange.exe"]},"id":312,"name":"Life Is Strange"},{"executables":{"win32":["Client_tos.exe"]},"id":313,"name":"Tree of Savior"},{"executables":{"win32":["olliolli2.exe"]},"id":314,"name":"OlliOlli2"},{"executables":{"win32":["cw.exe"]},"id":315,"name":"Closers Dimension Conflict"},{"executables":{"win32":["ESSTEAM.exe","elsword.exe","x2.exe"]},"id":316,"name":"Elsword"},{"executables":{"win32":["ori.exe"]},"id":317,"name":"Ori and the Blind Forest"},{"executables":{"win32":["Skyforge.exe"]},"id":318,"name":"Skyforge"},{"executables":{"win32":["projectzomboid64.exe","projectzomboid32.exe"]},"id":319,"name":"Project Zomboid"},{"executables":{"win32":["From_The_Depths.exe"]},"id":320,"name":"The Depths"},{"executables":{"win32":["TheCrew.exe"]},"id":321,"name":"The Crew"},{"executables":{"win32":["MarvelHeroes2015.exe"]},"id":322,"name":"Marvel Heroes 2015"},{"executables":{"win32":["timeclickers.exe"]},"id":324,"name":"Time Clickers"},{"executables":{"win32":["eurotrucks2.exe"]},"id":325,"name":"Euro Truck Simulator 2"},{"executables":{"win32":["FarmingSimulator2015Game.exe"]},"id":326,"name":"Farming Simulator 15"},{"executables":{"win32":["strife.exe"]},"id":327,"name":"Strife"},{"executables":{"win32":["Awesomenauts.exe"]},"id":328,"name":"Awesomenauts"},{"executables":{"win32":["Dofus.exe"]},"id":329,"name":"Dofus"},{"executables":{"win32":["Boid.exe"]},"id":330,"name":"Boid"},{"executables":{"win32":["adventure-capitalist.exe"]},"id":331,"name":"AdVenture Capitalist"},{"executables":{"win32":["OrcsMustDie2.exe"]},"id":332,"name":"Orcs Must Die! 2"},{"executables":{"win32":["Mountain.exe"]},"id":333,"name":"Mountain"},{"executables":{"win32":["Valkyria.exe"]},"id":335,"name":"Valkyria Chronicles"},{"executables":{"win32":["ffxiiiimg.exe"]},"id":336,"name":"Final Fantasy XIII"},{"executables":{"win32":["TLR.exe"]},"id":337,"name":"The Last Remnant"},{"executables":{"win32":["Cities.exe"]},"id":339,"name":"Cities Skylines"},{"executables":{"win32":["worldofwarships.exe","WoWSLauncher.exe"]},"id":341,"name":"World of Warships"},{"executables":{"win32":["spacegame-Win64-shipping.exe"]},"id":342,"name":"Fractured Space"},{"executables":{"win32":["thespacegame.exe"]},"id":343,"name":"Ascent - The Space Game"},{"executables":{"win32":["DuckGame.exe"]},"id":344,"name":"Duck Game"},{"executables":{"win32":["PPSSPPWindows.exe"]},"id":345,"name":"PPSSPP"},{"executables":{"win32":["MBAA.exe"]},"id":346,"name":"Melty Blood Actress Again: Current Code"},{"executables":{"win32":["TheWolfAmongUs.exe"]},"id":347,"name":"The Wolf Among Us"},{"executables":{"win32":["SpaceEngineers.exe"]},"id":348,"name":"Space Engineers"},{"executables":{"win32":["Borderlands.exe"]},"id":349,"name":"Borderlands"},{"executables":{"win32":["100orange.exe"]},"id":351,"name":"100% Orange Juice"},{"executables":{"win32":["reflex.exe"]},"id":354,"name":"Reflex"},{"executables":{"win32":["pso2.exe"]},"id":355,"name":"Phantasy Star Online 2"},{"executables":{"win32":["AssettoCorsa.exe"]},"id":356,"name":"Assetto Corsa"},{"executables":{"win32":["iw3mp.exe","iw3sp.exe"]},"id":357,"name":"Call of Duty 4: Modern Warfare"},{"executables":{"win32":["WolfOldBlood_x64.exe"]},"id":358,"name":"Wolfenstein: The Old Blood"},{"executables":{"win32":["castle.exe"]},"id":359,"name":"Castle Crashers"},{"executables":{"win32":["vindictus.exe"]},"id":360,"name":"Vindictus"},{"executables":{"win32":["ShooterGame-Win32-Shipping.exe"]},"id":361,"name":"Dirty Bomb"},{"executables":{"win32":["BatmanAK.exe"]},"id":362,"name":"Batman Arkham Knight"},{"executables":{"win32":["drt.exe"]},"id":363,"name":"Dirt Rally"},{"executables":{"win32":["rFactor.exe"]},"id":364,"name":"rFactor"},{"executables":{"win32":["clonk.exe"]},"id":365,"name":"Clonk Rage"},{"executables":{"win32":["SRHK.exe"]},"id":366,"name":"Shadowrun: Hong Kong"},{"executables":{"win32":["Insurgency.exe"]},"id":367,"name":"Insurgency"},{"executables":{"win32":["StepMania.exe"]},"id":368,"name":"Step Mania"},{"executables":{"win32":["FirefallCLient.exe"]},"id":369,"name":"Firefall"},{"executables":{"win32":["mirrorsedge.exe"]},"id":370,"name":"Mirrors Edge"},{"executables":{"win32":["MgsGroundZeroes.exe"]},"id":371,"name":"Metal Gear Solid V: Ground Zeroes"},{"executables":{"win32":["mgsvtpp.exe"]},"id":372,"name":"Metal Gear Solid V: The Phantom Pain"},{"executables":{"win32":["tld.exe"]},"id":373,"name":"The Long Dark"},{"executables":{"win32":["TKOM.exe"]},"id":374,"name":"Take On Mars"},{"executables":{"win32":["robloxplayerlauncher.exe","Roblox.exe"]},"id":375,"name":"Roblox"},{"executables":{"win32":["eu4.exe"]},"id":376,"name":"Europa Universalis 4"},{"executables":{"win32":["APB.exe"]},"id":377,"name":"APB Reloaded"},{"executables":{"win32":["Robocraft.exe"]},"id":378,"name":"Robocraft"},{"executables":{"win32":["Unity.exe"]},"id":379,"name":"Unity"},{"executables":{"win32":["Simpsons.exe"]},"id":380,"name":"The Simpsons: Hit & Run"},{"executables":{"win32":["Dnlauncher.exe","DragonNest.exe"]},"id":381,"name":"Dragon Nest"},{"executables":{"win32":["Trove.exe"]},"id":382,"name":"Trove"},{"executables":{"win32":["EndlessLegend.exe"]},"id":383,"name":"Endless Legend"},{"executables":{"win32":["TurbineLauncher.exe","dndclient.exe"]},"id":384,"name":"Dungeons & Dragons Online"},{"executables":{"win32":["quakelive.exe","quakelive_steam.exe"]},"id":385,"name":"Quake Live"},{"executables":{"win32":["7DaysToDie.exe"]},"id":386,"name":"7DaysToDie"},{"executables":{"win32":["SpeedRunners.exe"]},"id":387,"name":"SpeedRunners"},{"executables":{"win32":["gamemd.exe"]},"id":388,"name":"Command & Conquer: Red Alert 2"},{"executables":{"win32":["generals.exe"]},"id":389,"name":"Command & Conquer Generals: Zero Hour"},{"executables":{"win32":["Oblivion.exe"]},"id":390,"name":"The Elder Scrolls 4: Oblivion"},{"executables":{"win32":["mgsi.exe"]},"id":391,"name":"Metal Gear Solid"},{"executables":{"win32":["EoCApp.exe"]},"id":392,"name":"Divinity - Original Sin"},{"executables":{"win32":["Torment.exe"]},"id":393,"name":"Planescape: Torment"},{"executables":{"win32":["HexPatch.exe"]},"id":394,"name":"Hex: Shards of Fate"},{"executables":{"win32":["NS3FB.exe"]},"id":395,"name":"Naruto Shippuden Ultimate Ninja Storm 3 Full Burst"},{"executables":{"win32":["NSUNSR.exe"]},"id":396,"name":"Naruto Shippuden Ultimate Ninja Storm Revolution"},{"executables":{"win32":["SaintsRowIV.exe"]},"id":397,"name":"Saints Row IV"},{"executables":{"win32":["Shadowrun.exe"]},"id":398,"name":"Shadowrun"},{"executables":{"win32":["DungeonoftheEndless.exe"]},"id":399,"name":"Dungeon of the Endless"},{"executables":{"win32":["Hon.exe"]},"id":400,"name":"Heroes of Newerth"},{"executables":{"win32":["mabinogi.exe"]},"id":401,"name":"Mabinogi"},{"executables":{"win32":["CoD2MP_s.exe","CoDSP_s.exe"]},"id":402,"name":"Call of Duty 2:"},{"executables":{"win32":["CoDWaWmp.exe","CoDWaw.exe"]},"id":403,"name":"Call of Duty: World at War"},{"executables":{"win32":["heroes.exe"]},"id":404,"name":"Mabinogi Heroes (Vindictus) "},{"executables":{"win32":["KanColleViewer.exe"]},"id":405,"name":"KanColle "},{"executables":{"win32":["cyphers.exe"]},"id":406,"name":"Cyphers"},{"executables":{"win32":["RelicCoH2.exe"]},"id":407,"name":"Company of Heroes 2"},{"executables":{"win32":["MJ.exe"]},"id":408,"name":"セガNET麻雀MJ"},{"executables":{"win32":["ge.exe"]},"id":409,"name":"Granado Espada"},{"executables":{"win32":["NovaRO.exe"]},"id":410,"name":"Nova Ragnarok Online"},{"executables":{"win32":["RivalsofAether.exe"]},"id":411,"name":"Rivals of Aether"},{"executables":{"win32":["bfh.exe"]},"id":412,"name":"Battlefield Hardline"},{"executables":{"win32":["GrowHome.exe"]},"id":413,"name":"Grow Home"},{"executables":{"win32":["patriots.exe"]},"id":414,"name":"Rise of Nations Extended"},{"executables":{"win32":["Railroads.exe"]},"id":415,"name":"Sid Meier's Railroads!"},{"executables":{"win32":["Empire.exe"]},"id":416,"name":"Empire: Total War"},{"executables":{"win32":["Napoleon.exe"]},"id":417,"name":"Napoleon: Total War"},{"executables":{"win32":["gta_sa.exe"]},"id":418,"name":"Grand Theft Auto: San Andreas"},{"executables":{"win32":["MadMax.exe"]},"id":419,"name":"Mad Max"},{"executables":{"win32":["Titanfall.exe"]},"id":420,"name":"Titanfall"},{"executables":{"win32":["age2_x1.exe"]},"id":421,"name":"Age of Empires II: The Conquerors"},{"executables":{"win32":["Rome2.exe"]},"id":422,"name":"Total War: ROME 2"},{"executables":{"win32":["ShadowOfMordor.exe"]},"id":423,"name":"Middle-earth: Shadow of Mordor"},{"executables":{"win32":["Subnautica.exe"]},"id":424,"name":"Subnautica"},{"executables":{"win32":["anno5.exe"]},"id":425,"name":"Anno 2070"},{"executables":{"win32":["carrier.exe"]},"id":426,"name":"Carrier Command Gaea Mission"},{"executables":{"win32":["DarksidersPC.exe"]},"id":427,"name":"Darksiders"},{"executables":{"win32":["Darksiders2.exe"]},"id":428,"name":"Darksiders 2"},{"executables":{"win32":["mudlet.exe"]},"id":429,"name":"Mudlet"},{"executables":{"win32":["DunDefLauncher.exe"]},"id":430,"name":"Dungeon Defenders II"},{"executables":{"win32":["hng.exe"]},"id":431,"name":"Heroes and Generals"},{"executables":{"win32":["WFTOGame.exe"]},"id":432,"name":"War of the Overworld"},{"executables":{"win32":["Talisman.exe"]},"id":433,"name":"Talisman: Digital Edition"},{"executables":{"win32":["limbo.exe"]},"id":434,"name":"Limbo"},{"executables":{"win32":["ibbobb.exe"]},"id":435,"name":"ibb & obb"},{"executables":{"win32":["BattleBlockTheater.exe"]},"id":436,"name":"BattleBlock Theater"},{"executables":{"win32":["iracinglauncher.exe","iracingsim.exe","iracingsim64.exe"]},"id":437,"name":"iRacing"},{"executables":{"win32":["CivilizationV_DX11.exe"]},"id":438,"name":"Civilization V"}] +},{}]},{},[9])(9) +}); \ No newline at end of file diff --git a/web-dist/discord.min.3.9.0.js b/web-dist/discord.min.3.9.0.js new file mode 100644 index 000000000..0bd07e0a0 --- /dev/null +++ b/web-dist/discord.min.3.9.0.js @@ -0,0 +1,3 @@ +!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Discord=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g>>a&1)},a.prototype.setBit=function(){},e(a,[{key:"createInstantInvite",get:function(){return this.getBit(0)},set:function(a){this.setBit(0,a)}},{key:"manageRoles",get:function(){return this.getBit(3)},set:function(a){this.setBit(3,a)}},{key:"manageChannels",get:function(){return this.getBit(4)},set:function(a){this.setBit(4,a)}},{key:"readMessages",get:function(){return this.getBit(10)},set:function(a){this.setBit(10,a)}},{key:"sendMessages",get:function(){return this.getBit(11)},set:function(a){this.setBit(11,a)}},{key:"sendTTSMessages",get:function(){return this.getBit(12)},set:function(a){this.setBit(12,a)}},{key:"manageMessages",get:function(){return this.getBit(13)},set:function(a){this.setBit(13,a)}},{key:"embedLinks",get:function(){return this.getBit(14)},set:function(a){this.setBit(14,a)}},{key:"attachFiles",get:function(){return this.getBit(15)},set:function(a){this.setBit(15,a)}},{key:"readMessageHistory",get:function(){return this.getBit(16)},set:function(a){this.setBit(16,a)}},{key:"mentionEveryone",get:function(){return this.getBit(17)},set:function(a){this.setBit(17,a)}},{key:"voiceConnect",get:function(){return this.getBit(20)},set:function(a){this.setBit(20,a)}},{key:"voiceSpeak",get:function(){return this.getBit(21)},set:function(a){this.setBit(21,a)}},{key:"voiceMuteMembers",get:function(){return this.getBit(22)},set:function(a){this.setBit(22,a)}},{key:"voiceDeafenMembers",get:function(){return this.getBit(23)},set:function(a){this.setBit(23,a)}},{key:"voiceMoveMembers",get:function(){return this.getBit(24)},set:function(a){this.setBit(24,a)}},{key:"voiceUseVoiceActivation",get:function(){return this.getBit(25)},set:function(a){this.setBit(25,a)}}]),a}();b.exports=f},{}],2:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c=k.length)break;n=k[m++]}else{if(m=k.next(),m.done)break;n=m.value}for(var o=n,p=[],q=o.mentions,r=Array.isArray(q),s=0,q=r?q:q[Symbol.iterator]();;){var t;if(r){if(s>=q.length)break;t=q[s++]}else{if(s=q.next(),s.done)break;t=s.value}var u=t;p.push(d.addUser(u))}var v=d.addUser(o.author);f.push(new j(o,i,p,v))}c(null,f),e(f)}})})},a.prototype.deleteChannel=function(a){var b=arguments.length<=1||void 0===arguments[1]?function(a){}:arguments[1],c=this;return new Promise(function(d,e){var g=a;a instanceof i&&(g=a.id),n.del(f.CHANNELS+"/"+g).set("authorization",c.token).end(function(a){a?(b(a),e(a)):(b(null),d())})})},a.prototype.joinServer=function(a){var b=arguments.length<=1||void 0===arguments[1]?function(a,b){}:arguments[1],c=this;return new Promise(function(d,e){var g=a instanceof k?a.code:a;n.post(f.API+"/invite/"+g).set("authorization",c.token).end(function(a,f){a?(b(a),e(a)):c.getServer("id",f.body.guild.id)?d(c.getServer("id",f.body.guild.id)):c.serverCreateListener[f.body.guild.id]=[d,b]})})},a.prototype.sendFile=function(a,b){var c=arguments.length<=2||void 0===arguments[2]?"image.png":arguments[2],d=arguments.length<=3||void 0===arguments[3]?function(a,b){}:arguments[3],e=this,f=new Promise(function(g,h){function i(a){e.options.queue?(e.queue[a]||(e.queue[a]=[]),e.queue[a].push({action:"sendFile",attachment:l,attachmentName:c,then:j,error:k}),e.checkQueue(a)):e._sendFile(a,l,c).then(j)["catch"](k)}function j(a){f.message=a,d(null,a),g(a)}function k(a){f.error=a,d(a),h(a)}var l;"string"==typeof b||b instanceof String?(l=p.createReadStream(b),c=b):l=b,e.resolveDestination(a).then(i)["catch"](k)});return f},a.prototype.sendMessage=function(a,b,c){var d=arguments.length<=3||void 0===arguments[3]?function(a,b){}:arguments[3],e=arguments.length<=4||void 0===arguments[4]?"":arguments[4],f=this,g=new Promise(function(h,i){function j(a){d(a),i(a)}function k(a){f.options.queue?(f.queue[a]||(f.queue[a]=[]),f.queue[a].push({action:"sendMessage",content:b,mentions:p,tts:!!c,then:l,error:m}),f.checkQueue(a)):f._sendMessage(a,b,c,p).then(l)["catch"](m)}function l(a){g.message=a,d(null,a),h(a)}function m(a){g.error=a,d(a),i(a)}function n(){var a=b;return b instanceof Array&&(a=b.join("\n")),a}function o(){for(var a=[],c=b.match(/<@[^>]*>/g)||[],d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;a.push(g.substring(2,g.length-1))}return a}"function"==typeof c&&(d=c,c=!1),b=e+n(b);var p=o();f.resolveDestination(a).then(k)["catch"](j)});return g},a.prototype.createws=function(a){if(this.websocket)return!1;var b=this;this.websocket=new o(a),this.websocket.onopen=function(){b.trySendConnData()},this.websocket.onclose=function(){b.trigger("disconnected")},this.websocket.onmessage=function(a){var c=!1,d={};try{c=JSON.parse(a.data),d=c.d}catch(e){return void b.trigger("error",e,a)}switch(b.trigger("raw",c),c.t){case"READY":b.debug("received ready packet"),b.user=b.addUser(d.user);for(var f=d.guilds,h=Array.isArray(f),k=0,f=h?f:f[Symbol.iterator]();;){var l;if(h){if(k>=f.length)break;l=f[k++]}else{if(k=f.next(),k.done)break;l=k.value}var m=l,n=b.addServer(m)}for(var o=d.private_channels,p=Array.isArray(o),q=0,o=p?o:o[Symbol.iterator]();;){var r;if(p){if(q>=o.length)break;r=o[q++]}else{if(q=o.next(),q.done)break;r=q.value}var s=r;b.addPMChannel(s)}b.trigger("ready"),b.readyTime=Date.now(),b.debug("cached "+b.serverCache.length+" servers, "+b.channelCache.length+" channels, "+b.pmChannelCache.length+" PMs and "+b.userCache.length+" users."),b.state=3,setInterval(function(){b.keepAlive.apply(b)},d.heartbeat_interval);break;case"MESSAGE_CREATE":b.debug("received message");var t=[];d.mentions=d.mentions||[];for(var u=d.mentions,v=Array.isArray(u),w=0,u=v?u:u[Symbol.iterator]();;){var x;if(v){if(w>=u.length)break;x=u[w++]}else{if(w=u.next(),w.done)break;x=w.value}var y=x;t.push(b.addUser(y))}var z=b.getChannel("id",d.channel_id);if(z){var A=z.addMessage(new j(d,z,t,b.addUser(d.author)));b.trigger("message",A)}break;case"MESSAGE_DELETE":b.debug("message deleted");var z=b.getChannel("id",d.channel_id),B=z.getMessage("id",d.id);B?(b.trigger("messageDelete",z,B),z.messages.splice(z.messages.indexOf(B),1)):b.trigger("messageDelete",z);break;case"MESSAGE_UPDATE":b.debug("message updated");var z=b.getChannel("id",d.channel_id),C=z.getMessage("id",d.id);if(C){var D={};for(var E in C)D[E]=C[E];for(var E in d)D[E]=d[E];for(var t=[],F=D.mentions,G=Array.isArray(F),H=0,F=G?F:F[Symbol.iterator]();;){var I;if(G){if(H>=F.length)break;I=F[H++]}else{if(H=F.next(),H.done)break;I=H.value}var y=I;t.push(b.addUser(y))}var J=new j(D,z,t,C.author);b.trigger("messageUpdate",J,C),z.messages[z.messages.indexOf(C)]=J}break;case"GUILD_DELETE":var n=b.getServer("id",d.id);n&&(b.serverCache.splice(b.serverCache.indexOf(n),1),b.trigger("serverDelete",n));break;case"CHANNEL_DELETE":var z=b.getChannel("id",d.id);if(z){var n=z.server;n&&n.channels.splice(n.channels.indexOf(z),1),b.trigger("channelDelete",z),b.serverCache.splice(b.serverCache.indexOf(z),1)}break;case"GUILD_CREATE":var n=b.getServer("id",d.id);if(n||(n=b.addServer(d)),b.serverCreateListener[d.id]){var K=b.serverCreateListener[d.id];K[0](n),K[1](null,n),b.serverCreateListener[d.id]=null}b.trigger("serverCreate",n);break;case"CHANNEL_CREATE":var z=b.getChannel("id",d.id);if(!z){var L;L=d.is_private?b.addPMChannel(d):b.addChannel(d,d.guild_id);var M=b.getServer("id",d.guild_id);M&&M.addChannel(L),b.trigger("channelCreate",L)}break;case"GUILD_MEMBER_ADD":var n=b.getServer("id",d.guild_id);if(n){var N=b.addUser(d.user);b.trigger("serverNewMember",n.addMember(N,d.roles),n)}break;case"GUILD_MEMBER_REMOVE":var n=b.getServer("id",d.guild_id);if(n){var N=b.addUser(d.user);n.removeMember("id",N.id),b.trigger("serverRemoveMember",N,n)}break;case"USER_UPDATE":if(b.user&&d.id===b.user.id){var O=new g(d);b.trigger("userUpdate",O,b.user),~b.userCache.indexOf(b.user)&&(b.userCache[b.userCache.indexOf(b.user)]=O),b.user=O}break;case"PRESENCE_UPDATE":var P=b.getUser("id",d.user.id);if(P){d.user.username=d.user.username||P.username,d.user.id=d.user.id||P.id,d.user.discriminator=d.user.discriminator||P.discriminator,d.user.avatar=d.user.avatar||P.avatar;var Q=new g(d.user);Q.equalsStrict(P)?(b.trigger("presence",{user:P,oldStatus:P.status,status:d.status,server:b.getServer("id",d.guild_id),gameId:d.game_id}),P.status=d.status,P.gameId=d.game_id):(b.userCache[b.userCache.indexOf(P)]=Q,b.trigger("userUpdate",P,Q))}break;case"CHANNEL_UPDATE":var R=b.getChannel("id",d.id),S=b.getServer("id",d.guild_id);if(R&&S){var T=new i(d,S);T.messages=R.messages,b.trigger("channelUpdate",R,T),b.channelCache[b.channelCache.indexOf(R)]=T}break;case"TYPING_START":var P=b.getUser("id",d.user_id),R=b.getChannel("id",d.channel_id);b.userTypingListener[d.user_id]&&-1!==b.userTypingListener[d.user_id]||b.trigger("startTyping",P,R),b.userTypingListener[d.user_id]=Date.now(),setTimeout(function(){-1!==b.userTypingListener[d.user_id]&&Date.now()-b.userTypingListener[d.user_id]>6e3&&(b.trigger("stopTyping",P,R),b.userTypingListener[d.user_id]=-1)},6e3);break;case"GUILD_ROLE_DELETE":var n=b.getServer("id",d.guild_id),U=n.getRole(d.role_id);b.trigger("serverRoleDelete",n,U),n.removeRole(U.id);break;case"GUILD_ROLE_UPDATE":var n=b.getServer("id",d.guild_id),U=n.getRole(d.role.id),V=n.updateRole(d.role);b.trigger("serverRoleUpdate",n,U,V);break;default:b.debug("received unknown packet"),b.trigger("unknown",c)}}},a.prototype.addUser=function(a){return this.getUser("id",a.id)||this.userCache.push(new g(a)),this.getUser("id",a.id)},a.prototype.addChannel=function(a,b){return this.getChannel("id",a.id)||this.channelCache.push(new i(a,this.getServer("id",b))),this.getChannel("id",a.id)},a.prototype.addPMChannel=function(a){return this.getPMChannel("id",a.id)||this.pmChannelCache.push(new l(a,this)),this.getPMChannel("id",a.id)},a.prototype.setTopic=function(a,b){var c=arguments.length<=2||void 0===arguments[2]?function(a){}:arguments[2],d=this;return new Promise(function(e,g){function h(a){c(a),g(a)}function i(a){var g=d.getChannel("id",a);n.patch(f.CHANNELS+"/"+a).set("authorization",d.token).send({name:g.name,position:0,topic:b}).end(function(a,b){a?h(a):(g.topic=b.body.topic,e(),c())})}d.resolveDestination(a).then(i)["catch"](h)})},a.prototype.addServer=function(a){var b=this,c=this.getServer("id",a.id);if(a.unavailable)return b.trigger("unavailable",a),void b.debug("Server ID "+a.id+" has been marked unavailable by Discord. It was not cached.");if(!c&&(c=new h(a,this),this.serverCache.push(c),a.channels))for(var d=a.channels,e=Array.isArray(d),f=0,d=e?d:d[Symbol.iterator]();;){var g;if(e){if(f>=d.length)break;g=d[f++]}else{if(f=d.next(),f.done)break;g=f.value}var i=g;c.channels.push(this.addChannel(i,c.id))}for(var j=a.presences,k=Array.isArray(j),l=0,j=k?j:j[Symbol.iterator]();;){var m;if(k){if(l>=j.length)break;m=j[l++]}else{if(l=j.next(),l.done)break;m=l.value}var n=m,o=b.getUser("id",n.user.id);o.status=n.status,o.gameId=n.game_id}return c},a.prototype.getUser=function(a,b){for(var c=this.userCache,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.getChannel=function(a,b){for(var c=this.channelCache,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return this.getPMChannel(a,b)},a.prototype.getPMChannel=function(a,b){for(var c=this.pmChannelCache,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.getServer=function(a,b){for(var c=this.serverCache,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.trySendConnData=function(){if(this.token&&!this.alreadySentData){this.alreadySentData=!0;var a={op:2,d:{token:this.token,v:3,properties:{$os:"discord.js",$browser:"discord.js",$device:"discord.js",$referrer:"",$referring_domain:""}}};this.websocket.send(JSON.stringify(a))}},a.prototype.resolveServerID=function(a){return a instanceof h?a.id:!isNaN(a)&&a.length&&17===a.length?a:void 0},a.prototype.resolveDestination=function(a){var b=!1,c=this;return new Promise(function(d,e){if(a instanceof h)b=a.id;else if(a instanceof i)b=a.id;else if(a instanceof j)b=a.channel.id;else if(a instanceof l)b=a.id;else if(a instanceof g){for(var f=c.pmChannelCache,k=Array.isArray(f),m=0,f=k?f:f[Symbol.iterator]();;){var n;if(k){if(m>=f.length)break;n=f[m++]}else{if(m=f.next(),m.done)break;n=m.value}var o=n;if(o.user&&o.user.equals(a))return void d(o.id)}c.startPM(a).then(function(a){d(a.id)})["catch"](e)}else b=a;b?d(b):e()})},a.prototype._sendMessage=function(a,b,c,d){var e=this;return new Promise(function(g,h){n.post(f.CHANNELS+"/"+a+"/messages").set("authorization",e.token).send({content:b,mentions:d,tts:c}).end(function(a,b){if(a)h(a);else{var c=b.body,d=[];c.mentions=c.mentions||[];for(var f=c.mentions,i=Array.isArray(f),k=0,f=i?f:f[Symbol.iterator]();;){var l;if(i){if(k>=f.length)break;l=f[k++]}else{if(k=f.next(),k.done)break;l=k.value}var m=l;d.push(e.addUser(m))}var n=e.getChannel("id",c.channel_id);if(n){var o=n.addMessage(new j(c,n,d,e.addUser(c.author)));g(o)}}})})},a.prototype._sendFile=function(a,b){var c=arguments.length<=2||void 0===arguments[2]?"DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png":arguments[2],d=this;return new Promise(function(e,g){n.post(f.CHANNELS+"/"+a+"/messages").set("authorization",d.token).attach("file",b,c).end(function(b,c){if(b)g(b);else{var f=d.getChannel("id",a);if(f){var h=f.addMessage(new j(c.body,f,[],d.user));e(h)}}})})},a.prototype._updateMessage=function(a,b){var c=this;return new Promise(function(d,e){n.patch(f.CHANNELS+"/"+a.channel.id+"/messages/"+a.id).set("authorization",c.token).send({content:b,mentions:[]}).end(function(b,c){if(b)e(b);else{var f=new j(c.body,a.channel,a.mentions,a.sender);d(f),a.channel.messages[a.channel.messages.indexOf(a)]=f}})})},a.prototype.getGateway=function(){var a=this;return new Promise(function(b,c){n.get(f.API+"/gateway").set("authorization",a.token).end(function(a,d){a?c(a):b(d.body.url)})})},a.prototype.setStatusIdle=function(){this.setStatus("idle")},a.prototype.setStatusOnline=function(){this.setStatus("online")},a.prototype.setStatusActive=function(){this.setStatusOnline()},a.prototype.setStatusHere=function(){this.setStatusOnline()},a.prototype.setStatusAway=function(){this.setStatusIdle()},a.prototype.startTyping=function(a,b){function c(a){if(!d.typingIntervals[a]){var c=function(){n.post(f.CHANNELS+"/"+a+"/typing").set("authorization",d.token).end()};c();var e=setInterval(c,3e3);d.typingIntervals[a]=e,b&&setTimeout(function(){d.stopTyping(a)},b)}}var d=this;this.resolveDestination(a).then(c)},a.prototype.stopTyping=function(a){function b(a){c.typingIntervals[a]&&(clearInterval(c.typingIntervals[a]),delete c.typingIntervals[a])}var c=this;this.resolveDestination(a).then(b)},a.prototype.setStatus=function(a){var b="online"===a?null:Date.now();this.__idleTime=b,this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}))},a.prototype.setPlayingGame=function(a){if(a instanceof String||"string"==typeof a){var b=a.trim().toUpperCase();a=null;for(var c=m,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g.name.trim().toUpperCase()===b){a=g.id;break}}}this.__gameId=a,this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}))},a.prototype.playGame=function(a){this.setPlayingGame(a)},a.prototype.playingGame=function(a){this.setPlayingGame(a)},e(a,[{key:"uptime",get:function(){return this.readyTime?Date.now()-this.readyTime:null}},{key:"ready",get:function(){return 3===this.state}},{key:"servers",get:function(){return this.serverCache}},{key:"channels",get:function(){return this.channelCache}},{key:"users",get:function(){return this.userCache}},{key:"PMChannels",get:function(){return this.pmChannelCache}},{key:"messages",get:function(){for(var a=[],b=this.channelCache,c=Array.isArray(b),d=0,b=c?b:b[Symbol.iterator]();;){var e;if(c){if(d>=b.length)break;e=b[d++]}else{if(d=b.next(),d.done)break;e=d.value}var f=e;a=a.concat(f.messages)}return a}}]),a}();b.exports=r},{"../ref/gameMap.json":19,"./Endpoints.js":3,"./PMChannel.js":6,"./channel.js":8,"./invite.js":10,"./message.js":11,"./server.js":12,"./user.js":13,fs:14,superagent:15,ws:18}],3:[function(a,b,c){"use strict";c.BASE_DOMAIN="discordapp.com",c.BASE="https://"+c.BASE_DOMAIN,c.WEBSOCKET_HUB="wss://"+c.BASE_DOMAIN+"/hub",c.API=c.BASE+"/api",c.AUTH=c.API+"/auth",c.LOGIN=c.AUTH+"/login",c.LOGOUT=c.AUTH+"/logout",c.USERS=c.API+"/users",c.SERVERS=c.API+"/guilds",c.CHANNELS=c.API+"/channels"},{}],4:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c>>a&1)},a.prototype.setBit=function(){},e(a,[{key:"createInstantInvite",get:function(){return this.getBit(0)},set:function(a){this.setBit(0,a)}},{key:"manageRoles",get:function(){return this.getBit(3)},set:function(a){this.setBit(3,a)}},{key:"manageChannels",get:function(){return this.getBit(4)},set:function(a){this.setBit(4,a)}},{key:"readMessages",get:function(){return this.getBit(10)},set:function(a){this.setBit(10,a)}},{key:"sendMessages",get:function(){return this.getBit(11)},set:function(a){this.setBit(11,a)}},{key:"sendTTSMessages",get:function(){return this.getBit(12)},set:function(a){this.setBit(12,a)}},{key:"manageMessages",get:function(){return this.getBit(13)},set:function(a){this.setBit(13,a)}},{key:"embedLinks",get:function(){return this.getBit(14)},set:function(a){this.setBit(14,a)}},{key:"attachFiles",get:function(){return this.getBit(15)},set:function(a){this.setBit(15,a)}},{key:"readMessageHistory",get:function(){return this.getBit(16)},set:function(a){this.setBit(16,a)}},{key:"mentionEveryone",get:function(){return this.getBit(17)},set:function(a){this.setBit(17,a)}},{key:"voiceConnect",get:function(){return this.getBit(20)},set:function(a){this.setBit(20,a)}},{key:"voiceSpeak",get:function(){return this.getBit(21)},set:function(a){this.setBit(21,a)}},{key:"voiceMuteMembers",get:function(){return this.getBit(22)},set:function(a){this.setBit(22,a)}},{key:"voiceDeafenMembers",get:function(){return this.getBit(23)},set:function(a){this.setBit(23,a)}},{key:"voiceMoveMembers",get:function(){return this.getBit(24)},set:function(a){this.setBit(24,a)}},{key:"voiceUseVoiceActivation",get:function(){return this.getBit(25)},set:function(a){this.setBit(25,a)}}]),a}();b.exports=f},{}],5:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function e(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(Object.setPrototypeOf?Object.setPrototypeOf(a,b):a.__proto__=b)}var f=function(){function a(a,b){for(var c=0;c=d.length)break;g=d[f++]}else{if(f=d.next(),f.done)break;g=f.value}var h=g;h.id===this.id&&"member"===h.type?c.push(h):-1!==this.rawRoles.indexOf(h.id)&&b.push(h)}if(0===b.length&&0===c.length)return new i(this.evalPerms.packed);for(var j=0!==b.length?b[0].packed:c[0].packed,k=b,l=Array.isArray(k),m=0,k=l?k:k[Symbol.iterator]();;){var n;if(l){if(m>=k.length)break;n=k[m++]}else{if(m=k.next(),m.done)break;n=m.value}var h=n;j&=~h.deny,j|=h.allow}for(var o=c,p=Array.isArray(o),q=0,o=p?o:o[Symbol.iterator]();;){var r;if(p){if(q>=o.length)break;r=o[q++]}else{if(q=o.next(),q.done)break;r=q.value}var h=r;j&=~h.deny,j|=h.allow}return new i(j)},f(b,[{key:"roles",get:function(){for(var a=[this.server.getRole(this.server.id)],b=this.rawRoles,c=Array.isArray(b),d=0,b=c?b:b[Symbol.iterator]();;){var e;if(c){if(d>=b.length)break;e=b[d++]}else{if(d=b.next(),d.done)break;e=d.value}var f=e;a.push(this.server.getRole(f))}return a}},{key:"evalPerms",get:function(){for(var a=this.roles,b=a[0].packed,c=a,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;b|=g.packed}return new h({permissions:b})}}]),b}(g);b.exports=j},{"./EvaluatedPermissions.js":4,"./ServerPermissions.js":7,"./user.js":13}],6:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c1e3&&this.messages.splice(0,1);for(var c=this.messages,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},e(a,[{key:"isPrivate",get:function(){return!0}}]),a}();b.exports=f},{}],7:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c>>a&1)},a.prototype.setBit=function(){},a.prototype.toString=function(){return this.name},e(a,[{key:"createInstantInvite",get:function(){return this.getBit(0)},set:function(a){this.setBit(0,a)}},{key:"banMembers",get:function(){return this.getBit(1)},set:function(a){this.setBit(1,a)}},{key:"kickMembers",get:function(){return this.getBit(2)},set:function(a){this.setBit(2,a)}},{key:"manageRoles",get:function(){return this.getBit(3)},set:function(a){this.setBit(3,a)}},{key:"manageChannels",get:function(){return this.getBit(4)},set:function(a){this.setBit(4,a); +}},{key:"manageServer",get:function(){return this.getBit(5)},set:function(a){this.setBit(5,a)}},{key:"readMessages",get:function(){return this.getBit(10)},set:function(a){this.setBit(10,a)}},{key:"sendMessages",get:function(){return this.getBit(11)},set:function(a){this.setBit(11,a)}},{key:"sendTTSMessages",get:function(){return this.getBit(12)},set:function(a){this.setBit(12,a)}},{key:"manageMessages",get:function(){return this.getBit(13)},set:function(a){this.setBit(13,a)}},{key:"embedLinks",get:function(){return this.getBit(14)},set:function(a){this.setBit(14,a)}},{key:"attachFiles",get:function(){return this.getBit(15)},set:function(a){this.setBit(15,a)}},{key:"readMessageHistory",get:function(){return this.getBit(16)},set:function(a){this.setBit(16,a)}},{key:"mentionEveryone",get:function(){return this.getBit(17)},set:function(a){this.setBit(17,a)}},{key:"voiceConnect",get:function(){return this.getBit(20)},set:function(a){this.setBit(20,a)}},{key:"voiceSpeak",get:function(){return this.getBit(21)},set:function(a){this.setBit(21,a)}},{key:"voiceMuteMembers",get:function(){return this.getBit(22)},set:function(a){this.setBit(22,a)}},{key:"voiceDeafenMembers",get:function(){return this.getBit(23)},set:function(a){this.setBit(23,a)}},{key:"voiceMoveMembers",get:function(){return this.getBit(24)},set:function(a){this.setBit(24,a)}},{key:"voiceUseVoiceActivation",get:function(){return this.getBit(25)},set:function(a){this.setBit(25,a)}}]),a}();b.exports=f},{}],8:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c=e.length)break;i=e[h++]}else{if(h=e.next(),h.done)break;i=h.value}var j=i;this.roles.push(new f(j,this))}}return a.prototype.permissionsOf=function(a){var b=this.server.getMember("id",a.id);return b?b.permissionsIn(this):null},a.prototype.equals=function(a){return a&&a.id===this.id},a.prototype.addMessage=function(a){return this.messages.length>1e3&&this.messages.splice(0,1),this.getMessage("id",a.id)||this.messages.push(a),this.getMessage("id",a.id)},a.prototype.getMessage=function(a,b){for(var c=this.messages,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.toString=function(){return"<#"+this.id+">"},e(a,[{key:"permissionOverwrites",get:function(){return this.roles}},{key:"permissions",get:function(){return this.roles}},{key:"client",get:function(){return this.server.client}},{key:"isPrivate",get:function(){return!1}},{key:"users",get:function(){return this.server.members}},{key:"members",get:function(){return this.server.members}}]),a}();b.exports=g},{"./ChannelPermissions.js":1}],9:[function(a,b,c){"use strict";var d=(a("superagent"),a("./Endpoints.js")),e=a("./Client.js"),f={Endpoints:d,Client:e};b.exports=f},{"./Client.js":2,"./Endpoints.js":3,superagent:15}],10:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g.id===b)return!0}return!1},e(a,[{key:"sender",get:function(){return this.author}},{key:"isPrivate",get:function(){return this.channel.isPrivate}}]),a}());b.exports=f},{"./PMChannel.js":6}],12:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c=e.length)break;i=e[h++]}else{if(h=e.next(),h.done)break;i=h.value}var j=i;this.roles.push(new f(j))}if(!b.members)return void(b.members=[c.user]);for(var k=b.members,l=Array.isArray(k),m=0,k=l?k:k[Symbol.iterator]();;){var n;if(l){if(m>=k.length)break;n=k[m++]}else{if(m=k.next(),m.done)break;n=m.value}var o=n;o.user&&this.addMember(c.addUser(o.user),o.roles)}}return a.prototype.getRole=function(a){for(var b=this.roles,c=Array.isArray(b),d=0,b=c?b:b[Symbol.iterator]();;){var e;if(c){if(d>=b.length)break;e=b[d++]}else{if(d=b.next(),d.done)break;e=d.value}var f=e;if(f.id===a)return f}return null},a.prototype.updateRole=function(a){var b=this.getRole(a.id);if(b){var c=this.roles.indexOf(b);return this.roles[c]=new f(a),this.roles[c]}return!1},a.prototype.removeRole=function(a){for(var b in this.roles)this.roles[b].id===a&&this.roles.splice(b,1);for(var c=this.members,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;for(var b in g.rawRoles)g.rawRoles[b]===a&&g.rawRoles.splice(b,1)}},a.prototype.getChannel=function(a,b){for(var c=this.channels,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.getMember=function(a,b){for(var c=this.members,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.removeMember=function(a,b){for(var c=this.members,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return this.members.splice(a,1),g}return!1},a.prototype.addChannel=function(a){return this.getChannel("id",a.id)||this.channels.push(a),a},a.prototype.addMember=function(a,b){if(!this.getMember("id",a.id)){var c=new g(a,this,b);this.members.push(c)}return c},a.prototype.toString=function(){return this.name},a.prototype.equals=function(a){return a.id===this.id},e(a,[{key:"permissionGroups",get:function(){return this.roles}},{key:"permissions",get:function(){return this.roles}},{key:"iconURL",get:function(){return this.icon?"https://discordapp.com/api/guilds/"+this.id+"/icons/"+this.icon+".jpg":null}},{key:"afkChannel",get:function(){return this.afkChannelId?this.getChannel("id",this.afkChannelId):!1}},{key:"defaultChannel",get:function(){return this.getChannel("name","general")}},{key:"owner",get:function(){return this.client.getUser("id",this.ownerID)}},{key:"users",get:function(){return this.members}}]),a}();b.exports=h},{"./Member.js":5,"./ServerPermissions.js":7}],13:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c"},a.prototype.toString=function(){return this.mention()},a.prototype.equals=function(a){return a.id===this.id},a.prototype.equalsStrict=function(a){return a.id===this.id&&a.avatar===this.avatar&&a.username===this.username&&a.discriminator===this.discriminator},e(a,[{key:"avatarURL",get:function(){return this.avatar?"https://discordapp.com/api/users/"+this.id+"/avatars/"+this.avatar+".jpg":null}}]),a}();b.exports=f},{}],14:[function(a,b,c){},{}],15:[function(a,b,c){function d(){}function e(a){var b={}.toString.call(a);switch(b){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function f(a){return a===Object(a)}function g(a){if(!f(a))return a;var b=[];for(var c in a)null!=a[c]&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")}function h(a){for(var b,c,d={},e=a.split("&"),f=0,g=e.length;g>f;++f)c=e[f],b=c.split("="),d[decodeURIComponent(b[0])]=decodeURIComponent(b[1]);return d}function i(a){var b,c,d,e,f=a.split(/\r?\n/),g={};f.pop();for(var h=0,i=f.length;i>h;++h)c=f[h],b=c.indexOf(":"),d=c.slice(0,b).toLowerCase(),e=r(c.slice(b+1)),g[d]=e;return g}function j(a){return a.split(/ *; */).shift()}function k(a){return q(a.split(/ *; */),function(a,b){var c=b.split(/ *= */),d=c.shift(),e=c.shift();return d&&e&&(a[d]=e),a},{})}function l(a,b){b=b||{},this.req=a,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||"undefined"==typeof this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText,this.setStatusProperties(this.xhr.status),this.header=this.headers=i(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body="HEAD"!=this.req.method?this.parseBody(this.text?this.text:this.xhr.response):null}function m(a,b){var c=this;p.call(this),this._query=this._query||[],this.method=a,this.url=b,this.header={},this._header={},this.on("end",function(){var a=null,b=null;try{b=new l(c)}catch(d){return a=new Error("Parser is unable to parse the response"),a.parse=!0,a.original=d,c.callback(a)}if(c.emit("response",b),a)return c.callback(a,b);if(b.status>=200&&b.status<300)return c.callback(a,b);var e=new Error(b.statusText||"Unsuccessful HTTP response");e.original=a,e.response=b,e.status=b.status,c.callback(e,b)})}function n(a,b){return"function"==typeof b?new m("GET",a).end(b):1==arguments.length?new m("GET",a):new m(a,b)}var o,p=a("emitter"),q=a("reduce");o="undefined"!=typeof window?window:"undefined"!=typeof self?self:this,n.getXHR=function(){if(!(!o.XMLHttpRequest||o.location&&"file:"==o.location.protocol&&o.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(a){}return!1};var r="".trim?function(a){return a.trim()}:function(a){return a.replace(/(^\s*|\s*$)/g,"")};n.serializeObject=g,n.parseString=h,n.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},n.serialize={"application/x-www-form-urlencoded":g,"application/json":JSON.stringify},n.parse={"application/x-www-form-urlencoded":h,"application/json":JSON.parse},l.prototype.get=function(a){return this.header[a.toLowerCase()]},l.prototype.setHeaderProperties=function(a){var b=this.header["content-type"]||"";this.type=j(b);var c=k(b);for(var d in c)this[d]=c[d]},l.prototype.parse=function(a){return this.parser=a,this},l.prototype.parseBody=function(a){var b=this.parser||n.parse[this.type];return b&&a&&(a.length||a instanceof Object)?b(a):null},l.prototype.setStatusProperties=function(a){1223===a&&(a=204);var b=a/100|0;this.status=this.statusCode=a,this.statusType=b,this.info=1==b,this.ok=2==b,this.clientError=4==b,this.serverError=5==b,this.error=4==b||5==b?this.toError():!1,this.accepted=202==a,this.noContent=204==a,this.badRequest=400==a,this.unauthorized=401==a,this.notAcceptable=406==a,this.notFound=404==a,this.forbidden=403==a},l.prototype.toError=function(){var a=this.req,b=a.method,c=a.url,d="cannot "+b+" "+c+" ("+this.status+")",e=new Error(d);return e.status=this.status,e.method=b,e.url=c,e},n.Response=l,p(m.prototype),m.prototype.use=function(a){return a(this),this},m.prototype.timeout=function(a){return this._timeout=a,this},m.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},m.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(),this.clearTimeout(),this.emit("abort"),this)},m.prototype.set=function(a,b){if(f(a)){for(var c in a)this.set(c,a[c]);return this}return this._header[a.toLowerCase()]=b,this.header[a]=b,this},m.prototype.unset=function(a){return delete this._header[a.toLowerCase()],delete this.header[a],this},m.prototype.getHeader=function(a){return this._header[a.toLowerCase()]},m.prototype.type=function(a){return this.set("Content-Type",n.types[a]||a),this},m.prototype.accept=function(a){return this.set("Accept",n.types[a]||a),this},m.prototype.auth=function(a,b){var c=btoa(a+":"+b);return this.set("Authorization","Basic "+c),this},m.prototype.query=function(a){return"string"!=typeof a&&(a=g(a)),a&&this._query.push(a),this},m.prototype.field=function(a,b){return this._formData||(this._formData=new o.FormData),this._formData.append(a,b),this},m.prototype.attach=function(a,b,c){return this._formData||(this._formData=new o.FormData),this._formData.append(a,b,c),this},m.prototype.send=function(a){var b=f(a),c=this.getHeader("Content-Type");if(b&&f(this._data))for(var d in a)this._data[d]=a[d];else"string"==typeof a?(c||this.type("form"),c=this.getHeader("Content-Type"),"application/x-www-form-urlencoded"==c?this._data=this._data?this._data+"&"+a:a:this._data=(this._data||"")+a):this._data=a;return!b||e(a)?this:(c||this.type("json"),this)},m.prototype.callback=function(a,b){var c=this._callback;this.clearTimeout(),c(a,b)},m.prototype.crossDomainError=function(){var a=new Error("Origin is not allowed by Access-Control-Allow-Origin");a.crossDomain=!0,this.callback(a)},m.prototype.timeoutError=function(){var a=this._timeout,b=new Error("timeout of "+a+"ms exceeded");b.timeout=a,this.callback(b)},m.prototype.withCredentials=function(){return this._withCredentials=!0,this},m.prototype.end=function(a){var b=this,c=this.xhr=n.getXHR(),f=this._query.join("&"),g=this._timeout,h=this._formData||this._data;this._callback=a||d,c.onreadystatechange=function(){if(4==c.readyState){var a;try{a=c.status}catch(d){a=0}if(0==a){if(b.timedout)return b.timeoutError();if(b.aborted)return;return b.crossDomainError()}b.emit("end")}};var i=function(a){a.total>0&&(a.percent=a.loaded/a.total*100),b.emit("progress",a)};this.hasListeners("progress")&&(c.onprogress=i);try{c.upload&&this.hasListeners("progress")&&(c.upload.onprogress=i)}catch(j){}if(g&&!this._timer&&(this._timer=setTimeout(function(){b.timedout=!0,b.abort()},g)),f&&(f=n.serializeObject(f),this.url+=~this.url.indexOf("?")?"&"+f:"?"+f),c.open(this.method,this.url,!0),this._withCredentials&&(c.withCredentials=!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof h&&!e(h)){var k=this.getHeader("Content-Type"),l=n.serialize[k?k.split(";")[0]:""];l&&(h=l(h))}for(var m in this.header)null!=this.header[m]&&c.setRequestHeader(m,this.header[m]);return this.emit("request",this),c.send(h),this},m.prototype.then=function(a,b){return this.end(function(c,d){c?b(c):a(d)})},n.Request=m,n.get=function(a,b,c){var d=n("GET",a);return"function"==typeof b&&(c=b,b=null),b&&d.query(b),c&&d.end(c),d},n.head=function(a,b,c){var d=n("HEAD",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.del=function(a,b){var c=n("DELETE",a);return b&&c.end(b),c},n.patch=function(a,b,c){var d=n("PATCH",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.post=function(a,b,c){var d=n("POST",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.put=function(a,b,c){var d=n("PUT",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},b.exports=n},{emitter:16,reduce:17}],16:[function(a,b,c){function d(a){return a?e(a):void 0}function e(a){for(var b in d.prototype)a[b]=d.prototype[b];return a}b.exports=d,d.prototype.on=d.prototype.addEventListener=function(a,b){return this._callbacks=this._callbacks||{},(this._callbacks[a]=this._callbacks[a]||[]).push(b),this},d.prototype.once=function(a,b){function c(){d.off(a,c),b.apply(this,arguments)}var d=this;return this._callbacks=this._callbacks||{},c.fn=b,this.on(a,c),this},d.prototype.off=d.prototype.removeListener=d.prototype.removeAllListeners=d.prototype.removeEventListener=function(a,b){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var c=this._callbacks[a];if(!c)return this;if(1==arguments.length)return delete this._callbacks[a],this;for(var d,e=0;ed;++d)c[d].apply(this,b)}return this},d.prototype.listeners=function(a){return this._callbacks=this._callbacks||{},this._callbacks[a]||[]},d.prototype.hasListeners=function(a){return!!this.listeners(a).length}},{}],17:[function(a,b,c){b.exports=function(a,b,c){for(var d=0,e=a.length,f=3==arguments.length?c:a[d++];e>d;)f=b.call(null,f,a[d],++d,a);return f}},{}],18:[function(a,b,c){function d(a,b,c){var d;return d=b?new f(a,b):new f(a)}var e=function(){return this}(),f=e.WebSocket||e.MozWebSocket;b.exports=f?d:null,f&&(d.prototype=f.prototype)},{}],19:[function(a,b,c){b.exports=[{executables:{win32:["pol.exe"]},id:0,name:"FINAL FANTASY XI"},{executables:{win32:["ffxiv.exe","ffxiv_dx11.exe"]},id:1,name:"FINAL FANTASY XIV"},{executables:{win32:["Wow.exe","Wow-64.exe"]},id:3,name:"World of Warcraft"},{executables:{darwin:["LoLLauncher.app"],win32:["LolClient.exe","League of Legends.exe"]},id:4,name:"League of Legends"},{executables:{darwin:["Diablo%20III.app"],win32:["Diablo III.exe"]},id:5,name:"Diablo 3"},{executables:{darwin:["dota_osx.app"],win32:["dota2.exe"]},id:6,name:"DOTA 2"},{executables:{darwin:["Heroes.app"],win32:["Heroes of the Storm.exe","HeroesOfTheStorm_x64.exe","HeroesOfTheStorm.exe"]},id:7,name:"Heroes of the Storm"},{executables:{darwin:["Hearthstone.app"],win32:["Hearthstone.exe"]},id:8,name:"Hearthstone"},{executables:{win32:["csgo.exe"]},id:9,name:"Counter-Strike: Global Offensive"},{executables:{win32:["WorldOfTanks.exe"]},id:10,name:"World of Tanks"},{executables:{darwin:["gw2.app"],win32:["gw2.exe"]},id:11,name:"Guild Wars 2"},{executables:{win32:["dayz.exe"]},id:12,name:"Day Z"},{executables:{darwin:["starcraft%20ii.app"],win32:["starcraft ii.exe","SC2_x64.exe","SC2.exe"]},id:13,name:"Starcraft II"},{executables:{win32:["diablo.exe"]},id:14,name:"Diablo"},{executables:{win32:["diablo ii.exe"]},id:15,name:"Diablo 2"},{executables:{win32:["left4dead.exe"]},id:17,name:"Left 4 Dead"},{executables:{darwin:["minecraft.app"],win32:["minecraft.exe"]},id:18,name:"Minecraft"},{executables:{win32:["smite.exe"]},id:19,name:"Smite"},{executables:{win32:["bf4.exe"]},id:20,name:"Battlefield 4"},{executables:{win32:["AoK HD.exe","empires2.exe"]},id:101,name:"Age of Empire II"},{executables:{win32:["age3y.exe"]},id:102,name:"Age of Empire III"},{executables:{win32:["AlanWake.exe"]},id:104,name:"Alan Wake"},{executables:{win32:["alan_wakes_american_nightmare.exe"]},id:105,name:"Alan Wake's American Nightmare"},{executables:{win32:["AlienBreed2Assault.exe"]},id:106,name:"Alien Breed 2: Assault"},{executables:{win32:["Amnesia.exe"]},id:107,name:"Amnesia: The Dark Descent"},{executables:{win32:["UDK.exe"]},id:108,name:"Antichamber"},{executables:{win32:["ArcheAge.exe"]},id:109,name:"ArcheAge"},{executables:{win32:["arma3.exe"]},id:110,name:"Arma III"},{executables:{win32:["AC3SP.exe"]},id:111,name:"Assassin's Creed 3"},{executables:{win32:["Bastion.exe"]},id:112,name:"Bastion"},{executables:{win32:["BF2.exe"]},id:113,name:"Battlefield 2"},{executables:{win32:["bf3.exe"]},id:114,name:"Battlefield 3"},{executables:{win32:["Besiege.exe"]},id:116,name:"Besiege"},{executables:{win32:["Bioshock.exe"]},id:117,name:"Bioshock"},{executables:{win32:["Bioshock2.exe"]},id:118,name:"BioShock II"},{executables:{win32:["BioShockInfinite.exe"]},id:119,name:"BioShock Infinite"},{executables:{win32:["Borderlands2.exe"]},id:122,name:"Borderlands 2"},{executables:{win32:["braid.exe"]},id:123,name:"Braid"},{executables:{win32:["ShippingPC-StormGame.exe"]},id:124,name:"Bulletstorm"},{executables:{},id:125,name:"Cabal 2"},{executables:{win32:["CabalMain.exe"]},id:126,name:"Cabal Online"},{executables:{win32:["iw4mp.exe","iw4sp.exe"]},id:127,name:"Call of Duty: Modern Warfare 2"},{executables:{win32:["t6sp.exe"]},id:128,name:"Call of Duty: Black Ops"},{executables:{win32:["iw5mp.exe"]},id:129,name:"Call of Duty: Modern Warfare 3"},{executables:{win32:["RelicCOH.exe"]},id:132,name:"Company of Heroes"},{executables:{win32:["Crysis64.exe"]},id:135,name:"Crysis"},{executables:{win32:["Crysis2.exe"]},id:136,name:"Crysis 2"},{executables:{win32:["Crysis3.exe"]},id:137,name:"Crysis 3"},{executables:{win32:["Crysis.exe"]},id:138,name:"Crysis 4 "},{executables:{win32:["DATA.exe"]},id:140,name:"Dark Souls"},{executables:{win32:["DarkSoulsII.exe"]},id:141,name:"Dark Souls II"},{executables:{win32:["dfuw.exe"]},id:142,name:"Darkfall: Unholy Wars"},{executables:{win32:["DCGAME.exe"]},id:144,name:"DC Universe Online"},{executables:{win32:["DeadIslandGame.exe"]},id:145,name:"Dead Island"},{executables:{win32:["deadspace2.exe"]},id:146,name:"Dead Space 2"},{executables:{win32:["LOTDGame.exe"]},id:147,name:"Deadlight"},{executables:{win32:["dxhr.exe"]},id:148,name:"Deus Ex: Human Revolution"},{executables:{win32:["DeviMayCry4.exe"]},id:149,name:"Devil May Cry 4"},{executables:{win32:["DMC-DevilMayCry.exe"]},id:150,name:"DmC Devil May Cry"},{executables:{win32:["dirt2_game.exe"]},id:154,name:"DiRT 2"},{executables:{win32:["dirt3_game.exe"]},id:155,name:"DiRT 3"},{executables:{win32:["dota.exe"]},id:156,name:"DOTA"},{executables:{win32:["DoubleDragon.exe"]},id:158,name:"Double Dragon Neon"},{executables:{win32:["DragonAge2.exe"]},id:159,name:"Dragon Age II"},{executables:{win32:["DragonAgeInquisition.exe"]},id:160,name:"Dragon Age: Inquisition"},{executables:{win32:["daorigins.exe"]},id:161,name:"Dragon Age: Origins"},{executables:{win32:["DBXV.exe"]},id:162,name:"Dragon Ball XenoVerse"},{executables:{win32:["DukeForever.exe"]},id:163,name:"Duke Nukem Forever"},{executables:{darwin:["Dustforce.app"],win32:["dustforce.exe"]},id:164,name:"Dustforce"},{executables:{win32:["EliteDangerous32.exe"]},id:165,name:"Elite: Dangerous"},{executables:{win32:["exefile.exe"]},id:166,name:"Eve Online"},{executables:{win32:["eqgame.exe"]},id:167,name:"EverQuest"},{executables:{win32:["EverQuest2.exe"]},id:168,name:"EverQuest II"},{executables:{},id:169,name:"EverQuest Next"},{executables:{win32:["Engine.exe"]},id:170,name:"F.E.A.R."},{executables:{win32:["FEAR2.exe"]},id:171,name:"F.E.A.R. 2: Project Origin"},{executables:{win32:["fallout3.exe"]},id:172,name:"Fallout 3"},{executables:{win32:["FalloutNV.exe"]},id:174,name:"Fallout: New Vegas"},{executables:{win32:["farcry3.exe"]},id:175,name:"Far Cry 3"},{executables:{win32:["fifa15.exe"]},id:176,name:"FIFA 15"},{executables:{win32:["FTLGame.exe"]},id:180,name:"FTL: Faster Than Light"},{executables:{win32:["GTAIV.exe"]},id:181,name:"Grand Theft Auto 4"},{executables:{win32:["GTA5.exe"]},id:182,name:"Grand Theft Auto 5"},{executables:{win32:["Gw.exe"]},id:183,name:"Guild Wars"},{executables:{win32:["H1Z1.exe"]},id:186,name:"H1Z1"},{executables:{win32:["HL2HL2.exe","hl2.exe"]},id:188,name:"Half Life 2"},{executables:{win32:["HOMEFRONT.exe"]},id:195,name:"Homefront"},{executables:{win32:["invisibleinc.exe"]},id:196,name:"Invisible Inc."},{executables:{win32:["LANoire.exe"]},id:197,name:"L.A. Noire"},{executables:{win32:["Landmark64.exe"]},id:198,name:"Landmark"},{executables:{win32:["left4dead2.exe"]},id:201,name:"Left 4 Dead 2"},{executables:{win32:["lineage.exe"]},id:203,name:"Lineage"},{executables:{win32:["Magicka.exe"]},id:206,name:"Magicka"},{executables:{win32:["MapleStory.exe"]},id:208,name:"MapleStory"},{executables:{},id:209,name:"Mark of the Ninja"},{executables:{win32:["MassEffect.exe"]},id:210,name:"Mass Effect"},{executables:{win32:["MassEffect2.exe"]},id:211,name:"Mass Effect 2"},{executables:{win32:["MassEffect3Demo.exe"]},id:212,name:"Mass Effect 3"},{executables:{win32:["METAL GEAR RISING REVENGEANCE.exe"]},id:214,name:"Metal Gear Rising: Revengeance"},{executables:{win32:["metro2033.exe"]},id:215,name:"Metro 2033"},{executables:{win32:["MetroLL.exe"]},id:216,name:"Metro Last Light"},{executables:{win32:["MK10.exe"]},id:218,name:"Mortal Kombat X"},{executables:{win32:["speed.exe"]},id:219,name:"Need For Speed Most Wanted"},{executables:{},id:220,name:"Neverwinder"},{executables:{darwin:["Outlast.app"],win32:["OLGame.exe"]},id:221,name:"Outlast"},{executables:{win32:["PapersPlease.exe"]},id:222,name:"Papers, Please"},{executables:{win32:["payday_win32_release.exe"]},id:223,name:"PAYDAY"},{executables:{win32:["payday2_win32_release.exe"]},id:224,name:"PAYDAY2"},{executables:{win32:["PillarsOfEternity.exe"]},id:225,name:"Pillars of Eternity"},{executables:{win32:["PA.exe"]},id:226,name:"Planetary Annihilation"},{executables:{win32:["planetside2_x86.exe"]},id:227,name:"Planetside 2"},{executables:{win32:["hl2P.exe"]},id:228,name:"Portal"},{executables:{win32:["portal2.exe"]},id:229,name:"Portal 2"},{executables:{win32:["PrimalCarnageGame.exe"]},id:231,name:"Primal Cargnage"},{executables:{win32:["pCARS.exe"]},id:232,name:"Project Cars"},{executables:{win32:["RaceTheSun.exe"]},id:233,name:"Race The Sun"},{executables:{win32:["Rage.exe"]},id:234,name:"RAGE"},{executables:{win32:["ragexe.exe"]},id:235,name:"Ragnarok Online"},{executables:{win32:["rift.exe"]},id:236,name:"Rift"},{executables:{win32:["Rocksmith2014.exe"]},id:237,name:"Rocksmith 2014"},{executables:{win32:["SwiftKit-RS.exe","JagexLauncher.exe"]},id:238,name:"RuneScape"},{executables:{win32:["Shadowgrounds.exe"]},id:239,name:"Shadowgrounds"},{executables:{win32:["survivor.exe"]},id:240,name:"Shadowgrounds: Survivor"},{executables:{win32:["ShovelKnight.exe"]},id:241,name:"Shovel Knight"},{executables:{win32:["SimCity.exe"]},id:242,name:"SimCity"},{executables:{win32:["SporeApp.exe"]},id:245,name:"Spore"},{executables:{win32:["StarCitizen.exe"]},id:246,name:"Star Citizen"},{executables:{},id:247,name:"Star Trek Online"},{executables:{win32:["battlefront.exe"]},id:248,name:"Star Wars Battlefront"},{executables:{win32:["swtor.exe"]},id:249,name:"Star Wars: The Old Republic"},{executables:{win32:["starbound.exe","starbound_opengl.exe"]},id:250,name:"Starbound"},{executables:{win32:["starcraft.exe"]},id:251,name:"Starcraft"},{executables:{win32:["SSFIV.exe"]},id:253,name:"Ultra Street Fighter IV"},{executables:{win32:["superhexagon.exe"]},id:254,name:"Super Hexagon"},{executables:{win32:["swordandsworcery_pc.exe"]},id:255,name:"Superbrothers: Sword & Sworcery EP"},{executables:{win32:["hl2TF.exe"]},id:256,name:"Team Fortress 2"},{executables:{win32:["TERA.exe"]},id:258,name:"TERA"},{executables:{win32:["Terraria.exe"]},id:259,name:"Terraria"},{executables:{win32:["Bethesda.net_Launcher.exe"]},id:260,name:"The Elder Scrolls Online"},{executables:{win32:["TESV.exe"]},id:261,name:"The Elder Scrolls V: Skyrim"},{executables:{win32:["TheSecretWorld.exe"]},id:262,name:"The Secret World"},{executables:{win32:["TS3.exe","ts3w.exe"]},id:264,name:"The Sims 3"},{executables:{win32:["WALKINGDEAD101.EXE"]},id:265,name:"The Walking Dead"},{executables:{win32:["TheWalkingDead2.exe"]},id:266,name:"The Walking Dead Season Two"},{executables:{win32:["witcher3.exe"]},id:267,name:"The Witcher 3"},{executables:{win32:["Future Soldier.exe"]},id:268,name:"Tom Clancy's Ghost Recon: Future Solider"},{executables:{win32:["TombRaider.exe"]},id:269,name:"Tomb Raider (2013)"},{executables:{win32:["Torchlight.exe"]},id:271,name:"Torchlight"},{executables:{win32:["Torchlight2.exe"]},id:272,name:"Torchlight 2"},{executables:{win32:["Shogun2.exe"]},id:273,name:"Total War: Shogun 2"},{executables:{win32:["Transistor.exe"]},id:274,name:"Transistor"},{executables:{win32:["trine.exe"]},id:275,name:"Trine"},{executables:{win32:["trine2_32bit.exe"]},id:276,name:"Trine 2"},{executables:{win32:["UOKR.exe"]},id:277,name:"Ultima Online"},{executables:{win32:["aces.exe"]},id:279,name:"War Thunder"},{executables:{win32:["Warcraft III.exe","wc3.exe"]},id:281,name:"Warcraft 3: Reign of Chaos"},{executables:{win32:["Warcraft II BNE.exe"]},id:282,name:"Warcraft II"},{executables:{win32:["Warframe.x64.exe","Warframe.exe"]},id:283,name:"Warframe"},{executables:{win32:["watch_dogs.exe"]},id:284,name:"Watch Dogs"},{executables:{win32:["WildStar64.exe"]},id:285,name:"WildStar"},{executables:{win32:["XComGame.exe"]},id:288,name:"XCOM: Enemy Unknown"},{executables:{win32:["DFO.exe","dfo.exe"]},id:289,name:"Dungeon Fighter Online"},{executables:{win32:["aclauncher.exe","acclient.exe"]},id:290,name:"Asheron's Call"},{executables:{win32:["MapleStory2.exe"]},id:291,name:"MapleStory 2"},{executables:{win32:["ksp.exe"]},id:292,name:"Kerbal Space Program"},{executables:{win32:["PINBALL.EXE"]},id:293,name:"3D Pinball: Space Cadet"},{executables:{win32:["dave.exe"]},id:294,name:"Dangerous Dave"},{executables:{win32:["iwbtgbeta(slomo).exe","iwbtgbeta(fs).exe"]},id:295,name:"I Wanna Be The Guy"},{executables:{win32:["MechWarriorOnline.exe "]},id:296,name:"Mech Warrior Online"},{executables:{win32:["dontstarve_steam.exe"]},id:297,name:"Don't Starve"},{executables:{win32:["GalCiv3.exe"]},id:298,name:"Galactic Civilization 3"},{executables:{win32:["Risk of Rain.exe"]},id:299, +name:"Risk of Rain"},{executables:{win32:["Binding_of_Isaac.exe","Isaac-ng.exe"]},id:300,name:"The Binding of Isaac"},{executables:{win32:["RustClient.exe"]},id:301,name:"Rust"},{executables:{win32:["Clicker Heroes.exe"]},id:302,name:"Clicker Heroes"},{executables:{win32:["Brawlhalla.exe"]},id:303,name:"Brawlhalla"},{executables:{win32:["TownOfSalem.exe"]},id:304,name:"Town of Salem"},{executables:{win32:["osu!.exe"]},id:305,name:"osu!"},{executables:{win32:["PathOfExileSteam.exe","PathOfExile.exe"]},id:306,name:"Path of Exile"},{executables:{win32:["Dolphin.exe"]},id:307,name:"Dolphin"},{executables:{win32:["RocketLeague.exe"]},id:308,name:"Rocket League"},{executables:{win32:["TJPP.exe"]},id:309,name:"Jackbox Party Pack"},{executables:{win32:["KFGame.exe"]},id:310,name:"Killing Floor 2"},{executables:{win32:["ShooterGame.exe"]},id:311,name:"Ark: Survival Evolved"},{executables:{win32:["LifeIsStrange.exe"]},id:312,name:"Life Is Strange"},{executables:{win32:["Client_tos.exe"]},id:313,name:"Tree of Savior"},{executables:{win32:["olliolli2.exe"]},id:314,name:"OlliOlli2"},{executables:{win32:["cw.exe"]},id:315,name:"Closers Dimension Conflict"},{executables:{win32:["ESSTEAM.exe","elsword.exe","x2.exe"]},id:316,name:"Elsword"},{executables:{win32:["ori.exe"]},id:317,name:"Ori and the Blind Forest"},{executables:{win32:["Skyforge.exe"]},id:318,name:"Skyforge"},{executables:{win32:["projectzomboid64.exe","projectzomboid32.exe"]},id:319,name:"Project Zomboid"},{executables:{win32:["From_The_Depths.exe"]},id:320,name:"The Depths"},{executables:{win32:["TheCrew.exe"]},id:321,name:"The Crew"},{executables:{win32:["MarvelHeroes2015.exe"]},id:322,name:"Marvel Heroes 2015"},{executables:{win32:["timeclickers.exe"]},id:324,name:"Time Clickers"},{executables:{win32:["eurotrucks2.exe"]},id:325,name:"Euro Truck Simulator 2"},{executables:{win32:["FarmingSimulator2015Game.exe"]},id:326,name:"Farming Simulator 15"},{executables:{win32:["strife.exe"]},id:327,name:"Strife"},{executables:{win32:["Awesomenauts.exe"]},id:328,name:"Awesomenauts"},{executables:{win32:["Dofus.exe"]},id:329,name:"Dofus"},{executables:{win32:["Boid.exe"]},id:330,name:"Boid"},{executables:{win32:["adventure-capitalist.exe"]},id:331,name:"AdVenture Capitalist"},{executables:{win32:["OrcsMustDie2.exe"]},id:332,name:"Orcs Must Die! 2"},{executables:{win32:["Mountain.exe"]},id:333,name:"Mountain"},{executables:{win32:["Valkyria.exe"]},id:335,name:"Valkyria Chronicles"},{executables:{win32:["ffxiiiimg.exe"]},id:336,name:"Final Fantasy XIII"},{executables:{win32:["TLR.exe"]},id:337,name:"The Last Remnant"},{executables:{win32:["Cities.exe"]},id:339,name:"Cities Skylines"},{executables:{win32:["worldofwarships.exe","WoWSLauncher.exe"]},id:341,name:"World of Warships"},{executables:{win32:["spacegame-Win64-shipping.exe"]},id:342,name:"Fractured Space"},{executables:{win32:["thespacegame.exe"]},id:343,name:"Ascent - The Space Game"},{executables:{win32:["DuckGame.exe"]},id:344,name:"Duck Game"},{executables:{win32:["PPSSPPWindows.exe"]},id:345,name:"PPSSPP"},{executables:{win32:["MBAA.exe"]},id:346,name:"Melty Blood Actress Again: Current Code"},{executables:{win32:["TheWolfAmongUs.exe"]},id:347,name:"The Wolf Among Us"},{executables:{win32:["SpaceEngineers.exe"]},id:348,name:"Space Engineers"},{executables:{win32:["Borderlands.exe"]},id:349,name:"Borderlands"},{executables:{win32:["100orange.exe"]},id:351,name:"100% Orange Juice"},{executables:{win32:["reflex.exe"]},id:354,name:"Reflex"},{executables:{win32:["pso2.exe"]},id:355,name:"Phantasy Star Online 2"},{executables:{win32:["AssettoCorsa.exe"]},id:356,name:"Assetto Corsa"},{executables:{win32:["iw3mp.exe","iw3sp.exe"]},id:357,name:"Call of Duty 4: Modern Warfare"},{executables:{win32:["WolfOldBlood_x64.exe"]},id:358,name:"Wolfenstein: The Old Blood"},{executables:{win32:["castle.exe"]},id:359,name:"Castle Crashers"},{executables:{win32:["vindictus.exe"]},id:360,name:"Vindictus"},{executables:{win32:["ShooterGame-Win32-Shipping.exe"]},id:361,name:"Dirty Bomb"},{executables:{win32:["BatmanAK.exe"]},id:362,name:"Batman Arkham Knight"},{executables:{win32:["drt.exe"]},id:363,name:"Dirt Rally"},{executables:{win32:["rFactor.exe"]},id:364,name:"rFactor"},{executables:{win32:["clonk.exe"]},id:365,name:"Clonk Rage"},{executables:{win32:["SRHK.exe"]},id:366,name:"Shadowrun: Hong Kong"},{executables:{win32:["Insurgency.exe"]},id:367,name:"Insurgency"},{executables:{win32:["StepMania.exe"]},id:368,name:"Step Mania"},{executables:{win32:["FirefallCLient.exe"]},id:369,name:"Firefall"},{executables:{win32:["mirrorsedge.exe"]},id:370,name:"Mirrors Edge"},{executables:{win32:["MgsGroundZeroes.exe"]},id:371,name:"Metal Gear Solid V: Ground Zeroes"},{executables:{win32:["mgsvtpp.exe"]},id:372,name:"Metal Gear Solid V: The Phantom Pain"},{executables:{win32:["tld.exe"]},id:373,name:"The Long Dark"},{executables:{win32:["TKOM.exe"]},id:374,name:"Take On Mars"},{executables:{win32:["robloxplayerlauncher.exe","Roblox.exe"]},id:375,name:"Roblox"},{executables:{win32:["eu4.exe"]},id:376,name:"Europa Universalis 4"},{executables:{win32:["APB.exe"]},id:377,name:"APB Reloaded"},{executables:{win32:["Robocraft.exe"]},id:378,name:"Robocraft"},{executables:{win32:["Unity.exe"]},id:379,name:"Unity"},{executables:{win32:["Simpsons.exe"]},id:380,name:"The Simpsons: Hit & Run"},{executables:{win32:["Dnlauncher.exe","DragonNest.exe"]},id:381,name:"Dragon Nest"},{executables:{win32:["Trove.exe"]},id:382,name:"Trove"},{executables:{win32:["EndlessLegend.exe"]},id:383,name:"Endless Legend"},{executables:{win32:["TurbineLauncher.exe","dndclient.exe"]},id:384,name:"Dungeons & Dragons Online"},{executables:{win32:["quakelive.exe","quakelive_steam.exe"]},id:385,name:"Quake Live"},{executables:{win32:["7DaysToDie.exe"]},id:386,name:"7DaysToDie"},{executables:{win32:["SpeedRunners.exe"]},id:387,name:"SpeedRunners"},{executables:{win32:["gamemd.exe"]},id:388,name:"Command & Conquer: Red Alert 2"},{executables:{win32:["generals.exe"]},id:389,name:"Command & Conquer Generals: Zero Hour"},{executables:{win32:["Oblivion.exe"]},id:390,name:"The Elder Scrolls 4: Oblivion"},{executables:{win32:["mgsi.exe"]},id:391,name:"Metal Gear Solid"},{executables:{win32:["EoCApp.exe"]},id:392,name:"Divinity - Original Sin"},{executables:{win32:["Torment.exe"]},id:393,name:"Planescape: Torment"},{executables:{win32:["HexPatch.exe"]},id:394,name:"Hex: Shards of Fate"},{executables:{win32:["NS3FB.exe"]},id:395,name:"Naruto Shippuden Ultimate Ninja Storm 3 Full Burst"},{executables:{win32:["NSUNSR.exe"]},id:396,name:"Naruto Shippuden Ultimate Ninja Storm Revolution"},{executables:{win32:["SaintsRowIV.exe"]},id:397,name:"Saints Row IV"},{executables:{win32:["Shadowrun.exe"]},id:398,name:"Shadowrun"},{executables:{win32:["DungeonoftheEndless.exe"]},id:399,name:"Dungeon of the Endless"},{executables:{win32:["Hon.exe"]},id:400,name:"Heroes of Newerth"},{executables:{win32:["mabinogi.exe"]},id:401,name:"Mabinogi"},{executables:{win32:["CoD2MP_s.exe","CoDSP_s.exe"]},id:402,name:"Call of Duty 2:"},{executables:{win32:["CoDWaWmp.exe","CoDWaw.exe"]},id:403,name:"Call of Duty: World at War"},{executables:{win32:["heroes.exe"]},id:404,name:"Mabinogi Heroes (Vindictus) "},{executables:{win32:["KanColleViewer.exe"]},id:405,name:"KanColle "},{executables:{win32:["cyphers.exe"]},id:406,name:"Cyphers"},{executables:{win32:["RelicCoH2.exe"]},id:407,name:"Company of Heroes 2"},{executables:{win32:["MJ.exe"]},id:408,name:"セガNET麻雀MJ"},{executables:{win32:["ge.exe"]},id:409,name:"Granado Espada"},{executables:{win32:["NovaRO.exe"]},id:410,name:"Nova Ragnarok Online"},{executables:{win32:["RivalsofAether.exe"]},id:411,name:"Rivals of Aether"},{executables:{win32:["bfh.exe"]},id:412,name:"Battlefield Hardline"},{executables:{win32:["GrowHome.exe"]},id:413,name:"Grow Home"},{executables:{win32:["patriots.exe"]},id:414,name:"Rise of Nations Extended"},{executables:{win32:["Railroads.exe"]},id:415,name:"Sid Meier's Railroads!"},{executables:{win32:["Empire.exe"]},id:416,name:"Empire: Total War"},{executables:{win32:["Napoleon.exe"]},id:417,name:"Napoleon: Total War"},{executables:{win32:["gta_sa.exe"]},id:418,name:"Grand Theft Auto: San Andreas"},{executables:{win32:["MadMax.exe"]},id:419,name:"Mad Max"},{executables:{win32:["Titanfall.exe"]},id:420,name:"Titanfall"},{executables:{win32:["age2_x1.exe"]},id:421,name:"Age of Empires II: The Conquerors"},{executables:{win32:["Rome2.exe"]},id:422,name:"Total War: ROME 2"},{executables:{win32:["ShadowOfMordor.exe"]},id:423,name:"Middle-earth: Shadow of Mordor"},{executables:{win32:["Subnautica.exe"]},id:424,name:"Subnautica"},{executables:{win32:["anno5.exe"]},id:425,name:"Anno 2070"},{executables:{win32:["carrier.exe"]},id:426,name:"Carrier Command Gaea Mission"},{executables:{win32:["DarksidersPC.exe"]},id:427,name:"Darksiders"},{executables:{win32:["Darksiders2.exe"]},id:428,name:"Darksiders 2"},{executables:{win32:["mudlet.exe"]},id:429,name:"Mudlet"},{executables:{win32:["DunDefLauncher.exe"]},id:430,name:"Dungeon Defenders II"},{executables:{win32:["hng.exe"]},id:431,name:"Heroes and Generals"},{executables:{win32:["WFTOGame.exe"]},id:432,name:"War of the Overworld"},{executables:{win32:["Talisman.exe"]},id:433,name:"Talisman: Digital Edition"},{executables:{win32:["limbo.exe"]},id:434,name:"Limbo"},{executables:{win32:["ibbobb.exe"]},id:435,name:"ibb & obb"},{executables:{win32:["BattleBlockTheater.exe"]},id:436,name:"BattleBlock Theater"},{executables:{win32:["iracinglauncher.exe","iracingsim.exe","iracingsim64.exe"]},id:437,name:"iRacing"},{executables:{win32:["CivilizationV_DX11.exe"]},id:438,name:"Civilization V"}]},{}]},{},[9])(9)}); \ No newline at end of file From 9662d52d4f20443bd7d9398345c82931d2e1937c Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 25 Oct 2015 19:41:40 +0000 Subject: [PATCH 148/151] Fixed 3.9.0 dist --- lib/index.js | 2 +- src/index.js | 24 ++++++++++++++++++++++++ web-dist/discord.3.9.0.js | 2 +- web-dist/discord.min.3.9.0.js | 4 ++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/index.js b/lib/index.js index 9eabba0ae..7dfb7d88a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1 +1 @@ -"use strict";var request=require("superagent");var Endpoints=require("./Endpoints.js");var Client=require("./Client.js");var Discord={Endpoints:Endpoints,Client:Client};module.exports = Discord; +"use strict";var request=require("superagent");var Endpoints=require("./Endpoints.js");var Client=require("./Client.js");var Discord={Endpoints:Endpoints,Client:Client};Discord.patchStrings = function(){defineProperty("bold","**");defineProperty("underline","__");defineProperty("strike","~~");defineProperty("code","`");defineProperty("codeblock","```");defineProperty("newline","\n");Object.defineProperty(String.prototype,"italic",{get:function get(){return "*" + this + "*";}});function defineProperty(name,joiner){Object.defineProperty(String.prototype,name,{get:function get(){return joiner + this + joiner;}});}};module.exports = Discord; diff --git a/src/index.js b/src/index.js index 28df53ed9..53d7be58e 100644 --- a/src/index.js +++ b/src/index.js @@ -7,4 +7,28 @@ var Discord = { Client : Client } +Discord.patchStrings = function () { + + defineProperty("bold", "**"); + defineProperty("underline", "__"); + defineProperty("strike", "~~"); + defineProperty("code", "`"); + defineProperty("codeblock", "```"); + defineProperty("newline", "\n"); + + Object.defineProperty(String.prototype, "italic", { + get: function () { + return "*" + this + "*"; + } + }); + + function defineProperty(name, joiner) { + Object.defineProperty(String.prototype, name, { + get: function () { + return joiner + this + joiner; + } + }); + } +} + module.exports = Discord; \ No newline at end of file diff --git a/web-dist/discord.3.9.0.js b/web-dist/discord.3.9.0.js index 34d47857f..3122c5739 100644 --- a/web-dist/discord.3.9.0.js +++ b/web-dist/discord.3.9.0.js @@ -103,7 +103,7 @@ basePerm=basePerms[0].packed;for(var _iterator5=basePerms,_isArray5=Array.isArra }Channel.prototype.permissionsOf = function permissionsOf(member){var mem=this.server.getMember("id",member.id);if(mem){return mem.permissionsIn(this);}else {return null;}};Channel.prototype.equals = function equals(object){return object && object.id === this.id;};Channel.prototype.addMessage = function addMessage(data){if(this.messages.length > 1000){this.messages.splice(0,1);}if(!this.getMessage("id",data.id)){this.messages.push(data);}return this.getMessage("id",data.id);};Channel.prototype.getMessage = function getMessage(key,value){for(var _iterator2=this.messages,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var message=_ref2;if(message[key] === value){return message;}}return null;};Channel.prototype.toString = function toString(){return "<#" + this.id + ">";};_createClass(Channel,[{key:"permissionOverwrites",get:function get(){return this.roles;}},{key:"permissions",get:function get(){return this.roles;}},{key:"client",get:function get(){return this.server.client;}},{key:"isPrivate",get:function get(){return false;}},{key:"users",get:function get(){return this.server.members;}},{key:"members",get:function get(){return this.server.members;}}]);return Channel;})();module.exports = Channel; },{"./ChannelPermissions.js":1}],9:[function(require,module,exports){ -"use strict";var request=require("superagent");var Endpoints=require("./Endpoints.js");var Client=require("./Client.js");var Discord={Endpoints:Endpoints,Client:Client};module.exports = Discord; +"use strict";var request=require("superagent");var Endpoints=require("./Endpoints.js");var Client=require("./Client.js");var Discord={Endpoints:Endpoints,Client:Client};Discord.patchStrings = function(){defineProperty("bold","**");defineProperty("underline","__");defineProperty("strike","~~");defineProperty("code","`");defineProperty("codeblock","```");defineProperty("newline","\n");Object.defineProperty(String.prototype,"italic",{get:function get(){return "*" + this + "*";}});function defineProperty(name,joiner){Object.defineProperty(String.prototype,name,{get:function get(){return joiner + this + joiner;}});}};module.exports = Discord; },{"./Client.js":2,"./Endpoints.js":3,"superagent":15}],10:[function(require,module,exports){ "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 Invite=(function(){function Invite(data,client){_classCallCheck(this,Invite);this.max_age = data.max_age;this.code = data.code;this.server = client.getServer("id",data.guild.id);this.revoked = data.revoked;this.created_at = Date.parse(data.created_at);this.temporary = data.temporary;this.uses = data.uses;this.max_uses = data.uses;this.inviter = client.addUser(data.inviter);this.xkcd = data.xkcdpass;this.channel = client.getChannel("id",data.channel.id);}_createClass(Invite,[{key:"URL",get:function get(){var code=this.xkcd?this.xkcdpass:this.code;return "https://discord.gg/" + code;}}]);return Invite;})();module.exports = Invite; diff --git a/web-dist/discord.min.3.9.0.js b/web-dist/discord.min.3.9.0.js index 0bd07e0a0..97652caf4 100644 --- a/web-dist/discord.min.3.9.0.js +++ b/web-dist/discord.min.3.9.0.js @@ -1,3 +1,3 @@ !function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Discord=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g>>a&1)},a.prototype.setBit=function(){},e(a,[{key:"createInstantInvite",get:function(){return this.getBit(0)},set:function(a){this.setBit(0,a)}},{key:"manageRoles",get:function(){return this.getBit(3)},set:function(a){this.setBit(3,a)}},{key:"manageChannels",get:function(){return this.getBit(4)},set:function(a){this.setBit(4,a)}},{key:"readMessages",get:function(){return this.getBit(10)},set:function(a){this.setBit(10,a)}},{key:"sendMessages",get:function(){return this.getBit(11)},set:function(a){this.setBit(11,a)}},{key:"sendTTSMessages",get:function(){return this.getBit(12)},set:function(a){this.setBit(12,a)}},{key:"manageMessages",get:function(){return this.getBit(13)},set:function(a){this.setBit(13,a)}},{key:"embedLinks",get:function(){return this.getBit(14)},set:function(a){this.setBit(14,a)}},{key:"attachFiles",get:function(){return this.getBit(15)},set:function(a){this.setBit(15,a)}},{key:"readMessageHistory",get:function(){return this.getBit(16)},set:function(a){this.setBit(16,a)}},{key:"mentionEveryone",get:function(){return this.getBit(17)},set:function(a){this.setBit(17,a)}},{key:"voiceConnect",get:function(){return this.getBit(20)},set:function(a){this.setBit(20,a)}},{key:"voiceSpeak",get:function(){return this.getBit(21)},set:function(a){this.setBit(21,a)}},{key:"voiceMuteMembers",get:function(){return this.getBit(22)},set:function(a){this.setBit(22,a)}},{key:"voiceDeafenMembers",get:function(){return this.getBit(23)},set:function(a){this.setBit(23,a)}},{key:"voiceMoveMembers",get:function(){return this.getBit(24)},set:function(a){this.setBit(24,a)}},{key:"voiceUseVoiceActivation",get:function(){return this.getBit(25)},set:function(a){this.setBit(25,a)}}]),a}();b.exports=f},{}],2:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c=k.length)break;n=k[m++]}else{if(m=k.next(),m.done)break;n=m.value}for(var o=n,p=[],q=o.mentions,r=Array.isArray(q),s=0,q=r?q:q[Symbol.iterator]();;){var t;if(r){if(s>=q.length)break;t=q[s++]}else{if(s=q.next(),s.done)break;t=s.value}var u=t;p.push(d.addUser(u))}var v=d.addUser(o.author);f.push(new j(o,i,p,v))}c(null,f),e(f)}})})},a.prototype.deleteChannel=function(a){var b=arguments.length<=1||void 0===arguments[1]?function(a){}:arguments[1],c=this;return new Promise(function(d,e){var g=a;a instanceof i&&(g=a.id),n.del(f.CHANNELS+"/"+g).set("authorization",c.token).end(function(a){a?(b(a),e(a)):(b(null),d())})})},a.prototype.joinServer=function(a){var b=arguments.length<=1||void 0===arguments[1]?function(a,b){}:arguments[1],c=this;return new Promise(function(d,e){var g=a instanceof k?a.code:a;n.post(f.API+"/invite/"+g).set("authorization",c.token).end(function(a,f){a?(b(a),e(a)):c.getServer("id",f.body.guild.id)?d(c.getServer("id",f.body.guild.id)):c.serverCreateListener[f.body.guild.id]=[d,b]})})},a.prototype.sendFile=function(a,b){var c=arguments.length<=2||void 0===arguments[2]?"image.png":arguments[2],d=arguments.length<=3||void 0===arguments[3]?function(a,b){}:arguments[3],e=this,f=new Promise(function(g,h){function i(a){e.options.queue?(e.queue[a]||(e.queue[a]=[]),e.queue[a].push({action:"sendFile",attachment:l,attachmentName:c,then:j,error:k}),e.checkQueue(a)):e._sendFile(a,l,c).then(j)["catch"](k)}function j(a){f.message=a,d(null,a),g(a)}function k(a){f.error=a,d(a),h(a)}var l;"string"==typeof b||b instanceof String?(l=p.createReadStream(b),c=b):l=b,e.resolveDestination(a).then(i)["catch"](k)});return f},a.prototype.sendMessage=function(a,b,c){var d=arguments.length<=3||void 0===arguments[3]?function(a,b){}:arguments[3],e=arguments.length<=4||void 0===arguments[4]?"":arguments[4],f=this,g=new Promise(function(h,i){function j(a){d(a),i(a)}function k(a){f.options.queue?(f.queue[a]||(f.queue[a]=[]),f.queue[a].push({action:"sendMessage",content:b,mentions:p,tts:!!c,then:l,error:m}),f.checkQueue(a)):f._sendMessage(a,b,c,p).then(l)["catch"](m)}function l(a){g.message=a,d(null,a),h(a)}function m(a){g.error=a,d(a),i(a)}function n(){var a=b;return b instanceof Array&&(a=b.join("\n")),a}function o(){for(var a=[],c=b.match(/<@[^>]*>/g)||[],d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;a.push(g.substring(2,g.length-1))}return a}"function"==typeof c&&(d=c,c=!1),b=e+n(b);var p=o();f.resolveDestination(a).then(k)["catch"](j)});return g},a.prototype.createws=function(a){if(this.websocket)return!1;var b=this;this.websocket=new o(a),this.websocket.onopen=function(){b.trySendConnData()},this.websocket.onclose=function(){b.trigger("disconnected")},this.websocket.onmessage=function(a){var c=!1,d={};try{c=JSON.parse(a.data),d=c.d}catch(e){return void b.trigger("error",e,a)}switch(b.trigger("raw",c),c.t){case"READY":b.debug("received ready packet"),b.user=b.addUser(d.user);for(var f=d.guilds,h=Array.isArray(f),k=0,f=h?f:f[Symbol.iterator]();;){var l;if(h){if(k>=f.length)break;l=f[k++]}else{if(k=f.next(),k.done)break;l=k.value}var m=l,n=b.addServer(m)}for(var o=d.private_channels,p=Array.isArray(o),q=0,o=p?o:o[Symbol.iterator]();;){var r;if(p){if(q>=o.length)break;r=o[q++]}else{if(q=o.next(),q.done)break;r=q.value}var s=r;b.addPMChannel(s)}b.trigger("ready"),b.readyTime=Date.now(),b.debug("cached "+b.serverCache.length+" servers, "+b.channelCache.length+" channels, "+b.pmChannelCache.length+" PMs and "+b.userCache.length+" users."),b.state=3,setInterval(function(){b.keepAlive.apply(b)},d.heartbeat_interval);break;case"MESSAGE_CREATE":b.debug("received message");var t=[];d.mentions=d.mentions||[];for(var u=d.mentions,v=Array.isArray(u),w=0,u=v?u:u[Symbol.iterator]();;){var x;if(v){if(w>=u.length)break;x=u[w++]}else{if(w=u.next(),w.done)break;x=w.value}var y=x;t.push(b.addUser(y))}var z=b.getChannel("id",d.channel_id);if(z){var A=z.addMessage(new j(d,z,t,b.addUser(d.author)));b.trigger("message",A)}break;case"MESSAGE_DELETE":b.debug("message deleted");var z=b.getChannel("id",d.channel_id),B=z.getMessage("id",d.id);B?(b.trigger("messageDelete",z,B),z.messages.splice(z.messages.indexOf(B),1)):b.trigger("messageDelete",z);break;case"MESSAGE_UPDATE":b.debug("message updated");var z=b.getChannel("id",d.channel_id),C=z.getMessage("id",d.id);if(C){var D={};for(var E in C)D[E]=C[E];for(var E in d)D[E]=d[E];for(var t=[],F=D.mentions,G=Array.isArray(F),H=0,F=G?F:F[Symbol.iterator]();;){var I;if(G){if(H>=F.length)break;I=F[H++]}else{if(H=F.next(),H.done)break;I=H.value}var y=I;t.push(b.addUser(y))}var J=new j(D,z,t,C.author);b.trigger("messageUpdate",J,C),z.messages[z.messages.indexOf(C)]=J}break;case"GUILD_DELETE":var n=b.getServer("id",d.id);n&&(b.serverCache.splice(b.serverCache.indexOf(n),1),b.trigger("serverDelete",n));break;case"CHANNEL_DELETE":var z=b.getChannel("id",d.id);if(z){var n=z.server;n&&n.channels.splice(n.channels.indexOf(z),1),b.trigger("channelDelete",z),b.serverCache.splice(b.serverCache.indexOf(z),1)}break;case"GUILD_CREATE":var n=b.getServer("id",d.id);if(n||(n=b.addServer(d)),b.serverCreateListener[d.id]){var K=b.serverCreateListener[d.id];K[0](n),K[1](null,n),b.serverCreateListener[d.id]=null}b.trigger("serverCreate",n);break;case"CHANNEL_CREATE":var z=b.getChannel("id",d.id);if(!z){var L;L=d.is_private?b.addPMChannel(d):b.addChannel(d,d.guild_id);var M=b.getServer("id",d.guild_id);M&&M.addChannel(L),b.trigger("channelCreate",L)}break;case"GUILD_MEMBER_ADD":var n=b.getServer("id",d.guild_id);if(n){var N=b.addUser(d.user);b.trigger("serverNewMember",n.addMember(N,d.roles),n)}break;case"GUILD_MEMBER_REMOVE":var n=b.getServer("id",d.guild_id);if(n){var N=b.addUser(d.user);n.removeMember("id",N.id),b.trigger("serverRemoveMember",N,n)}break;case"USER_UPDATE":if(b.user&&d.id===b.user.id){var O=new g(d);b.trigger("userUpdate",O,b.user),~b.userCache.indexOf(b.user)&&(b.userCache[b.userCache.indexOf(b.user)]=O),b.user=O}break;case"PRESENCE_UPDATE":var P=b.getUser("id",d.user.id);if(P){d.user.username=d.user.username||P.username,d.user.id=d.user.id||P.id,d.user.discriminator=d.user.discriminator||P.discriminator,d.user.avatar=d.user.avatar||P.avatar;var Q=new g(d.user);Q.equalsStrict(P)?(b.trigger("presence",{user:P,oldStatus:P.status,status:d.status,server:b.getServer("id",d.guild_id),gameId:d.game_id}),P.status=d.status,P.gameId=d.game_id):(b.userCache[b.userCache.indexOf(P)]=Q,b.trigger("userUpdate",P,Q))}break;case"CHANNEL_UPDATE":var R=b.getChannel("id",d.id),S=b.getServer("id",d.guild_id);if(R&&S){var T=new i(d,S);T.messages=R.messages,b.trigger("channelUpdate",R,T),b.channelCache[b.channelCache.indexOf(R)]=T}break;case"TYPING_START":var P=b.getUser("id",d.user_id),R=b.getChannel("id",d.channel_id);b.userTypingListener[d.user_id]&&-1!==b.userTypingListener[d.user_id]||b.trigger("startTyping",P,R),b.userTypingListener[d.user_id]=Date.now(),setTimeout(function(){-1!==b.userTypingListener[d.user_id]&&Date.now()-b.userTypingListener[d.user_id]>6e3&&(b.trigger("stopTyping",P,R),b.userTypingListener[d.user_id]=-1)},6e3);break;case"GUILD_ROLE_DELETE":var n=b.getServer("id",d.guild_id),U=n.getRole(d.role_id);b.trigger("serverRoleDelete",n,U),n.removeRole(U.id);break;case"GUILD_ROLE_UPDATE":var n=b.getServer("id",d.guild_id),U=n.getRole(d.role.id),V=n.updateRole(d.role);b.trigger("serverRoleUpdate",n,U,V);break;default:b.debug("received unknown packet"),b.trigger("unknown",c)}}},a.prototype.addUser=function(a){return this.getUser("id",a.id)||this.userCache.push(new g(a)),this.getUser("id",a.id)},a.prototype.addChannel=function(a,b){return this.getChannel("id",a.id)||this.channelCache.push(new i(a,this.getServer("id",b))),this.getChannel("id",a.id)},a.prototype.addPMChannel=function(a){return this.getPMChannel("id",a.id)||this.pmChannelCache.push(new l(a,this)),this.getPMChannel("id",a.id)},a.prototype.setTopic=function(a,b){var c=arguments.length<=2||void 0===arguments[2]?function(a){}:arguments[2],d=this;return new Promise(function(e,g){function h(a){c(a),g(a)}function i(a){var g=d.getChannel("id",a);n.patch(f.CHANNELS+"/"+a).set("authorization",d.token).send({name:g.name,position:0,topic:b}).end(function(a,b){a?h(a):(g.topic=b.body.topic,e(),c())})}d.resolveDestination(a).then(i)["catch"](h)})},a.prototype.addServer=function(a){var b=this,c=this.getServer("id",a.id);if(a.unavailable)return b.trigger("unavailable",a),void b.debug("Server ID "+a.id+" has been marked unavailable by Discord. It was not cached.");if(!c&&(c=new h(a,this),this.serverCache.push(c),a.channels))for(var d=a.channels,e=Array.isArray(d),f=0,d=e?d:d[Symbol.iterator]();;){var g;if(e){if(f>=d.length)break;g=d[f++]}else{if(f=d.next(),f.done)break;g=f.value}var i=g;c.channels.push(this.addChannel(i,c.id))}for(var j=a.presences,k=Array.isArray(j),l=0,j=k?j:j[Symbol.iterator]();;){var m;if(k){if(l>=j.length)break;m=j[l++]}else{if(l=j.next(),l.done)break;m=l.value}var n=m,o=b.getUser("id",n.user.id);o.status=n.status,o.gameId=n.game_id}return c},a.prototype.getUser=function(a,b){for(var c=this.userCache,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.getChannel=function(a,b){for(var c=this.channelCache,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return this.getPMChannel(a,b)},a.prototype.getPMChannel=function(a,b){for(var c=this.pmChannelCache,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.getServer=function(a,b){for(var c=this.serverCache,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.trySendConnData=function(){if(this.token&&!this.alreadySentData){this.alreadySentData=!0;var a={op:2,d:{token:this.token,v:3,properties:{$os:"discord.js",$browser:"discord.js",$device:"discord.js",$referrer:"",$referring_domain:""}}};this.websocket.send(JSON.stringify(a))}},a.prototype.resolveServerID=function(a){return a instanceof h?a.id:!isNaN(a)&&a.length&&17===a.length?a:void 0},a.prototype.resolveDestination=function(a){var b=!1,c=this;return new Promise(function(d,e){if(a instanceof h)b=a.id;else if(a instanceof i)b=a.id;else if(a instanceof j)b=a.channel.id;else if(a instanceof l)b=a.id;else if(a instanceof g){for(var f=c.pmChannelCache,k=Array.isArray(f),m=0,f=k?f:f[Symbol.iterator]();;){var n;if(k){if(m>=f.length)break;n=f[m++]}else{if(m=f.next(),m.done)break;n=m.value}var o=n;if(o.user&&o.user.equals(a))return void d(o.id)}c.startPM(a).then(function(a){d(a.id)})["catch"](e)}else b=a;b?d(b):e()})},a.prototype._sendMessage=function(a,b,c,d){var e=this;return new Promise(function(g,h){n.post(f.CHANNELS+"/"+a+"/messages").set("authorization",e.token).send({content:b,mentions:d,tts:c}).end(function(a,b){if(a)h(a);else{var c=b.body,d=[];c.mentions=c.mentions||[];for(var f=c.mentions,i=Array.isArray(f),k=0,f=i?f:f[Symbol.iterator]();;){var l;if(i){if(k>=f.length)break;l=f[k++]}else{if(k=f.next(),k.done)break;l=k.value}var m=l;d.push(e.addUser(m))}var n=e.getChannel("id",c.channel_id);if(n){var o=n.addMessage(new j(c,n,d,e.addUser(c.author)));g(o)}}})})},a.prototype._sendFile=function(a,b){var c=arguments.length<=2||void 0===arguments[2]?"DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png":arguments[2],d=this;return new Promise(function(e,g){n.post(f.CHANNELS+"/"+a+"/messages").set("authorization",d.token).attach("file",b,c).end(function(b,c){if(b)g(b);else{var f=d.getChannel("id",a);if(f){var h=f.addMessage(new j(c.body,f,[],d.user));e(h)}}})})},a.prototype._updateMessage=function(a,b){var c=this;return new Promise(function(d,e){n.patch(f.CHANNELS+"/"+a.channel.id+"/messages/"+a.id).set("authorization",c.token).send({content:b,mentions:[]}).end(function(b,c){if(b)e(b);else{var f=new j(c.body,a.channel,a.mentions,a.sender);d(f),a.channel.messages[a.channel.messages.indexOf(a)]=f}})})},a.prototype.getGateway=function(){var a=this;return new Promise(function(b,c){n.get(f.API+"/gateway").set("authorization",a.token).end(function(a,d){a?c(a):b(d.body.url)})})},a.prototype.setStatusIdle=function(){this.setStatus("idle")},a.prototype.setStatusOnline=function(){this.setStatus("online")},a.prototype.setStatusActive=function(){this.setStatusOnline()},a.prototype.setStatusHere=function(){this.setStatusOnline()},a.prototype.setStatusAway=function(){this.setStatusIdle()},a.prototype.startTyping=function(a,b){function c(a){if(!d.typingIntervals[a]){var c=function(){n.post(f.CHANNELS+"/"+a+"/typing").set("authorization",d.token).end()};c();var e=setInterval(c,3e3);d.typingIntervals[a]=e,b&&setTimeout(function(){d.stopTyping(a)},b)}}var d=this;this.resolveDestination(a).then(c)},a.prototype.stopTyping=function(a){function b(a){c.typingIntervals[a]&&(clearInterval(c.typingIntervals[a]),delete c.typingIntervals[a])}var c=this;this.resolveDestination(a).then(b)},a.prototype.setStatus=function(a){var b="online"===a?null:Date.now();this.__idleTime=b,this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}))},a.prototype.setPlayingGame=function(a){if(a instanceof String||"string"==typeof a){var b=a.trim().toUpperCase();a=null;for(var c=m,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g.name.trim().toUpperCase()===b){a=g.id;break}}}this.__gameId=a,this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}))},a.prototype.playGame=function(a){this.setPlayingGame(a)},a.prototype.playingGame=function(a){this.setPlayingGame(a)},e(a,[{key:"uptime",get:function(){return this.readyTime?Date.now()-this.readyTime:null}},{key:"ready",get:function(){return 3===this.state}},{key:"servers",get:function(){return this.serverCache}},{key:"channels",get:function(){return this.channelCache}},{key:"users",get:function(){return this.userCache}},{key:"PMChannels",get:function(){return this.pmChannelCache}},{key:"messages",get:function(){for(var a=[],b=this.channelCache,c=Array.isArray(b),d=0,b=c?b:b[Symbol.iterator]();;){var e;if(c){if(d>=b.length)break;e=b[d++]}else{if(d=b.next(),d.done)break;e=d.value}var f=e;a=a.concat(f.messages)}return a}}]),a}();b.exports=r},{"../ref/gameMap.json":19,"./Endpoints.js":3,"./PMChannel.js":6,"./channel.js":8,"./invite.js":10,"./message.js":11,"./server.js":12,"./user.js":13,fs:14,superagent:15,ws:18}],3:[function(a,b,c){"use strict";c.BASE_DOMAIN="discordapp.com",c.BASE="https://"+c.BASE_DOMAIN,c.WEBSOCKET_HUB="wss://"+c.BASE_DOMAIN+"/hub",c.API=c.BASE+"/api",c.AUTH=c.API+"/auth",c.LOGIN=c.AUTH+"/login",c.LOGOUT=c.AUTH+"/logout",c.USERS=c.API+"/users",c.SERVERS=c.API+"/guilds",c.CHANNELS=c.API+"/channels"},{}],4:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c>>a&1)},a.prototype.setBit=function(){},e(a,[{key:"createInstantInvite",get:function(){return this.getBit(0)},set:function(a){this.setBit(0,a)}},{key:"manageRoles",get:function(){return this.getBit(3)},set:function(a){this.setBit(3,a)}},{key:"manageChannels",get:function(){return this.getBit(4)},set:function(a){this.setBit(4,a)}},{key:"readMessages",get:function(){return this.getBit(10)},set:function(a){this.setBit(10,a)}},{key:"sendMessages",get:function(){return this.getBit(11)},set:function(a){this.setBit(11,a)}},{key:"sendTTSMessages",get:function(){return this.getBit(12)},set:function(a){this.setBit(12,a)}},{key:"manageMessages",get:function(){return this.getBit(13)},set:function(a){this.setBit(13,a)}},{key:"embedLinks",get:function(){return this.getBit(14)},set:function(a){this.setBit(14,a)}},{key:"attachFiles",get:function(){return this.getBit(15)},set:function(a){this.setBit(15,a)}},{key:"readMessageHistory",get:function(){return this.getBit(16)},set:function(a){this.setBit(16,a)}},{key:"mentionEveryone",get:function(){return this.getBit(17)},set:function(a){this.setBit(17,a)}},{key:"voiceConnect",get:function(){return this.getBit(20)},set:function(a){this.setBit(20,a)}},{key:"voiceSpeak",get:function(){return this.getBit(21)},set:function(a){this.setBit(21,a)}},{key:"voiceMuteMembers",get:function(){return this.getBit(22)},set:function(a){this.setBit(22,a)}},{key:"voiceDeafenMembers",get:function(){return this.getBit(23)},set:function(a){this.setBit(23,a)}},{key:"voiceMoveMembers",get:function(){return this.getBit(24)},set:function(a){this.setBit(24,a)}},{key:"voiceUseVoiceActivation",get:function(){return this.getBit(25)},set:function(a){this.setBit(25,a)}}]),a}();b.exports=f},{}],5:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function e(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(Object.setPrototypeOf?Object.setPrototypeOf(a,b):a.__proto__=b)}var f=function(){function a(a,b){for(var c=0;c=d.length)break;g=d[f++]}else{if(f=d.next(),f.done)break;g=f.value}var h=g;h.id===this.id&&"member"===h.type?c.push(h):-1!==this.rawRoles.indexOf(h.id)&&b.push(h)}if(0===b.length&&0===c.length)return new i(this.evalPerms.packed);for(var j=0!==b.length?b[0].packed:c[0].packed,k=b,l=Array.isArray(k),m=0,k=l?k:k[Symbol.iterator]();;){var n;if(l){if(m>=k.length)break;n=k[m++]}else{if(m=k.next(),m.done)break;n=m.value}var h=n;j&=~h.deny,j|=h.allow}for(var o=c,p=Array.isArray(o),q=0,o=p?o:o[Symbol.iterator]();;){var r;if(p){if(q>=o.length)break;r=o[q++]}else{if(q=o.next(),q.done)break;r=q.value}var h=r;j&=~h.deny,j|=h.allow}return new i(j)},f(b,[{key:"roles",get:function(){for(var a=[this.server.getRole(this.server.id)],b=this.rawRoles,c=Array.isArray(b),d=0,b=c?b:b[Symbol.iterator]();;){var e;if(c){if(d>=b.length)break;e=b[d++]}else{if(d=b.next(),d.done)break;e=d.value}var f=e;a.push(this.server.getRole(f))}return a}},{key:"evalPerms",get:function(){for(var a=this.roles,b=a[0].packed,c=a,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;b|=g.packed}return new h({permissions:b})}}]),b}(g);b.exports=j},{"./EvaluatedPermissions.js":4,"./ServerPermissions.js":7,"./user.js":13}],6:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c1e3&&this.messages.splice(0,1);for(var c=this.messages,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},e(a,[{key:"isPrivate",get:function(){return!0}}]),a}();b.exports=f},{}],7:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c>>a&1)},a.prototype.setBit=function(){},a.prototype.toString=function(){return this.name},e(a,[{key:"createInstantInvite",get:function(){return this.getBit(0)},set:function(a){this.setBit(0,a)}},{key:"banMembers",get:function(){return this.getBit(1)},set:function(a){this.setBit(1,a)}},{key:"kickMembers",get:function(){return this.getBit(2)},set:function(a){this.setBit(2,a)}},{key:"manageRoles",get:function(){return this.getBit(3)},set:function(a){this.setBit(3,a)}},{key:"manageChannels",get:function(){return this.getBit(4)},set:function(a){this.setBit(4,a); -}},{key:"manageServer",get:function(){return this.getBit(5)},set:function(a){this.setBit(5,a)}},{key:"readMessages",get:function(){return this.getBit(10)},set:function(a){this.setBit(10,a)}},{key:"sendMessages",get:function(){return this.getBit(11)},set:function(a){this.setBit(11,a)}},{key:"sendTTSMessages",get:function(){return this.getBit(12)},set:function(a){this.setBit(12,a)}},{key:"manageMessages",get:function(){return this.getBit(13)},set:function(a){this.setBit(13,a)}},{key:"embedLinks",get:function(){return this.getBit(14)},set:function(a){this.setBit(14,a)}},{key:"attachFiles",get:function(){return this.getBit(15)},set:function(a){this.setBit(15,a)}},{key:"readMessageHistory",get:function(){return this.getBit(16)},set:function(a){this.setBit(16,a)}},{key:"mentionEveryone",get:function(){return this.getBit(17)},set:function(a){this.setBit(17,a)}},{key:"voiceConnect",get:function(){return this.getBit(20)},set:function(a){this.setBit(20,a)}},{key:"voiceSpeak",get:function(){return this.getBit(21)},set:function(a){this.setBit(21,a)}},{key:"voiceMuteMembers",get:function(){return this.getBit(22)},set:function(a){this.setBit(22,a)}},{key:"voiceDeafenMembers",get:function(){return this.getBit(23)},set:function(a){this.setBit(23,a)}},{key:"voiceMoveMembers",get:function(){return this.getBit(24)},set:function(a){this.setBit(24,a)}},{key:"voiceUseVoiceActivation",get:function(){return this.getBit(25)},set:function(a){this.setBit(25,a)}}]),a}();b.exports=f},{}],8:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c=e.length)break;i=e[h++]}else{if(h=e.next(),h.done)break;i=h.value}var j=i;this.roles.push(new f(j,this))}}return a.prototype.permissionsOf=function(a){var b=this.server.getMember("id",a.id);return b?b.permissionsIn(this):null},a.prototype.equals=function(a){return a&&a.id===this.id},a.prototype.addMessage=function(a){return this.messages.length>1e3&&this.messages.splice(0,1),this.getMessage("id",a.id)||this.messages.push(a),this.getMessage("id",a.id)},a.prototype.getMessage=function(a,b){for(var c=this.messages,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.toString=function(){return"<#"+this.id+">"},e(a,[{key:"permissionOverwrites",get:function(){return this.roles}},{key:"permissions",get:function(){return this.roles}},{key:"client",get:function(){return this.server.client}},{key:"isPrivate",get:function(){return!1}},{key:"users",get:function(){return this.server.members}},{key:"members",get:function(){return this.server.members}}]),a}();b.exports=g},{"./ChannelPermissions.js":1}],9:[function(a,b,c){"use strict";var d=(a("superagent"),a("./Endpoints.js")),e=a("./Client.js"),f={Endpoints:d,Client:e};b.exports=f},{"./Client.js":2,"./Endpoints.js":3,superagent:15}],10:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g.id===b)return!0}return!1},e(a,[{key:"sender",get:function(){return this.author}},{key:"isPrivate",get:function(){return this.channel.isPrivate}}]),a}());b.exports=f},{"./PMChannel.js":6}],12:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c=e.length)break;i=e[h++]}else{if(h=e.next(),h.done)break;i=h.value}var j=i;this.roles.push(new f(j))}if(!b.members)return void(b.members=[c.user]);for(var k=b.members,l=Array.isArray(k),m=0,k=l?k:k[Symbol.iterator]();;){var n;if(l){if(m>=k.length)break;n=k[m++]}else{if(m=k.next(),m.done)break;n=m.value}var o=n;o.user&&this.addMember(c.addUser(o.user),o.roles)}}return a.prototype.getRole=function(a){for(var b=this.roles,c=Array.isArray(b),d=0,b=c?b:b[Symbol.iterator]();;){var e;if(c){if(d>=b.length)break;e=b[d++]}else{if(d=b.next(),d.done)break;e=d.value}var f=e;if(f.id===a)return f}return null},a.prototype.updateRole=function(a){var b=this.getRole(a.id);if(b){var c=this.roles.indexOf(b);return this.roles[c]=new f(a),this.roles[c]}return!1},a.prototype.removeRole=function(a){for(var b in this.roles)this.roles[b].id===a&&this.roles.splice(b,1);for(var c=this.members,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;for(var b in g.rawRoles)g.rawRoles[b]===a&&g.rawRoles.splice(b,1)}},a.prototype.getChannel=function(a,b){for(var c=this.channels,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.getMember=function(a,b){for(var c=this.members,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.removeMember=function(a,b){for(var c=this.members,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return this.members.splice(a,1),g}return!1},a.prototype.addChannel=function(a){return this.getChannel("id",a.id)||this.channels.push(a),a},a.prototype.addMember=function(a,b){if(!this.getMember("id",a.id)){var c=new g(a,this,b);this.members.push(c)}return c},a.prototype.toString=function(){return this.name},a.prototype.equals=function(a){return a.id===this.id},e(a,[{key:"permissionGroups",get:function(){return this.roles}},{key:"permissions",get:function(){return this.roles}},{key:"iconURL",get:function(){return this.icon?"https://discordapp.com/api/guilds/"+this.id+"/icons/"+this.icon+".jpg":null}},{key:"afkChannel",get:function(){return this.afkChannelId?this.getChannel("id",this.afkChannelId):!1}},{key:"defaultChannel",get:function(){return this.getChannel("name","general")}},{key:"owner",get:function(){return this.client.getUser("id",this.ownerID)}},{key:"users",get:function(){return this.members}}]),a}();b.exports=h},{"./Member.js":5,"./ServerPermissions.js":7}],13:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c"},a.prototype.toString=function(){return this.mention()},a.prototype.equals=function(a){return a.id===this.id},a.prototype.equalsStrict=function(a){return a.id===this.id&&a.avatar===this.avatar&&a.username===this.username&&a.discriminator===this.discriminator},e(a,[{key:"avatarURL",get:function(){return this.avatar?"https://discordapp.com/api/users/"+this.id+"/avatars/"+this.avatar+".jpg":null}}]),a}();b.exports=f},{}],14:[function(a,b,c){},{}],15:[function(a,b,c){function d(){}function e(a){var b={}.toString.call(a);switch(b){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function f(a){return a===Object(a)}function g(a){if(!f(a))return a;var b=[];for(var c in a)null!=a[c]&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")}function h(a){for(var b,c,d={},e=a.split("&"),f=0,g=e.length;g>f;++f)c=e[f],b=c.split("="),d[decodeURIComponent(b[0])]=decodeURIComponent(b[1]);return d}function i(a){var b,c,d,e,f=a.split(/\r?\n/),g={};f.pop();for(var h=0,i=f.length;i>h;++h)c=f[h],b=c.indexOf(":"),d=c.slice(0,b).toLowerCase(),e=r(c.slice(b+1)),g[d]=e;return g}function j(a){return a.split(/ *; */).shift()}function k(a){return q(a.split(/ *; */),function(a,b){var c=b.split(/ *= */),d=c.shift(),e=c.shift();return d&&e&&(a[d]=e),a},{})}function l(a,b){b=b||{},this.req=a,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||"undefined"==typeof this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText,this.setStatusProperties(this.xhr.status),this.header=this.headers=i(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body="HEAD"!=this.req.method?this.parseBody(this.text?this.text:this.xhr.response):null}function m(a,b){var c=this;p.call(this),this._query=this._query||[],this.method=a,this.url=b,this.header={},this._header={},this.on("end",function(){var a=null,b=null;try{b=new l(c)}catch(d){return a=new Error("Parser is unable to parse the response"),a.parse=!0,a.original=d,c.callback(a)}if(c.emit("response",b),a)return c.callback(a,b);if(b.status>=200&&b.status<300)return c.callback(a,b);var e=new Error(b.statusText||"Unsuccessful HTTP response");e.original=a,e.response=b,e.status=b.status,c.callback(e,b)})}function n(a,b){return"function"==typeof b?new m("GET",a).end(b):1==arguments.length?new m("GET",a):new m(a,b)}var o,p=a("emitter"),q=a("reduce");o="undefined"!=typeof window?window:"undefined"!=typeof self?self:this,n.getXHR=function(){if(!(!o.XMLHttpRequest||o.location&&"file:"==o.location.protocol&&o.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(a){}return!1};var r="".trim?function(a){return a.trim()}:function(a){return a.replace(/(^\s*|\s*$)/g,"")};n.serializeObject=g,n.parseString=h,n.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},n.serialize={"application/x-www-form-urlencoded":g,"application/json":JSON.stringify},n.parse={"application/x-www-form-urlencoded":h,"application/json":JSON.parse},l.prototype.get=function(a){return this.header[a.toLowerCase()]},l.prototype.setHeaderProperties=function(a){var b=this.header["content-type"]||"";this.type=j(b);var c=k(b);for(var d in c)this[d]=c[d]},l.prototype.parse=function(a){return this.parser=a,this},l.prototype.parseBody=function(a){var b=this.parser||n.parse[this.type];return b&&a&&(a.length||a instanceof Object)?b(a):null},l.prototype.setStatusProperties=function(a){1223===a&&(a=204);var b=a/100|0;this.status=this.statusCode=a,this.statusType=b,this.info=1==b,this.ok=2==b,this.clientError=4==b,this.serverError=5==b,this.error=4==b||5==b?this.toError():!1,this.accepted=202==a,this.noContent=204==a,this.badRequest=400==a,this.unauthorized=401==a,this.notAcceptable=406==a,this.notFound=404==a,this.forbidden=403==a},l.prototype.toError=function(){var a=this.req,b=a.method,c=a.url,d="cannot "+b+" "+c+" ("+this.status+")",e=new Error(d);return e.status=this.status,e.method=b,e.url=c,e},n.Response=l,p(m.prototype),m.prototype.use=function(a){return a(this),this},m.prototype.timeout=function(a){return this._timeout=a,this},m.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},m.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(),this.clearTimeout(),this.emit("abort"),this)},m.prototype.set=function(a,b){if(f(a)){for(var c in a)this.set(c,a[c]);return this}return this._header[a.toLowerCase()]=b,this.header[a]=b,this},m.prototype.unset=function(a){return delete this._header[a.toLowerCase()],delete this.header[a],this},m.prototype.getHeader=function(a){return this._header[a.toLowerCase()]},m.prototype.type=function(a){return this.set("Content-Type",n.types[a]||a),this},m.prototype.accept=function(a){return this.set("Accept",n.types[a]||a),this},m.prototype.auth=function(a,b){var c=btoa(a+":"+b);return this.set("Authorization","Basic "+c),this},m.prototype.query=function(a){return"string"!=typeof a&&(a=g(a)),a&&this._query.push(a),this},m.prototype.field=function(a,b){return this._formData||(this._formData=new o.FormData),this._formData.append(a,b),this},m.prototype.attach=function(a,b,c){return this._formData||(this._formData=new o.FormData),this._formData.append(a,b,c),this},m.prototype.send=function(a){var b=f(a),c=this.getHeader("Content-Type");if(b&&f(this._data))for(var d in a)this._data[d]=a[d];else"string"==typeof a?(c||this.type("form"),c=this.getHeader("Content-Type"),"application/x-www-form-urlencoded"==c?this._data=this._data?this._data+"&"+a:a:this._data=(this._data||"")+a):this._data=a;return!b||e(a)?this:(c||this.type("json"),this)},m.prototype.callback=function(a,b){var c=this._callback;this.clearTimeout(),c(a,b)},m.prototype.crossDomainError=function(){var a=new Error("Origin is not allowed by Access-Control-Allow-Origin");a.crossDomain=!0,this.callback(a)},m.prototype.timeoutError=function(){var a=this._timeout,b=new Error("timeout of "+a+"ms exceeded");b.timeout=a,this.callback(b)},m.prototype.withCredentials=function(){return this._withCredentials=!0,this},m.prototype.end=function(a){var b=this,c=this.xhr=n.getXHR(),f=this._query.join("&"),g=this._timeout,h=this._formData||this._data;this._callback=a||d,c.onreadystatechange=function(){if(4==c.readyState){var a;try{a=c.status}catch(d){a=0}if(0==a){if(b.timedout)return b.timeoutError();if(b.aborted)return;return b.crossDomainError()}b.emit("end")}};var i=function(a){a.total>0&&(a.percent=a.loaded/a.total*100),b.emit("progress",a)};this.hasListeners("progress")&&(c.onprogress=i);try{c.upload&&this.hasListeners("progress")&&(c.upload.onprogress=i)}catch(j){}if(g&&!this._timer&&(this._timer=setTimeout(function(){b.timedout=!0,b.abort()},g)),f&&(f=n.serializeObject(f),this.url+=~this.url.indexOf("?")?"&"+f:"?"+f),c.open(this.method,this.url,!0),this._withCredentials&&(c.withCredentials=!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof h&&!e(h)){var k=this.getHeader("Content-Type"),l=n.serialize[k?k.split(";")[0]:""];l&&(h=l(h))}for(var m in this.header)null!=this.header[m]&&c.setRequestHeader(m,this.header[m]);return this.emit("request",this),c.send(h),this},m.prototype.then=function(a,b){return this.end(function(c,d){c?b(c):a(d)})},n.Request=m,n.get=function(a,b,c){var d=n("GET",a);return"function"==typeof b&&(c=b,b=null),b&&d.query(b),c&&d.end(c),d},n.head=function(a,b,c){var d=n("HEAD",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.del=function(a,b){var c=n("DELETE",a);return b&&c.end(b),c},n.patch=function(a,b,c){var d=n("PATCH",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.post=function(a,b,c){var d=n("POST",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.put=function(a,b,c){var d=n("PUT",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},b.exports=n},{emitter:16,reduce:17}],16:[function(a,b,c){function d(a){return a?e(a):void 0}function e(a){for(var b in d.prototype)a[b]=d.prototype[b];return a}b.exports=d,d.prototype.on=d.prototype.addEventListener=function(a,b){return this._callbacks=this._callbacks||{},(this._callbacks[a]=this._callbacks[a]||[]).push(b),this},d.prototype.once=function(a,b){function c(){d.off(a,c),b.apply(this,arguments)}var d=this;return this._callbacks=this._callbacks||{},c.fn=b,this.on(a,c),this},d.prototype.off=d.prototype.removeListener=d.prototype.removeAllListeners=d.prototype.removeEventListener=function(a,b){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var c=this._callbacks[a];if(!c)return this;if(1==arguments.length)return delete this._callbacks[a],this;for(var d,e=0;ed;++d)c[d].apply(this,b)}return this},d.prototype.listeners=function(a){return this._callbacks=this._callbacks||{},this._callbacks[a]||[]},d.prototype.hasListeners=function(a){return!!this.listeners(a).length}},{}],17:[function(a,b,c){b.exports=function(a,b,c){for(var d=0,e=a.length,f=3==arguments.length?c:a[d++];e>d;)f=b.call(null,f,a[d],++d,a);return f}},{}],18:[function(a,b,c){function d(a,b,c){var d;return d=b?new f(a,b):new f(a)}var e=function(){return this}(),f=e.WebSocket||e.MozWebSocket;b.exports=f?d:null,f&&(d.prototype=f.prototype)},{}],19:[function(a,b,c){b.exports=[{executables:{win32:["pol.exe"]},id:0,name:"FINAL FANTASY XI"},{executables:{win32:["ffxiv.exe","ffxiv_dx11.exe"]},id:1,name:"FINAL FANTASY XIV"},{executables:{win32:["Wow.exe","Wow-64.exe"]},id:3,name:"World of Warcraft"},{executables:{darwin:["LoLLauncher.app"],win32:["LolClient.exe","League of Legends.exe"]},id:4,name:"League of Legends"},{executables:{darwin:["Diablo%20III.app"],win32:["Diablo III.exe"]},id:5,name:"Diablo 3"},{executables:{darwin:["dota_osx.app"],win32:["dota2.exe"]},id:6,name:"DOTA 2"},{executables:{darwin:["Heroes.app"],win32:["Heroes of the Storm.exe","HeroesOfTheStorm_x64.exe","HeroesOfTheStorm.exe"]},id:7,name:"Heroes of the Storm"},{executables:{darwin:["Hearthstone.app"],win32:["Hearthstone.exe"]},id:8,name:"Hearthstone"},{executables:{win32:["csgo.exe"]},id:9,name:"Counter-Strike: Global Offensive"},{executables:{win32:["WorldOfTanks.exe"]},id:10,name:"World of Tanks"},{executables:{darwin:["gw2.app"],win32:["gw2.exe"]},id:11,name:"Guild Wars 2"},{executables:{win32:["dayz.exe"]},id:12,name:"Day Z"},{executables:{darwin:["starcraft%20ii.app"],win32:["starcraft ii.exe","SC2_x64.exe","SC2.exe"]},id:13,name:"Starcraft II"},{executables:{win32:["diablo.exe"]},id:14,name:"Diablo"},{executables:{win32:["diablo ii.exe"]},id:15,name:"Diablo 2"},{executables:{win32:["left4dead.exe"]},id:17,name:"Left 4 Dead"},{executables:{darwin:["minecraft.app"],win32:["minecraft.exe"]},id:18,name:"Minecraft"},{executables:{win32:["smite.exe"]},id:19,name:"Smite"},{executables:{win32:["bf4.exe"]},id:20,name:"Battlefield 4"},{executables:{win32:["AoK HD.exe","empires2.exe"]},id:101,name:"Age of Empire II"},{executables:{win32:["age3y.exe"]},id:102,name:"Age of Empire III"},{executables:{win32:["AlanWake.exe"]},id:104,name:"Alan Wake"},{executables:{win32:["alan_wakes_american_nightmare.exe"]},id:105,name:"Alan Wake's American Nightmare"},{executables:{win32:["AlienBreed2Assault.exe"]},id:106,name:"Alien Breed 2: Assault"},{executables:{win32:["Amnesia.exe"]},id:107,name:"Amnesia: The Dark Descent"},{executables:{win32:["UDK.exe"]},id:108,name:"Antichamber"},{executables:{win32:["ArcheAge.exe"]},id:109,name:"ArcheAge"},{executables:{win32:["arma3.exe"]},id:110,name:"Arma III"},{executables:{win32:["AC3SP.exe"]},id:111,name:"Assassin's Creed 3"},{executables:{win32:["Bastion.exe"]},id:112,name:"Bastion"},{executables:{win32:["BF2.exe"]},id:113,name:"Battlefield 2"},{executables:{win32:["bf3.exe"]},id:114,name:"Battlefield 3"},{executables:{win32:["Besiege.exe"]},id:116,name:"Besiege"},{executables:{win32:["Bioshock.exe"]},id:117,name:"Bioshock"},{executables:{win32:["Bioshock2.exe"]},id:118,name:"BioShock II"},{executables:{win32:["BioShockInfinite.exe"]},id:119,name:"BioShock Infinite"},{executables:{win32:["Borderlands2.exe"]},id:122,name:"Borderlands 2"},{executables:{win32:["braid.exe"]},id:123,name:"Braid"},{executables:{win32:["ShippingPC-StormGame.exe"]},id:124,name:"Bulletstorm"},{executables:{},id:125,name:"Cabal 2"},{executables:{win32:["CabalMain.exe"]},id:126,name:"Cabal Online"},{executables:{win32:["iw4mp.exe","iw4sp.exe"]},id:127,name:"Call of Duty: Modern Warfare 2"},{executables:{win32:["t6sp.exe"]},id:128,name:"Call of Duty: Black Ops"},{executables:{win32:["iw5mp.exe"]},id:129,name:"Call of Duty: Modern Warfare 3"},{executables:{win32:["RelicCOH.exe"]},id:132,name:"Company of Heroes"},{executables:{win32:["Crysis64.exe"]},id:135,name:"Crysis"},{executables:{win32:["Crysis2.exe"]},id:136,name:"Crysis 2"},{executables:{win32:["Crysis3.exe"]},id:137,name:"Crysis 3"},{executables:{win32:["Crysis.exe"]},id:138,name:"Crysis 4 "},{executables:{win32:["DATA.exe"]},id:140,name:"Dark Souls"},{executables:{win32:["DarkSoulsII.exe"]},id:141,name:"Dark Souls II"},{executables:{win32:["dfuw.exe"]},id:142,name:"Darkfall: Unholy Wars"},{executables:{win32:["DCGAME.exe"]},id:144,name:"DC Universe Online"},{executables:{win32:["DeadIslandGame.exe"]},id:145,name:"Dead Island"},{executables:{win32:["deadspace2.exe"]},id:146,name:"Dead Space 2"},{executables:{win32:["LOTDGame.exe"]},id:147,name:"Deadlight"},{executables:{win32:["dxhr.exe"]},id:148,name:"Deus Ex: Human Revolution"},{executables:{win32:["DeviMayCry4.exe"]},id:149,name:"Devil May Cry 4"},{executables:{win32:["DMC-DevilMayCry.exe"]},id:150,name:"DmC Devil May Cry"},{executables:{win32:["dirt2_game.exe"]},id:154,name:"DiRT 2"},{executables:{win32:["dirt3_game.exe"]},id:155,name:"DiRT 3"},{executables:{win32:["dota.exe"]},id:156,name:"DOTA"},{executables:{win32:["DoubleDragon.exe"]},id:158,name:"Double Dragon Neon"},{executables:{win32:["DragonAge2.exe"]},id:159,name:"Dragon Age II"},{executables:{win32:["DragonAgeInquisition.exe"]},id:160,name:"Dragon Age: Inquisition"},{executables:{win32:["daorigins.exe"]},id:161,name:"Dragon Age: Origins"},{executables:{win32:["DBXV.exe"]},id:162,name:"Dragon Ball XenoVerse"},{executables:{win32:["DukeForever.exe"]},id:163,name:"Duke Nukem Forever"},{executables:{darwin:["Dustforce.app"],win32:["dustforce.exe"]},id:164,name:"Dustforce"},{executables:{win32:["EliteDangerous32.exe"]},id:165,name:"Elite: Dangerous"},{executables:{win32:["exefile.exe"]},id:166,name:"Eve Online"},{executables:{win32:["eqgame.exe"]},id:167,name:"EverQuest"},{executables:{win32:["EverQuest2.exe"]},id:168,name:"EverQuest II"},{executables:{},id:169,name:"EverQuest Next"},{executables:{win32:["Engine.exe"]},id:170,name:"F.E.A.R."},{executables:{win32:["FEAR2.exe"]},id:171,name:"F.E.A.R. 2: Project Origin"},{executables:{win32:["fallout3.exe"]},id:172,name:"Fallout 3"},{executables:{win32:["FalloutNV.exe"]},id:174,name:"Fallout: New Vegas"},{executables:{win32:["farcry3.exe"]},id:175,name:"Far Cry 3"},{executables:{win32:["fifa15.exe"]},id:176,name:"FIFA 15"},{executables:{win32:["FTLGame.exe"]},id:180,name:"FTL: Faster Than Light"},{executables:{win32:["GTAIV.exe"]},id:181,name:"Grand Theft Auto 4"},{executables:{win32:["GTA5.exe"]},id:182,name:"Grand Theft Auto 5"},{executables:{win32:["Gw.exe"]},id:183,name:"Guild Wars"},{executables:{win32:["H1Z1.exe"]},id:186,name:"H1Z1"},{executables:{win32:["HL2HL2.exe","hl2.exe"]},id:188,name:"Half Life 2"},{executables:{win32:["HOMEFRONT.exe"]},id:195,name:"Homefront"},{executables:{win32:["invisibleinc.exe"]},id:196,name:"Invisible Inc."},{executables:{win32:["LANoire.exe"]},id:197,name:"L.A. Noire"},{executables:{win32:["Landmark64.exe"]},id:198,name:"Landmark"},{executables:{win32:["left4dead2.exe"]},id:201,name:"Left 4 Dead 2"},{executables:{win32:["lineage.exe"]},id:203,name:"Lineage"},{executables:{win32:["Magicka.exe"]},id:206,name:"Magicka"},{executables:{win32:["MapleStory.exe"]},id:208,name:"MapleStory"},{executables:{},id:209,name:"Mark of the Ninja"},{executables:{win32:["MassEffect.exe"]},id:210,name:"Mass Effect"},{executables:{win32:["MassEffect2.exe"]},id:211,name:"Mass Effect 2"},{executables:{win32:["MassEffect3Demo.exe"]},id:212,name:"Mass Effect 3"},{executables:{win32:["METAL GEAR RISING REVENGEANCE.exe"]},id:214,name:"Metal Gear Rising: Revengeance"},{executables:{win32:["metro2033.exe"]},id:215,name:"Metro 2033"},{executables:{win32:["MetroLL.exe"]},id:216,name:"Metro Last Light"},{executables:{win32:["MK10.exe"]},id:218,name:"Mortal Kombat X"},{executables:{win32:["speed.exe"]},id:219,name:"Need For Speed Most Wanted"},{executables:{},id:220,name:"Neverwinder"},{executables:{darwin:["Outlast.app"],win32:["OLGame.exe"]},id:221,name:"Outlast"},{executables:{win32:["PapersPlease.exe"]},id:222,name:"Papers, Please"},{executables:{win32:["payday_win32_release.exe"]},id:223,name:"PAYDAY"},{executables:{win32:["payday2_win32_release.exe"]},id:224,name:"PAYDAY2"},{executables:{win32:["PillarsOfEternity.exe"]},id:225,name:"Pillars of Eternity"},{executables:{win32:["PA.exe"]},id:226,name:"Planetary Annihilation"},{executables:{win32:["planetside2_x86.exe"]},id:227,name:"Planetside 2"},{executables:{win32:["hl2P.exe"]},id:228,name:"Portal"},{executables:{win32:["portal2.exe"]},id:229,name:"Portal 2"},{executables:{win32:["PrimalCarnageGame.exe"]},id:231,name:"Primal Cargnage"},{executables:{win32:["pCARS.exe"]},id:232,name:"Project Cars"},{executables:{win32:["RaceTheSun.exe"]},id:233,name:"Race The Sun"},{executables:{win32:["Rage.exe"]},id:234,name:"RAGE"},{executables:{win32:["ragexe.exe"]},id:235,name:"Ragnarok Online"},{executables:{win32:["rift.exe"]},id:236,name:"Rift"},{executables:{win32:["Rocksmith2014.exe"]},id:237,name:"Rocksmith 2014"},{executables:{win32:["SwiftKit-RS.exe","JagexLauncher.exe"]},id:238,name:"RuneScape"},{executables:{win32:["Shadowgrounds.exe"]},id:239,name:"Shadowgrounds"},{executables:{win32:["survivor.exe"]},id:240,name:"Shadowgrounds: Survivor"},{executables:{win32:["ShovelKnight.exe"]},id:241,name:"Shovel Knight"},{executables:{win32:["SimCity.exe"]},id:242,name:"SimCity"},{executables:{win32:["SporeApp.exe"]},id:245,name:"Spore"},{executables:{win32:["StarCitizen.exe"]},id:246,name:"Star Citizen"},{executables:{},id:247,name:"Star Trek Online"},{executables:{win32:["battlefront.exe"]},id:248,name:"Star Wars Battlefront"},{executables:{win32:["swtor.exe"]},id:249,name:"Star Wars: The Old Republic"},{executables:{win32:["starbound.exe","starbound_opengl.exe"]},id:250,name:"Starbound"},{executables:{win32:["starcraft.exe"]},id:251,name:"Starcraft"},{executables:{win32:["SSFIV.exe"]},id:253,name:"Ultra Street Fighter IV"},{executables:{win32:["superhexagon.exe"]},id:254,name:"Super Hexagon"},{executables:{win32:["swordandsworcery_pc.exe"]},id:255,name:"Superbrothers: Sword & Sworcery EP"},{executables:{win32:["hl2TF.exe"]},id:256,name:"Team Fortress 2"},{executables:{win32:["TERA.exe"]},id:258,name:"TERA"},{executables:{win32:["Terraria.exe"]},id:259,name:"Terraria"},{executables:{win32:["Bethesda.net_Launcher.exe"]},id:260,name:"The Elder Scrolls Online"},{executables:{win32:["TESV.exe"]},id:261,name:"The Elder Scrolls V: Skyrim"},{executables:{win32:["TheSecretWorld.exe"]},id:262,name:"The Secret World"},{executables:{win32:["TS3.exe","ts3w.exe"]},id:264,name:"The Sims 3"},{executables:{win32:["WALKINGDEAD101.EXE"]},id:265,name:"The Walking Dead"},{executables:{win32:["TheWalkingDead2.exe"]},id:266,name:"The Walking Dead Season Two"},{executables:{win32:["witcher3.exe"]},id:267,name:"The Witcher 3"},{executables:{win32:["Future Soldier.exe"]},id:268,name:"Tom Clancy's Ghost Recon: Future Solider"},{executables:{win32:["TombRaider.exe"]},id:269,name:"Tomb Raider (2013)"},{executables:{win32:["Torchlight.exe"]},id:271,name:"Torchlight"},{executables:{win32:["Torchlight2.exe"]},id:272,name:"Torchlight 2"},{executables:{win32:["Shogun2.exe"]},id:273,name:"Total War: Shogun 2"},{executables:{win32:["Transistor.exe"]},id:274,name:"Transistor"},{executables:{win32:["trine.exe"]},id:275,name:"Trine"},{executables:{win32:["trine2_32bit.exe"]},id:276,name:"Trine 2"},{executables:{win32:["UOKR.exe"]},id:277,name:"Ultima Online"},{executables:{win32:["aces.exe"]},id:279,name:"War Thunder"},{executables:{win32:["Warcraft III.exe","wc3.exe"]},id:281,name:"Warcraft 3: Reign of Chaos"},{executables:{win32:["Warcraft II BNE.exe"]},id:282,name:"Warcraft II"},{executables:{win32:["Warframe.x64.exe","Warframe.exe"]},id:283,name:"Warframe"},{executables:{win32:["watch_dogs.exe"]},id:284,name:"Watch Dogs"},{executables:{win32:["WildStar64.exe"]},id:285,name:"WildStar"},{executables:{win32:["XComGame.exe"]},id:288,name:"XCOM: Enemy Unknown"},{executables:{win32:["DFO.exe","dfo.exe"]},id:289,name:"Dungeon Fighter Online"},{executables:{win32:["aclauncher.exe","acclient.exe"]},id:290,name:"Asheron's Call"},{executables:{win32:["MapleStory2.exe"]},id:291,name:"MapleStory 2"},{executables:{win32:["ksp.exe"]},id:292,name:"Kerbal Space Program"},{executables:{win32:["PINBALL.EXE"]},id:293,name:"3D Pinball: Space Cadet"},{executables:{win32:["dave.exe"]},id:294,name:"Dangerous Dave"},{executables:{win32:["iwbtgbeta(slomo).exe","iwbtgbeta(fs).exe"]},id:295,name:"I Wanna Be The Guy"},{executables:{win32:["MechWarriorOnline.exe "]},id:296,name:"Mech Warrior Online"},{executables:{win32:["dontstarve_steam.exe"]},id:297,name:"Don't Starve"},{executables:{win32:["GalCiv3.exe"]},id:298,name:"Galactic Civilization 3"},{executables:{win32:["Risk of Rain.exe"]},id:299, -name:"Risk of Rain"},{executables:{win32:["Binding_of_Isaac.exe","Isaac-ng.exe"]},id:300,name:"The Binding of Isaac"},{executables:{win32:["RustClient.exe"]},id:301,name:"Rust"},{executables:{win32:["Clicker Heroes.exe"]},id:302,name:"Clicker Heroes"},{executables:{win32:["Brawlhalla.exe"]},id:303,name:"Brawlhalla"},{executables:{win32:["TownOfSalem.exe"]},id:304,name:"Town of Salem"},{executables:{win32:["osu!.exe"]},id:305,name:"osu!"},{executables:{win32:["PathOfExileSteam.exe","PathOfExile.exe"]},id:306,name:"Path of Exile"},{executables:{win32:["Dolphin.exe"]},id:307,name:"Dolphin"},{executables:{win32:["RocketLeague.exe"]},id:308,name:"Rocket League"},{executables:{win32:["TJPP.exe"]},id:309,name:"Jackbox Party Pack"},{executables:{win32:["KFGame.exe"]},id:310,name:"Killing Floor 2"},{executables:{win32:["ShooterGame.exe"]},id:311,name:"Ark: Survival Evolved"},{executables:{win32:["LifeIsStrange.exe"]},id:312,name:"Life Is Strange"},{executables:{win32:["Client_tos.exe"]},id:313,name:"Tree of Savior"},{executables:{win32:["olliolli2.exe"]},id:314,name:"OlliOlli2"},{executables:{win32:["cw.exe"]},id:315,name:"Closers Dimension Conflict"},{executables:{win32:["ESSTEAM.exe","elsword.exe","x2.exe"]},id:316,name:"Elsword"},{executables:{win32:["ori.exe"]},id:317,name:"Ori and the Blind Forest"},{executables:{win32:["Skyforge.exe"]},id:318,name:"Skyforge"},{executables:{win32:["projectzomboid64.exe","projectzomboid32.exe"]},id:319,name:"Project Zomboid"},{executables:{win32:["From_The_Depths.exe"]},id:320,name:"The Depths"},{executables:{win32:["TheCrew.exe"]},id:321,name:"The Crew"},{executables:{win32:["MarvelHeroes2015.exe"]},id:322,name:"Marvel Heroes 2015"},{executables:{win32:["timeclickers.exe"]},id:324,name:"Time Clickers"},{executables:{win32:["eurotrucks2.exe"]},id:325,name:"Euro Truck Simulator 2"},{executables:{win32:["FarmingSimulator2015Game.exe"]},id:326,name:"Farming Simulator 15"},{executables:{win32:["strife.exe"]},id:327,name:"Strife"},{executables:{win32:["Awesomenauts.exe"]},id:328,name:"Awesomenauts"},{executables:{win32:["Dofus.exe"]},id:329,name:"Dofus"},{executables:{win32:["Boid.exe"]},id:330,name:"Boid"},{executables:{win32:["adventure-capitalist.exe"]},id:331,name:"AdVenture Capitalist"},{executables:{win32:["OrcsMustDie2.exe"]},id:332,name:"Orcs Must Die! 2"},{executables:{win32:["Mountain.exe"]},id:333,name:"Mountain"},{executables:{win32:["Valkyria.exe"]},id:335,name:"Valkyria Chronicles"},{executables:{win32:["ffxiiiimg.exe"]},id:336,name:"Final Fantasy XIII"},{executables:{win32:["TLR.exe"]},id:337,name:"The Last Remnant"},{executables:{win32:["Cities.exe"]},id:339,name:"Cities Skylines"},{executables:{win32:["worldofwarships.exe","WoWSLauncher.exe"]},id:341,name:"World of Warships"},{executables:{win32:["spacegame-Win64-shipping.exe"]},id:342,name:"Fractured Space"},{executables:{win32:["thespacegame.exe"]},id:343,name:"Ascent - The Space Game"},{executables:{win32:["DuckGame.exe"]},id:344,name:"Duck Game"},{executables:{win32:["PPSSPPWindows.exe"]},id:345,name:"PPSSPP"},{executables:{win32:["MBAA.exe"]},id:346,name:"Melty Blood Actress Again: Current Code"},{executables:{win32:["TheWolfAmongUs.exe"]},id:347,name:"The Wolf Among Us"},{executables:{win32:["SpaceEngineers.exe"]},id:348,name:"Space Engineers"},{executables:{win32:["Borderlands.exe"]},id:349,name:"Borderlands"},{executables:{win32:["100orange.exe"]},id:351,name:"100% Orange Juice"},{executables:{win32:["reflex.exe"]},id:354,name:"Reflex"},{executables:{win32:["pso2.exe"]},id:355,name:"Phantasy Star Online 2"},{executables:{win32:["AssettoCorsa.exe"]},id:356,name:"Assetto Corsa"},{executables:{win32:["iw3mp.exe","iw3sp.exe"]},id:357,name:"Call of Duty 4: Modern Warfare"},{executables:{win32:["WolfOldBlood_x64.exe"]},id:358,name:"Wolfenstein: The Old Blood"},{executables:{win32:["castle.exe"]},id:359,name:"Castle Crashers"},{executables:{win32:["vindictus.exe"]},id:360,name:"Vindictus"},{executables:{win32:["ShooterGame-Win32-Shipping.exe"]},id:361,name:"Dirty Bomb"},{executables:{win32:["BatmanAK.exe"]},id:362,name:"Batman Arkham Knight"},{executables:{win32:["drt.exe"]},id:363,name:"Dirt Rally"},{executables:{win32:["rFactor.exe"]},id:364,name:"rFactor"},{executables:{win32:["clonk.exe"]},id:365,name:"Clonk Rage"},{executables:{win32:["SRHK.exe"]},id:366,name:"Shadowrun: Hong Kong"},{executables:{win32:["Insurgency.exe"]},id:367,name:"Insurgency"},{executables:{win32:["StepMania.exe"]},id:368,name:"Step Mania"},{executables:{win32:["FirefallCLient.exe"]},id:369,name:"Firefall"},{executables:{win32:["mirrorsedge.exe"]},id:370,name:"Mirrors Edge"},{executables:{win32:["MgsGroundZeroes.exe"]},id:371,name:"Metal Gear Solid V: Ground Zeroes"},{executables:{win32:["mgsvtpp.exe"]},id:372,name:"Metal Gear Solid V: The Phantom Pain"},{executables:{win32:["tld.exe"]},id:373,name:"The Long Dark"},{executables:{win32:["TKOM.exe"]},id:374,name:"Take On Mars"},{executables:{win32:["robloxplayerlauncher.exe","Roblox.exe"]},id:375,name:"Roblox"},{executables:{win32:["eu4.exe"]},id:376,name:"Europa Universalis 4"},{executables:{win32:["APB.exe"]},id:377,name:"APB Reloaded"},{executables:{win32:["Robocraft.exe"]},id:378,name:"Robocraft"},{executables:{win32:["Unity.exe"]},id:379,name:"Unity"},{executables:{win32:["Simpsons.exe"]},id:380,name:"The Simpsons: Hit & Run"},{executables:{win32:["Dnlauncher.exe","DragonNest.exe"]},id:381,name:"Dragon Nest"},{executables:{win32:["Trove.exe"]},id:382,name:"Trove"},{executables:{win32:["EndlessLegend.exe"]},id:383,name:"Endless Legend"},{executables:{win32:["TurbineLauncher.exe","dndclient.exe"]},id:384,name:"Dungeons & Dragons Online"},{executables:{win32:["quakelive.exe","quakelive_steam.exe"]},id:385,name:"Quake Live"},{executables:{win32:["7DaysToDie.exe"]},id:386,name:"7DaysToDie"},{executables:{win32:["SpeedRunners.exe"]},id:387,name:"SpeedRunners"},{executables:{win32:["gamemd.exe"]},id:388,name:"Command & Conquer: Red Alert 2"},{executables:{win32:["generals.exe"]},id:389,name:"Command & Conquer Generals: Zero Hour"},{executables:{win32:["Oblivion.exe"]},id:390,name:"The Elder Scrolls 4: Oblivion"},{executables:{win32:["mgsi.exe"]},id:391,name:"Metal Gear Solid"},{executables:{win32:["EoCApp.exe"]},id:392,name:"Divinity - Original Sin"},{executables:{win32:["Torment.exe"]},id:393,name:"Planescape: Torment"},{executables:{win32:["HexPatch.exe"]},id:394,name:"Hex: Shards of Fate"},{executables:{win32:["NS3FB.exe"]},id:395,name:"Naruto Shippuden Ultimate Ninja Storm 3 Full Burst"},{executables:{win32:["NSUNSR.exe"]},id:396,name:"Naruto Shippuden Ultimate Ninja Storm Revolution"},{executables:{win32:["SaintsRowIV.exe"]},id:397,name:"Saints Row IV"},{executables:{win32:["Shadowrun.exe"]},id:398,name:"Shadowrun"},{executables:{win32:["DungeonoftheEndless.exe"]},id:399,name:"Dungeon of the Endless"},{executables:{win32:["Hon.exe"]},id:400,name:"Heroes of Newerth"},{executables:{win32:["mabinogi.exe"]},id:401,name:"Mabinogi"},{executables:{win32:["CoD2MP_s.exe","CoDSP_s.exe"]},id:402,name:"Call of Duty 2:"},{executables:{win32:["CoDWaWmp.exe","CoDWaw.exe"]},id:403,name:"Call of Duty: World at War"},{executables:{win32:["heroes.exe"]},id:404,name:"Mabinogi Heroes (Vindictus) "},{executables:{win32:["KanColleViewer.exe"]},id:405,name:"KanColle "},{executables:{win32:["cyphers.exe"]},id:406,name:"Cyphers"},{executables:{win32:["RelicCoH2.exe"]},id:407,name:"Company of Heroes 2"},{executables:{win32:["MJ.exe"]},id:408,name:"セガNET麻雀MJ"},{executables:{win32:["ge.exe"]},id:409,name:"Granado Espada"},{executables:{win32:["NovaRO.exe"]},id:410,name:"Nova Ragnarok Online"},{executables:{win32:["RivalsofAether.exe"]},id:411,name:"Rivals of Aether"},{executables:{win32:["bfh.exe"]},id:412,name:"Battlefield Hardline"},{executables:{win32:["GrowHome.exe"]},id:413,name:"Grow Home"},{executables:{win32:["patriots.exe"]},id:414,name:"Rise of Nations Extended"},{executables:{win32:["Railroads.exe"]},id:415,name:"Sid Meier's Railroads!"},{executables:{win32:["Empire.exe"]},id:416,name:"Empire: Total War"},{executables:{win32:["Napoleon.exe"]},id:417,name:"Napoleon: Total War"},{executables:{win32:["gta_sa.exe"]},id:418,name:"Grand Theft Auto: San Andreas"},{executables:{win32:["MadMax.exe"]},id:419,name:"Mad Max"},{executables:{win32:["Titanfall.exe"]},id:420,name:"Titanfall"},{executables:{win32:["age2_x1.exe"]},id:421,name:"Age of Empires II: The Conquerors"},{executables:{win32:["Rome2.exe"]},id:422,name:"Total War: ROME 2"},{executables:{win32:["ShadowOfMordor.exe"]},id:423,name:"Middle-earth: Shadow of Mordor"},{executables:{win32:["Subnautica.exe"]},id:424,name:"Subnautica"},{executables:{win32:["anno5.exe"]},id:425,name:"Anno 2070"},{executables:{win32:["carrier.exe"]},id:426,name:"Carrier Command Gaea Mission"},{executables:{win32:["DarksidersPC.exe"]},id:427,name:"Darksiders"},{executables:{win32:["Darksiders2.exe"]},id:428,name:"Darksiders 2"},{executables:{win32:["mudlet.exe"]},id:429,name:"Mudlet"},{executables:{win32:["DunDefLauncher.exe"]},id:430,name:"Dungeon Defenders II"},{executables:{win32:["hng.exe"]},id:431,name:"Heroes and Generals"},{executables:{win32:["WFTOGame.exe"]},id:432,name:"War of the Overworld"},{executables:{win32:["Talisman.exe"]},id:433,name:"Talisman: Digital Edition"},{executables:{win32:["limbo.exe"]},id:434,name:"Limbo"},{executables:{win32:["ibbobb.exe"]},id:435,name:"ibb & obb"},{executables:{win32:["BattleBlockTheater.exe"]},id:436,name:"BattleBlock Theater"},{executables:{win32:["iracinglauncher.exe","iracingsim.exe","iracingsim64.exe"]},id:437,name:"iRacing"},{executables:{win32:["CivilizationV_DX11.exe"]},id:438,name:"Civilization V"}]},{}]},{},[9])(9)}); \ No newline at end of file +}},{key:"manageServer",get:function(){return this.getBit(5)},set:function(a){this.setBit(5,a)}},{key:"readMessages",get:function(){return this.getBit(10)},set:function(a){this.setBit(10,a)}},{key:"sendMessages",get:function(){return this.getBit(11)},set:function(a){this.setBit(11,a)}},{key:"sendTTSMessages",get:function(){return this.getBit(12)},set:function(a){this.setBit(12,a)}},{key:"manageMessages",get:function(){return this.getBit(13)},set:function(a){this.setBit(13,a)}},{key:"embedLinks",get:function(){return this.getBit(14)},set:function(a){this.setBit(14,a)}},{key:"attachFiles",get:function(){return this.getBit(15)},set:function(a){this.setBit(15,a)}},{key:"readMessageHistory",get:function(){return this.getBit(16)},set:function(a){this.setBit(16,a)}},{key:"mentionEveryone",get:function(){return this.getBit(17)},set:function(a){this.setBit(17,a)}},{key:"voiceConnect",get:function(){return this.getBit(20)},set:function(a){this.setBit(20,a)}},{key:"voiceSpeak",get:function(){return this.getBit(21)},set:function(a){this.setBit(21,a)}},{key:"voiceMuteMembers",get:function(){return this.getBit(22)},set:function(a){this.setBit(22,a)}},{key:"voiceDeafenMembers",get:function(){return this.getBit(23)},set:function(a){this.setBit(23,a)}},{key:"voiceMoveMembers",get:function(){return this.getBit(24)},set:function(a){this.setBit(24,a)}},{key:"voiceUseVoiceActivation",get:function(){return this.getBit(25)},set:function(a){this.setBit(25,a)}}]),a}();b.exports=f},{}],8:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c=e.length)break;i=e[h++]}else{if(h=e.next(),h.done)break;i=h.value}var j=i;this.roles.push(new f(j,this))}}return a.prototype.permissionsOf=function(a){var b=this.server.getMember("id",a.id);return b?b.permissionsIn(this):null},a.prototype.equals=function(a){return a&&a.id===this.id},a.prototype.addMessage=function(a){return this.messages.length>1e3&&this.messages.splice(0,1),this.getMessage("id",a.id)||this.messages.push(a),this.getMessage("id",a.id)},a.prototype.getMessage=function(a,b){for(var c=this.messages,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.toString=function(){return"<#"+this.id+">"},e(a,[{key:"permissionOverwrites",get:function(){return this.roles}},{key:"permissions",get:function(){return this.roles}},{key:"client",get:function(){return this.server.client}},{key:"isPrivate",get:function(){return!1}},{key:"users",get:function(){return this.server.members}},{key:"members",get:function(){return this.server.members}}]),a}();b.exports=g},{"./ChannelPermissions.js":1}],9:[function(a,b,c){"use strict";var d=(a("superagent"),a("./Endpoints.js")),e=a("./Client.js"),f={Endpoints:d,Client:e};f.patchStrings=function(){function a(a,b){Object.defineProperty(String.prototype,a,{get:function(){return b+this+b}})}a("bold","**"),a("underline","__"),a("strike","~~"),a("code","`"),a("codeblock","```"),a("newline","\n"),Object.defineProperty(String.prototype,"italic",{get:function(){return"*"+this+"*"}})},b.exports=f},{"./Client.js":2,"./Endpoints.js":3,superagent:15}],10:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g.id===b)return!0}return!1},e(a,[{key:"sender",get:function(){return this.author}},{key:"isPrivate",get:function(){return this.channel.isPrivate}}]),a}());b.exports=f},{"./PMChannel.js":6}],12:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c=e.length)break;i=e[h++]}else{if(h=e.next(),h.done)break;i=h.value}var j=i;this.roles.push(new f(j))}if(!b.members)return void(b.members=[c.user]);for(var k=b.members,l=Array.isArray(k),m=0,k=l?k:k[Symbol.iterator]();;){var n;if(l){if(m>=k.length)break;n=k[m++]}else{if(m=k.next(),m.done)break;n=m.value}var o=n;o.user&&this.addMember(c.addUser(o.user),o.roles)}}return a.prototype.getRole=function(a){for(var b=this.roles,c=Array.isArray(b),d=0,b=c?b:b[Symbol.iterator]();;){var e;if(c){if(d>=b.length)break;e=b[d++]}else{if(d=b.next(),d.done)break;e=d.value}var f=e;if(f.id===a)return f}return null},a.prototype.updateRole=function(a){var b=this.getRole(a.id);if(b){var c=this.roles.indexOf(b);return this.roles[c]=new f(a),this.roles[c]}return!1},a.prototype.removeRole=function(a){for(var b in this.roles)this.roles[b].id===a&&this.roles.splice(b,1);for(var c=this.members,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;for(var b in g.rawRoles)g.rawRoles[b]===a&&g.rawRoles.splice(b,1)}},a.prototype.getChannel=function(a,b){for(var c=this.channels,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.getMember=function(a,b){for(var c=this.members,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return g}return null},a.prototype.removeMember=function(a,b){for(var c=this.members,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(g[a]===b)return this.members.splice(a,1),g}return!1},a.prototype.addChannel=function(a){return this.getChannel("id",a.id)||this.channels.push(a),a},a.prototype.addMember=function(a,b){if(!this.getMember("id",a.id)){var c=new g(a,this,b);this.members.push(c)}return c},a.prototype.toString=function(){return this.name},a.prototype.equals=function(a){return a.id===this.id},e(a,[{key:"permissionGroups",get:function(){return this.roles}},{key:"permissions",get:function(){return this.roles}},{key:"iconURL",get:function(){return this.icon?"https://discordapp.com/api/guilds/"+this.id+"/icons/"+this.icon+".jpg":null}},{key:"afkChannel",get:function(){return this.afkChannelId?this.getChannel("id",this.afkChannelId):!1}},{key:"defaultChannel",get:function(){return this.getChannel("name","general")}},{key:"owner",get:function(){return this.client.getUser("id",this.ownerID)}},{key:"users",get:function(){return this.members}}]),a}();b.exports=h},{"./Member.js":5,"./ServerPermissions.js":7}],13:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c"},a.prototype.toString=function(){return this.mention()},a.prototype.equals=function(a){return a.id===this.id},a.prototype.equalsStrict=function(a){return a.id===this.id&&a.avatar===this.avatar&&a.username===this.username&&a.discriminator===this.discriminator},e(a,[{key:"avatarURL",get:function(){return this.avatar?"https://discordapp.com/api/users/"+this.id+"/avatars/"+this.avatar+".jpg":null}}]),a}();b.exports=f},{}],14:[function(a,b,c){},{}],15:[function(a,b,c){function d(){}function e(a){var b={}.toString.call(a);switch(b){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function f(a){return a===Object(a)}function g(a){if(!f(a))return a;var b=[];for(var c in a)null!=a[c]&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")}function h(a){for(var b,c,d={},e=a.split("&"),f=0,g=e.length;g>f;++f)c=e[f],b=c.split("="),d[decodeURIComponent(b[0])]=decodeURIComponent(b[1]);return d}function i(a){var b,c,d,e,f=a.split(/\r?\n/),g={};f.pop();for(var h=0,i=f.length;i>h;++h)c=f[h],b=c.indexOf(":"),d=c.slice(0,b).toLowerCase(),e=r(c.slice(b+1)),g[d]=e;return g}function j(a){return a.split(/ *; */).shift()}function k(a){return q(a.split(/ *; */),function(a,b){var c=b.split(/ *= */),d=c.shift(),e=c.shift();return d&&e&&(a[d]=e),a},{})}function l(a,b){b=b||{},this.req=a,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||"undefined"==typeof this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText,this.setStatusProperties(this.xhr.status),this.header=this.headers=i(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body="HEAD"!=this.req.method?this.parseBody(this.text?this.text:this.xhr.response):null}function m(a,b){var c=this;p.call(this),this._query=this._query||[],this.method=a,this.url=b,this.header={},this._header={},this.on("end",function(){var a=null,b=null;try{b=new l(c)}catch(d){return a=new Error("Parser is unable to parse the response"),a.parse=!0,a.original=d,c.callback(a)}if(c.emit("response",b),a)return c.callback(a,b);if(b.status>=200&&b.status<300)return c.callback(a,b);var e=new Error(b.statusText||"Unsuccessful HTTP response");e.original=a,e.response=b,e.status=b.status,c.callback(e,b)})}function n(a,b){return"function"==typeof b?new m("GET",a).end(b):1==arguments.length?new m("GET",a):new m(a,b)}var o,p=a("emitter"),q=a("reduce");o="undefined"!=typeof window?window:"undefined"!=typeof self?self:this,n.getXHR=function(){if(!(!o.XMLHttpRequest||o.location&&"file:"==o.location.protocol&&o.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(a){}return!1};var r="".trim?function(a){return a.trim()}:function(a){return a.replace(/(^\s*|\s*$)/g,"")};n.serializeObject=g,n.parseString=h,n.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},n.serialize={"application/x-www-form-urlencoded":g,"application/json":JSON.stringify},n.parse={"application/x-www-form-urlencoded":h,"application/json":JSON.parse},l.prototype.get=function(a){return this.header[a.toLowerCase()]},l.prototype.setHeaderProperties=function(a){var b=this.header["content-type"]||"";this.type=j(b);var c=k(b);for(var d in c)this[d]=c[d]},l.prototype.parse=function(a){return this.parser=a,this},l.prototype.parseBody=function(a){var b=this.parser||n.parse[this.type];return b&&a&&(a.length||a instanceof Object)?b(a):null},l.prototype.setStatusProperties=function(a){1223===a&&(a=204);var b=a/100|0;this.status=this.statusCode=a,this.statusType=b,this.info=1==b,this.ok=2==b,this.clientError=4==b,this.serverError=5==b,this.error=4==b||5==b?this.toError():!1,this.accepted=202==a,this.noContent=204==a,this.badRequest=400==a,this.unauthorized=401==a,this.notAcceptable=406==a,this.notFound=404==a,this.forbidden=403==a},l.prototype.toError=function(){var a=this.req,b=a.method,c=a.url,d="cannot "+b+" "+c+" ("+this.status+")",e=new Error(d);return e.status=this.status,e.method=b,e.url=c,e},n.Response=l,p(m.prototype),m.prototype.use=function(a){return a(this),this},m.prototype.timeout=function(a){return this._timeout=a,this},m.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},m.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(),this.clearTimeout(),this.emit("abort"),this)},m.prototype.set=function(a,b){if(f(a)){for(var c in a)this.set(c,a[c]);return this}return this._header[a.toLowerCase()]=b,this.header[a]=b,this},m.prototype.unset=function(a){return delete this._header[a.toLowerCase()],delete this.header[a],this},m.prototype.getHeader=function(a){return this._header[a.toLowerCase()]},m.prototype.type=function(a){return this.set("Content-Type",n.types[a]||a),this},m.prototype.accept=function(a){return this.set("Accept",n.types[a]||a),this},m.prototype.auth=function(a,b){var c=btoa(a+":"+b);return this.set("Authorization","Basic "+c),this},m.prototype.query=function(a){return"string"!=typeof a&&(a=g(a)),a&&this._query.push(a),this},m.prototype.field=function(a,b){return this._formData||(this._formData=new o.FormData),this._formData.append(a,b),this},m.prototype.attach=function(a,b,c){return this._formData||(this._formData=new o.FormData),this._formData.append(a,b,c),this},m.prototype.send=function(a){var b=f(a),c=this.getHeader("Content-Type");if(b&&f(this._data))for(var d in a)this._data[d]=a[d];else"string"==typeof a?(c||this.type("form"),c=this.getHeader("Content-Type"),"application/x-www-form-urlencoded"==c?this._data=this._data?this._data+"&"+a:a:this._data=(this._data||"")+a):this._data=a;return!b||e(a)?this:(c||this.type("json"),this)},m.prototype.callback=function(a,b){var c=this._callback;this.clearTimeout(),c(a,b)},m.prototype.crossDomainError=function(){var a=new Error("Origin is not allowed by Access-Control-Allow-Origin");a.crossDomain=!0,this.callback(a)},m.prototype.timeoutError=function(){var a=this._timeout,b=new Error("timeout of "+a+"ms exceeded");b.timeout=a,this.callback(b)},m.prototype.withCredentials=function(){return this._withCredentials=!0,this},m.prototype.end=function(a){var b=this,c=this.xhr=n.getXHR(),f=this._query.join("&"),g=this._timeout,h=this._formData||this._data;this._callback=a||d,c.onreadystatechange=function(){if(4==c.readyState){var a;try{a=c.status}catch(d){a=0}if(0==a){if(b.timedout)return b.timeoutError();if(b.aborted)return;return b.crossDomainError()}b.emit("end")}};var i=function(a){a.total>0&&(a.percent=a.loaded/a.total*100),b.emit("progress",a)};this.hasListeners("progress")&&(c.onprogress=i);try{c.upload&&this.hasListeners("progress")&&(c.upload.onprogress=i)}catch(j){}if(g&&!this._timer&&(this._timer=setTimeout(function(){b.timedout=!0,b.abort()},g)),f&&(f=n.serializeObject(f),this.url+=~this.url.indexOf("?")?"&"+f:"?"+f),c.open(this.method,this.url,!0),this._withCredentials&&(c.withCredentials=!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof h&&!e(h)){var k=this.getHeader("Content-Type"),l=n.serialize[k?k.split(";")[0]:""];l&&(h=l(h))}for(var m in this.header)null!=this.header[m]&&c.setRequestHeader(m,this.header[m]);return this.emit("request",this),c.send(h),this},m.prototype.then=function(a,b){return this.end(function(c,d){c?b(c):a(d)})},n.Request=m,n.get=function(a,b,c){var d=n("GET",a);return"function"==typeof b&&(c=b,b=null),b&&d.query(b),c&&d.end(c),d},n.head=function(a,b,c){var d=n("HEAD",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.del=function(a,b){var c=n("DELETE",a);return b&&c.end(b),c},n.patch=function(a,b,c){var d=n("PATCH",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.post=function(a,b,c){var d=n("POST",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.put=function(a,b,c){var d=n("PUT",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},b.exports=n},{emitter:16,reduce:17}],16:[function(a,b,c){function d(a){return a?e(a):void 0}function e(a){for(var b in d.prototype)a[b]=d.prototype[b];return a}b.exports=d,d.prototype.on=d.prototype.addEventListener=function(a,b){return this._callbacks=this._callbacks||{},(this._callbacks[a]=this._callbacks[a]||[]).push(b),this},d.prototype.once=function(a,b){function c(){d.off(a,c),b.apply(this,arguments)}var d=this;return this._callbacks=this._callbacks||{},c.fn=b,this.on(a,c),this},d.prototype.off=d.prototype.removeListener=d.prototype.removeAllListeners=d.prototype.removeEventListener=function(a,b){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var c=this._callbacks[a];if(!c)return this;if(1==arguments.length)return delete this._callbacks[a],this;for(var d,e=0;ed;++d)c[d].apply(this,b)}return this},d.prototype.listeners=function(a){return this._callbacks=this._callbacks||{},this._callbacks[a]||[]},d.prototype.hasListeners=function(a){return!!this.listeners(a).length}},{}],17:[function(a,b,c){b.exports=function(a,b,c){for(var d=0,e=a.length,f=3==arguments.length?c:a[d++];e>d;)f=b.call(null,f,a[d],++d,a);return f}},{}],18:[function(a,b,c){function d(a,b,c){var d;return d=b?new f(a,b):new f(a)}var e=function(){return this}(),f=e.WebSocket||e.MozWebSocket;b.exports=f?d:null,f&&(d.prototype=f.prototype)},{}],19:[function(a,b,c){b.exports=[{executables:{win32:["pol.exe"]},id:0,name:"FINAL FANTASY XI"},{executables:{win32:["ffxiv.exe","ffxiv_dx11.exe"]},id:1,name:"FINAL FANTASY XIV"},{executables:{win32:["Wow.exe","Wow-64.exe"]},id:3,name:"World of Warcraft"},{executables:{darwin:["LoLLauncher.app"],win32:["LolClient.exe","League of Legends.exe"]},id:4,name:"League of Legends"},{executables:{darwin:["Diablo%20III.app"],win32:["Diablo III.exe"]},id:5,name:"Diablo 3"},{executables:{darwin:["dota_osx.app"],win32:["dota2.exe"]},id:6,name:"DOTA 2"},{executables:{darwin:["Heroes.app"],win32:["Heroes of the Storm.exe","HeroesOfTheStorm_x64.exe","HeroesOfTheStorm.exe"]},id:7,name:"Heroes of the Storm"},{executables:{darwin:["Hearthstone.app"],win32:["Hearthstone.exe"]},id:8,name:"Hearthstone"},{executables:{win32:["csgo.exe"]},id:9,name:"Counter-Strike: Global Offensive"},{executables:{win32:["WorldOfTanks.exe"]},id:10,name:"World of Tanks"},{executables:{darwin:["gw2.app"],win32:["gw2.exe"]},id:11,name:"Guild Wars 2"},{executables:{win32:["dayz.exe"]},id:12,name:"Day Z"},{executables:{darwin:["starcraft%20ii.app"],win32:["starcraft ii.exe","SC2_x64.exe","SC2.exe"]},id:13,name:"Starcraft II"},{executables:{win32:["diablo.exe"]},id:14,name:"Diablo"},{executables:{win32:["diablo ii.exe"]},id:15,name:"Diablo 2"},{executables:{win32:["left4dead.exe"]},id:17,name:"Left 4 Dead"},{executables:{darwin:["minecraft.app"],win32:["minecraft.exe"]},id:18,name:"Minecraft"},{executables:{win32:["smite.exe"]},id:19,name:"Smite"},{executables:{win32:["bf4.exe"]},id:20,name:"Battlefield 4"},{executables:{win32:["AoK HD.exe","empires2.exe"]},id:101,name:"Age of Empire II"},{executables:{win32:["age3y.exe"]},id:102,name:"Age of Empire III"},{executables:{win32:["AlanWake.exe"]},id:104,name:"Alan Wake"},{executables:{win32:["alan_wakes_american_nightmare.exe"]},id:105,name:"Alan Wake's American Nightmare"},{executables:{win32:["AlienBreed2Assault.exe"]},id:106,name:"Alien Breed 2: Assault"},{executables:{win32:["Amnesia.exe"]},id:107,name:"Amnesia: The Dark Descent"},{executables:{win32:["UDK.exe"]},id:108,name:"Antichamber"},{executables:{win32:["ArcheAge.exe"]},id:109,name:"ArcheAge"},{executables:{win32:["arma3.exe"]},id:110,name:"Arma III"},{executables:{win32:["AC3SP.exe"]},id:111,name:"Assassin's Creed 3"},{executables:{win32:["Bastion.exe"]},id:112,name:"Bastion"},{executables:{win32:["BF2.exe"]},id:113,name:"Battlefield 2"},{executables:{win32:["bf3.exe"]},id:114,name:"Battlefield 3"},{executables:{win32:["Besiege.exe"]},id:116,name:"Besiege"},{executables:{win32:["Bioshock.exe"]},id:117,name:"Bioshock"},{executables:{win32:["Bioshock2.exe"]},id:118,name:"BioShock II"},{executables:{win32:["BioShockInfinite.exe"]},id:119,name:"BioShock Infinite"},{executables:{win32:["Borderlands2.exe"]},id:122,name:"Borderlands 2"},{executables:{win32:["braid.exe"]},id:123,name:"Braid"},{executables:{win32:["ShippingPC-StormGame.exe"]},id:124,name:"Bulletstorm"},{executables:{},id:125,name:"Cabal 2"},{executables:{win32:["CabalMain.exe"]},id:126,name:"Cabal Online"},{executables:{win32:["iw4mp.exe","iw4sp.exe"]},id:127,name:"Call of Duty: Modern Warfare 2"},{executables:{win32:["t6sp.exe"]},id:128,name:"Call of Duty: Black Ops"},{executables:{win32:["iw5mp.exe"]},id:129,name:"Call of Duty: Modern Warfare 3"},{executables:{win32:["RelicCOH.exe"]},id:132,name:"Company of Heroes"},{executables:{win32:["Crysis64.exe"]},id:135,name:"Crysis"},{executables:{win32:["Crysis2.exe"]},id:136,name:"Crysis 2"},{executables:{win32:["Crysis3.exe"]},id:137,name:"Crysis 3"},{executables:{win32:["Crysis.exe"]},id:138,name:"Crysis 4 "},{executables:{win32:["DATA.exe"]},id:140,name:"Dark Souls"},{executables:{win32:["DarkSoulsII.exe"]},id:141,name:"Dark Souls II"},{executables:{win32:["dfuw.exe"]},id:142,name:"Darkfall: Unholy Wars"},{executables:{win32:["DCGAME.exe"]},id:144,name:"DC Universe Online"},{executables:{win32:["DeadIslandGame.exe"]},id:145,name:"Dead Island"},{executables:{win32:["deadspace2.exe"]},id:146,name:"Dead Space 2"},{executables:{win32:["LOTDGame.exe"]},id:147,name:"Deadlight"},{executables:{win32:["dxhr.exe"]},id:148,name:"Deus Ex: Human Revolution"},{executables:{win32:["DeviMayCry4.exe"]},id:149,name:"Devil May Cry 4"},{executables:{win32:["DMC-DevilMayCry.exe"]},id:150,name:"DmC Devil May Cry"},{executables:{win32:["dirt2_game.exe"]},id:154,name:"DiRT 2"},{executables:{win32:["dirt3_game.exe"]},id:155,name:"DiRT 3"},{executables:{win32:["dota.exe"]},id:156,name:"DOTA"},{executables:{win32:["DoubleDragon.exe"]},id:158,name:"Double Dragon Neon"},{executables:{win32:["DragonAge2.exe"]},id:159,name:"Dragon Age II"},{executables:{win32:["DragonAgeInquisition.exe"]},id:160,name:"Dragon Age: Inquisition"},{executables:{win32:["daorigins.exe"]},id:161,name:"Dragon Age: Origins"},{executables:{win32:["DBXV.exe"]},id:162,name:"Dragon Ball XenoVerse"},{executables:{win32:["DukeForever.exe"]},id:163,name:"Duke Nukem Forever"},{executables:{darwin:["Dustforce.app"],win32:["dustforce.exe"]},id:164,name:"Dustforce"},{executables:{win32:["EliteDangerous32.exe"]},id:165,name:"Elite: Dangerous"},{executables:{win32:["exefile.exe"]},id:166,name:"Eve Online"},{executables:{win32:["eqgame.exe"]},id:167,name:"EverQuest"},{executables:{win32:["EverQuest2.exe"]},id:168,name:"EverQuest II"},{executables:{},id:169,name:"EverQuest Next"},{executables:{win32:["Engine.exe"]},id:170,name:"F.E.A.R."},{executables:{win32:["FEAR2.exe"]},id:171,name:"F.E.A.R. 2: Project Origin"},{executables:{win32:["fallout3.exe"]},id:172,name:"Fallout 3"},{executables:{win32:["FalloutNV.exe"]},id:174,name:"Fallout: New Vegas"},{executables:{win32:["farcry3.exe"]},id:175,name:"Far Cry 3"},{executables:{win32:["fifa15.exe"]},id:176,name:"FIFA 15"},{executables:{win32:["FTLGame.exe"]},id:180,name:"FTL: Faster Than Light"},{executables:{win32:["GTAIV.exe"]},id:181,name:"Grand Theft Auto 4"},{executables:{win32:["GTA5.exe"]},id:182,name:"Grand Theft Auto 5"},{executables:{win32:["Gw.exe"]},id:183,name:"Guild Wars"},{executables:{win32:["H1Z1.exe"]},id:186,name:"H1Z1"},{executables:{win32:["HL2HL2.exe","hl2.exe"]},id:188,name:"Half Life 2"},{executables:{win32:["HOMEFRONT.exe"]},id:195,name:"Homefront"},{executables:{win32:["invisibleinc.exe"]},id:196,name:"Invisible Inc."},{executables:{win32:["LANoire.exe"]},id:197,name:"L.A. Noire"},{executables:{win32:["Landmark64.exe"]},id:198,name:"Landmark"},{executables:{win32:["left4dead2.exe"]},id:201,name:"Left 4 Dead 2"},{executables:{win32:["lineage.exe"]},id:203,name:"Lineage"},{executables:{win32:["Magicka.exe"]},id:206,name:"Magicka"},{executables:{win32:["MapleStory.exe"]},id:208,name:"MapleStory"},{executables:{},id:209,name:"Mark of the Ninja"},{executables:{win32:["MassEffect.exe"]},id:210,name:"Mass Effect"},{executables:{win32:["MassEffect2.exe"]},id:211,name:"Mass Effect 2"},{executables:{win32:["MassEffect3Demo.exe"]},id:212,name:"Mass Effect 3"},{executables:{win32:["METAL GEAR RISING REVENGEANCE.exe"]},id:214,name:"Metal Gear Rising: Revengeance"},{executables:{win32:["metro2033.exe"]},id:215,name:"Metro 2033"},{executables:{win32:["MetroLL.exe"]},id:216,name:"Metro Last Light"},{executables:{win32:["MK10.exe"]},id:218,name:"Mortal Kombat X"},{executables:{win32:["speed.exe"]},id:219,name:"Need For Speed Most Wanted"},{executables:{},id:220,name:"Neverwinder"},{executables:{darwin:["Outlast.app"],win32:["OLGame.exe"]},id:221,name:"Outlast"},{executables:{win32:["PapersPlease.exe"]},id:222,name:"Papers, Please"},{executables:{win32:["payday_win32_release.exe"]},id:223,name:"PAYDAY"},{executables:{win32:["payday2_win32_release.exe"]},id:224,name:"PAYDAY2"},{executables:{win32:["PillarsOfEternity.exe"]},id:225,name:"Pillars of Eternity"},{executables:{win32:["PA.exe"]},id:226,name:"Planetary Annihilation"},{executables:{win32:["planetside2_x86.exe"]},id:227,name:"Planetside 2"},{executables:{win32:["hl2P.exe"]},id:228,name:"Portal"},{executables:{win32:["portal2.exe"]},id:229,name:"Portal 2"},{executables:{win32:["PrimalCarnageGame.exe"]},id:231,name:"Primal Cargnage"},{executables:{win32:["pCARS.exe"]},id:232,name:"Project Cars"},{executables:{win32:["RaceTheSun.exe"]},id:233,name:"Race The Sun"},{executables:{win32:["Rage.exe"]},id:234,name:"RAGE"},{executables:{win32:["ragexe.exe"]},id:235,name:"Ragnarok Online"},{executables:{win32:["rift.exe"]},id:236,name:"Rift"},{executables:{win32:["Rocksmith2014.exe"]},id:237,name:"Rocksmith 2014"},{executables:{win32:["SwiftKit-RS.exe","JagexLauncher.exe"]},id:238,name:"RuneScape"},{executables:{win32:["Shadowgrounds.exe"]},id:239,name:"Shadowgrounds"},{executables:{win32:["survivor.exe"]},id:240,name:"Shadowgrounds: Survivor"},{executables:{win32:["ShovelKnight.exe"]},id:241,name:"Shovel Knight"},{executables:{win32:["SimCity.exe"]},id:242,name:"SimCity"},{executables:{win32:["SporeApp.exe"]},id:245,name:"Spore"},{executables:{win32:["StarCitizen.exe"]},id:246,name:"Star Citizen"},{executables:{},id:247,name:"Star Trek Online"},{executables:{win32:["battlefront.exe"]},id:248,name:"Star Wars Battlefront"},{executables:{win32:["swtor.exe"]},id:249,name:"Star Wars: The Old Republic"},{executables:{win32:["starbound.exe","starbound_opengl.exe"]},id:250,name:"Starbound"},{executables:{win32:["starcraft.exe"]},id:251,name:"Starcraft"},{executables:{win32:["SSFIV.exe"]},id:253,name:"Ultra Street Fighter IV"},{executables:{win32:["superhexagon.exe"]},id:254,name:"Super Hexagon"},{executables:{win32:["swordandsworcery_pc.exe"]},id:255,name:"Superbrothers: Sword & Sworcery EP"},{executables:{win32:["hl2TF.exe"]},id:256,name:"Team Fortress 2"},{executables:{win32:["TERA.exe"]},id:258,name:"TERA"},{executables:{win32:["Terraria.exe"]},id:259,name:"Terraria"},{executables:{win32:["Bethesda.net_Launcher.exe"]},id:260,name:"The Elder Scrolls Online"},{executables:{win32:["TESV.exe"]},id:261,name:"The Elder Scrolls V: Skyrim"},{executables:{win32:["TheSecretWorld.exe"]},id:262,name:"The Secret World"},{executables:{win32:["TS3.exe","ts3w.exe"]},id:264,name:"The Sims 3"},{executables:{win32:["WALKINGDEAD101.EXE"]},id:265,name:"The Walking Dead"},{executables:{win32:["TheWalkingDead2.exe"]},id:266,name:"The Walking Dead Season Two"},{executables:{win32:["witcher3.exe"]},id:267,name:"The Witcher 3"},{executables:{win32:["Future Soldier.exe"]},id:268,name:"Tom Clancy's Ghost Recon: Future Solider"},{executables:{win32:["TombRaider.exe"]},id:269,name:"Tomb Raider (2013)"},{executables:{win32:["Torchlight.exe"]},id:271,name:"Torchlight"},{executables:{win32:["Torchlight2.exe"]},id:272,name:"Torchlight 2"},{executables:{win32:["Shogun2.exe"]},id:273,name:"Total War: Shogun 2"},{executables:{win32:["Transistor.exe"]},id:274,name:"Transistor"},{executables:{win32:["trine.exe"]},id:275,name:"Trine"},{executables:{win32:["trine2_32bit.exe"]},id:276,name:"Trine 2"},{executables:{win32:["UOKR.exe"]},id:277,name:"Ultima Online"},{executables:{win32:["aces.exe"]},id:279,name:"War Thunder"},{executables:{win32:["Warcraft III.exe","wc3.exe"]},id:281,name:"Warcraft 3: Reign of Chaos"},{executables:{win32:["Warcraft II BNE.exe"]},id:282,name:"Warcraft II"},{executables:{win32:["Warframe.x64.exe","Warframe.exe"]},id:283,name:"Warframe"},{executables:{win32:["watch_dogs.exe"]},id:284,name:"Watch Dogs"},{executables:{win32:["WildStar64.exe"]},id:285,name:"WildStar"},{executables:{win32:["XComGame.exe"]},id:288,name:"XCOM: Enemy Unknown"},{executables:{win32:["DFO.exe","dfo.exe"]},id:289,name:"Dungeon Fighter Online"},{executables:{win32:["aclauncher.exe","acclient.exe"]},id:290,name:"Asheron's Call"},{executables:{win32:["MapleStory2.exe"]},id:291,name:"MapleStory 2"},{executables:{win32:["ksp.exe"]},id:292,name:"Kerbal Space Program"},{executables:{win32:["PINBALL.EXE"]},id:293,name:"3D Pinball: Space Cadet"},{executables:{win32:["dave.exe"]},id:294,name:"Dangerous Dave"},{executables:{win32:["iwbtgbeta(slomo).exe","iwbtgbeta(fs).exe"]}, +id:295,name:"I Wanna Be The Guy"},{executables:{win32:["MechWarriorOnline.exe "]},id:296,name:"Mech Warrior Online"},{executables:{win32:["dontstarve_steam.exe"]},id:297,name:"Don't Starve"},{executables:{win32:["GalCiv3.exe"]},id:298,name:"Galactic Civilization 3"},{executables:{win32:["Risk of Rain.exe"]},id:299,name:"Risk of Rain"},{executables:{win32:["Binding_of_Isaac.exe","Isaac-ng.exe"]},id:300,name:"The Binding of Isaac"},{executables:{win32:["RustClient.exe"]},id:301,name:"Rust"},{executables:{win32:["Clicker Heroes.exe"]},id:302,name:"Clicker Heroes"},{executables:{win32:["Brawlhalla.exe"]},id:303,name:"Brawlhalla"},{executables:{win32:["TownOfSalem.exe"]},id:304,name:"Town of Salem"},{executables:{win32:["osu!.exe"]},id:305,name:"osu!"},{executables:{win32:["PathOfExileSteam.exe","PathOfExile.exe"]},id:306,name:"Path of Exile"},{executables:{win32:["Dolphin.exe"]},id:307,name:"Dolphin"},{executables:{win32:["RocketLeague.exe"]},id:308,name:"Rocket League"},{executables:{win32:["TJPP.exe"]},id:309,name:"Jackbox Party Pack"},{executables:{win32:["KFGame.exe"]},id:310,name:"Killing Floor 2"},{executables:{win32:["ShooterGame.exe"]},id:311,name:"Ark: Survival Evolved"},{executables:{win32:["LifeIsStrange.exe"]},id:312,name:"Life Is Strange"},{executables:{win32:["Client_tos.exe"]},id:313,name:"Tree of Savior"},{executables:{win32:["olliolli2.exe"]},id:314,name:"OlliOlli2"},{executables:{win32:["cw.exe"]},id:315,name:"Closers Dimension Conflict"},{executables:{win32:["ESSTEAM.exe","elsword.exe","x2.exe"]},id:316,name:"Elsword"},{executables:{win32:["ori.exe"]},id:317,name:"Ori and the Blind Forest"},{executables:{win32:["Skyforge.exe"]},id:318,name:"Skyforge"},{executables:{win32:["projectzomboid64.exe","projectzomboid32.exe"]},id:319,name:"Project Zomboid"},{executables:{win32:["From_The_Depths.exe"]},id:320,name:"The Depths"},{executables:{win32:["TheCrew.exe"]},id:321,name:"The Crew"},{executables:{win32:["MarvelHeroes2015.exe"]},id:322,name:"Marvel Heroes 2015"},{executables:{win32:["timeclickers.exe"]},id:324,name:"Time Clickers"},{executables:{win32:["eurotrucks2.exe"]},id:325,name:"Euro Truck Simulator 2"},{executables:{win32:["FarmingSimulator2015Game.exe"]},id:326,name:"Farming Simulator 15"},{executables:{win32:["strife.exe"]},id:327,name:"Strife"},{executables:{win32:["Awesomenauts.exe"]},id:328,name:"Awesomenauts"},{executables:{win32:["Dofus.exe"]},id:329,name:"Dofus"},{executables:{win32:["Boid.exe"]},id:330,name:"Boid"},{executables:{win32:["adventure-capitalist.exe"]},id:331,name:"AdVenture Capitalist"},{executables:{win32:["OrcsMustDie2.exe"]},id:332,name:"Orcs Must Die! 2"},{executables:{win32:["Mountain.exe"]},id:333,name:"Mountain"},{executables:{win32:["Valkyria.exe"]},id:335,name:"Valkyria Chronicles"},{executables:{win32:["ffxiiiimg.exe"]},id:336,name:"Final Fantasy XIII"},{executables:{win32:["TLR.exe"]},id:337,name:"The Last Remnant"},{executables:{win32:["Cities.exe"]},id:339,name:"Cities Skylines"},{executables:{win32:["worldofwarships.exe","WoWSLauncher.exe"]},id:341,name:"World of Warships"},{executables:{win32:["spacegame-Win64-shipping.exe"]},id:342,name:"Fractured Space"},{executables:{win32:["thespacegame.exe"]},id:343,name:"Ascent - The Space Game"},{executables:{win32:["DuckGame.exe"]},id:344,name:"Duck Game"},{executables:{win32:["PPSSPPWindows.exe"]},id:345,name:"PPSSPP"},{executables:{win32:["MBAA.exe"]},id:346,name:"Melty Blood Actress Again: Current Code"},{executables:{win32:["TheWolfAmongUs.exe"]},id:347,name:"The Wolf Among Us"},{executables:{win32:["SpaceEngineers.exe"]},id:348,name:"Space Engineers"},{executables:{win32:["Borderlands.exe"]},id:349,name:"Borderlands"},{executables:{win32:["100orange.exe"]},id:351,name:"100% Orange Juice"},{executables:{win32:["reflex.exe"]},id:354,name:"Reflex"},{executables:{win32:["pso2.exe"]},id:355,name:"Phantasy Star Online 2"},{executables:{win32:["AssettoCorsa.exe"]},id:356,name:"Assetto Corsa"},{executables:{win32:["iw3mp.exe","iw3sp.exe"]},id:357,name:"Call of Duty 4: Modern Warfare"},{executables:{win32:["WolfOldBlood_x64.exe"]},id:358,name:"Wolfenstein: The Old Blood"},{executables:{win32:["castle.exe"]},id:359,name:"Castle Crashers"},{executables:{win32:["vindictus.exe"]},id:360,name:"Vindictus"},{executables:{win32:["ShooterGame-Win32-Shipping.exe"]},id:361,name:"Dirty Bomb"},{executables:{win32:["BatmanAK.exe"]},id:362,name:"Batman Arkham Knight"},{executables:{win32:["drt.exe"]},id:363,name:"Dirt Rally"},{executables:{win32:["rFactor.exe"]},id:364,name:"rFactor"},{executables:{win32:["clonk.exe"]},id:365,name:"Clonk Rage"},{executables:{win32:["SRHK.exe"]},id:366,name:"Shadowrun: Hong Kong"},{executables:{win32:["Insurgency.exe"]},id:367,name:"Insurgency"},{executables:{win32:["StepMania.exe"]},id:368,name:"Step Mania"},{executables:{win32:["FirefallCLient.exe"]},id:369,name:"Firefall"},{executables:{win32:["mirrorsedge.exe"]},id:370,name:"Mirrors Edge"},{executables:{win32:["MgsGroundZeroes.exe"]},id:371,name:"Metal Gear Solid V: Ground Zeroes"},{executables:{win32:["mgsvtpp.exe"]},id:372,name:"Metal Gear Solid V: The Phantom Pain"},{executables:{win32:["tld.exe"]},id:373,name:"The Long Dark"},{executables:{win32:["TKOM.exe"]},id:374,name:"Take On Mars"},{executables:{win32:["robloxplayerlauncher.exe","Roblox.exe"]},id:375,name:"Roblox"},{executables:{win32:["eu4.exe"]},id:376,name:"Europa Universalis 4"},{executables:{win32:["APB.exe"]},id:377,name:"APB Reloaded"},{executables:{win32:["Robocraft.exe"]},id:378,name:"Robocraft"},{executables:{win32:["Unity.exe"]},id:379,name:"Unity"},{executables:{win32:["Simpsons.exe"]},id:380,name:"The Simpsons: Hit & Run"},{executables:{win32:["Dnlauncher.exe","DragonNest.exe"]},id:381,name:"Dragon Nest"},{executables:{win32:["Trove.exe"]},id:382,name:"Trove"},{executables:{win32:["EndlessLegend.exe"]},id:383,name:"Endless Legend"},{executables:{win32:["TurbineLauncher.exe","dndclient.exe"]},id:384,name:"Dungeons & Dragons Online"},{executables:{win32:["quakelive.exe","quakelive_steam.exe"]},id:385,name:"Quake Live"},{executables:{win32:["7DaysToDie.exe"]},id:386,name:"7DaysToDie"},{executables:{win32:["SpeedRunners.exe"]},id:387,name:"SpeedRunners"},{executables:{win32:["gamemd.exe"]},id:388,name:"Command & Conquer: Red Alert 2"},{executables:{win32:["generals.exe"]},id:389,name:"Command & Conquer Generals: Zero Hour"},{executables:{win32:["Oblivion.exe"]},id:390,name:"The Elder Scrolls 4: Oblivion"},{executables:{win32:["mgsi.exe"]},id:391,name:"Metal Gear Solid"},{executables:{win32:["EoCApp.exe"]},id:392,name:"Divinity - Original Sin"},{executables:{win32:["Torment.exe"]},id:393,name:"Planescape: Torment"},{executables:{win32:["HexPatch.exe"]},id:394,name:"Hex: Shards of Fate"},{executables:{win32:["NS3FB.exe"]},id:395,name:"Naruto Shippuden Ultimate Ninja Storm 3 Full Burst"},{executables:{win32:["NSUNSR.exe"]},id:396,name:"Naruto Shippuden Ultimate Ninja Storm Revolution"},{executables:{win32:["SaintsRowIV.exe"]},id:397,name:"Saints Row IV"},{executables:{win32:["Shadowrun.exe"]},id:398,name:"Shadowrun"},{executables:{win32:["DungeonoftheEndless.exe"]},id:399,name:"Dungeon of the Endless"},{executables:{win32:["Hon.exe"]},id:400,name:"Heroes of Newerth"},{executables:{win32:["mabinogi.exe"]},id:401,name:"Mabinogi"},{executables:{win32:["CoD2MP_s.exe","CoDSP_s.exe"]},id:402,name:"Call of Duty 2:"},{executables:{win32:["CoDWaWmp.exe","CoDWaw.exe"]},id:403,name:"Call of Duty: World at War"},{executables:{win32:["heroes.exe"]},id:404,name:"Mabinogi Heroes (Vindictus) "},{executables:{win32:["KanColleViewer.exe"]},id:405,name:"KanColle "},{executables:{win32:["cyphers.exe"]},id:406,name:"Cyphers"},{executables:{win32:["RelicCoH2.exe"]},id:407,name:"Company of Heroes 2"},{executables:{win32:["MJ.exe"]},id:408,name:"セガNET麻雀MJ"},{executables:{win32:["ge.exe"]},id:409,name:"Granado Espada"},{executables:{win32:["NovaRO.exe"]},id:410,name:"Nova Ragnarok Online"},{executables:{win32:["RivalsofAether.exe"]},id:411,name:"Rivals of Aether"},{executables:{win32:["bfh.exe"]},id:412,name:"Battlefield Hardline"},{executables:{win32:["GrowHome.exe"]},id:413,name:"Grow Home"},{executables:{win32:["patriots.exe"]},id:414,name:"Rise of Nations Extended"},{executables:{win32:["Railroads.exe"]},id:415,name:"Sid Meier's Railroads!"},{executables:{win32:["Empire.exe"]},id:416,name:"Empire: Total War"},{executables:{win32:["Napoleon.exe"]},id:417,name:"Napoleon: Total War"},{executables:{win32:["gta_sa.exe"]},id:418,name:"Grand Theft Auto: San Andreas"},{executables:{win32:["MadMax.exe"]},id:419,name:"Mad Max"},{executables:{win32:["Titanfall.exe"]},id:420,name:"Titanfall"},{executables:{win32:["age2_x1.exe"]},id:421,name:"Age of Empires II: The Conquerors"},{executables:{win32:["Rome2.exe"]},id:422,name:"Total War: ROME 2"},{executables:{win32:["ShadowOfMordor.exe"]},id:423,name:"Middle-earth: Shadow of Mordor"},{executables:{win32:["Subnautica.exe"]},id:424,name:"Subnautica"},{executables:{win32:["anno5.exe"]},id:425,name:"Anno 2070"},{executables:{win32:["carrier.exe"]},id:426,name:"Carrier Command Gaea Mission"},{executables:{win32:["DarksidersPC.exe"]},id:427,name:"Darksiders"},{executables:{win32:["Darksiders2.exe"]},id:428,name:"Darksiders 2"},{executables:{win32:["mudlet.exe"]},id:429,name:"Mudlet"},{executables:{win32:["DunDefLauncher.exe"]},id:430,name:"Dungeon Defenders II"},{executables:{win32:["hng.exe"]},id:431,name:"Heroes and Generals"},{executables:{win32:["WFTOGame.exe"]},id:432,name:"War of the Overworld"},{executables:{win32:["Talisman.exe"]},id:433,name:"Talisman: Digital Edition"},{executables:{win32:["limbo.exe"]},id:434,name:"Limbo"},{executables:{win32:["ibbobb.exe"]},id:435,name:"ibb & obb"},{executables:{win32:["BattleBlockTheater.exe"]},id:436,name:"BattleBlock Theater"},{executables:{win32:["iracinglauncher.exe","iracingsim.exe","iracingsim64.exe"]},id:437,name:"iRacing"},{executables:{win32:["CivilizationV_DX11.exe"]},id:438,name:"Civilization V"}]},{}]},{},[9])(9)}); \ No newline at end of file From 0f82202a6bd56e4f5936e6dbcb5fd256055fae04 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 25 Oct 2015 22:05:15 +0000 Subject: [PATCH 149/151] Added npmignore for tinier installations --- .npmignore | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .npmignore diff --git a/.npmignore b/.npmignore new file mode 100644 index 000000000..d7d6c67e1 --- /dev/null +++ b/.npmignore @@ -0,0 +1,5 @@ +.vscode/ +docs/ +examples/ +web-dist/ +.travis.yml \ No newline at end of file diff --git a/package.json b/package.json index 37b9644d3..5cc1e0db0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.9.0", + "version": "3.9.1", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { From a577f968fa91f46f552c346c35e0d1d09c7a6f2d Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 25 Oct 2015 22:11:16 +0000 Subject: [PATCH 150/151] fixed typo in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9412f2a87..8521d3207 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ discord.js is a node module used as a way of interfacing with [Discord](https://discordapp.com/). It is a very useful module for creating bots. -**The examples in the repo are in EC6, either update your node or compile them down to babel yourself if you want to use them!** +**The examples in the repo are in ES6, either update your node or compile them down to babel yourself if you want to use them!** ### Installation `npm install --save discord.js` From dbbeba56d9209d762c979d12d23e208ded4cc0af Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sun, 25 Oct 2015 22:25:30 +0000 Subject: [PATCH 151/151] Added setAvatar --- lib/ChannelPermissions.js | 182 +++- lib/Client.js | 1776 +++++++++++++++++++++++++++++++++-- lib/Endpoints.js | 14 +- lib/EvaluatedPermissions.js | 188 +++- lib/Member.js | 161 +++- lib/PMChannel.js | 62 +- lib/ServerPermissions.js | 201 +++- lib/channel.js | 132 ++- lib/index.js | 37 +- lib/internal.js | 204 +++- lib/invite.js | 36 +- lib/message.js | 78 +- lib/server.js | 284 +++++- lib/user.js | 61 +- src/Client.js | 56 +- test/bot.1.js | 14 +- 16 files changed, 3360 insertions(+), 126 deletions(-) diff --git a/lib/ChannelPermissions.js b/lib/ChannelPermissions.js index e5fe374b5..5193b5938 100644 --- a/lib/ChannelPermissions.js +++ b/lib/ChannelPermissions.js @@ -1,2 +1,180 @@ -"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var ChannelPermissions=(function(){function ChannelPermissions(data,channel){_classCallCheck(this,ChannelPermissions);var self=this;function getBit(x){return (self.packed >>> x & 1) === 1;}this.type = data.type; //either member or role -this.id = data.id;if(this.type === "member"){this.packed = channel.server.getMember("id",data.id).evalPerms.packed;}else {this.packed = channel.server.getRole(data.id).packed;}this.packed = this.packed & ~data.deny;this.packed = this.packed | data.allow;this.deny = data.deny;this.allow = data.allow;}ChannelPermissions.prototype.getBit = function getBit(x){return (this.packed >>> x & 1) === 1;};ChannelPermissions.prototype.setBit = function setBit(){};_createClass(ChannelPermissions,[{key:"createInstantInvite",get:function get(){return this.getBit(0);},set:function set(val){this.setBit(0,val);}},{key:"manageRoles",get:function get(){return this.getBit(3);},set:function set(val){this.setBit(3,val);}},{key:"manageChannels",get:function get(){return this.getBit(4);},set:function set(val){this.setBit(4,val);}},{key:"readMessages",get:function get(){return this.getBit(10);},set:function set(val){this.setBit(10,val);}},{key:"sendMessages",get:function get(){return this.getBit(11);},set:function set(val){this.setBit(11,val);}},{key:"sendTTSMessages",get:function get(){return this.getBit(12);},set:function set(val){this.setBit(12,val);}},{key:"manageMessages",get:function get(){return this.getBit(13);},set:function set(val){this.setBit(13,val);}},{key:"embedLinks",get:function get(){return this.getBit(14);},set:function set(val){this.setBit(14,val);}},{key:"attachFiles",get:function get(){return this.getBit(15);},set:function set(val){this.setBit(15,val);}},{key:"readMessageHistory",get:function get(){return this.getBit(16);},set:function set(val){this.setBit(16,val);}},{key:"mentionEveryone",get:function get(){return this.getBit(17);},set:function set(val){this.setBit(17,val);}},{key:"voiceConnect",get:function get(){return this.getBit(20);},set:function set(val){this.setBit(20,val);}},{key:"voiceSpeak",get:function get(){return this.getBit(21);},set:function set(val){this.setBit(21,val);}},{key:"voiceMuteMembers",get:function get(){return this.getBit(22);},set:function set(val){this.setBit(22,val);}},{key:"voiceDeafenMembers",get:function get(){return this.getBit(23);},set:function set(val){this.setBit(23,val);}},{key:"voiceMoveMembers",get:function get(){return this.getBit(24);},set:function set(val){this.setBit(24,val);}},{key:"voiceUseVoiceActivation",get:function get(){return this.getBit(25);},set:function set(val){this.setBit(25,val);}}]);return ChannelPermissions;})();module.exports = ChannelPermissions; +"use strict"; + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var ChannelPermissions = (function () { + function ChannelPermissions(data, channel) { + _classCallCheck(this, ChannelPermissions); + + var self = this; + + function getBit(x) { + return (self.packed >>> x & 1) === 1; + } + + this.type = data.type; //either member or role + this.id = data.id; + + if (this.type === "member") { + this.packed = channel.server.getMember("id", data.id).evalPerms.packed; + } else { + this.packed = channel.server.getRole(data.id).packed; + } + + this.packed = this.packed & ~data.deny; + this.packed = this.packed | data.allow; + + this.deny = data.deny; + this.allow = data.allow; + } + + ChannelPermissions.prototype.getBit = function getBit(x) { + return (this.packed >>> x & 1) === 1; + }; + + ChannelPermissions.prototype.setBit = function setBit() {}; + + _createClass(ChannelPermissions, [{ + key: "createInstantInvite", + get: function get() { + return this.getBit(0); + }, + set: function set(val) { + this.setBit(0, val); + } + }, { + key: "manageRoles", + get: function get() { + return this.getBit(3); + }, + set: function set(val) { + this.setBit(3, val); + } + }, { + key: "manageChannels", + get: function get() { + return this.getBit(4); + }, + set: function set(val) { + this.setBit(4, val); + } + }, { + key: "readMessages", + get: function get() { + return this.getBit(10); + }, + set: function set(val) { + this.setBit(10, val); + } + }, { + key: "sendMessages", + get: function get() { + return this.getBit(11); + }, + set: function set(val) { + this.setBit(11, val); + } + }, { + key: "sendTTSMessages", + get: function get() { + return this.getBit(12); + }, + set: function set(val) { + this.setBit(12, val); + } + }, { + key: "manageMessages", + get: function get() { + return this.getBit(13); + }, + set: function set(val) { + this.setBit(13, val); + } + }, { + key: "embedLinks", + get: function get() { + return this.getBit(14); + }, + set: function set(val) { + this.setBit(14, val); + } + }, { + key: "attachFiles", + get: function get() { + return this.getBit(15); + }, + set: function set(val) { + this.setBit(15, val); + } + }, { + key: "readMessageHistory", + get: function get() { + return this.getBit(16); + }, + set: function set(val) { + this.setBit(16, val); + } + }, { + key: "mentionEveryone", + get: function get() { + return this.getBit(17); + }, + set: function set(val) { + this.setBit(17, val); + } + }, { + key: "voiceConnect", + get: function get() { + return this.getBit(20); + }, + set: function set(val) { + this.setBit(20, val); + } + }, { + key: "voiceSpeak", + get: function get() { + return this.getBit(21); + }, + set: function set(val) { + this.setBit(21, val); + } + }, { + key: "voiceMuteMembers", + get: function get() { + return this.getBit(22); + }, + set: function set(val) { + this.setBit(22, val); + } + }, { + key: "voiceDeafenMembers", + get: function get() { + return this.getBit(23); + }, + set: function set(val) { + this.setBit(23, val); + } + }, { + key: "voiceMoveMembers", + get: function get() { + return this.getBit(24); + }, + set: function set(val) { + this.setBit(24, val); + } + }, { + key: "voiceUseVoiceActivation", + get: function get() { + return this.getBit(25); + }, + set: function set(val) { + this.setBit(25, val); + } + }]); + + return ChannelPermissions; +})(); + +module.exports = ChannelPermissions; \ No newline at end of file diff --git a/lib/Client.js b/lib/Client.js index 335061bd6..6f5b8eb32 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1,75 +1,1705 @@ //discord.js modules -"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 Endpoints=require("./Endpoints.js");var User=require("./user.js");var Server=require("./server.js");var Channel=require("./channel.js");var Message=require("./message.js");var Invite=require("./invite.js");var PMChannel=require("./PMChannel.js");var gameMap=require("../ref/gameMap.json"); //node modules -var request=require("superagent");var WebSocket=require("ws");var fs=require("fs");var defaultOptions={queue:false};var Client=(function(){function Client(){var options=arguments.length <= 0 || arguments[0] === undefined?defaultOptions:arguments[0];var token=arguments.length <= 1 || arguments[1] === undefined?undefined:arguments[1];_classCallCheck(this,Client); /* - When created, if a token is specified the Client will - try connecting with it. If the token is incorrect, no - further efforts will be made to connect. - */this.options = options;this.options.queue = this.options.queue;this.token = token;this.state = 0;this.websocket = null;this.events = {};this.user = null;this.alreadySentData = false;this.serverCreateListener = {};this.typingIntervals = {};this.email = "abc";this.password = "abc"; /* - State values: - 0 - idle - 1 - logging in - 2 - logged in - 3 - ready - 4 - disconnected - */this.userCache = [];this.channelCache = [];this.serverCache = [];this.pmChannelCache = [];this.readyTime = null;this.checkingQueue = {};this.userTypingListener = {};this.queue = {};this.__idleTime = null;this.__gameId = null;}Client.prototype.sendPacket = function sendPacket(JSONObject){if(this.websocket.readyState === 1){this.websocket.send(JSON.stringify(JSONObject));}}; //def debug -Client.prototype.debug = function debug(message){this.trigger("debug",message);};Client.prototype.on = function on(event,fn){this.events[event] = fn;};Client.prototype.off = function off(event){this.events[event] = null;};Client.prototype.keepAlive = function keepAlive(){this.debug("keep alive triggered");this.sendPacket({op:1,d:Date.now()});}; //def trigger -Client.prototype.trigger = function trigger(event){var args=[];for(var arg in arguments) {args.push(arguments[arg]);}var evt=this.events[event];if(evt){evt.apply(this,args.slice(1));}}; //def login -Client.prototype.login = function login(){var email=arguments.length <= 0 || arguments[0] === undefined?"foo@bar.com":arguments[0];var password=arguments.length <= 1 || arguments[1] === undefined?"pass1234":arguments[1];var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,token){}:arguments[2];var self=this;return new Promise(function(resolve,reject){if(self.state === 0 || self.state === 4){self.state = 1; //set the state to logging in -self.email = email;self.password = password;request.post(Endpoints.LOGIN).send({email:email,password:password}).end(function(err,res){if(err){self.state = 4; //set state to disconnected -self.trigger("disconnected");if(self.websocket){self.websocket.close();}callback(err);reject(err);}else {self.state = 2; //set state to logged in (not yet ready) -self.token = res.body.token; //set our token -self.getGateway().then(function(url){self.createws(url);callback(null,self.token);resolve(self.token);})["catch"](function(err){callback(err);reject(err);});}});}else {reject(new Error("Client already logging in or ready"));}});};Client.prototype.logout = function logout(){var callback=arguments.length <= 0 || arguments[0] === undefined?function(err){}:arguments[0];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.LOGOUT).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {self.websocket.close();self.state = 4;callback();resolve();}});});};Client.prototype.createServer = function createServer(name,region){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,server){}:arguments[2];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.SERVERS).set("authorization",self.token).send({name:name,region:region}).end(function(err,res){if(err){callback(err);reject(err);}else { // potentially redundant in future -// creating here does NOT give us the channels of the server -// so we must wait for the guild_create event. -self.serverCreateListener[res.body.id] = [resolve,callback]; /*var srv = self.addServer(res.body); - callback(null, srv); - resolve(srv);*/}});});};Client.prototype.createChannel = function createChannel(server,channelName,channelType){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,chann){}:arguments[3];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.SERVERS + "/" + self.resolveServerID(server) + "/channels").set("authorization",self.token).send({name:channelName,type:channelType}).end(function(err,res){if(err){callback(err);reject(err);}else {var server=self.getServer("id",res.body.guild_id);var chann=self.addChannel(res.body,res.body.guild_id);server.addChannel(chann);callback(null,chann);resolve(chann);}});});};Client.prototype.leaveServer = function leaveServer(server){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,server){}:arguments[1];var self=this;return new Promise(function(resolve,reject){request.del(Endpoints.SERVERS + "/" + self.resolveServerID(server)).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {self.serverCache.splice(self.serverCache.indexOf(server),1);callback(null);resolve();}});});};Client.prototype.createInvite = function createInvite(serverOrChannel,options){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,invite){}:arguments[2];var self=this;return new Promise(function(resolve,reject){var destination;if(serverOrChannel instanceof Server){destination = serverOrChannel.id;}else if(serverOrChannel instanceof Channel){destination = serverOrChannel.id;}else {destination = serverOrChannel;}options = options || {};options.max_age = options.maxAge || 0;options.max_uses = options.maxUses || 0;options.temporary = options.temporary || false;options.xkcdpass = options.xkcd || false;request.post(Endpoints.CHANNELS + "/" + destination + "/invites").set("authorization",self.token).send(options).end(function(err,res){if(err){callback(err);reject(err);}else {var inv=new Invite(res.body,self);callback(null,inv);resolve(inv);}});});};Client.prototype.startPM = function startPM(user){var self=this;return new Promise(function(resolve,reject){var userId=user;if(user instanceof User){userId = user.id;}request.post(Endpoints.USERS + "/" + self.user.id + "/channels").set("authorization",self.token).send({recipient_id:userId}).end(function(err,res){if(err){reject(err);}else {resolve(self.addPMChannel(res.body));}});});};Client.prototype.reply = function reply(destination,message,tts){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var self=this;return new Promise(function(response,reject){if(typeof tts === "function"){ // tts is a function, which means the developer wants this to be the callback -callback = tts;tts = false;}var user=destination.sender;self.sendMessage(destination,message,tts,callback,user + ", ").then(response)["catch"](reject);});};Client.prototype.deleteMessage = function deleteMessage(message,timeout){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,msg){}:arguments[2];var self=this;return new Promise(function(resolve,reject){if(timeout){setTimeout(remove,timeout);}else {remove();}function remove(){request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization",self.token).end(function(err,res){if(err){bad();}else {good();}});}function good(){callback();resolve();}function bad(err){callback(err);reject(err);}});};Client.prototype.updateMessage = function updateMessage(message,content){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,msg){}:arguments[2];var self=this;var prom=new Promise(function(resolve,reject){content = content instanceof Array?content.join("\n"):content;if(self.options.queue){if(!self.queue[message.channel.id]){self.queue[message.channel.id] = [];}self.queue[message.channel.id].push({action:"updateMessage",message:message,content:content,then:good,error:bad});self.checkQueue(message.channel.id);}else {self._updateMessage(message,content).then(good)["catch"](bad);}function good(msg){prom.message = msg;callback(null,msg);resolve(msg);}function bad(error){prom.error = error;callback(error);reject(error);}});return prom;};Client.prototype.setUsername = function setUsername(newName){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){request.patch(Endpoints.API + "/users/@me").set("authorization",self.token).send({avatar:self.user.avatar,email:self.email,new_password:null,password:self.password,username:newName}).end(function(err){callback(err);if(err)reject(err);else resolve();});});};Client.prototype.getChannelLogs = function getChannelLogs(channel){var amount=arguments.length <= 1 || arguments[1] === undefined?500:arguments[1];var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,logs){}:arguments[2];var self=this;return new Promise(function(resolve,reject){var channelID=channel;if(channel instanceof Channel){channelID = channel.id;}request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {var logs=[];var channel=self.getChannel("id",channelID);for(var _iterator=res.body,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var message=_ref;var mentions=[];for(var _iterator2=message.mentions,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var mention=_ref2;mentions.push(self.addUser(mention));}var author=self.addUser(message.author);logs.push(new Message(message,channel,mentions,author));}callback(null,logs);resolve(logs);}});});};Client.prototype.deleteChannel = function deleteChannel(channel){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){var channelID=channel;if(channel instanceof Channel){channelID = channel.id;}request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization",self.token).end(function(err){if(err){callback(err);reject(err);}else {callback(null);resolve();}});});};Client.prototype.joinServer = function joinServer(invite){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,server){}:arguments[1];var self=this;return new Promise(function(resolve,reject){var id=invite instanceof Invite?invite.code:invite;request.post(Endpoints.API + "/invite/" + id).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {if(self.getServer("id",res.body.guild.id)){resolve(self.getServer("id",res.body.guild.id));}else {self.serverCreateListener[res.body.guild.id] = [resolve,callback];}}});});};Client.prototype.sendFile = function sendFile(destination,file){var fileName=arguments.length <= 2 || arguments[2] === undefined?"image.png":arguments[2];var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var self=this;var prom=new Promise(function(resolve,reject){var fstream;if(typeof file === "string" || file instanceof String){fstream = fs.createReadStream(file);fileName = file;}else {fstream = file;}self.resolveDestination(destination).then(send)["catch"](bad);function send(destination){if(self.options.queue){ //queue send file too -if(!self.queue[destination]){self.queue[destination] = [];}self.queue[destination].push({action:"sendFile",attachment:fstream,attachmentName:fileName,then:good,error:bad});self.checkQueue(destination);}else { //not queue -self._sendFile(destination,fstream,fileName).then(good)["catch"](bad);}}function good(msg){prom.message = msg;callback(null,msg);resolve(msg);}function bad(err){prom.error = err;callback(err);reject(err);}});return prom;};Client.prototype.sendMessage = function sendMessage(destination,message,tts){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var premessage=arguments.length <= 4 || arguments[4] === undefined?"":arguments[4];var self=this;var prom=new Promise(function(resolve,reject){if(typeof tts === "function"){ // tts is a function, which means the developer wants this to be the callback -callback = tts;tts = false;}message = premessage + resolveMessage(message);var mentions=resolveMentions();self.resolveDestination(destination).then(send)["catch"](error);function error(err){callback(err);reject(err);}function send(destination){if(self.options.queue){ //we're QUEUEING messages, so sending them sequentially based on servers. -if(!self.queue[destination]){self.queue[destination] = [];}self.queue[destination].push({action:"sendMessage",content:message,mentions:mentions,tts:!!tts, //incase it's not a boolean -then:mgood,error:mbad});self.checkQueue(destination);}else {self._sendMessage(destination,message,tts,mentions).then(mgood)["catch"](mbad);}}function mgood(msg){prom.message = msg;callback(null,msg);resolve(msg);}function mbad(error){prom.error = error;callback(error);reject(error);}function resolveMessage(){var msg=message;if(message instanceof Array){msg = message.join("\n");}return msg;}function resolveMentions(){var _mentions=[];for(var _iterator3=message.match(/<@[^>]*>/g) || [],_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[Symbol.iterator]();;) {var _ref3;if(_isArray3){if(_i3 >= _iterator3.length)break;_ref3 = _iterator3[_i3++];}else {_i3 = _iterator3.next();if(_i3.done)break;_ref3 = _i3.value;}var mention=_ref3;_mentions.push(mention.substring(2,mention.length - 1));}return _mentions;}});return prom;}; //def createws -Client.prototype.createws = function createws(url){if(this.websocket)return false;var self=this; //good to go -this.websocket = new WebSocket(url); //open -this.websocket.onopen = function(){self.trySendConnData(); //try connecting -}; //close -this.websocket.onclose = function(){self.trigger("disconnected");}; //message -this.websocket.onmessage = function(e){var dat=false,data={};try{dat = JSON.parse(e.data);data = dat.d;}catch(err) {self.trigger("error",err,e);return;}self.trigger("raw",dat); //valid message -switch(dat.t){case "READY":self.debug("received ready packet");self.user = self.addUser(data.user);for(var _iterator4=data.guilds,_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[Symbol.iterator]();;) {var _ref4;if(_isArray4){if(_i4 >= _iterator4.length)break;_ref4 = _iterator4[_i4++];}else {_i4 = _iterator4.next();if(_i4.done)break;_ref4 = _i4.value;}var _server=_ref4;var server=self.addServer(_server);}for(var _iterator5=data.private_channels,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var _pmc=_ref5;var pmc=self.addPMChannel(_pmc);}self.trigger("ready");self.readyTime = Date.now();self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users.");self.state = 3;setInterval(function(){self.keepAlive.apply(self);},data.heartbeat_interval);break;case "MESSAGE_CREATE":self.debug("received message");var mentions=[];data.mentions = data.mentions || []; //for some reason this was not defined at some point? -for(var _iterator6=data.mentions,_isArray6=Array.isArray(_iterator6),_i6=0,_iterator6=_isArray6?_iterator6:_iterator6[Symbol.iterator]();;) {var _ref6;if(_isArray6){if(_i6 >= _iterator6.length)break;_ref6 = _iterator6[_i6++];}else {_i6 = _iterator6.next();if(_i6.done)break;_ref6 = _i6.value;}var mention=_ref6;mentions.push(self.addUser(mention));}var channel=self.getChannel("id",data.channel_id);if(channel){var msg=channel.addMessage(new Message(data,channel,mentions,self.addUser(data.author)));self.trigger("message",msg);}break;case "MESSAGE_DELETE":self.debug("message deleted");var channel=self.getChannel("id",data.channel_id);var message=channel.getMessage("id",data.id);if(message){self.trigger("messageDelete",channel,message);channel.messages.splice(channel.messages.indexOf(message),1);}else { //don't have the cache of that message ;( -self.trigger("messageDelete",channel);}break;case "MESSAGE_UPDATE":self.debug("message updated");var channel=self.getChannel("id",data.channel_id);var formerMessage=channel.getMessage("id",data.id);if(formerMessage){ //new message might be partial, so we need to fill it with whatever the old message was. -var info={};for(var key in formerMessage) {info[key] = formerMessage[key];}for(var key in data) {info[key] = data[key];}var mentions=[];for(var _iterator7=info.mentions,_isArray7=Array.isArray(_iterator7),_i7=0,_iterator7=_isArray7?_iterator7:_iterator7[Symbol.iterator]();;) {var _ref7;if(_isArray7){if(_i7 >= _iterator7.length)break;_ref7 = _iterator7[_i7++];}else {_i7 = _iterator7.next();if(_i7.done)break;_ref7 = _i7.value;}var mention=_ref7;mentions.push(self.addUser(mention));}var newMessage=new Message(info,channel,mentions,formerMessage.author);self.trigger("messageUpdate",newMessage,formerMessage);channel.messages[channel.messages.indexOf(formerMessage)] = newMessage;} // message isn't in cache, and if it's a partial it could cause -// all hell to break loose... best to just act as if nothing happened -break;case "GUILD_DELETE":var server=self.getServer("id",data.id);if(server){self.serverCache.splice(self.serverCache.indexOf(server),1);self.trigger("serverDelete",server);}break;case "CHANNEL_DELETE":var channel=self.getChannel("id",data.id);if(channel){var server=channel.server;if(server){server.channels.splice(server.channels.indexOf(channel),1);}self.trigger("channelDelete",channel);self.serverCache.splice(self.serverCache.indexOf(channel),1);}break;case "GUILD_CREATE":var server=self.getServer("id",data.id);if(!server){ //if server doesn't already exist because duh -server = self.addServer(data);} /*else if(server.channels.length === 0){ - - var srv = new Server(data, self); - for(channel of data.channels){ - srv.channels.push(new Channel(channel, data.id)); +"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 Endpoints = require("./Endpoints.js"); +var User = require("./user.js"); +var Server = require("./server.js"); +var Channel = require("./channel.js"); +var Message = require("./message.js"); +var Invite = require("./invite.js"); +var PMChannel = require("./PMChannel.js"); + +var gameMap = require("../ref/gameMap.json"); + +//node modules +var request = require("superagent"); +var WebSocket = require("ws"); +var fs = require("fs"); + +var defaultOptions = { + queue: false +}; + +var Client = (function () { + function Client() { + var options = arguments.length <= 0 || arguments[0] === undefined ? defaultOptions : arguments[0]; + var token = arguments.length <= 1 || arguments[1] === undefined ? undefined : arguments[1]; + + _classCallCheck(this, Client); + + /* + When created, if a token is specified the Client will + try connecting with it. If the token is incorrect, no + further efforts will be made to connect. + */ + this.options = options; + this.options.queue = this.options.queue; + this.token = token; + this.state = 0; + this.websocket = null; + this.events = {}; + this.user = null; + this.alreadySentData = false; + this.serverCreateListener = {}; + this.typingIntervals = {}; + this.email = "abc"; + this.password = "abc"; + + /* + State values: + 0 - idle + 1 - logging in + 2 - logged in + 3 - ready + 4 - disconnected + */ + + this.userCache = []; + this.channelCache = []; + this.serverCache = []; + this.pmChannelCache = []; + this.readyTime = null; + this.checkingQueue = {}; + this.userTypingListener = {}; + this.queue = {}; + + this.__idleTime = null; + this.__gameId = null; + } + + Client.prototype.sendPacket = function sendPacket(JSONObject) { + if (this.websocket.readyState === 1) { + this.websocket.send(JSON.stringify(JSONObject)); + } + }; + + //def debug + + Client.prototype.debug = function debug(message) { + this.trigger("debug", message); + }; + + Client.prototype.on = function on(event, fn) { + this.events[event] = fn; + }; + + Client.prototype.off = function off(event) { + this.events[event] = null; + }; + + Client.prototype.keepAlive = function keepAlive() { + this.debug("keep alive triggered"); + this.sendPacket({ + op: 1, + d: Date.now() + }); + }; + + //def trigger + + Client.prototype.trigger = function trigger(event) { + var args = []; + for (var arg in arguments) { + args.push(arguments[arg]); + } + var evt = this.events[event]; + if (evt) { + evt.apply(this, args.slice(1)); + } + }; + + //def login + + Client.prototype.login = function login() { + var email = arguments.length <= 0 || arguments[0] === undefined ? "foo@bar.com" : arguments[0]; + var password = arguments.length <= 1 || arguments[1] === undefined ? "pass1234" : arguments[1]; + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, token) {} : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + if (self.state === 0 || self.state === 4) { + + self.state = 1; //set the state to logging in + + self.email = email; + self.password = password; + + request.post(Endpoints.LOGIN).send({ + email: email, + password: password + }).end(function (err, res) { + + if (err) { + self.state = 4; //set state to disconnected + self.trigger("disconnected"); + if (self.websocket) { + self.websocket.close(); } - self.serverCache[self.serverCache.indexOf(server)] = srv; - - }*/if(self.serverCreateListener[data.id]){var cbs=self.serverCreateListener[data.id];cbs[0](server); //promise then callback -cbs[1](null,server); //legacy callback -self.serverCreateListener[data.id] = null;}self.trigger("serverCreate",server);break;case "CHANNEL_CREATE":var channel=self.getChannel("id",data.id);if(!channel){var chann;if(data.is_private){chann = self.addPMChannel(data);}else {chann = self.addChannel(data,data.guild_id);}var srv=self.getServer("id",data.guild_id);if(srv){srv.addChannel(chann);}self.trigger("channelCreate",chann);}break;case "GUILD_MEMBER_ADD":var server=self.getServer("id",data.guild_id);if(server){var user=self.addUser(data.user); //if for whatever reason it doesn't exist.. -self.trigger("serverNewMember",server.addMember(user,data.roles),server);}break;case "GUILD_MEMBER_REMOVE":var server=self.getServer("id",data.guild_id);if(server){var user=self.addUser(data.user); //if for whatever reason it doesn't exist.. -server.removeMember("id",user.id);self.trigger("serverRemoveMember",user,server);}break;case "USER_UPDATE":if(self.user && data.id === self.user.id){var newUser=new User(data); //not actually adding to the cache -self.trigger("userUpdate",newUser,self.user);if(~self.userCache.indexOf(self.user)){self.userCache[self.userCache.indexOf(self.user)] = newUser;}self.user = newUser;}break;case "PRESENCE_UPDATE":var userInCache=self.getUser("id",data.user.id);if(userInCache){ //user exists -data.user.username = data.user.username || userInCache.username;data.user.id = data.user.id || userInCache.id;data.user.discriminator = data.user.discriminator || userInCache.discriminator;data.user.avatar = data.user.avatar || userInCache.avatar;var presenceUser=new User(data.user);if(presenceUser.equalsStrict(userInCache)){ //they're exactly the same, an actual presence update -self.trigger("presence",{user:userInCache,oldStatus:userInCache.status,status:data.status,server:self.getServer("id",data.guild_id),gameId:data.game_id});userInCache.status = data.status;userInCache.gameId = data.game_id;}else { //one of their details changed. -self.userCache[self.userCache.indexOf(userInCache)] = presenceUser;self.trigger("userUpdate",userInCache,presenceUser);}}break;case "CHANNEL_UPDATE":var channelInCache=self.getChannel("id",data.id),serverInCache=self.getServer("id",data.guild_id);if(channelInCache && serverInCache){var newChann=new Channel(data,serverInCache);newChann.messages = channelInCache.messages;self.trigger("channelUpdate",channelInCache,newChann);self.channelCache[self.channelCache.indexOf(channelInCache)] = newChann;}break;case "TYPING_START":var userInCache=self.getUser("id",data.user_id);var channelInCache=self.getChannel("id",data.channel_id);if(!self.userTypingListener[data.user_id] || self.userTypingListener[data.user_id] === -1){self.trigger("startTyping",userInCache,channelInCache);}self.userTypingListener[data.user_id] = Date.now();setTimeout(function(){if(self.userTypingListener[data.user_id] === -1){return;}if(Date.now() - self.userTypingListener[data.user_id] > 6000){ // stopped typing -self.trigger("stopTyping",userInCache,channelInCache);self.userTypingListener[data.user_id] = -1;}},6000);break;case "GUILD_ROLE_DELETE":var server=self.getServer("id",data.guild_id);var role=server.getRole(data.role_id);self.trigger("serverRoleDelete",server,role);server.removeRole(role.id);break;case "GUILD_ROLE_UPDATE":var server=self.getServer("id",data.guild_id);var role=server.getRole(data.role.id);var newRole=server.updateRole(data.role);self.trigger("serverRoleUpdate",server,role,newRole);break;default:self.debug("received unknown packet");self.trigger("unknown",dat);break;}};}; //def addUser -Client.prototype.addUser = function addUser(data){if(!this.getUser("id",data.id)){this.userCache.push(new User(data));}return this.getUser("id",data.id);}; //def addChannel -Client.prototype.addChannel = function addChannel(data,serverId){if(!this.getChannel("id",data.id)){this.channelCache.push(new Channel(data,this.getServer("id",serverId)));}return this.getChannel("id",data.id);};Client.prototype.addPMChannel = function addPMChannel(data){if(!this.getPMChannel("id",data.id)){this.pmChannelCache.push(new PMChannel(data,this));}return this.getPMChannel("id",data.id);};Client.prototype.setTopic = function setTopic(channel,topic){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err){}:arguments[2];var self=this;return new Promise(function(resolve,reject){self.resolveDestination(channel).then(next)["catch"](error);function error(e){callback(e);reject(e);}function next(destination){var asChan=self.getChannel("id",destination);request.patch(Endpoints.CHANNELS + "/" + destination).set("authorization",self.token).send({name:asChan.name,position:0,topic:topic}).end(function(err,res){if(err){error(err);}else {asChan.topic = res.body.topic;resolve();callback();}});}});}; //def addServer -Client.prototype.addServer = function addServer(data){var self=this;var server=this.getServer("id",data.id);if(data.unavailable){self.trigger("unavailable",data);self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached.");return;}if(!server){server = new Server(data,this);this.serverCache.push(server);if(data.channels){for(var _iterator8=data.channels,_isArray8=Array.isArray(_iterator8),_i8=0,_iterator8=_isArray8?_iterator8:_iterator8[Symbol.iterator]();;) {var _ref8;if(_isArray8){if(_i8 >= _iterator8.length)break;_ref8 = _iterator8[_i8++];}else {_i8 = _iterator8.next();if(_i8.done)break;_ref8 = _i8.value;}var channel=_ref8;server.channels.push(this.addChannel(channel,server.id));}}}for(var _iterator9=data.presences,_isArray9=Array.isArray(_iterator9),_i9=0,_iterator9=_isArray9?_iterator9:_iterator9[Symbol.iterator]();;) {var _ref9;if(_isArray9){if(_i9 >= _iterator9.length)break;_ref9 = _iterator9[_i9++];}else {_i9 = _iterator9.next();if(_i9.done)break;_ref9 = _i9.value;}var presence=_ref9;var user=self.getUser("id",presence.user.id);user.status = presence.status;user.gameId = presence.game_id;}return server;}; //def getUser -Client.prototype.getUser = function getUser(key,value){for(var _iterator10=this.userCache,_isArray10=Array.isArray(_iterator10),_i10=0,_iterator10=_isArray10?_iterator10:_iterator10[Symbol.iterator]();;) {var _ref10;if(_isArray10){if(_i10 >= _iterator10.length)break;_ref10 = _iterator10[_i10++];}else {_i10 = _iterator10.next();if(_i10.done)break;_ref10 = _i10.value;}var user=_ref10;if(user[key] === value){return user;}}return null;}; //def getChannel -Client.prototype.getChannel = function getChannel(key,value){for(var _iterator11=this.channelCache,_isArray11=Array.isArray(_iterator11),_i11=0,_iterator11=_isArray11?_iterator11:_iterator11[Symbol.iterator]();;) {var _ref11;if(_isArray11){if(_i11 >= _iterator11.length)break;_ref11 = _iterator11[_i11++];}else {_i11 = _iterator11.next();if(_i11.done)break;_ref11 = _i11.value;}var channel=_ref11;if(channel[key] === value){return channel;}}return this.getPMChannel(key,value); //might be a PM -};Client.prototype.getPMChannel = function getPMChannel(key,value){for(var _iterator12=this.pmChannelCache,_isArray12=Array.isArray(_iterator12),_i12=0,_iterator12=_isArray12?_iterator12:_iterator12[Symbol.iterator]();;) {var _ref12;if(_isArray12){if(_i12 >= _iterator12.length)break;_ref12 = _iterator12[_i12++];}else {_i12 = _iterator12.next();if(_i12.done)break;_ref12 = _i12.value;}var channel=_ref12;if(channel[key] === value){return channel;}}return null;}; //def getServer -Client.prototype.getServer = function getServer(key,value){for(var _iterator13=this.serverCache,_isArray13=Array.isArray(_iterator13),_i13=0,_iterator13=_isArray13?_iterator13:_iterator13[Symbol.iterator]();;) {var _ref13;if(_isArray13){if(_i13 >= _iterator13.length)break;_ref13 = _iterator13[_i13++];}else {_i13 = _iterator13.next();if(_i13.done)break;_ref13 = _i13.value;}var server=_ref13;if(server[key] === value){return server;}}return null;}; //def trySendConnData -Client.prototype.trySendConnData = function trySendConnData(){if(this.token && !this.alreadySentData){this.alreadySentData = true;var data={op:2,d:{token:this.token,v:3,properties:{"$os":"discord.js","$browser":"discord.js","$device":"discord.js","$referrer":"","$referring_domain":""}}};this.websocket.send(JSON.stringify(data));}};Client.prototype.resolveServerID = function resolveServerID(resource){if(resource instanceof Server){return resource.id;}else if(!isNaN(resource) && resource.length && resource.length === 17){return resource;}};Client.prototype.resolveDestination = function resolveDestination(destination){var channId=false;var self=this;return new Promise(function(resolve,reject){if(destination instanceof Server){channId = destination.id; //general is the same as server id -}else if(destination instanceof Channel){channId = destination.id;}else if(destination instanceof Message){channId = destination.channel.id;}else if(destination instanceof PMChannel){channId = destination.id;}else if(destination instanceof User){ //check if we have a PM -for(var _iterator14=self.pmChannelCache,_isArray14=Array.isArray(_iterator14),_i14=0,_iterator14=_isArray14?_iterator14:_iterator14[Symbol.iterator]();;) {var _ref14;if(_isArray14){if(_i14 >= _iterator14.length)break;_ref14 = _iterator14[_i14++];}else {_i14 = _iterator14.next();if(_i14.done)break;_ref14 = _i14.value;}var pmc=_ref14;if(pmc.user && pmc.user.equals(destination)){resolve(pmc.id);return;}} //we don't, at this point we're late -self.startPM(destination).then(function(pmc){resolve(pmc.id);})["catch"](reject);}else {channId = destination;}if(channId)resolve(channId);else reject();});};Client.prototype._sendMessage = function _sendMessage(destination,content,tts,mentions){var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization",self.token).send({content:content,mentions:mentions,tts:tts}).end(function(err,res){if(err){reject(err);}else {var data=res.body;var mentions=[];data.mentions = data.mentions || []; //for some reason this was not defined at some point? -for(var _iterator15=data.mentions,_isArray15=Array.isArray(_iterator15),_i15=0,_iterator15=_isArray15?_iterator15:_iterator15[Symbol.iterator]();;) {var _ref15;if(_isArray15){if(_i15 >= _iterator15.length)break;_ref15 = _iterator15[_i15++];}else {_i15 = _iterator15.next();if(_i15.done)break;_ref15 = _i15.value;}var mention=_ref15;mentions.push(self.addUser(mention));}var channel=self.getChannel("id",data.channel_id);if(channel){var msg=channel.addMessage(new Message(data,channel,mentions,self.addUser(data.author)));resolve(msg);}}});});};Client.prototype._sendFile = function _sendFile(destination,attachment){var attachmentName=arguments.length <= 2 || arguments[2] === undefined?"DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png":arguments[2];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization",self.token).attach("file",attachment,attachmentName).end(function(err,res){if(err){reject(err);}else {var chann=self.getChannel("id",destination);if(chann){var msg=chann.addMessage(new Message(res.body,chann,[],self.user));resolve(msg);}}});});};Client.prototype._updateMessage = function _updateMessage(message,content){var self=this;return new Promise(function(resolve,reject){request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization",self.token).send({content:content,mentions:[]}).end(function(err,res){if(err){reject(err);}else {var msg=new Message(res.body,message.channel,message.mentions,message.sender);resolve(msg);message.channel.messages[message.channel.messages.indexOf(message)] = msg;}});});};Client.prototype.getGateway = function getGateway(){var self=this;return new Promise(function(resolve,reject){request.get(Endpoints.API + "/gateway").set("authorization",self.token).end(function(err,res){if(err){reject(err);}else {resolve(res.body.url);}});});};Client.prototype.setStatusIdle = function setStatusIdle(){this.setStatus("idle");};Client.prototype.setStatusOnline = function setStatusOnline(){this.setStatus("online");};Client.prototype.setStatusActive = function setStatusActive(){this.setStatusOnline();};Client.prototype.setStatusHere = function setStatusHere(){this.setStatusOnline();};Client.prototype.setStatusAway = function setStatusAway(){this.setStatusIdle();};Client.prototype.startTyping = function startTyping(chann,stopTypeTime){var self=this;this.resolveDestination(chann).then(next);function next(channel){if(self.typingIntervals[channel]){return;}var fn=function fn(){request.post(Endpoints.CHANNELS + "/" + channel + "/typing").set("authorization",self.token).end();};fn();var interval=setInterval(fn,3000);self.typingIntervals[channel] = interval;if(stopTypeTime){setTimeout(function(){self.stopTyping(channel);},stopTypeTime);}}};Client.prototype.stopTyping = function stopTyping(chann){var self=this;this.resolveDestination(chann).then(next);function next(channel){if(!self.typingIntervals[channel]){return;}clearInterval(self.typingIntervals[channel]);delete self.typingIntervals[channel];}};Client.prototype.setStatus = function setStatus(stat){var idleTime=stat === "online"?null:Date.now();this.__idleTime = idleTime;this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}));};Client.prototype.setPlayingGame = function setPlayingGame(id){if(id instanceof String || typeof id === "string"){ // working on names -var gid=id.trim().toUpperCase();id = null;for(var _iterator16=gameMap,_isArray16=Array.isArray(_iterator16),_i16=0,_iterator16=_isArray16?_iterator16:_iterator16[Symbol.iterator]();;) {var _ref16;if(_isArray16){if(_i16 >= _iterator16.length)break;_ref16 = _iterator16[_i16++];}else {_i16 = _iterator16.next();if(_i16.done)break;_ref16 = _i16.value;}var game=_ref16;if(game.name.trim().toUpperCase() === gid){id = game.id;break;}}}this.__gameId = id;this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}));};Client.prototype.playGame = function playGame(id){this.setPlayingGame(id);};Client.prototype.playingGame = function playingGame(id){this.setPlayingGame(id);};_createClass(Client,[{key:"uptime",get:function get(){return this.readyTime?Date.now() - this.readyTime:null;}},{key:"ready",get:function get(){return this.state === 3;}},{key:"servers",get:function get(){return this.serverCache;}},{key:"channels",get:function get(){return this.channelCache;}},{key:"users",get:function get(){return this.userCache;}},{key:"PMChannels",get:function get(){return this.pmChannelCache;}},{key:"messages",get:function get(){var msgs=[];for(var _iterator17=this.channelCache,_isArray17=Array.isArray(_iterator17),_i17=0,_iterator17=_isArray17?_iterator17:_iterator17[Symbol.iterator]();;) {var _ref17;if(_isArray17){if(_i17 >= _iterator17.length)break;_ref17 = _iterator17[_i17++];}else {_i17 = _iterator17.next();if(_i17.done)break;_ref17 = _i17.value;}var channel=_ref17;msgs = msgs.concat(channel.messages);}return msgs;}}]);return Client;})();module.exports = Client; + callback(err); + reject(err); + } else { + self.state = 2; //set state to logged in (not yet ready) + self.token = res.body.token; //set our token + + self.getGateway().then(function (url) { + self.createws(url); + callback(null, self.token); + resolve(self.token); + })["catch"](function (err) { + callback(err); + reject(err); + }); + } + }); + } else { + reject(new Error("Client already logging in or ready")); + } + }); + }; + + Client.prototype.logout = function logout() { + var callback = arguments.length <= 0 || arguments[0] === undefined ? function (err) {} : arguments[0]; + + var self = this; + + return new Promise(function (resolve, reject) { + + request.post(Endpoints.LOGOUT).set("authorization", self.token).end(function (err, res) { + + if (err) { + callback(err); + reject(err); + } else { + self.websocket.close(); + self.state = 4; + callback(); + resolve(); + } + }); + }); + }; + + Client.prototype.createServer = function createServer(name, region) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, server) {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + + request.post(Endpoints.SERVERS).set("authorization", self.token).send({ + name: name, + region: region + }).end(function (err, res) { + if (err) { + callback(err); + reject(err); + } else { + // potentially redundant in future + // creating here does NOT give us the channels of the server + // so we must wait for the guild_create event. + self.serverCreateListener[res.body.id] = [resolve, callback]; + /*var srv = self.addServer(res.body); + callback(null, srv); + resolve(srv);*/ + } + }); + }); + }; + + Client.prototype.createChannel = function createChannel(server, channelName, channelType) { + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, chann) {} : arguments[3]; + + var self = this; + + return new Promise(function (resolve, reject) { + + request.post(Endpoints.SERVERS + "/" + self.resolveServerID(server) + "/channels").set("authorization", self.token).send({ + name: channelName, + type: channelType + }).end(function (err, res) { + + if (err) { + callback(err); + reject(err); + } else { + var server = self.getServer("id", res.body.guild_id); + var chann = self.addChannel(res.body, res.body.guild_id); + server.addChannel(chann); + callback(null, chann); + resolve(chann); + } + }); + }); + }; + + Client.prototype.leaveServer = function leaveServer(server) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, server) {} : arguments[1]; + + var self = this; + + return new Promise(function (resolve, reject) { + + request.del(Endpoints.SERVERS + "/" + self.resolveServerID(server)).set("authorization", self.token).end(function (err, res) { + + if (err) { + callback(err); + reject(err); + } else { + self.serverCache.splice(self.serverCache.indexOf(server), 1); + callback(null); + resolve(); + } + }); + }); + }; + + Client.prototype.createInvite = function createInvite(serverOrChannel, options) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, invite) {} : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + + var destination; + + if (serverOrChannel instanceof Server) { + destination = serverOrChannel.id; + } else if (serverOrChannel instanceof Channel) { + destination = serverOrChannel.id; + } else { + destination = serverOrChannel; + } + + options = options || {}; + options.max_age = options.maxAge || 0; + options.max_uses = options.maxUses || 0; + options.temporary = options.temporary || false; + options.xkcdpass = options.xkcd || false; + + request.post(Endpoints.CHANNELS + "/" + destination + "/invites").set("authorization", self.token).send(options).end(function (err, res) { + if (err) { + callback(err); + reject(err); + } else { + var inv = new Invite(res.body, self); + callback(null, inv); + resolve(inv); + } + }); + }); + }; + + Client.prototype.startPM = function startPM(user) { + + var self = this; + + return new Promise(function (resolve, reject) { + var userId = user; + if (user instanceof User) { + userId = user.id; + } + request.post(Endpoints.USERS + "/" + self.user.id + "/channels").set("authorization", self.token).send({ + recipient_id: userId + }).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(self.addPMChannel(res.body)); + } + }); + }); + }; + + Client.prototype.reply = function reply(destination, message, tts) { + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; + + var self = this; + + return new Promise(function (response, reject) { + + if (typeof tts === "function") { + // tts is a function, which means the developer wants this to be the callback + callback = tts; + tts = false; + } + + var user = destination.sender; + self.sendMessage(destination, message, tts, callback, user + ", ").then(response)["catch"](reject); + }); + }; + + Client.prototype.deleteMessage = function deleteMessage(message, timeout) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, msg) {} : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + if (timeout) { + setTimeout(remove, timeout); + } else { + remove(); + } + + function remove() { + request.del(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).end(function (err, res) { + if (err) { + bad(); + } else { + good(); + } + }); + } + + function good() { + callback(); + resolve(); + } + + function bad(err) { + callback(err); + reject(err); + } + }); + }; + + Client.prototype.updateMessage = function updateMessage(message, content) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, msg) {} : arguments[2]; + + var self = this; + + var prom = new Promise(function (resolve, reject) { + + content = content instanceof Array ? content.join("\n") : content; + + if (self.options.queue) { + if (!self.queue[message.channel.id]) { + self.queue[message.channel.id] = []; + } + self.queue[message.channel.id].push({ + action: "updateMessage", + message: message, + content: content, + then: good, + error: bad + }); + + self.checkQueue(message.channel.id); + } else { + self._updateMessage(message, content).then(good)["catch"](bad); + } + + function good(msg) { + prom.message = msg; + callback(null, msg); + resolve(msg); + } + + function bad(error) { + prom.error = error; + callback(error); + reject(error); + } + }); + + return prom; + }; + + Client.prototype.setUsername = function setUsername(newName) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; + + var self = this; + + return new Promise(function (resolve, reject) { + request.patch(Endpoints.API + "/users/@me").set("authorization", self.token).send({ + avatar: self.user.avatar, + email: self.email, + new_password: null, + password: self.password, + username: newName + }).end(function (err) { + callback(err); + if (err) reject(err);else resolve(); + }); + }); + }; + + Client.prototype.getChannelLogs = function getChannelLogs(channel) { + var amount = arguments.length <= 1 || arguments[1] === undefined ? 500 : arguments[1]; + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, logs) {} : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + + var channelID = channel; + if (channel instanceof Channel) { + channelID = channel.id; + } + + request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization", self.token).end(function (err, res) { + + if (err) { + callback(err); + reject(err); + } else { + var logs = []; + + var channel = self.getChannel("id", channelID); + + for (var _iterator = res.body, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + var message = _ref; + + var mentions = []; + for (var _iterator2 = message.mentions, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { + var _ref2; + + if (_isArray2) { + if (_i2 >= _iterator2.length) break; + _ref2 = _iterator2[_i2++]; + } else { + _i2 = _iterator2.next(); + if (_i2.done) break; + _ref2 = _i2.value; + } + + var mention = _ref2; + + mentions.push(self.addUser(mention)); + } + + var author = self.addUser(message.author); + + logs.push(new Message(message, channel, mentions, author)); + } + callback(null, logs); + resolve(logs); + } + }); + }); + }; + + Client.prototype.deleteChannel = function deleteChannel(channel) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; + + var self = this; + + return new Promise(function (resolve, reject) { + + var channelID = channel; + if (channel instanceof Channel) { + channelID = channel.id; + } + + request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization", self.token).end(function (err) { + if (err) { + callback(err); + reject(err); + } else { + callback(null); + resolve(); + } + }); + }); + }; + + Client.prototype.joinServer = function joinServer(invite) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, server) {} : arguments[1]; + + var self = this; + + return new Promise(function (resolve, reject) { + + var id = invite instanceof Invite ? invite.code : invite; + + request.post(Endpoints.API + "/invite/" + id).set("authorization", self.token).end(function (err, res) { + if (err) { + callback(err); + reject(err); + } else { + if (self.getServer("id", res.body.guild.id)) { + resolve(self.getServer("id", res.body.guild.id)); + } else { + self.serverCreateListener[res.body.guild.id] = [resolve, callback]; + } + } + }); + }); + }; + + Client.prototype.setAvatar = function setAvatar(resource) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; + + var self = this; + + return new Promise(function (resolve, reject) { + if (resource instanceof Buffer) { + resource = resource.toString("base64"); + resource = "data:image/jpg;base64," + resource; + } + + request.patch(Endpoints.API + "/users/@me").set("authorization", self.token).send({ + avatar: resource, + email: self.email, + new_password: null, + password: self.password, + username: self.user.username + }).end(function (err) { + callback(err); + if (err) reject(err);else resolve(); + }); + }); + }; + + Client.prototype.sendFile = function sendFile(destination, file) { + var fileName = arguments.length <= 2 || arguments[2] === undefined ? "image.png" : arguments[2]; + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; + + var self = this; + + var prom = new Promise(function (resolve, reject) { + + var fstream; + + if (typeof file === "string" || file instanceof String) { + fstream = fs.createReadStream(file); + fileName = file; + } else { + fstream = file; + } + + self.resolveDestination(destination).then(send)["catch"](bad); + + function send(destination) { + if (self.options.queue) { + //queue send file too + if (!self.queue[destination]) { + self.queue[destination] = []; + } + + self.queue[destination].push({ + action: "sendFile", + attachment: fstream, + attachmentName: fileName, + then: good, + error: bad + }); + + self.checkQueue(destination); + } else { + //not queue + self._sendFile(destination, fstream, fileName).then(good)["catch"](bad); + } + } + + function good(msg) { + prom.message = msg; + callback(null, msg); + resolve(msg); + } + + function bad(err) { + prom.error = err; + callback(err); + reject(err); + } + }); + + return prom; + }; + + Client.prototype.sendMessage = function sendMessage(destination, message, tts) { + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; + var premessage = arguments.length <= 4 || arguments[4] === undefined ? "" : arguments[4]; + + var self = this; + + var prom = new Promise(function (resolve, reject) { + + if (typeof tts === "function") { + // tts is a function, which means the developer wants this to be the callback + callback = tts; + tts = false; + } + + message = premessage + resolveMessage(message); + var mentions = resolveMentions(); + self.resolveDestination(destination).then(send)["catch"](error); + + function error(err) { + callback(err); + reject(err); + } + + function send(destination) { + if (self.options.queue) { + //we're QUEUEING messages, so sending them sequentially based on servers. + if (!self.queue[destination]) { + self.queue[destination] = []; + } + + self.queue[destination].push({ + action: "sendMessage", + content: message, + mentions: mentions, + tts: !!tts, //incase it's not a boolean + then: mgood, + error: mbad + }); + + self.checkQueue(destination); + } else { + self._sendMessage(destination, message, tts, mentions).then(mgood)["catch"](mbad); + } + } + + function mgood(msg) { + prom.message = msg; + callback(null, msg); + resolve(msg); + } + + function mbad(error) { + prom.error = error; + callback(error); + reject(error); + } + + function resolveMessage() { + var msg = message; + if (message instanceof Array) { + msg = message.join("\n"); + } + return msg; + } + + function resolveMentions() { + var _mentions = []; + for (var _iterator3 = message.match(/<@[^>]*>/g) || [], _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { + var _ref3; + + if (_isArray3) { + if (_i3 >= _iterator3.length) break; + _ref3 = _iterator3[_i3++]; + } else { + _i3 = _iterator3.next(); + if (_i3.done) break; + _ref3 = _i3.value; + } + + var mention = _ref3; + + _mentions.push(mention.substring(2, mention.length - 1)); + } + return _mentions; + } + }); + + return prom; + }; + + //def createws + + Client.prototype.createws = function createws(url) { + if (this.websocket) return false; + + var self = this; + + //good to go + this.websocket = new WebSocket(url); + + //open + this.websocket.onopen = function () { + self.trySendConnData(); //try connecting + }; + + //close + this.websocket.onclose = function () { + self.trigger("disconnected"); + }; + + //message + this.websocket.onmessage = function (e) { + + var dat = false, + data = {}; + + try { + dat = JSON.parse(e.data); + data = dat.d; + } catch (err) { + self.trigger("error", err, e); + return; + } + + self.trigger("raw", dat); + + //valid message + switch (dat.t) { + + case "READY": + self.debug("received ready packet"); + + self.user = self.addUser(data.user); + + for (var _iterator4 = data.guilds, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { + var _ref4; + + if (_isArray4) { + if (_i4 >= _iterator4.length) break; + _ref4 = _iterator4[_i4++]; + } else { + _i4 = _iterator4.next(); + if (_i4.done) break; + _ref4 = _i4.value; + } + + var _server = _ref4; + + var server = self.addServer(_server); + } + + for (var _iterator5 = data.private_channels, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { + var _ref5; + + if (_isArray5) { + if (_i5 >= _iterator5.length) break; + _ref5 = _iterator5[_i5++]; + } else { + _i5 = _iterator5.next(); + if (_i5.done) break; + _ref5 = _i5.value; + } + + var _pmc = _ref5; + + var pmc = self.addPMChannel(_pmc); + } + + self.trigger("ready"); + self.readyTime = Date.now(); + self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users."); + self.state = 3; + setInterval(function () { + self.keepAlive.apply(self); + }, data.heartbeat_interval); + + break; + case "MESSAGE_CREATE": + self.debug("received message"); + + var mentions = []; + data.mentions = data.mentions || []; //for some reason this was not defined at some point? + for (var _iterator6 = data.mentions, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { + var _ref6; + + if (_isArray6) { + if (_i6 >= _iterator6.length) break; + _ref6 = _iterator6[_i6++]; + } else { + _i6 = _iterator6.next(); + if (_i6.done) break; + _ref6 = _i6.value; + } + + var mention = _ref6; + + mentions.push(self.addUser(mention)); + } + + var channel = self.getChannel("id", data.channel_id); + if (channel) { + var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); + self.trigger("message", msg); + } + + break; + case "MESSAGE_DELETE": + self.debug("message deleted"); + + var channel = self.getChannel("id", data.channel_id); + var message = channel.getMessage("id", data.id); + if (message) { + self.trigger("messageDelete", channel, message); + channel.messages.splice(channel.messages.indexOf(message), 1); + } else { + //don't have the cache of that message ;( + self.trigger("messageDelete", channel); + } + break; + case "MESSAGE_UPDATE": + self.debug("message updated"); + + var channel = self.getChannel("id", data.channel_id); + var formerMessage = channel.getMessage("id", data.id); + + if (formerMessage) { + + //new message might be partial, so we need to fill it with whatever the old message was. + var info = {}; + + for (var key in formerMessage) { + info[key] = formerMessage[key]; + } + + for (var key in data) { + info[key] = data[key]; + } + + var mentions = []; + for (var _iterator7 = info.mentions, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) { + var _ref7; + + if (_isArray7) { + if (_i7 >= _iterator7.length) break; + _ref7 = _iterator7[_i7++]; + } else { + _i7 = _iterator7.next(); + if (_i7.done) break; + _ref7 = _i7.value; + } + + var mention = _ref7; + + mentions.push(self.addUser(mention)); + } + + var newMessage = new Message(info, channel, mentions, formerMessage.author); + + self.trigger("messageUpdate", newMessage, formerMessage); + + channel.messages[channel.messages.indexOf(formerMessage)] = newMessage; + } + + // message isn't in cache, and if it's a partial it could cause + // all hell to break loose... best to just act as if nothing happened + + break; + + case "GUILD_DELETE": + + var server = self.getServer("id", data.id); + + if (server) { + self.serverCache.splice(self.serverCache.indexOf(server), 1); + self.trigger("serverDelete", server); + } + + break; + + case "CHANNEL_DELETE": + + var channel = self.getChannel("id", data.id); + + if (channel) { + + var server = channel.server; + + if (server) { + + server.channels.splice(server.channels.indexOf(channel), 1); + } + + self.trigger("channelDelete", channel); + + self.serverCache.splice(self.serverCache.indexOf(channel), 1); + } + + break; + + case "GUILD_CREATE": + + var server = self.getServer("id", data.id); + + if (!server) { + //if server doesn't already exist because duh + server = self.addServer(data); + } /*else if(server.channels.length === 0){ + + var srv = new Server(data, self); + for(channel of data.channels){ + srv.channels.push(new Channel(channel, data.id)); + } + self.serverCache[self.serverCache.indexOf(server)] = srv; + + }*/ + + if (self.serverCreateListener[data.id]) { + var cbs = self.serverCreateListener[data.id]; + cbs[0](server); //promise then callback + cbs[1](null, server); //legacy callback + self.serverCreateListener[data.id] = null; + } + + self.trigger("serverCreate", server); + + break; + + case "CHANNEL_CREATE": + + var channel = self.getChannel("id", data.id); + + if (!channel) { + + var chann; + if (data.is_private) { + chann = self.addPMChannel(data); + } else { + chann = self.addChannel(data, data.guild_id); + } + var srv = self.getServer("id", data.guild_id); + if (srv) { + srv.addChannel(chann); + } + self.trigger("channelCreate", chann); + } + + break; + + case "GUILD_MEMBER_ADD": + + var server = self.getServer("id", data.guild_id); + + if (server) { + + var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. + + self.trigger("serverNewMember", server.addMember(user, data.roles), server); + } + + break; + + case "GUILD_MEMBER_REMOVE": + + var server = self.getServer("id", data.guild_id); + + if (server) { + + var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. + + server.removeMember("id", user.id); + + self.trigger("serverRemoveMember", user, server); + } + + break; + + case "USER_UPDATE": + + if (self.user && data.id === self.user.id) { + + var newUser = new User(data); //not actually adding to the cache + + self.trigger("userUpdate", newUser, self.user); + + if (~self.userCache.indexOf(self.user)) { + self.userCache[self.userCache.indexOf(self.user)] = newUser; + } + + self.user = newUser; + } + + break; + + case "PRESENCE_UPDATE": + + var userInCache = self.getUser("id", data.user.id); + + if (userInCache) { + //user exists + + data.user.username = data.user.username || userInCache.username; + data.user.id = data.user.id || userInCache.id; + data.user.discriminator = data.user.discriminator || userInCache.discriminator; + data.user.avatar = data.user.avatar || userInCache.avatar; + + var presenceUser = new User(data.user); + if (presenceUser.equalsStrict(userInCache)) { + //they're exactly the same, an actual presence update + self.trigger("presence", { + user: userInCache, + oldStatus: userInCache.status, + status: data.status, + server: self.getServer("id", data.guild_id), + gameId: data.game_id + }); + userInCache.status = data.status; + userInCache.gameId = data.game_id; + } else { + //one of their details changed. + self.userCache[self.userCache.indexOf(userInCache)] = presenceUser; + self.trigger("userUpdate", userInCache, presenceUser); + } + } + + break; + + case "CHANNEL_UPDATE": + + var channelInCache = self.getChannel("id", data.id), + serverInCache = self.getServer("id", data.guild_id); + + if (channelInCache && serverInCache) { + + var newChann = new Channel(data, serverInCache); + newChann.messages = channelInCache.messages; + + self.trigger("channelUpdate", channelInCache, newChann); + + self.channelCache[self.channelCache.indexOf(channelInCache)] = newChann; + } + + break; + + case "TYPING_START": + + var userInCache = self.getUser("id", data.user_id); + var channelInCache = self.getChannel("id", data.channel_id); + + if (!self.userTypingListener[data.user_id] || self.userTypingListener[data.user_id] === -1) { + self.trigger("startTyping", userInCache, channelInCache); + } + + self.userTypingListener[data.user_id] = Date.now(); + + setTimeout(function () { + if (self.userTypingListener[data.user_id] === -1) { + return; + } + if (Date.now() - self.userTypingListener[data.user_id] > 6000) { + // stopped typing + self.trigger("stopTyping", userInCache, channelInCache); + self.userTypingListener[data.user_id] = -1; + } + }, 6000); + + break; + + case "GUILD_ROLE_DELETE": + + var server = self.getServer("id", data.guild_id); + var role = server.getRole(data.role_id); + + self.trigger("serverRoleDelete", server, role); + + server.removeRole(role.id); + + break; + + case "GUILD_ROLE_UPDATE": + + var server = self.getServer("id", data.guild_id); + var role = server.getRole(data.role.id); + var newRole = server.updateRole(data.role); + + self.trigger("serverRoleUpdate", server, role, newRole); + + break; + + default: + self.debug("received unknown packet"); + self.trigger("unknown", dat); + break; + + } + }; + }; + + //def addUser + + Client.prototype.addUser = function addUser(data) { + if (!this.getUser("id", data.id)) { + this.userCache.push(new User(data)); + } + return this.getUser("id", data.id); + }; + + //def addChannel + + Client.prototype.addChannel = function addChannel(data, serverId) { + if (!this.getChannel("id", data.id)) { + this.channelCache.push(new Channel(data, this.getServer("id", serverId))); + } + return this.getChannel("id", data.id); + }; + + Client.prototype.addPMChannel = function addPMChannel(data) { + if (!this.getPMChannel("id", data.id)) { + this.pmChannelCache.push(new PMChannel(data, this)); + } + return this.getPMChannel("id", data.id); + }; + + Client.prototype.setTopic = function setTopic(channel, topic) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + + self.resolveDestination(channel).then(next)["catch"](error); + + function error(e) { + callback(e); + reject(e); + } + + function next(destination) { + + var asChan = self.getChannel("id", destination); + + request.patch(Endpoints.CHANNELS + "/" + destination).set("authorization", self.token).send({ + name: asChan.name, + position: 0, + topic: topic + }).end(function (err, res) { + if (err) { + error(err); + } else { + asChan.topic = res.body.topic; + resolve(); + callback(); + } + }); + } + }); + }; + + //def addServer + + Client.prototype.addServer = function addServer(data) { + + var self = this; + var server = this.getServer("id", data.id); + + if (data.unavailable) { + self.trigger("unavailable", data); + self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached."); + return; + } + + if (!server) { + server = new Server(data, this); + this.serverCache.push(server); + if (data.channels) { + for (var _iterator8 = data.channels, _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) { + var _ref8; + + if (_isArray8) { + if (_i8 >= _iterator8.length) break; + _ref8 = _iterator8[_i8++]; + } else { + _i8 = _iterator8.next(); + if (_i8.done) break; + _ref8 = _i8.value; + } + + var channel = _ref8; + + server.channels.push(this.addChannel(channel, server.id)); + } + } + } + + for (var _iterator9 = data.presences, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) { + var _ref9; + + if (_isArray9) { + if (_i9 >= _iterator9.length) break; + _ref9 = _iterator9[_i9++]; + } else { + _i9 = _iterator9.next(); + if (_i9.done) break; + _ref9 = _i9.value; + } + + var presence = _ref9; + + var user = self.getUser("id", presence.user.id); + user.status = presence.status; + user.gameId = presence.game_id; + } + + return server; + }; + + //def getUser + + Client.prototype.getUser = function getUser(key, value) { + for (var _iterator10 = this.userCache, _isArray10 = Array.isArray(_iterator10), _i10 = 0, _iterator10 = _isArray10 ? _iterator10 : _iterator10[Symbol.iterator]();;) { + var _ref10; + + if (_isArray10) { + if (_i10 >= _iterator10.length) break; + _ref10 = _iterator10[_i10++]; + } else { + _i10 = _iterator10.next(); + if (_i10.done) break; + _ref10 = _i10.value; + } + + var user = _ref10; + + if (user[key] === value) { + return user; + } + } + return null; + }; + + //def getChannel + + Client.prototype.getChannel = function getChannel(key, value) { + for (var _iterator11 = this.channelCache, _isArray11 = Array.isArray(_iterator11), _i11 = 0, _iterator11 = _isArray11 ? _iterator11 : _iterator11[Symbol.iterator]();;) { + var _ref11; + + if (_isArray11) { + if (_i11 >= _iterator11.length) break; + _ref11 = _iterator11[_i11++]; + } else { + _i11 = _iterator11.next(); + if (_i11.done) break; + _ref11 = _i11.value; + } + + var channel = _ref11; + + if (channel[key] === value) { + return channel; + } + } + return this.getPMChannel(key, value); //might be a PM + }; + + Client.prototype.getPMChannel = function getPMChannel(key, value) { + for (var _iterator12 = this.pmChannelCache, _isArray12 = Array.isArray(_iterator12), _i12 = 0, _iterator12 = _isArray12 ? _iterator12 : _iterator12[Symbol.iterator]();;) { + var _ref12; + + if (_isArray12) { + if (_i12 >= _iterator12.length) break; + _ref12 = _iterator12[_i12++]; + } else { + _i12 = _iterator12.next(); + if (_i12.done) break; + _ref12 = _i12.value; + } + + var channel = _ref12; + + if (channel[key] === value) { + return channel; + } + } + return null; + }; + + //def getServer + + Client.prototype.getServer = function getServer(key, value) { + for (var _iterator13 = this.serverCache, _isArray13 = Array.isArray(_iterator13), _i13 = 0, _iterator13 = _isArray13 ? _iterator13 : _iterator13[Symbol.iterator]();;) { + var _ref13; + + if (_isArray13) { + if (_i13 >= _iterator13.length) break; + _ref13 = _iterator13[_i13++]; + } else { + _i13 = _iterator13.next(); + if (_i13.done) break; + _ref13 = _i13.value; + } + + var server = _ref13; + + if (server[key] === value) { + return server; + } + } + return null; + }; + + //def trySendConnData + + Client.prototype.trySendConnData = function trySendConnData() { + + if (this.token && !this.alreadySentData) { + + this.alreadySentData = true; + + var data = { + op: 2, + d: { + token: this.token, + v: 3, + properties: { + "$os": "discord.js", + "$browser": "discord.js", + "$device": "discord.js", + "$referrer": "", + "$referring_domain": "" + } + } + }; + this.websocket.send(JSON.stringify(data)); + } + }; + + Client.prototype.resolveServerID = function resolveServerID(resource) { + + if (resource instanceof Server) { + return resource.id; + } else if (!isNaN(resource) && resource.length && resource.length === 17) { + return resource; + } + }; + + Client.prototype.resolveDestination = function resolveDestination(destination) { + var channId = false; + var self = this; + + return new Promise(function (resolve, reject) { + if (destination instanceof Server) { + channId = destination.id; //general is the same as server id + } else if (destination instanceof Channel) { + channId = destination.id; + } else if (destination instanceof Message) { + channId = destination.channel.id; + } else if (destination instanceof PMChannel) { + channId = destination.id; + } else if (destination instanceof User) { + + //check if we have a PM + for (var _iterator14 = self.pmChannelCache, _isArray14 = Array.isArray(_iterator14), _i14 = 0, _iterator14 = _isArray14 ? _iterator14 : _iterator14[Symbol.iterator]();;) { + var _ref14; + + if (_isArray14) { + if (_i14 >= _iterator14.length) break; + _ref14 = _iterator14[_i14++]; + } else { + _i14 = _iterator14.next(); + if (_i14.done) break; + _ref14 = _i14.value; + } + + var pmc = _ref14; + + if (pmc.user && pmc.user.equals(destination)) { + resolve(pmc.id); + return; + } + } + + //we don't, at this point we're late + self.startPM(destination).then(function (pmc) { + resolve(pmc.id); + })["catch"](reject); + } else { + channId = destination; + } + if (channId) resolve(channId);else reject(); + }); + }; + + Client.prototype._sendMessage = function _sendMessage(destination, content, tts, mentions) { + + var self = this; + + return new Promise(function (resolve, reject) { + request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).send({ + content: content, + mentions: mentions, + tts: tts + }).end(function (err, res) { + + if (err) { + reject(err); + } else { + var data = res.body; + + var mentions = []; + + data.mentions = data.mentions || []; //for some reason this was not defined at some point? + + for (var _iterator15 = data.mentions, _isArray15 = Array.isArray(_iterator15), _i15 = 0, _iterator15 = _isArray15 ? _iterator15 : _iterator15[Symbol.iterator]();;) { + var _ref15; + + if (_isArray15) { + if (_i15 >= _iterator15.length) break; + _ref15 = _iterator15[_i15++]; + } else { + _i15 = _iterator15.next(); + if (_i15.done) break; + _ref15 = _i15.value; + } + + var mention = _ref15; + + mentions.push(self.addUser(mention)); + } + + var channel = self.getChannel("id", data.channel_id); + if (channel) { + var msg = channel.addMessage(new Message(data, channel, mentions, self.addUser(data.author))); + resolve(msg); + } + } + }); + }); + }; + + Client.prototype._sendFile = function _sendFile(destination, attachment) { + var attachmentName = arguments.length <= 2 || arguments[2] === undefined ? "DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png" : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).attach("file", attachment, attachmentName).end(function (err, res) { + + if (err) { + reject(err); + } else { + + var chann = self.getChannel("id", destination); + if (chann) { + var msg = chann.addMessage(new Message(res.body, chann, [], self.user)); + resolve(msg); + } + } + }); + }); + }; + + Client.prototype._updateMessage = function _updateMessage(message, content) { + var self = this; + return new Promise(function (resolve, reject) { + request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization", self.token).send({ + content: content, + mentions: [] + }).end(function (err, res) { + if (err) { + reject(err); + } else { + var msg = new Message(res.body, message.channel, message.mentions, message.sender); + resolve(msg); + message.channel.messages[message.channel.messages.indexOf(message)] = msg; + } + }); + }); + }; + + Client.prototype.getGateway = function getGateway() { + var self = this; + return new Promise(function (resolve, reject) { + request.get(Endpoints.API + "/gateway").set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(res.body.url); + } + }); + }); + }; + + Client.prototype.setStatusIdle = function setStatusIdle() { + this.setStatus("idle"); + }; + + Client.prototype.setStatusOnline = function setStatusOnline() { + this.setStatus("online"); + }; + + Client.prototype.setStatusActive = function setStatusActive() { + this.setStatusOnline(); + }; + + Client.prototype.setStatusHere = function setStatusHere() { + this.setStatusOnline(); + }; + + Client.prototype.setStatusAway = function setStatusAway() { + this.setStatusIdle(); + }; + + Client.prototype.startTyping = function startTyping(chann, stopTypeTime) { + var self = this; + + this.resolveDestination(chann).then(next); + + function next(channel) { + if (self.typingIntervals[channel]) { + return; + } + + var fn = function fn() { + request.post(Endpoints.CHANNELS + "/" + channel + "/typing").set("authorization", self.token).end(); + }; + + fn(); + + var interval = setInterval(fn, 3000); + + self.typingIntervals[channel] = interval; + + if (stopTypeTime) { + setTimeout(function () { + self.stopTyping(channel); + }, stopTypeTime); + } + } + }; + + Client.prototype.stopTyping = function stopTyping(chann) { + var self = this; + + this.resolveDestination(chann).then(next); + + function next(channel) { + if (!self.typingIntervals[channel]) { + return; + } + + clearInterval(self.typingIntervals[channel]); + + delete self.typingIntervals[channel]; + } + }; + + Client.prototype.setStatus = function setStatus(stat) { + + var idleTime = stat === "online" ? null : Date.now(); + + this.__idleTime = idleTime; + + this.websocket.send(JSON.stringify({ + op: 3, + d: { + idle_since: this.__idleTime, + game_id: this.__gameId + } + })); + }; + + Client.prototype.setPlayingGame = function setPlayingGame(id) { + + if (id instanceof String || typeof id === "string") { + + // working on names + var gid = id.trim().toUpperCase(); + + id = null; + + for (var _iterator16 = gameMap, _isArray16 = Array.isArray(_iterator16), _i16 = 0, _iterator16 = _isArray16 ? _iterator16 : _iterator16[Symbol.iterator]();;) { + var _ref16; + + if (_isArray16) { + if (_i16 >= _iterator16.length) break; + _ref16 = _iterator16[_i16++]; + } else { + _i16 = _iterator16.next(); + if (_i16.done) break; + _ref16 = _i16.value; + } + + var game = _ref16; + + if (game.name.trim().toUpperCase() === gid) { + + id = game.id; + break; + } + } + } + + this.__gameId = id; + + this.websocket.send(JSON.stringify({ + op: 3, + d: { + idle_since: this.__idleTime, + game_id: this.__gameId + } + })); + }; + + Client.prototype.playGame = function playGame(id) { + this.setPlayingGame(id); + }; + + Client.prototype.playingGame = function playingGame(id) { + + this.setPlayingGame(id); + }; + + _createClass(Client, [{ + key: "uptime", + get: function get() { + + return this.readyTime ? Date.now() - this.readyTime : null; + } + }, { + key: "ready", + get: function get() { + return this.state === 3; + } + }, { + key: "servers", + get: function get() { + return this.serverCache; + } + }, { + key: "channels", + get: function get() { + return this.channelCache; + } + }, { + key: "users", + get: function get() { + return this.userCache; + } + }, { + key: "PMChannels", + get: function get() { + return this.pmChannelCache; + } + }, { + key: "messages", + get: function get() { + + var msgs = []; + for (var _iterator17 = this.channelCache, _isArray17 = Array.isArray(_iterator17), _i17 = 0, _iterator17 = _isArray17 ? _iterator17 : _iterator17[Symbol.iterator]();;) { + var _ref17; + + if (_isArray17) { + if (_i17 >= _iterator17.length) break; + _ref17 = _iterator17[_i17++]; + } else { + _i17 = _iterator17.next(); + if (_i17.done) break; + _ref17 = _i17.value; + } + + var channel = _ref17; + + msgs = msgs.concat(channel.messages); + } + return msgs; + } + }]); + + return Client; +})(); + +module.exports = Client; \ No newline at end of file diff --git a/lib/Endpoints.js b/lib/Endpoints.js index 60cd7925c..271b465eb 100644 --- a/lib/Endpoints.js +++ b/lib/Endpoints.js @@ -1 +1,13 @@ -"use strict";exports.BASE_DOMAIN = "discordapp.com";exports.BASE = "https://" + exports.BASE_DOMAIN;exports.WEBSOCKET_HUB = "wss://" + exports.BASE_DOMAIN + "/hub";exports.API = exports.BASE + "/api";exports.AUTH = exports.API + "/auth";exports.LOGIN = exports.AUTH + "/login";exports.LOGOUT = exports.AUTH + "/logout";exports.USERS = exports.API + "/users";exports.SERVERS = exports.API + "/guilds";exports.CHANNELS = exports.API + "/channels"; +"use strict"; + +exports.BASE_DOMAIN = "discordapp.com"; +exports.BASE = "https://" + exports.BASE_DOMAIN; +exports.WEBSOCKET_HUB = "wss://" + exports.BASE_DOMAIN + "/hub"; + +exports.API = exports.BASE + "/api"; +exports.AUTH = exports.API + "/auth"; +exports.LOGIN = exports.AUTH + "/login"; +exports.LOGOUT = exports.AUTH + "/logout"; +exports.USERS = exports.API + "/users"; +exports.SERVERS = exports.API + "/guilds"; +exports.CHANNELS = exports.API + "/channels"; \ No newline at end of file diff --git a/lib/EvaluatedPermissions.js b/lib/EvaluatedPermissions.js index efda9971a..c4720c46b 100644 --- a/lib/EvaluatedPermissions.js +++ b/lib/EvaluatedPermissions.js @@ -1 +1,187 @@ -"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 EvaluatedPermissions=(function(){function EvaluatedPermissions(data){_classCallCheck(this,EvaluatedPermissions);var self=this;this.packed = data;if(this.getBit(3))this.packed = 4294967295;}EvaluatedPermissions.prototype.serialise = function serialise(){return {createInstantInvite:this.createInstantInvite,manageRoles:this.manageRoles,manageChannels:this.manageChannels,readMessages:this.readMessages,sendMessages:this.sendMessage,sendTTSMessages:this.sendTTSMessages,manageMessages:this.manageMessages,embedLinks:this.embedLinks,attachFiles:this.attachFiles,readMessageHistory:this.readMessageHistory,mentionEveryone:this.mentionEveryone,voiceConnect:this.voiceConnect,voiceSpeak:this.voiceSpeak,voiceMuteMembers:this.voiceMuteMembers,voiceDeafenMembers:this.voiceDeafenMembers,voiceMoveMember:this.voiceMoveMembers,voiceUseVoiceActivation:this.voiceUseVoiceActivation};};EvaluatedPermissions.prototype.getBit = function getBit(x){return (this.packed >>> x & 1) === 1;};EvaluatedPermissions.prototype.setBit = function setBit(){};_createClass(EvaluatedPermissions,[{key:"createInstantInvite",get:function get(){return this.getBit(0);},set:function set(val){this.setBit(0,val);}},{key:"manageRoles",get:function get(){return this.getBit(3);},set:function set(val){this.setBit(3,val);}},{key:"manageChannels",get:function get(){return this.getBit(4);},set:function set(val){this.setBit(4,val);}},{key:"readMessages",get:function get(){return this.getBit(10);},set:function set(val){this.setBit(10,val);}},{key:"sendMessages",get:function get(){return this.getBit(11);},set:function set(val){this.setBit(11,val);}},{key:"sendTTSMessages",get:function get(){return this.getBit(12);},set:function set(val){this.setBit(12,val);}},{key:"manageMessages",get:function get(){return this.getBit(13);},set:function set(val){this.setBit(13,val);}},{key:"embedLinks",get:function get(){return this.getBit(14);},set:function set(val){this.setBit(14,val);}},{key:"attachFiles",get:function get(){return this.getBit(15);},set:function set(val){this.setBit(15,val);}},{key:"readMessageHistory",get:function get(){return this.getBit(16);},set:function set(val){this.setBit(16,val);}},{key:"mentionEveryone",get:function get(){return this.getBit(17);},set:function set(val){this.setBit(17,val);}},{key:"voiceConnect",get:function get(){return this.getBit(20);},set:function set(val){this.setBit(20,val);}},{key:"voiceSpeak",get:function get(){return this.getBit(21);},set:function set(val){this.setBit(21,val);}},{key:"voiceMuteMembers",get:function get(){return this.getBit(22);},set:function set(val){this.setBit(22,val);}},{key:"voiceDeafenMembers",get:function get(){return this.getBit(23);},set:function set(val){this.setBit(23,val);}},{key:"voiceMoveMembers",get:function get(){return this.getBit(24);},set:function set(val){this.setBit(24,val);}},{key:"voiceUseVoiceActivation",get:function get(){return this.getBit(25);},set:function set(val){this.setBit(25,val);}}]);return EvaluatedPermissions;})();module.exports = EvaluatedPermissions; +"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 EvaluatedPermissions = (function () { + function EvaluatedPermissions(data) { + _classCallCheck(this, EvaluatedPermissions); + + var self = this; + + this.packed = data; + + if (this.getBit(3)) this.packed = 4294967295; + } + + EvaluatedPermissions.prototype.serialise = function serialise() { + return { + createInstantInvite: this.createInstantInvite, + manageRoles: this.manageRoles, + manageChannels: this.manageChannels, + readMessages: this.readMessages, + sendMessages: this.sendMessage, + sendTTSMessages: this.sendTTSMessages, + manageMessages: this.manageMessages, + embedLinks: this.embedLinks, + attachFiles: this.attachFiles, + readMessageHistory: this.readMessageHistory, + mentionEveryone: this.mentionEveryone, + voiceConnect: this.voiceConnect, + voiceSpeak: this.voiceSpeak, + voiceMuteMembers: this.voiceMuteMembers, + voiceDeafenMembers: this.voiceDeafenMembers, + voiceMoveMember: this.voiceMoveMembers, + voiceUseVoiceActivation: this.voiceUseVoiceActivation + }; + }; + + EvaluatedPermissions.prototype.getBit = function getBit(x) { + return (this.packed >>> x & 1) === 1; + }; + + EvaluatedPermissions.prototype.setBit = function setBit() {}; + + _createClass(EvaluatedPermissions, [{ + key: "createInstantInvite", + get: function get() { + return this.getBit(0); + }, + set: function set(val) { + this.setBit(0, val); + } + }, { + key: "manageRoles", + get: function get() { + return this.getBit(3); + }, + set: function set(val) { + this.setBit(3, val); + } + }, { + key: "manageChannels", + get: function get() { + return this.getBit(4); + }, + set: function set(val) { + this.setBit(4, val); + } + }, { + key: "readMessages", + get: function get() { + return this.getBit(10); + }, + set: function set(val) { + this.setBit(10, val); + } + }, { + key: "sendMessages", + get: function get() { + return this.getBit(11); + }, + set: function set(val) { + this.setBit(11, val); + } + }, { + key: "sendTTSMessages", + get: function get() { + return this.getBit(12); + }, + set: function set(val) { + this.setBit(12, val); + } + }, { + key: "manageMessages", + get: function get() { + return this.getBit(13); + }, + set: function set(val) { + this.setBit(13, val); + } + }, { + key: "embedLinks", + get: function get() { + return this.getBit(14); + }, + set: function set(val) { + this.setBit(14, val); + } + }, { + key: "attachFiles", + get: function get() { + return this.getBit(15); + }, + set: function set(val) { + this.setBit(15, val); + } + }, { + key: "readMessageHistory", + get: function get() { + return this.getBit(16); + }, + set: function set(val) { + this.setBit(16, val); + } + }, { + key: "mentionEveryone", + get: function get() { + return this.getBit(17); + }, + set: function set(val) { + this.setBit(17, val); + } + }, { + key: "voiceConnect", + get: function get() { + return this.getBit(20); + }, + set: function set(val) { + this.setBit(20, val); + } + }, { + key: "voiceSpeak", + get: function get() { + return this.getBit(21); + }, + set: function set(val) { + this.setBit(21, val); + } + }, { + key: "voiceMuteMembers", + get: function get() { + return this.getBit(22); + }, + set: function set(val) { + this.setBit(22, val); + } + }, { + key: "voiceDeafenMembers", + get: function get() { + return this.getBit(23); + }, + set: function set(val) { + this.setBit(23, val); + } + }, { + key: "voiceMoveMembers", + get: function get() { + return this.getBit(24); + }, + set: function set(val) { + this.setBit(24, val); + } + }, { + key: "voiceUseVoiceActivation", + get: function get() { + return this.getBit(25); + }, + set: function set(val) { + this.setBit(25, val); + } + }]); + + return EvaluatedPermissions; +})(); + +module.exports = EvaluatedPermissions; \ No newline at end of file diff --git a/lib/Member.js b/lib/Member.js index fd41c7dce..813acda1b 100644 --- a/lib/Member.js +++ b/lib/Member.js @@ -1,4 +1,157 @@ -"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 User=require("./user.js");var ServerPermissions=require("./ServerPermissions.js");var EvaluatedPermissions=require("./EvaluatedPermissions.js");var Member=(function(_User){_inherits(Member,_User);function Member(user,server,roles){_classCallCheck(this,Member);_User.call(this,user); // should work, we are basically creating a Member that has the same properties as user and a few more -this.server = server;this.rawRoles = roles;}Member.prototype.permissionsIn = function permissionsIn(channel){if(channel.server.ownerID === this.id){return new EvaluatedPermissions(4294967295); //all perms -}var affectingOverwrites=[];var affectingMemberOverwrites=[];for(var _iterator=channel.roles,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var overwrite=_ref;if(overwrite.id === this.id && overwrite.type === "member"){affectingMemberOverwrites.push(overwrite);}else if(this.rawRoles.indexOf(overwrite.id) !== -1){affectingOverwrites.push(overwrite);}}if(affectingOverwrites.length === 0 && affectingMemberOverwrites.length === 0){return new EvaluatedPermissions(this.evalPerms.packed);}var finalPacked=affectingOverwrites.length !== 0?affectingOverwrites[0].packed:affectingMemberOverwrites[0].packed;for(var _iterator2=affectingOverwrites,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var overwrite=_ref2;finalPacked = finalPacked & ~overwrite.deny;finalPacked = finalPacked | overwrite.allow;}for(var _iterator3=affectingMemberOverwrites,_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[Symbol.iterator]();;) {var _ref3;if(_isArray3){if(_i3 >= _iterator3.length)break;_ref3 = _iterator3[_i3++];}else {_i3 = _iterator3.next();if(_i3.done)break;_ref3 = _i3.value;}var overwrite=_ref3;finalPacked = finalPacked & ~overwrite.deny;finalPacked = finalPacked | overwrite.allow;}return new EvaluatedPermissions(finalPacked);};_createClass(Member,[{key:"roles",get:function get(){var ufRoles=[this.server.getRole(this.server.id)];for(var _iterator4=this.rawRoles,_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[Symbol.iterator]();;) {var _ref4;if(_isArray4){if(_i4 >= _iterator4.length)break;_ref4 = _iterator4[_i4++];}else {_i4 = _iterator4.next();if(_i4.done)break;_ref4 = _i4.value;}var rawRole=_ref4;ufRoles.push(this.server.getRole(rawRole));}return ufRoles;}},{key:"evalPerms",get:function get(){var basePerms=this.roles, //cache roles as it can be slightly expensive -basePerm=basePerms[0].packed;for(var _iterator5=basePerms,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var perm=_ref5;basePerm = basePerm | perm.packed;}return new ServerPermissions({permissions:basePerm});}}]);return Member;})(User);module.exports = Member; +"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 User = require("./user.js"); +var ServerPermissions = require("./ServerPermissions.js"); +var EvaluatedPermissions = require("./EvaluatedPermissions.js"); + +var Member = (function (_User) { + _inherits(Member, _User); + + function Member(user, server, roles) { + _classCallCheck(this, Member); + + _User.call(this, user); // should work, we are basically creating a Member that has the same properties as user and a few more + this.server = server; + this.rawRoles = roles; + } + + Member.prototype.permissionsIn = function permissionsIn(channel) { + + if (channel.server.ownerID === this.id) { + return new EvaluatedPermissions(4294967295); //all perms + } + + var affectingOverwrites = []; + var affectingMemberOverwrites = []; + + for (var _iterator = channel.roles, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + var overwrite = _ref; + + if (overwrite.id === this.id && overwrite.type === "member") { + affectingMemberOverwrites.push(overwrite); + } else if (this.rawRoles.indexOf(overwrite.id) !== -1) { + affectingOverwrites.push(overwrite); + } + } + + if (affectingOverwrites.length === 0 && affectingMemberOverwrites.length === 0) { + return new EvaluatedPermissions(this.evalPerms.packed); + } + + var finalPacked = affectingOverwrites.length !== 0 ? affectingOverwrites[0].packed : affectingMemberOverwrites[0].packed; + + for (var _iterator2 = affectingOverwrites, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { + var _ref2; + + if (_isArray2) { + if (_i2 >= _iterator2.length) break; + _ref2 = _iterator2[_i2++]; + } else { + _i2 = _iterator2.next(); + if (_i2.done) break; + _ref2 = _i2.value; + } + + var overwrite = _ref2; + + finalPacked = finalPacked & ~overwrite.deny; + finalPacked = finalPacked | overwrite.allow; + } + + for (var _iterator3 = affectingMemberOverwrites, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { + var _ref3; + + if (_isArray3) { + if (_i3 >= _iterator3.length) break; + _ref3 = _iterator3[_i3++]; + } else { + _i3 = _iterator3.next(); + if (_i3.done) break; + _ref3 = _i3.value; + } + + var overwrite = _ref3; + + finalPacked = finalPacked & ~overwrite.deny; + finalPacked = finalPacked | overwrite.allow; + } + + return new EvaluatedPermissions(finalPacked); + }; + + _createClass(Member, [{ + key: "roles", + get: function get() { + + var ufRoles = [this.server.getRole(this.server.id)]; + + for (var _iterator4 = this.rawRoles, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { + var _ref4; + + if (_isArray4) { + if (_i4 >= _iterator4.length) break; + _ref4 = _iterator4[_i4++]; + } else { + _i4 = _iterator4.next(); + if (_i4.done) break; + _ref4 = _i4.value; + } + + var rawRole = _ref4; + + ufRoles.push(this.server.getRole(rawRole)); + } + + return ufRoles; + } + }, { + key: "evalPerms", + get: function get() { + var basePerms = this.roles, + //cache roles as it can be slightly expensive + basePerm = basePerms[0].packed; + + for (var _iterator5 = basePerms, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { + var _ref5; + + if (_isArray5) { + if (_i5 >= _iterator5.length) break; + _ref5 = _iterator5[_i5++]; + } else { + _i5 = _iterator5.next(); + if (_i5.done) break; + _ref5 = _i5.value; + } + + var perm = _ref5; + + basePerm = basePerm | perm.packed; + } + + return new ServerPermissions({ + permissions: basePerm + }); + } + }]); + + return Member; +})(User); + +module.exports = Member; \ No newline at end of file diff --git a/lib/PMChannel.js b/lib/PMChannel.js index 8d90dade1..06d1c120b 100644 --- a/lib/PMChannel.js +++ b/lib/PMChannel.js @@ -1 +1,61 @@ -"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 PMChannel=(function(){function PMChannel(data,client){_classCallCheck(this,PMChannel);this.user = client.getUser("id",data.recipient.id);this.id = data.id;this.messages = [];this.client = client;}PMChannel.prototype.addMessage = function addMessage(data){if(!this.getMessage("id",data.id)){this.messages.push(data);}return this.getMessage("id",data.id);};PMChannel.prototype.getMessage = function getMessage(key,value){if(this.messages.length > 1000){this.messages.splice(0,1);}for(var _iterator=this.messages,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var message=_ref;if(message[key] === value){return message;}}return null;};_createClass(PMChannel,[{key:"isPrivate",get:function get(){return true;}}]);return PMChannel;})();module.exports = PMChannel; +"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 PMChannel = (function () { + function PMChannel(data, client) { + _classCallCheck(this, PMChannel); + + this.user = client.getUser("id", data.recipient.id); + this.id = data.id; + this.messages = []; + this.client = client; + } + + PMChannel.prototype.addMessage = function addMessage(data) { + if (!this.getMessage("id", data.id)) { + this.messages.push(data); + } + return this.getMessage("id", data.id); + }; + + PMChannel.prototype.getMessage = function getMessage(key, value) { + + if (this.messages.length > 1000) { + this.messages.splice(0, 1); + } + + for (var _iterator = this.messages, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + var message = _ref; + + if (message[key] === value) { + return message; + } + } + return null; + }; + + _createClass(PMChannel, [{ + key: "isPrivate", + get: function get() { + return true; + } + }]); + + return PMChannel; +})(); + +module.exports = PMChannel; \ No newline at end of file diff --git a/lib/ServerPermissions.js b/lib/ServerPermissions.js index c4ad8cefb..6384f759b 100644 --- a/lib/ServerPermissions.js +++ b/lib/ServerPermissions.js @@ -1,2 +1,199 @@ -"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 ServerPermissions=(function(){function ServerPermissions(data){_classCallCheck(this,ServerPermissions);var self=this;function getBit(x){return (self.packed >>> x & 1) === 1;}this.packed = data.permissions;this.name = data.name;this.id = data.id;}ServerPermissions.prototype.getBit = function getBit(x){return (this.packed >>> x & 1) === 1;};ServerPermissions.prototype.setBit = function setBit(){ //dummy function for now -};ServerPermissions.prototype.toString = function toString(){return this.name;};_createClass(ServerPermissions,[{key:"createInstantInvite",get:function get(){return this.getBit(0);},set:function set(val){this.setBit(0,val);}},{key:"banMembers",get:function get(){return this.getBit(1);},set:function set(val){this.setBit(1,val);}},{key:"kickMembers",get:function get(){return this.getBit(2);},set:function set(val){this.setBit(2,val);}},{key:"manageRoles",get:function get(){return this.getBit(3);},set:function set(val){this.setBit(3,val);}},{key:"manageChannels",get:function get(){return this.getBit(4);},set:function set(val){this.setBit(4,val);}},{key:"manageServer",get:function get(){return this.getBit(5);},set:function set(val){this.setBit(5,val);}},{key:"readMessages",get:function get(){return this.getBit(10);},set:function set(val){this.setBit(10,val);}},{key:"sendMessages",get:function get(){return this.getBit(11);},set:function set(val){this.setBit(11,val);}},{key:"sendTTSMessages",get:function get(){return this.getBit(12);},set:function set(val){this.setBit(12,val);}},{key:"manageMessages",get:function get(){return this.getBit(13);},set:function set(val){this.setBit(13,val);}},{key:"embedLinks",get:function get(){return this.getBit(14);},set:function set(val){this.setBit(14,val);}},{key:"attachFiles",get:function get(){return this.getBit(15);},set:function set(val){this.setBit(15,val);}},{key:"readMessageHistory",get:function get(){return this.getBit(16);},set:function set(val){this.setBit(16,val);}},{key:"mentionEveryone",get:function get(){return this.getBit(17);},set:function set(val){this.setBit(17,val);}},{key:"voiceConnect",get:function get(){return this.getBit(20);},set:function set(val){this.setBit(20,val);}},{key:"voiceSpeak",get:function get(){return this.getBit(21);},set:function set(val){this.setBit(21,val);}},{key:"voiceMuteMembers",get:function get(){return this.getBit(22);},set:function set(val){this.setBit(22,val);}},{key:"voiceDeafenMembers",get:function get(){return this.getBit(23);},set:function set(val){this.setBit(23,val);}},{key:"voiceMoveMembers",get:function get(){return this.getBit(24);},set:function set(val){this.setBit(24,val);}},{key:"voiceUseVoiceActivation",get:function get(){return this.getBit(25);},set:function set(val){this.setBit(25,val);}}]);return ServerPermissions;})();module.exports = ServerPermissions; +"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 ServerPermissions = (function () { + function ServerPermissions(data) { + _classCallCheck(this, ServerPermissions); + + var self = this; + + function getBit(x) { + return (self.packed >>> x & 1) === 1; + } + + this.packed = data.permissions; + this.name = data.name; + this.id = data.id; + } + + ServerPermissions.prototype.getBit = function getBit(x) { + return (this.packed >>> x & 1) === 1; + }; + + ServerPermissions.prototype.setBit = function setBit() { + //dummy function for now + }; + + ServerPermissions.prototype.toString = function toString() { + return this.name; + }; + + _createClass(ServerPermissions, [{ + key: "createInstantInvite", + get: function get() { + return this.getBit(0); + }, + set: function set(val) { + this.setBit(0, val); + } + }, { + key: "banMembers", + get: function get() { + return this.getBit(1); + }, + set: function set(val) { + this.setBit(1, val); + } + }, { + key: "kickMembers", + get: function get() { + return this.getBit(2); + }, + set: function set(val) { + this.setBit(2, val); + } + }, { + key: "manageRoles", + get: function get() { + return this.getBit(3); + }, + set: function set(val) { + this.setBit(3, val); + } + }, { + key: "manageChannels", + get: function get() { + return this.getBit(4); + }, + set: function set(val) { + this.setBit(4, val); + } + }, { + key: "manageServer", + get: function get() { + return this.getBit(5); + }, + set: function set(val) { + this.setBit(5, val); + } + }, { + key: "readMessages", + get: function get() { + return this.getBit(10); + }, + set: function set(val) { + this.setBit(10, val); + } + }, { + key: "sendMessages", + get: function get() { + return this.getBit(11); + }, + set: function set(val) { + this.setBit(11, val); + } + }, { + key: "sendTTSMessages", + get: function get() { + return this.getBit(12); + }, + set: function set(val) { + this.setBit(12, val); + } + }, { + key: "manageMessages", + get: function get() { + return this.getBit(13); + }, + set: function set(val) { + this.setBit(13, val); + } + }, { + key: "embedLinks", + get: function get() { + return this.getBit(14); + }, + set: function set(val) { + this.setBit(14, val); + } + }, { + key: "attachFiles", + get: function get() { + return this.getBit(15); + }, + set: function set(val) { + this.setBit(15, val); + } + }, { + key: "readMessageHistory", + get: function get() { + return this.getBit(16); + }, + set: function set(val) { + this.setBit(16, val); + } + }, { + key: "mentionEveryone", + get: function get() { + return this.getBit(17); + }, + set: function set(val) { + this.setBit(17, val); + } + }, { + key: "voiceConnect", + get: function get() { + return this.getBit(20); + }, + set: function set(val) { + this.setBit(20, val); + } + }, { + key: "voiceSpeak", + get: function get() { + return this.getBit(21); + }, + set: function set(val) { + this.setBit(21, val); + } + }, { + key: "voiceMuteMembers", + get: function get() { + return this.getBit(22); + }, + set: function set(val) { + this.setBit(22, val); + } + }, { + key: "voiceDeafenMembers", + get: function get() { + return this.getBit(23); + }, + set: function set(val) { + this.setBit(23, val); + } + }, { + key: "voiceMoveMembers", + get: function get() { + return this.getBit(24); + }, + set: function set(val) { + this.setBit(24, val); + } + }, { + key: "voiceUseVoiceActivation", + get: function get() { + return this.getBit(25); + }, + set: function set(val) { + this.setBit(25, val); + } + }]); + + return ServerPermissions; +})(); + +module.exports = ServerPermissions; \ No newline at end of file diff --git a/lib/channel.js b/lib/channel.js index 04c363943..7b8b1c027 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -1,2 +1,130 @@ -"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var ChannelPermissions=require("./ChannelPermissions.js");var Channel=(function(){function Channel(data,server){_classCallCheck(this,Channel);this.server = server;this.name = data.name;this.type = data.type;this.topic = data.topic;this.id = data.id;this.messages = [];this.roles = [];if(data.permission_overwrites)for(var _iterator=data.permission_overwrites,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var role=_ref;this.roles.push(new ChannelPermissions(role,this));} //this.isPrivate = isPrivate; //not sure about the implementation of this... -}Channel.prototype.permissionsOf = function permissionsOf(member){var mem=this.server.getMember("id",member.id);if(mem){return mem.permissionsIn(this);}else {return null;}};Channel.prototype.equals = function equals(object){return object && object.id === this.id;};Channel.prototype.addMessage = function addMessage(data){if(this.messages.length > 1000){this.messages.splice(0,1);}if(!this.getMessage("id",data.id)){this.messages.push(data);}return this.getMessage("id",data.id);};Channel.prototype.getMessage = function getMessage(key,value){for(var _iterator2=this.messages,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var message=_ref2;if(message[key] === value){return message;}}return null;};Channel.prototype.toString = function toString(){return "<#" + this.id + ">";};_createClass(Channel,[{key:"permissionOverwrites",get:function get(){return this.roles;}},{key:"permissions",get:function get(){return this.roles;}},{key:"client",get:function get(){return this.server.client;}},{key:"isPrivate",get:function get(){return false;}},{key:"users",get:function get(){return this.server.members;}},{key:"members",get:function get(){return this.server.members;}}]);return Channel;})();module.exports = Channel; +"use strict"; + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var ChannelPermissions = require("./ChannelPermissions.js"); + +var Channel = (function () { + function Channel(data, server) { + _classCallCheck(this, Channel); + + this.server = server; + this.name = data.name; + this.type = data.type; + this.topic = data.topic; + this.id = data.id; + this.messages = []; + this.roles = []; + + if (data.permission_overwrites) for (var _iterator = data.permission_overwrites, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + var role = _ref; + + this.roles.push(new ChannelPermissions(role, this)); + } + + //this.isPrivate = isPrivate; //not sure about the implementation of this... + } + + Channel.prototype.permissionsOf = function permissionsOf(member) { + + var mem = this.server.getMember("id", member.id); + + if (mem) { + return mem.permissionsIn(this); + } else { + return null; + } + }; + + Channel.prototype.equals = function equals(object) { + return object && object.id === this.id; + }; + + Channel.prototype.addMessage = function addMessage(data) { + + if (this.messages.length > 1000) { + this.messages.splice(0, 1); + } + + if (!this.getMessage("id", data.id)) { + this.messages.push(data); + } + + return this.getMessage("id", data.id); + }; + + Channel.prototype.getMessage = function getMessage(key, value) { + for (var _iterator2 = this.messages, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { + var _ref2; + + if (_isArray2) { + if (_i2 >= _iterator2.length) break; + _ref2 = _iterator2[_i2++]; + } else { + _i2 = _iterator2.next(); + if (_i2.done) break; + _ref2 = _i2.value; + } + + var message = _ref2; + + if (message[key] === value) { + return message; + } + } + return null; + }; + + Channel.prototype.toString = function toString() { + return "<#" + this.id + ">"; + }; + + _createClass(Channel, [{ + key: "permissionOverwrites", + get: function get() { + return this.roles; + } + }, { + key: "permissions", + get: function get() { + return this.roles; + } + }, { + key: "client", + get: function get() { + return this.server.client; + } + }, { + key: "isPrivate", + get: function get() { + return false; + } + }, { + key: "users", + get: function get() { + return this.server.members; + } + }, { + key: "members", + get: function get() { + return this.server.members; + } + }]); + + return Channel; +})(); + +module.exports = Channel; \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index 7dfb7d88a..d0edc45cf 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1 +1,36 @@ -"use strict";var request=require("superagent");var Endpoints=require("./Endpoints.js");var Client=require("./Client.js");var Discord={Endpoints:Endpoints,Client:Client};Discord.patchStrings = function(){defineProperty("bold","**");defineProperty("underline","__");defineProperty("strike","~~");defineProperty("code","`");defineProperty("codeblock","```");defineProperty("newline","\n");Object.defineProperty(String.prototype,"italic",{get:function get(){return "*" + this + "*";}});function defineProperty(name,joiner){Object.defineProperty(String.prototype,name,{get:function get(){return joiner + this + joiner;}});}};module.exports = Discord; +"use strict"; + +var request = require("superagent"); +var Endpoints = require("./Endpoints.js"); +var Client = require("./Client.js"); + +var Discord = { + Endpoints: Endpoints, + Client: Client +}; + +Discord.patchStrings = function () { + + defineProperty("bold", "**"); + defineProperty("underline", "__"); + defineProperty("strike", "~~"); + defineProperty("code", "`"); + defineProperty("codeblock", "```"); + defineProperty("newline", "\n"); + + Object.defineProperty(String.prototype, "italic", { + get: function get() { + return "*" + this + "*"; + } + }); + + function defineProperty(name, joiner) { + Object.defineProperty(String.prototype, name, { + get: function get() { + return joiner + this + joiner; + } + }); + } +}; + +module.exports = Discord; \ No newline at end of file diff --git a/lib/internal.js b/lib/internal.js index b91c38597..3acf5940b 100644 --- a/lib/internal.js +++ b/lib/internal.js @@ -1 +1,203 @@ -"use strict";var request=require("superagent");var Endpoints=require("./endpoints.js");var Internal={};Internal.XHR = {};Internal.WebSocket = {};Internal.WebSocket.properties = {"$os":"discord.js","$browser":"discord.js","$device":"discord.js","$referrer":"","$referring_domain":""};Internal.XHR.login = function(email,password,callback){request.post(Endpoints.LOGIN).send({email:email,password:password}).end(function(err,res){if(err){callback(err);}else {callback(null,res.body.token);}});};Internal.XHR.logout = function(token,callback){request.post(Endpoints.LOGOUT).end(function(err,res){err?callback(err):callback(null);});};Internal.XHR.createServer = function(token,name,region,callback){request.post(Endpoints.SERVERS).set("authorization",token).send({name:name,region:region}).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.leaveServer = function(token,serverId,callback){request.del(Endpoints.SERVERS + "/" + serverId).set("authorization",token).end(function(err,res){err?callback(err):callback(null);});};Internal.XHR.createInvite = function(token,channelId,options,callback){request.post(Endpoints.CHANNELS + "/" + channelId + "/invites").set("authorization",token).send(options).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.startPM = function(token,selfID,userID,callback){request.post(Endpoints.USERS + "/" + selfID + "/channels").set("authorization",token).send({recipient_id:userID}).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.sendMessage = function(token,channelID,messageParameters,callback){request.post(Endpoints.CHANNELS + "/" + channelID + "/messages").set("authorization",token).send(messageParameters).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.sendFile = function(token,channelID,file,fileName,callback){request.post(Endpoints.CHANNELS + "/" + channelID + "/messages").set("authorization",token).attach("file",file,fileName).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.deleteMessage = function(token,channelID,messageID,callback){request.del(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID).set("authorization",token).end(function(err){err?callback(err):callback(null);});};Internal.XHR.updateMessage = function(token,channelID,messageID,messageParameters,callback){request.patch(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID).set("authorization",token).send(messageParameters).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.getChannelLogs = function(token,channelID,amount,callback){request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization",token).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.createChannel = function(token,serverID,name,type,callback){request.post(Endpoints.SERVERS + "/" + serverID + "/channels").set("authorization",token).send({name:name,type:type}).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.deleteChannel = function(token,channelID,callback){request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization",token).end(function(err){err?callback(err):callback(null);});};Internal.XHR.deleteServer = function(token,serverID,callback){request.del(Endpoints.SERVERS + "/" + serverID).set("authorization",token).end(function(err){err?callback(err):callback(null);});};Internal.XHR.getChannels = function(token,serverID,callback){request.get(Endpoints.SERVERS + "/" + serverID + "/channels").set("authorization",token).end(function(err){err?callback(err):callback(null);});};Internal.XHR.getServer = function(token,serverID,callback){request.get(Endpoints.SERVERS + "/" + serverID).set("authorization",token).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.acceptInvite = function(token,inviteID,callback){request.post(Endpoints.API + "/invite/" + inviteID).set("authorization",token).end(function(err,res){if(err){callback(err);}else {callback(null,res.body);}});};Internal.XHR.setUsername = function(token,avatar,email,newPassword,password,username,callback){request.patch(Endpoints.API + "/users/@me").set("authorization",token).send({avatar:avatar,email:email,new_password:newPassword,password:password,username:username}).end(function(err){callback(err);});};exports.Internal = Internal; +"use strict"; + +var request = require("superagent"); +var Endpoints = require("./endpoints.js"); + +var Internal = {}; + +Internal.XHR = {}; +Internal.WebSocket = {}; + +Internal.WebSocket.properties = { + "$os": "discord.js", + "$browser": "discord.js", + "$device": "discord.js", + "$referrer": "", + "$referring_domain": "" +}; + +Internal.XHR.login = function (email, password, callback) { + + request.post(Endpoints.LOGIN).send({ + email: email, + password: password + }).end(function (err, res) { + if (err) { + callback(err); + } else { + callback(null, res.body.token); + } + }); +}; + +Internal.XHR.logout = function (token, callback) { + + request.post(Endpoints.LOGOUT).end(function (err, res) { + + err ? callback(err) : callback(null); + }); +}; + +Internal.XHR.createServer = function (token, name, region, callback) { + + request.post(Endpoints.SERVERS).set("authorization", token).send({ + name: name, + region: region + }).end(function (err, res) { + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.leaveServer = function (token, serverId, callback) { + + request.del(Endpoints.SERVERS + "/" + serverId).set("authorization", token).end(function (err, res) { + + err ? callback(err) : callback(null); + }); +}; + +Internal.XHR.createInvite = function (token, channelId, options, callback) { + request.post(Endpoints.CHANNELS + "/" + channelId + "/invites").set("authorization", token).send(options).end(function (err, res) { + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.startPM = function (token, selfID, userID, callback) { + + request.post(Endpoints.USERS + "/" + selfID + "/channels").set("authorization", token).send({ + recipient_id: userID + }).end(function (err, res) { + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.sendMessage = function (token, channelID, messageParameters, callback) { + request.post(Endpoints.CHANNELS + "/" + channelID + "/messages").set("authorization", token).send(messageParameters).end(function (err, res) { + + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.sendFile = function (token, channelID, file, fileName, callback) { + request.post(Endpoints.CHANNELS + "/" + channelID + "/messages").set("authorization", token).attach("file", file, fileName).end(function (err, res) { + + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.deleteMessage = function (token, channelID, messageID, callback) { + request.del(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID).set("authorization", token).end(function (err) { + err ? callback(err) : callback(null); + }); +}; + +Internal.XHR.updateMessage = function (token, channelID, messageID, messageParameters, callback) { + + request.patch(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID).set("authorization", token).send(messageParameters).end(function (err, res) { + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.getChannelLogs = function (token, channelID, amount, callback) { + request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization", token).end(function (err, res) { + + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.createChannel = function (token, serverID, name, type, callback) { + request.post(Endpoints.SERVERS + "/" + serverID + "/channels").set("authorization", token).send({ + name: name, + type: type + }).end(function (err, res) { + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.deleteChannel = function (token, channelID, callback) { + + request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization", token).end(function (err) { + err ? callback(err) : callback(null); + }); +}; +Internal.XHR.deleteServer = function (token, serverID, callback) { + request.del(Endpoints.SERVERS + "/" + serverID).set("authorization", token).end(function (err) { + err ? callback(err) : callback(null); + }); +}; + +Internal.XHR.getChannels = function (token, serverID, callback) { + request.get(Endpoints.SERVERS + "/" + serverID + "/channels").set("authorization", token).end(function (err) { + err ? callback(err) : callback(null); + }); +}; + +Internal.XHR.getServer = function (token, serverID, callback) { + + request.get(Endpoints.SERVERS + "/" + serverID).set("authorization", token).end(function (err, res) { + + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.acceptInvite = function (token, inviteID, callback) { + + request.post(Endpoints.API + "/invite/" + inviteID).set("authorization", token).end(function (err, res) { + if (err) { + callback(err); + } else { + callback(null, res.body); + } + }); +}; + +Internal.XHR.setUsername = function (token, avatar, email, newPassword, password, username, callback) { + + request.patch(Endpoints.API + "/users/@me").set("authorization", token).send({ + avatar: avatar, + email: email, + new_password: newPassword, + password: password, + username: username + }).end(function (err) { + callback(err); + }); +}; + +exports.Internal = Internal; \ No newline at end of file diff --git a/lib/invite.js b/lib/invite.js index 5ff2ddf15..5f51dc1a9 100644 --- a/lib/invite.js +++ b/lib/invite.js @@ -1 +1,35 @@ -"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 Invite=(function(){function Invite(data,client){_classCallCheck(this,Invite);this.max_age = data.max_age;this.code = data.code;this.server = client.getServer("id",data.guild.id);this.revoked = data.revoked;this.created_at = Date.parse(data.created_at);this.temporary = data.temporary;this.uses = data.uses;this.max_uses = data.uses;this.inviter = client.addUser(data.inviter);this.xkcd = data.xkcdpass;this.channel = client.getChannel("id",data.channel.id);}_createClass(Invite,[{key:"URL",get:function get(){var code=this.xkcd?this.xkcdpass:this.code;return "https://discord.gg/" + code;}}]);return Invite;})();module.exports = Invite; +"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 Invite = (function () { + function Invite(data, client) { + _classCallCheck(this, Invite); + + this.max_age = data.max_age; + this.code = data.code; + this.server = client.getServer("id", data.guild.id); + this.revoked = data.revoked; + this.created_at = Date.parse(data.created_at); + this.temporary = data.temporary; + this.uses = data.uses; + this.max_uses = data.uses; + this.inviter = client.addUser(data.inviter); + this.xkcd = data.xkcdpass; + this.channel = client.getChannel("id", data.channel.id); + } + + _createClass(Invite, [{ + key: "URL", + get: function get() { + var code = this.xkcd ? this.xkcdpass : this.code; + return "https://discord.gg/" + code; + } + }]); + + return Invite; +})(); + +module.exports = Invite; \ No newline at end of file diff --git a/lib/message.js b/lib/message.js index 26d9e4f69..72c1eb7f2 100644 --- a/lib/message.js +++ b/lib/message.js @@ -1,3 +1,75 @@ -"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 PMChannel=require("./PMChannel.js");var Message=(function(){function Message(data,channel,mentions,author){_classCallCheck(this,Message);this.tts = data.tts;this.timestamp = Date.parse(data.timestamp);this.nonce = data.nonce;this.mentions = mentions;this.everyoneMentioned = data.mention_everyone;this.id = data.id;this.embeds = data.embeds;this.editedTimestamp = data.edited_timestamp;this.content = data.content.trim();this.channel = channel;if(this.isPrivate){this.author = this.channel.client.getUser("id",author.id);}else {this.author = this.channel.server.getMember("id",author.id) || this.channel.client.getUser("id",author.id);}this.attachments = data.attachments;} /*exports.Message.prototype.isPM = function() { - return ( this.channel instanceof PMChannel ); -}*/Message.prototype.isMentioned = function isMentioned(user){var id=user.id?user.id:user;for(var _iterator=this.mentions,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var mention=_ref;if(mention.id === id){return true;}}return false;};_createClass(Message,[{key:"sender",get:function get(){return this.author;}},{key:"isPrivate",get:function get(){return this.channel.isPrivate;}}]);return Message;})();module.exports = Message; +"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 PMChannel = require("./PMChannel.js"); + +var Message = (function () { + function Message(data, channel, mentions, author) { + _classCallCheck(this, Message); + + this.tts = data.tts; + this.timestamp = Date.parse(data.timestamp); + this.nonce = data.nonce; + this.mentions = mentions; + this.everyoneMentioned = data.mention_everyone; + this.id = data.id; + this.embeds = data.embeds; + this.editedTimestamp = data.edited_timestamp; + this.content = data.content.trim(); + this.channel = channel; + + if (this.isPrivate) { + this.author = this.channel.client.getUser("id", author.id); + } else { + this.author = this.channel.server.getMember("id", author.id) || this.channel.client.getUser("id", author.id); + } + + this.attachments = data.attachments; + } + + /*exports.Message.prototype.isPM = function() { + return ( this.channel instanceof PMChannel ); + }*/ + + Message.prototype.isMentioned = function isMentioned(user) { + var id = user.id ? user.id : user; + for (var _iterator = this.mentions, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + var mention = _ref; + + if (mention.id === id) { + return true; + } + } + return false; + }; + + _createClass(Message, [{ + key: "sender", + get: function get() { + return this.author; + } + }, { + key: "isPrivate", + get: function get() { + return this.channel.isPrivate; + } + }]); + + return Message; +})(); + +module.exports = Message; \ No newline at end of file diff --git a/lib/server.js b/lib/server.js index b2fc6353a..46676d5eb 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1,7 +1,277 @@ -"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 ServerPermissions=require("./ServerPermissions.js");var Member=require("./Member.js");var Server=(function(){function Server(data,client){_classCallCheck(this,Server);this.client = client;this.region = data.region;this.ownerID = data.owner_id;this.name = data.name;this.id = data.id;this.members = [];this.channels = [];this.icon = data.icon;this.afkTimeout = data.afk_timeout;this.afkChannelId = data.afk_channel_id;this.roles = [];for(var _iterator=data.roles,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var permissionGroup=_ref;this.roles.push(new ServerPermissions(permissionGroup));}if(!data.members){data.members = [client.user];return;}for(var _iterator2=data.members,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var member=_ref2; // first we cache the user in our Discord Client, -// then we add it to our list. This way when we -// get a user from this server's member list, -// it will be identical (unless an async change occurred) -// to the client's cache. -if(member.user)this.addMember(client.addUser(member.user),member.roles);}} // get/set -Server.prototype.getRole = function getRole(id){for(var _iterator3=this.roles,_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[Symbol.iterator]();;) {var _ref3;if(_isArray3){if(_i3 >= _iterator3.length)break;_ref3 = _iterator3[_i3++];}else {_i3 = _iterator3.next();if(_i3.done)break;_ref3 = _i3.value;}var role=_ref3;if(role.id === id){return role;}}return null;};Server.prototype.updateRole = function updateRole(data){var oldRole=this.getRole(data.id);if(oldRole){var index=this.roles.indexOf(oldRole);this.roles[index] = new ServerPermissions(data);return this.roles[index];}else {return false;}};Server.prototype.removeRole = function removeRole(id){for(var roleId in this.roles) {if(this.roles[roleId].id === id){this.roles.splice(roleId,1);}}for(var _iterator4=this.members,_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[Symbol.iterator]();;) {var _ref4;if(_isArray4){if(_i4 >= _iterator4.length)break;_ref4 = _iterator4[_i4++];}else {_i4 = _iterator4.next();if(_i4.done)break;_ref4 = _i4.value;}var member=_ref4;for(var roleId in member.rawRoles) {if(member.rawRoles[roleId] === id){member.rawRoles.splice(roleId,1);}}}};Server.prototype.getChannel = function getChannel(key,value){for(var _iterator5=this.channels,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var channel=_ref5;if(channel[key] === value){return channel;}}return null;};Server.prototype.getMember = function getMember(key,value){for(var _iterator6=this.members,_isArray6=Array.isArray(_iterator6),_i6=0,_iterator6=_isArray6?_iterator6:_iterator6[Symbol.iterator]();;) {var _ref6;if(_isArray6){if(_i6 >= _iterator6.length)break;_ref6 = _iterator6[_i6++];}else {_i6 = _iterator6.next();if(_i6.done)break;_ref6 = _i6.value;}var member=_ref6;if(member[key] === value){return member;}}return null;};Server.prototype.removeMember = function removeMember(key,value){for(var _iterator7=this.members,_isArray7=Array.isArray(_iterator7),_i7=0,_iterator7=_isArray7?_iterator7:_iterator7[Symbol.iterator]();;) {var _ref7;if(_isArray7){if(_i7 >= _iterator7.length)break;_ref7 = _iterator7[_i7++];}else {_i7 = _iterator7.next();if(_i7.done)break;_ref7 = _i7.value;}var member=_ref7;if(member[key] === value){this.members.splice(key,1);return member;}}return false;};Server.prototype.addChannel = function addChannel(chann){if(!this.getChannel("id",chann.id)){this.channels.push(chann);}return chann;};Server.prototype.addMember = function addMember(user,roles){if(!this.getMember("id",user.id)){var mem=new Member(user,this,roles);this.members.push(mem);}return mem;};Server.prototype.toString = function toString(){return this.name;};Server.prototype.equals = function equals(object){return object.id === this.id;};_createClass(Server,[{key:"permissionGroups",get:function get(){return this.roles;}},{key:"permissions",get:function get(){return this.roles;}},{key:"iconURL",get:function get(){if(!this.icon)return null;return "https://discordapp.com/api/guilds/" + this.id + "/icons/" + this.icon + ".jpg";}},{key:"afkChannel",get:function get(){if(!this.afkChannelId)return false;return this.getChannel("id",this.afkChannelId);}},{key:"defaultChannel",get:function get(){return this.getChannel("name","general");}},{key:"owner",get:function get(){return this.client.getUser("id",this.ownerID);}},{key:"users",get:function get(){return this.members;}}]);return Server;})();module.exports = Server; +"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 ServerPermissions = require("./ServerPermissions.js"); +var Member = require("./Member.js"); + +var Server = (function () { + function Server(data, client) { + _classCallCheck(this, Server); + + this.client = client; + this.region = data.region; + this.ownerID = data.owner_id; + this.name = data.name; + this.id = data.id; + this.members = []; + this.channels = []; + this.icon = data.icon; + this.afkTimeout = data.afk_timeout; + this.afkChannelId = data.afk_channel_id; + + this.roles = []; + + for (var _iterator = data.roles, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + var permissionGroup = _ref; + + this.roles.push(new ServerPermissions(permissionGroup)); + } + + if (!data.members) { + data.members = [client.user]; + return; + } + + for (var _iterator2 = data.members, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { + var _ref2; + + if (_isArray2) { + if (_i2 >= _iterator2.length) break; + _ref2 = _iterator2[_i2++]; + } else { + _i2 = _iterator2.next(); + if (_i2.done) break; + _ref2 = _i2.value; + } + + var member = _ref2; + + // first we cache the user in our Discord Client, + // then we add it to our list. This way when we + // get a user from this server's member list, + // it will be identical (unless an async change occurred) + // to the client's cache. + if (member.user) this.addMember(client.addUser(member.user), member.roles); + } + } + + // get/set + + Server.prototype.getRole = function getRole(id) { + for (var _iterator3 = this.roles, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { + var _ref3; + + if (_isArray3) { + if (_i3 >= _iterator3.length) break; + _ref3 = _iterator3[_i3++]; + } else { + _i3 = _iterator3.next(); + if (_i3.done) break; + _ref3 = _i3.value; + } + + var role = _ref3; + + if (role.id === id) { + return role; + } + } + + return null; + }; + + Server.prototype.updateRole = function updateRole(data) { + + var oldRole = this.getRole(data.id); + + if (oldRole) { + + var index = this.roles.indexOf(oldRole); + this.roles[index] = new ServerPermissions(data); + + return this.roles[index]; + } else { + return false; + } + }; + + Server.prototype.removeRole = function removeRole(id) { + for (var roleId in this.roles) { + if (this.roles[roleId].id === id) { + this.roles.splice(roleId, 1); + } + } + + for (var _iterator4 = this.members, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { + var _ref4; + + if (_isArray4) { + if (_i4 >= _iterator4.length) break; + _ref4 = _iterator4[_i4++]; + } else { + _i4 = _iterator4.next(); + if (_i4.done) break; + _ref4 = _i4.value; + } + + var member = _ref4; + + for (var roleId in member.rawRoles) { + if (member.rawRoles[roleId] === id) { + member.rawRoles.splice(roleId, 1); + } + } + } + }; + + Server.prototype.getChannel = function getChannel(key, value) { + for (var _iterator5 = this.channels, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { + var _ref5; + + if (_isArray5) { + if (_i5 >= _iterator5.length) break; + _ref5 = _iterator5[_i5++]; + } else { + _i5 = _iterator5.next(); + if (_i5.done) break; + _ref5 = _i5.value; + } + + var channel = _ref5; + + if (channel[key] === value) { + return channel; + } + } + + return null; + }; + + Server.prototype.getMember = function getMember(key, value) { + for (var _iterator6 = this.members, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { + var _ref6; + + if (_isArray6) { + if (_i6 >= _iterator6.length) break; + _ref6 = _iterator6[_i6++]; + } else { + _i6 = _iterator6.next(); + if (_i6.done) break; + _ref6 = _i6.value; + } + + var member = _ref6; + + if (member[key] === value) { + return member; + } + } + + return null; + }; + + Server.prototype.removeMember = function removeMember(key, value) { + for (var _iterator7 = this.members, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) { + var _ref7; + + if (_isArray7) { + if (_i7 >= _iterator7.length) break; + _ref7 = _iterator7[_i7++]; + } else { + _i7 = _iterator7.next(); + if (_i7.done) break; + _ref7 = _i7.value; + } + + var member = _ref7; + + if (member[key] === value) { + this.members.splice(key, 1); + return member; + } + } + + return false; + }; + + Server.prototype.addChannel = function addChannel(chann) { + if (!this.getChannel("id", chann.id)) { + this.channels.push(chann); + } + return chann; + }; + + Server.prototype.addMember = function addMember(user, roles) { + if (!this.getMember("id", user.id)) { + var mem = new Member(user, this, roles); + this.members.push(mem); + } + return mem; + }; + + Server.prototype.toString = function toString() { + return this.name; + }; + + Server.prototype.equals = function equals(object) { + return object.id === this.id; + }; + + _createClass(Server, [{ + key: "permissionGroups", + get: function get() { + return this.roles; + } + }, { + key: "permissions", + get: function get() { + return this.roles; + } + }, { + key: "iconURL", + get: function get() { + if (!this.icon) return null; + return "https://discordapp.com/api/guilds/" + this.id + "/icons/" + this.icon + ".jpg"; + } + }, { + key: "afkChannel", + get: function get() { + if (!this.afkChannelId) return false; + + return this.getChannel("id", this.afkChannelId); + } + }, { + key: "defaultChannel", + get: function get() { + return this.getChannel("name", "general"); + } + }, { + key: "owner", + get: function get() { + return this.client.getUser("id", this.ownerID); + } + }, { + key: "users", + get: function get() { + return this.members; + } + }]); + + return Server; +})(); + +module.exports = Server; \ No newline at end of file diff --git a/lib/user.js b/lib/user.js index ed82a19dc..2234f030f 100644 --- a/lib/user.js +++ b/lib/user.js @@ -1,7 +1,54 @@ -"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 User=(function(){function User(data){_classCallCheck(this,User);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;} // access using user.avatarURL; -User.prototype.mention = function mention(){return "<@" + this.id + ">";};User.prototype.toString = function toString(){ /* - if we embed a user in a String - like so: - "Yo " + user + " what's up?" - It would generate something along the lines of: - "Yo @hydrabolt what's up?" - */return this.mention();};User.prototype.equals = function equals(object){return object.id === this.id;};User.prototype.equalsStrict = function equalsStrict(object){return object.id === this.id && object.avatar === this.avatar && object.username === this.username && object.discriminator === this.discriminator;};_createClass(User,[{key:"avatarURL",get:function get(){if(!this.avatar)return null;return "https://discordapp.com/api/users/" + this.id + "/avatars/" + this.avatar + ".jpg";}}]);return User;})();module.exports = User; +"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 User = (function () { + function User(data) { + _classCallCheck(this, User); + + 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; + } + + // access using user.avatarURL; + + User.prototype.mention = function mention() { + return "<@" + this.id + ">"; + }; + + User.prototype.toString = function toString() { + /* + if we embed a user in a String - like so: + "Yo " + user + " what's up?" + It would generate something along the lines of: + "Yo @hydrabolt what's up?" + */ + return this.mention(); + }; + + User.prototype.equals = function equals(object) { + return object.id === this.id; + }; + + User.prototype.equalsStrict = function equalsStrict(object) { + return object.id === this.id && object.avatar === this.avatar && object.username === this.username && object.discriminator === this.discriminator; + }; + + _createClass(User, [{ + key: "avatarURL", + get: function get() { + if (!this.avatar) return null; + return "https://discordapp.com/api/users/" + this.id + "/avatars/" + this.avatar + ".jpg"; + } + }]); + + return User; +})(); + +module.exports = User; \ No newline at end of file diff --git a/src/Client.js b/src/Client.js index ad9b33524..b51a9d446 100644 --- a/src/Client.js +++ b/src/Client.js @@ -591,6 +591,38 @@ class Client { } + setAvatar(resource, callback = function (err) { }) { + + var self = this; + + return new Promise(function (resolve, reject) { + if (resource instanceof Buffer) { + resource = resource.toString("base64"); + resource = "data:image/jpg;base64," + resource; + } + + request + .patch(`${Endpoints.API}/users/@me`) + .set("authorization", self.token) + .send({ + avatar: resource, + email: self.email, + new_password: null, + password: self.password, + username: self.user.username + }) + .end(function (err) { + callback(err); + if (err) + reject(err); + else + resolve(); + }); + + }); + + } + sendFile(destination, file, fileName = "image.png", callback = function (err, msg) { }) { var self = this; @@ -958,7 +990,7 @@ class Client { var user = self.addUser(data.user); //if for whatever reason it doesn't exist.. server.removeMember("id", user.id); - + self.trigger("serverRemoveMember", user, server); } @@ -993,13 +1025,13 @@ class Client { data.user.id = data.user.id || userInCache.id; data.user.discriminator = data.user.discriminator || userInCache.discriminator; data.user.avatar = data.user.avatar || userInCache.avatar; - + var presenceUser = new User(data.user); if (presenceUser.equalsStrict(userInCache)) { //they're exactly the same, an actual presence update self.trigger("presence", { user: userInCache, - oldStatus : userInCache.status, + oldStatus: userInCache.status, status: data.status, server: self.getServer("id", data.guild_id), gameId: data.game_id @@ -1055,26 +1087,26 @@ class Client { }, 6000); break; - + case "GUILD_ROLE_DELETE": - + var server = self.getServer("id", data.guild_id); var role = server.getRole(data.role_id); - + self.trigger("serverRoleDelete", server, role); - + server.removeRole(role.id); - + break; - + case "GUILD_ROLE_UPDATE": - + var server = self.getServer("id", data.guild_id); var role = server.getRole(data.role.id); var newRole = server.updateRole(data.role); - + self.trigger("serverRoleUpdate", server, role, newRole); - + break; default: diff --git a/test/bot.1.js b/test/bot.1.js index 4917e0f93..b607701eb 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -1,6 +1,7 @@ var Discord = require("../"); var mybot = new Discord.Client(); var fs = require("fs"); +var request = require("request").defaults({ encoding: null }); Discord.patchStrings(); @@ -29,14 +30,11 @@ mybot.on("message", function (message) { var perms = JSON.stringify(message.channel.permissionsOf(user).serialise(), null, 4); perms = JSON.parse(perms); - mybot.sendMessage(message, - "bold".bold.newline + - "italic".italic.newline + - "underline".underline.newline + - "strike".strike.newline + - "code".code.newline + - "codeblock".codeblock.newline - ); + request.get(message.sender.avatarURL, function(err, resp, body){ + mybot.setAvatar( new Buffer(body) ).catch(error).then(() => { + mybot.reply(message, "I have your avatar now!"); + }); + }); });