UNPKG

discord-rich-presence-typescript

Version:
1 lines 25.4 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.DiscordRichPresence=t():e.DiscordRichPresence=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var s=t[i]={i:i,l:!1,exports:{}};return e[i].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:i})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=5)}([function(e,t,n){"use strict";var i,s="object"==typeof Reflect?Reflect:null,r=s&&"function"==typeof s.apply?s.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};i=s&&"function"==typeof s.ownKeys?s.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var o=Number.isNaN||function(e){return e!=e};function c(){c.init.call(this)}e.exports=c,e.exports.once=function(e,t){return new Promise(function(n,i){function s(n){e.removeListener(t,r),i(n)}function r(){"function"==typeof e.removeListener&&e.removeListener("error",s),n([].slice.call(arguments))}p(e,t,r,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&p(e,"error",t,n)}(e,s,{once:!0})})},c.EventEmitter=c,c.prototype._events=void 0,c.prototype._eventsCount=0,c.prototype._maxListeners=void 0;var a=10;function u(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function E(e){return void 0===e._maxListeners?c.defaultMaxListeners:e._maxListeners}function l(e,t,n,i){var s,r,o;if(u(n),void 0===(r=e._events)?(r=e._events=Object.create(null),e._eventsCount=0):(void 0!==r.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),r=e._events),o=r[t]),void 0===o)o=r[t]=n,++e._eventsCount;else if("function"==typeof o?o=r[t]=i?[n,o]:[o,n]:i?o.unshift(n):o.push(n),(s=E(e))>0&&o.length>s&&!o.warned){o.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=o.length,function(e){console&&console.warn&&console.warn(e)}(c)}return e}function d(e,t,n){var i={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},s=function(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}.bind(i);return s.listener=n,i.wrapFn=s,s}function _(e,t,n){var i=e._events;if(void 0===i)return[];var s=i[t];return void 0===s?[]:"function"==typeof s?n?[s.listener||s]:[s]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(s):T(s,s.length)}function h(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function T(e,t){for(var n=new Array(t),i=0;i<t;++i)n[i]=e[i];return n}function p(e,t,n,i){if("function"==typeof e.on)i.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,function s(r){i.once&&e.removeEventListener(t,s),n(r)})}}Object.defineProperty(c,"defaultMaxListeners",{enumerable:!0,get:function(){return a},set:function(e){if("number"!=typeof e||e<0||o(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");a=e}}),c.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},c.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||o(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},c.prototype.getMaxListeners=function(){return E(this)},c.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i="error"===e,s=this._events;if(void 0!==s)i=i&&void 0===s.error;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var c=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw c.context=o,c}var a=s[e];if(void 0===a)return!1;if("function"==typeof a)r(a,this,t);else{var u=a.length,E=T(a,u);for(n=0;n<u;++n)r(E[n],this,t)}return!0},c.prototype.addListener=function(e,t){return l(this,e,t,!1)},c.prototype.on=c.prototype.addListener,c.prototype.prependListener=function(e,t){return l(this,e,t,!0)},c.prototype.once=function(e,t){return u(t),this.on(e,d(this,e,t)),this},c.prototype.prependOnceListener=function(e,t){return u(t),this.prependListener(e,d(this,e,t)),this},c.prototype.removeListener=function(e,t){var n,i,s,r,o;if(u(t),void 0===(i=this._events))return this;if(void 0===(n=i[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(s=-1,r=n.length-1;r>=0;r--)if(n[r]===t||n[r].listener===t){o=n[r].listener,s=r;break}if(s<0)return this;0===s?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,s),1===n.length&&(i[e]=n[0]),void 0!==i.removeListener&&this.emit("removeListener",e,o||t)}return this},c.prototype.off=c.prototype.removeListener,c.prototype.removeAllListeners=function(e){var t,n,i;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var s,r=Object.keys(n);for(i=0;i<r.length;++i)"removeListener"!==(s=r[i])&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(i=t.length-1;i>=0;i--)this.removeListener(e,t[i]);return this},c.prototype.listeners=function(e){return _(this,e,!0)},c.prototype.rawListeners=function(e){return _(this,e,!1)},c.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):h.call(e,t)},c.prototype.listenerCount=h,c.prototype.eventNames=function(){return this._eventsCount>0?i(this._events):[]}},function(e,t,n){"use strict";let i;try{const{app:e}=n(7);i=e.setAsDefaultProtocolClient.bind(e)}catch(e){try{i=n(8)}catch(e){}}"function"!=typeof i&&(i=(()=>!1));e.exports={pid:function(){return"undefined"!=typeof process?process.pid:null},register:i,uuid:()=>{let e="";for(let t=0;t<32;t+=1){let n;if(8!==t&&12!==t&&16!==t&&20!==t||(e+="-"),12===t)n=4;else{const e=16*Math.random()|0;n=16===t?3&e|0:e}e+=n.toString(16)}return e}}},function(e,t){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";var i=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==i)return i;throw new Error("unable to locate global object")}();e.exports=t=i.fetch,i.fetch&&(t.default=i.fetch.bind(i)),t.Headers=i.Headers,t.Request=i.Request,t.Response=i.Response},function(e,t,n){"use strict";function i(e){const t={};for(const n of e)t[n]=n;return t}t.browser="undefined"!=typeof window,t.RPCCommands=i(["DISPATCH","AUTHORIZE","AUTHENTICATE","GET_GUILD","GET_GUILDS","GET_CHANNEL","GET_CHANNELS","CREATE_CHANNEL_INVITE","GET_RELATIONSHIPS","GET_USER","SUBSCRIBE","UNSUBSCRIBE","SET_USER_VOICE_SETTINGS","SET_USER_VOICE_SETTINGS_2","SELECT_VOICE_CHANNEL","GET_SELECTED_VOICE_CHANNEL","SELECT_TEXT_CHANNEL","GET_VOICE_SETTINGS","SET_VOICE_SETTINGS_2","SET_VOICE_SETTINGS","CAPTURE_SHORTCUT","SET_ACTIVITY","SEND_ACTIVITY_JOIN_INVITE","CLOSE_ACTIVITY_JOIN_REQUEST","ACTIVITY_INVITE_USER","ACCEPT_ACTIVITY_INVITE","INVITE_BROWSER","DEEP_LINK","CONNECTIONS_CALLBACK","BRAINTREE_POPUP_BRIDGE_CALLBACK","GIFT_CODE_BROWSER","GUILD_TEMPLATE_BROWSER","OVERLAY","BROWSER_HANDOFF","SET_CERTIFIED_DEVICES","GET_IMAGE","CREATE_LOBBY","UPDATE_LOBBY","DELETE_LOBBY","UPDATE_LOBBY_MEMBER","CONNECT_TO_LOBBY","DISCONNECT_FROM_LOBBY","SEND_TO_LOBBY","SEARCH_LOBBIES","CONNECT_TO_LOBBY_VOICE","DISCONNECT_FROM_LOBBY_VOICE","SET_OVERLAY_LOCKED","OPEN_OVERLAY_ACTIVITY_INVITE","OPEN_OVERLAY_GUILD_INVITE","OPEN_OVERLAY_VOICE_SETTINGS","VALIDATE_APPLICATION","GET_ENTITLEMENT_TICKET","GET_APPLICATION_TICKET","START_PURCHASE","GET_SKUS","GET_ENTITLEMENTS","GET_NETWORKING_CONFIG","NETWORKING_SYSTEM_METRICS","NETWORKING_PEER_METRICS","NETWORKING_CREATE_TOKEN","SET_USER_ACHIEVEMENT","GET_USER_ACHIEVEMENTS"]),t.RPCEvents=i(["CURRENT_USER_UPDATE","GUILD_STATUS","GUILD_CREATE","CHANNEL_CREATE","RELATIONSHIP_UPDATE","VOICE_CHANNEL_SELECT","VOICE_STATE_CREATE","VOICE_STATE_DELETE","VOICE_STATE_UPDATE","VOICE_SETTINGS_UPDATE","VOICE_SETTINGS_UPDATE_2","VOICE_CONNECTION_STATUS","SPEAKING_START","SPEAKING_STOP","GAME_JOIN","GAME_SPECTATE","ACTIVITY_JOIN","ACTIVITY_JOIN_REQUEST","ACTIVITY_SPECTATE","ACTIVITY_INVITE","NOTIFICATION_CREATE","MESSAGE_CREATE","MESSAGE_UPDATE","MESSAGE_DELETE","LOBBY_DELETE","LOBBY_UPDATE","LOBBY_MEMBER_CONNECT","LOBBY_MEMBER_DISCONNECT","LOBBY_MEMBER_UPDATE","LOBBY_MESSAGE","CAPTURE_SHORTCUT_CHANGE","OVERLAY","OVERLAY_UPDATE","ENTITLEMENT_CREATE","ENTITLEMENT_DELETE","USER_ACHIEVEMENT_UPDATE","READY","ERROR"]),t.RPCErrors={CAPTURE_SHORTCUT_ALREADY_LISTENING:5004,GET_GUILD_TIMED_OUT:5002,INVALID_ACTIVITY_JOIN_REQUEST:4012,INVALID_ACTIVITY_SECRET:5005,INVALID_CHANNEL:4005,INVALID_CLIENTID:4007,INVALID_COMMAND:4002,INVALID_ENTITLEMENT:4015,INVALID_EVENT:4004,INVALID_GIFT_CODE:4016,INVALID_GUILD:4003,INVALID_INVITE:4011,INVALID_LOBBY:4013,INVALID_LOBBY_SECRET:4014,INVALID_ORIGIN:4008,INVALID_PAYLOAD:4e3,INVALID_PERMISSIONS:4006,INVALID_TOKEN:4009,INVALID_USER:4010,LOBBY_FULL:5007,NO_ELIGIBLE_ACTIVITY:5006,OAUTH2_ERROR:5e3,PURCHASE_CANCELED:5008,PURCHASE_ERROR:5009,RATE_LIMITED:5011,SELECT_CHANNEL_TIMED_OUT:5001,SELECT_VOICE_FORCE_REQUIRED:5003,SERVICE_UNAVAILABLE:1001,TRANSACTION_ABORTED:1002,UNAUTHORIZED_FOR_ACHIEVEMENT:5010,UNKNOWN_ERROR:1e3},t.RPCCloseCodes={CLOSE_NORMAL:1e3,CLOSE_UNSUPPORTED:1003,CLOSE_ABNORMAL:1006,INVALID_CLIENTID:4e3,INVALID_ORIGIN:4001,RATELIMITED:4002,TOKEN_REVOKED:4003,INVALID_VERSION:4004,INVALID_ENCODING:4005},t.LobbyTypes={PRIVATE:1,PUBLIC:2},t.RelationshipTypes={NONE:0,FRIEND:1,BLOCKED:2,PENDING_INCOMING:3,PENDING_OUTGOING:4,IMPLICIT:5}},function(e,t,n){"use strict";const i=n(6),s=n(0),r="undefined"!=typeof window;e.exports=function(e){const t=new i.Client({transport:r?"websocket":"ipc"});let n=!1,o=null;const c=new class extends s{updatePresence(e){n?t.setActivity(e).catch(e=>this.emit("error",e)):o=e}reply(e,n){const i=e=>this.emit("error",e);switch(n){case"YES":t.sendJoinInvite(e).catch(i);break;case"NO":case"IGNORE":t.closeJoinRequest(e).catch(i);break;default:throw new RangeError("unknown response")}}disconnect(){t.destroy().catch(e=>this.emit("error",e))}};return t.on("error",e=>c.emit("error",e)),t.login({clientId:e}).then(()=>{c.emit("connected"),n=!0,t.subscribe("ACTIVITY_JOIN",({secret:e})=>{c.emit("join",e)}),t.subscribe("ACTIVITY_SPECTATE",({secret:e})=>{c.emit("spectate",e)}),t.subscribe("ACTIVITY_JOIN_REQUEST",e=>{c.emit("joinRequest",e)}),o&&(t.setActivity(o).catch(e=>c.emit("error",e)),o=null)}).catch(e=>c.emit("error",e)),c}},function(e,t,n){"use strict";const i=n(1);e.exports={Client:n(9),register:e=>i.register(`discord-${e}`)}},function(e,t){},function(e,t){},function(e,t,n){"use strict";const i=n(0),{setTimeout:s,clearTimeout:r}=n(10),o=n(3),c=n(12),{RPCCommands:a,RPCEvents:u,RelationshipTypes:E}=n(4),{pid:l,uuid:d}=n(1);function _(e,t){return`${e}${JSON.stringify(t)}`}e.exports=class extends i{constructor(e={}){super(),this.options=e,this.accessToken=null,this.clientId=null,this.application=null,this.user=null;const t=c[e.transport];if(!t)throw new TypeError("RPC_INVALID_TRANSPORT",e.transport);this.fetch=((e,t,{data:n,query:i}={})=>o(`${this.fetch.endpoint}${t}${i?new URLSearchParams(i):""}`,{method:e,body:n,headers:{Authorization:`Bearer ${this.accessToken}`}}).then(async e=>{const t=await e.json();if(!e.ok){const n=new Error(e.status);throw n.body=t,n}return t})),this.fetch.endpoint="https://discord.com/api",this.transport=new t(this),this.transport.on("message",this._onRpcMessage.bind(this)),this._expecting=new Map,this._subscriptions=new Map,this._connectPromise=void 0}connect(e){return this._connectPromise?this._connectPromise:(this._connectPromise=new Promise((t,n)=>{this.clientId=e;const i=s(()=>n(new Error("RPC_CONNECTION_TIMEOUT")),1e4);i.unref(),this.once("connected",()=>{r(i),t(this)}),this.transport.once("close",()=>{this._expecting.forEach(e=>{e.reject(new Error("connection closed"))}),this.emit("disconnected"),n(new Error("connection closed"))}),this.transport.connect().catch(n)}),this._connectPromise)}async login(e={}){let{clientId:t,accessToken:n}=e;return await this.connect(t),e.scopes?(n||(n=await this.authorize(e)),this.authenticate(n)):(this.emit("ready"),this)}request(e,t,n){return new Promise((i,s)=>{const r=d();this.transport.send({cmd:e,args:t,evt:n,nonce:r}),this._expecting.set(r,{resolve:i,reject:s})})}_onRpcMessage(e){if(e.cmd===a.DISPATCH&&e.evt===u.READY)e.data.user&&(this.user=e.data.user),this.emit("connected");else if(this._expecting.has(e.nonce)){const{resolve:t,reject:n}=this._expecting.get(e.nonce);if("ERROR"===e.evt){const t=new Error(e.data.message);t.code=e.data.code,t.data=e.data,n(t)}else t(e.data);this._expecting.delete(e.nonce)}else{const t=_(e.evt,e.args);if(!this._subscriptions.has(t))return;this._subscriptions.get(t)(e.data)}}async authorize({scopes:e,clientSecret:t,rpcToken:n,redirectUri:i}={}){t&&!0===n&&(n=(await this.fetch("POST","/oauth2/token/rpc",{data:new URLSearchParams({client_id:this.clientId,client_secret:t})})).rpc_token);const{code:s}=await this.request("AUTHORIZE",{scopes:e,client_id:this.clientId,rpc_token:n});return(await this.fetch("POST","/oauth2/token",{data:new URLSearchParams({client_id:this.clientId,client_secret:t,code:s,grant_type:"authorization_code",redirect_uri:i})})).access_token}authenticate(e){return this.request("AUTHENTICATE",{access_token:e}).then(({application:t,user:n})=>(this.accessToken=e,this.application=t,this.user=n,this.emit("ready"),this))}getGuild(e,t){return this.request(a.GET_GUILD,{guild_id:e,timeout:t})}getGuilds(e){return this.request(a.GET_GUILDS,{timeout:e})}getChannel(e,t){return this.request(a.GET_CHANNEL,{channel_id:e,timeout:t})}async getChannels(e,t){const{channels:n}=await this.request(a.GET_CHANNELS,{timeout:t,guild_id:e});return n}setCertifiedDevices(e){return this.request(a.SET_CERTIFIED_DEVICES,{devices:e.map(e=>({type:e.type,id:e.uuid,vendor:e.vendor,model:e.model,related:e.related,echo_cancellation:e.echoCancellation,noise_suppression:e.noiseSuppression,automatic_gain_control:e.automaticGainControl,hardware_mute:e.hardwareMute}))})}setUserVoiceSettings(e,t){return this.request(a.SET_USER_VOICE_SETTINGS,{user_id:e,pan:t.pan,mute:t.mute,volume:t.volume})}selectVoiceChannel(e,{timeout:t,force:n=!1}={}){return this.request(a.SELECT_VOICE_CHANNEL,{channel_id:e,timeout:t,force:n})}selectTextChannel(e,{timeout:t}={}){return this.request(a.SELECT_TEXT_CHANNEL,{channel_id:e,timeout:t})}getVoiceSettings(){return this.request(a.GET_VOICE_SETTINGS).then(e=>({automaticGainControl:e.automatic_gain_control,echoCancellation:e.echo_cancellation,noiseSuppression:e.noise_suppression,qos:e.qos,silenceWarning:e.silence_warning,deaf:e.deaf,mute:e.mute,input:{availableDevices:e.input.available_devices,device:e.input.device_id,volume:e.input.volume},output:{availableDevices:e.output.available_devices,device:e.output.device_id,volume:e.output.volume},mode:{type:e.mode.type,autoThreshold:e.mode.auto_threshold,threshold:e.mode.threshold,shortcut:e.mode.shortcut,delay:e.mode.delay}}))}setVoiceSettings(e){return this.request(a.SET_VOICE_SETTINGS,{automatic_gain_control:e.automaticGainControl,echo_cancellation:e.echoCancellation,noise_suppression:e.noiseSuppression,qos:e.qos,silence_warning:e.silenceWarning,deaf:e.deaf,mute:e.mute,input:e.input?{device_id:e.input.device,volume:e.input.volume}:void 0,output:e.output?{device_id:e.output.device,volume:e.output.volume}:void 0,mode:e.mode?{mode:e.mode.type,auto_threshold:e.mode.autoThreshold,threshold:e.mode.threshold,shortcut:e.mode.shortcut,delay:e.mode.delay}:void 0})}captureShortcut(e){const t=_(u.CAPTURE_SHORTCUT_CHANGE),n=()=>(this._subscriptions.delete(t),this.request(a.CAPTURE_SHORTCUT,{action:"STOP"}));return this._subscriptions.set(t,({shortcut:t})=>{e(t,n)}),this.request(a.CAPTURE_SHORTCUT,{action:"START"}).then(()=>n)}setActivity(e={},t=l()){let n,i,s,r;if(e.startTimestamp||e.endTimestamp){if((n={start:e.startTimestamp,end:e.endTimestamp}).start instanceof Date&&(n.start=Math.round(n.start.getTime())),n.end instanceof Date&&(n.end=Math.round(n.end.getTime())),n.start>2147483647e3)throw new RangeError("timestamps.start must fit into a unix timestamp");if(n.end>2147483647e3)throw new RangeError("timestamps.end must fit into a unix timestamp")}return(e.largeImageKey||e.largeImageText||e.smallImageKey||e.smallImageText)&&(i={large_image:e.largeImageKey,large_text:e.largeImageText,small_image:e.smallImageKey,small_text:e.smallImageText}),(e.partySize||e.partyId||e.partyMax)&&(s={id:e.partyId},(e.partySize||e.partyMax)&&(s.size=[e.partySize,e.partyMax])),(e.matchSecret||e.joinSecret||e.spectateSecret)&&(r={match:e.matchSecret,join:e.joinSecret,spectate:e.spectateSecret}),this.request(a.SET_ACTIVITY,{pid:t,activity:{state:e.state,details:e.details,timestamps:n,assets:i,party:s,secrets:r,buttons:e.buttons,instance:!!e.instance}})}clearActivity(e=l()){return this.request(a.SET_ACTIVITY,{pid:e})}sendJoinInvite(e){return this.request(a.SEND_ACTIVITY_JOIN_INVITE,{user_id:e.id||e})}sendJoinRequest(e){return this.request(a.SEND_ACTIVITY_JOIN_REQUEST,{user_id:e.id||e})}closeJoinRequest(e){return this.request(a.CLOSE_ACTIVITY_JOIN_REQUEST,{user_id:e.id||e})}createLobby(e,t,n){return this.request(a.CREATE_LOBBY,{type:e,capacity:t,metadata:n})}updateLobby(e,{type:t,owner:n,capacity:i,metadata:s}={}){return this.request(a.UPDATE_LOBBY,{id:e.id||e,type:t,owner_id:n&&n.id||n,capacity:i,metadata:s})}deleteLobby(e){return this.request(a.DELETE_LOBBY,{id:e.id||e})}connectToLobby(e,t){return this.request(a.CONNECT_TO_LOBBY,{id:e,secret:t})}sendToLobby(e,t){return this.request(a.SEND_TO_LOBBY,{id:e.id||e,data:t})}disconnectFromLobby(e){return this.request(a.DISCONNECT_FROM_LOBBY,{id:e.id||e})}updateLobbyMember(e,t,n){return this.request(a.UPDATE_LOBBY_MEMBER,{lobby_id:e.id||e,user_id:t.id||t,metadata:n})}getRelationships(){const e=Object.keys(E);return this.request(a.GET_RELATIONSHIPS).then(t=>t.relationships.map(t=>Object.assign({},t,{type:e[t.type]})))}subscribe(e,t,n){return n||"function"!=typeof t||(n=t,t=void 0),this.request(a.SUBSCRIBE,t,e).then(()=>{const i=_(e,t);return this._subscriptions.set(i,n),{unsubscribe:()=>this.request(a.UNSUBSCRIBE,t,e).then(()=>this._subscriptions.delete(i))}})}async destroy(){await this.transport.close()}}},function(e,t,n){(function(e){var i=void 0!==e&&e||"undefined"!=typeof self&&self||window,s=Function.prototype.apply;function r(e,t){this._id=e,this._clearFn=t}t.setTimeout=function(){return new r(s.call(setTimeout,i,arguments),clearTimeout)},t.setInterval=function(){return new r(s.call(setInterval,i,arguments),clearInterval)},t.clearTimeout=t.clearInterval=function(e){e&&e.close()},r.prototype.unref=r.prototype.ref=function(){},r.prototype.close=function(){this._clearFn.call(i,this._id)},t.enroll=function(e,t){clearTimeout(e._idleTimeoutId),e._idleTimeout=t},t.unenroll=function(e){clearTimeout(e._idleTimeoutId),e._idleTimeout=-1},t._unrefActive=t.active=function(e){clearTimeout(e._idleTimeoutId);var t=e._idleTimeout;t>=0&&(e._idleTimeoutId=setTimeout(function(){e._onTimeout&&e._onTimeout()},t))},n(11),t.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==e&&e.setImmediate||this&&this.setImmediate,t.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==e&&e.clearImmediate||this&&this.clearImmediate}).call(t,n(2))},function(e,t,n){(function(e){!function(e,t){"use strict";if(!e.setImmediate){var n,i=1,s={},r=!1,o=e.document,c=Object.getPrototypeOf&&Object.getPrototypeOf(e);c=c&&c.setTimeout?c:e,"[object process]"==={}.toString.call(e.process)?n=function(e){process.nextTick(function(){u(e)})}:function(){if(e.postMessage&&!e.importScripts){var t=!0,n=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=n,t}}()?function(){var t="setImmediate$"+Math.random()+"$",i=function(n){n.source===e&&"string"==typeof n.data&&0===n.data.indexOf(t)&&u(+n.data.slice(t.length))};e.addEventListener?e.addEventListener("message",i,!1):e.attachEvent("onmessage",i),n=function(n){e.postMessage(t+n,"*")}}():e.MessageChannel?function(){var e=new MessageChannel;e.port1.onmessage=function(e){u(e.data)},n=function(t){e.port2.postMessage(t)}}():o&&"onreadystatechange"in o.createElement("script")?function(){var e=o.documentElement;n=function(t){var n=o.createElement("script");n.onreadystatechange=function(){u(t),n.onreadystatechange=null,e.removeChild(n),n=null},e.appendChild(n)}}():n=function(e){setTimeout(u,0,e)},c.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),r=0;r<t.length;r++)t[r]=arguments[r+1];var o={callback:e,args:t};return s[i]=o,n(i),i++},c.clearImmediate=a}function a(e){delete s[e]}function u(e){if(r)setTimeout(u,0,e);else{var n=s[e];if(n){r=!0;try{!function(e){var n=e.callback,i=e.args;switch(i.length){case 0:n();break;case 1:n(i[0]);break;case 2:n(i[0],i[1]);break;case 3:n(i[0],i[1],i[2]);break;default:n.apply(t,i)}}(n)}finally{a(e),r=!1}}}}}("undefined"==typeof self?void 0===e?this:e:self)}).call(t,n(2))},function(e,t,n){"use strict";e.exports={ipc:n(13),websocket:n(15)}},function(e,t,n){"use strict";const i=n(14),s=n(0),r=n(3),{uuid:o}=n(1),c={HANDSHAKE:0,FRAME:1,CLOSE:2,PING:3,PONG:4};function a(e=0){return new Promise((t,n)=>{const s=function(e){if("win32"===process.platform)return`\\\\?\\pipe\\discord-ipc-${e}`;const{env:{XDG_RUNTIME_DIR:t,TMPDIR:n,TMP:i,TEMP:s}}=process;return`${(t||n||i||s||"/tmp").replace(/\/$/,"")}/discord-ipc-${e}`}(e),r=()=>{e<10?t(a(e+1)):n(new Error("Could not connect"))},o=i.createConnection(s,()=>{o.removeListener("error",r),t(o)});o.once("error",r)})}function u(e,t){t=JSON.stringify(t);const n=Buffer.byteLength(t),i=Buffer.alloc(8+n);return i.writeInt32LE(e,0),i.writeInt32LE(n,4),i.write(t,8,n),i}const E={full:"",op:void 0};function l(e,t){const n=e.read();if(!n)return;let i,{op:s}=E;if(""===E.full){s=E.op=n.readInt32LE(0);const e=n.readInt32LE(4);i=n.slice(8,e+8)}else i=n.toString();try{t({op:s,data:JSON.parse(E.full+i)}),E.full="",E.op=void 0}catch(e){E.full+=i}l(e,t)}e.exports=class extends s{constructor(e){super(),this.client=e,this.socket=null}async connect(){const e=this.socket=await a();e.on("close",this.onClose.bind(this)),e.on("error",this.onClose.bind(this)),this.emit("open"),e.write(u(c.HANDSHAKE,{v:1,client_id:this.client.clientId})),e.pause(),e.on("readable",()=>{l(e,({op:e,data:t})=>{switch(e){case c.PING:this.send(t,c.PONG);break;case c.FRAME:if(!t)return;"AUTHORIZE"===t.cmd&&"ERROR"!==t.evt&&async function e(t=0){if(t>30)throw new Error("Could not find endpoint");const n=`http://127.0.0.1:${6463+t%10}`;try{return 404===(await r(n)).status?n:e(t+1)}catch(n){return e(t+1)}}().then(e=>{this.client.request.endpoint=e}).catch(e=>{this.client.emit("error",e)}),this.emit("message",t);break;case c.CLOSE:this.emit("close",t)}})})}onClose(e){this.emit("close",e)}send(e,t=c.FRAME){this.socket.write(u(t,e))}async close(){return new Promise(e=>{this.once("close",e),this.send({},c.CLOSE),this.socket.end()})}ping(){this.send(o(),c.PING)}},e.exports.encode=u,e.exports.decode=l},function(e,t){},function(e,t,n){"use strict";const i=n(0),{browser:s}=n(4),r=s?window.WebSocket:n(16),o=e=>JSON.stringify(e),c=e=>JSON.parse(e);e.exports=class extends i{constructor(e){super(),this.client=e,this.ws=null,this.tries=0}async connect(){const e=6463+this.tries%10;this.tries+=1,this.ws=new r(`ws://127.0.0.1:${e}/?v=1&client_id=${this.client.clientId}`,s?void 0:{origin:this.client.options.origin}),this.ws.onopen=this.onOpen.bind(this),this.ws.onclose=this.onClose.bind(this),this.ws.onerror=this.onError.bind(this),this.ws.onmessage=this.onMessage.bind(this)}onOpen(){this.emit("open")}onClose(e){e.wasClean&&this.emit("close",e)}onError(e){try{this.ws.close()}catch(e){}this.tries>20?this.emit("error",e.error):setTimeout(()=>{this.connect()},250)}onMessage(e){this.emit("message",c(e.data))}send(e){this.ws.send(o(e))}ping(){}close(){return new Promise(e=>{this.once("close",e),this.ws.close()})}}},function(e,t){}])});