Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

discord.js

Package Overview
Dependencies
Maintainers
1
Versions
1747
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discord.js - npm Package Compare versions

Comparing version 3.10.2 to 4.0.0

lib/Embed.js

4

lib/channel.js

@@ -1,2 +0,2 @@

"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var ChannelPermissions=require("./ChannelPermissions.js");var Channel=(function(){function Channel(data,server){_classCallCheck(this,Channel);this.server = server;this.name = data.name;this.type = data.type;this.topic = data.topic;this.id = data.id;this.messages = [];this.roles = [];if(data.permission_overwrites)for(var _iterator=data.permission_overwrites,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var role=_ref;this.roles.push(new ChannelPermissions(role,this));} //this.isPrivate = isPrivate; //not sure about the implementation of this...
}Channel.prototype.permissionsOf = function permissionsOf(member){var mem=this.server.getMember("id",member.id);if(mem){return mem.permissionsIn(this);}else {return null;}};Channel.prototype.equals = function equals(object){return object && object.id === this.id;};Channel.prototype.addMessage = function addMessage(data){if(this.messages.length > 1000){this.messages.splice(0,1);}if(!this.getMessage("id",data.id)){this.messages.push(data);}return this.getMessage("id",data.id);};Channel.prototype.getMessage = function getMessage(key,value){for(var _iterator2=this.messages,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var message=_ref2;if(message[key] === value){return message;}}return null;};Channel.prototype.toString = function toString(){return "<#" + this.id + ">";};_createClass(Channel,[{key:"permissionOverwrites",get:function get(){return this.roles;}},{key:"permissions",get:function get(){return this.roles;}},{key:"client",get:function get(){return this.server.client;}},{key:"isPrivate",get:function get(){return false;}},{key:"users",get:function get(){return this.server.members;}},{key:"members",get:function get(){return this.server.members;}}]);return Channel;})();module.exports = Channel;
"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var ChannelPermissions=require("./ChannelPermissions.js");var Channel=(function(){function Channel(data,server){_classCallCheck(this,Channel);this.serverID = server.id;this.client = server.client;this.name = data.name;this.type = data.type;this.topic = data.topic;this.id = data.id;this.messages = [];this.roles = [];if(data.permission_overwrites)for(var _iterator=data.permission_overwrites,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var role=_ref;this.roles.push(new ChannelPermissions(role,this));} //this.isPrivate = isPrivate; //not sure about the implementation of this...
}Channel.prototype.permissionsOf = function permissionsOf(member){var mem=this.server.getMember("id",member.id);if(mem){return mem.permissionsIn(this);}else {return null;}};Channel.prototype.equals = function equals(object){return object && object.id === this.id;};Channel.prototype.addMessage = function addMessage(data){if(this.messages.length > 1000){this.messages.splice(0,1);}if(!this.getMessage("id",data.id)){this.messages.push(data);}return this.getMessage("id",data.id);};Channel.prototype.getMessage = function getMessage(key,value){for(var _iterator2=this.messages,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var message=_ref2;if(message[key] === value){return message;}}return null;};Channel.prototype.toString = function toString(){return "<#" + this.id + ">";};_createClass(Channel,[{key:"server",get:function get(){return this.client.getServer("id",this.serverID);}},{key:"permissionOverwrites",get:function get(){return this.roles;}},{key:"permissions",get:function get(){return this.roles;}},{key:"isPrivate",get:function get(){return false;}},{key:"users",get:function get(){return this.server.members;}},{key:"members",get:function get(){return this.server.members;}}]);return Channel;})();module.exports = Channel;
//discord.js modules
"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}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 Endpoints=require("./Endpoints.js");var User=require("./user.js");var Server=require("./server.js");var Channel=require("./channel.js");var Message=require("./message.js");var Invite=require("./invite.js");var PMChannel=require("./PMChannel.js");var ServerPermissions=require("./ServerPermissions.js");var gameMap=require("../ref/gameMap.json");var Color=require("../ref/colours.js");var zlib;var EventEmitter=require('events'); //node modules
"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}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 Endpoints=require("./Endpoints.js");var User=require("./user.js");var Server=require("./server.js");var Channel=require("./channel.js");var Message=require("./message.js");var Invite=require("./invite.js");var PMChannel=require("./PMChannel.js");var ServerPermissions=require("./ServerPermissions.js");var gameMap=require("../ref/gameMap.json");var Color=require("../ref/colours.js");var Embeddable=require("./Embeds/IEmbed.js");var zlib;var EventEmitter=require('events'); //node modules
var request=require("superagent");var WebSocket=require("ws");var fs=require("fs");var defaultOptions={queue:false};var Client=(function(_EventEmitter){_inherits(Client,_EventEmitter);function Client(){var options=arguments.length <= 0 || arguments[0] === undefined?defaultOptions:arguments[0];var token=arguments.length <= 1 || arguments[1] === undefined?undefined:arguments[1];_classCallCheck(this,Client); /*

@@ -19,5 +19,5 @@ When created, if a token is specified the Client will

self.email = email;self.password = password;request.post(Endpoints.LOGIN).send({email:email,password:password}).end(function(err,res){if(err){self.state = 4; //set state to disconnected
self.emit("disconnected");if(self.websocket){self.websocket.close();}callback(err);reject(err);}else {self.state = 2; //set state to logged in (not yet ready)
self.emit("disconnected");if(self.websocket){self.websocket.close();}self.debug("error logging in - " + err);callback(err);reject(err);}else {self.state = 2; //set state to logged in (not yet ready)
self.token = res.body.token; //set our token
self.getGateway().then(function(url){self.createws(url);callback(null,self.token);resolve(self.token);})["catch"](function(err){callback(err);reject(err);});}});}else {reject(new Error("Client already logging in or ready"));}});};Client.prototype.banMember = function banMember(user,server){var daysToDeleteMessage=arguments.length <= 2 || arguments[2] === undefined?1:arguments[2];var cb=arguments.length <= 3 || arguments[3] === undefined?function(err){}:arguments[3];var self=this;return new Promise(function(resolve,reject){var serverID=self.resolveServerID(server);var memberID=self.resolveUserID(user);request.put(Endpoints.SERVERS + "/" + serverID + "/bans/" + memberID + "?delete-message-days=" + daysToDeleteMessage).set("authorization",self.token).end(function(err,res){cb(err);if(err){reject(err);}else {resolve();}});});};Client.prototype.logout = function logout(){var callback=arguments.length <= 0 || arguments[0] === undefined?function(err){}:arguments[0];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.LOGOUT).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {self.websocket.close();self.state = 4;callback();resolve();}});});};Client.prototype.createServer = function createServer(name,region){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,server){}:arguments[2];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.SERVERS).set("authorization",self.token).send({name:name,region:region}).end(function(err,res){if(err){callback(err);reject(err);}else { // potentially redundant in future
self.debug("client logged in w/ token " + self.token);self.getGateway().then(function(url){self.debug("gateway response successful");self.createws(url);callback(null,self.token);resolve(self.token);})["catch"](function(err){self.debug("unable to connect to gateways - " + err);callback(err);reject(err);});}});}else {reject(new Error("Client already logging in or ready"));}});};Client.prototype.banMember = function banMember(user,server){var daysToDeleteMessage=arguments.length <= 2 || arguments[2] === undefined?1:arguments[2];var cb=arguments.length <= 3 || arguments[3] === undefined?function(err){}:arguments[3];var self=this;return new Promise(function(resolve,reject){var serverID=self.resolveServerID(server);var memberID=self.resolveUserID(user);request.put(Endpoints.SERVERS + "/" + serverID + "/bans/" + memberID + "?delete-message-days=" + daysToDeleteMessage).set("authorization",self.token).end(function(err,res){cb(err);if(err){reject(err);}else {resolve();}});});};Client.prototype.logout = function logout(){var callback=arguments.length <= 0 || arguments[0] === undefined?function(err){}:arguments[0];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.LOGOUT).set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {self.websocket.close();self.state = 4;callback();resolve();}});});};Client.prototype.createServer = function createServer(name,region){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err,server){}:arguments[2];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.SERVERS).set("authorization",self.token).send({name:name,region:region}).end(function(err,res){if(err){callback(err);reject(err);}else { // potentially redundant in future
// creating here does NOT give us the channels of the server

@@ -35,3 +35,3 @@ // so we must wait for the guild_create event.

var self=this;return new Promise(function(resolve,reject){request.del(Endpoints.SERVERS + "/" + role.server.id + "/roles/" + role.id).set("authorization",self.token).end(function(err){if(err){reject(err);callback(err);}else {resolve();callback();}});});};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){try{var serverId=self.resolveServerID(member.server);var memberId=self.resolveUserID(member);var acServer=self.getServer("id",serverId);var acMember=acServer.getMember("id",memberId);if(acMember.rawRoles.indexOf(role.id) !== -1){ // user already has role
return;}request.patch("https://discordapp.com/api/guilds/" + serverId + "/members/" + memberId).set("authorization",self.token).send({roles:acMember.rawRoles.concat(role.id)}).end(function(err){if(err){reject(err);callback(err);}else {acMember.addRole(role);resolve();callback();}});}catch(e) {reject(e);}});};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){try{var serverId=self.resolveServerID(member.server);var memberId=self.resolveUserID(member);var acServer=self.getServer("id",serverId);var acMember=acServer.getMember("id",memberId);if(~acMember.rawRoles.indexOf(role.id)){acMember.removeRole(role);}request.patch("https://discordapp.com/api/guilds/" + serverId + "/members/" + memberId).set("authorization",self.token).send({roles:acMember.rawRoles}).end(function(err){if(err){reject(err);callback(err);}else {acMember.addRole(role);resolve();callback();}});}catch(e) {reject(e);}});};Client.prototype.overwritePermissions = function overwritePermissions(channel,role,updatedStuff){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err){}:arguments[3];var self=this;return new Promise(function(resolve,reject){function dieerror(e){reject(e);callback(e);}self.resolveDestination(channel).then(next)["catch"](dieerror);function next(channelID){var data;if(role instanceof ServerPermissions || role.type === "role"){data = ad(updatedStuff);data.id = role.id;data.type = "role";}else {data = ad(updatedStuff);data.id = role.id;data.type = "member";}request.put(Endpoints.CHANNELS + "/" + channelID + "/permissions/" + role.id).set("authorization",self.token).send(data).end(function(err){if(err){reject(err);callback(err);}else {resolve();callback();}});}});function ad(data){var allow=0,disallow=0;function bitit(value,position){if(value){allow |= 1 << position;}else {disallow |= 1 << position;}}for(var perm in data) {switch(perm){case "canCreateInstantInvite":bitit(data[perm],0);break;case "manageRoles":bitit(data[perm],3);break;case "manageChannels":bitit(data[perm],4);break;case "readMessages":bitit(data[perm],10);break;case "sendMessages":bitit(data[perm],11);break;case "sendTTSMessages":bitit(data[perm],12);break;case "manageMessages":bitit(data[perm],13);break;case "embedLinks":bitit(data[perm],14);break;case "attachFiles":bitit(data[perm],15);break;case "readMessageHistory":bitit(data[perm],16);break;case "mentionEveryone":bitit(data[perm],17);break;case "voiceConnect":bitit(data[perm],20);break;case "voiceSpeak":bitit(data[perm],21);break;case "voiceMuteMembers":bitit(data[perm],22);break;case "voiceDeafenMembers":bitit(data[perm],23);break;case "voiceMoveMembers":bitit(data[perm],24);break;case "voiceUseVoiceActivation":bitit(data[perm],25);break;default:break;}}return {allow:allow,deny:disallow};}}; //def createws
return;}request.patch("https://discordapp.com/api/guilds/" + serverId + "/members/" + memberId).set("authorization",self.token).send({roles:acMember.rawRoles.concat(role.id)}).end(function(err){if(err){reject(err);callback(err);}else {acMember.addRole(role);resolve();callback();}});}catch(e) {reject(e);}});};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){try{var serverId=self.resolveServerID(member.server);var memberId=self.resolveUserID(member);var acServer=self.getServer("id",serverId);var acMember=acServer.getMember("id",memberId);if(~acMember.rawRoles.indexOf(role.id)){acMember.removeRole(role);}request.patch("https://discordapp.com/api/guilds/" + serverId + "/members/" + memberId).set("authorization",self.token).send({roles:acMember.rawRoles}).end(function(err){if(err){reject(err);callback(err);}else {acMember.addRole(role);resolve();callback();}});}catch(e) {reject(e);}});};Client.prototype.overwritePermissions = function overwritePermissions(channel,role,updatedStuff){var callback=arguments.length <= 3 || arguments[3] === undefined?function(err){}:arguments[3];var self=this;return new Promise(function(resolve,reject){function dieerror(e){reject(e);callback(e);}self.resolveDestination(channel).then(next)["catch"](dieerror);function next(channelID){var data;if(role instanceof ServerPermissions || role.type === "role"){data = ad(updatedStuff);data.id = role.id;data.type = "role";}else {data = ad(updatedStuff);data.id = role.id;data.type = "member";}request.put(Endpoints.CHANNELS + "/" + channelID + "/permissions/" + role.id).set("authorization",self.token).send(data).end(function(err){if(err){reject(err);callback(err);}else {resolve();callback();}});}});function ad(data){var allow=0,disallow=0;function bitit(value,position){if(value){allow |= 1 << position;}else {disallow |= 1 << position;}}for(var perm in data) {switch(perm){case "canCreateInstantInvite":bitit(data[perm],0);break;case "manageRoles":bitit(data[perm],3);break;case "manageChannels":bitit(data[perm],4);break;case "readMessages":bitit(data[perm],10);break;case "sendMessages":bitit(data[perm],11);break;case "sendTTSMessages":bitit(data[perm],12);break;case "manageMessages":bitit(data[perm],13);break;case "embedLinks":bitit(data[perm],14);break;case "attachFiles":bitit(data[perm],15);break;case "readMessageHistory":bitit(data[perm],16);break;case "mentionEveryone":bitit(data[perm],17);break;case "voiceConnect":bitit(data[perm],20);break;case "voiceSpeak":bitit(data[perm],21);break;case "voiceMuteMembers":bitit(data[perm],22);break;case "voiceDeafenMembers":bitit(data[perm],23);break;case "voiceMoveMembers":bitit(data[perm],24);break;case "voiceUseVoiceActivation":bitit(data[perm],25);break;default:break;}}return {allow:allow,deny:disallow};}};Client.prototype.getBans = function getBans(serverResource){var callback=arguments.length <= 1 || arguments[1] === undefined?function(err,arrayOfBans){}:arguments[1];var self=this;return new Promise(function(resolve,reject){var serverID=self.resolveServerID(serverResource);request.get(Endpoints.SERVERS + "/" + serverID + "/bans").set("authorization",self.token).end(function(err,res){if(err){callback(err);reject(err);}else {var banList=[];for(var _iterator5=res.body,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var user=_ref5;banList.push(self.addUser(user.user));}callback(null,banList);resolve(banList);}});});}; //def createws
Client.prototype.createws = function createws(url){if(this.websocket)return false;var self=this; //good to go

@@ -43,8 +43,8 @@ this.websocket = new WebSocket(url); //open

this.websocket.onmessage = function(e){if(e.type === "Binary"){if(!zlib)zlib = require("zlib");e.data = zlib.inflateSync(e.data).toString();}var dat=false,data={};try{dat = JSON.parse(e.data);data = dat.d;}catch(err) {self.emit("error",err,e);return;}self.emit("raw",dat); //valid message
switch(dat.t){case "READY":self.debug("received ready packet");self.user = self.addUser(data.user);for(var _iterator5=data.guilds,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var _server=_ref5;var server=self.addServer(_server);}for(var _iterator6=data.private_channels,_isArray6=Array.isArray(_iterator6),_i6=0,_iterator6=_isArray6?_iterator6:_iterator6[Symbol.iterator]();;) {var _ref6;if(_isArray6){if(_i6 >= _iterator6.length)break;_ref6 = _iterator6[_i6++];}else {_i6 = _iterator6.next();if(_i6.done)break;_ref6 = _i6.value;}var _pmc=_ref6;var pmc=self.addPMChannel(_pmc);}self.emit("ready");self.readyTime = Date.now();self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users.");self.state = 3;setInterval(function(){self.keepAlive.apply(self);},data.heartbeat_interval);break;case "MESSAGE_CREATE":self.debug("received message");var mentions=[];data.mentions = data.mentions || []; //for some reason this was not defined at some point?
var channel=self.getChannel("id",data.channel_id);for(var _iterator7=data.mentions,_isArray7=Array.isArray(_iterator7),_i7=0,_iterator7=_isArray7?_iterator7:_iterator7[Symbol.iterator]();;) {var _ref7;if(_isArray7){if(_i7 >= _iterator7.length)break;_ref7 = _iterator7[_i7++];}else {_i7 = _iterator7.next();if(_i7.done)break;_ref7 = _i7.value;}var mention=_ref7;var user=self.addUser(mention);if(channel.server)mentions.push(channel.server.getMember("id",user.id) || user);else mentions.push(user);}if(channel){var msg=channel.addMessage(new Message(data,channel,mentions,data.author));self.emit("message",msg);}break;case "MESSAGE_DELETE":self.debug("message deleted");var channel=self.getChannel("id",data.channel_id);var message=channel.getMessage("id",data.id);if(message){self.emit("messageDelete",channel,message);channel.messages.splice(channel.messages.indexOf(message),1);}else { //don't have the cache of that message ;(
switch(dat.t){case "READY":self.debug("received ready packet");self.user = self.addUser(data.user);for(var _iterator6=data.guilds,_isArray6=Array.isArray(_iterator6),_i6=0,_iterator6=_isArray6?_iterator6:_iterator6[Symbol.iterator]();;) {var _ref6;if(_isArray6){if(_i6 >= _iterator6.length)break;_ref6 = _iterator6[_i6++];}else {_i6 = _iterator6.next();if(_i6.done)break;_ref6 = _i6.value;}var _server=_ref6;var server=self.addServer(_server);}for(var _iterator7=data.private_channels,_isArray7=Array.isArray(_iterator7),_i7=0,_iterator7=_isArray7?_iterator7:_iterator7[Symbol.iterator]();;) {var _ref7;if(_isArray7){if(_i7 >= _iterator7.length)break;_ref7 = _iterator7[_i7++];}else {_i7 = _iterator7.next();if(_i7.done)break;_ref7 = _i7.value;}var _pmc=_ref7;var pmc=self.addPMChannel(_pmc);}self.emit("ready");self.readyTime = Date.now();self.debug("cached " + self.serverCache.length + " servers, " + self.channelCache.length + " channels, " + self.pmChannelCache.length + " PMs and " + self.userCache.length + " users.");self.state = 3;setInterval(function(){self.keepAlive.apply(self);},data.heartbeat_interval);break;case "MESSAGE_CREATE":self.debug("received message");var mentions=[];data.mentions = data.mentions || []; //for some reason this was not defined at some point?
var channel=self.getChannel("id",data.channel_id);for(var _iterator8=data.mentions,_isArray8=Array.isArray(_iterator8),_i8=0,_iterator8=_isArray8?_iterator8:_iterator8[Symbol.iterator]();;) {var _ref8;if(_isArray8){if(_i8 >= _iterator8.length)break;_ref8 = _iterator8[_i8++];}else {_i8 = _iterator8.next();if(_i8.done)break;_ref8 = _i8.value;}var mention=_ref8;var user=self.addUser(mention);if(channel.server)mentions.push(channel.server.getMember("id",user.id) || user);else mentions.push(user);}if(channel){var msg=channel.addMessage(new Message(data,channel,mentions,data.author));self.emit("message",msg);}break;case "MESSAGE_DELETE":self.debug("message deleted");var channel=self.getChannel("id",data.channel_id);var message=channel.getMessage("id",data.id);if(message){self.emit("messageDelete",channel,message);channel.messages.splice(channel.messages.indexOf(message),1);}else { //don't have the cache of that message ;(
self.emit("messageDelete",channel);}break;case "MESSAGE_UPDATE":self.debug("message updated");var channel=self.getChannel("id",data.channel_id);var formerMessage=channel.getMessage("id",data.id);if(formerMessage){ //new message might be partial, so we need to fill it with whatever the old message was.
var info={};for(var key in formerMessage) {info[key] = formerMessage[key];}for(var key in data) {info[key] = data[key];}data.mentions = data.mentions || [];var mentions=[];for(var _iterator8=data.mentions,_isArray8=Array.isArray(_iterator8),_i8=0,_iterator8=_isArray8?_iterator8:_iterator8[Symbol.iterator]();;) {var _ref8;if(_isArray8){if(_i8 >= _iterator8.length)break;_ref8 = _iterator8[_i8++];}else {_i8 = _iterator8.next();if(_i8.done)break;_ref8 = _i8.value;}var mention=_ref8;var user=self.addUser(mention);if(channel.server)mentions.push(channel.server.getMember("id",user.id) || user);else mentions.push(user);}var newMessage=new Message(info,channel,mentions,formerMessage.author);self.emit("messageUpdate",newMessage,formerMessage);channel.messages[channel.messages.indexOf(formerMessage)] = newMessage;} // message isn't in cache, and if it's a partial it could cause
var info={};for(var key in formerMessage) {info[key] = formerMessage[key];}for(var key in data) {info[key] = data[key];}data.mentions = data.mentions || [];var mentions=[];for(var _iterator9=data.mentions,_isArray9=Array.isArray(_iterator9),_i9=0,_iterator9=_isArray9?_iterator9:_iterator9[Symbol.iterator]();;) {var _ref9;if(_isArray9){if(_i9 >= _iterator9.length)break;_ref9 = _iterator9[_i9++];}else {_i9 = _iterator9.next();if(_i9.done)break;_ref9 = _i9.value;}var mention=_ref9;var user=self.addUser(mention);if(channel.server)mentions.push(channel.server.getMember("id",user.id) || user);else mentions.push(user);}var newMessage=new Message(info,channel,mentions,formerMessage.author);self.emit("messageUpdate",newMessage,formerMessage);channel.messages[channel.messages.indexOf(formerMessage)] = newMessage;} // message isn't in cache, and if it's a partial it could cause
// all hell to break loose... best to just act as if nothing happened
break;case "GUILD_DELETE":var server=self.getServer("id",data.id);if(server){self.serverCache.splice(self.serverCache.indexOf(server),1);self.emit("serverDelete",server);}break;case "GUILD_BAN_ADD":var bannedUser=self.addUser(data.user);var server=self.getServer("id",data.guild_id);self.emit("userBanned",bannedUser,server);case "CHANNEL_DELETE":var channel=self.getChannel("id",data.id);if(channel){var server=channel.server;if(server){server.channels.splice(server.channels.indexOf(channel),1);}self.emit("channelDelete",channel);self.serverCache.splice(self.serverCache.indexOf(channel),1);}break;case "GUILD_CREATE":var server=self.getServer("id",data.id);if(!server){ //if server doesn't already exist because duh
break;case "GUILD_DELETE":var server=self.getServer("id",data.id);if(server){self.serverCache.splice(self.serverCache.indexOf(server),1);self.emit("serverDelete",server);}break;case "GUILD_BAN_ADD":var bannedUser=self.addUser(data.user);var server=self.getServer("id",data.guild_id);self.emit("userBanned",bannedUser,server);break;case "GUILD_BAN_REMOVE":var bannedUser=self.addUser(data.user);var server=self.getServer("id",data.guild_id);self.emiter("userUnbanned",bannedUser,server);break;case "CHANNEL_DELETE":var channel=self.getChannel("id",data.id);if(channel){self.channelCache.splice(self.channelCache.indexOf(channel),1);server.channels.splice(server.channels.indexOf(channel),1);self.emit("channelDelete",channel);}break;case "GUILD_UPDATE":var server=self.getServer("id",data.id);var newserver=self.addServer(data,true);self.serverCache.splice(self.serverCache.indexOf(server),1);self.emit("serverUpdate",server,newserver);break;case "GUILD_CREATE":var server=self.getServer("id",data.id);if(!server){ //if server doesn't already exist because duh
server = self.addServer(data);} /*else if(server.channels.length === 0){

@@ -70,13 +70,13 @@

Client.prototype.addChannel = function addChannel(data,serverId){if(!this.getChannel("id",data.id)){this.channelCache.push(new Channel(data,this.getServer("id",serverId)));}return this.getChannel("id",data.id);};Client.prototype.addPMChannel = function addPMChannel(data){if(!this.getPMChannel("id",data.id)){this.pmChannelCache.push(new PMChannel(data,this));}return this.getPMChannel("id",data.id);};Client.prototype.setTopic = function setTopic(channel,topic){var callback=arguments.length <= 2 || arguments[2] === undefined?function(err){}:arguments[2];var self=this;return new Promise(function(resolve,reject){self.resolveDestination(channel).then(next)["catch"](error);function error(e){callback(e);reject(e);}function next(destination){var asChan=self.getChannel("id",destination);request.patch(Endpoints.CHANNELS + "/" + destination).set("authorization",self.token).send({name:asChan.name,position:0,topic:topic}).end(function(err,res){if(err){error(err);}else {asChan.topic = res.body.topic;resolve();callback();}});}});}; //def addServer
Client.prototype.addServer = function addServer(data){var self=this;var server=this.getServer("id",data.id);if(data.unavailable){self.emit("unavailable",data);self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached.");return;}if(!server){server = new Server(data,this);this.serverCache.push(server);if(data.channels){for(var _iterator9=data.channels,_isArray9=Array.isArray(_iterator9),_i9=0,_iterator9=_isArray9?_iterator9:_iterator9[Symbol.iterator]();;) {var _ref9;if(_isArray9){if(_i9 >= _iterator9.length)break;_ref9 = _iterator9[_i9++];}else {_i9 = _iterator9.next();if(_i9.done)break;_ref9 = _i9.value;}var channel=_ref9;server.channels.push(this.addChannel(channel,server.id));}}}for(var _iterator10=data.presences,_isArray10=Array.isArray(_iterator10),_i10=0,_iterator10=_isArray10?_iterator10:_iterator10[Symbol.iterator]();;) {var _ref10;if(_isArray10){if(_i10 >= _iterator10.length)break;_ref10 = _iterator10[_i10++];}else {_i10 = _iterator10.next();if(_i10.done)break;_ref10 = _i10.value;}var presence=_ref10;var user=self.getUser("id",presence.user.id);user.status = presence.status;user.gameId = presence.game_id;}return server;}; //def getUser
Client.prototype.getUser = function getUser(key,value){for(var _iterator11=this.userCache,_isArray11=Array.isArray(_iterator11),_i11=0,_iterator11=_isArray11?_iterator11:_iterator11[Symbol.iterator]();;) {var _ref11;if(_isArray11){if(_i11 >= _iterator11.length)break;_ref11 = _iterator11[_i11++];}else {_i11 = _iterator11.next();if(_i11.done)break;_ref11 = _i11.value;}var user=_ref11;if(user[key] === value){return user;}}return null;}; //def getChannel
Client.prototype.getChannel = function getChannel(key,value){for(var _iterator12=this.channelCache,_isArray12=Array.isArray(_iterator12),_i12=0,_iterator12=_isArray12?_iterator12:_iterator12[Symbol.iterator]();;) {var _ref12;if(_isArray12){if(_i12 >= _iterator12.length)break;_ref12 = _iterator12[_i12++];}else {_i12 = _iterator12.next();if(_i12.done)break;_ref12 = _i12.value;}var channel=_ref12;if(channel[key] === value){return channel;}}return this.getPMChannel(key,value); //might be a PM
};Client.prototype.getPMChannel = function getPMChannel(key,value){for(var _iterator13=this.pmChannelCache,_isArray13=Array.isArray(_iterator13),_i13=0,_iterator13=_isArray13?_iterator13:_iterator13[Symbol.iterator]();;) {var _ref13;if(_isArray13){if(_i13 >= _iterator13.length)break;_ref13 = _iterator13[_i13++];}else {_i13 = _iterator13.next();if(_i13.done)break;_ref13 = _i13.value;}var channel=_ref13;if(channel[key] === value){return channel;}}return null;}; //def getServer
Client.prototype.getServer = function getServer(key,value){for(var _iterator14=this.serverCache,_isArray14=Array.isArray(_iterator14),_i14=0,_iterator14=_isArray14?_iterator14:_iterator14[Symbol.iterator]();;) {var _ref14;if(_isArray14){if(_i14 >= _iterator14.length)break;_ref14 = _iterator14[_i14++];}else {_i14 = _iterator14.next();if(_i14.done)break;_ref14 = _i14.value;}var server=_ref14;if(server[key] === value){return server;}}return null;}; //def trySendConnData
Client.prototype.addServer = function addServer(data){var force=arguments.length <= 1 || arguments[1] === undefined?false:arguments[1];var self=this;var server=this.getServer("id",data.id);if(data.unavailable){self.emit("unavailable",data);self.debug("Server ID " + data.id + " has been marked unavailable by Discord. It was not cached.");return;}if(!server || force){server = new Server(data,this);this.serverCache.push(server);if(data.channels){for(var _iterator10=data.channels,_isArray10=Array.isArray(_iterator10),_i10=0,_iterator10=_isArray10?_iterator10:_iterator10[Symbol.iterator]();;) {var _ref10;if(_isArray10){if(_i10 >= _iterator10.length)break;_ref10 = _iterator10[_i10++];}else {_i10 = _iterator10.next();if(_i10.done)break;_ref10 = _i10.value;}var channel=_ref10;server.channels.push(this.addChannel(channel,server.id));}}if(data.presences){for(var _iterator11=data.presences,_isArray11=Array.isArray(_iterator11),_i11=0,_iterator11=_isArray11?_iterator11:_iterator11[Symbol.iterator]();;) {var _ref11;if(_isArray11){if(_i11 >= _iterator11.length)break;_ref11 = _iterator11[_i11++];}else {_i11 = _iterator11.next();if(_i11.done)break;_ref11 = _i11.value;}var presence=_ref11;var user=self.getUser("id",presence.user.id);user.status = presence.status;user.gameId = presence.game_id;}}}return server;}; //def getUser
Client.prototype.getUser = function getUser(key,value){for(var _iterator12=this.userCache,_isArray12=Array.isArray(_iterator12),_i12=0,_iterator12=_isArray12?_iterator12:_iterator12[Symbol.iterator]();;) {var _ref12;if(_isArray12){if(_i12 >= _iterator12.length)break;_ref12 = _iterator12[_i12++];}else {_i12 = _iterator12.next();if(_i12.done)break;_ref12 = _i12.value;}var user=_ref12;if(user[key] === value){return user;}}return null;}; //def getChannel
Client.prototype.getChannel = function getChannel(key,value){for(var _iterator13=this.channelCache,_isArray13=Array.isArray(_iterator13),_i13=0,_iterator13=_isArray13?_iterator13:_iterator13[Symbol.iterator]();;) {var _ref13;if(_isArray13){if(_i13 >= _iterator13.length)break;_ref13 = _iterator13[_i13++];}else {_i13 = _iterator13.next();if(_i13.done)break;_ref13 = _i13.value;}var channel=_ref13;if(channel[key] === value){return channel;}}return this.getPMChannel(key,value); //might be a PM
};Client.prototype.getPMChannel = function getPMChannel(key,value){for(var _iterator14=this.pmChannelCache,_isArray14=Array.isArray(_iterator14),_i14=0,_iterator14=_isArray14?_iterator14:_iterator14[Symbol.iterator]();;) {var _ref14;if(_isArray14){if(_i14 >= _iterator14.length)break;_ref14 = _iterator14[_i14++];}else {_i14 = _iterator14.next();if(_i14.done)break;_ref14 = _i14.value;}var channel=_ref14;if(channel[key] === value){return channel;}}return null;}; //def getServer
Client.prototype.getServer = function getServer(key,value){for(var _iterator15=this.serverCache,_isArray15=Array.isArray(_iterator15),_i15=0,_iterator15=_isArray15?_iterator15:_iterator15[Symbol.iterator]();;) {var _ref15;if(_isArray15){if(_i15 >= _iterator15.length)break;_ref15 = _iterator15[_i15++];}else {_i15 = _iterator15.next();if(_i15.done)break;_ref15 = _i15.value;}var server=_ref15;if(server[key] === value){return server;}}return null;}; //def trySendConnData
Client.prototype.trySendConnData = function trySendConnData(){var self=this;if(this.token && !this.alreadySentData){this.alreadySentData = true;var data={op:2,d:{token:this.token,v:3,properties:{"$os":"discord.js","$browser":"discord.js","$device":"discord.js","$referrer":"","$referring_domain":""},compress:self.options.compress}};this.websocket.send(JSON.stringify(data));}};Client.prototype.resolveServerID = function resolveServerID(resource){if(resource instanceof Server){return resource.id;}else if(resource instanceof Channel){return resource.server.id;}else if(resource instanceof Message){return resource.channel.server.id;}else {return resource;}};Client.prototype.resolveUserID = function resolveUserID(resource){if(resource instanceof User){ // also accounts for Member
return resource.id;}else {return resource;}};Client.prototype.resolveDestination = function resolveDestination(destination){var channId=false;var self=this;return new Promise(function(resolve,reject){if(destination instanceof Server){channId = destination.id; //general is the same as server id
}else if(destination instanceof Channel){channId = destination.id;}else if(destination instanceof Message){channId = destination.channel.id;}else if(destination instanceof PMChannel){channId = destination.id;}else if(destination instanceof User){ //check if we have a PM
for(var _iterator15=self.pmChannelCache,_isArray15=Array.isArray(_iterator15),_i15=0,_iterator15=_isArray15?_iterator15:_iterator15[Symbol.iterator]();;) {var _ref15;if(_isArray15){if(_i15 >= _iterator15.length)break;_ref15 = _iterator15[_i15++];}else {_i15 = _iterator15.next();if(_i15.done)break;_ref15 = _i15.value;}var pmc=_ref15;if(pmc.user && pmc.user.equals(destination)){resolve(pmc.id);return;}} //we don't, at this point we're late
for(var _iterator16=self.pmChannelCache,_isArray16=Array.isArray(_iterator16),_i16=0,_iterator16=_isArray16?_iterator16:_iterator16[Symbol.iterator]();;) {var _ref16;if(_isArray16){if(_i16 >= _iterator16.length)break;_ref16 = _iterator16[_i16++];}else {_i16 = _iterator16.next();if(_i16.done)break;_ref16 = _i16.value;}var pmc=_ref16;if(pmc.user && pmc.user.equals(destination)){resolve(pmc.id);return;}} //we don't, at this point we're late
self.startPM(destination).then(function(pmc){resolve(pmc.id);})["catch"](reject);}else {channId = destination;}if(channId)resolve(channId);else reject();});};Client.prototype._sendMessage = function _sendMessage(destination,content,options,mentions){var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization",self.token).send({content:content,mentions:mentions,tts:options.tts}).end(function(err,res){if(err){reject(err);}else {var data=res.body;var mentions=[];data.mentions = data.mentions || []; //for some reason this was not defined at some point?
var channel=self.getChannel("id",data.channel_id);for(var _iterator16=data.mentions,_isArray16=Array.isArray(_iterator16),_i16=0,_iterator16=_isArray16?_iterator16:_iterator16[Symbol.iterator]();;) {var _ref16;if(_isArray16){if(_i16 >= _iterator16.length)break;_ref16 = _iterator16[_i16++];}else {_i16 = _iterator16.next();if(_i16.done)break;_ref16 = _i16.value;}var mention=_ref16;var user=self.addUser(mention);if(channel.server)mentions.push(channel.server.getMember("id",user.id) || user);else mentions.push(user);}if(channel){var msg=channel.addMessage(new Message(data,channel,mentions,{id:data.author.id}));resolve(msg);}}});});};Client.prototype._sendFile = function _sendFile(destination,attachment){var attachmentName=arguments.length <= 2 || arguments[2] === undefined?"DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png":arguments[2];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization",self.token).attach("file",attachment,attachmentName).end(function(err,res){if(err){reject(err);}else {var chann=self.getChannel("id",destination);if(chann){var msg=chann.addMessage(new Message(res.body,chann,[],self.user));resolve(msg);}}});});};Client.prototype._updateMessage = function _updateMessage(message,content){var self=this;return new Promise(function(resolve,reject){request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization",self.token).send({content:content,mentions:[]}).end(function(err,res){if(err){reject(err);}else {var msg=new Message(res.body,message.channel,message.mentions,message.sender);resolve(msg);message.channel.messages[message.channel.messages.indexOf(message)] = msg;}});});};Client.prototype.getGateway = function getGateway(){var self=this;return new Promise(function(resolve,reject){request.get(Endpoints.API + "/gateway").set("authorization",self.token).end(function(err,res){if(err){reject(err);}else {resolve(res.body.url);}});});};Client.prototype.setStatusIdle = function setStatusIdle(){this.setStatus("idle");};Client.prototype.setStatusOnline = function setStatusOnline(){this.setStatus("online");};Client.prototype.setStatusActive = function setStatusActive(){this.setStatusOnline();};Client.prototype.setStatusHere = function setStatusHere(){this.setStatusOnline();};Client.prototype.setStatusAway = function setStatusAway(){this.setStatusIdle();};Client.prototype.startTyping = function startTyping(chann,stopTypeTime){var self=this;this.resolveDestination(chann).then(next);function next(channel){if(self.typingIntervals[channel]){return;}var fn=function fn(){request.post(Endpoints.CHANNELS + "/" + channel + "/typing").set("authorization",self.token).end();};fn();var interval=setInterval(fn,3000);self.typingIntervals[channel] = interval;if(stopTypeTime){setTimeout(function(){self.stopTyping(channel);},stopTypeTime);}}};Client.prototype.stopTyping = function stopTyping(chann){var self=this;this.resolveDestination(chann).then(next);function next(channel){if(!self.typingIntervals[channel]){return;}clearInterval(self.typingIntervals[channel]);delete self.typingIntervals[channel];}};Client.prototype.setStatus = function setStatus(stat){var idleTime=stat === "online"?null:Date.now();this.__idleTime = idleTime;this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}));};Client.prototype.setPlayingGame = function setPlayingGame(id){if(id instanceof String || typeof id === "string"){ // working on names
var gid=id.trim().toUpperCase();id = null;for(var _iterator17=gameMap,_isArray17=Array.isArray(_iterator17),_i17=0,_iterator17=_isArray17?_iterator17:_iterator17[Symbol.iterator]();;) {var _ref17;if(_isArray17){if(_i17 >= _iterator17.length)break;_ref17 = _iterator17[_i17++];}else {_i17 = _iterator17.next();if(_i17.done)break;_ref17 = _i17.value;}var game=_ref17;if(game.name.trim().toUpperCase() === gid){id = game.id;break;}}}this.__gameId = id;this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}));};Client.prototype.playGame = function playGame(id){this.setPlayingGame(id);};Client.prototype.playingGame = function playingGame(id){this.setPlayingGame(id);};Client.prototype.resolveInvite = function resolveInvite(resource){if(resource instanceof Invite){return resource.code;}else if(typeof resource == "string" || resource instanceof String){if(resource.indexOf("http") === 0){var split=resource.split("/");return split.pop();}else {return resource;}}};_createClass(Client,[{key:"uptime",get:function get(){return this.readyTime?Date.now() - this.readyTime:null;}},{key:"ready",get:function get(){return this.state === 3;}},{key:"servers",get:function get(){return this.serverCache;}},{key:"channels",get:function get(){return this.channelCache;}},{key:"users",get:function get(){return this.userCache;}},{key:"PMChannels",get:function get(){return this.pmChannelCache;}},{key:"messages",get:function get(){var msgs=[];for(var _iterator18=this.channelCache,_isArray18=Array.isArray(_iterator18),_i18=0,_iterator18=_isArray18?_iterator18:_iterator18[Symbol.iterator]();;) {var _ref18;if(_isArray18){if(_i18 >= _iterator18.length)break;_ref18 = _iterator18[_i18++];}else {_i18 = _iterator18.next();if(_i18.done)break;_ref18 = _i18.value;}var channel=_ref18;msgs = msgs.concat(channel.messages);}return msgs;}}]);return Client;})(EventEmitter);module.exports = Client;
var channel=self.getChannel("id",data.channel_id);for(var _iterator17=data.mentions,_isArray17=Array.isArray(_iterator17),_i17=0,_iterator17=_isArray17?_iterator17:_iterator17[Symbol.iterator]();;) {var _ref17;if(_isArray17){if(_i17 >= _iterator17.length)break;_ref17 = _iterator17[_i17++];}else {_i17 = _iterator17.next();if(_i17.done)break;_ref17 = _i17.value;}var mention=_ref17;var user=self.addUser(mention);if(channel.server)mentions.push(channel.server.getMember("id",user.id) || user);else mentions.push(user);}if(channel){var msg=channel.addMessage(new Message(data,channel,mentions,{id:data.author.id}));resolve(msg);}}});});};Client.prototype._sendFile = function _sendFile(destination,attachment){var attachmentName=arguments.length <= 2 || arguments[2] === undefined?"DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png":arguments[2];var self=this;return new Promise(function(resolve,reject){request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization",self.token).attach("file",attachment,attachmentName).end(function(err,res){if(err){reject(err);}else {var chann=self.getChannel("id",destination);if(chann){var msg=chann.addMessage(new Message(res.body,chann,[],self.user));resolve(msg);}}});});};Client.prototype._updateMessage = function _updateMessage(message,content){var self=this;return new Promise(function(resolve,reject){request.patch(Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id).set("authorization",self.token).send({content:content,mentions:[]}).end(function(err,res){if(err){reject(err);}else {var msg=new Message(res.body,message.channel,message.mentions,message.sender);resolve(msg);message.channel.messages[message.channel.messages.indexOf(message)] = msg;}});});};Client.prototype.getGateway = function getGateway(){var self=this;return new Promise(function(resolve,reject){request.get(Endpoints.API + "/gateway").set("authorization",self.token).end(function(err,res){if(err){reject(err);}else {resolve(res.body.url);}});});};Client.prototype.setStatusIdle = function setStatusIdle(){this.setStatus("idle");};Client.prototype.setStatusOnline = function setStatusOnline(){this.setStatus("online");};Client.prototype.setStatusActive = function setStatusActive(){this.setStatusOnline();};Client.prototype.setStatusHere = function setStatusHere(){this.setStatusOnline();};Client.prototype.setStatusAway = function setStatusAway(){this.setStatusIdle();};Client.prototype.startTyping = function startTyping(chann,stopTypeTime){var self=this;this.resolveDestination(chann).then(next);function next(channel){if(self.typingIntervals[channel]){return;}var fn=function fn(){request.post(Endpoints.CHANNELS + "/" + channel + "/typing").set("authorization",self.token).end();};fn();var interval=setInterval(fn,3000);self.typingIntervals[channel] = interval;if(stopTypeTime){setTimeout(function(){self.stopTyping(channel);},stopTypeTime);}}};Client.prototype.stopTyping = function stopTyping(chann){var self=this;this.resolveDestination(chann).then(next);function next(channel){if(!self.typingIntervals[channel]){return;}clearInterval(self.typingIntervals[channel]);delete self.typingIntervals[channel];}};Client.prototype.setStatus = function setStatus(stat){var idleTime=stat === "online"?null:Date.now();this.__idleTime = idleTime;this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}));};Client.prototype.setPlayingGame = function setPlayingGame(id){if(id instanceof String || typeof id === "string"){ // working on names
var gid=id.trim().toUpperCase();id = null;for(var _iterator18=gameMap,_isArray18=Array.isArray(_iterator18),_i18=0,_iterator18=_isArray18?_iterator18:_iterator18[Symbol.iterator]();;) {var _ref18;if(_isArray18){if(_i18 >= _iterator18.length)break;_ref18 = _iterator18[_i18++];}else {_i18 = _iterator18.next();if(_i18.done)break;_ref18 = _i18.value;}var game=_ref18;if(game.name.trim().toUpperCase() === gid){id = game.id;break;}}}this.__gameId = id;this.websocket.send(JSON.stringify({op:3,d:{idle_since:this.__idleTime,game_id:this.__gameId}}));};Client.prototype.playGame = function playGame(id){this.setPlayingGame(id);};Client.prototype.playingGame = function playingGame(id){this.setPlayingGame(id);};Client.prototype.resolveInvite = function resolveInvite(resource){if(resource instanceof Invite){return resource.code;}else if(typeof resource == "string" || resource instanceof String){if(resource.indexOf("http") === 0){var split=resource.split("/");return split.pop();}else {return resource;}}};_createClass(Client,[{key:"uptime",get:function get(){return this.readyTime?Date.now() - this.readyTime:null;}},{key:"ready",get:function get(){return this.state === 3;}},{key:"servers",get:function get(){return this.serverCache;}},{key:"channels",get:function get(){return this.channelCache;}},{key:"users",get:function get(){return this.userCache;}},{key:"PMChannels",get:function get(){return this.pmChannelCache;}},{key:"messages",get:function get(){var msgs=[];for(var _iterator19=this.channelCache,_isArray19=Array.isArray(_iterator19),_i19=0,_iterator19=_isArray19?_iterator19:_iterator19[Symbol.iterator]();;) {var _ref19;if(_isArray19){if(_i19 >= _iterator19.length)break;_ref19 = _iterator19[_i19++];}else {_i19 = _iterator19.next();if(_i19.done)break;_ref19 = _i19.value;}var channel=_ref19;msgs = msgs.concat(channel.messages);}return msgs;}}]);return Client;})(EventEmitter);module.exports = Client;

@@ -1,1 +0,1 @@

"use strict";var request=require("superagent");var Endpoints=require("./Endpoints.js");var Client=require("./Client.js");var Color=require("../ref/colours.js");var Discord={Endpoints:Endpoints,Client:Client,Color:Color,User:require("./user.js"),Server:require("./server.js"),Channel:require("./channel.js"),Message:require("./message.js"),Invite:require("./invite.js"),PMChannel:require("./PMChannel.js"),ServerPermissions:require("./ServerPermissions.js"),ChannelPermissions:require("./ChannelPermissions.js"),EvaluatedPermissiosn:require("./EvaluatedPermissions.js"),VoiceChannel:require("./VoiceChannel.js"),gameMap:require("../ref/gameMap.json")};Discord.patchStrings = function(){defineProperty("bold","**");defineProperty("underline","__");defineProperty("strike","~~");defineProperty("code","`");defineProperty("codeblock","```");defineProperty("newline","\n");Object.defineProperty(String.prototype,"italic",{get:function get(){return "*" + this + "*";}});function defineProperty(name,joiner){Object.defineProperty(String.prototype,name,{get:function get(){return joiner + this + joiner;}});}};module.exports = Discord;
"use strict";var request=require("superagent");var Endpoints=require("./Endpoints.js");var Client=require("./Client.js");var Color=require("../ref/colours.js");var Discord={Endpoints:Endpoints,Client:Client,Color:Color,User:require("./user.js"),Server:require("./server.js"),Channel:require("./channel.js"),Message:require("./message.js"),Invite:require("./invite.js"),PMChannel:require("./PMChannel.js"),ServerPermissions:require("./ServerPermissions.js"),ChannelPermissions:require("./ChannelPermissions.js"),EvaluatedPermissiosn:require("./EvaluatedPermissions.js"),VoiceChannel:require("./VoiceChannel.js"),gameMap:require("../ref/gameMap.json"),Embed:require("./Embeds/Embed.js"),LinkEmbed:require("./Embeds/LinkEmbed.js"),VideoEmbed:require("./Embeds/VideoEmbed.js"),ImageEmbed:require("./Embeds/ImageEmbed.js")};Discord.patchStrings = function(){defineProperty("bold","**");defineProperty("underline","__");defineProperty("strike","~~");defineProperty("code","`");defineProperty("codeblock","```");defineProperty("newline","\n");Object.defineProperty(String.prototype,"italic",{get:function get(){return "*" + this + "*";}});function defineProperty(name,joiner){Object.defineProperty(String.prototype,name,{get:function get(){return joiner + this + joiner;}});}};module.exports = Discord;
"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _inherits(subClass,superClass){if(typeof superClass !== "function" && superClass !== null){throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__ = superClass;}var User=require("./user.js");var ServerPermissions=require("./ServerPermissions.js");var EvaluatedPermissions=require("./EvaluatedPermissions.js");var Member=(function(_User){_inherits(Member,_User);function Member(user,server,roles){_classCallCheck(this,Member);_User.call(this,user); // should work, we are basically creating a Member that has the same properties as user and a few more
this.server = server;this.rawRoles = roles;}Member.prototype.removeRole = function removeRole(role){this.rawRoles.splice(this.rawRoles.indexOf(role.id),1);};Member.prototype.addRole = function addRole(role){if(this.rawRoles.indexOf(role.id) == -1){this.rawRoles.push(role.id);}};Member.prototype.hasRole = function hasRole(role){for(var _iterator=this.roles,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var _role=_ref;if(role.id === _role.id)return true;}return false;};Member.prototype.permissionsIn = function permissionsIn(channel){if(channel.server.ownerID === this.id){return new EvaluatedPermissions(4294967295); //all perms
}var affectingOverwrites=[];var affectingMemberOverwrites=[];for(var _iterator2=channel.roles,_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;if(overwrite.id === this.id && overwrite.type === "member"){affectingMemberOverwrites.push(overwrite);}else if(this.rawRoles.indexOf(overwrite.id) !== -1){affectingOverwrites.push(overwrite);}}if(affectingOverwrites.length === 0 && affectingMemberOverwrites.length === 0){return new EvaluatedPermissions(this.evalPerms.packed);}var finalPacked=affectingOverwrites.length !== 0?affectingOverwrites[0].packed:affectingMemberOverwrites[0].packed;for(var _iterator3=affectingOverwrites,_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[Symbol.iterator]();;) {var _ref3;if(_isArray3){if(_i3 >= _iterator3.length)break;_ref3 = _iterator3[_i3++];}else {_i3 = _iterator3.next();if(_i3.done)break;_ref3 = _i3.value;}var overwrite=_ref3;finalPacked = finalPacked & ~overwrite.deny;finalPacked = finalPacked | overwrite.allow;}for(var _iterator4=affectingMemberOverwrites,_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[Symbol.iterator]();;) {var _ref4;if(_isArray4){if(_i4 >= _iterator4.length)break;_ref4 = _iterator4[_i4++];}else {_i4 = _iterator4.next();if(_i4.done)break;_ref4 = _i4.value;}var overwrite=_ref4;finalPacked = finalPacked & ~overwrite.deny;finalPacked = finalPacked | overwrite.allow;}return new EvaluatedPermissions(finalPacked);};_createClass(Member,[{key:"roles",get:function get(){var ufRoles=[this.server.getRole("id",this.server.id)];for(var _iterator5=this.rawRoles,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var rawRole=_ref5;ufRoles.push(this.server.getRole("id",rawRole));}return ufRoles;}},{key:"evalPerms",get:function get(){var basePerms=this.roles, //cache roles as it can be slightly expensive
basePerm=basePerms[0].packed;basePerms = basePerms || [];for(var _iterator6=basePerms,_isArray6=Array.isArray(_iterator6),_i6=0,_iterator6=_isArray6?_iterator6:_iterator6[Symbol.iterator]();;) {var _ref6;if(_isArray6){if(_i6 >= _iterator6.length)break;_ref6 = _iterator6[_i6++];}else {_i6 = _iterator6.next();if(_i6.done)break;_ref6 = _i6.value;}var perm=_ref6;basePerm = basePerm | perm.packed;}return new ServerPermissions({permissions:basePerm});}}]);return Member;})(User);module.exports = Member;
this.serverID = server.id;this.client = server.client;this.rawRoles = roles;}Member.prototype.removeRole = function removeRole(role){this.rawRoles.splice(this.rawRoles.indexOf(role.id),1);};Member.prototype.addRole = function addRole(role){if(this.rawRoles.indexOf(role.id) == -1){this.rawRoles.push(role.id);}};Member.prototype.hasRole = function hasRole(role){for(var _iterator=this.roles,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var _role=_ref;if(role.id === _role.id)return true;}return false;};Member.prototype.permissionsIn = function permissionsIn(channel){if(channel.server.ownerID === this.id){return new EvaluatedPermissions(4294967295); //all perms
}var affectingOverwrites=[];var affectingMemberOverwrites=[];for(var _iterator2=channel.roles,_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;if(overwrite.id === this.id && overwrite.type === "member"){affectingMemberOverwrites.push(overwrite);}else if(this.rawRoles.indexOf(overwrite.id) !== -1){affectingOverwrites.push(overwrite);}}if(affectingOverwrites.length === 0 && affectingMemberOverwrites.length === 0){return this.evalPerms;}var finalPacked=affectingOverwrites.length !== 0?affectingOverwrites[0].packed:affectingMemberOverwrites[0].packed;for(var _iterator3=affectingOverwrites,_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[Symbol.iterator]();;) {var _ref3;if(_isArray3){if(_i3 >= _iterator3.length)break;_ref3 = _iterator3[_i3++];}else {_i3 = _iterator3.next();if(_i3.done)break;_ref3 = _i3.value;}var overwrite=_ref3;finalPacked = finalPacked & ~overwrite.deny;finalPacked = finalPacked | overwrite.allow;}for(var _iterator4=affectingMemberOverwrites,_isArray4=Array.isArray(_iterator4),_i4=0,_iterator4=_isArray4?_iterator4:_iterator4[Symbol.iterator]();;) {var _ref4;if(_isArray4){if(_i4 >= _iterator4.length)break;_ref4 = _iterator4[_i4++];}else {_i4 = _iterator4.next();if(_i4.done)break;_ref4 = _i4.value;}var overwrite=_ref4;finalPacked = finalPacked & ~overwrite.deny;finalPacked = finalPacked | overwrite.allow;}return new EvaluatedPermissions(finalPacked);};_createClass(Member,[{key:"server",get:function get(){return this.client.getServer("id",this.serverID);}},{key:"roles",get:function get(){var ufRoles=[this.server.getRole("id",this.server.id)];for(var _iterator5=this.rawRoles,_isArray5=Array.isArray(_iterator5),_i5=0,_iterator5=_isArray5?_iterator5:_iterator5[Symbol.iterator]();;) {var _ref5;if(_isArray5){if(_i5 >= _iterator5.length)break;_ref5 = _iterator5[_i5++];}else {_i5 = _iterator5.next();if(_i5.done)break;_ref5 = _i5.value;}var rawRole=_ref5;ufRoles.push(this.server.getRole("id",rawRole));}return ufRoles;}},{key:"evalPerms",get:function get(){var basePerms=this.roles, //cache roles as it can be slightly expensive
basePerm=basePerms[0].packed;basePerms = basePerms || [];for(var _iterator6=basePerms,_isArray6=Array.isArray(_iterator6),_i6=0,_iterator6=_isArray6?_iterator6:_iterator6[Symbol.iterator]();;) {var _ref6;if(_isArray6){if(_i6 >= _iterator6.length)break;_ref6 = _iterator6[_i6++];}else {_i6 = _iterator6.next();if(_i6.done)break;_ref6 = _i6.value;}var perm=_ref6;basePerm = basePerm | perm.packed;}return new EvaluatedPermissions(basePerm);}}]);return Member;})(User);module.exports = Member;

@@ -1,3 +0,3 @@

"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var PMChannel=require("./PMChannel.js");var Message=(function(){function Message(data,channel,mentions,author){_classCallCheck(this,Message);this.tts = data.tts;this.timestamp = Date.parse(data.timestamp);this.nonce = data.nonce;this.mentions = mentions;this.everyoneMentioned = data.mention_everyone;this.id = data.id;this.embeds = data.embeds;this.editedTimestamp = data.edited_timestamp;this.content = data.content.trim();this.channel = channel;if(this.isPrivate){this.author = this.channel.client.getUser("id",author.id);}else {this.author = this.channel.server.getMember("id",author.id) || this.channel.client.getUser("id",author.id);}this.attachments = data.attachments;} /*exports.Message.prototype.isPM = function() {
"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var PMChannel=require("./PMChannel.js");var Embeddable=require("./Embeds/IEmbed.js");var Message=(function(){function Message(data,channel,mentions,author){_classCallCheck(this,Message);this.tts = data.tts;this.timestamp = Date.parse(data.timestamp);this.nonce = data.nonce;this.mentions = mentions;this.everyoneMentioned = data.mention_everyone;this.id = data.id;this.embeds = [];if(data.embeds){for(var _iterator=data.embeds,_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 embed=_ref;this.embeds.push(Embeddable.createEmbed(embed));}}this.editedTimestamp = data.edited_timestamp;this.content = data.content.trim();this.channel = channel;if(this.isPrivate){this.author = this.channel.client.getUser("id",author.id);}else {this.author = this.channel.server.getMember("id",author.id) || this.channel.client.getUser("id",author.id);}this.attachments = data.attachments;} /*exports.Message.prototype.isPM = function() {
return ( this.channel instanceof PMChannel );
}*/Message.prototype.isMentioned = function isMentioned(user){var id=user.id?user.id:user;for(var _iterator=this.mentions,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[Symbol.iterator]();;) {var _ref;if(_isArray){if(_i >= _iterator.length)break;_ref = _iterator[_i++];}else {_i = _iterator.next();if(_i.done)break;_ref = _i.value;}var mention=_ref;if(mention.id === id){return true;}}return false;};_createClass(Message,[{key:"sender",get:function get(){return this.author;}},{key:"isPrivate",get:function get(){return this.channel.isPrivate;}}]);return Message;})();module.exports = Message;
}*/Message.prototype.isMentioned = function isMentioned(user){var id=user.id?user.id:user;for(var _iterator2=this.mentions,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[Symbol.iterator]();;) {var _ref2;if(_isArray2){if(_i2 >= _iterator2.length)break;_ref2 = _iterator2[_i2++];}else {_i2 = _iterator2.next();if(_i2.done)break;_ref2 = _i2.value;}var mention=_ref2;if(mention.id === id){return true;}}return false;};_createClass(Message,[{key:"sender",get:function get(){return this.author;}},{key:"isPrivate",get:function get(){return this.channel.isPrivate;}}]);return Message;})();module.exports = Message;

