diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..2132329f3 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,30 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Launch", + "type": "node", + "request": "launch", + "program": "./entrypoint.js", + "stopOnEntry": false, + "args": [], + "cwd": ".", + "runtimeExecutable": null, + "runtimeArgs": [ + "--nolazy" + ], + "env": { + "NODE_ENV": "development" + }, + "externalConsole": false, + "sourceMaps": false, + "outDir": null + }, + { + "name": "Attach", + "type": "node", + "request": "attach", + "port": 5858 + } + ] +} \ No newline at end of file diff --git a/lib/Client/Client.js b/lib/Client/Client.js index 9752bf72b..ea20f2693 100644 --- a/lib/Client/Client.js +++ b/lib/Client/Client.js @@ -1,58 +1,878 @@ -"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 InternalClient=require("./InternalClient.js");var EventEmitter=require("events");var Client=(function(_EventEmitter){_inherits(Client,_EventEmitter); /* - this class is an interface for the internal - client. - */function Client(options){_classCallCheck(this,Client);_EventEmitter.call(this);this.options = options || {};this.internal = new InternalClient(this);} // def login -Client.prototype.login = function login(email,password){var cb=arguments.length <= 2 || arguments[2] === undefined?function(err,token){}:arguments[2];var self=this;return new Promise(function(resolve,reject){self.internal.login(email,password).then(function(token){cb(null,token);resolve(token);})["catch"](function(e){cb(e);reject(e);});});}; // def logout -Client.prototype.logout = function logout(){var cb=arguments.length <= 0 || arguments[0] === undefined?function(err){}:arguments[0];var self=this;return new Promise(function(resolve,reject){self.internal.logout().then(function(){cb();resolve();})["catch"](function(e){cb(e);reject(e);});});}; // def sendMessage -Client.prototype.sendMessage = function sendMessage(where,content){var options=arguments.length <= 2 || arguments[2] === undefined?{}:arguments[2];var callback=arguments.length <= 3 || arguments[3] === undefined?function(e,m){}:arguments[3];var self=this;return new Promise(function(resolve,reject){if(typeof options === "function"){ // options is the callback -callback = options;}self.internal.sendMessage(where,content,options).then(function(m){callback(null,m);resolve(m);})["catch"](function(e){callback(e);reject(e);});});}; // def sendTTSMessage -Client.prototype.sendTTSMessage = function sendTTSMessage(where,content){var callback=arguments.length <= 2 || arguments[2] === undefined?function(e,m){}:arguments[2];var self=this;return new Promise(function(resolve,reject){self.sendMessage(where,content,{tts:true}).then(function(m){callback(null,m);resolve(m);})["catch"](function(e){callback(e);reject(e);});});}; // def reply -Client.prototype.reply = function reply(where,content){var options=arguments.length <= 2 || arguments[2] === undefined?{}:arguments[2];var callback=arguments.length <= 3 || arguments[3] === undefined?function(e,m){}:arguments[3];var self=this;return new Promise(function(resolve,reject){if(typeof options === "function"){ // options is the callback -callback = options;}var msg=self.internal.resolver.resolveMessage(where);if(msg){content = msg.author + ", " + content;self.internal.sendMessage(msg,content,options).then(function(m){callback(null,m);resolve(m);})["catch"](function(e){callback(e);reject(e);});}else {var err=new Error("Destination not resolvable to a message!");callback(err);reject(err);}});}; // def replyTTS -Client.prototype.replyTTS = function replyTTS(where,content){var callback=arguments.length <= 2 || arguments[2] === undefined?function(){}:arguments[2];return new Promise(function(resolve,reject){self.reply(where,content,{tts:true}).then(function(m){callback(null,m);resolve(m);})["catch"](function(e){callback(e);reject(e);});});}; // def deleteMessage -Client.prototype.deleteMessage = function deleteMessage(msg){var options=arguments.length <= 1 || arguments[1] === undefined?{}:arguments[1];var callback=arguments.length <= 2 || arguments[2] === undefined?function(e){}:arguments[2];var self=this;return new Promise(function(resolve,reject){if(typeof options === "function"){ // options is the callback -callback = options;}self.internal.deleteMessage(msg,options).then(function(){callback();resolve();})["catch"](function(e){callback(e);reject(e);});});}; //def updateMessage -Client.prototype.updateMessage = function updateMessage(msg,content){var options=arguments.length <= 2 || arguments[2] === undefined?{}:arguments[2];var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,msg){}:arguments[3];var self=this;return new Promise(function(resolve,reject){if(typeof options === "function"){ // options is the callback -callback = options;}self.internal.updateMessage(msg,content,options).then(function(msg){callback(null,msg);resolve(msg);})["catch"](function(e){callback(e);reject(e);});});}; // def getChannelLogs -Client.prototype.getChannelLogs = function getChannelLogs(where){var limit=arguments.length <= 1 || arguments[1] === undefined?500:arguments[1];var options=arguments.length <= 2 || arguments[2] === undefined?{}:arguments[2];var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,logs){}:arguments[3];var self=this;return new Promise(function(resolve,reject){if(typeof options === "function"){ // options is the callback -callback = options;}self.internal.getChannelLogs(where,limit,options).then(function(logs){callback(null,logs);resolve(logs);})["catch"](function(e){callback(e);reject(e);});});}; // def getBans -Client.prototype.getBans = function getBans(where){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,bans){}:arguments[1];var self=this;return new Promise(function(resolve,reject){self.internal.getBans(where).then(function(bans){callback(null,bans);resolve(bans);})["catch"](function(e){callback(e);reject(e);});});}; // def sendFile -Client.prototype.sendFile = function sendFile(where,attachment){var name=arguments.length <= 2 || arguments[2] === undefined?"image.png":arguments[2];var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,m){}:arguments[3];var self=this;return new Promise(function(resolve,reject){self.internal.sendFile(where,attachment,name).then(function(m){callback(null,m);resolve(m);})["catch"](function(e){callback(e);reject(e);});});}; // def joinServer -Client.prototype.joinServer = function joinServer(invite){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,srv){}:arguments[1];var self=this;return new Promise(function(resolve,reject){self.internal.joinServer(invite).then(function(srv){callback(null,srv);resolve(srv);})["catch"](function(e){callback(e);reject(e);});});}; // def createServer -Client.prototype.createServer = function createServer(name){var region=arguments.length <= 1 || arguments[1] === undefined?"london":arguments[1];var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,srv){}:arguments[2];var self=this;return new Promise(function(resolve,reject){self.internal.createServer(name,region).then(function(srv){callback(null,srv);resolve(srv);})["catch"](function(e){callback(e);reject(e);});});}; // def leaveServer -Client.prototype.leaveServer = function leaveServer(server){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){self.internal.leaveServer(server).then(function(){callback();resolve();})["catch"](function(e){callback(e);reject(e);});});}; // def createChannel -Client.prototype.createChannel = function createChannel(server,name){var type=arguments.length <= 2 || arguments[2] === undefined?"text":arguments[2];var callback=arguments.length <= 3 || arguments[3] === undefined?function(err,channel){}:arguments[3];var self=this;return new Promise(function(resolve,reject){if(typeof type === "function"){ // options is the callback -callback = type;}self.internal.createChannel(server,name,type).then(function(channel){callback(channel);resolve(channel);})["catch"](function(e){callback(e);reject(e);});});}; // def deleteChannel -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){self.internal.deleteChannel(channel).then(function(){callback();resolve();})["catch"](function(e){callback(e);reject(e);});});}; //def banMember -Client.prototype.banMember = function banMember(user,server){var length=arguments.length <= 2 || arguments[2] === undefined?1:arguments[2];var callback=arguments.length <= 3 || arguments[3] === undefined?function(err){}:arguments[3];var self=this;return new Promise(function(resolve,reject){if(typeof length === "function"){ // length is the callback -callback = length;}self.internal.banMember(user,server,length).then(function(){callback();resolve();})["catch"](function(e){callback(e);reject(e);});});}; //def unbanMember -Client.prototype.unbanMember = function unbanMember(user,server){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err){}:arguments[2];var self=this;return new Promise(function(resolve,reject){self.internal.unbanMember(user,server).then(function(){callback();resolve();})["catch"](function(e){callback(e);reject(e);});});}; //def kickMember -Client.prototype.kickMember = function kickMember(user,server){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err){}:arguments[2];var self=this;return new Promise(function(resolve,reject){self.internal.kickMember(user,server).then(function(){callback();resolve();})["catch"](function(e){callback(e);reject(e);});});}; //def createRole -Client.prototype.createRole = function createRole(server){var data=arguments.length <= 1 || arguments[1] === undefined?null:arguments[1];var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,res){}:arguments[2];var self=this;return new Promise(function(resolve,reject){if(typeof data === "function"){ // data is the callback -callback = data;}self.internal.createRole(server,data).then(function(role){callback(null,role);resolve(role);})["catch"](function(e){callback(e);reject(e);});});}; //def updateRole -Client.prototype.updateRole = function updateRole(role){var data=arguments.length <= 1 || arguments[1] === undefined?null:arguments[1];var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,res){}:arguments[2];var self=this;return new Promise(function(resolve,reject){if(typeof data === "function"){ // data is the callback -callback = data;}self.internal.updateRole(role,data).then(function(role){callback(null,role);resolve(role);})["catch"](function(e){callback(e);reject(e);});});}; //def deleteRole -Client.prototype.deleteRole = function deleteRole(role){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){self.internal.deleteRole(role).then(function(){callback();resolve();})["catch"](function(e){callback(e);reject(e);});});}; //def addMemberToRole -Client.prototype.addMemberToRole = function addMemberToRole(member,role){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err){}:arguments[2];var self=this;return new Promise(function(resolve,reject){self.internal.addMemberToRole(member,role).then(function(){callback();resolve();})["catch"](function(e){callback(e);reject(e);});});}; // def addUserToRole -Client.prototype.addUserToRole = function addUserToRole(member,role){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err){}:arguments[2];return this.addMemberToRole(member,role,callback);}; // def removeMemberFromRole -Client.prototype.removeMemberFromRole = function removeMemberFromRole(member,role){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err){}:arguments[2];var self=this;return new Promise(function(resolve,reject){self.internal.removeMemberFromRole(member,role).then(function(){callback();resolve();})["catch"](function(e){callback(e);reject(e);});});}; // def removeUserFromRole -Client.prototype.removeUserFromRole = function removeUserFromRole(member,role){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err){}:arguments[2];return this.removeUserFromRole(member,role,callback);}; // def createInvite -Client.prototype.createInvite = function createInvite(chanServ,options){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,invite){}:arguments[2];var self=this;return new Promise(function(resolve,reject){if(typeof options === "function"){ // length is the callback -callback = options;}self.internal.createInvite(chanServ,options).then(function(invite){callback(null,invite);resolve(invite);})["catch"](function(e){callback(e);reject(e);});});}; // def deleteInvite -Client.prototype.deleteInvite = function deleteInvite(invite){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){self.internal.deleteInvite(invite).then(function(){callback();resolve();})["catch"](function(e){callback(e);reject(e);});});}; // def overwritePermissions -Client.prototype.overwritePermissions = function overwritePermissions(channel,role){var options=arguments.length <= 2 || arguments[2] === undefined?{}:arguments[2];var callback=arguments.length <= 3 || arguments[3] === undefined?function(err){}:arguments[3];var self=this;return new Promise(function(resolve,reject){self.internal.overwritePermissions(channel,role,options).then(function(){callback();resolve();})["catch"](function(e){callback(e);reject(e);});});}; //def setStatus -Client.prototype.setStatus = function setStatus(idleStatus,gameID){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err){}:arguments[2];var self=this;return new Promise(function(resolve,reject){if(typeof gameID === "function"){ // gameID is the callback -callback = gameID;}else if(typeof idleStatus === "function"){ // idleStatus is the callback -callback = idleStatus;}self.internal.setStatus(idleStatus,gameID).then(function(){callback();resolve();})["catch"](function(e){callback(e);reject(e);});});}; //def sendTyping -Client.prototype.sendTyping = function sendTyping(channel){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){self.internal.sendTyping(channel).then(function(){callback();resolve();})["catch"](function(e){callback(e);reject(e);});});}; // def setTopic -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.internal.setTopic(channel,topic).then(function(){callback();resolve();})["catch"](function(e){callback(e);reject(e);});});}; //def setChannelName -Client.prototype.setChannelName = function setChannelName(channel,name){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err){}:arguments[2];var self=this;return new Promise(function(resolve,reject){self.internal.setChannelName(channel,name).then(function(){callback();resolve();})["catch"](function(e){callback(e);reject(e);});});}; //def setChannelNameAndTopic -Client.prototype.setChannelNameAndTopic = function setChannelNameAndTopic(channel,name,topic){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err){}:arguments[3];var self=this;return new Promise(function(resolve,reject){self.internal.setChannelNameAndTopic(channel,name,topic).then(function(){callback();resolve();})["catch"](function(e){callback(e);reject(e);});});}; //def updateChannel -Client.prototype.updateChannel = function updateChannel(channel,data){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err){}:arguments[2];var self=this;return new Promise(function(resolve,reject){self.internal.updateChannel(channel,data).then(function(){callback();resolve();})["catch"](function(e){callback(e);reject(e);});});}; //def startTyping -Client.prototype.startTyping = function startTyping(channel){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){self.internal.startTyping(channel).then(function(){callback(null);resolve();})["catch"](function(e){callback(e);reject(e);});});}; //def stopTyping -Client.prototype.stopTyping = function stopTyping(channel){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){self.internal.stopTyping(channel).then(function(){callback(null);resolve();})["catch"](function(e){callback(e);reject(e);});});}; //def updateDetails -Client.prototype.updateDetails = function updateDetails(details){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){self.internal.updateDetails(details).then(function(){callback();resolve();})["catch"](function(err){callback(err);reject(err);});});}; //def setUsername -Client.prototype.setUsername = function setUsername(name){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){self.internal.setUsername(name).then(function(){callback();resolve();})["catch"](function(err){callback(err);reject(err);});});}; //def setAvatar -Client.prototype.setAvatar = function setAvatar(avatar){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){self.internal.setAvatar(avatar).then(function(){callback();resolve();})["catch"](function(err){callback(err);reject(err);});});}; //def joinVoiceChannel -Client.prototype.joinVoiceChannel = function joinVoiceChannel(channel){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;return new Promise(function(resolve,reject){self.internal.joinVoiceChannel(channel).then(function(chan){callback(null,chan);resolve(chan);})["catch"](function(err){callback(err);reject(err);});});}; // def leaveVoiceChannel -Client.prototype.leaveVoiceChannel = function leaveVoiceChannel(){var callback=arguments.length <= 0 || arguments[0] === undefined?function(err){}:arguments[0];var self=this;return new Promise(function(resolve,reject){self.internal.leaveVoiceChannel().then(function(){callback();resolve();})["catch"](function(err){callback(err);reject(err);});});};_createClass(Client,[{key:"users",get:function get(){return this.internal.users;}},{key:"channels",get:function get(){return this.internal.channels;}},{key:"servers",get:function get(){return this.internal.servers;}},{key:"privateChannels",get:function get(){return this.internal.private_channels;}},{key:"voiceConnection",get:function get(){return this.internal.voiceConnection;}},{key:"readyTime",get:function get(){return this.internal.readyTime;}},{key:"uptime",get:function get(){return this.internal.uptime;}},{key:"user",get:function get(){return this.internal.user;}}]);return Client;})(EventEmitter);module.exports = Client; +"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 InternalClient = require("./InternalClient.js"); +var EventEmitter = require("events"); + +var Client = (function (_EventEmitter) { + _inherits(Client, _EventEmitter); + + /* + this class is an interface for the internal + client. + */ + + function Client(options) { + _classCallCheck(this, Client); + + _EventEmitter.call(this); + this.options = options || {}; + this.internal = new InternalClient(this); + } + + // def login + + Client.prototype.login = function login(email, password) { + var cb = arguments.length <= 2 || arguments[2] === undefined ? function (err, token) {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.internal.login(email, password).then(function (token) { + cb(null, token); + resolve(token); + })["catch"](function (e) { + cb(e); + reject(e); + }); + }); + }; + + // def logout + + Client.prototype.logout = function logout() { + var cb = arguments.length <= 0 || arguments[0] === undefined ? function (err) {} : arguments[0]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.internal.logout().then(function () { + cb(); + resolve(); + })["catch"](function (e) { + cb(e); + reject(e); + }); + }); + }; + + // def sendMessage + + Client.prototype.sendMessage = function sendMessage(where, content) { + var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (e, m) {} : arguments[3]; + + var self = this; + return new Promise(function (resolve, reject) { + + if (typeof options === "function") { + // options is the callback + callback = options; + } + + self.internal.sendMessage(where, content, options).then(function (m) { + callback(null, m); + resolve(m); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + // def sendTTSMessage + + Client.prototype.sendTTSMessage = function sendTTSMessage(where, content) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (e, m) {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + self.sendMessage(where, content, { tts: true }).then(function (m) { + callback(null, m); + resolve(m); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + // def reply + + Client.prototype.reply = function reply(where, content) { + var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (e, m) {} : arguments[3]; + + var self = this; + return new Promise(function (resolve, reject) { + + if (typeof options === "function") { + // options is the callback + callback = options; + } + + var msg = self.internal.resolver.resolveMessage(where); + if (msg) { + content = msg.author + ", " + content; + self.internal.sendMessage(msg, content, options).then(function (m) { + callback(null, m); + resolve(m); + })["catch"](function (e) { + callback(e); + reject(e); + }); + } else { + var err = new Error("Destination not resolvable to a message!"); + callback(err); + reject(err); + } + }); + }; + + // def replyTTS + + Client.prototype.replyTTS = function replyTTS(where, content) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function () {} : arguments[2]; + + return new Promise(function (resolve, reject) { + self.reply(where, content, { tts: true }).then(function (m) { + callback(null, m); + resolve(m); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + // def deleteMessage + + Client.prototype.deleteMessage = function deleteMessage(msg) { + var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (e) {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + if (typeof options === "function") { + // options is the callback + callback = options; + } + + self.internal.deleteMessage(msg, options).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + //def updateMessage + + Client.prototype.updateMessage = function updateMessage(msg, content) { + var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; + + var self = this; + return new Promise(function (resolve, reject) { + if (typeof options === "function") { + // options is the callback + callback = options; + } + + self.internal.updateMessage(msg, content, options).then(function (msg) { + callback(null, msg); + resolve(msg); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + // def getChannelLogs + + Client.prototype.getChannelLogs = function getChannelLogs(where) { + var limit = arguments.length <= 1 || arguments[1] === undefined ? 500 : arguments[1]; + var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, logs) {} : arguments[3]; + + var self = this; + return new Promise(function (resolve, reject) { + if (typeof options === "function") { + // options is the callback + callback = options; + } + self.internal.getChannelLogs(where, limit, options).then(function (logs) { + callback(null, logs); + resolve(logs); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + // def getBans + + Client.prototype.getBans = function getBans(where) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, bans) {} : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + self.internal.getBans(where).then(function (bans) { + callback(null, bans); + resolve(bans); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + // def sendFile + + Client.prototype.sendFile = function sendFile(where, attachment) { + var name = arguments.length <= 2 || arguments[2] === undefined ? "image.png" : arguments[2]; + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, m) {} : arguments[3]; + + var self = this; + return new Promise(function (resolve, reject) { + self.internal.sendFile(where, attachment, name).then(function (m) { + callback(null, m); + resolve(m); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + // def joinServer + + Client.prototype.joinServer = function joinServer(invite) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, srv) {} : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + self.internal.joinServer(invite).then(function (srv) { + callback(null, srv); + resolve(srv); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + // def createServer + + Client.prototype.createServer = function createServer(name) { + var region = arguments.length <= 1 || arguments[1] === undefined ? "london" : arguments[1]; + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, srv) {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + self.internal.createServer(name, region).then(function (srv) { + callback(null, srv); + resolve(srv); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + // def leaveServer + + Client.prototype.leaveServer = function leaveServer(server) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.internal.leaveServer(server).then(function () { + callback();resolve(); + })["catch"](function (e) { + callback(e);reject(e); + }); + }); + }; + + // def createChannel + + Client.prototype.createChannel = function createChannel(server, name) { + var type = arguments.length <= 2 || arguments[2] === undefined ? "text" : arguments[2]; + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, channel) {} : arguments[3]; + + var self = this; + return new Promise(function (resolve, reject) { + if (typeof type === "function") { + // options is the callback + callback = type; + } + self.internal.createChannel(server, name, type).then(function (channel) { + callback(channel);resolve(channel); + })["catch"](function (e) { + callback(e);reject(e); + }); + }); + }; + + // def deleteChannel + + 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) { + + self.internal.deleteChannel(channel).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e);reject(e); + }); + }); + }; + + //def banMember + + Client.prototype.banMember = function banMember(user, server) { + var length = arguments.length <= 2 || arguments[2] === undefined ? 1 : arguments[2]; + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err) {} : arguments[3]; + + var self = this; + return new Promise(function (resolve, reject) { + if (typeof length === "function") { + // length is the callback + callback = length; + } + self.internal.banMember(user, server, length).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e);reject(e); + }); + }); + }; + + //def unbanMember + + Client.prototype.unbanMember = function unbanMember(user, server) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + self.internal.unbanMember(user, server).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e);reject(e); + }); + }); + }; + + //def kickMember + + Client.prototype.kickMember = function kickMember(user, server) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + self.internal.kickMember(user, server).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e);reject(e); + }); + }); + }; + + //def createRole + + Client.prototype.createRole = function createRole(server) { + var data = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, res) {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + if (typeof data === "function") { + // data is the callback + callback = data; + } + self.internal.createRole(server, data).then(function (role) { + callback(null, role); + resolve(role); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + //def updateRole + + Client.prototype.updateRole = function updateRole(role) { + var data = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, res) {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + if (typeof data === "function") { + // data is the callback + callback = data; + } + self.internal.updateRole(role, data).then(function (role) { + callback(null, role); + resolve(role); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + //def deleteRole + + Client.prototype.deleteRole = function deleteRole(role) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.internal.deleteRole(role).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + //def addMemberToRole + + Client.prototype.addMemberToRole = function addMemberToRole(member, role) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.internal.addMemberToRole(member, role).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + // def addUserToRole + + Client.prototype.addUserToRole = function addUserToRole(member, role) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2]; + + return this.addMemberToRole(member, role, callback); + }; + + // def removeMemberFromRole + + Client.prototype.removeMemberFromRole = function removeMemberFromRole(member, role) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.internal.removeMemberFromRole(member, role).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + // def removeUserFromRole + + Client.prototype.removeUserFromRole = function removeUserFromRole(member, role) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2]; + + return this.removeUserFromRole(member, role, callback); + }; + + // def createInvite + + Client.prototype.createInvite = function createInvite(chanServ, options) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, invite) {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + if (typeof options === "function") { + // length is the callback + callback = options; + } + + self.internal.createInvite(chanServ, options).then(function (invite) { + callback(null, invite); + resolve(invite); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + // def deleteInvite + + Client.prototype.deleteInvite = function deleteInvite(invite) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + self.internal.deleteInvite(invite).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + // def overwritePermissions + + Client.prototype.overwritePermissions = function overwritePermissions(channel, role) { + var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err) {} : arguments[3]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.internal.overwritePermissions(channel, role, options).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + //def setStatus + + Client.prototype.setStatus = function setStatus(idleStatus, gameID) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + if (typeof gameID === "function") { + // gameID is the callback + callback = gameID; + } else if (typeof idleStatus === "function") { + // idleStatus is the callback + callback = idleStatus; + } + + self.internal.setStatus(idleStatus, gameID).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + //def sendTyping + + Client.prototype.sendTyping = function sendTyping(channel) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.internal.sendTyping(channel).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + // def setTopic + + 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.internal.setTopic(channel, topic).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + //def setChannelName + + Client.prototype.setChannelName = function setChannelName(channel, name) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.internal.setChannelName(channel, name).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + //def setChannelNameAndTopic + + Client.prototype.setChannelNameAndTopic = function setChannelNameAndTopic(channel, name, topic) { + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err) {} : arguments[3]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.internal.setChannelNameAndTopic(channel, name, topic).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + //def updateChannel + + Client.prototype.updateChannel = function updateChannel(channel, data) { + var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.internal.updateChannel(channel, data).then(function () { + callback(); + resolve(); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + //def startTyping + + Client.prototype.startTyping = function startTyping(channel) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.internal.startTyping(channel).then(function () { + callback(null); + resolve(); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + //def stopTyping + + Client.prototype.stopTyping = function stopTyping(channel) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.internal.stopTyping(channel).then(function () { + callback(null); + resolve(); + })["catch"](function (e) { + callback(e); + reject(e); + }); + }); + }; + + //def updateDetails + + Client.prototype.updateDetails = function updateDetails(details) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + self.internal.updateDetails(details).then(function () { + callback(); + resolve(); + })["catch"](function (err) { + callback(err); + reject(err); + }); + }); + }; + + //def setUsername + + Client.prototype.setUsername = function setUsername(name) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + self.internal.setUsername(name).then(function () { + callback(); + resolve(); + })["catch"](function (err) { + callback(err); + reject(err); + }); + }); + }; + + //def setAvatar + + Client.prototype.setAvatar = function setAvatar(avatar) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + self.internal.setAvatar(avatar).then(function () { + callback(); + resolve(); + })["catch"](function (err) { + callback(err); + reject(err); + }); + }); + }; + + //def joinVoiceChannel + + Client.prototype.joinVoiceChannel = function joinVoiceChannel(channel) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.internal.joinVoiceChannel(channel).then(function (chan) { + callback(null, chan); + resolve(chan); + })["catch"](function (err) { + callback(err); + reject(err); + }); + }); + }; + + // def leaveVoiceChannel + + Client.prototype.leaveVoiceChannel = function leaveVoiceChannel() { + var callback = arguments.length <= 0 || arguments[0] === undefined ? function (err) {} : arguments[0]; + + var self = this; + return new Promise(function (resolve, reject) { + self.internal.leaveVoiceChannel().then(function () { + callback(); + resolve(); + })["catch"](function (err) { + callback(err); + reject(err); + }); + }); + }; + + Client.prototype.setStatusIdle = function setStatusIdle() { + this.setStatus("idle"); + }; + + Client.prototype.setStatusOnline = function setStatusOnline() { + var cb = arguments.length <= 0 || arguments[0] === undefined ? function (err) {} : arguments[0]; + + 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.setPlayingGame = function setPlayingGame(game) { + this.setStatus(null, game); + }; + + _createClass(Client, [{ + key: "users", + get: function get() { + return this.internal.users; + } + }, { + key: "channels", + get: function get() { + return this.internal.channels; + } + }, { + key: "servers", + get: function get() { + return this.internal.servers; + } + }, { + key: "privateChannels", + get: function get() { + return this.internal.private_channels; + } + }, { + key: "voiceConnection", + get: function get() { + return this.internal.voiceConnection; + } + }, { + key: "readyTime", + get: function get() { + return this.internal.readyTime; + } + }, { + key: "uptime", + get: function get() { + return this.internal.uptime; + } + }, { + key: "user", + get: function get() { + return this.internal.user; + } + }]); + + return Client; +})(EventEmitter); + +module.exports = Client; \ No newline at end of file diff --git a/lib/Client/ConnectionState.js b/lib/Client/ConnectionState.js index e2129c3cf..86fb95261 100644 --- a/lib/Client/ConnectionState.js +++ b/lib/Client/ConnectionState.js @@ -1 +1,7 @@ -"use strict";exports.IDLE = 0;exports.LOGGING_IN = 1;exports.LOGGED_IN = 2;exports.READY = 3;exports.DISCONNECTED = 4; +"use strict"; + +exports.IDLE = 0; +exports.LOGGING_IN = 1; +exports.LOGGED_IN = 2; +exports.READY = 3; +exports.DISCONNECTED = 4; \ No newline at end of file diff --git a/lib/Client/InternalClient.js b/lib/Client/InternalClient.js index 263f0077a..ee5568aa1 100644 --- a/lib/Client/InternalClient.js +++ b/lib/Client/InternalClient.js @@ -1,69 +1,1599 @@ -"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 EventEmitter=require("events");var request=require("superagent");var WebSocket=require("ws");var ConnectionState=require("./ConnectionState.js");var Constants=require("../Constants.js"),Endpoints=Constants.Endpoints,PacketType=Constants.PacketType;var Cache=require("../Util/Cache.js");var Resolver=require("./Resolver/Resolver.js");var User=require("../Structures/User.js"),Channel=require("../Structures/Channel.js"),TextChannel=require("../Structures/TextChannel.js"),VoiceChannel=require("../Structures/VoiceChannel.js"),PMChannel=require("../Structures/PMChannel.js"),Server=require("../Structures/Server.js"),Message=require("../Structures/Message.js"),Role=require("../Structures/Role.js"),Invite=require("../Structures/Invite.js"),VoiceConnection=require("../Voice/VoiceConnection.js");var zlib;var InternalClient=(function(){function InternalClient(discordClient){_classCallCheck(this,InternalClient);this.client = discordClient;this.state = ConnectionState.IDLE;this.websocket = null;if(this.client.options.compress){zlib = require("zlib");} // creates 4 caches with discriminators based on ID -this.users = new Cache();this.channels = new Cache();this.servers = new Cache();this.private_channels = new Cache();this.typingIntervals = [];this.voiceConnection = null;this.resolver = new Resolver(this);this.readyTime = null;} //def leaveVoiceChannel -InternalClient.prototype.leaveVoiceChannel = function leaveVoiceChannel(){var self=this;return new Promise(function(resolve,reject){if(self.voiceConnection){self.voiceConnection.destroy();self.voiceConnection = null;resolve();}else {resolve();}});}; //def joinVoiceChannel -InternalClient.prototype.joinVoiceChannel = function joinVoiceChannel(chann){var self=this;return new Promise(function(resolve,reject){var channel=self.resolver.resolveVoiceChannel(chann);if(channel){var next=function next(){var session,token,server=channel.server,endpoint;var check=function check(m){var data=JSON.parse(m);if(data.t === "VOICE_STATE_UPDATE"){session = data.d.session_id;}else if(data.t === "VOICE_SERVER_UPDATE"){token = data.d.token;endpoint = data.d.endpoint;var chan=self.voiceConnection = new VoiceConnection(channel,self.client,session,token,server,endpoint);chan.on("ready",function(){return resolve(chan);});chan.on("error",reject);self.client.emit("debug","removed temporary voice websocket listeners");self.websocket.removeListener("message",check);}};self.websocket.on("message",check);self.sendWS({op:4,d:{"guild_id":server.id,"channel_id":channel.id,"self_mute":false,"self_deaf":false}});};self.leaveVoiceChannel().then(next);}else {reject(new Error("voice channel does not exist"));}});}; // def createServer -InternalClient.prototype.createServer = function createServer(name){var region=arguments.length <= 1 || arguments[1] === undefined?"london":arguments[1];var self=this;return new Promise(function(resolve,reject){name = self.resolver.resolveString(name);request.post(Endpoints.SERVERS).set("authorization",self.token).send({name:name,region:region}).end(function(err,res){if(err){reject(new Error(err));}else { // valid server, wait until it is cached -var inter=setInterval(function(){if(self.servers.get("id",res.body.id)){clearInterval(inter);resolve(self.servers.get("id",res.body.id));}},20);}});});}; //def joinServer -InternalClient.prototype.joinServer = function joinServer(invite){var self=this;return new Promise(function(resolve,reject){invite = self.resolver.resolveInviteID(invite);if(invite){request.post(Endpoints.INVITE(invite)).set("authorization",self.token).end(function(err,res){if(err){reject(err);}else { // valid server, wait until it is received via ws and cached -var inter=setInterval(function(){if(self.servers.get("id",res.body.guild.id)){clearInterval(inter);resolve(self.servers.get("id",res.body.guild.id));}},20);}});}else {reject(new Error("Not a valid invite"));}});}; //def leaveServer -InternalClient.prototype.leaveServer = function leaveServer(srv){var self=this;return new Promise(function(resolve,reject){var server=self.resolver.resolveServer(srv);if(server){request.del(Endpoints.SERVER(server.id)).set("authorization",self.token).end(function(err,res){if(err){reject(new Error(err));}else { // remove channels of server then the server -for(var _iterator=server.channels,_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 chan=_ref;self.channels.remove(chan);} // remove server -self.servers.remove(server);resolve();}});}else {reject(new Error("server did not resolve"));}});}; // def login -InternalClient.prototype.login = function login(email,password){var self=this;var client=self.client;return new Promise(function(resolve,reject){if(self.state === ConnectionState.DISCONNECTED || self.state === ConnectionState.IDLE){self.state = ConnectionState.LOGGING_IN;request.post(Endpoints.LOGIN).send({email:email,password:password}).end(function(err,res){if(err){self.state = ConnectionState.DISCONNECTED;self.websocket = null;client.emit("disconnected");reject(new Error(err));}else {var token=res.body.token;self.state = ConnectionState.LOGGED_IN;self.token = token;self.email = email;self.password = password;self.getGateway().then(function(url){self.createWS(url);resolve(token);})["catch"](function(e){self.state = ConnectionState.DISCONNECTED;client.emit("disconnected");reject(new Error(err));});}});}else {reject(new Error("already logging in/logged in/ready!"));}});}; // def logout -InternalClient.prototype.logout = function logout(){var _this=this;var self=this;return new Promise(function(resolve,reject){if(self.state === ConnectionState.DISCONNECTED || self.state === ConnectionState.IDLE){reject(new Error("Client is not logged in!"));return;}request.post(Endpoints.LOGOUT).set("authorization",self.token).end(function(err,res){if(err){reject(new Error(err));}else {if(_this.websocket){_this.websocket.close();_this.websocket = null;}self.token = null;self.email = null;self.password = null;self.state = ConnectionState.DISCONNECTED;resolve();}});});}; // def startPM -InternalClient.prototype.startPM = function startPM(resUser){var self=this;return new Promise(function(resolve,reject){var user=self.resolver.resolveUser(resUser);if(user){ // start the PM -request.post("" + Endpoints.USER_CHANNELS(user.id)).set("authorization",self.token).send({recipient_id:user.id}).end(function(err,res){if(err){reject(new Error(err));}else {resolve(self.private_channels.add(new PMChannel(res.body,self.client)));}});}else {reject(new Error("Unable to resolve resUser to a User"));}});}; // def getGateway -InternalClient.prototype.getGateway = function getGateway(){var self=this;return new Promise(function(resolve,reject){request.get(Endpoints.GATEWAY).set("authorization",self.token).end(function(err,res){if(err)reject(err);else resolve(res.body.url);});});}; // def sendMessage -InternalClient.prototype.sendMessage = function sendMessage(where,_content){var options=arguments.length <= 2 || arguments[2] === undefined?{}:arguments[2];var self=this;return new Promise(function(resolve,reject){self.resolver.resolveChannel(where).then(next)["catch"](function(e){return reject(new Error("Error resolving destination - " + e));});function next(destination){ //var destination; -var content=self.resolver.resolveString(_content);var mentions=self.resolver.resolveMentions(content);request.post(Endpoints.CHANNEL_MESSAGES(destination.id)).set("authorization",self.token).send({content:content,mentions:mentions,tts:options.tts}).end(function(err,res){if(err){reject(new Error(err));}else {resolve(destination.messages.add(new Message(res.body,destination,self.client)));}});}});}; // def deleteMessage -InternalClient.prototype.deleteMessage = function deleteMessage(_message){var options=arguments.length <= 1 || arguments[1] === undefined?{}:arguments[1];var self=this;return new Promise(function(resolve,reject){var message=self.resolver.resolveMessage(_message);if(message){var deleteMsg=function deleteMsg(){request.del(Endpoints.CHANNEL_MESSAGE(message.channel.id,message.id)).set("authorization",self.token).end(function(err,res){if(err){reject(new Error(err));}else {message.channel.messages.remove(message);resolve();}});};if(options.wait){setTimeout(deleteMsg,options.wait);}else {deleteMsg();}}else {reject(new Error("Supplied message did not resolve to a message!"));}});}; // def updateMessage -InternalClient.prototype.updateMessage = function updateMessage(msg,_content){var options=arguments.length <= 2 || arguments[2] === undefined?{}:arguments[2];var self=this;return new Promise(function(resolve,reject){var message=self.resolver.resolveMessage(msg);if(message){var content=self.resolver.resolveString(_content);var mentions=self.resolver.resolveMentions(content);request.patch(Endpoints.CHANNEL_MESSAGE(message.channel.id,message.id)).set("authorization",self.token).send({content:content,tts:options.tts,mentions:mentions}).end(function(err,res){if(err){reject(new Error(err));}else {resolve(message.channel.messages.update(message,new Message(res.body,message.channel,self.client)));}});}else {reject(new Error("Supplied message did not resolve to a message!"));}});}; // def sendFile -InternalClient.prototype.sendFile = function sendFile(where,_file){var name=arguments.length <= 2 || arguments[2] === undefined?"image.png":arguments[2];var self=this;return new Promise(function(resolve,reject){self.resolver.resolveChannel(where).then(next)["catch"](function(e){return reject(new Error("couldn't resolve to channel - " + e));});function next(channel){var file=self.resolver.resolveFile(_file);request.post(Endpoints.CHANNEL_MESSAGES(channel.id)).set("authorization",self.token).attach("file",file,name).end(function(err,res){if(err){reject(new Error(err));}else {resolve(channel.messages.add(new Message(res.body,channel,self.client)));}});}});}; // def getChannelLogs -InternalClient.prototype.getChannelLogs = function getChannelLogs(_channel){var limit=arguments.length <= 1 || arguments[1] === undefined?500:arguments[1];var options=arguments.length <= 2 || arguments[2] === undefined?{}:arguments[2];var self=this;return new Promise(function(resolve,reject){self.resolver.resolveChannel(_channel).then(next)["catch"](function(e){return reject(new Error("couldn't resolve to channel - " + e));});function next(channel){if(options.before)options.before = self.resolver.resolveMessage(options.before);if(options.after)options.after = self.resolver.resolveMessage(options.after);var params=[];if(options.before)params.push("before=" + options.before.id);if(options.after)params.push("after=" + options.after.id);var joinedParams=params.join();if(joinedParams !== "")joinedParams = "&" + params.join();request.get(Endpoints.CHANNEL_MESSAGES(channel.id) + "?limit=" + limit + joinedParams).set("authorization",self.token).end(function(err,res){if(err){reject(new Error(err));}else {var logs=[];res.body.forEach(function(msg){logs.push(channel.messages.add(new Message(msg,channel,self.client)));});resolve(logs);}});}});}; // def getBans -InternalClient.prototype.getBans = function getBans(server){var self=this;return new Promise(function(resolve,reject){server = self.resolver.resolveServer(server);request.get("" + Endpoints.SERVER_BANS(server.id)).set("authorization",self.token).end(function(err,res){if(err){reject(new Error(err));}else {var bans=[];res.body.forEach(function(ban){bans.push(self.users.add(new User(ban.user,self.client)));});resolve(bans);}});});}; // def createChannel -InternalClient.prototype.createChannel = function createChannel(server,name){var type=arguments.length <= 2 || arguments[2] === undefined?"text":arguments[2];var self=this;return new Promise(function(resolve,reject){server = self.resolver.resolveServer(server);request.post(Endpoints.SERVER_CHANNELS(server.id)).set("authorization",self.token).send({name:name,type:type}).end(function(err,res){if(err){reject(err);}else {var channel;if(res.body.type === "text"){channel = new TextChannel(res.body,self.client,server);}else {channel = new VoiceChannel(res.body,self.client,server);}resolve(server.channels.add(self.channels.add(channel)));}});});}; // def deleteChannel -InternalClient.prototype.deleteChannel = function deleteChannel(_channel){var self=this;return new Promise(function(resolve,reject){self.resolver.resolveChannel(_channel).then(next)["catch"](reject);function next(channel){request.del(Endpoints.CHANNEL(channel.id)).set("authorization",self.token).end(function(err,res){if(err){reject(err);}else {channel.server.channels.remove(channel);self.channels.remove(channel);resolve();}});}});}; // def banMember -InternalClient.prototype.banMember = function banMember(user,server){var length=arguments.length <= 2 || arguments[2] === undefined?1:arguments[2];var self=this;return new Promise(function(resolve,reject){user = self.resolver.resolveUser(user);server = self.resolver.resolveServer(server);request.put(Endpoints.SERVER_BANS(server.id) + "/" + user.id + "/?delete-message-days=" + length).set("authorization",self.token).end(function(err,res){if(err){reject(err);}else {resolve();}});});}; // def unbanMember -InternalClient.prototype.unbanMember = function unbanMember(user,server){var self=this;return new Promise(function(resolve,reject){server = self.resolver.resolveServer(server);user = self.resolver.resolveUser(user);request.del(Endpoints.SERVER_BANS(server.id) + "/" + user.id).set("authorization",self.token).end(function(err,res){if(err){reject(err);}else {resolve();}});});}; // def kickMember -InternalClient.prototype.kickMember = function kickMember(user,server){var self=this;return new Promise(function(resolve,reject){user = self.resolver.resolveUser(user);server = self.resolver.resolveServer(server);request.del(Endpoints.SERVER_MEMBERS(server.id) + "/" + user.id).set("authorization",self.token).end(function(err,res){if(err){reject(err);}else {resolve();}});});}; // def createRole -InternalClient.prototype.createRole = function createRole(server,data){var self=this;return new Promise(function(resolve,reject){server = self.resolver.resolveServer(server);request.post(Endpoints.SERVER_ROLES(server.id)).set("authorization",self.token).end(function(err,res){if(err){reject(err);}else {var role=server.roles.add(new Role(res.body,server,self.client));if(data){self.updateRole(role,data).then(resolve)["catch"](reject);}else {resolve(role);}}});});}; // def updateRole -InternalClient.prototype.updateRole = function updateRole(role,data){var self=this;data = data || {};data.permissions = data.permissions || [];return new Promise(function(resolve,reject){var server=self.resolver.resolveServer(role.server);var permissions=0;for(var _iterator2=data.permissions,_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;if(perm instanceof String || typeof perm === "string"){permissions |= Constants.Permissions[perm] || 0;}else {permissions |= perm;}}data.color = data.color || 0;request.patch(Endpoints.SERVER_ROLES(server.id) + "/" + role.id).set("authorization",self.token).send({color:data.color || role.color,hoist:data.hoist || role.hoist,name:data.name || role.name,permissions:permissions}).end(function(err,res){if(err){reject(err);}else {var nrole=new Role(res.body,server,self.client);resolve(server.roles.update(role,nrole));}});});}; // def deleteRole -InternalClient.prototype.deleteRole = function deleteRole(role){var self=this;return new Promise(function(resolve,reject){request.del(Endpoints.SERVER_ROLES(role.server.id) + "/" + role.id).set("authorization",self.token).end(function(err,res){if(err){reject(err);}else {resolve(); // the ws cache will handle it -// role.server.roles.remove(role); -}});});}; //def addMemberToRole -InternalClient.prototype.addMemberToRole = function addMemberToRole(member,role){var self=this;return new Promise(function(resolve,reject){member = self.resolver.resolveUser(member);if(!member || !role){reject(new Error("member/role not in server"));return;}if(role.server.memberMap[member.id]){var roleIDS=role.server.memberMap[member.id].roles.map(function(r){return r.id;}).concat(role.id);request.patch(Endpoints.SERVER_MEMBERS(role.server.id) + "/" + member.id).set("authorization",self.token).send({roles:roleIDS}).end(function(err){if(err){reject(err);}else {resolve();}});}else {reject(new Error("member not in server"));}});}; //def removeMemberFromRole -InternalClient.prototype.removeMemberFromRole = function removeMemberFromRole(member,role){var self=this;return new Promise(function(resolve,reject){member = self.resolver.resolveUser(member);if(!member || !role){reject(new Error("member/role not in server"));return;}if(role.server.memberMap[member.id]){var roleIDS=role.server.memberMap[member.id].roles.map(function(r){return r.id;});for(var item in roleIDS) {if(roleIDS[item] === role.id){roleIDS.splice(item,1);}}request.patch(Endpoints.SERVER_MEMBERS(role.server.id) + "/" + member.id).set("authorization",self.token).send({roles:roleIDS}).end(function(err){if(err){reject(err);}else {resolve();}});}else {reject(new Error("member not in server"));}});}; // def createInvite -InternalClient.prototype.createInvite = function createInvite(chanServ,options){var self=this;return new Promise(function(resolve,reject){if(chanServ instanceof Channel){ // do something -}else if(chanServ instanceof Server){ // do something -}else {chanServ = self.resolver.resolveServer(chanServ) || self.resolver.resolveChannel(chanServ);}if(!chanServ){reject(new Error("couldn't resolve where"));return;}if(!options){options = {validate:null};}else {options.max_age = options.maxAge || 0;options.max_uses = options.maxUses || 0;options.temporary = options.temporary || false;options.xkcdpass = options.xkcd || false;}var epoint;if(chanServ instanceof Channel){epoint = Endpoints.CHANNEL_INVITES(chanServ.id);}else {epoint = Endpoints.SERVER_INVITES(chanServ.id);}request.post(epoint).set("authorization",self.token).send(options).end(function(err,res){if(err){reject(err);}else {resolve(new Invite(res.body,self.channels.get("id",res.body.channel.id),self.client));}});});}; //def deleteInvite -InternalClient.prototype.deleteInvite = function deleteInvite(invite){var self=this;return new Promise(function(resolve,reject){invite = self.resolver.resolveInviteID(invite);if(invite){request.del(Endpoints.INVITE(invite)).set("authorization",self.token).end(function(err,res){if(err){reject(err);}else {resolve();}});}else {reject(new Error("Not a valid invite"));}});}; //def overwritePermissions -InternalClient.prototype.overwritePermissions = function overwritePermissions(channel,role,updated){var self=this;return new Promise(function(resolve,reject){channel = self.resolver.resolveChannel(channel)["catch"](reject).then(next);function next(channel){var user;if(role instanceof User){user = role;}var data={};data.allow = 0;data.deny = 0;updated.allow = updated.allow || [];updated.deny = updated.deny || [];if(role instanceof Role){data.id = role.id;data.type = "role";}else if(user){data.id = user.id;data.type = "member";}else {reject(new Error("role incorrect"));return;}for(var perm in updated) {if(updated[perm]){if(perm instanceof String || typeof perm === "string"){data.allow |= Constants.Permissions[perm] || 0;}else {data.allow |= perm;}}else {if(perm instanceof String || typeof perm === "string"){data.deny |= Constants.Permissions[perm] || 0;}else {data.deny |= perm;}}}request.put(Endpoints.CHANNEL_PERMISSIONS(channel.id) + "/" + data.id).set("authorization",self.token).send(data).end(function(err){if(err){reject(err);}else {resolve();}});}});}; //def setStatus -InternalClient.prototype.setStatus = function setStatus(idleStatus,gameID){var self=this;return new Promise(function(resolve,reject){var packet={op:3,d:{idle_since:null,game_id:null}};if(idleStatus){packet.d.idle_since = Date.now();}if(typeof gameID === "number"){packet.d.game_id = gameID;}self.sendWS(packet);resolve();});}; //def sendTyping -InternalClient.prototype.sendTyping = function sendTyping(channel){var self=this;return new Promise(function(resolve,reject){self.resolver.resolveChannel(channel).then(next)["catch"](reject);function next(channel){request.post(Endpoints.CHANNEL(channel.id) + "/typing").set("authorization",self.token).end(function(err,res){if(err){reject(err);}else {resolve();}});}});}; //def startTyping -InternalClient.prototype.startTyping = function startTyping(channel){var self=this;return new Promise(function(resolve,reject){self.resolver.resolveChannel(channel).then(next)["catch"](reject);function next(channel){if(self.typingIntervals[channel.id]){ // typing interval already exists, leave it alone -reject(new Error("Already typing in that channel"));return;}self.sendTyping(channel);self.typingIntervals[channel.id] = setInterval(function(){return self.sendTyping(channel);},4000);}});}; //def stopTyping -InternalClient.prototype.stopTyping = function stopTyping(channel){var self=this;return new Promise(function(resolve,reject){self.resolver.resolveChannel(channel).then(next)["catch"](reject);function next(channel){if(!self.typingIntervals[channel.id]){ // typing interval doesn't exist -reject(new Error("Not typing in that channel"));return;}clearInterval(self.typingIntervals[channel.id]);self.typingIntervals[channel.id] = false;}});}; //def updateDetails -InternalClient.prototype.updateDetails = function updateDetails(data){var self=this;return new Promise(function(resolve,reject){request.patch(Endpoints.ME).set("authorization",self.token).send({avatar:self.resolver.resolveToBase64(data.avatar) || self.user.avatar,email:data.email || self.email,new_password:data.newPassword || null,password:data.password || self.password,username:data.username || self.user.username}).end(function(err){if(err){reject(err);}else {resolve();}});});}; //def setAvatar -InternalClient.prototype.setAvatar = function setAvatar(avatar){return this.updateDetails({avatar:avatar});}; //def setUsername -InternalClient.prototype.setUsername = function setUsername(username){return this.updateDetails({username:username});}; //def setTopic -InternalClient.prototype.setTopic = function setTopic(chann){var topic=arguments.length <= 1 || arguments[1] === undefined?"":arguments[1];var self=this;return new Promise(function(resolve,reject){self.resolver.resolveChannel(chann).then(next)["catch"](reject);function next(channel){request.patch(Endpoints.CHANNEL(channel.id)).set("authorization",self.token).send({name:channel.name,position:channel.position,topic:topic}).end(function(err,res){if(err){reject(err);}else {channel.topic = res.body.topic;resolve();}});}});}; //def setChannelName -InternalClient.prototype.setChannelName = function setChannelName(chann){var name=arguments.length <= 1 || arguments[1] === undefined?"discordjs_is_the_best":arguments[1];var self=this;return new Promise(function(resolve,reject){self.resolver.resolveChannel(chann).then(next)["catch"](reject);function next(channel){request.patch(Endpoints.CHANNEL(channel.id)).set("authorization",self.token).send({name:name,position:channel.position,topic:channel.topic}).end(function(err,res){if(err){reject(err);}else {channel.name = res.body.name;resolve();}});}});}; //def setChannelNameAndTopic -InternalClient.prototype.setChannelNameAndTopic = function setChannelNameAndTopic(chann){var name=arguments.length <= 1 || arguments[1] === undefined?"discordjs_is_the_best":arguments[1];var topic=arguments.length <= 2 || arguments[2] === undefined?"":arguments[2];var self=this;return new Promise(function(resolve,reject){self.resolver.resolveChannel(chann).then(next)["catch"](reject);function next(channel){request.patch(Endpoints.CHANNEL(channel.id)).set("authorization",self.token).send({name:name,position:channel.position,topic:topic}).end(function(err,res){if(err){reject(err);}else {channel.name = res.body.name;channel.topic = res.body.topic;resolve();}});}});}; //def updateChannel -InternalClient.prototype.updateChannel = function updateChannel(chann,data){return this.setChannelNameAndTopic(chann,data.name,data.topic);}; //def ack -InternalClient.prototype.ack = function ack(msg){var self=this;return new Promise(function(resolve,reject){msg = self.resolver.resolveMessage(msg);if(msg){request.post(Endpoints.CHANNEL_MESSAGE(msg.channel.id,msg.id) + "/ack").set("authorization",self.token).end(function(err){if(err){reject(err);}else {resolve();}});}else {reject(new Error("Message does not exist"));}});};InternalClient.prototype.sendWS = function sendWS(object){if(this.websocket)this.websocket.send(JSON.stringify(object));};InternalClient.prototype.createWS = function createWS(url){var self=this;var client=self.client;if(this.websocket)return false;this.websocket = new WebSocket(url);this.websocket.onopen = function(){self.sendWS({op:2,d:{token:self.token,v:3,compress:self.client.options.compress,properties:{"$os":"discord.js","$browser":"discord.js","$device":"discord.js","$referrer":"discord.js","$referring_domain":"discord.js"}}});};this.websocket.onclose = function(){self.websocket = null;self.state = ConnectionState.DISCONNECTED;client.emit("disconnected");};this.websocket.onerror = function(e){client.emit("error",e);};this.websocket.onmessage = function(e){if(e.type === "Binary"){if(!zlib)zlib = require("zlib");e.data = zlib.inflateSync(e.data).toString();}var packet,data;try{packet = JSON.parse(e.data);data = packet.d;}catch(e) {client.emit("error",e);return;}client.emit("raw",packet);switch(packet.t){case PacketType.READY:var startTime=Date.now();self.user = self.users.add(new User(data.user,client));data.guilds.forEach(function(server){self.servers.add(new Server(server,client));});data.private_channels.forEach(function(pm){self.private_channels.add(new PMChannel(pm,client));});self.state = ConnectionState.READY;setInterval(function(){return self.sendWS({op:1,d:Date.now()});},data.heartbeat_interval);client.emit("ready");client.emit("debug","ready packet took " + (Date.now() - startTime) + "ms to process");client.emit("debug","ready with " + self.servers.length + " servers, " + self.channels.length + " channels and " + self.users.length + " users cached.");self.readyTime = Date.now();break;case PacketType.MESSAGE_CREATE: // format: https://discordapi.readthedocs.org/en/latest/reference/channels/messages.html#message-format -var channel=self.channels.get("id",data.channel_id) || self.private_channels.get("id",data.channel_id);if(channel){var msg=channel.messages.add(new Message(data,channel,client));client.emit("message",msg);self.ack(msg);}else {client.emit("warn","message created but channel is not cached");}break;case PacketType.MESSAGE_DELETE: // format https://discordapi.readthedocs.org/en/latest/reference/channels/messages.html#message-delete -var channel=self.channels.get("id",data.channel_id) || self.private_channels.get("id",data.channel_id);if(channel){ // potentially blank -var msg=channel.messages.get("id",data.id);client.emit("messageDeleted",msg);if(msg){channel.messages.remove(msg);}}else {client.emit("warn","message was deleted but channel is not cached");}break;case PacketType.MESSAGE_UPDATE: // format https://discordapi.readthedocs.org/en/latest/reference/channels/messages.html#message-format -var channel=self.channels.get("id",data.channel_id) || self.private_channels.get("id",data.channel_id);if(channel){ // potentially blank -var msg=channel.messages.get("id",data.id);if(msg){ // old message exists -data.nonce = data.nonce || msg.nonce;data.attachments = data.attachments || msg.attachments;data.tts = data.tts || msg.tts;data.embeds = data.embeds || msg.embeds;data.timestamp = data.timestamp || msg.timestamp;data.mention_everyone = data.mention_everyone || msg.everyoneMentioned;data.content = data.content || msg.content;data.mentions = data.mentions || msg.mentions;data.author = data.author || msg.author;var nmsg=channel.messages.update(msg,new Message(data,channel,client));client.emit("messageUpdated",nmsg,msg);}}else {client.emit("warn","message was updated but channel is not cached");}break;case PacketType.SERVER_CREATE:var server=self.servers.get("id",data.id);if(!server){self.servers.add(new Server(data,client));client.emit("serverCreated",server);}break;case PacketType.SERVER_DELETE:var server=self.servers.get("id",data.id);if(server){for(var _iterator3=server.channels,_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 channel=_ref3;self.channels.remove(channel);}self.servers.remove(server);client.emit("serverDeleted",server);}else {client.emit("warn","server was deleted but it was not in the cache");}break;case PacketType.SERVER_UPDATE:var server=self.servers.get("id",data.id);if(server){ // server exists -data.members = data.members || [];data.channels = data.channels || [];var newserver=new Server(data,self);newserver.members = server.members;newserver.memberMap = server.memberMap;newserver.channels = server.channels;if(newserver.equalsStrict(server)){ // already the same don't do anything -client.emit("debug","received server update but server already updated");}else {self.servers.update(server,newserver);client.emit("serverUpdated",server,newserver);}}else if(!server){client.emit("warn","server was updated but it was not in the cache");self.servers.add(new Server(data,self));client.emit("serverCreated",server);}break;case PacketType.CHANNEL_CREATE:var channel=self.channels.get("id",data.id);if(!channel){var server=self.servers.get("id",data.guild_id);if(server){if(data.is_private){client.emit("channelCreated",self.private_channels.add(new PMChannel(data,client)));}else {var chan=null;if(data.type === "text"){chan = self.channels.add(new TextChannel(data,client,server));}else {chan = self.channels.add(new VoiceChannel(data,client,server));}client.emit("channelCreated",server.channels.add(chan));}}else {client.emit("warn","channel created but server does not exist");}}else {client.emit("warn","channel created but already in cache");}break;case PacketType.CHANNEL_DELETE:var channel=self.channels.get("id",data.id);if(channel){if(channel.server) // accounts for PMs -channel.server.channels.remove(channel);self.channels.remove(channel);client.emit("channelDeleted",channel);}else {client.emit("warn","channel deleted but already out of cache?");}break;case PacketType.CHANNEL_UPDATE:var channel=self.channels.get("id",data.id) || self.private_channels.get("id",data.id);if(channel){if(channel instanceof PMChannel){ //PM CHANNEL -client.emit("channelUpdated",channel,self.private_channels.update(channel,new PMChannel(data,client)));}else {if(channel.server){if(channel.type === "text"){ //TEXT CHANNEL -var chan=new TextChannel(data,client,channel.server);chan.messages = channel.messages;channel.server.channels.update(channel,chan);self.channels.update(channel,chan);client.emit("channelUpdated",channel,chan);}else { //VOICE CHANNEL -var chan=new VoiceChannel(data,client,channel.server);channel.server.channels.update(channel,chan);self.channels.update(channel,chan);client.emit("channelUpdated",channel,chan);}}else {client.emit("warn","channel updated but server non-existant");}}}else {client.emit("warn","channel updated but not in cache");}break;case PacketType.SERVER_ROLE_CREATE:var server=self.servers.get("id",data.guild_id);if(server){client.emit("serverRoleCreated",server.roles.add(new Role(data.role,server,client)),server);}else {client.emit("warn","server role made but server not in cache");}break;case PacketType.SERVER_ROLE_DELETE:var server=self.servers.get("id",data.guild_id);if(server){var role=server.roles.get("id",data.role_id);if(role){server.roles.remove(role);client.emit("serverRoleDeleted",role);}else {client.emit("warn","server role deleted but role not in cache");}}else {client.emit("warn","server role deleted but server not in cache");}break;case PacketType.SERVER_ROLE_UPDATE:var server=self.servers.get("id",data.guild_id);if(server){var role=server.roles.get("id",data.role.id);if(role){var newRole=new Role(data.role,server,client);server.roles.update(role,newRole);client.emit("serverRoleUpdated",role,newRole);}else {client.emit("warn","server role updated but role not in cache");}}else {client.emit("warn","server role updated but server not in cache");}break;case PacketType.SERVER_MEMBER_ADD:var server=self.servers.get("id",data.guild_id);if(server){server.memberMap[data.user.id] = {roles:data.roles.map(function(pid){return server.roles.get("id",pid);}),mute:false,deaf:false,joinedAt:Date.parse(data.joined_at)};client.emit("serverNewMember",server,server.members.add(self.users.add(new User(data.user,client))));}else {client.emit("warn","server member added but server doesn't exist in cache");}break;case PacketType.SERVER_MEMBER_REMOVE:var server=self.servers.get("id",data.guild_id);if(server){var user=self.users.get("id",data.user.id);if(user){server.memberMap[data.user.id] = null;server.members.remove(user);client.emit("serverMemberRemoved",server,user);}else {client.emit("warn","server member removed but user doesn't exist in cache");}}else {client.emit("warn","server member removed but server doesn't exist in cache");}break;case PacketType.SERVER_MEMBER_UPDATE:var server=self.servers.get("id",data.guild_id);if(server){var user=self.users.get("id",data.user.id);if(user){server.memberMap[data.user.id].roles = data.roles.map(function(pid){return server.roles.get("id",pid);});server.memberMap[data.user.id].mute = data.mute;server.memberMap[data.user.id].deaf = data.deaf;client.emit("serverMemberUpdated",server,user);}else {client.emit("warn","server member removed but user doesn't exist in cache");}}else {client.emit("warn","server member updated but server doesn't exist in cache");}break;case PacketType.PRESENCE_UPDATE:var user=self.users.get("id",data.user.id);if(user){data.user.username = data.user.username || user.username;data.user.id = data.user.id || user.id;data.user.avatar = data.user.avatar || user.avatar;data.user.discriminator = data.user.discriminator || user.discriminator;var presenceUser=new User(data.user,client);if(presenceUser.equalsStrict(user)){ // a real presence update -client.emit("presence",user,data.status,data.game_id);user.status = data.status;user.gameID = data.game_id;}else { // a name change or avatar change -client.emit("userUpdate",user,presenceUser);self.users.update(user,presenceUser);}}else {client.emit("warn","presence update but user not in cache");}break;case PacketType.TYPING:var user=self.users.get("id",data.user_id);var channel=self.channels.get("id",data.channel_id) || self.private_channels.get("id",data.channel_id);if(user && channel){if(user.typing.since){user.typing.since = Date.now();user.typing.channel = channel;}else {user.typing.since = Date.now();user.typing.channel = channel;client.emit("userTypingStart",user,channel);}setTimeout(function(){if(Date.now() - user.typing.since > 5500){ // they haven't typed since -user.typing.since = null;user.typing.channel = null;client.emit("userTypingStop",user,channel);}},6000);}else {client.emit("warn","user typing but user or channel not existant in cache");}break;case PacketType.SERVER_BAN_ADD:var user=self.users.get("id",data.user.id);var server=self.servers.get("id",data.guild_id);if(user && server){client.emit("userBanned",user,server);}else {client.emit("warn","user banned but user/server not in cache.");}break;case PacketType.SERVER_BAN_REMOVE:var user=self.users.get("id",data.user.id);var server=self.servers.get("id",data.guild_id);if(user && server){client.emit("userUnbanned",user,server);}else {client.emit("warn","user unbanned but user/server not in cache.");}break;}};};_createClass(InternalClient,[{key:"uptime",get:function get(){return this.readyTime?Date.now() - this.readyTime:null;}}]);return InternalClient;})();module.exports = InternalClient; +"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 EventEmitter = require("events"); +var request = require("superagent"); +var WebSocket = require("ws"); +var ConnectionState = require("./ConnectionState.js"); + +var Constants = require("../Constants.js"), + Endpoints = Constants.Endpoints, + PacketType = Constants.PacketType; + +var Cache = require("../Util/Cache.js"); +var Resolver = require("./Resolver/Resolver.js"); + +var User = require("../Structures/User.js"), + Channel = require("../Structures/Channel.js"), + TextChannel = require("../Structures/TextChannel.js"), + VoiceChannel = require("../Structures/VoiceChannel.js"), + PMChannel = require("../Structures/PMChannel.js"), + Server = require("../Structures/Server.js"), + Message = require("../Structures/Message.js"), + Role = require("../Structures/Role.js"), + Invite = require("../Structures/Invite.js"), + VoiceConnection = require("../Voice/VoiceConnection.js"); + +var zlib; + +var InternalClient = (function () { + function InternalClient(discordClient) { + _classCallCheck(this, InternalClient); + + this.client = discordClient; + this.state = ConnectionState.IDLE; + this.websocket = null; + + if (this.client.options.compress) { + zlib = require("zlib"); + } + + // creates 4 caches with discriminators based on ID + this.users = new Cache(); + this.channels = new Cache(); + this.servers = new Cache(); + this.private_channels = new Cache(); + this.typingIntervals = []; + this.voiceConnection = null; + this.resolver = new Resolver(this); + this.readyTime = null; + } + + //def leaveVoiceChannel + + InternalClient.prototype.leaveVoiceChannel = function leaveVoiceChannel() { + var self = this; + return new Promise(function (resolve, reject) { + if (self.voiceConnection) { + self.voiceConnection.destroy(); + self.voiceConnection = null; + resolve(); + } else { + resolve(); + } + }); + }; + + //def joinVoiceChannel + + InternalClient.prototype.joinVoiceChannel = function joinVoiceChannel(chann) { + var self = this; + return new Promise(function (resolve, reject) { + + var channel = self.resolver.resolveVoiceChannel(chann); + + if (channel) { + var next = function next() { + var session, + token, + server = channel.server, + endpoint; + + var check = function check(m) { + var data = JSON.parse(m); + if (data.t === "VOICE_STATE_UPDATE") { + session = data.d.session_id; + } else if (data.t === "VOICE_SERVER_UPDATE") { + token = data.d.token; + endpoint = data.d.endpoint; + var chan = self.voiceConnection = new VoiceConnection(channel, self.client, session, token, server, endpoint); + + chan.on("ready", function () { + return resolve(chan); + }); + chan.on("error", reject); + + self.client.emit("debug", "removed temporary voice websocket listeners"); + self.websocket.removeListener("message", check); + } + }; + + self.websocket.on("message", check); + self.sendWS({ + op: 4, + d: { + "guild_id": server.id, + "channel_id": channel.id, + "self_mute": false, + "self_deaf": false + } + }); + }; + + self.leaveVoiceChannel().then(next); + } else { + reject(new Error("voice channel does not exist")); + } + }); + }; + + // def createServer + + InternalClient.prototype.createServer = function createServer(name) { + var region = arguments.length <= 1 || arguments[1] === undefined ? "london" : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + name = self.resolver.resolveString(name); + + request.post(Endpoints.SERVERS).set("authorization", self.token).send({ name: name, region: region }).end(function (err, res) { + if (err) { + reject(new Error(err)); + } else { + // valid server, wait until it is cached + var inter = setInterval(function () { + if (self.servers.get("id", res.body.id)) { + clearInterval(inter); + resolve(self.servers.get("id", res.body.id)); + } + }, 20); + } + }); + }); + }; + + //def joinServer + + InternalClient.prototype.joinServer = function joinServer(invite) { + var self = this; + return new Promise(function (resolve, reject) { + + invite = self.resolver.resolveInviteID(invite); + if (invite) { + request.post(Endpoints.INVITE(invite)).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + // valid server, wait until it is received via ws and cached + var inter = setInterval(function () { + if (self.servers.get("id", res.body.guild.id)) { + clearInterval(inter); + resolve(self.servers.get("id", res.body.guild.id)); + } + }, 20); + } + }); + } else { + reject(new Error("Not a valid invite")); + } + }); + }; + + //def leaveServer + + InternalClient.prototype.leaveServer = function leaveServer(srv) { + var self = this; + return new Promise(function (resolve, reject) { + var server = self.resolver.resolveServer(srv); + if (server) { + + request.del(Endpoints.SERVER(server.id)).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(new Error(err)); + } else { + // remove channels of server then the server + for (var _iterator = server.channels, _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 chan = _ref; + + self.channels.remove(chan); + } + // remove server + self.servers.remove(server); + resolve(); + } + }); + } else { + reject(new Error("server did not resolve")); + } + }); + }; + + // def login + + InternalClient.prototype.login = function login(email, password) { + var self = this; + var client = self.client; + return new Promise(function (resolve, reject) { + if (self.state === ConnectionState.DISCONNECTED || self.state === ConnectionState.IDLE) { + + self.state = ConnectionState.LOGGING_IN; + + request.post(Endpoints.LOGIN).send({ email: email, password: password }).end(function (err, res) { + + if (err) { + self.state = ConnectionState.DISCONNECTED; + self.websocket = null; + client.emit("disconnected"); + reject(new Error(err)); + } else { + var token = res.body.token; + self.state = ConnectionState.LOGGED_IN; + self.token = token; + self.email = email; + self.password = password; + + self.getGateway().then(function (url) { + + self.createWS(url); + resolve(token); + })["catch"](function (e) { + self.state = ConnectionState.DISCONNECTED; + client.emit("disconnected"); + reject(new Error(err)); + }); + } + }); + } else { + reject(new Error("already logging in/logged in/ready!")); + } + }); + }; + + // def logout + + InternalClient.prototype.logout = function logout() { + var _this = this; + + var self = this; + return new Promise(function (resolve, reject) { + + if (self.state === ConnectionState.DISCONNECTED || self.state === ConnectionState.IDLE) { + reject(new Error("Client is not logged in!")); + return; + } + + request.post(Endpoints.LOGOUT).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(new Error(err)); + } else { + if (_this.websocket) { + _this.websocket.close(); + _this.websocket = null; + } + self.token = null; + self.email = null; + self.password = null; + self.state = ConnectionState.DISCONNECTED; + resolve(); + } + }); + }); + }; + + // def startPM + + InternalClient.prototype.startPM = function startPM(resUser) { + var self = this; + return new Promise(function (resolve, reject) { + var user = self.resolver.resolveUser(resUser); + + if (user) { + + // start the PM + request.post("" + Endpoints.USER_CHANNELS(user.id)).set("authorization", self.token).send({ + recipient_id: user.id + }).end(function (err, res) { + if (err) { + reject(new Error(err)); + } else { + resolve(self.private_channels.add(new PMChannel(res.body, self.client))); + } + }); + } else { + reject(new Error("Unable to resolve resUser to a User")); + } + }); + }; + + // def getGateway + + InternalClient.prototype.getGateway = function getGateway() { + var self = this; + return new Promise(function (resolve, reject) { + + request.get(Endpoints.GATEWAY).set("authorization", self.token).end(function (err, res) { + if (err) reject(err);else resolve(res.body.url); + }); + }); + }; + + // def sendMessage + + InternalClient.prototype.sendMessage = function sendMessage(where, _content) { + var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.resolver.resolveChannel(where).then(next)["catch"](function (e) { + return reject(new Error("Error resolving destination - " + e)); + }); + + function next(destination) { + //var destination; + var content = self.resolver.resolveString(_content); + var mentions = self.resolver.resolveMentions(content); + + request.post(Endpoints.CHANNEL_MESSAGES(destination.id)).set("authorization", self.token).send({ + content: content, + mentions: mentions, + tts: options.tts + }).end(function (err, res) { + if (err) { + reject(new Error(err)); + } else { + + resolve(destination.messages.add(new Message(res.body, destination, self.client))); + } + }); + } + }); + }; + + // def deleteMessage + + InternalClient.prototype.deleteMessage = function deleteMessage(_message) { + var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + + var message = self.resolver.resolveMessage(_message); + + if (message) { + var deleteMsg = function deleteMsg() { + request.del(Endpoints.CHANNEL_MESSAGE(message.channel.id, message.id)).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(new Error(err)); + } else { + message.channel.messages.remove(message); + resolve(); + } + }); + }; + + if (options.wait) { + setTimeout(deleteMsg, options.wait); + } else { + deleteMsg(); + } + } else { + reject(new Error("Supplied message did not resolve to a message!")); + } + }); + }; + + // def updateMessage + + InternalClient.prototype.updateMessage = function updateMessage(msg, _content) { + var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + + var message = self.resolver.resolveMessage(msg); + + if (message) { + + var content = self.resolver.resolveString(_content); + var mentions = self.resolver.resolveMentions(content); + + request.patch(Endpoints.CHANNEL_MESSAGE(message.channel.id, message.id)).set("authorization", self.token).send({ + content: content, + tts: options.tts, + mentions: mentions + }).end(function (err, res) { + if (err) { + reject(new Error(err)); + } else { + resolve(message.channel.messages.update(message, new Message(res.body, message.channel, self.client))); + } + }); + } else { + reject(new Error("Supplied message did not resolve to a message!")); + } + }); + }; + + // def sendFile + + InternalClient.prototype.sendFile = function sendFile(where, _file) { + var name = arguments.length <= 2 || arguments[2] === undefined ? "image.png" : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + self.resolver.resolveChannel(where).then(next)["catch"](function (e) { + return reject(new Error("couldn't resolve to channel - " + e)); + }); + + function next(channel) { + + var file = self.resolver.resolveFile(_file); + + request.post(Endpoints.CHANNEL_MESSAGES(channel.id)).set("authorization", self.token).attach("file", file, name).end(function (err, res) { + + if (err) { + reject(new Error(err)); + } else { + resolve(channel.messages.add(new Message(res.body, channel, self.client))); + } + }); + } + }); + }; + + // def getChannelLogs + + InternalClient.prototype.getChannelLogs = function getChannelLogs(_channel) { + var limit = arguments.length <= 1 || arguments[1] === undefined ? 500 : arguments[1]; + var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.resolver.resolveChannel(_channel).then(next)["catch"](function (e) { + return reject(new Error("couldn't resolve to channel - " + e)); + }); + + function next(channel) { + + if (options.before) options.before = self.resolver.resolveMessage(options.before); + if (options.after) options.after = self.resolver.resolveMessage(options.after); + + var params = []; + if (options.before) params.push("before=" + options.before.id); + if (options.after) params.push("after=" + options.after.id); + + var joinedParams = params.join(); + if (joinedParams !== "") joinedParams = "&" + params.join(); + + request.get(Endpoints.CHANNEL_MESSAGES(channel.id) + "?limit=" + limit + joinedParams).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(new Error(err)); + } else { + var logs = []; + res.body.forEach(function (msg) { + logs.push(channel.messages.add(new Message(msg, channel, self.client))); + }); + resolve(logs); + } + }); + } + }); + }; + + // def getBans + + InternalClient.prototype.getBans = function getBans(server) { + var self = this; + return new Promise(function (resolve, reject) { + + server = self.resolver.resolveServer(server); + + request.get("" + Endpoints.SERVER_BANS(server.id)).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(new Error(err)); + } else { + var bans = []; + res.body.forEach(function (ban) { + bans.push(self.users.add(new User(ban.user, self.client))); + }); + resolve(bans); + } + }); + }); + }; + + // def createChannel + + InternalClient.prototype.createChannel = function createChannel(server, name) { + var type = arguments.length <= 2 || arguments[2] === undefined ? "text" : arguments[2]; + + var self = this; + + return new Promise(function (resolve, reject) { + + server = self.resolver.resolveServer(server); + + request.post(Endpoints.SERVER_CHANNELS(server.id)).set("authorization", self.token).send({ + name: name, type: type + }).end(function (err, res) { + if (err) { + reject(err); + } else { + var channel; + if (res.body.type === "text") { + channel = new TextChannel(res.body, self.client, server); + } else { + channel = new VoiceChannel(res.body, self.client, server); + } + resolve(server.channels.add(self.channels.add(channel))); + } + }); + }); + }; + + // def deleteChannel + + InternalClient.prototype.deleteChannel = function deleteChannel(_channel) { + var self = this; + return new Promise(function (resolve, reject) { + + self.resolver.resolveChannel(_channel).then(next)["catch"](reject); + + function next(channel) { + request.del(Endpoints.CHANNEL(channel.id)).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + channel.server.channels.remove(channel); + self.channels.remove(channel); + resolve(); + } + }); + } + }); + }; + + // def banMember + + InternalClient.prototype.banMember = function banMember(user, server) { + var length = arguments.length <= 2 || arguments[2] === undefined ? 1 : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + + user = self.resolver.resolveUser(user); + server = self.resolver.resolveServer(server); + + request.put(Endpoints.SERVER_BANS(server.id) + "/" + user.id + "/?delete-message-days=" + length).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + }); + }; + + // def unbanMember + + InternalClient.prototype.unbanMember = function unbanMember(user, server) { + var self = this; + return new Promise(function (resolve, reject) { + + server = self.resolver.resolveServer(server); + user = self.resolver.resolveUser(user); + + request.del(Endpoints.SERVER_BANS(server.id) + "/" + user.id).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + }); + }; + + // def kickMember + + InternalClient.prototype.kickMember = function kickMember(user, server) { + var self = this; + return new Promise(function (resolve, reject) { + + user = self.resolver.resolveUser(user); + server = self.resolver.resolveServer(server); + + request.del(Endpoints.SERVER_MEMBERS(server.id) + "/" + user.id).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + }); + }; + + // def createRole + + InternalClient.prototype.createRole = function createRole(server, data) { + var self = this; + return new Promise(function (resolve, reject) { + + server = self.resolver.resolveServer(server); + + request.post(Endpoints.SERVER_ROLES(server.id)).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + + var role = server.roles.add(new Role(res.body, server, self.client)); + + if (data) { + + self.updateRole(role, data).then(resolve)["catch"](reject); + } else { + resolve(role); + } + } + }); + }); + }; + + // def updateRole + + InternalClient.prototype.updateRole = function updateRole(role, data) { + var self = this; + data = data || {}; + data.permissions = data.permissions || []; + return new Promise(function (resolve, reject) { + + var server = self.resolver.resolveServer(role.server); + + var permissions = 0; + for (var _iterator2 = data.permissions, _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; + + if (perm instanceof String || typeof perm === "string") { + permissions |= Constants.Permissions[perm] || 0; + } else { + permissions |= perm; + } + } + + data.color = data.color || 0; + + request.patch(Endpoints.SERVER_ROLES(server.id) + "/" + role.id).set("authorization", self.token).send({ + color: data.color || role.color, + hoist: data.hoist || role.hoist, + name: data.name || role.name, + permissions: permissions + }).end(function (err, res) { + if (err) { + reject(err); + } else { + var nrole = new Role(res.body, server, self.client); + resolve(server.roles.update(role, nrole)); + } + }); + }); + }; + + // def deleteRole + + InternalClient.prototype.deleteRole = function deleteRole(role) { + var self = this; + return new Promise(function (resolve, reject) { + + request.del(Endpoints.SERVER_ROLES(role.server.id) + "/" + role.id).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(); + // the ws cache will handle it + // role.server.roles.remove(role); + } + }); + }); + }; + + //def addMemberToRole + + InternalClient.prototype.addMemberToRole = function addMemberToRole(member, role) { + var self = this; + return new Promise(function (resolve, reject) { + + member = self.resolver.resolveUser(member); + + if (!member || !role) { + reject(new Error("member/role not in server")); + return; + } + + if (role.server.memberMap[member.id]) { + + var roleIDS = role.server.memberMap[member.id].roles.map(function (r) { + return r.id; + }).concat(role.id); + + request.patch(Endpoints.SERVER_MEMBERS(role.server.id) + "/" + member.id).set("authorization", self.token).send({ + roles: roleIDS + }).end(function (err) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + } else { + reject(new Error("member not in server")); + } + }); + }; + + //def removeMemberFromRole + + InternalClient.prototype.removeMemberFromRole = function removeMemberFromRole(member, role) { + var self = this; + return new Promise(function (resolve, reject) { + + member = self.resolver.resolveUser(member); + + if (!member || !role) { + reject(new Error("member/role not in server")); + return; + } + + if (role.server.memberMap[member.id]) { + + var roleIDS = role.server.memberMap[member.id].roles.map(function (r) { + return r.id; + }); + + for (var item in roleIDS) { + if (roleIDS[item] === role.id) { + roleIDS.splice(item, 1); + } + } + + request.patch(Endpoints.SERVER_MEMBERS(role.server.id) + "/" + member.id).set("authorization", self.token).send({ + roles: roleIDS + }).end(function (err) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + } else { + reject(new Error("member not in server")); + } + }); + }; + + // def createInvite + + InternalClient.prototype.createInvite = function createInvite(chanServ, options) { + var self = this; + return new Promise(function (resolve, reject) { + + if (chanServ instanceof Channel) { + // do something + } else if (chanServ instanceof Server) { + // do something + } else { + chanServ = self.resolver.resolveServer(chanServ) || self.resolver.resolveChannel(chanServ); + } + + if (!chanServ) { + reject(new Error("couldn't resolve where")); + return; + } + + if (!options) { + options = { validate: null }; + } else { + options.max_age = options.maxAge || 0; + options.max_uses = options.maxUses || 0; + options.temporary = options.temporary || false; + options.xkcdpass = options.xkcd || false; + } + + var epoint; + if (chanServ instanceof Channel) { + epoint = Endpoints.CHANNEL_INVITES(chanServ.id); + } else { + epoint = Endpoints.SERVER_INVITES(chanServ.id); + } + + request.post(epoint).set("authorization", self.token).send(options).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(new Invite(res.body, self.channels.get("id", res.body.channel.id), self.client)); + } + }); + }); + }; + + //def deleteInvite + + InternalClient.prototype.deleteInvite = function deleteInvite(invite) { + var self = this; + return new Promise(function (resolve, reject) { + + invite = self.resolver.resolveInviteID(invite); + if (invite) { + request.del(Endpoints.INVITE(invite)).set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + } else { + reject(new Error("Not a valid invite")); + } + }); + }; + + //def overwritePermissions + + InternalClient.prototype.overwritePermissions = function overwritePermissions(channel, role, updated) { + var self = this; + return new Promise(function (resolve, reject) { + channel = self.resolver.resolveChannel(channel)["catch"](reject).then(next); + function next(channel) { + + var user; + if (role instanceof User) { + user = role; + } + + var data = {}; + data.allow = 0; + data.deny = 0; + + updated.allow = updated.allow || []; + updated.deny = updated.deny || []; + + if (role instanceof Role) { + data.id = role.id; + data.type = "role"; + } else if (user) { + data.id = user.id; + data.type = "member"; + } else { + reject(new Error("role incorrect")); + return; + } + + for (var perm in updated) { + if (updated[perm]) { + if (perm instanceof String || typeof perm === "string") { + data.allow |= Constants.Permissions[perm] || 0; + } else { + data.allow |= perm; + } + } else { + if (perm instanceof String || typeof perm === "string") { + data.deny |= Constants.Permissions[perm] || 0; + } else { + data.deny |= perm; + } + } + } + + request.put(Endpoints.CHANNEL_PERMISSIONS(channel.id) + "/" + data.id).set("authorization", self.token).send(data).end(function (err) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + } + }); + }; + + //def setStatus + + InternalClient.prototype.setStatus = function setStatus(idleStatus, gameID) { + var self = this; + + self.idleStatus = idleStatus || self.idleStatus || null; + if (idleStatus) { + if (idleStatus == "online" || idleStatus == "here" || idleStatus == "available") { + self.idleStatus = null; + } + } + self.gameID = self.resolver.resolveGameID(gameID) || self.gameID || null; + + return new Promise(function (resolve, reject) { + + var packet = { + op: 3, + d: { + idle_since: self.idleStatus, + game_id: self.gameID + } + }; + + if (self.idleStatus == "idle" || self.idleStatus == "away") { + packet.d.idle_since = Date.now(); + } + + self.sendWS(packet); + + resolve(); + }); + }; + + //def sendTyping + + InternalClient.prototype.sendTyping = function sendTyping(channel) { + var self = this; + return new Promise(function (resolve, reject) { + + self.resolver.resolveChannel(channel).then(next)["catch"](reject); + + function next(channel) { + + request.post(Endpoints.CHANNEL(channel.id) + "/typing").set("authorization", self.token).end(function (err, res) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + } + }); + }; + + //def startTyping + + InternalClient.prototype.startTyping = function startTyping(channel) { + var self = this; + return new Promise(function (resolve, reject) { + + self.resolver.resolveChannel(channel).then(next)["catch"](reject); + + function next(channel) { + + if (self.typingIntervals[channel.id]) { + // typing interval already exists, leave it alone + reject(new Error("Already typing in that channel")); + return; + } + + self.sendTyping(channel); + + self.typingIntervals[channel.id] = setInterval(function () { + return self.sendTyping(channel); + }, 4000); + } + }); + }; + + //def stopTyping + + InternalClient.prototype.stopTyping = function stopTyping(channel) { + var self = this; + return new Promise(function (resolve, reject) { + + self.resolver.resolveChannel(channel).then(next)["catch"](reject); + + function next(channel) { + + if (!self.typingIntervals[channel.id]) { + // typing interval doesn't exist + reject(new Error("Not typing in that channel")); + return; + } + + clearInterval(self.typingIntervals[channel.id]); + self.typingIntervals[channel.id] = false; + } + }); + }; + + //def updateDetails + + InternalClient.prototype.updateDetails = function updateDetails(data) { + var self = this; + return new Promise(function (resolve, reject) { + request.patch(Endpoints.ME).set("authorization", self.token).send({ + avatar: self.resolver.resolveToBase64(data.avatar) || self.user.avatar, + email: data.email || self.email, + new_password: data.newPassword || null, + password: data.password || self.password, + username: data.username || self.user.username + }).end(function (err) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + }); + }; + + //def setAvatar + + InternalClient.prototype.setAvatar = function setAvatar(avatar) { + return this.updateDetails({ avatar: avatar }); + }; + + //def setUsername + + InternalClient.prototype.setUsername = function setUsername(username) { + return this.updateDetails({ username: username }); + }; + + //def setTopic + + InternalClient.prototype.setTopic = function setTopic(chann) { + var topic = arguments.length <= 1 || arguments[1] === undefined ? "" : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.resolver.resolveChannel(chann).then(next)["catch"](reject); + + function next(channel) { + + request.patch(Endpoints.CHANNEL(channel.id)).set("authorization", self.token).send({ + name: channel.name, + position: channel.position, + topic: topic + }).end(function (err, res) { + if (err) { + reject(err); + } else { + channel.topic = res.body.topic; + resolve(); + } + }); + } + }); + }; + + //def setChannelName + + InternalClient.prototype.setChannelName = function setChannelName(chann) { + var name = arguments.length <= 1 || arguments[1] === undefined ? "discordjs_is_the_best" : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.resolver.resolveChannel(chann).then(next)["catch"](reject); + + function next(channel) { + + request.patch(Endpoints.CHANNEL(channel.id)).set("authorization", self.token).send({ + name: name, + position: channel.position, + topic: channel.topic + }).end(function (err, res) { + if (err) { + reject(err); + } else { + channel.name = res.body.name; + resolve(); + } + }); + } + }); + }; + + //def setChannelNameAndTopic + + InternalClient.prototype.setChannelNameAndTopic = function setChannelNameAndTopic(chann) { + var name = arguments.length <= 1 || arguments[1] === undefined ? "discordjs_is_the_best" : arguments[1]; + var topic = arguments.length <= 2 || arguments[2] === undefined ? "" : arguments[2]; + + var self = this; + return new Promise(function (resolve, reject) { + + self.resolver.resolveChannel(chann).then(next)["catch"](reject); + + function next(channel) { + + request.patch(Endpoints.CHANNEL(channel.id)).set("authorization", self.token).send({ + name: name, + position: channel.position, + topic: topic + }).end(function (err, res) { + if (err) { + reject(err); + } else { + channel.name = res.body.name; + channel.topic = res.body.topic; + resolve(); + } + }); + } + }); + }; + + //def updateChannel + + InternalClient.prototype.updateChannel = function updateChannel(chann, data) { + return this.setChannelNameAndTopic(chann, data.name, data.topic); + }; + + //def ack + + InternalClient.prototype.ack = function ack(msg) { + var self = this; + return new Promise(function (resolve, reject) { + + msg = self.resolver.resolveMessage(msg); + + if (msg) { + + request.post(Endpoints.CHANNEL_MESSAGE(msg.channel.id, msg.id) + "/ack").set("authorization", self.token).end(function (err) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + } else { + reject(new Error("Message does not exist")); + } + }); + }; + + InternalClient.prototype.sendWS = function sendWS(object) { + if (this.websocket) this.websocket.send(JSON.stringify(object)); + }; + + InternalClient.prototype.createWS = function createWS(url) { + var self = this; + var client = self.client; + + if (this.websocket) return false; + + this.websocket = new WebSocket(url); + + this.websocket.onopen = function () { + + self.sendWS({ + op: 2, + d: { + token: self.token, + v: 3, + compress: self.client.options.compress, + properties: { + "$os": "discord.js", + "$browser": "discord.js", + "$device": "discord.js", + "$referrer": "discord.js", + "$referring_domain": "discord.js" + } + } + }); + }; + + this.websocket.onclose = function () { + self.websocket = null; + self.state = ConnectionState.DISCONNECTED; + client.emit("disconnected"); + }; + + this.websocket.onerror = function (e) { + client.emit("error", e); + }; + + this.websocket.onmessage = function (e) { + + if (e.type === "Binary") { + if (!zlib) zlib = require("zlib"); + e.data = zlib.inflateSync(e.data).toString(); + } + + var packet, data; + try { + packet = JSON.parse(e.data); + data = packet.d; + } catch (e) { + client.emit("error", e); + return; + } + + client.emit("raw", packet); + + switch (packet.t) { + + case PacketType.READY: + var startTime = Date.now(); + self.user = self.users.add(new User(data.user, client)); + data.guilds.forEach(function (server) { + self.servers.add(new Server(server, client)); + }); + data.private_channels.forEach(function (pm) { + self.private_channels.add(new PMChannel(pm, client)); + }); + self.state = ConnectionState.READY; + + setInterval(function () { + return self.sendWS({ op: 1, d: Date.now() }); + }, data.heartbeat_interval); + + client.emit("ready"); + client.emit("debug", "ready packet took " + (Date.now() - startTime) + "ms to process"); + client.emit("debug", "ready with " + self.servers.length + " servers, " + self.channels.length + " channels and " + self.users.length + " users cached."); + + self.readyTime = Date.now(); + break; + + case PacketType.MESSAGE_CREATE: + // format: https://discordapi.readthedocs.org/en/latest/reference/channels/messages.html#message-format + var channel = self.channels.get("id", data.channel_id) || self.private_channels.get("id", data.channel_id); + if (channel) { + var msg = channel.messages.add(new Message(data, channel, client)); + client.emit("message", msg); + self.ack(msg); + } else { + client.emit("warn", "message created but channel is not cached"); + } + break; + case PacketType.MESSAGE_DELETE: + // format https://discordapi.readthedocs.org/en/latest/reference/channels/messages.html#message-delete + var channel = self.channels.get("id", data.channel_id) || self.private_channels.get("id", data.channel_id); + if (channel) { + // potentially blank + var msg = channel.messages.get("id", data.id); + client.emit("messageDeleted", msg); + if (msg) { + channel.messages.remove(msg); + } + } else { + client.emit("warn", "message was deleted but channel is not cached"); + } + break; + case PacketType.MESSAGE_UPDATE: + // format https://discordapi.readthedocs.org/en/latest/reference/channels/messages.html#message-format + var channel = self.channels.get("id", data.channel_id) || self.private_channels.get("id", data.channel_id); + if (channel) { + // potentially blank + var msg = channel.messages.get("id", data.id); + + if (msg) { + // old message exists + data.nonce = data.nonce || msg.nonce; + data.attachments = data.attachments || msg.attachments; + data.tts = data.tts || msg.tts; + data.embeds = data.embeds || msg.embeds; + data.timestamp = data.timestamp || msg.timestamp; + data.mention_everyone = data.mention_everyone || msg.everyoneMentioned; + data.content = data.content || msg.content; + data.mentions = data.mentions || msg.mentions; + data.author = data.author || msg.author; + var nmsg = channel.messages.update(msg, new Message(data, channel, client)); + client.emit("messageUpdated", nmsg, msg); + } + } else { + client.emit("warn", "message was updated but channel is not cached"); + } + break; + case PacketType.SERVER_CREATE: + var server = self.servers.get("id", data.id); + if (!server) { + self.servers.add(new Server(data, client)); + client.emit("serverCreated", server); + } + break; + case PacketType.SERVER_DELETE: + var server = self.servers.get("id", data.id); + if (server) { + + for (var _iterator3 = server.channels, _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 channel = _ref3; + + self.channels.remove(channel); + } + + self.servers.remove(server); + client.emit("serverDeleted", server); + } else { + client.emit("warn", "server was deleted but it was not in the cache"); + } + break; + case PacketType.SERVER_UPDATE: + var server = self.servers.get("id", data.id); + if (server) { + // server exists + data.members = data.members || []; + data.channels = data.channels || []; + var newserver = new Server(data, self); + newserver.members = server.members; + newserver.memberMap = server.memberMap; + newserver.channels = server.channels; + if (newserver.equalsStrict(server)) { + // already the same don't do anything + client.emit("debug", "received server update but server already updated"); + } else { + self.servers.update(server, newserver); + client.emit("serverUpdated", server, newserver); + } + } else if (!server) { + client.emit("warn", "server was updated but it was not in the cache"); + self.servers.add(new Server(data, self)); + client.emit("serverCreated", server); + } + break; + case PacketType.CHANNEL_CREATE: + + var channel = self.channels.get("id", data.id); + + if (!channel) { + + var server = self.servers.get("id", data.guild_id); + if (server) { + if (data.is_private) { + client.emit("channelCreated", self.private_channels.add(new PMChannel(data, client))); + } else { + var chan = null; + if (data.type === "text") { + chan = self.channels.add(new TextChannel(data, client, server)); + } else { + chan = self.channels.add(new VoiceChannel(data, client, server)); + } + client.emit("channelCreated", server.channels.add(chan)); + } + } else { + client.emit("warn", "channel created but server does not exist"); + } + } else { + client.emit("warn", "channel created but already in cache"); + } + + break; + case PacketType.CHANNEL_DELETE: + var channel = self.channels.get("id", data.id); + if (channel) { + + if (channel.server) // accounts for PMs + channel.server.channels.remove(channel); + + self.channels.remove(channel); + client.emit("channelDeleted", channel); + } else { + client.emit("warn", "channel deleted but already out of cache?"); + } + break; + case PacketType.CHANNEL_UPDATE: + var channel = self.channels.get("id", data.id) || self.private_channels.get("id", data.id); + if (channel) { + + if (channel instanceof PMChannel) { + //PM CHANNEL + client.emit("channelUpdated", channel, self.private_channels.update(channel, new PMChannel(data, client))); + } else { + if (channel.server) { + if (channel.type === "text") { + //TEXT CHANNEL + var chan = new TextChannel(data, client, channel.server); + chan.messages = channel.messages; + channel.server.channels.update(channel, chan); + self.channels.update(channel, chan); + client.emit("channelUpdated", channel, chan); + } else { + //VOICE CHANNEL + var chan = new VoiceChannel(data, client, channel.server); + channel.server.channels.update(channel, chan); + self.channels.update(channel, chan); + client.emit("channelUpdated", channel, chan); + } + } else { + client.emit("warn", "channel updated but server non-existant"); + } + } + } else { + client.emit("warn", "channel updated but not in cache"); + } + break; + case PacketType.SERVER_ROLE_CREATE: + var server = self.servers.get("id", data.guild_id); + if (server) { + client.emit("serverRoleCreated", server.roles.add(new Role(data.role, server, client)), server); + } else { + client.emit("warn", "server role made but server not in cache"); + } + break; + case PacketType.SERVER_ROLE_DELETE: + var server = self.servers.get("id", data.guild_id); + if (server) { + var role = server.roles.get("id", data.role_id); + if (role) { + server.roles.remove(role); + client.emit("serverRoleDeleted", role); + } else { + client.emit("warn", "server role deleted but role not in cache"); + } + } else { + client.emit("warn", "server role deleted but server not in cache"); + } + break; + case PacketType.SERVER_ROLE_UPDATE: + var server = self.servers.get("id", data.guild_id); + if (server) { + var role = server.roles.get("id", data.role.id); + if (role) { + var newRole = new Role(data.role, server, client); + server.roles.update(role, newRole); + client.emit("serverRoleUpdated", role, newRole); + } else { + client.emit("warn", "server role updated but role not in cache"); + } + } else { + client.emit("warn", "server role updated but server not in cache"); + } + break; + case PacketType.SERVER_MEMBER_ADD: + var server = self.servers.get("id", data.guild_id); + if (server) { + + server.memberMap[data.user.id] = { + roles: data.roles.map(function (pid) { + return server.roles.get("id", pid); + }), + mute: false, + deaf: false, + joinedAt: Date.parse(data.joined_at) + }; + + client.emit("serverNewMember", server, server.members.add(self.users.add(new User(data.user, client)))); + } else { + client.emit("warn", "server member added but server doesn't exist in cache"); + } + break; + case PacketType.SERVER_MEMBER_REMOVE: + var server = self.servers.get("id", data.guild_id); + if (server) { + var user = self.users.get("id", data.user.id); + if (user) { + server.memberMap[data.user.id] = null; + server.members.remove(user); + client.emit("serverMemberRemoved", server, user); + } else { + client.emit("warn", "server member removed but user doesn't exist in cache"); + } + } else { + client.emit("warn", "server member removed but server doesn't exist in cache"); + } + break; + case PacketType.SERVER_MEMBER_UPDATE: + var server = self.servers.get("id", data.guild_id); + if (server) { + var user = self.users.get("id", data.user.id); + if (user) { + server.memberMap[data.user.id].roles = data.roles.map(function (pid) { + return server.roles.get("id", pid); + }); + server.memberMap[data.user.id].mute = data.mute; + server.memberMap[data.user.id].deaf = data.deaf; + client.emit("serverMemberUpdated", server, user); + } else { + client.emit("warn", "server member removed but user doesn't exist in cache"); + } + } else { + client.emit("warn", "server member updated but server doesn't exist in cache"); + } + break; + case PacketType.PRESENCE_UPDATE: + + var user = self.users.get("id", data.user.id); + + if (user) { + + data.user.username = data.user.username || user.username; + data.user.id = data.user.id || user.id; + data.user.avatar = data.user.avatar || user.avatar; + data.user.discriminator = data.user.discriminator || user.discriminator; + + var presenceUser = new User(data.user, client); + + if (presenceUser.equalsStrict(user)) { + // a real presence update + client.emit("presence", user, data.status, data.game_id); + user.status = data.status; + user.gameID = data.game_id; + } else { + // a name change or avatar change + client.emit("userUpdate", user, presenceUser); + self.users.update(user, presenceUser); + } + } else { + client.emit("warn", "presence update but user not in cache"); + } + + break; + case PacketType.TYPING: + + var user = self.users.get("id", data.user_id); + var channel = self.channels.get("id", data.channel_id) || self.private_channels.get("id", data.channel_id); + + if (user && channel) { + if (user.typing.since) { + user.typing.since = Date.now(); + user.typing.channel = channel; + } else { + user.typing.since = Date.now(); + user.typing.channel = channel; + client.emit("userTypingStart", user, channel); + } + setTimeout(function () { + if (Date.now() - user.typing.since > 5500) { + // they haven't typed since + user.typing.since = null; + user.typing.channel = null; + client.emit("userTypingStop", user, channel); + } + }, 6000); + } else { + client.emit("warn", "user typing but user or channel not existant in cache"); + } + break; + case PacketType.SERVER_BAN_ADD: + var user = self.users.get("id", data.user.id); + var server = self.servers.get("id", data.guild_id); + + if (user && server) { + client.emit("userBanned", user, server); + } else { + client.emit("warn", "user banned but user/server not in cache."); + } + break; + case PacketType.SERVER_BAN_REMOVE: + var user = self.users.get("id", data.user.id); + var server = self.servers.get("id", data.guild_id); + + if (user && server) { + client.emit("userUnbanned", user, server); + } else { + client.emit("warn", "user unbanned but user/server not in cache."); + } + break; + } + }; + }; + + _createClass(InternalClient, [{ + key: "uptime", + get: function get() { + return this.readyTime ? Date.now() - this.readyTime : null; + } + }]); + + return InternalClient; +})(); + +module.exports = InternalClient; \ No newline at end of file diff --git a/lib/Client/Resolver/Resolver.js b/lib/Client/Resolver/Resolver.js index 952a177bf..ed23d92f7 100644 --- a/lib/Client/Resolver/Resolver.js +++ b/lib/Client/Resolver/Resolver.js @@ -1,13 +1,239 @@ -"use strict"; /* global Buffer */function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var fs=require("fs");var User=require("../../Structures/User.js"),Channel=require("../../Structures/Channel.js"),TextChannel=require("../../Structures/TextChannel.js"),VoiceChannel=require("../../Structures/VoiceChannel.js"),ServerChannel=require("../../Structures/ServerChannel.js"),PMChannel=require("../../Structures/PMChannel.js"),Server=require("../../Structures/Server.js"),Message=require("../../Structures/Message.js"),Invite=require("../../Structures/Invite.js");var Resolver=(function(){function Resolver(internal){_classCallCheck(this,Resolver);this.internal = internal;}Resolver.prototype.resolveToBase64 = function resolveToBase64(resource){if(resource instanceof Buffer){resource = resource.toString("base64");resource = "data:image/jpg;base64," + resource;}return resource;};Resolver.prototype.resolveInviteID = function resolveInviteID(resource){if(resource instanceof Invite){return resource.id;}else if(typeof resource == "string" || resource instanceof String){if(resource.indexOf("http") === 0){var split=resource.split("/");return split.pop();}else {return resource;}}return null;};Resolver.prototype.resolveServer = function resolveServer(resource){if(resource instanceof Server){return resource;}else if(resource instanceof ServerChannel){return resource.server;}else if(resource instanceof String || typeof resource === "string"){return this.internal.servers.get("id",resource);}else if(resource instanceof Message){if(resource.channel instanceof TextChannel){return resource.server;}}return null;};Resolver.prototype.resolveFile = function resolveFile(resource){if(typeof resource === "string" || resource instanceof String){return fs.createReadStream(resource);}else {return resource;}};Resolver.prototype.resolveMentions = function resolveMentions(resource){ // resource is a string -var _mentions=[];for(var _iterator=resource.match(/<@[^>]*>/g) || [],_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;_mentions.push(mention.substring(2,mention.length - 1));}return _mentions;};Resolver.prototype.resolveString = function resolveString(resource){ // accepts Array, Channel, Server, User, Message, String and anything -// toString()-able -var final=resource;if(resource instanceof Array){final = resource.join("\n");}return final.toString();};Resolver.prototype.resolveUser = function resolveUser(resource){ /* - accepts a Message, Channel, Server, String ID, User, PMChannel - */var found=null;if(resource instanceof User){found = resource;}else if(resource instanceof Message){found = resource.author;}else if(resource instanceof TextChannel){var lmsg=resource.lastMessage;if(lmsg){found = lmsg.author;}}else if(resource instanceof Server){found = resource.owner;}else if(resource instanceof PMChannel){found = resource.recipient;}else if(resource instanceof String || typeof resource === "string"){found = this.client.internal.users.get("id",resource);}return found;};Resolver.prototype.resolveMessage = function resolveMessage(resource){ // accepts a Message, PMChannel & TextChannel -var found=null;if(resource instanceof TextChannel || resource instanceof PMChannel){found = resource.lastMessage;}else if(resource instanceof Message){found = resource;}return found;};Resolver.prototype.resolveVoiceChannel = function resolveVoiceChannel(resource){ // resolveChannel will also work but this is more apt -if(resource instanceof VoiceChannel){return resource;}return null;};Resolver.prototype.resolveChannel = function resolveChannel(resource){ /* - accepts a Message, Channel, Server, String ID, User - */var self=this;return new Promise(function(resolve,reject){var found=null;if(resource instanceof Message){found = resource.channel;}else if(resource instanceof Channel){found = resource;}else if(resource instanceof Server){found = resource.channels.get("id",resource.id);}else if(resource instanceof String || typeof resource === "string"){found = self.internal.channels.get("id",resource);}else if(resource instanceof User){ // see if a PM exists -var chatFound=false;for(var _iterator2=self.internal.private_channels,_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 pmchat=_ref2;if(pmchat.recipient.equals(resource)){chatFound = pmchat;break;}}if(chatFound){ // a PM already exists! -found = chatFound;}else { // PM does not exist :\ -self.internal.startPM(resource).then(function(pmchannel){return resolve(pmchannel);})["catch"](function(e){return reject(e);});return;}}if(found)resolve(found);else reject(new Error("Didn't found anything"));});};return Resolver;})();module.exports = Resolver; +"use strict"; +/* global Buffer */ + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var fs = require("fs"); + +var User = require("../../Structures/User.js"), + Channel = require("../../Structures/Channel.js"), + TextChannel = require("../../Structures/TextChannel.js"), + VoiceChannel = require("../../Structures/VoiceChannel.js"), + ServerChannel = require("../../Structures/ServerChannel.js"), + PMChannel = require("../../Structures/PMChannel.js"), + Server = require("../../Structures/Server.js"), + Message = require("../../Structures/Message.js"), + Invite = require("../../Structures/Invite.js"), + Games = require("../../../ref/gameMap.js"); + +var Resolver = (function () { + function Resolver(internal) { + _classCallCheck(this, Resolver); + + this.internal = internal; + } + + Resolver.prototype.resolveGameID = function resolveGameID(resource) { + if (!isNaN(resource) && parseInt(resource) % 1 === 0) { + return resource; + } else if (typeof resource == "string" || resource instanceof String) { + + for (var _iterator = Games, _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 game = _ref; + + if (game.name.toUpperCase() === resource.toUpperCase()) { + return game.id; + } + } + } + + return null; + }; + + Resolver.prototype.resolveToBase64 = function resolveToBase64(resource) { + if (resource instanceof Buffer) { + resource = resource.toString("base64"); + resource = "data:image/jpg;base64," + resource; + } + return resource; + }; + + Resolver.prototype.resolveInviteID = function resolveInviteID(resource) { + if (resource instanceof Invite) { + return resource.id; + } else if (typeof resource == "string" || resource instanceof String) { + + if (resource.indexOf("http") === 0) { + var split = resource.split("/"); + return split.pop(); + } else { + return resource; + } + } + return null; + }; + + Resolver.prototype.resolveServer = function resolveServer(resource) { + if (resource instanceof Server) { + return resource; + } else if (resource instanceof ServerChannel) { + return resource.server; + } else if (resource instanceof String || typeof resource === "string") { + return this.internal.servers.get("id", resource); + } else if (resource instanceof Message) { + if (resource.channel instanceof TextChannel) { + return resource.server; + } + } + return null; + }; + + Resolver.prototype.resolveFile = function resolveFile(resource) { + if (typeof resource === "string" || resource instanceof String) { + return fs.createReadStream(resource); + } else { + return resource; + } + }; + + Resolver.prototype.resolveMentions = function resolveMentions(resource) { + // resource is a string + var _mentions = []; + for (var _iterator2 = resource.match(/<@[^>]*>/g) || [], _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(mention.substring(2, mention.length - 1)); + } + return _mentions; + }; + + Resolver.prototype.resolveString = function resolveString(resource) { + + // accepts Array, Channel, Server, User, Message, String and anything + // toString()-able + + var final = resource; + if (resource instanceof Array) { + final = resource.join("\n"); + } + + return final.toString(); + }; + + Resolver.prototype.resolveUser = function resolveUser(resource) { + /* + accepts a Message, Channel, Server, String ID, User, PMChannel + */ + var found = null; + if (resource instanceof User) { + found = resource; + } else if (resource instanceof Message) { + found = resource.author; + } else if (resource instanceof TextChannel) { + var lmsg = resource.lastMessage; + if (lmsg) { + found = lmsg.author; + } + } else if (resource instanceof Server) { + found = resource.owner; + } else if (resource instanceof PMChannel) { + found = resource.recipient; + } else if (resource instanceof String || typeof resource === "string") { + found = this.client.internal.users.get("id", resource); + } + + return found; + }; + + Resolver.prototype.resolveMessage = function resolveMessage(resource) { + // accepts a Message, PMChannel & TextChannel + var found = null; + + if (resource instanceof TextChannel || resource instanceof PMChannel) { + found = resource.lastMessage; + } else if (resource instanceof Message) { + found = resource; + } + + return found; + }; + + Resolver.prototype.resolveVoiceChannel = function resolveVoiceChannel(resource) { + // resolveChannel will also work but this is more apt + if (resource instanceof VoiceChannel) { + return resource; + } + return null; + }; + + Resolver.prototype.resolveChannel = function resolveChannel(resource) { + /* + accepts a Message, Channel, Server, String ID, User + */ + var self = this; + + return new Promise(function (resolve, reject) { + var found = null; + if (resource instanceof Message) { + found = resource.channel; + } else if (resource instanceof Channel) { + found = resource; + } else if (resource instanceof Server) { + found = resource.channels.get("id", resource.id); + } else if (resource instanceof String || typeof resource === "string") { + found = self.internal.channels.get("id", resource); + } else if (resource instanceof User) { + // see if a PM exists + var chatFound = false; + for (var _iterator3 = self.internal.private_channels, _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 pmchat = _ref3; + + if (pmchat.recipient.equals(resource)) { + chatFound = pmchat; + break; + } + } + if (chatFound) { + // a PM already exists! + found = chatFound; + } else { + // PM does not exist :\ + self.internal.startPM(resource).then(function (pmchannel) { + return resolve(pmchannel); + })["catch"](function (e) { + return reject(e); + }); + return; + } + } + if (found) resolve(found);else reject(new Error("Didn't found anything")); + }); + }; + + return Resolver; +})(); + +module.exports = Resolver; \ No newline at end of file diff --git a/lib/Constants.js b/lib/Constants.js index 41eb71724..572f3c8f2 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -1,7 +1,130 @@ -"use strict";var API="https://discordapp.com/api";var Endpoints={ // general endpoints -LOGIN:API + "/auth/login",LOGOUT:API + "/auth/logout",ME:API + "/users/@me",GATEWAY:API + "/gateway",USER_CHANNELS:function USER_CHANNELS(userID){return API + "/users/" + userID + "/channels";},AVATAR:function AVATAR(userID,avatar){return API + "/users/" + userID + "/avatars/" + avatar + ".jpg";},INVITE:function INVITE(id){return API + "/invite/" + id;}, // servers -SERVERS:API + "/guilds",SERVER:function SERVER(serverID){return Endpoints.SERVERS + "/" + serverID;},SERVER_ICON:function SERVER_ICON(serverID,hash){return Endpoints.SERVER(serverID) + "/icons/" + hash + ".jpg";},SERVER_PRUNE:function SERVER_PRUNE(serverID){return Endpoints.SERVER(serverID) + "/prune";},SERVER_EMBED:function SERVER_EMBED(serverID){return Endpoints.SERVER(serverID) + "/embed";},SERVER_INVITES:function SERVER_INVITES(serverID){return Endpoints.SERVER(serverID) + "/invites";},SERVER_ROLES:function SERVER_ROLES(serverID){return Endpoints.SERVER(serverID) + "/roles";},SERVER_BANS:function SERVER_BANS(serverID){return Endpoints.SERVER(serverID) + "/bans";},SERVER_INTEGRATIONS:function SERVER_INTEGRATIONS(serverID){return Endpoints.SERVER(serverID) + "/integrations";},SERVER_MEMBERS:function SERVER_MEMBERS(serverID){return Endpoints.SERVER(serverID) + "/members";},SERVER_CHANNELS:function SERVER_CHANNELS(serverID){return Endpoints.SERVER(serverID) + "/channels";}, // channels -CHANNELS:API + "/channels",CHANNEL:function CHANNEL(channelID){return Endpoints.CHANNELS + "/" + channelID;},CHANNEL_MESSAGES:function CHANNEL_MESSAGES(channelID){return Endpoints.CHANNEL(channelID) + "/messages";},CHANNEL_INVITES:function CHANNEL_INVITES(channelID){return Endpoints.CHANNEL(channelID) + "/invites";},CHANNEL_TYPING:function CHANNEL_TYPING(channelID){return Endpoints.CHANNEL(channelID) + "/typing";},CHANNEL_PERMISSIONS:function CHANNEL_PERMISSIONS(channelID){return Endpoints.CHANNEL(channelID) + "/permissions";},CHANNEL_MESSAGE:function CHANNEL_MESSAGE(channelID,messageID){return Endpoints.CHANNEL_MESSAGES(channelID) + "/" + messageID;}};var Permissions={ // general -createInstantInvite:1 << 0,kickMembers:1 << 1,banMembers:1 << 2,manageRoles:1 << 3,managePermissions:1 << 3,manageChannels:1 << 4,manageChannel:1 << 4,manageServer:1 << 5, // text -readMessages:1 << 10,sendMessages:1 << 11,sendTTSMessages:1 << 12,manageMessages:1 << 13,embedLinks:1 << 14,attachFiles:1 << 15,readMessageHistory:1 << 16,mentionEveryone:1 << 17, // voice -voiceConnect:1 << 20,voiceSpeak:1 << 21,voiceMuteMembers:1 << 22,voiceDeafenMembers:1 << 23,voiceMoveMembers:1 << 24,voiceUseVAD:1 << 25};var PacketType={READY:"READY",MESSAGE_CREATE:"MESSAGE_CREATE",MESSAGE_UPDATE:"MESSAGE_UPDATE",MESSAGE_DELETE:"MESSAGE_DELETE",SERVER_CREATE:"GUILD_CREATE",SERVER_DELETE:"GUILD_DELETE",SERVER_UPDATE:"GUILD_UPDATE",CHANNEL_CREATE:"CHANNEL_CREATE",CHANNEL_DELETE:"CHANNEL_DELETE",CHANNEL_UPDATE:"CHANNEL_UPDATE",SERVER_ROLE_CREATE:"GUILD_ROLE_CREATE",SERVER_ROLE_DELETE:"GUILD_ROLE_DELETE",SERVER_ROLE_UPDATE:"GUILD_ROLE_UPDATE",SERVER_MEMBER_ADD:"GUILD_MEMBER_ADD",SERVER_MEMBER_REMOVE:"GUILD_MEMBER_REMOVE",SERVER_MEMBER_UPDATE:"GUILD_MEMBER_UPDATE",PRESENCE_UPDATE:"PRESENCE_UPDATE",TYPING:"TYPING_START",SERVER_BAN_ADD:"GUILD_BAN_ADD",SERVER_BAN_REMOVE:"GUILD_BAN_REMOVE"};exports.API_ENDPOINT = API;exports.Endpoints = Endpoints;exports.PacketType = PacketType;exports.Permissions = Permissions; +"use strict"; + +var API = "https://discordapp.com/api"; +var Endpoints = { + // general endpoints + LOGIN: API + "/auth/login", + LOGOUT: API + "/auth/logout", + ME: API + "/users/@me", + GATEWAY: API + "/gateway", + USER_CHANNELS: function USER_CHANNELS(userID) { + return API + "/users/" + userID + "/channels"; + }, + AVATAR: function AVATAR(userID, avatar) { + return API + "/users/" + userID + "/avatars/" + avatar + ".jpg"; + }, + INVITE: function INVITE(id) { + return API + "/invite/" + id; + }, + + // servers + SERVERS: API + "/guilds", + SERVER: function SERVER(serverID) { + return Endpoints.SERVERS + "/" + serverID; + }, + SERVER_ICON: function SERVER_ICON(serverID, hash) { + return Endpoints.SERVER(serverID) + "/icons/" + hash + ".jpg"; + }, + SERVER_PRUNE: function SERVER_PRUNE(serverID) { + return Endpoints.SERVER(serverID) + "/prune"; + }, + SERVER_EMBED: function SERVER_EMBED(serverID) { + return Endpoints.SERVER(serverID) + "/embed"; + }, + SERVER_INVITES: function SERVER_INVITES(serverID) { + return Endpoints.SERVER(serverID) + "/invites"; + }, + SERVER_ROLES: function SERVER_ROLES(serverID) { + return Endpoints.SERVER(serverID) + "/roles"; + }, + SERVER_BANS: function SERVER_BANS(serverID) { + return Endpoints.SERVER(serverID) + "/bans"; + }, + SERVER_INTEGRATIONS: function SERVER_INTEGRATIONS(serverID) { + return Endpoints.SERVER(serverID) + "/integrations"; + }, + SERVER_MEMBERS: function SERVER_MEMBERS(serverID) { + return Endpoints.SERVER(serverID) + "/members"; + }, + SERVER_CHANNELS: function SERVER_CHANNELS(serverID) { + return Endpoints.SERVER(serverID) + "/channels"; + }, + + // channels + CHANNELS: API + "/channels", + CHANNEL: function CHANNEL(channelID) { + return Endpoints.CHANNELS + "/" + channelID; + }, + CHANNEL_MESSAGES: function CHANNEL_MESSAGES(channelID) { + return Endpoints.CHANNEL(channelID) + "/messages"; + }, + CHANNEL_INVITES: function CHANNEL_INVITES(channelID) { + return Endpoints.CHANNEL(channelID) + "/invites"; + }, + CHANNEL_TYPING: function CHANNEL_TYPING(channelID) { + return Endpoints.CHANNEL(channelID) + "/typing"; + }, + CHANNEL_PERMISSIONS: function CHANNEL_PERMISSIONS(channelID) { + return Endpoints.CHANNEL(channelID) + "/permissions"; + }, + CHANNEL_MESSAGE: function CHANNEL_MESSAGE(channelID, messageID) { + return Endpoints.CHANNEL_MESSAGES(channelID) + "/" + messageID; + } +}; + +var Permissions = { + // general + createInstantInvite: 1 << 0, + kickMembers: 1 << 1, + banMembers: 1 << 2, + manageRoles: 1 << 3, + managePermissions: 1 << 3, + manageChannels: 1 << 4, + manageChannel: 1 << 4, + manageServer: 1 << 5, + // text + readMessages: 1 << 10, + sendMessages: 1 << 11, + sendTTSMessages: 1 << 12, + manageMessages: 1 << 13, + embedLinks: 1 << 14, + attachFiles: 1 << 15, + readMessageHistory: 1 << 16, + mentionEveryone: 1 << 17, + // voice + voiceConnect: 1 << 20, + voiceSpeak: 1 << 21, + voiceMuteMembers: 1 << 22, + voiceDeafenMembers: 1 << 23, + voiceMoveMembers: 1 << 24, + voiceUseVAD: 1 << 25 + +}; + +var PacketType = { + READY: "READY", + MESSAGE_CREATE: "MESSAGE_CREATE", + MESSAGE_UPDATE: "MESSAGE_UPDATE", + MESSAGE_DELETE: "MESSAGE_DELETE", + SERVER_CREATE: "GUILD_CREATE", + SERVER_DELETE: "GUILD_DELETE", + SERVER_UPDATE: "GUILD_UPDATE", + CHANNEL_CREATE: "CHANNEL_CREATE", + CHANNEL_DELETE: "CHANNEL_DELETE", + CHANNEL_UPDATE: "CHANNEL_UPDATE", + SERVER_ROLE_CREATE: "GUILD_ROLE_CREATE", + SERVER_ROLE_DELETE: "GUILD_ROLE_DELETE", + SERVER_ROLE_UPDATE: "GUILD_ROLE_UPDATE", + SERVER_MEMBER_ADD: "GUILD_MEMBER_ADD", + SERVER_MEMBER_REMOVE: "GUILD_MEMBER_REMOVE", + SERVER_MEMBER_UPDATE: "GUILD_MEMBER_UPDATE", + PRESENCE_UPDATE: "PRESENCE_UPDATE", + TYPING: "TYPING_START", + SERVER_BAN_ADD: "GUILD_BAN_ADD", + SERVER_BAN_REMOVE: "GUILD_BAN_REMOVE" +}; + +exports.API_ENDPOINT = API; +exports.Endpoints = Endpoints; +exports.PacketType = PacketType; +exports.Permissions = Permissions; \ No newline at end of file diff --git a/lib/Structures/Channel.js b/lib/Structures/Channel.js index a9164ccfa..93d222f13 100644 --- a/lib/Structures/Channel.js +++ b/lib/Structures/Channel.js @@ -1 +1,39 @@ -"use strict";function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _inherits(subClass,superClass){if(typeof superClass !== "function" && superClass !== null){throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__ = superClass;}var Equality=require("../Util/Equality.js");var Cache=require("../Util/Cache.js");var PermissionOverwrite=require("./PermissionOverwrite.js");var reg=require("../Util/ArgumentRegulariser.js").reg;var Channel=(function(_Equality){_inherits(Channel,_Equality);function Channel(data,client){_classCallCheck(this,Channel);_Equality.call(this);this.id = data.id;this.client = client;}Channel.prototype["delete"] = function _delete(){return this.client.deleteChannel.apply(this.client,reg(this,arguments));};return Channel;})(Equality);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"); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var Equality = require("../Util/Equality.js"); +var Cache = require("../Util/Cache.js"); +var PermissionOverwrite = require("./PermissionOverwrite.js"); +var reg = require("../Util/ArgumentRegulariser.js").reg; + +var Channel = (function (_Equality) { + _inherits(Channel, _Equality); + + function Channel(data, client) { + _classCallCheck(this, Channel); + + _Equality.call(this); + this.id = data.id; + this.client = client; + } + + Channel.prototype["delete"] = function _delete() { + return this.client.deleteChannel.apply(this.client, reg(this, arguments)); + }; + + _createClass(Channel, [{ + key: "isPrivate", + get: function get() { + return !!this.server; + } + }]); + + return Channel; +})(Equality); + +module.exports = Channel; \ No newline at end of file diff --git a/lib/Structures/ChannelPermissions.js b/lib/Structures/ChannelPermissions.js index 7e7211bff..fe7a039fd 100644 --- a/lib/Structures/ChannelPermissions.js +++ b/lib/Structures/ChannelPermissions.js @@ -1,7 +1,75 @@ -"use strict";function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var Permissions=require("../Constants.js").Permissions;var ChannelPermissions=(function(){function ChannelPermissions(permissions){_classCallCheck(this,ChannelPermissions);this.permissions = permissions;}ChannelPermissions.prototype.serialise = function serialise(explicit){var _this=this;var hp=function hp(perm){return _this.hasPermission(perm,explicit);};return { // general -createInstantInvite:hp(Permissions.createInstantInvite),kickMembers:hp(Permissions.kickMembers),banMembers:hp(Permissions.banMembers),managePermissions:hp(Permissions.managePermissions),manageChannel:hp(Permissions.manageChannel),manageServer:hp(Permissions.manageServer), // text -readMessages:hp(Permissions.readMessages),sendMessages:hp(Permissions.sendMessages),sendTTSMessages:hp(Permissions.sendTTSMessages),manageMessages:hp(Permissions.manageMessages),embedLinks:hp(Permissions.embedLinks),attachFiles:hp(Permissions.attachFiles),readMessageHistory:hp(Permissions.readMessageHistory),mentionEveryone:hp(Permissions.mentionEveryone), // voice -voiceConnect:hp(Permissions.voiceConnect),voiceSpeak:hp(Permissions.voiceSpeak),voiceMuteMembers:hp(Permissions.voiceMuteMembers),voiceDeafenMembers:hp(Permissions.voiceDeafenMembers),voiceMoveMembers:hp(Permissions.voiceMoveMembers),voiceUseVAD:hp(Permissions.voiceUseVAD)};};ChannelPermissions.prototype.serialize = function serialize(){ // ;n; -return this.serialise();};ChannelPermissions.prototype.hasPermission = function hasPermission(perm){var explicit=arguments.length <= 1 || arguments[1] === undefined?false:arguments[1];if(perm instanceof String || typeof perm === "string"){perm = Permissions[perm];}if(!perm){return false;}if(!explicit){ // implicit permissions allowed -if(!!(this.permissions & Permissions.manageRoles)){ // manageRoles allowed, they have all permissions -return true;}}return !!(this.permissions & perm);};return ChannelPermissions;})();module.exports = ChannelPermissions; +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var Permissions = require("../Constants.js").Permissions; + +var ChannelPermissions = (function () { + function ChannelPermissions(permissions) { + _classCallCheck(this, ChannelPermissions); + + this.permissions = permissions; + } + + ChannelPermissions.prototype.serialise = function serialise(explicit) { + var _this = this; + + var hp = function hp(perm) { + return _this.hasPermission(perm, explicit); + }; + + return { + // general + createInstantInvite: hp(Permissions.createInstantInvite), + kickMembers: hp(Permissions.kickMembers), + banMembers: hp(Permissions.banMembers), + managePermissions: hp(Permissions.managePermissions), + manageChannel: hp(Permissions.manageChannel), + manageServer: hp(Permissions.manageServer), + // text + readMessages: hp(Permissions.readMessages), + sendMessages: hp(Permissions.sendMessages), + sendTTSMessages: hp(Permissions.sendTTSMessages), + manageMessages: hp(Permissions.manageMessages), + embedLinks: hp(Permissions.embedLinks), + attachFiles: hp(Permissions.attachFiles), + readMessageHistory: hp(Permissions.readMessageHistory), + mentionEveryone: hp(Permissions.mentionEveryone), + // voice + voiceConnect: hp(Permissions.voiceConnect), + voiceSpeak: hp(Permissions.voiceSpeak), + voiceMuteMembers: hp(Permissions.voiceMuteMembers), + voiceDeafenMembers: hp(Permissions.voiceDeafenMembers), + voiceMoveMembers: hp(Permissions.voiceMoveMembers), + voiceUseVAD: hp(Permissions.voiceUseVAD) + }; + }; + + ChannelPermissions.prototype.serialize = function serialize() { + // ;n; + return this.serialise(); + }; + + ChannelPermissions.prototype.hasPermission = function hasPermission(perm) { + var explicit = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1]; + + if (perm instanceof String || typeof perm === "string") { + perm = Permissions[perm]; + } + if (!perm) { + return false; + } + if (!explicit) { + // implicit permissions allowed + if (!!(this.permissions & Permissions.manageRoles)) { + // manageRoles allowed, they have all permissions + return true; + } + } + return !!(this.permissions & perm); + }; + + return ChannelPermissions; +})(); + +module.exports = ChannelPermissions; \ No newline at end of file diff --git a/lib/Structures/Invite.js b/lib/Structures/Invite.js index f0a1d01ba..c003ff1dc 100644 --- a/lib/Structures/Invite.js +++ b/lib/Structures/Invite.js @@ -1 +1,32 @@ -"use strict";function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var Server=require("./Server.js");var ServerChannel=require("./ServerChannel.js");var Invite=(function(){function Invite(data,chan,client){_classCallCheck(this,Invite);this.maxAge = data.max_age;this.code = data.code;this.server = chan.server;this.channel = chan;this.revoked = data.revoked;this.createdAt = Date.parse(data.created_at);this.temporary = data.temporary;this.uses = data.uses;this.maxUses = data.uses;this.inviter = client.internal.users.get("id",data.inviter.id);this.xkcd = data.xkcdpass;}Invite.prototype.toString = function toString(){return "https://discord.gg/" + this.code;};return Invite;})();module.exports = Invite; +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var Server = require("./Server.js"); +var ServerChannel = require("./ServerChannel.js"); + +var Invite = (function () { + function Invite(data, chan, client) { + _classCallCheck(this, Invite); + + this.maxAge = data.max_age; + this.code = data.code; + this.server = chan.server; + this.channel = chan; + this.revoked = data.revoked; + this.createdAt = Date.parse(data.created_at); + this.temporary = data.temporary; + this.uses = data.uses; + this.maxUses = data.uses; + this.inviter = client.internal.users.get("id", data.inviter.id); + this.xkcd = data.xkcdpass; + } + + Invite.prototype.toString = function toString() { + return "https://discord.gg/" + this.code; + }; + + return Invite; +})(); + +module.exports = Invite; \ No newline at end of file diff --git a/lib/Structures/Message.js b/lib/Structures/Message.js index a47ad3642..d61295506 100644 --- a/lib/Structures/Message.js +++ b/lib/Structures/Message.js @@ -1,4 +1,87 @@ -"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _inherits(subClass,superClass){if(typeof superClass !== "function" && superClass !== null){throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__ = superClass;}var Cache=require("../Util/Cache.js");var User=require("./User.js");var reg=require("../Util/ArgumentRegulariser.js").reg;var Equality=require("../Util/Equality");var Message=(function(_Equality){_inherits(Message,_Equality);function Message(data,channel,client){var _this=this;_classCallCheck(this,Message);_Equality.call(this);this.channel = channel;this.client = client;this.nonce = data.nonce;this.attachments = data.attachments;this.tts = data.tts;this.embeds = data.embeds;this.timestamp = Date.parse(data.timestamp);this.everyoneMentioned = data.mention_everyone;this.id = data.id;if(data.edited_timestamp)this.editedTimestamp = Date.parse(data.edited_timestamp);if(data.author instanceof User)this.author = data.author;else this.author = client.internal.users.add(new User(data.author,client));this.content = data.content;this.mentions = new Cache();data.mentions.forEach(function(mention){ // this is .add and not .get because it allows the bot to cache -// users from messages from logs who may have left the server and were -// not previously cached. -if(mention instanceof User)_this.mentions.push(mention);else _this.mentions.add(client.internal.users.add(new User(mention,client)));});}Message.prototype.isMentioned = function isMentioned(user){user = this.client.internal.resolver.resolveUser(user);if(user){return this.mentions.has("id",user.id);}else {return false;}};Message.prototype.toString = function toString(){return this.content;};Message.prototype["delete"] = function _delete(){return this.client.deleteMessage.apply(this.client,reg(this,arguments));};Message.prototype.update = function update(){return this.client.updateMessage.apply(this.client,reg(this,arguments));};Message.prototype.reply = function reply(){return this.client.reply.apply(this.client,reg(this,arguments));};Message.prototype.replyTTS = function replyTTS(){return this.client.replyTTS.apply(this.client,reg(this,arguments));};_createClass(Message,[{key:"sender",get:function get(){return this.author;}}]);return Message;})(Equality);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"); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var Cache = require("../Util/Cache.js"); +var User = require("./User.js"); +var reg = require("../Util/ArgumentRegulariser.js").reg; +var Equality = require("../Util/Equality"); + +var Message = (function (_Equality) { + _inherits(Message, _Equality); + + function Message(data, channel, client) { + var _this = this; + + _classCallCheck(this, Message); + + _Equality.call(this); + this.channel = channel; + this.client = client; + this.nonce = data.nonce; + this.attachments = data.attachments; + this.tts = data.tts; + this.embeds = data.embeds; + this.timestamp = Date.parse(data.timestamp); + this.everyoneMentioned = data.mention_everyone; + this.id = data.id; + + if (data.edited_timestamp) this.editedTimestamp = Date.parse(data.edited_timestamp); + + if (data.author instanceof User) this.author = data.author;else this.author = client.internal.users.add(new User(data.author, client)); + + this.content = data.content; + this.mentions = new Cache(); + + data.mentions.forEach(function (mention) { + // this is .add and not .get because it allows the bot to cache + // users from messages from logs who may have left the server and were + // not previously cached. + if (mention instanceof User) _this.mentions.push(mention);else _this.mentions.add(client.internal.users.add(new User(mention, client))); + }); + } + + Message.prototype.isMentioned = function isMentioned(user) { + user = this.client.internal.resolver.resolveUser(user); + if (user) { + return this.mentions.has("id", user.id); + } else { + return false; + } + }; + + Message.prototype.toString = function toString() { + return this.content; + }; + + Message.prototype["delete"] = function _delete() { + return this.client.deleteMessage.apply(this.client, reg(this, arguments)); + }; + + Message.prototype.update = function update() { + return this.client.updateMessage.apply(this.client, reg(this, arguments)); + }; + + Message.prototype.reply = function reply() { + return this.client.reply.apply(this.client, reg(this, arguments)); + }; + + Message.prototype.replyTTS = function replyTTS() { + return this.client.replyTTS.apply(this.client, reg(this, arguments)); + }; + + _createClass(Message, [{ + key: "sender", + get: function get() { + return this.author; + } + }]); + + return Message; +})(Equality); + +module.exports = Message; \ No newline at end of file diff --git a/lib/Structures/PMChannel.js b/lib/Structures/PMChannel.js index 480788f60..3f0404241 100644 --- a/lib/Structures/PMChannel.js +++ b/lib/Structures/PMChannel.js @@ -1 +1,53 @@ -"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _inherits(subClass,superClass){if(typeof superClass !== "function" && superClass !== null){throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__ = superClass;}var Channel=require("./Channel.js");var User=require("./User.js");var Equality=require("../Util/Equality.js");var Cache=require("../Util/Cache.js");var reg=require("../Util/ArgumentRegulariser.js").reg;var PMChannel=(function(_Channel){_inherits(PMChannel,_Channel);function PMChannel(data,client){_classCallCheck(this,PMChannel);_Channel.call(this,data,client);this.type = data.type || "text";this.lastMessageId = data.last_message_id;this.messages = new Cache("id",1000);this.recipient = this.client.internal.users.add(new User(data.recipient,this.client));} /* warning! may return null */PMChannel.prototype.toString = function toString(){return this.recipient.toString();};PMChannel.prototype.sendMessage = function sendMessage(){return this.client.sendMessage.apply(this.client,reg(this,arguments));};PMChannel.prototype.sendTTSMessage = function sendTTSMessage(){return this.client.sendTTSMessage.apply(this.client,reg(this,arguments));};_createClass(PMChannel,[{key:"lastMessage",get:function get(){return this.messages.get("id",this.lastMessageID);}}]);return PMChannel;})(Channel);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"); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var Channel = require("./Channel.js"); +var User = require("./User.js"); +var Equality = require("../Util/Equality.js"); +var Cache = require("../Util/Cache.js"); +var reg = require("../Util/ArgumentRegulariser.js").reg; + +var PMChannel = (function (_Channel) { + _inherits(PMChannel, _Channel); + + function PMChannel(data, client) { + _classCallCheck(this, PMChannel); + + _Channel.call(this, data, client); + + this.type = data.type || "text"; + this.lastMessageId = data.last_message_id; + this.messages = new Cache("id", 1000); + this.recipient = this.client.internal.users.add(new User(data.recipient, this.client)); + } + + /* warning! may return null */ + + PMChannel.prototype.toString = function toString() { + return this.recipient.toString(); + }; + + PMChannel.prototype.sendMessage = function sendMessage() { + return this.client.sendMessage.apply(this.client, reg(this, arguments)); + }; + + PMChannel.prototype.sendTTSMessage = function sendTTSMessage() { + return this.client.sendTTSMessage.apply(this.client, reg(this, arguments)); + }; + + _createClass(PMChannel, [{ + key: "lastMessage", + get: function get() { + return this.messages.get("id", this.lastMessageID); + } + }]); + + return PMChannel; +})(Channel); + +module.exports = PMChannel; \ No newline at end of file diff --git a/lib/Structures/PermissionOverwrite.js b/lib/Structures/PermissionOverwrite.js index 1ffb2e463..f20d61b7a 100644 --- a/lib/Structures/PermissionOverwrite.js +++ b/lib/Structures/PermissionOverwrite.js @@ -1,6 +1,86 @@ -"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var Permissions=require("../Constants.js").Permissions;var PermissionOverwrite=(function(){function PermissionOverwrite(data){_classCallCheck(this,PermissionOverwrite);this.id = data.id;this.type = data.type; // member or role -this.deny = data.deny;this.allow = data.allow;} // returns an array of allowed permissions -PermissionOverwrite.prototype.setAllowed = function setAllowed(allowedArray){var _this=this;allowedArray.forEach(function(permission){if(permission instanceof String || typeof permission === "string"){permission = Permissions[permission];}if(permission){_this.allow |= 1 << permission;}});};PermissionOverwrite.prototype.setDenied = function setDenied(deniedArray){var _this2=this;deniedArray.forEach(function(permission){if(permission instanceof String || typeof permission === "string"){permission = Permissions[permission];}if(permission){_this2.deny |= 1 << permission;}});};_createClass(PermissionOverwrite,[{key:"allowed",get:function get(){var allowed=[];for(var permName in Permissions) {if(permName === "manageRoles" || permName === "manageChannels"){ // these permissions do not exist in overwrites. -continue;}if(!!(this.allow & Permissions[permName])){allowed.push(permName);}}return allowed;} // returns an array of denied permissions -},{key:"denied",get:function get(){var denied=[];for(var permName in Permissions) {if(permName === "manageRoles" || permName === "manageChannels"){ // these permissions do not exist in overwrites. -continue;}if(!!(this.deny & Permissions[permName])){denied.push(permName);}}return denied;}}]);return PermissionOverwrite;})();module.exports = PermissionOverwrite; +"use strict"; + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var Permissions = require("../Constants.js").Permissions; + +var PermissionOverwrite = (function () { + function PermissionOverwrite(data) { + _classCallCheck(this, PermissionOverwrite); + + this.id = data.id; + this.type = data.type; // member or role + this.deny = data.deny; + this.allow = data.allow; + } + + // returns an array of allowed permissions + + PermissionOverwrite.prototype.setAllowed = function setAllowed(allowedArray) { + var _this = this; + + allowedArray.forEach(function (permission) { + if (permission instanceof String || typeof permission === "string") { + permission = Permissions[permission]; + } + if (permission) { + _this.allow |= 1 << permission; + } + }); + }; + + PermissionOverwrite.prototype.setDenied = function setDenied(deniedArray) { + var _this2 = this; + + deniedArray.forEach(function (permission) { + if (permission instanceof String || typeof permission === "string") { + permission = Permissions[permission]; + } + if (permission) { + _this2.deny |= 1 << permission; + } + }); + }; + + _createClass(PermissionOverwrite, [{ + key: "allowed", + get: function get() { + var allowed = []; + for (var permName in Permissions) { + if (permName === "manageRoles" || permName === "manageChannels") { + // these permissions do not exist in overwrites. + continue; + } + + if (!!(this.allow & Permissions[permName])) { + allowed.push(permName); + } + } + return allowed; + } + + // returns an array of denied permissions + }, { + key: "denied", + get: function get() { + var denied = []; + for (var permName in Permissions) { + if (permName === "manageRoles" || permName === "manageChannels") { + // these permissions do not exist in overwrites. + continue; + } + + if (!!(this.deny & Permissions[permName])) { + denied.push(permName); + } + } + return denied; + } + }]); + + return PermissionOverwrite; +})(); + +module.exports = PermissionOverwrite; \ No newline at end of file diff --git a/lib/Structures/Role.js b/lib/Structures/Role.js index 1e9cb9a6a..048c183cb 100644 --- a/lib/Structures/Role.js +++ b/lib/Structures/Role.js @@ -1,4 +1,9 @@ -"use strict";function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var Permissions=require("../Constants.js").Permissions; /* +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var Permissions = require("../Constants.js").Permissions; +/* example data @@ -9,15 +14,126 @@ example data id: '110007368451915776', hoist: false, color: 0 } -*/var DefaultRole=[Permissions.createInstantInvite,Permissions.readMessages,Permissions.readMessageHistory,Permissions.sendMessages,Permissions.sendTTSMessages,Permissions.embedLinks,Permissions.attachFiles,Permissions.readMessageHistory,Permissions.mentionEveryone,Permissions.voiceConnect,Permissions.voiceSpeak,Permissions.voiceUseVAD].reduce(function(previous,current){return previous | current;},0);var Role=(function(){function Role(data,server,client){_classCallCheck(this,Role);this.position = data.position || -1;this.permissions = data.permissions || (data.name === "@everyone"?DefaultRole:0);this.name = data.name || "@everyone";this.managed = data.managed || false;this.id = data.id;this.hoist = data.hoist || false;this.color = data.color || 0;this.server = server;this.client = client;}Role.prototype.serialise = function serialise(explicit){var _this=this;var hp=function hp(perm){return _this.hasPermission(perm,explicit);};return { // general -createInstantInvite:hp(Permissions.createInstantInvite),kickMembers:hp(Permissions.kickMembers),banMembers:hp(Permissions.banMembers),manageRoles:hp(Permissions.manageRoles),manageChannels:hp(Permissions.manageChannels),manageServer:hp(Permissions.manageServer), // text -readMessages:hp(Permissions.readMessages),sendMessages:hp(Permissions.sendMessages),sendTTSMessages:hp(Permissions.sendTTSMessages),manageMessages:hp(Permissions.manageMessages),embedLinks:hp(Permissions.embedLinks),attachFiles:hp(Permissions.attachFiles),readMessageHistory:hp(Permissions.readMessageHistory),mentionEveryone:hp(Permissions.mentionEveryone), // voice -voiceConnect:hp(Permissions.voiceConnect),voiceSpeak:hp(Permissions.voiceSpeak),voiceMuteMembers:hp(Permissions.voiceMuteMembers),voiceDeafenMembers:hp(Permissions.voiceDeafenMembers),voiceMoveMembers:hp(Permissions.voiceMoveMembers),voiceUseVAD:hp(Permissions.voiceUseVAD)};};Role.prototype.serialize = function serialize(){ // ;n; -return this.serialise();};Role.prototype.hasPermission = function hasPermission(perm){var explicit=arguments.length <= 1 || arguments[1] === undefined?false:arguments[1];if(perm instanceof String || typeof perm === "string"){perm = Permissions[perm];}if(!perm){return false;}if(!explicit){ // implicit permissions allowed -if(!!(this.permissions & Permissions.manageRoles)){ // manageRoles allowed, they have all permissions -return true;}} // e.g. -// !!(36953089 & Permissions.manageRoles) = not allowed to manage roles -// !!(36953089 & (1 << 21)) = voice speak allowed -return !!(this.permissions & perm);};Role.prototype.setPermission = function setPermission(permission,value){if(permission instanceof String || typeof permission === "string"){permission = Permissions[permission];}if(permission){ // valid permission -if(value){this.permissions |= permission;}else {this.permissions &= ~permission;}}};Role.prototype.setPermissions = function setPermissions(obj){var _this2=this;obj.forEach(function(value,permission){if(permission instanceof String || typeof permission === "string"){permission = Permissions[permission];}if(permission){ // valid permission -_this2.setPermission(permission,value);}});};Role.prototype.colorAsHex = function colorAsHex(){var val=this.color.toString();while(val.length < 6) {val = "0" + val;}return "#" + val;};return Role;})();module.exports = Role; +*/ + +var DefaultRole = [Permissions.createInstantInvite, Permissions.readMessages, Permissions.readMessageHistory, Permissions.sendMessages, Permissions.sendTTSMessages, Permissions.embedLinks, Permissions.attachFiles, Permissions.readMessageHistory, Permissions.mentionEveryone, Permissions.voiceConnect, Permissions.voiceSpeak, Permissions.voiceUseVAD].reduce(function (previous, current) { + return previous | current; +}, 0); + +var Role = (function () { + function Role(data, server, client) { + _classCallCheck(this, Role); + + this.position = data.position || -1; + this.permissions = data.permissions || (data.name === "@everyone" ? DefaultRole : 0); + this.name = data.name || "@everyone"; + this.managed = data.managed || false; + this.id = data.id; + this.hoist = data.hoist || false; + this.color = data.color || 0; + this.server = server; + this.client = client; + } + + Role.prototype.serialise = function serialise(explicit) { + var _this = this; + + var hp = function hp(perm) { + return _this.hasPermission(perm, explicit); + }; + + return { + // general + createInstantInvite: hp(Permissions.createInstantInvite), + kickMembers: hp(Permissions.kickMembers), + banMembers: hp(Permissions.banMembers), + manageRoles: hp(Permissions.manageRoles), + manageChannels: hp(Permissions.manageChannels), + manageServer: hp(Permissions.manageServer), + // text + readMessages: hp(Permissions.readMessages), + sendMessages: hp(Permissions.sendMessages), + sendTTSMessages: hp(Permissions.sendTTSMessages), + manageMessages: hp(Permissions.manageMessages), + embedLinks: hp(Permissions.embedLinks), + attachFiles: hp(Permissions.attachFiles), + readMessageHistory: hp(Permissions.readMessageHistory), + mentionEveryone: hp(Permissions.mentionEveryone), + // voice + voiceConnect: hp(Permissions.voiceConnect), + voiceSpeak: hp(Permissions.voiceSpeak), + voiceMuteMembers: hp(Permissions.voiceMuteMembers), + voiceDeafenMembers: hp(Permissions.voiceDeafenMembers), + voiceMoveMembers: hp(Permissions.voiceMoveMembers), + voiceUseVAD: hp(Permissions.voiceUseVAD) + }; + }; + + Role.prototype.serialize = function serialize() { + // ;n; + return this.serialise(); + }; + + Role.prototype.hasPermission = function hasPermission(perm) { + var explicit = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1]; + + if (perm instanceof String || typeof perm === "string") { + perm = Permissions[perm]; + } + if (!perm) { + return false; + } + if (!explicit) { + // implicit permissions allowed + if (!!(this.permissions & Permissions.manageRoles)) { + // manageRoles allowed, they have all permissions + return true; + } + } + // e.g. + // !!(36953089 & Permissions.manageRoles) = not allowed to manage roles + // !!(36953089 & (1 << 21)) = voice speak allowed + + return !!(this.permissions & perm); + }; + + Role.prototype.setPermission = function setPermission(permission, value) { + if (permission instanceof String || typeof permission === "string") { + permission = Permissions[permission]; + } + if (permission) { + // valid permission + if (value) { + this.permissions |= permission; + } else { + this.permissions &= ~permission; + } + } + }; + + Role.prototype.setPermissions = function setPermissions(obj) { + var _this2 = this; + + obj.forEach(function (value, permission) { + if (permission instanceof String || typeof permission === "string") { + permission = Permissions[permission]; + } + if (permission) { + // valid permission + _this2.setPermission(permission, value); + } + }); + }; + + Role.prototype.colorAsHex = function colorAsHex() { + var val = this.color.toString(); + while (val.length < 6) { + val = "0" + val; + } + return "#" + val; + }; + + return Role; +})(); + +module.exports = Role; \ No newline at end of file diff --git a/lib/Structures/Server.js b/lib/Structures/Server.js index 6aa8fd595..99ee3971a 100644 --- a/lib/Structures/Server.js +++ b/lib/Structures/Server.js @@ -1 +1,169 @@ -"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _inherits(subClass,superClass){if(typeof superClass !== "function" && superClass !== null){throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__ = superClass;}var Equality=require("../Util/Equality.js");var Endpoints=require("../Constants.js").Endpoints;var Cache=require("../Util/Cache.js");var User=require("./User.js");var TextChannel=require("./TextChannel.js");var VoiceChannel=require("./VoiceChannel.js");var Role=require("./Role.js");var strictKeys=["region","ownerID","name","id","icon","afkTimeout","afkChannelID"];var Server=(function(_Equality){_inherits(Server,_Equality);function Server(data,client){var _this=this;_classCallCheck(this,Server);_Equality.call(this);var self=this;this.client = client;this.region = data.region;this.ownerID = data.owner_id;this.name = data.name;this.id = data.id;this.members = new Cache();this.channels = new Cache();this.roles = new Cache();this.icon = data.icon;this.afkTimeout = data.afkTimeout;this.afkChannelID = data.afk_channel_id;this.memberMap = {};var self=this;data.roles.forEach(function(dataRole){_this.roles.add(new Role(dataRole,_this,client));});data.members.forEach(function(dataUser){_this.memberMap[dataUser.user.id] = {roles:dataUser.roles.map(function(pid){return self.roles.get("id",pid);}),mute:dataUser.mute,deaf:dataUser.deaf,joinedAt:Date.parse(dataUser.joined_at)};var user=client.internal.users.add(new User(dataUser.user,client));_this.members.add(user);});data.channels.forEach(function(dataChannel){if(dataChannel.type === "text"){var channel=client.internal.channels.add(new TextChannel(dataChannel,client,_this));_this.channels.add(channel);}else {var channel=client.internal.channels.add(new VoiceChannel(dataChannel,client,_this));_this.channels.add(channel);}});if(data.presences){for(var _iterator=data.presences,_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 presence=_ref;var user=client.internal.users.get("id",presence.user.id);if(user){user.status = presence.status;user.gameID = presence.game_id;}}}}Server.prototype.rolesOfUser = function rolesOfUser(user){user = this.client.internal.resolver.resolveUser(user);if(user){return this.memberMap[user.id]?this.memberMap[user.id].roles:[];}else {return null;}};Server.prototype.rolesOf = function rolesOf(user){return this.rolesOfUser(user);};Server.prototype.toString = function toString(){return this.name;};Server.prototype.equalsStrict = function equalsStrict(obj){if(obj instanceof Server){for(var _iterator2=strictKeys,_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 key=_ref2;if(obj[key] !== this[key]){return false;}}}else {return false;}return true;};_createClass(Server,[{key:"iconURL",get:function get(){if(!this.icon){return null;}else {return Endpoints.SERVER_ICON(this.id,this.icon);}}},{key:"afkChannel",get:function get(){return this.channels.get("id",this.afkChannelID);}},{key:"defaultChannel",get:function get(){return this.channels.get("id",this.id);}},{key:"owner",get:function get(){return this.members.get("id",this.ownerID);}}]);return Server;})(Equality);module.exports = Server; +"use strict"; + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var Equality = require("../Util/Equality.js"); +var Endpoints = require("../Constants.js").Endpoints; +var Cache = require("../Util/Cache.js"); +var User = require("./User.js"); +var TextChannel = require("./TextChannel.js"); +var VoiceChannel = require("./VoiceChannel.js"); +var Role = require("./Role.js"); + +var strictKeys = ["region", "ownerID", "name", "id", "icon", "afkTimeout", "afkChannelID"]; + +var Server = (function (_Equality) { + _inherits(Server, _Equality); + + function Server(data, client) { + var _this = this; + + _classCallCheck(this, Server); + + _Equality.call(this); + + var self = this; + this.client = client; + + this.region = data.region; + this.ownerID = data.owner_id; + this.name = data.name; + this.id = data.id; + this.members = new Cache(); + this.channels = new Cache(); + this.roles = new Cache(); + this.icon = data.icon; + this.afkTimeout = data.afkTimeout; + this.afkChannelID = data.afk_channel_id; + this.memberMap = {}; + + var self = this; + + data.roles.forEach(function (dataRole) { + _this.roles.add(new Role(dataRole, _this, client)); + }); + + data.members.forEach(function (dataUser) { + _this.memberMap[dataUser.user.id] = { + roles: dataUser.roles.map(function (pid) { + return self.roles.get("id", pid); + }), + mute: dataUser.mute, + deaf: dataUser.deaf, + joinedAt: Date.parse(dataUser.joined_at) + }; + var user = client.internal.users.add(new User(dataUser.user, client)); + _this.members.add(user); + }); + + data.channels.forEach(function (dataChannel) { + if (dataChannel.type === "text") { + var channel = client.internal.channels.add(new TextChannel(dataChannel, client, _this)); + _this.channels.add(channel); + } else { + var channel = client.internal.channels.add(new VoiceChannel(dataChannel, client, _this)); + _this.channels.add(channel); + } + }); + + if (data.presences) { + for (var _iterator = data.presences, _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 presence = _ref; + + var user = client.internal.users.get("id", presence.user.id); + if (user) { + user.status = presence.status; + user.gameID = presence.game_id; + } + } + } + } + + Server.prototype.rolesOfUser = function rolesOfUser(user) { + user = this.client.internal.resolver.resolveUser(user); + if (user) { + return this.memberMap[user.id] ? this.memberMap[user.id].roles : []; + } else { + return null; + } + }; + + Server.prototype.rolesOf = function rolesOf(user) { + return this.rolesOfUser(user); + }; + + Server.prototype.toString = function toString() { + return this.name; + }; + + Server.prototype.equalsStrict = function equalsStrict(obj) { + if (obj instanceof Server) { + for (var _iterator2 = strictKeys, _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 key = _ref2; + + if (obj[key] !== this[key]) { + return false; + } + } + } else { + return false; + } + return true; + }; + + _createClass(Server, [{ + key: "iconURL", + get: function get() { + if (!this.icon) { + return null; + } else { + return Endpoints.SERVER_ICON(this.id, this.icon); + } + } + }, { + key: "afkChannel", + get: function get() { + return this.channels.get("id", this.afkChannelID); + } + }, { + key: "defaultChannel", + get: function get() { + return this.channels.get("id", this.id); + } + }, { + key: "owner", + get: function get() { + return this.members.get("id", this.ownerID); + } + }]); + + return Server; +})(Equality); + +module.exports = Server; \ No newline at end of file diff --git a/lib/Structures/ServerChannel.js b/lib/Structures/ServerChannel.js index 6f7a96caf..0349d33f9 100644 --- a/lib/Structures/ServerChannel.js +++ b/lib/Structures/ServerChannel.js @@ -1 +1,117 @@ -"use strict";function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _inherits(subClass,superClass){if(typeof superClass !== "function" && superClass !== null){throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__ = superClass;}var Channel=require("./Channel.js");var Cache=require("../Util/Cache.js");var PermissionOverwrite=require("./PermissionOverwrite.js");var ChannelPermissions=require("./ChannelPermissions.js");var reg=require("../Util/ArgumentRegulariser.js").reg;var ServerChannel=(function(_Channel){_inherits(ServerChannel,_Channel);function ServerChannel(data,client,server){var _this=this;_classCallCheck(this,ServerChannel);_Channel.call(this,data,client);this.name = data.name;this.type = data.type;this.position = data.position;this.permissionOverwrites = new Cache();this.server = server;data.permission_overwrites.forEach(function(permission){_this.permissionOverwrites.add(new PermissionOverwrite(permission));});}ServerChannel.prototype.permissionsOf = function permissionsOf(user){user = this.client.internal.resolver.resolveUser(user);if(user){if(this.server.owner.equals(user)){return new ChannelPermissions(4294967295);}var everyoneRole=this.server.roles.get("name","@everyone");var userRoles=[everyoneRole].concat(this.server.rolesOf(user) || []);var userRolesID=userRoles.map(function(v){return v.id;});var roleOverwrites=[],memberOverwrites=[];this.permissionOverwrites.forEach(function(overwrite){if(overwrite.type === "member" && overwrite.id === user.id){memberOverwrites.push(overwrite);}else if(overwrite.type === "role" && overwrite.id in userRolesID){roleOverwrites.push(overwrite);}});var permissions=0;for(var _iterator=userRoles,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var serverRole=_ref;permissions |= serverRole.permissions;}for(var _iterator2=roleOverwrites.concat(memberOverwrites),_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var overwrite=_ref2;permissions = permissions & ~overwrite.deny;permissions = permissions | overwrite.allow;}return new ChannelPermissions(permissions);}else {return null;}};ServerChannel.prototype.permsOf = function permsOf(user){return this.permissionsOf(user);};ServerChannel.prototype.mention = function mention(){return "<#" + this.id + ">";};ServerChannel.prototype.toString = function toString(){return this.mention();};ServerChannel.prototype.setName = function setName(){return this.client.setChannelName.apply(this.client,reg(this,arguments));};return ServerChannel;})(Channel);module.exports = ServerChannel; +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var Channel = require("./Channel.js"); +var Cache = require("../Util/Cache.js"); +var PermissionOverwrite = require("./PermissionOverwrite.js"); +var ChannelPermissions = require("./ChannelPermissions.js"); +var reg = require("../Util/ArgumentRegulariser.js").reg; + +var ServerChannel = (function (_Channel) { + _inherits(ServerChannel, _Channel); + + function ServerChannel(data, client, server) { + var _this = this; + + _classCallCheck(this, ServerChannel); + + _Channel.call(this, data, client); + this.name = data.name; + this.type = data.type; + this.position = data.position; + this.permissionOverwrites = new Cache(); + this.server = server; + data.permission_overwrites.forEach(function (permission) { + _this.permissionOverwrites.add(new PermissionOverwrite(permission)); + }); + } + + ServerChannel.prototype.permissionsOf = function permissionsOf(user) { + user = this.client.internal.resolver.resolveUser(user); + if (user) { + if (this.server.owner.equals(user)) { + return new ChannelPermissions(4294967295); + } + var everyoneRole = this.server.roles.get("name", "@everyone"); + + var userRoles = [everyoneRole].concat(this.server.rolesOf(user) || []); + var userRolesID = userRoles.map(function (v) { + return v.id; + }); + var roleOverwrites = [], + memberOverwrites = []; + + this.permissionOverwrites.forEach(function (overwrite) { + if (overwrite.type === "member" && overwrite.id === user.id) { + memberOverwrites.push(overwrite); + } else if (overwrite.type === "role" && overwrite.id in userRolesID) { + roleOverwrites.push(overwrite); + } + }); + + var permissions = 0; + + for (var _iterator = userRoles, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + var serverRole = _ref; + + permissions |= serverRole.permissions; + } + + for (var _iterator2 = roleOverwrites.concat(memberOverwrites), _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { + var _ref2; + + if (_isArray2) { + if (_i2 >= _iterator2.length) break; + _ref2 = _iterator2[_i2++]; + } else { + _i2 = _iterator2.next(); + if (_i2.done) break; + _ref2 = _i2.value; + } + + var overwrite = _ref2; + + permissions = permissions & ~overwrite.deny; + permissions = permissions | overwrite.allow; + } + + return new ChannelPermissions(permissions); + } else { + return null; + } + }; + + ServerChannel.prototype.permsOf = function permsOf(user) { + return this.permissionsOf(user); + }; + + ServerChannel.prototype.mention = function mention() { + return "<#" + this.id + ">"; + }; + + ServerChannel.prototype.toString = function toString() { + return this.mention(); + }; + + ServerChannel.prototype.setName = function setName() { + return this.client.setChannelName.apply(this.client, reg(this, arguments)); + }; + + return ServerChannel; +})(Channel); + +module.exports = ServerChannel; \ No newline at end of file diff --git a/lib/Structures/TextChannel.js b/lib/Structures/TextChannel.js index 2804182d0..181d20354 100644 --- a/lib/Structures/TextChannel.js +++ b/lib/Structures/TextChannel.js @@ -1 +1,58 @@ -"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _inherits(subClass,superClass){if(typeof superClass !== "function" && superClass !== null){throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__ = superClass;}var ServerChannel=require("./ServerChannel.js");var Cache=require("../Util/Cache.js");var reg=require("../Util/ArgumentRegulariser.js").reg;var TextChannel=(function(_ServerChannel){_inherits(TextChannel,_ServerChannel);function TextChannel(data,client,server){_classCallCheck(this,TextChannel);_ServerChannel.call(this,data,client,server);this.topic = data.topic;this.lastMessageID = data.last_message_id;this.messages = new Cache("id",client.options.maximumMessages);} /* warning! may return null */TextChannel.prototype.setTopic = function setTopic(){return this.client.setTopic.apply(this.client,reg(this,arguments));};TextChannel.prototype.setNameAndTopic = function setNameAndTopic(){return this.client.setChannelNameAndTopic.apply(this.client,reg(this,arguments));};TextChannel.prototype.update = function update(){return this.client.updateChannel.apply(this.client,reg(this,arguments));};TextChannel.prototype.sendMessage = function sendMessage(){return this.client.sendMessage.apply(this.client,reg(this,arguments));};TextChannel.prototype.sendTTSMessage = function sendTTSMessage(){return this.client.sendTTSMessage.apply(this.client,reg(this,arguments));};_createClass(TextChannel,[{key:"lastMessage",get:function get(){return this.messages.get("id",this.lastMessageID);}}]);return TextChannel;})(ServerChannel);module.exports = TextChannel; +"use strict"; + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var ServerChannel = require("./ServerChannel.js"); +var Cache = require("../Util/Cache.js"); +var reg = require("../Util/ArgumentRegulariser.js").reg; + +var TextChannel = (function (_ServerChannel) { + _inherits(TextChannel, _ServerChannel); + + function TextChannel(data, client, server) { + _classCallCheck(this, TextChannel); + + _ServerChannel.call(this, data, client, server); + + this.topic = data.topic; + this.lastMessageID = data.last_message_id; + this.messages = new Cache("id", client.options.maximumMessages); + } + + /* warning! may return null */ + + TextChannel.prototype.setTopic = function setTopic() { + return this.client.setTopic.apply(this.client, reg(this, arguments)); + }; + + TextChannel.prototype.setNameAndTopic = function setNameAndTopic() { + return this.client.setChannelNameAndTopic.apply(this.client, reg(this, arguments)); + }; + + TextChannel.prototype.update = function update() { + return this.client.updateChannel.apply(this.client, reg(this, arguments)); + }; + + TextChannel.prototype.sendMessage = function sendMessage() { + return this.client.sendMessage.apply(this.client, reg(this, arguments)); + }; + + TextChannel.prototype.sendTTSMessage = function sendTTSMessage() { + return this.client.sendTTSMessage.apply(this.client, reg(this, arguments)); + }; + + _createClass(TextChannel, [{ + key: "lastMessage", + get: function get() { + return this.messages.get("id", this.lastMessageID); + } + }]); + + return TextChannel; +})(ServerChannel); + +module.exports = TextChannel; \ No newline at end of file diff --git a/lib/Structures/User.js b/lib/Structures/User.js index c62791033..3815089ee 100644 --- a/lib/Structures/User.js +++ b/lib/Structures/User.js @@ -1 +1,58 @@ -"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _inherits(subClass,superClass){if(typeof superClass !== "function" && superClass !== null){throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__ = superClass;}var Equality=require("../Util/Equality.js");var Endpoints=require("../Constants.js").Endpoints;var User=(function(_Equality){_inherits(User,_Equality);function User(data,client){_classCallCheck(this,User);_Equality.call(this);this.client = client;this.username = data.username;this.discriminator = data.discriminator;this.id = data.id;this.avatar = data.avatar;this.status = data.status || "offline";this.gameID = data.game_id || null;this.typing = {since:null,channel:null};}User.prototype.mention = function mention(){return "<@" + this.id + ">";};User.prototype.toString = function toString(){return this.mention();};User.prototype.equalsStrict = function equalsStrict(obj){if(obj instanceof User)return this.id === obj.id && this.username === obj.username && this.discriminator === obj.discriminator && this.avatar === obj.avatar && this.status === obj.status && this.gameID === obj.gameID;else return false;};_createClass(User,[{key:"avatarURL",get:function get(){if(!this.avatar){return null;}else {return Endpoints.AVATAR(this.id,this.avatar);}}}]);return User;})(Equality);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"); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var Equality = require("../Util/Equality.js"); +var Endpoints = require("../Constants.js").Endpoints; + +var User = (function (_Equality) { + _inherits(User, _Equality); + + function User(data, client) { + _classCallCheck(this, User); + + _Equality.call(this); + this.client = client; + this.username = data.username; + this.discriminator = data.discriminator; + this.id = data.id; + this.avatar = data.avatar; + this.status = data.status || "offline"; + this.gameID = data.game_id || null; + this.typing = { + since: null, + channel: null + }; + } + + User.prototype.mention = function mention() { + return "<@" + this.id + ">"; + }; + + User.prototype.toString = function toString() { + return this.mention(); + }; + + User.prototype.equalsStrict = function equalsStrict(obj) { + if (obj instanceof User) return this.id === obj.id && this.username === obj.username && this.discriminator === obj.discriminator && this.avatar === obj.avatar && this.status === obj.status && this.gameID === obj.gameID;else return false; + }; + + _createClass(User, [{ + key: "avatarURL", + get: function get() { + if (!this.avatar) { + return null; + } else { + return Endpoints.AVATAR(this.id, this.avatar); + } + } + }]); + + return User; +})(Equality); + +module.exports = User; \ No newline at end of file diff --git a/lib/Structures/VoiceChannel.js b/lib/Structures/VoiceChannel.js index 0de07566f..333786b58 100644 --- a/lib/Structures/VoiceChannel.js +++ b/lib/Structures/VoiceChannel.js @@ -1 +1,21 @@ -"use strict";function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _inherits(subClass,superClass){if(typeof superClass !== "function" && superClass !== null){throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__ = superClass;}var ServerChannel=require("./ServerChannel.js");var VoiceChannel=(function(_ServerChannel){_inherits(VoiceChannel,_ServerChannel);function VoiceChannel(data,client,server){_classCallCheck(this,VoiceChannel);_ServerChannel.call(this,data,client,server);}return VoiceChannel;})(ServerChannel);module.exports = VoiceChannel; +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var ServerChannel = require("./ServerChannel.js"); + +var VoiceChannel = (function (_ServerChannel) { + _inherits(VoiceChannel, _ServerChannel); + + function VoiceChannel(data, client, server) { + _classCallCheck(this, VoiceChannel); + + _ServerChannel.call(this, data, client, server); + } + + return VoiceChannel; +})(ServerChannel); + +module.exports = VoiceChannel; \ No newline at end of file diff --git a/lib/Util/ArgumentRegulariser.js b/lib/Util/ArgumentRegulariser.js index 7feac0b68..9c98ddb39 100644 --- a/lib/Util/ArgumentRegulariser.js +++ b/lib/Util/ArgumentRegulariser.js @@ -1 +1,5 @@ -"use strict";exports.reg = function(c,a){return [c].concat(Array.prototype.slice.call(a));}; +"use strict"; + +exports.reg = function (c, a) { + return [c].concat(Array.prototype.slice.call(a)); +}; \ No newline at end of file diff --git a/lib/Util/Cache.js b/lib/Util/Cache.js index 7b6930466..b0d5f51c0 100644 --- a/lib/Util/Cache.js +++ b/lib/Util/Cache.js @@ -1 +1,102 @@ -"use strict";function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _inherits(subClass,superClass){if(typeof superClass !== "function" && superClass !== null){throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__ = superClass;}var Cache=(function(_Array){_inherits(Cache,_Array);function Cache(discrim,limit){_classCallCheck(this,Cache);_Array.call(this);this.discrim = discrim || "id";}Cache.prototype.get = function get(key,value){var found=null;this.forEach(function(val,index,array){if(val.hasOwnProperty(key) && val[key] == value){found = val;return;}});return found;};Cache.prototype.has = function has(key,value){return !!this.get(key,value);};Cache.prototype.getAll = function getAll(key,value){var found=new Cache(this.discrim);this.forEach(function(val,index,array){if(val.hasOwnProperty(key) && val[key] == value){found.push(val);return;}});return found;};Cache.prototype.add = function add(data){var exit=false;for(var _iterator=this,_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 item=_ref;if(item[this.discrim] === data[this.discrim]){exit = item;break;}}if(exit){return exit;}else {if(this.limit && this.length >= this.limit){this.splice(0,1);}this.push(data);return data;}};Cache.prototype.update = function update(old,data){var item=this.get(this.discrim,old[this.discrim]);if(item){var index=this.indexOf(item);this[index] = data;return this[index];}else {return false;}};Cache.prototype.remove = function remove(data){var index=this.indexOf(data);if(~index){this.splice(index,1);}else {var item=this.get(this.discrim,data[this.discrim]);if(item){this.splice(this.indexOf(item),1);}}return false;};return Cache;})(Array);module.exports = Cache; +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var Cache = (function (_Array) { + _inherits(Cache, _Array); + + function Cache(discrim, limit) { + _classCallCheck(this, Cache); + + _Array.call(this); + this.discrim = discrim || "id"; + } + + Cache.prototype.get = function get(key, value) { + var found = null; + this.forEach(function (val, index, array) { + if (val.hasOwnProperty(key) && val[key] == value) { + found = val; + return; + } + }); + return found; + }; + + Cache.prototype.has = function has(key, value) { + return !!this.get(key, value); + }; + + Cache.prototype.getAll = function getAll(key, value) { + var found = new Cache(this.discrim); + this.forEach(function (val, index, array) { + if (val.hasOwnProperty(key) && val[key] == value) { + found.push(val); + return; + } + }); + return found; + }; + + Cache.prototype.add = function add(data) { + var exit = false; + for (var _iterator = this, _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 item = _ref; + + if (item[this.discrim] === data[this.discrim]) { + exit = item; + break; + } + } + if (exit) { + return exit; + } else { + if (this.limit && this.length >= this.limit) { + this.splice(0, 1); + } + this.push(data); + return data; + } + }; + + Cache.prototype.update = function update(old, data) { + var item = this.get(this.discrim, old[this.discrim]); + if (item) { + var index = this.indexOf(item); + this[index] = data; + return this[index]; + } else { + return false; + } + }; + + Cache.prototype.remove = function remove(data) { + var index = this.indexOf(data); + if (~index) { + this.splice(index, 1); + } else { + var item = this.get(this.discrim, data[this.discrim]); + if (item) { + this.splice(this.indexOf(item), 1); + } + } + return false; + }; + + return Cache; +})(Array); + +module.exports = Cache; \ No newline at end of file diff --git a/lib/Util/Equality.js b/lib/Util/Equality.js index 73591741b..3288d530a 100644 --- a/lib/Util/Equality.js +++ b/lib/Util/Equality.js @@ -8,5 +8,38 @@ instances sometimes. Instead, use objectThatExtendsEquality.equals() -*/"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var Equality=(function(){function Equality(){_classCallCheck(this,Equality);}Equality.prototype.equals = function equals(object){if(object && object[this.eqDiscriminator] == this[this.eqDiscriminator]){return true;}return false;};Equality.prototype.equalsStrict = function equalsStrict(object){ // override per class type -return;};_createClass(Equality,[{key:"eqDiscriminator",get:function get(){return "id";}}]);return Equality;})();module.exports = Equality; +*/ +"use strict"; + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var Equality = (function () { + function Equality() { + _classCallCheck(this, Equality); + } + + Equality.prototype.equals = function equals(object) { + if (object && object[this.eqDiscriminator] == this[this.eqDiscriminator]) { + return true; + } + return false; + }; + + Equality.prototype.equalsStrict = function equalsStrict(object) { + // override per class type + return; + }; + + _createClass(Equality, [{ + key: "eqDiscriminator", + get: function get() { + return "id"; + } + }]); + + return Equality; +})(); + +module.exports = Equality; \ No newline at end of file diff --git a/lib/Voice/AudioEncoder.js b/lib/Voice/AudioEncoder.js index d8edf8b43..517a7cf68 100644 --- a/lib/Voice/AudioEncoder.js +++ b/lib/Voice/AudioEncoder.js @@ -1,4 +1,129 @@ -"use strict";function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var cpoc=require("child_process");var opus;try{opus = require("node-opus");}catch(e) { // no opus! -}var VoicePacket=require("./VoicePacket.js");var AudioEncoder=(function(){function AudioEncoder(){_classCallCheck(this,AudioEncoder);if(opus){this.opus = new opus.OpusEncoder(48000,1);}this.choice = false;}AudioEncoder.prototype.opusBuffer = function opusBuffer(buffer){return this.opus.encode(buffer,1920);};AudioEncoder.prototype.getCommand = function getCommand(force){if(this.choice && force)return choice;var choices=["avconv","ffmpeg"];for(var _iterator=choices,_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 choice=_ref;var p=cpoc.spawnSync(choice);if(!p.error){this.choice = choice;return choice;}}return "help";};AudioEncoder.prototype.encodeStream = function encodeStream(stream){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,buffer){}:arguments[1];var self=this;return new Promise(function(resolve,reject){var enc=cpoc.spawn(self.getCommand(),["-f","s16le","-ar","48000","-ac","1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth. -"-af","volume=1","pipe:1","-i","-"]);stream.pipe(enc.stdin);enc.stdout.once("readable",function(){callback(null,{proc:enc,stream:enc.stdout,instream:stream});resolve({proc:enc,stream:enc.stdout,instream:stream});});enc.stdout.on("end",function(){callback("end");reject("end");});enc.stdout.on("close",function(){callback("close");reject("close");});});};AudioEncoder.prototype.encodeFile = function encodeFile(file){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,buffer){}:arguments[1];var self=this;return new Promise(function(resolve,reject){var enc=cpoc.spawn(self.getCommand(),["-f","s16le","-ar","48000","-ac","1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth. -"-af","volume=1","pipe:1","-i",file]);enc.stdout.once("readable",function(){callback(null,{proc:enc,stream:enc.stdout});resolve({proc:enc,stream:enc.stdout});});enc.stdout.on("end",function(){callback("end");reject("end");});enc.stdout.on("close",function(){callback("close");reject("close");});});};return AudioEncoder;})();module.exports = AudioEncoder; +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var cpoc = require("child_process"); + +var opus; +try { + opus = require("node-opus"); +} catch (e) { + // no opus! +} +var VoicePacket = require("./VoicePacket.js"); + +var AudioEncoder = (function () { + function AudioEncoder() { + _classCallCheck(this, AudioEncoder); + + if (opus) { + this.opus = new opus.OpusEncoder(48000, 1); + } + this.choice = false; + } + + AudioEncoder.prototype.opusBuffer = function opusBuffer(buffer) { + + return this.opus.encode(buffer, 1920); + }; + + AudioEncoder.prototype.getCommand = function getCommand(force) { + + if (this.choice && force) return choice; + + var choices = ["avconv", "ffmpeg"]; + + for (var _iterator = choices, _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 choice = _ref; + + var p = cpoc.spawnSync(choice); + if (!p.error) { + this.choice = choice; + return choice; + } + } + + return "help"; + }; + + AudioEncoder.prototype.encodeStream = function encodeStream(stream) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, buffer) {} : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + var enc = cpoc.spawn(self.getCommand(), ["-f", "s16le", "-ar", "48000", "-ac", "1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth. + "-af", "volume=1", "pipe:1", "-i", "-"]); + + stream.pipe(enc.stdin); + + enc.stdout.once("readable", function () { + callback(null, { + proc: enc, + stream: enc.stdout, + instream: stream + }); + resolve({ + proc: enc, + stream: enc.stdout, + instream: stream + }); + }); + + enc.stdout.on("end", function () { + callback("end"); + reject("end"); + }); + + enc.stdout.on("close", function () { + callback("close"); + reject("close"); + }); + }); + }; + + AudioEncoder.prototype.encodeFile = function encodeFile(file) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, buffer) {} : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + var enc = cpoc.spawn(self.getCommand(), ["-f", "s16le", "-ar", "48000", "-ac", "1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth. + "-af", "volume=1", "pipe:1", "-i", file]); + + enc.stdout.once("readable", function () { + callback(null, { + proc: enc, + stream: enc.stdout + }); + resolve({ + proc: enc, + stream: enc.stdout + }); + }); + + enc.stdout.on("end", function () { + callback("end"); + reject("end"); + }); + + enc.stdout.on("close", function () { + callback("close"); + reject("close"); + }); + }); + }; + + return AudioEncoder; +})(); + +module.exports = AudioEncoder; \ No newline at end of file diff --git a/lib/Voice/StreamIntent.js b/lib/Voice/StreamIntent.js index 5d4140d09..97953194c 100644 --- a/lib/Voice/StreamIntent.js +++ b/lib/Voice/StreamIntent.js @@ -1,2 +1,22 @@ -"use strict"; // represents an intent of streaming music -function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _inherits(subClass,superClass){if(typeof superClass !== "function" && superClass !== null){throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__ = superClass;}var EventEmitter=require("events");var StreamIntent=(function(_EventEmitter){_inherits(StreamIntent,_EventEmitter);function StreamIntent(){_classCallCheck(this,StreamIntent);_EventEmitter.call(this);}return StreamIntent;})(EventEmitter);module.exports = StreamIntent; +"use strict"; +// represents an intent of streaming music + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var EventEmitter = require("events"); + +var StreamIntent = (function (_EventEmitter) { + _inherits(StreamIntent, _EventEmitter); + + function StreamIntent() { + _classCallCheck(this, StreamIntent); + + _EventEmitter.call(this); + } + + return StreamIntent; +})(EventEmitter); + +module.exports = StreamIntent; \ No newline at end of file diff --git a/lib/Voice/VoiceConnection.js b/lib/Voice/VoiceConnection.js index 227cc58da..4dee53b15 100644 --- a/lib/Voice/VoiceConnection.js +++ b/lib/Voice/VoiceConnection.js @@ -1,11 +1,332 @@ -"use strict"; /* +"use strict"; +/* Major credit to izy521 who is the creator of https://github.com/izy521/discord.io, without his help voice chat in discord.js would not have been possible! -*/function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _inherits(subClass,superClass){if(typeof superClass !== "function" && superClass !== null){throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__ = superClass;}var WebSocket=require("ws");var dns=require("dns");var udp=require("dgram");var fs=require("fs");var AudioEncoder=require("./AudioEncoder.js");var VoicePacket=require("./VoicePacket.js");var StreamIntent=require("./StreamIntent.js");var EventEmitter=require("events");var VoiceConnection=(function(_EventEmitter){_inherits(VoiceConnection,_EventEmitter);function VoiceConnection(channel,client,session,token,server,endpoint){_classCallCheck(this,VoiceConnection);_EventEmitter.call(this);this.id = channel.id;this.voiceChannel = channel;this.client = client;this.session = session;this.token = token;this.server = server;this.endpoint = endpoint.replace(":80","");this.vWS = null; // vWS means voice websocket -this.ready = false;this.vWSData = {};this.encoder = new AudioEncoder();this.udp = null;this.playingIntent = null;this.playing = false;this.streamTime = 0;this.streamProc = null;this.KAI = null;this.init();}VoiceConnection.prototype.destroy = function destroy(){this.stopPlaying();if(this.KAI)clearInterval(this.KAI);this.vWS.close();this.udp.close();this.client.internal.sendWS({op:4,d:{guild_id:null,channel_id:null,self_mute:true,self_deaf:false}});};VoiceConnection.prototype.stopPlaying = function stopPlaying(){this.playing = false;this.playingIntent = null;if(this.instream){this.instream.end();this.instream.destroy();}};VoiceConnection.prototype.playStream = function playStream(stream){var self=this;var startTime=Date.now();var sequence=0;var time=0;var count=0;var length=20;if(self.playingIntent){self.stopPlaying();}self.playing = true;var retStream=new StreamIntent();var onWarning=false;self.playingIntent = retStream;function send(){if(!self.playingIntent || !self.playing){self.setSpeaking(false);retStream.emit("end");self;return;}try{var buffer=stream.read(1920);if(!buffer){setTimeout(send,length * 10); // give chance for some data in 200ms to appear -return;}if(buffer.length !== 1920){if(onWarning){retStream.emit("end");stream.destroy();self.setSpeaking(false);return;}else {onWarning = true;setTimeout(send,length * 10); // give chance for some data in 200ms to appear -return;}}count++;sequence + 10 < 65535?sequence += 1:sequence = 0;time + 9600 < 4294967295?time += 960:time = 0;self.sendBuffer(buffer,sequence,time,function(e){});var nextTime=startTime + count * length;self.streamTime = count * length;setTimeout(send,length + (nextTime - Date.now()));if(!self.playing)self.setSpeaking(true);retStream.emit("time",self.streamTime);}catch(e) {retStream.emit("error",e);}}self.setSpeaking(true);send();return retStream;};VoiceConnection.prototype.setSpeaking = function setSpeaking(value){this.playing = value;if(this.vWS.readyState === WebSocket.OPEN)this.vWS.send(JSON.stringify({op:5,d:{speaking:value,delay:0}}));};VoiceConnection.prototype.sendPacket = function sendPacket(packet){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err){}:arguments[1];var self=this;self.playing = true;try{if(self.vWS.readyState === WebSocket.OPEN)self.udp.send(packet,0,packet.length,self.vWSData.port,self.endpoint,callback);}catch(e) {self.playing = false;callback(e);return false;}};VoiceConnection.prototype.sendBuffer = function sendBuffer(rawbuffer,sequence,timestamp,callback){var self=this;self.playing = true;try{if(!self.encoder.opus){self.playing = false;self.emit("error","No Opus!");self.client.emit("debug","Tried to use node-opus, but opus not available - install it!");return;}var buffer=self.encoder.opusBuffer(rawbuffer);var packet=new VoicePacket(buffer,sequence,timestamp,self.vWSData.ssrc);return self.sendPacket(packet,callback);}catch(e) {self.playing = false;self.emit("error",e);return false;}};VoiceConnection.prototype.test = function test(){this.playFile("C:/users/amish/desktop/audio.mp3").then(function(stream){stream.on("time",function(time){console.log("Time",time);});});};VoiceConnection.prototype.playFile = function playFile(stream){var _this=this;var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,str){}:arguments[1];var self=this;return new Promise(function(resolve,reject){_this.encoder.encodeFile(stream)["catch"](error).then(function(data){self.streamProc = data.proc;var intent=self.playStream(data.stream);resolve(intent);callback(null,intent);});function error(){var e=arguments.length <= 0 || arguments[0] === undefined?true:arguments[0];reject(e);callback(e);}});};VoiceConnection.prototype.playRawStream = function playRawStream(stream){var _this2=this;var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,str){}:arguments[1];var self=this;return new Promise(function(resolve,reject){_this2.encoder.encodeStream(stream)["catch"](error).then(function(data){self.streamProc = data.proc;self.instream = data.instream;var intent=self.playStream(data.stream);resolve(intent);callback(null,intent);});function error(){var e=arguments.length <= 0 || arguments[0] === undefined?true:arguments[0];reject(e);callback(e);}});};VoiceConnection.prototype.init = function init(){var _this3=this;var self=this;dns.lookup(this.endpoint,function(err,address,family){self.endpoint = address;var vWS=self.vWS = new WebSocket("wss://" + _this3.endpoint,null,{rejectUnauthorized:false});var udpClient=self.udp = udp.createSocket("udp4");var firstPacket=true;var discordIP="",discordPort="";udpClient.bind({exclusive:true});udpClient.on('message',function(msg,rinfo){var buffArr=JSON.parse(JSON.stringify(msg)).data;if(firstPacket === true){for(var i=4;i < buffArr.indexOf(0,i);i++) {discordIP += String.fromCharCode(buffArr[i]);}discordPort = msg.readUIntLE(msg.length - 2,2).toString(10);var wsDiscPayload={"op":1,"d":{"protocol":"udp","data":{"address":discordIP,"port":Number(discordPort),"mode":self.vWSData.modes[0] //Plain -}}};vWS.send(JSON.stringify(wsDiscPayload));firstPacket = false;}});vWS.on("open",function(){vWS.send(JSON.stringify({op:0,d:{server_id:self.server.id,user_id:self.client.internal.user.id,session_id:self.session,token:self.token}}));});var KAI;vWS.on("message",function(msg){var data=JSON.parse(msg);switch(data.op){case 2:self.vWSData = data.d;KAI = setInterval(function(){if(vWS && vWS.readyState === WebSocket.OPEN)vWS.send(JSON.stringify({op:3,d:null}));},data.d.heartbeat_interval);self.KAI = KAI;var udpPacket=new Buffer(70);udpPacket.writeUIntBE(data.d.ssrc,0,4);udpClient.send(udpPacket,0,udpPacket.length,data.d.port,self.endpoint,function(err){if(err)self.emit("error",err);});break;case 4:self.ready = true;self.mode = data.d.mode;self.emit("ready",self);break;}});});};return VoiceConnection;})(EventEmitter);module.exports = VoiceConnection; +*/ + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var WebSocket = require("ws"); +var dns = require("dns"); +var udp = require("dgram"); +var fs = require("fs"); +var AudioEncoder = require("./AudioEncoder.js"); +var VoicePacket = require("./VoicePacket.js"); +var StreamIntent = require("./StreamIntent.js"); +var EventEmitter = require("events"); + +var VoiceConnection = (function (_EventEmitter) { + _inherits(VoiceConnection, _EventEmitter); + + function VoiceConnection(channel, client, session, token, server, endpoint) { + _classCallCheck(this, VoiceConnection); + + _EventEmitter.call(this); + this.id = channel.id; + this.voiceChannel = channel; + this.client = client; + this.session = session; + this.token = token; + this.server = server; + this.endpoint = endpoint.replace(":80", ""); + this.vWS = null; // vWS means voice websocket + this.ready = false; + this.vWSData = {}; + this.encoder = new AudioEncoder(); + this.udp = null; + this.playingIntent = null; + this.playing = false; + this.streamTime = 0; + this.streamProc = null; + this.KAI = null; + this.init(); + } + + VoiceConnection.prototype.destroy = function destroy() { + this.stopPlaying(); + if (this.KAI) clearInterval(this.KAI); + this.vWS.close(); + this.udp.close(); + this.client.internal.sendWS({ + op: 4, + d: { + guild_id: null, + channel_id: null, + self_mute: true, + self_deaf: false + } + }); + }; + + VoiceConnection.prototype.stopPlaying = function stopPlaying() { + this.playing = false; + this.playingIntent = null; + if (this.instream) { + this.instream.end(); + this.instream.destroy(); + } + }; + + VoiceConnection.prototype.playStream = function playStream(stream) { + + var self = this; + + var startTime = Date.now(); + var sequence = 0; + var time = 0; + var count = 0; + + var length = 20; + + if (self.playingIntent) { + self.stopPlaying(); + } + self.playing = true; + var retStream = new StreamIntent(); + var onWarning = false; + self.playingIntent = retStream; + + function send() { + + if (!self.playingIntent || !self.playing) { + self.setSpeaking(false); + retStream.emit("end"); + self; + return; + } + try { + var buffer = stream.read(1920); + if (!buffer) { + setTimeout(send, length * 10); // give chance for some data in 200ms to appear + return; + } + + if (buffer.length !== 1920) { + if (onWarning) { + retStream.emit("end"); + stream.destroy(); + self.setSpeaking(false); + return; + } else { + onWarning = true; + setTimeout(send, length * 10); // give chance for some data in 200ms to appear + return; + } + } + + count++; + sequence + 10 < 65535 ? sequence += 1 : sequence = 0; + time + 9600 < 4294967295 ? time += 960 : time = 0; + + self.sendBuffer(buffer, sequence, time, function (e) {}); + + var nextTime = startTime + count * length; + + self.streamTime = count * length; + + setTimeout(send, length + (nextTime - Date.now())); + if (!self.playing) self.setSpeaking(true); + + retStream.emit("time", self.streamTime); + } catch (e) { + retStream.emit("error", e); + } + } + self.setSpeaking(true); + send(); + + return retStream; + }; + + VoiceConnection.prototype.setSpeaking = function setSpeaking(value) { + this.playing = value; + if (this.vWS.readyState === WebSocket.OPEN) this.vWS.send(JSON.stringify({ + op: 5, + d: { + speaking: value, + delay: 0 + } + })); + }; + + VoiceConnection.prototype.sendPacket = function sendPacket(packet) { + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1]; + + var self = this; + self.playing = true; + try { + if (self.vWS.readyState === WebSocket.OPEN) self.udp.send(packet, 0, packet.length, self.vWSData.port, self.endpoint, callback); + } catch (e) { + self.playing = false; + callback(e); + return false; + } + }; + + VoiceConnection.prototype.sendBuffer = function sendBuffer(rawbuffer, sequence, timestamp, callback) { + var self = this; + self.playing = true; + try { + if (!self.encoder.opus) { + self.playing = false; + self.emit("error", "No Opus!"); + self.client.emit("debug", "Tried to use node-opus, but opus not available - install it!"); + return; + } + var buffer = self.encoder.opusBuffer(rawbuffer); + var packet = new VoicePacket(buffer, sequence, timestamp, self.vWSData.ssrc); + return self.sendPacket(packet, callback); + } catch (e) { + self.playing = false; + self.emit("error", e); + return false; + } + }; + + VoiceConnection.prototype.test = function test() { + this.playFile("C:/users/amish/desktop/audio.mp3").then(function (stream) { + stream.on("time", function (time) { + console.log("Time", time); + }); + }); + }; + + VoiceConnection.prototype.playFile = function playFile(stream) { + var _this = this; + + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, str) {} : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + _this.encoder.encodeFile(stream)["catch"](error).then(function (data) { + self.streamProc = data.proc; + var intent = self.playStream(data.stream); + resolve(intent); + callback(null, intent); + }); + function error() { + var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0]; + + reject(e); + callback(e); + } + }); + }; + + VoiceConnection.prototype.playRawStream = function playRawStream(stream) { + var _this2 = this; + + var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, str) {} : arguments[1]; + + var self = this; + return new Promise(function (resolve, reject) { + _this2.encoder.encodeStream(stream)["catch"](error).then(function (data) { + self.streamProc = data.proc; + self.instream = data.instream; + var intent = self.playStream(data.stream); + resolve(intent); + callback(null, intent); + }); + function error() { + var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0]; + + reject(e); + callback(e); + } + }); + }; + + VoiceConnection.prototype.init = function init() { + var _this3 = this; + + var self = this; + dns.lookup(this.endpoint, function (err, address, family) { + self.endpoint = address; + var vWS = self.vWS = new WebSocket("wss://" + _this3.endpoint, null, { rejectUnauthorized: false }); + var udpClient = self.udp = udp.createSocket("udp4"); + + var firstPacket = true; + + var discordIP = "", + discordPort = ""; + + udpClient.bind({ exclusive: true }); + udpClient.on('message', function (msg, rinfo) { + var buffArr = JSON.parse(JSON.stringify(msg)).data; + if (firstPacket === true) { + for (var i = 4; i < buffArr.indexOf(0, i); i++) { + discordIP += String.fromCharCode(buffArr[i]); + } + discordPort = msg.readUIntLE(msg.length - 2, 2).toString(10); + + var wsDiscPayload = { + "op": 1, + "d": { + "protocol": "udp", + "data": { + "address": discordIP, + "port": Number(discordPort), + "mode": self.vWSData.modes[0] //Plain + } + } + }; + vWS.send(JSON.stringify(wsDiscPayload)); + firstPacket = false; + } + }); + + vWS.on("open", function () { + vWS.send(JSON.stringify({ + op: 0, + d: { + server_id: self.server.id, + user_id: self.client.internal.user.id, + session_id: self.session, + token: self.token + } + })); + }); + + var KAI; + + vWS.on("message", function (msg) { + var data = JSON.parse(msg); + switch (data.op) { + case 2: + self.vWSData = data.d; + + KAI = setInterval(function () { + if (vWS && vWS.readyState === WebSocket.OPEN) vWS.send(JSON.stringify({ + op: 3, + d: null + })); + }, data.d.heartbeat_interval); + self.KAI = KAI; + + var udpPacket = new Buffer(70); + udpPacket.writeUIntBE(data.d.ssrc, 0, 4); + udpClient.send(udpPacket, 0, udpPacket.length, data.d.port, self.endpoint, function (err) { + if (err) self.emit("error", err); + }); + break; + case 4: + + self.ready = true; + self.mode = data.d.mode; + self.emit("ready", self); + + break; + } + }); + }); + }; + + return VoiceConnection; +})(EventEmitter); + +module.exports = VoiceConnection; \ No newline at end of file diff --git a/lib/Voice/VoicePacket.js b/lib/Voice/VoicePacket.js index e44204175..f432bf241 100644 --- a/lib/Voice/VoicePacket.js +++ b/lib/Voice/VoicePacket.js @@ -1 +1,26 @@ -"use strict";function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var VoicePacket=function VoicePacket(data,sequence,time,ssrc){_classCallCheck(this,VoicePacket);var audioBuffer=data,returnBuffer=new Buffer(audioBuffer.length + 12);returnBuffer.fill(0);returnBuffer[0] = 0x80;returnBuffer[1] = 0x78;returnBuffer.writeUIntBE(sequence,2,2);returnBuffer.writeUIntBE(time,4,4);returnBuffer.writeUIntBE(ssrc,8,4);for(var i=0;i < audioBuffer.length;i++) {returnBuffer[i + 12] = audioBuffer[i];}return returnBuffer;};module.exports = VoicePacket; +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var VoicePacket = function VoicePacket(data, sequence, time, ssrc) { + _classCallCheck(this, VoicePacket); + + var audioBuffer = data, + returnBuffer = new Buffer(audioBuffer.length + 12); + + returnBuffer.fill(0); + returnBuffer[0] = 0x80; + returnBuffer[1] = 0x78; + + returnBuffer.writeUIntBE(sequence, 2, 2); + returnBuffer.writeUIntBE(time, 4, 4); + returnBuffer.writeUIntBE(ssrc, 8, 4); + + for (var i = 0; i < audioBuffer.length; i++) { + returnBuffer[i + 12] = audioBuffer[i]; + } + + return returnBuffer; +}; + +module.exports = VoicePacket; \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index 14b76be38..29c9cc6a3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1 +1,18 @@ -"use strict";module.exports = {Client:require("./Client/Client"),Channel:require("./Structures/Channel"),ChannelPermissions:require("./Structures/ChannelPermissions"),Invite:require("./Structures/Invite"),Message:require("./Structures/Message"),PermissionOverwrite:require("./Structures/PermissionOverwrite"),PMChannel:require("./Structures/PMChannel"),Role:require("./Structures/Role"),Server:require("./Structures/Server"),ServerChannel:require("./Structures/ServerChannel"),TextChannel:require("./Structures/TextChannel"),User:require("./Structures/User"),VoiceChannel:require("./Structures/VoiceChannel"),Constants:require("./Constants.js")}; +"use strict"; + +module.exports = { + Client: require("./Client/Client"), + Channel: require("./Structures/Channel"), + ChannelPermissions: require("./Structures/ChannelPermissions"), + Invite: require("./Structures/Invite"), + Message: require("./Structures/Message"), + PermissionOverwrite: require("./Structures/PermissionOverwrite"), + PMChannel: require("./Structures/PMChannel"), + Role: require("./Structures/Role"), + Server: require("./Structures/Server"), + ServerChannel: require("./Structures/ServerChannel"), + TextChannel: require("./Structures/TextChannel"), + User: require("./Structures/User"), + VoiceChannel: require("./Structures/VoiceChannel"), + Constants: require("./Constants.js") +}; \ No newline at end of file diff --git a/ref/gameMap.js b/ref/gameMap.js new file mode 100644 index 000000000..d0a640759 --- /dev/null +++ b/ref/gameMap.js @@ -0,0 +1,5687 @@ +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", + "Gw2-64.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 Empires II" + }, + { + "executables": { + "win32": [ + "age3y.exe" + ] + }, + "id": 102, + "name": "Age of Empires 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": {}, + "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": { + "win32": [ + "cabal2main.exe" + ] + }, + "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", + "DARKSOULS.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", + "DXHRDC.exe" + ] + }, + "id": 148, + "name": "Deus Ex: Human Revolution" + }, + { + "executables": { + "win32": [ + "DeviMayCry4.exe", + "DevilMayCry4_DX9.exe", + "DevilMayCry4_DX10.exe", + "DevilMayCry4SpecialEdition.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": {}, + "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", + "MassEffect3.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": "PAYDAY 2" + }, + { + "executables": { + "win32": [ + "PillarsOfEternity.exe" + ] + }, + "id": 225, + "name": "Pillars of Eternity" + }, + { + "executables": { + "win32": [ + "PA.exe" + ] + }, + "id": 226, + "name": "Planetary Annihilation" + }, + { + "executables": { + "win32": [ + "planetside2_x86.exe", + "PlanetSide2_x64.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", + "OSBuddy.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", + "starwarsbattlefront.exe" + ] + }, + "id": 248, + "name": "Star Wars Battlefront" + }, + { + "executables": { + "win32": [ + "swtor.exe" + ] + }, + "id": 249, + "name": "Star Wars: The Old Republic" + }, + { + "executables": { + "darwin": [ + "Starbound.app" + ], + "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": { + "darwin": [ + "Terraria.app" + ], + "win32": [ + "Terraria.exe" + ] + }, + "id": 259, + "name": "Terraria" + }, + { + "executables": { + "win32": [ + "Bethesda.net_Launcher.exe", + "eso.exe" + ] + }, + "id": 260, + "name": "The Elder Scrolls Online" + }, + { + "executables": { + "win32": [ + "TESV.exe", + "TESV_original.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": { + "darwin": [ + "Trine.app" + ], + "win32": [ + "trine.exe" + ] + }, + "id": 275, + "name": "Trine" + }, + { + "executables": { + "darwin": [ + "Trine2.app" + ], + "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": { + "darwin": [ + "Warcraft%20III.app", + "Frozen%20Throne.app" + ], + "win32": [ + "Warcraft III.exe", + "wc3.exe", + "war3.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", + "Wildstar.exe" + ] + }, + "id": 285, + "name": "WildStar" + }, + { + "executables": { + "win32": [ + "XComGame.exe", + "XcomEW.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 ", + "mwoclient.exe" + ] + }, + "id": 296, + "name": "MechWarrior 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": { + "darwin": [ + "Isaac.app" + ], + "win32": [ + "Binding_of_Isaac.exe", + "Isaac.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": "From 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", + "PPSSPPWindows64.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", + "RobloxPlayerBeta.exe" + ] + }, + "id": 375, + "name": "Roblox" + }, + { + "executables": { + "darwin": [ + "eu4.app" + ], + "win32": [ + "eu4.exe" + ] + }, + "id": 376, + "name": "Europa Universalis 4" + }, + { + "executables": { + "win32": [ + "APB.exe" + ] + }, + "id": 377, + "name": "APB Reloaded" + }, + { + "executables": { + "win32": [ + "Robocraft.exe", + "RobocraftClient.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", + "Hex.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", + "CoD2SP_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", + "ElectronicObserver.exe" + ] + }, + "id": 405, + "name": "Kantai Collection" + }, + { + "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", + "DunDefGame.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 For 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" + }, + { + "executables": { + "win32": [ + "lostsaga.exe", + "LoginLauncherN.exe" + ] + }, + "id": 439, + "name": "Lost Saga" + }, + { + "executables": { + "win32": [ + "nuclearthrone.exe" + ] + }, + "id": 440, + "name": "Nuclear Throne" + }, + { + "executables": { + "win32": [ + "SwordCoast.exe" + ] + }, + "id": 441, + "name": "Sword Coast Legends" + }, + { + "executables": { + "win32": [ + "FF3_Launcher.exe" + ] + }, + "id": 442, + "name": "Final Fantasy III" + }, + { + "executables": { + "darwin": [ + "UNDERTALE.app" + ], + "win32": [ + "UNDERTALE.exe" + ] + }, + "id": 443, + "name": "Undertale" + }, + { + "executables": { + "win32": [ + "Blockland.exe" + ] + }, + "id": 444, + "name": "Blockland" + }, + { + "executables": { + "win32": [ + "DNF.exe" + ] + }, + "id": 445, + "name": "Dungeon & Fighter" + }, + { + "executables": { + "win32": [ + "Bugs.exe" + ] + }, + "id": 446, + "name": "BBLiT" + }, + { + "executables": { + "win32": [ + "grid2.exe" + ] + }, + "id": 447, + "name": "Grid 2" + }, + { + "executables": { + "win32": [ + "RainbowSix.exe" + ] + }, + "id": 448, + "name": "Rainbow Six Siege" + }, + { + "executables": { + "win32": [ + "rotaku.exe" + ] + }, + "id": 449, + "name": "Rotaku Society" + }, + { + "executables": { + "win32": [ + "Cube.exe" + ] + }, + "id": 450, + "name": "Cube World" + }, + { + "executables": { + "win32": [ + "TS4.exe" + ] + }, + "id": 451, + "name": "The Sims 4" + }, + { + "executables": { + "win32": [ + "nekopara_vol1.exe" + ] + }, + "id": 452, + "name": "Nekopara Vol. 1" + }, + { + "executables": { + "win32": [ + "nekopara_vol0.exe" + ] + }, + "id": 453, + "name": "Nekopara Vol. 0" + }, + { + "executables": { + "win32": [ + "FreeStyle2.exe" + ] + }, + "id": 454, + "name": "Freestyle Basketball 2" + }, + { + "executables": { + "win32": [ + "HMA.exe" + ] + }, + "id": 455, + "name": "Hitman: Absolution" + }, + { + "executables": { + "win32": [ + "SaintsRowTheThird_DX11.exe", + "SaintsRowTheThird.exe" + ] + }, + "id": 456, + "name": "Saints Row 3" + }, + { + "executables": { + "win32": [ + "JustCause.exe" + ] + }, + "id": 457, + "name": "Just Cause" + }, + { + "executables": { + "win32": [ + "KillingFloor.exe" + ] + }, + "id": 458, + "name": "Killing Floor" + }, + { + "executables": { + "win32": [ + "DeadIslandGame_x86_rwdi.exe" + ] + }, + "id": 459, + "name": "Dead Island Riptide" + }, + { + "executables": { + "win32": [ + "JustCause2.exe" + ] + }, + "id": 460, + "name": "Just Cause 2" + }, + { + "executables": { + "win32": [ + "altitude.exe" + ] + }, + "id": 461, + "name": "Altitude" + }, + { + "executables": { + "darwin": [ + "ygopro.app" + ], + "win32": [ + "ygopro_vs.exe" + ] + }, + "id": 462, + "name": "Yu-gi-oh Pro" + }, + { + "executables": { + "win32": [ + "bejeweled3.exe" + ] + }, + "id": 463, + "name": "Bejeweled 3" + }, + { + "executables": { + "win32": [ + "fable.exe" + ] + }, + "id": 464, + "name": "Fable: The Lost Chapters" + }, + { + "executables": { + "win32": [ + "lyne.exe" + ] + }, + "id": 465, + "name": "LYNE" + }, + { + "executables": { + "win32": [ + "Tabletop Simulator.exe" + ] + }, + "id": 466, + "name": "Tabletop Simulator" + }, + { + "executables": { + "win32": [ + "screencheat.exe" + ] + }, + "id": 467, + "name": "Screencheat" + }, + { + "executables": { + "win32": [ + "cataclysm-tiles.exe" + ] + }, + "id": 468, + "name": "Cataclysm: Dark Days Ahead" + }, + { + "executables": { + "win32": [ + "Prison Architect.exe" + ] + }, + "id": 469, + "name": "Prison Architect" + }, + { + "executables": { + "win32": [ + "armoredwarfare.exe" + ] + }, + "id": 470, + "name": "Armored Warfare" + }, + { + "executables": { + "win32": [ + "Devilian.exe" + ] + }, + "id": 471, + "name": "Devilian" + }, + { + "executables": { + "win32": [ + "aion.bin" + ] + }, + "id": 472, + "name": "Aion" + }, + { + "executables": { + "win32": [ + "Allegiance.exe" + ] + }, + "id": 473, + "name": "Allegiance" + }, + { + "executables": { + "win32": [ + "infantry.exe" + ] + }, + "id": 474, + "name": "Infantry" + }, + { + "executables": { + "win32": [ + "audiosurf.exe", + "Questviewer.exe" + ] + }, + "id": 475, + "name": "Audiosurf" + }, + { + "executables": { + "win32": [ + "audiosurf2.exe" + ] + }, + "id": 476, + "name": "Audiosurf 2" + }, + { + "executables": { + "win32": [ + "morrowind.exe" + ] + }, + "id": 477, + "name": "Morrowind" + }, + { + "executables": { + "win32": [ + "GoatGame-Win32-Shipping.exe" + ] + }, + "id": 478, + "name": "Goat Simulator" + }, + { + "executables": { + "win32": [ + "th123.exe", + "th123e.exe" + ] + }, + "id": 479, + "name": "Touhou 12.3: Hisoutensoku" + }, + { + "executables": { + "win32": [ + "th135.exe", + "th135e.exe" + ] + }, + "id": 480, + "name": "Touhou 13.5 Hopeless Mascarade" + }, + { + "executables": { + "win32": [ + "th145.exe", + "th145e.exe" + ] + }, + "id": 481, + "name": "Touhou 14.5: Urban Legend in Limbo" + }, + { + "executables": { + "win32": [ + "quake1.exe" + ] + }, + "id": 482, + "name": "Quake I" + }, + { + "executables": { + "win32": [ + "quake2.exe" + ] + }, + "id": 483, + "name": "Quake II" + }, + { + "executables": { + "win32": [ + "quake3.exe" + ] + }, + "id": 484, + "name": "Quake III" + }, + { + "executables": { + "win32": [ + "MONACO.exe" + ] + }, + "id": 485, + "name": "Monaco: What's Yours Is Mine" + }, + { + "executables": { + "win32": [ + "ToothAndTail.exe" + ] + }, + "id": 486, + "name": "Tooth & Tail" + }, + { + "executables": { + "win32": [ + "PD.exe" + ] + }, + "id": 487, + "name": "Pixel Dungeon" + }, + { + "executables": { + "win32": [ + "BlackDesert32.exe", + "BlackDesert64.exe" + ] + }, + "id": 488, + "name": "Black Desert Online" + }, + { + "executables": { + "win32": [ + "LovelyPlanet.exe" + ] + }, + "id": 489, + "name": "Lovely Planet" + }, + { + "executables": { + "win32": [ + "DeadCore.exe" + ] + }, + "id": 490, + "name": "DeadCore" + }, + { + "executables": { + "win32": [ + "fifa16.exe" + ] + }, + "id": 491, + "name": "FIFA 16" + }, + { + "executables": { + "win32": [ + "KAG.exe" + ] + }, + "id": 492, + "name": "King Arthur's Gold" + }, + { + "executables": { + "win32": [ + "TR.exe" + ] + }, + "id": 493, + "name": "Trench Run" + }, + { + "executables": { + "win32": [ + "fm.exe" + ] + }, + "id": 494, + "name": "Football Manager 2014" + }, + { + "executables": { + "win32": [ + "NecroDancer.exe" + ] + }, + "id": 495, + "name": "Crypt of the NecroDancer" + }, + { + "executables": { + "win32": [ + "EthanCarter-Win64-Shipping.exe" + ] + }, + "id": 496, + "name": "The Vanishing of Ethan Carter Redux" + }, + { + "executables": { + "win32": [ + "AstronautsGame-Win64-Shipping.exe" + ] + }, + "id": 497, + "name": "The Vanishing of Ethan Carter" + }, + { + "executables": { + "win32": [ + "fsx.exe" + ] + }, + "id": 498, + "name": "Microsoft Flight Simulator X" + }, + { + "executables": { + "win32": [ + "Prepar3D.exe" + ] + }, + "id": 499, + "name": "Prepar3D" + }, + { + "executables": { + "win32": [ + "lumini_Win64.exe" + ] + }, + "id": 500, + "name": "Lumini" + }, + { + "executables": { + "win32": [ + "BeatHazard.exe" + ] + }, + "id": 501, + "name": "Beat Hazard" + }, + { + "executables": { + "win32": [ + "TribesAscend.exe" + ] + }, + "id": 502, + "name": "Tribes Ascend" + }, + { + "executables": { + "win32": [ + "Supernova.exe" + ] + }, + "id": 503, + "name": "Supernova" + }, + { + "executables": { + "win32": [ + "NitronicRush.exe" + ] + }, + "id": 504, + "name": "Nitronic Rush" + }, + { + "executables": { + "win32": [ + "Might & Magic Heroes VI.exe" + ] + }, + "id": 505, + "name": "Might & Magic Heroes VI" + }, + { + "executables": { + "win32": [ + "AdvHD.exe" + ] + }, + "id": 506, + "name": "If My Heart Had Wings" + }, + { + "executables": { + "win32": [ + "hatoful.exe" + ] + }, + "id": 507, + "name": "Hatoful Boyfriend" + }, + { + "executables": { + "win32": [ + "HuniePop.exe" + ] + }, + "id": 508, + "name": "HuniePop" + }, + { + "executables": { + "win32": [ + "SC2VN.exe" + ] + }, + "id": 509, + "name": "SC2VN: The e-sport Visual Novel" + }, + { + "executables": { + "win32": [ + "Pyrite Heart.exe" + ] + }, + "id": 510, + "name": "Pyrite Heart" + }, + { + "executables": { + "win32": [ + "Sakura Angels.exe" + ] + }, + "id": 511, + "name": "Sakura Angels" + }, + { + "executables": { + "win32": [ + "BGI.exe" + ] + }, + "id": 512, + "name": "Go! Go! Nippon! ~My First Trip to Japan~" + }, + { + "executables": { + "win32": [ + "Sword of Asumi.exe" + ] + }, + "id": 513, + "name": "Sword of Asumi" + }, + { + "executables": { + "win32": [ + "Sakura Clicker.exe" + ] + }, + "id": 514, + "name": "Sakura Clicker" + }, + { + "executables": { + "win32": [ + "Sakura Spirit.exe" + ] + }, + "id": 515, + "name": "Sakura Spirit" + }, + { + "executables": { + "win32": [ + "NeoAquarium.exe" + ] + }, + "id": 516, + "name": "NEO AQUARIUM - The King of Crustaceans" + }, + { + "executables": { + "win32": [ + "Nicole.exe" + ] + }, + "id": 517, + "name": "Nicole (Otome Version)" + }, + { + "executables": { + "win32": [ + "LongLiveTheQueen.exe" + ] + }, + "id": 518, + "name": "Long Live The Queen" + }, + { + "executables": { + "win32": [ + "The Sacred Tears TRUE.exe" + ] + }, + "id": 519, + "name": "The Sacred Tears TRUE" + }, + { + "executables": { + "win32": [ + "trgame.exe" + ] + }, + "id": 520, + "name": "Tales Runner" + }, + { + "executables": { + "win32": [ + "CelebrityPoker.exe" + ] + }, + "id": 521, + "name": "Poker Night at the Inventory" + }, + { + "executables": { + "win32": [ + "PokerNight2.exe" + ] + }, + "id": 522, + "name": "Poker Night 2" + }, + { + "executables": { + "win32": [ + "PokeMMO.exe" + ] + }, + "id": 523, + "name": "PokeMMO" + }, + { + "executables": { + "win32": [ + "LoversInADangerousSpacetime.exe" + ] + }, + "id": 524, + "name": "Lovers in a Dangerous Spacetime" + }, + { + "executables": { + "win32": [ + "tis100.exe" + ] + }, + "id": 525, + "name": "TIS-100" + }, + { + "executables": { + "win32": [ + "TTREngine.exe" + ] + }, + "id": 526, + "name": "Toontown" + }, + { + "executables": { + "win32": [ + "mgs2_sse.exe" + ] + }, + "id": 527, + "name": "Metal Gear Solid 2: Substance" + }, + { + "executables": { + "win32": [ + "hl.exe" + ] + }, + "id": 528, + "name": "Half Life" + }, + { + "executables": { + "win32": [ + "Cloudbuilt.exe" + ] + }, + "id": 529, + "name": "Cloudbuilt" + }, + { + "executables": { + "win32": [ + "ACBSP.exe", + "ACBMP.exe" + ] + }, + "id": 530, + "name": "Assassin's Creed: Brotherhood" + }, + { + "executables": { + "win32": [ + "mm.exe" + ] + }, + "id": 531, + "name": "Dark Messiah of Might & Magic" + }, + { + "executables": { + "win32": [ + "Stalker-COP.exe" + ] + }, + "id": 532, + "name": "S.T.A.L.K.E.R.: Call of Pripyat" + }, + { + "executables": { + "win32": [ + "ROGame.exe" + ] + }, + "id": 533, + "name": "Rising Storm/Red Orchestra 2" + }, + { + "executables": { + "win32": [ + "strife-ve.exe" + ] + }, + "id": 534, + "name": "Strife: Veteran Edition" + }, + { + "executables": { + "win32": [ + "BFBC2Game.exe" + ] + }, + "id": 535, + "name": "Battlefield: Bad Company 2" + }, + { + "executables": { + "win32": [ + "FarCry2.exe" + ] + }, + "id": 536, + "name": "Far Cry 2" + }, + { + "executables": { + "win32": [ + "Nidhogg.exe" + ] + }, + "id": 537, + "name": "Nidhogg" + }, + { + "executables": { + "win32": [ + "pbbg_win32.exe" + ] + }, + "id": 538, + "name": "Phantom Break: Baggle Grounds" + }, + { + "executables": { + "darwin": [ + "Wakfu.app" + ], + "win32": [ + "Wakfu.exe" + ] + }, + "id": 539, + "name": "Wakfu" + }, + { + "executables": { + "win32": [ + "wizard101.exe" + ] + }, + "id": 540, + "name": "Wzard101" + }, + { + "executables": { + "win32": [ + "BarkleyV120.exe" + ] + }, + "id": 541, + "name": "Charles Barkley: Shut Up and Jam Gaiden" + }, + { + "executables": { + "win32": [ + "RimWorld914Win.exe" + ] + }, + "id": 542, + "name": "RimWorld" + }, + { + "executables": { + "win32": [ + "Order of Battle - Pacific.exe" + ] + }, + "id": 543, + "name": "Order of Battle" + }, + { + "executables": { + "win32": [ + "gh3.exe" + ] + }, + "id": 544, + "name": "Guitar Hero III: Legends of Rock" + }, + { + "executables": { + "win32": [ + "phase_shift.exe" + ] + }, + "id": 545, + "name": "Phase Shift" + }, + { + "executables": { + "win32": [ + "GHWT.exe" + ] + }, + "id": 546, + "name": "Guitar Hero World Tour" + }, + { + "executables": { + "win32": [ + "THEMOD 1.3.exe", + "THUG2.exe" + ] + }, + "id": 547, + "name": "Tony Hawk's Underground 2" + }, + { + "executables": { + "win32": [ + "THUGPro.exe" + ] + }, + "id": 548, + "name": "THUG Pro" + }, + { + "executables": { + "win32": [ + "THUG.exe " + ] + }, + "id": 549, + "name": "Tony Hawk's Underground" + }, + { + "executables": { + "darwin": [ + "The Binding of Isaac Rebirth.app", + "The%20Binding%20of%20Isaac%20Rebirth.app" + ], + "win32": [ + "isaac-ng.exe" + ] + }, + "id": 550, + "name": "The Binding of Isaac: Rebirth" + }, + { + "executables": { + "win32": [ + "ProjectG.exe" + ] + }, + "id": 551, + "name": "PangYa!" + }, + { + "executables": { + "win32": [ + "Overwatch.exe", + "GameClientApp.exe", + "Overwatch Launcher.exe" + ] + }, + "id": 552, + "name": "Overwatch" + }, + { + "executables": { + "win32": [ + "CivilizationBE_DX11.exe", + "CivilizationBE_Mantle.exe" + ] + }, + "id": 553, + "name": "Civilization Beyond Earth" + }, + { + "executables": { + "win32": [ + "SecretPonchosD3D11.exe" + ] + }, + "id": 554, + "name": "Secret Ponchos" + }, + { + "executables": { + "win32": [ + "Duelyst.exe" + ] + }, + "id": 555, + "name": "Duelyst" + }, + { + "executables": { + "win32": [ + "vermintide.exe" + ] + }, + "id": 556, + "name": "Warhammer: End Times - Vermintide" + }, + { + "executables": { + "darwin": [ + "Huniepop.app" + ] + }, + "id": 557, + "name": "Hunie Pop" + }, + { + "executables": { + "darwin": [ + "Reus.app" + ], + "win32": [ + "reus.exe" + ] + }, + "id": 558, + "name": "Reus" + }, + { + "executables": { + "darwin": [ + "Everlasting%20Summer.app" + ] + }, + "id": 559, + "name": "Everlasting Summer" + }, + { + "executables": { + "darwin": [ + "GunsofIcarusOnline.app" + ] + }, + "id": 560, + "name": "Guns of Icarus - Online" + }, + { + "executables": { + "darwin": [ + "Rising%20Angels%20-%20Reborn.app" + ] + }, + "id": 561, + "name": "Rising Angels - Reborn" + }, + { + "executables": { + "darwin": [ + "Hate%20Plus.app" + ] + }, + "id": 562, + "name": "Hate Plus" + }, + { + "executables": { + "win32": [ + "dcs.exe" + ] + }, + "id": 563, + "name": "DCS World" + }, + { + "executables": { + "win32": [ + "arena.exe" + ] + }, + "id": 564, + "name": "Total War: Arena" + }, + { + "executables": { + "win32": [ + "Pokemon Trading Card Game Online.exe" + ] + }, + "id": 565, + "name": "Pokemon Trading Card Game Online" + }, + { + "executables": { + "win32": [ + "Tales of Zestiria.exe" + ] + }, + "id": 566, + "name": "Tales of Zestiria" + }, + { + "executables": { + "win32": [ + "ns2.exe" + ] + }, + "id": 567, + "name": "Natural Selection 2" + }, + { + "executables": { + "win32": [ + "Rayman Legends.exe" + ] + }, + "id": 568, + "name": "Rayman Legends" + }, + { + "executables": { + "darwin": [ + "avalonlords.app" + ], + "win32": [ + "avalonlords.exe" + ] + }, + "id": 569, + "name": "Avalon Lords" + }, + { + "executables": { + "win32": [ + "th06.exe", + "th06e.exe" + ] + }, + "id": 570, + "name": "Touhou 6: Embodiment of Scarlet Devil" + }, + { + "executables": { + "win32": [ + "th07.exe", + "th07e.exe" + ] + }, + "id": 571, + "name": "Touhou 7: Perfect Cherry Blossom" + }, + { + "executables": { + "win32": [ + "th08.exe", + "th08e.exe" + ] + }, + "id": 572, + "name": "Touhou 8: Imperishable Night" + }, + { + "executables": { + "win32": [ + "th09.exe", + "th09e.exe" + ] + }, + "id": 573, + "name": "Touhou 9: Phantasmagoria Of Flower View" + }, + { + "executables": { + "win32": [ + "th095.exe", + "th095e.exe" + ] + }, + "id": 574, + "name": "Touhou 9.5: Shoot the Bullet" + }, + { + "executables": { + "win32": [ + "th10.exe", + "th10e.exe" + ] + }, + "id": 575, + "name": "Touhou 10: Mountain of Faith" + }, + { + "executables": { + "win32": [ + "th105.exe", + "th105e.exe" + ] + }, + "id": 576, + "name": "Touhou 10.5: Scarlet Weather Rhapsody" + }, + { + "executables": { + "win32": [ + "th11.exe", + "th11e.exe" + ] + }, + "id": 577, + "name": "Touhou 11: Subterranean Animism" + }, + { + "executables": { + "win32": [ + "th12.exe", + "th12e.exe" + ] + }, + "id": 578, + "name": "Touhou 12: Undefined Fantastic Object" + }, + { + "executables": { + "win32": [ + "th125.exe", + "th125e.exe" + ] + }, + "id": 579, + "name": "Touhou 12.5: Double Spoiler" + }, + { + "executables": { + "win32": [ + "th128.exe", + "th128e.exe" + ] + }, + "id": 580, + "name": "Touhou 12.8: Great Fairy Wars" + }, + { + "executables": { + "win32": [ + "th13.exe", + "th13e.exe" + ] + }, + "id": 581, + "name": "Touhou 13: Ten Desires" + }, + { + "executables": { + "win32": [ + "th14.exe", + "th14e.exe" + ] + }, + "id": 582, + "name": "Touhou 14: Double Dealing Character" + }, + { + "executables": { + "win32": [ + "th143.exe", + "th143e.exe" + ] + }, + "id": 583, + "name": "Touhou 14.3: Impossible Spell Card" + }, + { + "executables": { + "win32": [ + "th15.exe", + "th15e.exe" + ] + }, + "id": 584, + "name": "Touhou 15: Legacy of Lunatic Kingdom" + }, + { + "executables": { + "win32": [ + "grandia2.exe" + ] + }, + "id": 585, + "name": "Grandia 2" + }, + { + "executables": { + "win32": [ + "Albion-Online.exe" + ] + }, + "id": 586, + "name": "Albion Online" + }, + { + "executables": { + "win32": [ + "ThereWasACaveman.exe" + ] + }, + "id": 587, + "name": "There Was A Caveman" + }, + { + "executables": { + "win32": [ + "ASN_App_PcDx9_Final.exe" + ] + }, + "id": 588, + "name": "Sonic & All Stars Racing Transformed" + }, + { + "executables": { + "win32": [ + "Cryptark.exe" + ] + }, + "id": 589, + "name": "CRYPTARK" + }, + { + "executables": { + "win32": [ + "Entropia.exe" + ] + }, + "id": 590, + "name": "Entropia Universe" + }, + { + "executables": { + "win32": [ + "DepthGame.exe" + ] + }, + "id": 591, + "name": "Depth" + }, + { + "executables": { + "win32": [ + "Factorio.exe" + ] + }, + "id": 592, + "name": "Factorio" + }, + { + "executables": { + "win32": [ + "ChildofLight.exe" + ] + }, + "id": 593, + "name": "Child of Light" + }, + { + "executables": { + "win32": [ + "TransformersDevatstation.exe" + ] + }, + "id": 594, + "name": "Transformers: Devastation" + }, + { + "executables": { + "win32": [ + "oppw3.exe" + ] + }, + "id": 595, + "name": "One Piece Pirate Warriors 3" + }, + { + "executables": { + "win32": [ + "Astebreed.exe" + ] + }, + "id": 596, + "name": "Astebreed" + }, + { + "executables": { + "win32": [ + "ktane.exe" + ] + }, + "id": 597, + "name": "Keep Talking and Nobody Explodes" + }, + { + "executables": { + "win32": [ + "Steredenn.exe" + ] + }, + "id": 598, + "name": "Steredenn" + }, + { + "executables": { + "win32": [ + "CK2game.exe" + ] + }, + "id": 599, + "name": "Crusader Kings II" + }, + { + "executables": { + "win32": [ + "jamp.exe", + "openjk.x86.exe" + ] + }, + "id": 600, + "name": "Star Wars Jedi Knight" + }, + { + "executables": { + "win32": [ + "jk2mp.exe", + "jk2mvmp_x86.exe", + "jk2mvmp_x64.exe" + ] + }, + "id": 601, + "name": "Star Wars Jedi Knight II" + }, + { + "executables": { + "win32": [ + "FightCade.exe" + ] + }, + "id": 602, + "name": "FightCade" + }, + { + "executables": { + "win32": [ + "Downwell.exe" + ] + }, + "id": 603, + "name": "Downwell" + }, + { + "executables": { + "win32": [ + "flamebreak.exe" + ] + }, + "id": 604, + "name": "Flamebreak" + }, + { + "executables": { + "win32": [ + "Disco Dodgeball.exe" + ] + }, + "id": 605, + "name": "Robot Roller-Derby Disco Dodgeball" + }, + { + "executables": { + "win32": [ + "DarkStarOne.exe" + ] + }, + "id": 606, + "name": "DarkStar One" + }, + { + "executables": { + "win32": [ + "20XX.exe" + ] + }, + "id": 607, + "name": "20XX" + }, + { + "executables": { + "win32": [ + "wesnoth.exe" + ] + }, + "id": 608, + "name": "Battle for Wesnoth" + }, + { + "executables": { + "win32": [ + "Creativerse.exe" + ] + }, + "id": 609, + "name": "Creativerse" + }, + { + "executables": { + "win32": [ + "BlockNLoad.exe" + ] + }, + "id": 610, + "name": "Block n Load" + }, + { + "executables": { + "win32": [ + "rwr_game.exe" + ] + }, + "id": 611, + "name": "Running with Rifles" + }, + { + "executables": { + "win32": [ + "Evolve.exe" + ] + }, + "id": 612, + "name": "Evolve" + }, + { + "executables": { + "win32": [ + "et.exe" + ] + }, + "id": 613, + "name": "Wolfenstein - Enemy Territory" + }, + { + "executables": { + "win32": [ + "C9.exe" + ] + }, + "id": 614, + "name": "C9" + }, + { + "executables": { + "win32": [ + "Multi Theft Auto.exe" + ] + }, + "id": 615, + "name": "Multi Theft Auto San Andreas" + }, + { + "executables": { + "win32": [ + "SpecOpsTheLine.exe" + ] + }, + "id": 616, + "name": "Spec Ops: The Line" + }, + { + "executables": { + "win32": [ + "stanley.exe" + ] + }, + "id": 617, + "name": "The Stanley Parable" + }, + { + "executables": { + "win32": [ + "Secrets Of Grindea.exe" + ] + }, + "id": 618, + "name": "Secrets of Grindea" + }, + { + "executables": { + "win32": [ + "MugenSouls.exe" + ] + }, + "id": 619, + "name": "Mugen Souls " + }, + { + "executables": { + "win32": [ + "RebelGalaxyGOG.exe", + "RebelGalaxySteam.exe" + ] + }, + "id": 620, + "name": "Rebel Galaxy" + }, + { + "executables": { + "win32": [ + "rerev.exe" + ] + }, + "id": 621, + "name": "Resident Evil Revelations" + }, + { + "executables": { + "win32": [ + "rerev2.exe" + ] + }, + "id": 622, + "name": "Resident Evil Revelations 2" + }, + { + "executables": { + "win32": [ + "re5dx9.exe" + ] + }, + "id": 623, + "name": "Resident Evil 5" + }, + { + "executables": { + "win32": [ + "bio4.exe" + ] + }, + "id": 624, + "name": "Resident Evil 4 HD" + }, + { + "executables": { + "win32": [ + "bhd.exe" + ] + }, + "id": 625, + "name": "Resident Evil 4HD Remaster" + }, + { + "executables": { + "win32": [ + "SSF2.exe" + ] + }, + "id": 626, + "name": "Super Smash Flash 2 " + }, + { + "executables": { + "win32": [ + "AI.exe" + ] + }, + "id": 627, + "name": "Alien: Isolation" + }, + { + "executables": { + "win32": [ + "dungeonland.exe" + ] + }, + "id": 628, + "name": "Dungeonland" + }, + { + "executables": { + "win32": [ + "TerraTechWin32.exe" + ] + }, + "id": 629, + "name": "TerraTech" + }, + { + "executables": { + "win32": [ + "beginnersguide.exe" + ] + }, + "id": 630, + "name": "The Beginner's Guide" + }, + { + "executables": { + "win32": [ + "StreetFighterVBeta-Win64-Shipping.exe" + ] + }, + "id": 631, + "name": "Street Fighter V" + }, + { + "executables": { + "win32": [ + "bf4cte.exe" + ] + }, + "id": 632, + "name": "Battlefiled 4 CTE" + }, + { + "executables": { + "win32": [ + "Suguri.exe" + ] + }, + "id": 633, + "name": "Suguri" + }, + { + "executables": { + "win32": [ + "UT3.exe" + ] + }, + "id": 634, + "name": "Unreal Tournament 3" + }, + { + "executables": { + "win32": [ + "Unreal.exe" + ] + }, + "id": 635, + "name": "Unreal" + }, + { + "executables": { + "win32": [ + "AVA.exe" + ] + }, + "id": 636, + "name": "Alliance of Valiant Arms" + }, + { + "executables": { + "win32": [ + "ShooterUltimate.exe" + ] + }, + "id": 637, + "name": "PixelJunk Shooter Ultimate" + }, + { + "executables": { + "win32": [ + "pokemonshowdown.exe" + ] + }, + "id": 638, + "name": "Pokemon Showdown" + }, + { + "executables": { + "win32": [ + "SuperMeatBoy.exe" + ] + }, + "id": 639, + "name": "Super Meat Boy" + }, + { + "executables": { + "win32": [ + "Kara no Shojo 2.exe" + ] + }, + "id": 640, + "name": "Kara no Shoujo 2" + }, + { + "executables": { + "win32": [ + "Intruder.exe" + ] + }, + "id": 641, + "name": "Intruder" + }, + { + "executables": { + "win32": [ + "Aeon Rivals.exe" + ] + }, + "id": 642, + "name": "Aeon Rivals" + }, + { + "executables": { + "win32": [ + "Rats.exe" + ] + }, + "id": 643, + "name": "Bad Rats" + }, + { + "executables": { + "win32": [ + "BH6.exe" + ] + }, + "id": 644, + "name": "Resident Evil 6" + }, + { + "executables": { + "win32": [ + "ZOMBI.exe" + ] + }, + "id": 645, + "name": "Zombi" + }, + { + "executables": { + "win32": [ + "Xenonauts.exe" + ] + }, + "id": 646, + "name": "Xenonauts" + }, + { + "executables": { + "win32": [ + "OrganTrail.exe" + ] + }, + "id": 647, + "name": "Organ Trail" + }, + { + "executables": { + "darwin": [ + "LethalLeague.app" + ], + "win32": [ + "LethalLeague.exe" + ] + }, + "id": 648, + "name": "Lethal League" + }, + { + "executables": { + "win32": [ + "blobby.exe" + ] + }, + "id": 649, + "name": "Blobby Volley 2" + }, + { + "executables": { + "win32": [ + "DQXGame.exe" + ] + }, + "id": 650, + "name": "Dragon Quest X: Mezameshi Itsutsu no Shuzoku Online" + }, + { + "executables": { + "win32": [ + "Dishonored.exe" + ] + }, + "id": 651, + "name": "Dishonored" + }, + { + "executables": { + "win32": [ + "TheForest.exe" + ] + }, + "id": 652, + "name": "The Forest" + }, + { + "executables": { + "win32": [ + "ThePark.exe" + ] + }, + "id": 653, + "name": "The Park" + }, + { + "executables": { + "win32": [ + "FishingPlanet.exe" + ] + }, + "id": 654, + "name": "Fishing Planet" + }, + { + "executables": { + "win32": [ + "pso.exe" + ] + }, + "id": 655, + "name": "Phantasy Star Online" + }, + { + "executables": {}, + "id": 656, + "name": "Our Darker Purpose" + }, + { + "executables": { + "win32": [ + "Darkest.exe" + ] + }, + "id": 657, + "name": "Darkest Dungeon" + }, + { + "executables": { + "win32": [ + "UE4-Win64-Test.exe" + ] + }, + "id": 658, + "name": "Unreal Tournament 4" + }, + { + "executables": { + "win32": [ + "ed6_win2.exe" + ] + }, + "id": 659, + "name": "Trails in the Sky SC" + }, + { + "executables": { + "win32": [ + "ed6_win.exe" + ] + }, + "id": 660, + "name": "Trails in the Sky FC" + }, + { + "executables": { + "win32": [ + "kshootmania.exe" + ] + }, + "id": 661, + "name": "K-Shoot Mania" + }, + { + "executables": { + "win32": [ + "df.exe" + ] + }, + "id": 662, + "name": "Delta Force 1" + }, + { + "executables": { + "win32": [ + "BloodlineChampions.exe" + ] + }, + "id": 663, + "name": "Bloodline Champions" + }, + { + "executables": { + "win32": [ + "TmForever.exe" + ] + }, + "id": 664, + "name": "Trackmania Nations Forever" + }, + { + "executables": { + "win32": [ + "DragonFinSoup.exe" + ] + }, + "id": 666, + "name": "Dragon Fin Soup" + }, + { + "executables": { + "win32": [ + "Anno2205.exe" + ] + }, + "id": 667, + "name": "Anno 2205" + }, + { + "executables": { + "darwin": [ + "KatawaShoujo.app" + ] + }, + "id": 668, + "name": "Katawa Shoujo" + }, + { + "executables": { + "win32": [ + "NeptuniaReBirth1.exe" + ] + }, + "id": 669, + "name": "Hyperdimension Neptunia Re;Birth1" + }, + { + "executables": { + "win32": [ + "NeptuniaReBirth2.exe" + ] + }, + "id": 670, + "name": "Hyperdimension Neptunia Re;Birth2" + }, + { + "executables": { + "win32": [ + "NeptuniaReBirth3.exe" + ] + }, + "id": 671, + "name": "Hyperdimension Neptunia Re;Birth3" + }, + { + "executables": { + "win32": [ + "HatinTimeGame.exe" + ] + }, + "id": 672, + "name": "A Hat in Time" + }, + { + "executables": { + "win32": [ + "AxiomVerge.exe" + ] + }, + "id": 673, + "name": "Axiom Verge" + }, + { + "executables": { + "win32": [ + "CoJGunslinger.exe" + ] + }, + "id": 674, + "name": "Call of Juarez: Gunslinger" + }, + { + "executables": { + "darwin": [ + "CardHunter.app" + ], + "win32": [ + "CardHunter.exe" + ] + }, + "id": 675, + "name": "Card Hunter" + }, + { + "executables": { + "darwin": [ + "CargoCommander.app" + ], + "win32": [ + "CargoCommander.exe" + ] + }, + "id": 676, + "name": "Cargo Commander" + }, + { + "executables": { + "win32": [ + "DDO.exe" + ] + }, + "id": 677, + "name": "Dragon's Dogma Online" + }, + { + "executables": { + "win32": [ + "falloutw.exe" + ] + }, + "id": 678, + "name": "Fallout" + }, + { + "executables": { + "win32": [ + "FALLOUT2.EXE", + "Fallout2HR.exe" + ] + }, + "id": 679, + "name": "Fallout 2" + }, + { + "executables": { + "win32": [ + "Fallout4.exe" + ] + }, + "id": 680, + "name": "Fallout 4" + }, + { + "executables": { + "win32": [ + "FarCry4.exe" + ] + }, + "id": 681, + "name": "Far Cry 4" + }, + { + "executables": { + "win32": [ + "OpenITG-PC.exe" + ] + }, + "id": 682, + "name": "In The Groove 2" + }, + { + "executables": { + "win32": [ + "L2.bin" + ] + }, + "id": 683, + "name": "Lineage II" + }, + { + "executables": { + "win32": [ + "LordsOfTheFallen.exe" + ] + }, + "id": 684, + "name": "Lords of the Fallen" + }, + { + "executables": { + "win32": [ + "LR2.exe" + ] + }, + "id": 685, + "name": "Lunatic Rave 2" + }, + { + "executables": { + "win32": [ + "MBA.exe" + ] + }, + "id": 686, + "name": "Magical Battle Arena" + }, + { + "executables": { + "win32": [ + "MBAN_M.exe", + "MBAN_F.exe" + ] + }, + "id": 687, + "name": "Magical Battle Arena NEXT" + }, + { + "executables": { + "win32": [ + "ManiaPlanet.exe" + ] + }, + "id": 688, + "name": "ManiaPlanet" + }, + { + "executables": { + "win32": [ + "mhf.exe" + ] + }, + "id": 689, + "name": "Monster Hunter Frontier" + }, + { + "executables": { + "win32": [ + "6kinoko.exe" + ] + }, + "id": 690, + "name": "New Super Marisa Land" + }, + { + "executables": { + "win32": [ + "Nosgoth.exe" + ] + }, + "id": 691, + "name": "Nosgoth" + }, + { + "executables": { + "win32": [ + "Poi.exe" + ] + }, + "id": 692, + "name": "Poi" + }, + { + "executables": { + "win32": [ + "RogueSystemSim.exe" + ] + }, + "id": 693, + "name": "Rogue System" + }, + { + "executables": { + "darwin": [ + "SinaRun.app" + ], + "win32": [ + "SinaRun.exe" + ] + }, + "id": 694, + "name": "SinaRun" + }, + { + "executables": { + "win32": [ + "SkullGirls.exe" + ] + }, + "id": 695, + "name": "Skullgirls" + }, + { + "executables": { + "win32": [ + "Soma.exe" + ] + }, + "id": 696, + "name": "SOMA" + }, + { + "executables": { + "win32": [ + "sonic2app.exe" + ] + }, + "id": 697, + "name": "Sonic Adventure 2" + }, + { + "executables": { + "win32": [ + "SonicGenerations.exe" + ] + }, + "id": 698, + "name": "Sonic Generations" + }, + { + "executables": { + "win32": [ + "SpaceChem.exe" + ] + }, + "id": 699, + "name": "SpaceChem" + }, + { + "executables": { + "win32": [ + "SSFexe.exe" + ] + }, + "id": 700, + "name": "Super Smash Flash 1" + }, + { + "executables": { + "win32": [ + "System Shock2.exe", + "shock2.exe" + ] + }, + "id": 701, + "name": "System Shock 2" + }, + { + "executables": { + "win32": [ + "Blacklist_launcher.exe" + ] + }, + "id": 702, + "name": "Tom Clancy's Splinter Cell: Blacklist" + }, + { + "executables": { + "win32": [ + "gn_enbu.exe" + ] + }, + "id": 703, + "name": "Touhou Puppet Dance Performance" + }, + { + "executables": { + "win32": [ + "TSA.exe" + ] + }, + "id": 704, + "name": "Touhou Sky Arena" + }, + { + "executables": { + "win32": [ + "Verdun.exe" + ] + }, + "id": 705, + "name": "Verdun" + }, + { + "executables": { + "darwin": [ + "wz2100.app" + ], + "win32": [ + "wz2100.exe" + ] + }, + "id": 706, + "name": "Warzone 2100" + }, + { + "executables": { + "win32": [ + "WowT-64.exe" + ] + }, + "id": 707, + "name": "World of Warcraft PTR" + }, + { + "executables": { + "win32": [ + "Chronicon.exe" + ] + }, + "id": 708, + "name": "Chronicon" + }, + { + "executables": { + "win32": [ + "MagicDuels.exe" + ] + }, + "id": 709, + "name": "Magic Duels" + }, + { + "executables": { + "win32": [ + "BorderlandsPreSequel.exe" + ] + }, + "id": 710, + "name": "Borderlands: the Pre-Sequel" + }, + { + "executables": { + "win32": [ + "AoD.exe" + ] + }, + "id": 711, + "name": "The Age of Decadence" + }, + { + "executables": { + "win32": [ + "Doom.exe" + ] + }, + "id": 712, + "name": "Doom 3" + }, + { + "executables": { + "win32": [ + "Dead Space.exe" + ] + }, + "id": 713, + "name": "Dead Space" + }, + { + "executables": { + "win32": [ + "AvP3.exe" + ] + }, + "id": 714, + "name": "Alien Vs Predator" + }, + { + "executables": { + "win32": [ + "BlackOps3.exe" + ] + }, + "id": 715, + "name": "Call of Duty: Black Ops III" + }, + { + "executables": { + "win32": [ + "halo_online.exe" + ] + }, + "id": 716, + "name": "Halo Online" + }, + { + "executables": { + "win32": [ + "Krosmaster Arena.exe" + ] + }, + "id": 717, + "name": "Krosmaster Arena" + }, + { + "executables": { + "win32": [ + "MapleRoyals.exe" + ] + }, + "id": 718, + "name": "MapleRoyals" + }, + { + "executables": { + "win32": [ + "clragexe.exe" + ] + }, + "id": 719, + "name": "Ragnarok Online Classic" + }, + { + "executables": { + "win32": [ + "RememberingHowWeMet.exe" + ] + }, + "id": 720, + "name": "A Kiss For The Petals - Remembering How We Met" + }, + { + "executables": { + "win32": [ + "Command.exe" + ] + }, + "id": 721, + "name": "Command: Modern Air/Naval Operations " + }, + { + "executables": { + "win32": [ + "CM Black Sea.exe" + ] + }, + "id": 722, + "name": "Combat Mission: Black Sea" + }, + { + "executables": { + "win32": [ + "CM Shock Force.exe" + ] + }, + "id": 723, + "name": "Combat Mission: Shock Force" + }, + { + "executables": { + "win32": [ + "KingOfFighters2002UM.exe" + ] + }, + "id": 724, + "name": "The King Of Fighters 2002 Unlimited Match" + }, + { + "executables": { + "win32": [ + "NFSC.exe" + ] + }, + "id": 725, + "name": "Need for Speed: Carbon" + }, + { + "executables": { + "win32": [ + "th075.exe", + "th075e.exe" + ] + }, + "id": 726, + "name": "Touhou 7.5: Immaterial and Missing Power" + }, + { + "executables": { + "win32": [ + "Demul.exe" + ] + }, + "id": 727, + "name": "Demul" + }, + { + "executables": { + "win32": [ + "DeSmuMe_0.9.11_x86.exe", + "DeSmuME_0.9.11_x64.exe" + ] + }, + "id": 728, + "name": "DeSmuME" + }, + { + "executables": { + "win32": [ + "Fusion.exe" + ] + }, + "id": 729, + "name": "Kega Fusion" + }, + { + "executables": { + "win32": [ + "nullDC_Win32_Release-NoTrace.exe" + ] + }, + "id": 730, + "name": "nullDC" + }, + { + "executables": { + "win32": [ + "pcsx2-r5875.exe" + ] + }, + "id": 731, + "name": "PCSX2" + }, + { + "executables": { + "win32": [ + "Project64.exe" + ] + }, + "id": 732, + "name": "Project64" + }, + { + "executables": { + "win32": [ + "Snes9X.exe" + ] + }, + "id": 733, + "name": "Snes9x" + }, + { + "executables": { + "win32": [ + "VisualBoyAdvance.exe" + ] + }, + "id": 734, + "name": "VisualBoyAdvance" + }, + { + "executables": { + "win32": [ + "zsnesw.exe" + ] + }, + "id": 735, + "name": "ZSNES" + }, + { + "executables": { + "win32": [ + "Uplink.exe" + ] + }, + "id": 736, + "name": "Uplink" + }, + { + "executables": { + "win32": [ + "RIK.exe" + ] + }, + "id": 737, + "name": "ProjectRIK" + }, + { + "executables": { + "win32": [ + "warsow_x64.exe", + "warsow_x86.exe" + ] + }, + "id": 738, + "name": "Warsow" + }, + { + "executables": { + "win32": [ + "cactus.exe" + ] + }, + "id": 739, + "name": "Assault Android Cactus" + }, + { + "executables": { + "win32": [ + "PlantsVsZombies.exe" + ] + }, + "id": 740, + "name": "Plants vs. Zombies" + }, + { + "executables": { + "win32": [ + "HeavyWeapon.exe" + ] + }, + "id": 741, + "name": "Heavy Weapon" + }, + { + "executables": { + "win32": [ + "BejBlitz.exe" + ] + }, + "id": 742, + "name": "Bejeweled Blitz" + }, + { + "executables": { + "win32": [ + "slw.exe" + ] + }, + "id": 743, + "name": "Sonic Lost World" + }, + { + "executables": { + "win32": [ + "age.exe" + ] + }, + "id": 744, + "name": "Kamidori Alchemy Meister" + }, + { + "executables": { + "win32": [ + "psobb.exe" + ] + }, + "id": 745, + "name": "Phantasy Star Online Blue Burst" + }, + { + "executables": { + "win32": [ + "Evoland2.exe" + ] + }, + "id": 746, + "name": "Evoland 2" + }, + { + "executables": { + "win32": [ + "FFV_Game.exe" + ] + }, + "id": 747, + "name": "Final Fantasy V" + }, + { + "executables": { + "win32": [ + "TITAN.exe" + ] + }, + "id": 748, + "name": "Titan Souls" + }, + { + "executables": { + "win32": [ + "FTP.exe" + ] + }, + "id": 749, + "name": "Free To Play" + }, + { + "executables": { + "win32": [ + "Hero_Siege.exe" + ] + }, + "id": 750, + "name": "Hero Siege" + } +] \ No newline at end of file diff --git a/ref/gameMap.json b/ref/gameMap.json deleted file mode 100644 index 8b351465f..000000000 --- a/ref/gameMap.json +++ /dev/null @@ -1 +0,0 @@ -[{"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/Client.js b/src/Client/Client.js index 9d6ec3fe4..342d81251 100644 --- a/src/Client/Client.js +++ b/src/Client/Client.js @@ -796,6 +796,30 @@ class Client extends EventEmitter { }); }); } + + setStatusIdle() { + this.setStatus("idle"); + } + + setStatusOnline(cb = function (err) { }) { + this.setStatus("online"); + } + + setStatusActive() { + this.setStatusOnline(); + } + + setStatusHere() { + this.setStatusOnline(); + } + + setStatusAway() { + this.setStatusIdle(); + } + + setPlayingGame(game) { + this.setStatus(null, game); + } } module.exports = Client; \ No newline at end of file diff --git a/src/Client/InternalClient.js b/src/Client/InternalClient.js index fad7e5a66..dc0f83ce9 100644 --- a/src/Client/InternalClient.js +++ b/src/Client/InternalClient.js @@ -974,22 +974,28 @@ class InternalClient { //def setStatus setStatus(idleStatus, gameID) { var self = this; + + self.idleStatus = idleStatus || self.idleStatus || null; + if(idleStatus){ + if(idleStatus == "online" || idleStatus == "here" || idleStatus == "available"){ + self.idleStatus = null; + } + } + self.gameID = self.resolver.resolveGameID(gameID) || self.gameID || null; + return new Promise((resolve, reject) => { var packet = { op: 3, d: { - idle_since: null, - game_id: null + idle_since: self.idleStatus, + game_id: self.gameID } }; - if (idleStatus) { + if (self.idleStatus == "idle" || self.idleStatus == "away") { packet.d.idle_since = Date.now(); } - if (typeof gameID === "number") { - packet.d.game_id = gameID; - } self.sendWS(packet); diff --git a/src/Client/Resolver/Resolver.js b/src/Client/Resolver/Resolver.js index 704fb95b6..28b670b8c 100644 --- a/src/Client/Resolver/Resolver.js +++ b/src/Client/Resolver/Resolver.js @@ -11,12 +11,29 @@ var User = require("../../Structures/User.js"), PMChannel = require("../../Structures/PMChannel.js"), Server = require("../../Structures/Server.js"), Message = require("../../Structures/Message.js"), - Invite = require("../../Structures/Invite.js"); + Invite = require("../../Structures/Invite.js"), + Games = require("../../../ref/gameMap.js"); class Resolver { constructor(internal) { this.internal = internal; } + + resolveGameID(resource) { + if (!isNaN(resource) && parseInt(resource) % 1 === 0) { + return resource; + } else if (typeof resource == "string" || resource instanceof String) { + + for (var game of Games) { + if (game.name.toUpperCase() === resource.toUpperCase()) { + return game.id; + } + } + + } + + return null; + } resolveToBase64(resource) { if (resource instanceof Buffer) { diff --git a/src/Structures/Channel.js b/src/Structures/Channel.js index 11888a8ed..20dd3e564 100644 --- a/src/Structures/Channel.js +++ b/src/Structures/Channel.js @@ -12,6 +12,10 @@ class Channel extends Equality{ this.id = data.id; this.client = client; } + + get isPrivate() { + return !!this.server; + } delete(){ return this.client.deleteChannel.apply(this.client, reg(this, arguments)); diff --git a/test/bot.1.js b/test/bot.1.js index 0eeb7f1e5..5b48c9ac9 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -16,6 +16,12 @@ client.on("message", m => { } else if (m.content === "setav") { var fs = require("fs"); client.setAvatar(fs.readFileSync("./test/image.png")); + } else if (m.content.startsWith("startplaying")) { + var game = m.content.split(" ").slice(1).join(" "); + client.setPlayingGame(game); + } else if (m.content.startsWith("setstatus")) { + var game = m.content.split(" ").slice(1).join(" "); + client.setStatus(game); } });