mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
2 lines
36 KiB
JavaScript
2 lines
36 KiB
JavaScript
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Discord=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function e(){return new Promise(function(a,b){n.get(g.API+"/gateway").end(function(c,d){c?b(c):a(d.body.url)})})}var f=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),g=a("./Endpoints.js"),h=a("./user.js"),i=a("./server.js"),j=a("./channel.js"),k=a("./message.js"),l=a("./invite.js"),m=a("./PMChannel.js"),n=a("superagent"),o=a("ws"),p=a("fs"),q={queue:!1},r=function(){function a(){var b=arguments.length<=0||void 0===arguments[0]?q:arguments[0],c=arguments.length<=1||void 0===arguments[1]?void 0:arguments[1];d(this,a),this.options=b,this.options.queue=this.options.queue,this.token=c,this.state=0,this.websocket=null,this.events={},this.user=null,this.alreadySentData=!1,this.serverCreateListener=new Map,this.email="abc",this.password="abc",this.userCache=[],this.channelCache=[],this.serverCache=[],this.pmChannelCache=[],this.readyTime=null,this.checkingQueue={},this.queue={}}return f(a,[{key:"sendPacket",value:function(a){1===this.websocket.readyState&&this.websocket.send(JSON.stringify(a))}},{key:"debug",value:function(a){this.trigger("debug",a)}},{key:"on",value:function(a,b){this.events[a]=b}},{key:"off",value:function(a){this.events[a]=null}},{key:"keepAlive",value:function(){this.debug("keep alive triggered"),this.sendPacket({op:1,d:Date.now()})}},{key:"trigger",value:function(a){var b=[];for(var c in arguments)b.push(arguments[c]);var d=this.events[a];d&&d.apply(this,b.slice(1))}},{key:"login",value:function(){var a=arguments.length<=0||void 0===arguments[0]?"foo@bar.com":arguments[0],b=arguments.length<=1||void 0===arguments[1]?"pass1234":arguments[1],c=arguments.length<=2||void 0===arguments[2]?function(a,b){}:arguments[2],d=this;return new Promise(function(f,h){0===d.state||4===d.state?(d.state=1,d.email=a,d.password=b,n.post(g.LOGIN).send({email:a,password:b}).end(function(a,b){a?(d.state=4,d.trigger("disconnected"),d.websocket&&d.websocket.close(),c(a),h(a)):(d.state=2,d.token=b.body.token,e().then(function(a){d.createws(a),c(null,d.token),f(d.token)})["catch"](function(a){c(a),h(a)}))})):h(new Error("Client already logging in or ready"))})}},{key:"logout",value:function(){var a=arguments.length<=0||void 0===arguments[0]?function(a){}:arguments[0],b=this;return new Promise(function(c,d){n.post(g.LOGOUT).set("authorization",b.token).end(function(e,f){e?(a(e),d(e)):(b.websocket.close(),b.state=4,a(),c())})})}},{key:"createServer",value:function(a,b){var c=arguments.length<=2||void 0===arguments[2]?function(a,b){}:arguments[2],d=this;return new Promise(function(e,f){n.post(g.SERVERS).set("authorization",d.token).send({name:a,region:b}).end(function(a,b){a?(c(a),f(a)):d.serverCreateListener.set(b.body.id,[e,c])})})}},{key:"createChannel",value:function(a,b,c){var d=arguments.length<=3||void 0===arguments[3]?function(a,b){}:arguments[3],e=this;return new Promise(function(f,h){n.post(g.SERVERS+"/"+e.resolveServerID(a)+"/channels").set("authorization",e.token).send({name:b,type:c}).end(function(a,b){if(a)d(a),h(a);else{var c=e.getServer("id",b.body.guild_id),g=e.addChannel(b.body,b.body.guild_id);c.addChannel(g),d(null,g),f(g)}})})}},{key:"leaveServer",value:function(a){var b=arguments.length<=1||void 0===arguments[1]?function(a,b){}:arguments[1],c=this;return new Promise(function(d,e){n.del(g.SERVERS+"/"+c.resolveServerID(a)).set("authorization",c.token).end(function(f,g){f?(b(f),e(f)):(c.serverCache.splice(c.serverCache.indexOf(a),1),b(null),d())})})}},{key:"createInvite",value:function(a,b){var c=arguments.length<=2||void 0===arguments[2]?function(a,b){}:arguments[2],d=this;return new Promise(function(e,f){var h;h=a instanceof i?a.id:a instanceof j?a.id:a,b=b||{},b.max_age=b.maxAge||0,b.max_uses=b.maxUses||0,b.temporary=b.temporary||!1,b.xkcdpass=b.xkcd||!1,n.post(g.CHANNELS+"/"+h+"/invites").set("authorization",d.token).send(b).end(function(a,b){if(a)c(a),f(a);else{var g=new l(b.body,d);c(null,g),e(g)}})})}},{key:"startPM",value:function(a){var b=this;return new Promise(function(c,d){var e=a;a instanceof h&&(e=a.id),n.post(g.USERS+"/"+b.user.id+"/channels").set("authorization",b.token).send({recipient_id:e}).end(function(a,e){a?d(a):c(b.addPMChannel(e.body))})})}},{key:"reply",value:function(a,b,c){var d=arguments.length<=3||void 0===arguments[3]?function(a,b){}:arguments[3],e=this;return new Promise(function(f,g){"function"==typeof c&&(d=c,c=!1);var h=a.sender;e.sendMessage(a,b,d,h+", ").then(f)["catch"](g)})}},{key:"deleteMessage",value:function(a,b){var c=arguments.length<=2||void 0===arguments[2]?function(a,b){}:arguments[2],d=this,e=new Promise(function(f,g){function h(){d.options.queue?(d.queue[a.channel.id]||(d.queue[a.channel.id]=[]),d.queue[a.channel.id].push({action:"deleteMessage",message:a,then:i,error:j}),d.checkQueue(a.channel.id)):d._deleteMessage(a).then(i)["catch"](j)}function i(){e.success=!0,c(null),f()}function j(a){e.error=a,c(a),g(a)}b?setTimeout(h,b):h()});return e}},{key:"updateMessage",value:function(a,b){var c=arguments.length<=2||void 0===arguments[2]?function(a,b){}:arguments[2],d=this,e=new Promise(function(f,g){function h(a){e.message=a,c(null,a),f(a)}function i(a){e.error=a,c(a),g(a)}b=b instanceof Array?b.join("\n"):b,d.options.queue?(d.queue[a.channel.id]||(d.queue[a.channel.id]=[]),d.queue[a.channel.id].push({action:"updateMessage",message:a,content:b,then:h,error:i}),d.checkQueue(a.channel.id)):d._updateMessage(a,b).then(h)["catch"](i)});return e}},{key:"setUsername",value:function(a){var b=arguments.length<=1||void 0===arguments[1]?function(a){}:arguments[1],c=this;return new Promise(function(d,e){n.patch(g.API+"/users/@me").set("authorization",c.token).send({avatar:c.user.avatar,email:c.email,new_password:null,password:c.password,username:a}).end(function(a){b(a),a?e(a):d()})})}},{key:"getChannelLogs",value:function(a){var b=arguments.length<=1||void 0===arguments[1]?500:arguments[1],c=arguments.length<=2||void 0===arguments[2]?function(a,b){}:arguments[2],d=this;return new Promise(function(e,f){var h=a;a instanceof j&&(h=a.id),n.get(g.CHANNELS+"/"+h+"/messages?limit="+b).set("authorization",d.token).end(function(a,b){if(a)c(a),f(a);else{var g=[],i=d.getChannel("id",h),j=!0,l=!1,m=void 0;try{for(var n,o=b.body[Symbol.iterator]();!(j=(n=o.next()).done);j=!0){var p=n.value,q=[],r=!0,s=!1,t=void 0;try{for(var u,v=p.mentions[Symbol.iterator]();!(r=(u=v.next()).done);r=!0){var w=u.value;q.push(d.addUser(w))}}catch(a){s=!0,t=a}finally{try{!r&&v["return"]&&v["return"]()}finally{if(s)throw t}}var x=d.addUser(p.author);g.push(new k(p,i,q,x))}}catch(a){l=!0,m=a}finally{try{!j&&o["return"]&&o["return"]()}finally{if(l)throw m}}c(null,g),e(g)}})})}},{key:"deleteChannel",value:function(a){var b=arguments.length<=1||void 0===arguments[1]?function(a){}:arguments[1],c=this;return new Promise(function(d,e){var f=a;a instanceof j&&(f=a.id),n.del(g.CHANNELS+"/"+f).set("authorization",c.token).end(function(a){a?(b(a),e(a)):(b(null),d())})})}},{key:"joinServer",value:function(a){var b=arguments.length<=1||void 0===arguments[1]?function(a,b){}:arguments[1],c=this;return new Promise(function(d,e){var f=a instanceof l?a.code:a;n.post(g.API+"/invite/"+f).set("authorization",c.token).end(function(a,f){a?(b(a),e(a)):c.getServer("id",f.body.guild.id)?d(c.getServer("id",f.body.guild.id)):c.serverCreateListener.set(f.body.guild.id,[d,b])})})}},{key:"sendFile",value:function(a,b){var c=arguments.length<=2||void 0===arguments[2]?"image.png":arguments[2],d=arguments.length<=3||void 0===arguments[3]?function(a,b){}:arguments[3],e=this,f=new Promise(function(g,h){function i(a){e.options.queue?(e.queue[a]||(e.queue[a]=[]),e.queue[a].push({action:"sendFile",attachment:l,attachmentName:c,then:j,error:k}),e.checkQueue(a)):e._sendFile(a,l,c).then(j)["catch"](k)}function j(a){f.message=a,d(null,a),g(a)}function k(a){f.error=a,d(a),h(a)}var l;"string"==typeof b||b instanceof String?(l=p.createReadStream(b),c=b):l=b,e.resolveDestination(a).then(i)["catch"](k)});return f}},{key:"sendMessage",value:function(a,b,c){var d=arguments.length<=3||void 0===arguments[3]?function(a,b){}:arguments[3],e=arguments.length<=4||void 0===arguments[4]?"":arguments[4],f=this,g=new Promise(function(h,i){function j(a){d(a),i(a)}function k(a){f.options.queue?(f.queue[a]||(f.queue[a]=[]),f.queue[a].push({action:"sendMessage",content:b,mentions:p,tts:!!c,then:l,error:m}),f.checkQueue(a)):f._sendMessage(a,b,c,p).then(l)["catch"](m)}function l(a){g.message=a,d(null,a),h(a)}function m(a){g.error=a,d(a),i(a)}function n(){var a=b;return b instanceof Array&&(a=b.join("\n")),a}function o(){var a=[],c=!0,d=!1,e=void 0;try{for(var f,g=(b.match(/<@[^>]*>/g)||[])[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;a.push(h.substring(2,h.length-1))}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return a}"function"==typeof c&&(d=c,c=!1),b=e+n(b);var p=o();f.resolveDestination(a).then(k)["catch"](j)});return g}},{key:"createws",value:function(a){if(this.websocket)return!1;var b=this;this.websocket=new o(a),this.websocket.onopen=function(){b.trySendConnData()},this.websocket.onclose=function(){b.trigger("disconnected")},this.websocket.onmessage=function(a){var c=!1,d={};try{c=JSON.parse(a.data),d=c.d}catch(e){return void b.trigger("error",e,a)}switch(c.t){case"READY":b.debug("received ready packet"),b.user=b.addUser(d.user);var f=!0,g=!1,i=void 0;try{for(var j,l=d.guilds[Symbol.iterator]();!(f=(j=l.next()).done);f=!0)var m=j.value,n=b.addServer(m)}catch(e){g=!0,i=e}finally{try{!f&&l["return"]&&l["return"]()}finally{if(g)throw i}}var o=!0,p=!1,q=void 0;try{for(var r,s=d.private_channels[Symbol.iterator]();!(o=(r=s.next()).done);o=!0){var t=r.value;b.addPMChannel(t)}}catch(e){p=!0,q=e}finally{try{!o&&s["return"]&&s["return"]()}finally{if(p)throw q}}b.trigger("ready"),b.readyTime=Date.now(),b.debug("cached "+b.serverCache.length+" servers, "+b.channelCache.length+" channels, "+b.pmChannelCache.length+" PMs and "+b.userCache.length+" users."),b.state=3,setInterval(function(){b.keepAlive.apply(b)},d.heartbeat_interval);break;case"MESSAGE_CREATE":b.debug("received message");var u=[];d.mentions=d.mentions||[];var v=!0,w=!1,x=void 0;try{for(var y,z=d.mentions[Symbol.iterator]();!(v=(y=z.next()).done);v=!0){var A=y.value;u.push(b.addUser(A))}}catch(e){w=!0,x=e}finally{try{!v&&z["return"]&&z["return"]()}finally{if(w)throw x}}var B=b.getChannel("id",d.channel_id);if(B){var C=B.addMessage(new k(d,B,u,b.addUser(d.author)));b.trigger("message",C)}break;case"MESSAGE_DELETE":b.debug("message deleted");var B=b.getChannel("id",d.channel_id),D=B.getMessage("id",d.id);D?(b.trigger("messageDelete",B,D),B.messages.splice(B.messages.indexOf(D),1)):b.trigger("messageDelete",B);break;case"MESSAGE_UPDATE":b.debug("message updated");var B=b.getChannel("id",d.channel_id),E=B.getMessage("id",d.id);if(E){var F={};for(var G in E)F[G]=E[G];for(var G in d)F[G]=d[G];var u=[],H=!0,I=!1,J=void 0;try{for(var K,L=F.mentions[Symbol.iterator]();!(H=(K=L.next()).done);H=!0){var A=K.value;u.push(b.addUser(A))}}catch(e){I=!0,J=e}finally{try{!H&&L["return"]&&L["return"]()}finally{if(I)throw J}}var M=new k(F,B,u,E.author);b.trigger("messageUpdate",M,E),B.messages[B.messages.indexOf(E)]=M}break;case"GUILD_DELETE":var n=b.getServer("id",d.id);n&&(b.serverCache.splice(b.serverCache.indexOf(n),1),b.trigger("serverDelete",n));break;case"CHANNEL_DELETE":var B=b.getChannel("id",d.id);if(B){var n=B.server;n&&n.channels.splice(n.channels.indexOf(B),1),b.trigger("channelDelete",B),b.serverCache.splice(b.serverCache.indexOf(B),1)}break;case"GUILD_CREATE":var n=b.getServer("id",d.id);if(n||(n=b.addServer(d)),b.serverCreateListener.get(d.id)){var N=b.serverCreateListener.get(d.id);N[0](n),N[1](null,n),b.serverCreateListener["delete"](d.id)}b.trigger("serverCreate",n);break;case"CHANNEL_CREATE":var B=b.getChannel("id",d.id);if(!B){var O=b.addChannel(d,d.guild_id),P=b.getServer("id",d.guild_id);P&&P.addChannel(O),b.trigger("channelCreate",O)}break;case"GUILD_MEMBER_ADD":var n=b.getServer("id",d.guild_id);if(n){var Q=b.addUser(d.user);~n.members.indexOf(Q)||n.members.push(Q),b.trigger("serverNewMember",Q,n)}break;case"GUILD_MEMBER_REMOVE":var n=b.getServer("id",d.guild_id);if(n){var Q=b.addUser(d.user);~n.members.indexOf(Q)&&n.members.splice(n.members.indexOf(Q),1),b.trigger("serverRemoveMember",Q,n)}break;case"USER_UPDATE":if(b.user&&d.id===b.user.id){var R=new h(d);b.trigger("userUpdate",R,b.user),~b.userCache.indexOf(b.user)&&(b.userCache[b.userCache.indexOf(b.user)]=R),b.user=R}break;case"PRESENCE_UPDATE":var S=b.getUser("id",d.user.id);if(S){var T=new h(d.user);T.equalsStrict(S)?b.trigger("presence",{user:S,status:d.status,server:b.getServer("id",d.guild_id),gameId:d.game_id}):(b.trigger("userUpdate",S,T),b.userCache[b.userCache.indexOf(S)]=T)}break;default:b.debug("received unknown packet"),b.trigger("unknown",c)}}}},{key:"addUser",value:function(a){return this.getUser("id",a.id)||this.userCache.push(new h(a)),this.getUser("id",a.id)}},{key:"addChannel",value:function(a,b){return this.getChannel("id",a.id)||this.channelCache.push(new j(a,this.getServer("id",b))),this.getChannel("id",a.id)}},{key:"addPMChannel",value:function(a){return this.getPMChannel("id",a.id)||this.pmChannelCache.push(new m(a,this)),this.getPMChannel("id",a.id)}},{key:"addServer",value:function(a){var b=this.getServer("id",a.id);if(!b&&(b=new i(a,this),this.serverCache.push(b),a.channels)){var c=!0,d=!1,e=void 0;try{for(var f,g=a.channels[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;b.channels.push(this.addChannel(h,b.id))}}catch(j){d=!0,e=j}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}}return b}},{key:"getUser",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.userCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"getChannel",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.channelCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return this.getPMChannel(a,b)}},{key:"getPMChannel",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.pmChannelCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"getServer",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.serverCache[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"trySendConnData",value:function(){if(this.token&&!this.alreadySentData){this.alreadySentData=!0;var a={op:2,d:{token:this.token,v:2,properties:{$os:"discord.js",$browser:"discord.js",$device:"discord.js",$referrer:"",$referring_domain:""}}};this.websocket.send(JSON.stringify(a))}}},{key:"resolveServerID",value:function(a){return a instanceof i?a.id:!isNaN(a)&&a.length&&17===a.length?a:void 0}},{key:"resolveDestination",value:function(a){var b=!1,c=this;return new Promise(function(d,e){if(a instanceof i)b=a.id;else if(a instanceof j)b=a.id;else if(a instanceof k)b=a.channel.id;else if(a instanceof h){var f=!0,g=!1,l=void 0;try{for(var m,n=c.pmChannelCache[Symbol.iterator]();!(f=(m=n.next()).done);f=!0){var o=m.value;if(o.user.equals(a))return o.id}}catch(p){g=!0,l=p}finally{try{!f&&n["return"]&&n["return"]()}finally{if(g)throw l}}c.startPM(a).then(function(a){d(a.id)})["catch"](e)}else b=a;b&&d(b)})}},{key:"_sendMessage",value:function(a,b,c,d){var e=this;return new Promise(function(f,h){n.post(g.CHANNELS+"/"+a+"/messages").set("authorization",e.token).send({content:b,mentions:d,tts:c}).end(function(a,b){if(a)h(a);else{var c=b.body,d=[];c.mentions=c.mentions||[];var g=!0,i=!1,j=void 0;try{for(var l,m=c.mentions[Symbol.iterator]();!(g=(l=m.next()).done);g=!0){var n=l.value;d.push(e.addUser(n))}}catch(a){i=!0,j=a}finally{try{!g&&m["return"]&&m["return"]()}finally{if(i)throw j}}var o=e.getChannel("id",c.channel_id);if(o){var p=o.addMessage(new k(c,o,d,e.addUser(c.author)));f(p)}}})})}},{key:"_sendFile",value:function(a,b){var c=arguments.length<=2||void 0===arguments[2]?"DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png":arguments[2],d=this;return new Promise(function(e,f){n.post(g.CHANNELS+"/"+a+"/messages").set("authorization",d.token).attach("file",b,c).end(function(b,c){if(b)f(b);else{var g=d.getChannel("id",a);if(g){var h=g.addMessage(new k(c.body,g,[],d.user));e(h)}}})})}},{key:"_updateMessage",value:function(a,b){var c=this;return new Promise(function(d,e){n.patch(g.CHANNELS+"/"+a.channel.id+"/messages/"+a.id).set("authorization",c.token).send({content:b,mentions:[]}).end(function(b,c){if(b)e(b);else{var f=new k(c.body,a.channel,a.mentions,a.sender);d(f),a.channel.messages[a.channel.messages.indexOf(a)]=f}})})}},{key:"_deleteMessage",value:function(a){var b=this;return new Promise(function(c,d){n.del(g.CHANNELS+"/"+a.channel.id+"/messages/"+a.id).set("authorization",b.token).end(function(a,b){a?d(a):c()})})}},{key:"checkQueue",value:function(a){var b=this,c=this;this.checkingQueue[a]||!function(){var d=function f(){if(0===c.queue[a].length)return void e();var b=c.queue[a][0];switch(b.action){case"sendMessage":var d=b;c._sendMessage(a,d.content,d.tts,d.mentions).then(function(b){d.then(b),c.queue[a].shift(),f()})["catch"](function(b){d.error(b),c.queue[a].shift(),f()});break;case"sendFile":var g=b;c._sendFile(a,g.attachment,g.attachmentName).then(function(b){g.then(b),c.queue[a].shift(),f()})["catch"](function(b){g.error(b),c.queue[a].shift(),f()});break;case"updateMessage":var h=b;c._updateMessage(h.message,h.content).then(function(b){h.then(b),c.queue[a].shift(),f()})["catch"](function(b){h.error(b),c.queue[a].shift(),f()});break;case"deleteMessage":var i=b;c._deleteMessage(i.message).then(function(b){i.then(b),c.queue[a].shift(),f()})["catch"](function(b){i.error(b),c.queue[a].shift(),f()});break;default:e()}},e=function(){c.checkingQueue[a]=!1};b.checkingQueue[a]=!0,d()}()}},{key:"uptime",get:function(){return this.readyTime?Date.now()-this.readyTime:null}},{key:"ready",get:function(){return 3===this.state}},{key:"servers",get:function(){return this.serverCache}},{key:"channels",get:function(){return this.channelCache}},{key:"users",get:function(){return this.userCache}},{key:"PMChannels",get:function(){return this.pmChannelCache}},{key:"messages",get:function(){var a=[],b=!0,c=!1,d=void 0;try{for(var e,f=this.channelCache[Symbol.iterator]();!(b=(e=f.next()).done);b=!0){var g=e.value;a=a.concat(g.messages)}}catch(h){c=!0,d=h}finally{try{!b&&f["return"]&&f["return"]()}finally{if(c)throw d}}return a}}]),a}();b.exports=r},{"./Endpoints.js":2,"./PMChannel.js":3,"./channel.js":4,"./invite.js":6,"./message.js":7,"./server.js":8,"./user.js":9,fs:10,superagent:11,ws:14}],2:[function(a,b,c){"use strict";c.BASE_DOMAIN="discordapp.com",c.BASE="https://"+c.BASE_DOMAIN,c.WEBSOCKET_HUB="wss://"+c.BASE_DOMAIN+"/hub",c.API=c.BASE+"/api",c.AUTH=c.API+"/auth",c.LOGIN=c.AUTH+"/login",c.LOGOUT=c.AUTH+"/logout",c.USERS=c.API+"/users",c.SERVERS=c.API+"/guilds",c.CHANNELS=c.API+"/channels"},{}],3:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),f=function(){function a(b,c){d(this,a),this.user=c.getUser("id",b.recipient.id),this.id=b.id,this.messages=[]}return e(a,[{key:"addMessage",value:function(a){return this.getMessage("id",a.id)||this.messages.push(a),this.getMessage("id",a.id)}},{key:"getMessage",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.messages[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"isPrivate",get:function(){return!0}}]),a}();b.exports=f},{}],4:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),f=function(){function a(b,c){d(this,a),this.server=c,this.name=b.name,this.type=b.type,this.id=b.id,this.messages=[]}return e(a,[{key:"equals",value:function(a){return a&&a.id===this.id}},{key:"addMessage",value:function(a){return this.getMessage("id",a.id)||this.messages.push(a),this.getMessage("id",a.id)}},{key:"getMessage",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.messages[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"toString",value:function(){return"#"+this.name}},{key:"client",get:function(){return this.server.client}},{key:"isPrivate",get:function(){return!1}}]),a}();b.exports=f},{}],5:[function(a,b,c){"use strict";var d=(a("superagent"),a("./Endpoints.js")),e=a("./Client.js"),f={Endpoints:d,Client:e};b.exports=f},{"./Client.js":1,"./Endpoints.js":2,superagent:11}],6:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),f=function(){function a(b,c){d(this,a),this.max_age=b.max_age,this.code=b.code,this.server=c.getServer("id",b.guild.id),this.revoked=b.revoked,this.created_at=Date.parse(b.created_at),this.temporary=b.temporary,this.uses=b.uses,this.max_uses=b.uses,this.inviter=c.addUser(b.inviter),this.xkcd=b.xkcdpass,this.channel=c.getChannel("id",b.channel.id)}return e(a,[{key:"URL",get:function(){var a=this.xkcd?this.xkcdpass:this.code;return"https://discord.gg/"+a}}]),a}();b.exports=f},{}],7:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),f=(a("./PMChannel.js"),function(){function a(b,c,e,f){d(this,a),this.tts=b.tts,this.timestamp=Date.parse(b.timestamp),this.nonce=b.nonce,this.mentions=e,this.everyoneMentioned=b.mention_everyone,this.id=b.id,this.embeds=b.embeds,this.editedTimestamp=b.edited_timestamp,this.content=b.content.trim(),this.channel=c,this.author=f,this.attachments=b.attachments}return e(a,[{key:"isMentioned",value:function(a){var b=a.id?a.id:a,c=!0,d=!1,e=void 0;try{for(var f,g=this.mentions[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h.id===b)return!0}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return!1}},{key:"sender",get:function(){return this.author}},{key:"isPrivate",get:function(){return this.channel.isPrivate}}]),a}());b.exports=f},{"./PMChannel.js":3}],8:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),f=function(){function a(b,c){if(d(this,a),this.client=c,this.region=b.region,this.ownerID=b.owner_id,this.name=b.name,this.id=b.id,this.members=[],this.channels=[],this.icon=b.icon,this.afkTimeout=b.afk_timeout,this.afkChannelId=b.afk_channel_id,!b.members)return void(b.members=[c.user]);var e=!0,f=!1,g=void 0;try{for(var h,i=b.members[Symbol.iterator]();!(e=(h=i.next()).done);e=!0){var j=h.value;j.user&&this.members.push(c.addUser(j.user))}}catch(k){f=!0,g=k}finally{try{!e&&i["return"]&&i["return"]()}finally{if(f)throw g}}}return e(a,[{key:"getChannel",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.channels[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"getMember",value:function(a,b){var c=!0,d=!1,e=void 0;try{for(var f,g=this.members[Symbol.iterator]();!(c=(f=g.next()).done);c=!0){var h=f.value;if(h[a]===b)return h}}catch(i){d=!0,e=i}finally{try{!c&&g["return"]&&g["return"]()}finally{if(d)throw e}}return null}},{key:"addChannel",value:function(a){return this.getChannel("id",a.id)||this.channels.push(a),a}},{key:"addMember",value:function(a){return this.getMember("id",a.id)||this.members.push(a),a}},{key:"toString",value:function(){return this.name}},{key:"iconURL",get:function(){return this.icon?"https://discordapp.com/api/guilds/"+this.id+"/icons/"+this.icon+".jpg":null}},{key:"afkChannel",get:function(){return this.afkChannelId?this.getChannel("id",this.afkChannelId):!1}},{key:"defaultChannel",get:function(){return this.getChannel("name","general")}},{key:"owner",get:function(){return this.client.getUser("id",this.ownerID)}}]),a}();b.exports=f},{}],9:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var e=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),f=function(){function a(b){d(this,a),this.username=b.username,this.discriminator=b.discriminator,this.id=b.id,this.avatar=b.avatar}return e(a,[{key:"mention",value:function(){return"<@"+this.id+">"}},{key:"toString",value:function(){return this.mention()}},{key:"equals",value:function(a){return a.id===this.id}},{key:"equalsStrict",value:function(a){return a.id===this.id&&a.avatar===this.avatar&&a.username===this.username&&a.discriminator===this.discriminator}},{key:"avatarURL",get:function(){return this.avatar?"https://discordapp.com/api/users/"+this.id+"/avatars/"+this.avatar+".jpg":null}}]),a}();b.exports=f},{}],10:[function(a,b,c){},{}],11:[function(a,b,c){function d(){}function e(a){var b={}.toString.call(a);switch(b){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function f(a){return a===Object(a)}function g(a){if(!f(a))return a;var b=[];for(var c in a)null!=a[c]&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")}function h(a){for(var b,c,d={},e=a.split("&"),f=0,g=e.length;g>f;++f)c=e[f],b=c.split("="),d[decodeURIComponent(b[0])]=decodeURIComponent(b[1]);return d}function i(a){var b,c,d,e,f=a.split(/\r?\n/),g={};f.pop();for(var h=0,i=f.length;i>h;++h)c=f[h],b=c.indexOf(":"),d=c.slice(0,b).toLowerCase(),e=r(c.slice(b+1)),g[d]=e;return g}function j(a){return a.split(/ *; */).shift()}function k(a){return p(a.split(/ *; */),function(a,b){var c=b.split(/ *= */),d=c.shift(),e=c.shift();return d&&e&&(a[d]=e),a},{})}function l(a,b){b=b||{},this.req=a,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||"undefined"==typeof this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText,this.setStatusProperties(this.xhr.status),this.header=this.headers=i(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body="HEAD"!=this.req.method?this.parseBody(this.text?this.text:this.xhr.response):null}function m(a,b){var c=this;o.call(this),this._query=this._query||[],this.method=a,this.url=b,this.header={},this._header={},this.on("end",function(){var a=null,b=null;try{b=new l(c)}catch(d){return a=new Error("Parser is unable to parse the response"),a.parse=!0,a.original=d,c.callback(a)}if(c.emit("response",b),a)return c.callback(a,b);if(b.status>=200&&b.status<300)return c.callback(a,b);var e=new Error(b.statusText||"Unsuccessful HTTP response");e.original=a,e.response=b,e.status=b.status,c.callback(e,b)})}function n(a,b){return"function"==typeof b?new m("GET",a).end(b):1==arguments.length?new m("GET",a):new m(a,b)}var o=a("emitter"),p=a("reduce"),q="undefined"==typeof window?this||self:window;n.getXHR=function(){if(!(!q.XMLHttpRequest||q.location&&"file:"==q.location.protocol&&q.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(a){}return!1};var r="".trim?function(a){return a.trim()}:function(a){return a.replace(/(^\s*|\s*$)/g,"")};n.serializeObject=g,n.parseString=h,n.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},n.serialize={"application/x-www-form-urlencoded":g,"application/json":JSON.stringify},n.parse={"application/x-www-form-urlencoded":h,"application/json":JSON.parse},l.prototype.get=function(a){return this.header[a.toLowerCase()]},l.prototype.setHeaderProperties=function(a){var b=this.header["content-type"]||"";this.type=j(b);var c=k(b);for(var d in c)this[d]=c[d]},l.prototype.parseBody=function(a){var b=n.parse[this.type];return b&&a&&(a.length||a instanceof Object)?b(a):null},l.prototype.setStatusProperties=function(a){1223===a&&(a=204);var b=a/100|0;this.status=a,this.statusType=b,this.info=1==b,this.ok=2==b,this.clientError=4==b,this.serverError=5==b,this.error=4==b||5==b?this.toError():!1,this.accepted=202==a,this.noContent=204==a,this.badRequest=400==a,this.unauthorized=401==a,this.notAcceptable=406==a,this.notFound=404==a,this.forbidden=403==a},l.prototype.toError=function(){var a=this.req,b=a.method,c=a.url,d="cannot "+b+" "+c+" ("+this.status+")",e=new Error(d);return e.status=this.status,e.method=b,e.url=c,e},n.Response=l,o(m.prototype),m.prototype.use=function(a){return a(this),this},m.prototype.timeout=function(a){return this._timeout=a,this},m.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},m.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(),
|
|
this.clearTimeout(),this.emit("abort"),this)},m.prototype.set=function(a,b){if(f(a)){for(var c in a)this.set(c,a[c]);return this}return this._header[a.toLowerCase()]=b,this.header[a]=b,this},m.prototype.unset=function(a){return delete this._header[a.toLowerCase()],delete this.header[a],this},m.prototype.getHeader=function(a){return this._header[a.toLowerCase()]},m.prototype.type=function(a){return this.set("Content-Type",n.types[a]||a),this},m.prototype.accept=function(a){return this.set("Accept",n.types[a]||a),this},m.prototype.auth=function(a,b){var c=btoa(a+":"+b);return this.set("Authorization","Basic "+c),this},m.prototype.query=function(a){return"string"!=typeof a&&(a=g(a)),a&&this._query.push(a),this},m.prototype.field=function(a,b){return this._formData||(this._formData=new q.FormData),this._formData.append(a,b),this},m.prototype.attach=function(a,b,c){return this._formData||(this._formData=new q.FormData),this._formData.append(a,b,c),this},m.prototype.send=function(a){var b=f(a),c=this.getHeader("Content-Type");if(b&&f(this._data))for(var d in a)this._data[d]=a[d];else"string"==typeof a?(c||this.type("form"),c=this.getHeader("Content-Type"),"application/x-www-form-urlencoded"==c?this._data=this._data?this._data+"&"+a:a:this._data=(this._data||"")+a):this._data=a;return!b||e(a)?this:(c||this.type("json"),this)},m.prototype.callback=function(a,b){var c=this._callback;this.clearTimeout(),c(a,b)},m.prototype.crossDomainError=function(){var a=new Error("Origin is not allowed by Access-Control-Allow-Origin");a.crossDomain=!0,this.callback(a)},m.prototype.timeoutError=function(){var a=this._timeout,b=new Error("timeout of "+a+"ms exceeded");b.timeout=a,this.callback(b)},m.prototype.withCredentials=function(){return this._withCredentials=!0,this},m.prototype.end=function(a){var b=this,c=this.xhr=n.getXHR(),f=this._query.join("&"),g=this._timeout,h=this._formData||this._data;this._callback=a||d,c.onreadystatechange=function(){if(4==c.readyState){var a;try{a=c.status}catch(d){a=0}if(0==a){if(b.timedout)return b.timeoutError();if(b.aborted)return;return b.crossDomainError()}b.emit("end")}};var i=function(a){a.total>0&&(a.percent=a.loaded/a.total*100),b.emit("progress",a)};this.hasListeners("progress")&&(c.onprogress=i);try{c.upload&&this.hasListeners("progress")&&(c.upload.onprogress=i)}catch(j){}if(g&&!this._timer&&(this._timer=setTimeout(function(){b.timedout=!0,b.abort()},g)),f&&(f=n.serializeObject(f),this.url+=~this.url.indexOf("?")?"&"+f:"?"+f),c.open(this.method,this.url,!0),this._withCredentials&&(c.withCredentials=!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof h&&!e(h)){var k=this.getHeader("Content-Type"),l=n.serialize[k?k.split(";")[0]:""];l&&(h=l(h))}for(var m in this.header)null!=this.header[m]&&c.setRequestHeader(m,this.header[m]);return this.emit("request",this),c.send(h),this},m.prototype.then=function(a,b){return this.end(function(c,d){c?b(c):a(d)})},n.Request=m,n.get=function(a,b,c){var d=n("GET",a);return"function"==typeof b&&(c=b,b=null),b&&d.query(b),c&&d.end(c),d},n.head=function(a,b,c){var d=n("HEAD",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.del=function(a,b){var c=n("DELETE",a);return b&&c.end(b),c},n.patch=function(a,b,c){var d=n("PATCH",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.post=function(a,b,c){var d=n("POST",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},n.put=function(a,b,c){var d=n("PUT",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},b.exports=n},{emitter:12,reduce:13}],12:[function(a,b,c){function d(a){return a?e(a):void 0}function e(a){for(var b in d.prototype)a[b]=d.prototype[b];return a}b.exports=d,d.prototype.on=d.prototype.addEventListener=function(a,b){return this._callbacks=this._callbacks||{},(this._callbacks[a]=this._callbacks[a]||[]).push(b),this},d.prototype.once=function(a,b){function c(){d.off(a,c),b.apply(this,arguments)}var d=this;return this._callbacks=this._callbacks||{},c.fn=b,this.on(a,c),this},d.prototype.off=d.prototype.removeListener=d.prototype.removeAllListeners=d.prototype.removeEventListener=function(a,b){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var c=this._callbacks[a];if(!c)return this;if(1==arguments.length)return delete this._callbacks[a],this;for(var d,e=0;e<c.length;e++)if(d=c[e],d===b||d.fn===b){c.splice(e,1);break}return this},d.prototype.emit=function(a){this._callbacks=this._callbacks||{};var b=[].slice.call(arguments,1),c=this._callbacks[a];if(c){c=c.slice(0);for(var d=0,e=c.length;e>d;++d)c[d].apply(this,b)}return this},d.prototype.listeners=function(a){return this._callbacks=this._callbacks||{},this._callbacks[a]||[]},d.prototype.hasListeners=function(a){return!!this.listeners(a).length}},{}],13:[function(a,b,c){b.exports=function(a,b,c){for(var d=0,e=a.length,f=3==arguments.length?c:a[d++];e>d;)f=b.call(null,f,a[d],++d,a);return f}},{}],14:[function(a,b,c){function d(a,b,c){var d;return d=b?new f(a,b):new f(a)}var e=function(){return this}(),f=e.WebSocket||e.MozWebSocket;b.exports=f?d:null,f&&(d.prototype=f.prototype)},{}]},{},[5])(5)}); |