@@ -1,3 +0,3 @@

"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var ServerPermissions=(function(){function ServerPermissions(data,server){_classCallCheck(this,ServerPermissions);var self=this;function getBit(x){return (self.packed >>> x & 1) === 1;}this.managed = data.managed || false;this.position = data.position || 1;this.hoist = data.hoist || false;this.color = data.color || 0;this.packed = data.permissions || 36953089;this.name = data.name || "new role";this.id = data.id || null;this.server = server;}ServerPermissions.prototype.serialise = function serialise(){return {createInstantInvite:this.createInstantInvite,manageRoles:this.manageRoles,manageChannels:this.manageChannels,readMessages:this.readMessages,sendMessages:this.sendMessages,sendTTSMessages:this.sendTTSMessages,manageMessages:this.manageMessages,embedLinks:this.embedLinks,attachFiles:this.attachFiles,readMessageHistory:this.readMessageHistory,mentionEveryone:this.mentionEveryone,voiceConnect:this.voiceConnect,voiceSpeak:this.voiceSpeak,voiceMuteMembers:this.voiceMuteMembers,voiceDeafenMembers:this.voiceDeafenMembers,voiceMoveMembers:this.voiceMoveMembers,voiceUseVoiceActivation:this.voiceUseVoiceActivation};};ServerPermissions.prototype.serialize = function serialize(){return this.serialise();};ServerPermissions.prototype.getBit = function getBit(x){if((this.packed >>> 3 & 1) === 1){return true;}return (this.packed >>> x & 1) === 1;};ServerPermissions.prototype.setBit = function setBit(location,value){if(value){ // allow that permission
"use strict";var _createClass=(function(){function defineProperties(target,props){for(var i=0;i < props.length;i++) {var descriptor=props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if("value" in descriptor)descriptor.writable = true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};})();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var ServerPermissions=(function(){function ServerPermissions(data,server){_classCallCheck(this,ServerPermissions);var self=this;function getBit(x){return (self.packed >>> x & 1) === 1;}this.managed = data.managed || false;this.position = data.position || 1;this.hoist = data.hoist || false;this.color = data.color || 0;this.packed = data.permissions || (data.name === "@everyone"?36953089:0);this.name = data.name || "new role";this.id = data.id || null;this.server = server;}ServerPermissions.prototype.serialise = function serialise(){return {createInstantInvite:this.createInstantInvite,manageRoles:this.manageRoles,manageChannels:this.manageChannels,readMessages:this.readMessages,sendMessages:this.sendMessages,sendTTSMessages:this.sendTTSMessages,manageMessages:this.manageMessages,embedLinks:this.embedLinks,attachFiles:this.attachFiles,readMessageHistory:this.readMessageHistory,mentionEveryone:this.mentionEveryone,voiceConnect:this.voiceConnect,voiceSpeak:this.voiceSpeak,voiceMuteMembers:this.voiceMuteMembers,voiceDeafenMembers:this.voiceDeafenMembers,voiceMoveMembers:this.voiceMoveMembers,voiceUseVoiceActivation:this.voiceUseVoiceActivation};};ServerPermissions.prototype.serialize = function serialize(){return this.serialise();};ServerPermissions.prototype.getBit = function getBit(x){if((this.packed >>> 3 & 1) === 1){return true;}return (this.packed >>> x & 1) === 1;};ServerPermissions.prototype.setBit = function setBit(location,value){if(value){ // allow that permission
this.packed |= 1 << location;}else { // not allowed
this.packed &= ~(1 << location);}};ServerPermissions.prototype.toString = function toString(){return this.name;};_createClass(ServerPermissions,[{key:"createInstantInvite",get:function get(){return this.getBit(0);},set:function set(val){this.setBit(0,val);}},{key:"banMembers",get:function get(){return this.getBit(1);},set:function set(val){this.setBit(1,val);}},{key:"kickMembers",get:function get(){return this.getBit(2);},set:function set(val){this.setBit(2,val);}},{key:"manageRoles",get:function get(){return this.getBit(3);},set:function set(val){this.setBit(3,val);}},{key:"manageChannels",get:function get(){return this.getBit(4);},set:function set(val){this.setBit(4,val);}},{key:"manageServer",get:function get(){return this.getBit(5);},set:function set(val){this.setBit(5,val);}},{key:"readMessages",get:function get(){return this.getBit(10);},set:function set(val){this.setBit(10,val);}},{key:"sendMessages",get:function get(){return this.getBit(11);},set:function set(val){this.setBit(11,val);}},{key:"sendTTSMessages",get:function get(){return this.getBit(12);},set:function set(val){this.setBit(12,val);}},{key:"manageMessages",get:function get(){return this.getBit(13);},set:function set(val){this.setBit(13,val);}},{key:"embedLinks",get:function get(){return this.getBit(14);},set:function set(val){this.setBit(14,val);}},{key:"attachFiles",get:function get(){return this.getBit(15);},set:function set(val){this.setBit(15,val);}},{key:"readMessageHistory",get:function get(){return this.getBit(16);},set:function set(val){this.setBit(16,val);}},{key:"mentionEveryone",get:function get(){return this.getBit(17);},set:function set(val){this.setBit(17,val);}},{key:"voiceConnect",get:function get(){return this.getBit(20);},set:function set(val){this.setBit(20,val);}},{key:"voiceSpeak",get:function get(){return this.getBit(21);},set:function set(val){this.setBit(21,val);}},{key:"voiceMuteMembers",get:function get(){return this.getBit(22);},set:function set(val){this.setBit(22,val);}},{key:"voiceDeafenMembers",get:function get(){return this.getBit(23);},set:function set(val){this.setBit(23,val);}},{key:"voiceMoveMembers",get:function get(){return this.getBit(24);},set:function set(val){this.setBit(24,val);}},{key:"voiceUseVoiceActivation",get:function get(){return this.getBit(25);},set:function set(val){this.setBit(25,val);}}]);return ServerPermissions;})();module.exports = ServerPermissions;
{
"name": "discord.js",
"version": "3.10.2",
"version": "4.0.0",
"description": "A way to interface with the Discord API",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -13,4 +13,2 @@ var Discord = require("../");

counter = 1;
mybot.on("message", function (message) {

@@ -32,4 +30,7 @@

mybot.reply(message, "this is tts", {tts:true}).catch(error);
mybot.getChannelLogs(message.channel, 5000).then((messages)=>{
for(var msg of messages){
mybot.deleteMessage(msg);
}
})
});

@@ -48,8 +49,13 @@

mybot.on("debug", function (info) {
mybot.on("messageUpdate", function(newMessage, oldMessage){
// links and videos will create a loop
mybot.reply(newMessage, JSON.stringify(newMessage.embeds, null, 4));
})
mybot.on("serverUpdate", function (oldserver, newserver) {
console.log("server changed! " + mybot.servers.length);
})
mybot.on("unknown", function (info) {
console.log("warning!", info);
console.log("unknown!", info);
})

@@ -56,0 +62,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc