Socket
Socket
Sign inDemoInstall

tmi.js

Package Overview
Dependencies
4
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.9.0-pre.0 to 1.9.0-pre.1

lib/Client.js

14

dist/tmi.min.js

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

(()=>{var $=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var U=$(()=>{});var E=$(($e,q)=>{var he=/^\u0001ACTION ([^\u0001]+)\u0001$/,me=/^(justinfan)(\d+$)/,ue=/\\([sn:r\\])/g,fe=/([ \n;\r\\])/g,j={s:" ",n:"",":":";",r:""},J={" ":"s","\n":"n",";":":","\r":"r"},pe=q.exports={hasOwn:(t,e)=>({}).hasOwnProperty.call(t,e),promiseDelay:t=>new Promise(e=>setTimeout(e,t)),isInteger(t){return typeof t!="string"&&typeof t!="number"?!1:!isNaN(Math.round(t))},justinfan:()=>`justinfan${Math.floor(Math.random()*8e4+1e3)}`,isJustinfan:t=>me.test(t),channel(t){let e=(t||"").toLowerCase();return e[0]==="#"?e:`#${e}`},username(t){let e=(t||"").toLowerCase();return e[0]==="#"?e.slice(1):e},token:t=>t?t.toLowerCase().replace("oauth:",""):"",password(t){let e=pe.token(t);return e?`oauth:${e}`:""},actionMessage:t=>t.match(he),unescapeHtml:t=>t.replace(/\\&amp\\;/g,"&").replace(/\\&lt\\;/g,"<").replace(/\\&gt\\;/g,">").replace(/\\&quot\\;/g,'"').replace(/\\&#039\\;/g,"'"),unescapeIRC(t){return!t||typeof t!="string"||!t.includes("\\")?t:t.replace(ue,(e,s)=>s in j?j[s]:s)},escapeIRC(t){return!t||typeof t!="string"?t:t.replace(fe,(e,s)=>s in J?`\\${J[s]}`:s)},inherits(t,e){t.super_=e;let s=function(){};s.prototype=e.prototype,t.prototype=new s,t.prototype.constructor=t}}});var X=$((xe,Q)=>{var l=E();function H(t,e){return t=l.channel(t),e=e!=null?e:30,this._sendCommand(null,t,`/followers ${e}`,(s,i)=>this.once("_promiseFollowers",o=>o?i(o):s([t,~~e])))}function G(t){return t=l.channel(t),this._sendCommand(null,t,"/followersoff",(e,s)=>this.once("_promiseFollowersoff",i=>i?s(i):e([t])))}function V(t){return t=l.channel(t),this._sendCommand(null,null,`PART ${t}`,(e,s)=>this.once("_promisePart",i=>i?s(i):e([t])))}function W(t){return t=l.channel(t),this._sendCommand(null,t,"/r9kbeta",(e,s)=>this.once("_promiseR9kbeta",i=>i?s(i):e([t])))}function F(t){return t=l.channel(t),this._sendCommand(null,t,"/r9kbetaoff",(e,s)=>this.once("_promiseR9kbetaoff",i=>i?s(i):e([t])))}function B(t,e){return t=l.channel(t),e=e!=null?e:300,this._sendCommand(null,t,`/slow ${e}`,(s,i)=>this.once("_promiseSlow",o=>o?i(o):s([t,~~e])))}function z(t){return t=l.channel(t),this._sendCommand(null,t,"/slowoff",(e,s)=>this.once("_promiseSlowoff",i=>i?s(i):e([t])))}Q.exports={action(t,e){return t=l.channel(t),e=`ACTION ${e}`,this._sendMessage(this._getPromiseDelay(),t,e,(s,i)=>s([t,e]))},ban(t,e,s){return t=l.channel(t),e=l.username(e),s=s!=null?s:"",this._sendCommand(null,t,`/ban ${e} ${s}`,(i,o)=>this.once("_promiseBan",n=>n?o(n):i([t,e,s])))},clear(t){return t=l.channel(t),this._sendCommand(null,t,"/clear",(e,s)=>this.once("_promiseClear",i=>i?s(i):e([t])))},color(t,e){return e=e!=null?e:t,this._sendCommand(null,"#tmijs",`/color ${e}`,(s,i)=>this.once("_promiseColor",o=>o?i(o):s([e])))},commercial(t,e){return t=l.channel(t),e=e!=null?e:30,this._sendCommand(null,t,`/commercial ${e}`,(s,i)=>this.once("_promiseCommercial",o=>o?i(o):s([t,~~e])))},deletemessage(t,e){return t=l.channel(t),this._sendCommand(null,t,`/delete ${e}`,(s,i)=>this.once("_promiseDeletemessage",o=>o?i(o):s([t])))},emoteonly(t){return t=l.channel(t),this._sendCommand(null,t,"/emoteonly",(e,s)=>this.once("_promiseEmoteonly",i=>i?s(i):e([t])))},emoteonlyoff(t){return t=l.channel(t),this._sendCommand(null,t,"/emoteonlyoff",(e,s)=>this.once("_promiseEmoteonlyoff",i=>i?s(i):e([t])))},followersonly:H,followersmode:H,followersonlyoff:G,followersmodeoff:G,host(t,e){return t=l.channel(t),e=l.username(e),this._sendCommand(2e3,t,`/host ${e}`,(s,i)=>this.once("_promiseHost",(o,n)=>o?i(o):s([t,e,~~n])))},join(t){return t=l.channel(t),this._sendCommand(void 0,null,`JOIN ${t}`,(e,s)=>{let i="_promiseJoin",o=!1,n=(f,g)=>{t===l.channel(g)&&(this.removeListener(i,n),o=!0,f?s(f):e([t]))};this.on(i,n);let m=this._getPromiseDelay();l.promiseDelay(m).then(()=>{o||this.emit(i,"No response from Twitch.",t)})})},mod(t,e){return t=l.channel(t),e=l.username(e),this._sendCommand(null,t,`/mod ${e}`,(s,i)=>this.once("_promiseMod",o=>o?i(o):s([t,e])))},mods(t){return t=l.channel(t),this._sendCommand(null,t,"/mods",(e,s)=>{this.once("_promiseMods",(i,o)=>{i?s(i):(o.forEach(n=>{this.moderators[t]||(this.moderators[t]=[]),this.moderators[t].includes(n)||this.moderators[t].push(n)}),e(o))})})},part:V,leave:V,ping(){return this._sendCommand(null,null,"PING",(t,e)=>{var s;this.latency=new Date,this.pingTimeout=setTimeout(()=>{this.ws!==null&&(this.wasCloseCalled=!1,this.log.error("Ping timeout."),this.ws.close(),clearInterval(this.pingLoop),clearTimeout(this.pingTimeout))},(s=this.opts.connection.timeout)!=null?s:9999),this.once("_promisePing",i=>t([parseFloat(i)]))})},r9kbeta:W,r9kmode:W,r9kbetaoff:F,r9kmodeoff:F,raw(t){return this._sendCommand(null,null,t,(e,s)=>e([t]))},say(t,e){return t=l.channel(t),e.startsWith(".")&&!e.startsWith("..")||e.startsWith("/")||e.startsWith("\\")?e.slice(1,4)==="me "?this.action(t,e.slice(4)):this._sendCommand(null,t,e,(s,i)=>s([t,e])):this._sendMessage(this._getPromiseDelay(),t,e,(s,i)=>s([t,e]))},slow:B,slowmode:B,slowoff:z,slowmodeoff:z,subscribers(t){return t=l.channel(t),this._sendCommand(null,t,"/subscribers",(e,s)=>this.once("_promiseSubscribers",i=>i?s(i):e([t])))},subscribersoff(t){return t=l.channel(t),this._sendCommand(null,t,"/subscribersoff",(e,s)=>this.once("_promiseSubscribersoff",i=>i?s(i):e([t])))},timeout(t,e,s,i){return t=l.channel(t),e=l.username(e),(s!=null?s:!1)&&!l.isInteger(s)&&(i=s,s=300),s=s!=null?s:300,i=i!=null?i:"",this._sendCommand(null,t,`/timeout ${e} ${s} ${i}`,(o,n)=>this.once("_promiseTimeout",m=>m?n(m):o([t,e,~~s,i])))},unban(t,e){return t=l.channel(t),e=l.username(e),this._sendCommand(null,t,`/unban ${e}`,(s,i)=>this.once("_promiseUnban",o=>o?i(o):s([t,e])))},unhost(t){return t=l.channel(t),this._sendCommand(2e3,t,"/unhost",(e,s)=>this.once("_promiseUnhost",i=>i?s(i):e([t])))},unmod(t,e){return t=l.channel(t),e=l.username(e),this._sendCommand(null,t,`/unmod ${e}`,(s,i)=>this.once("_promiseUnmod",o=>o?i(o):s([t,e])))},unvip(t,e){return t=l.channel(t),e=l.username(e),this._sendCommand(null,t,`/unvip ${e}`,(s,i)=>this.once("_promiseUnvip",o=>o?i(o):s([t,e])))},vip(t,e){return t=l.channel(t),e=l.username(e),this._sendCommand(null,t,`/vip ${e}`,(s,i)=>this.once("_promiseVip",o=>o?i(o):s([t,e])))},vips(t){return t=l.channel(t),this._sendCommand(null,t,"/vips",(e,s)=>this.once("_promiseVips",(i,o)=>i?s(i):e(o)))},whisper(t,e){return t=l.username(t),t===this.getUsername()?Promise.reject("Cannot send a whisper to the same account."):this._sendCommand(null,"#tmijs",`/w ${t} ${e}`,(s,i)=>this.once("_promiseWhisper",o=>o&&i(o))).catch(s=>{if(s&&typeof s=="string"&&s.indexOf("No response from Twitch.")!==0)throw s;let i=l.channel(t),o=Object.assign({"message-type":"whisper","message-id":null,"thread-id":null,username:this.getUsername()},this.globaluserstate);return this.emits(["whisper","message"],[[i,o,e,!0],[i,o,e,!0]]),[t,e]})}}});var Z=$((Te,Y)=>{var y=class{constructor(){this._events=new Map,this._maxListeners=0}setMaxListeners(e){return this._maxListeners=e,this}emit(e,...s){if(e==="error"&&(!this._events.has("error")||!this._events.get("error").length))throw s[0]instanceof Error?s[0]:TypeError('Uncaught, unspecified "error" event.');let i=this._events.get(e);return i?(i.forEach(o=>o.apply(this,s)),!0):!1}on(e,s){this._events.has(e)||this._events.set(e,[]);let i=this._events.get(e);if(this._maxListeners&&i.length>=this._maxListeners)throw Error(`Max listeners exceeded for event '${e}'`);return i.push(s),this}once(e,s){let i=(...o)=>{this.removeListener(e,i),s(...o)};return this.on(e,i)}removeListener(e,s){let i=this._events.get(e);if(!i)return this;let o=i.indexOf(s);return o===-1?this:(i.splice(o,1),i.length===0&&this._events.delete(e),this)}removeAllListeners(e){return e?this._events.delete(e):this._events.clear(),this}listeners(e){return this._events.get(e)||[]}listenerCount(e){return this._events.get(e)?this._events.get(e).length:0}};y.prototype.addListener=y.prototype.on;y.prototype.off=y.prototype.removeListener;y.EventEmitter=y;y.defaultMaxListeners=10;Y.exports=y});var ee=$((Se,K)=>{var N=class{constructor(){this._levels={trace:0,debug:1,info:2,warn:3,error:4,fatal:5},this._currentLevel="info"}_log(e,s){if(this._levels[e]<this._levels[this._currentLevel])return;let i=new Date,o=i.getHours(),n=i.getMinutes(),m=`${(o<10?"0":"")+o}:${(n<10?"0":"")+n}`;console.log(`[${m}] ${e}: ${s}`)}setLevel(e){this._currentLevel=e}getLevel(){return this._currentLevel}trace(e){this._log("trace",e)}debug(e){this._log("debug",e)}info(e){this._log("info",e)}warn(e){this._log("warn",e)}error(e){this._log("error",e)}fatal(e){this._log("fatal",e)}};K.exports=N});var te=$((Ie,se)=>{var A=E(),I=/\S+/g;function P(t,e,s=",",i="/",o){let n=t[e];if(n===void 0)return t;let m=typeof n=="string";if(t[`${e}-raw`]=m?n:null,n===!0)return t[e]=null,t;if(t[e]={},m){let f=n.split(s);for(let g=0;g<f.length;g++){let k=f[g].split(i),w=k[1];o!==void 0&&w&&(w=w.split(o)),t[e][k[0]]=w||null}}return t}se.exports={badges:t=>P(t,"badges"),badgeInfo:t=>P(t,"badge-info"),emotes:t=>P(t,"emotes","/",":",","),emoteRegex(t,e,s,i){I.lastIndex=0;let o=new RegExp(`(\\b|^|\\s)${A.unescapeHtml(e)}(\\b|$|\\s)`),n;for(;(n=I.exec(t))!==null;)o.test(n[0])&&(i[s]=i[s]||[],i[s].push([n.index,I.lastIndex-1]))},emoteString(t,e,s,i){I.lastIndex=0;let o;for(;(o=I.exec(t))!==null;)o[0]===A.unescapeHtml(e)&&(i[s]=i[s]||[],i[s].push([o.index,I.lastIndex-1]))},transformEmotes(t){let e="";return Object.keys(t).forEach(s=>{e=`${e}${s}:`,t[s].forEach(i=>e=`${e}${i.join("-")},`),e=`${e.slice(0,-1)}/`}),e.slice(0,-1)},formTags(t){let e=[];for(let s in t){let i=A.escapeIRC(t[s]);e.push(`${s}=${i}`)}return`@${e.join(";")}`},msg(t){let e={raw:t,tags:{},prefix:null,command:null,params:[]},s=0,i=0;if(t.charCodeAt(0)===64){if(i=t.indexOf(" "),i===-1)return null;let o=t.slice(1,i).split(";");for(let n=0;n<o.length;n++){let m=o[n],f=m.split("=");e.tags[f[0]]=m.slice(m.indexOf("=")+1)||!0}s=i+1}for(;t.charCodeAt(s)===32;)s++;if(t.charCodeAt(s)===58){if(i=t.indexOf(" ",s),i===-1)return null;for(e.prefix=t.slice(s+1,i),s=i+1;t.charCodeAt(s)===32;)s++}if(i=t.indexOf(" ",s),i===-1)return t.length>s?(e.command=t.slice(s),e):null;for(e.command=t.slice(s,i),s=i+1;t.charCodeAt(s)===32;)s++;for(;s<t.length;){if(i=t.indexOf(" ",s),t.charCodeAt(s)===58){e.params.push(t.slice(s+1));break}if(i!==-1){for(e.params.push(t.slice(s,i)),s=i+1;t.charCodeAt(s)===32;)s++;continue}if(i===-1){e.params.push(t.slice(s));break}}return e}}});var oe=$((Le,ie)=>{var D=class{constructor(e){this.queue=[],this.index=0,this.defaultDelay=e===void 0?3e3:e}add(e,s){this.queue.push({fn:e,delay:s})}next(){let e=this.index++,s=this.queue[e];if(!s)return;let i=this.queue[this.index];if(s.fn(),i){let o=i.delay===void 0?this.defaultDelay:i.delay;setTimeout(()=>this.next(),o)}}};ie.exports=D});var ae=$((Ee,R)=>{var de=typeof global!="undefined"?global:typeof window!="undefined"?window:{},re,_e=(re=de.WebSocket)!=null?re:U(),ne=X(),ge=Z(),be=ee(),O=te(),we=oe(),h=E(),L=class extends ge{constructor(e){var s,i,o,n,m,f,g,k,w,x,S,v,r,a;super(),this.opts=e!=null?e:{},this.opts.channels=(s=this.opts.channels)!=null?s:[],this.opts.connection=(i=this.opts.connection)!=null?i:{},this.opts.identity=(o=this.opts.identity)!=null?o:{},this.opts.options=(n=this.opts.options)!=null?n:{},this.clientId=(m=this.opts.options.clientId)!=null?m:null,this._globalDefaultChannel=h.channel((f=this.opts.options.globalDefaultChannel)!=null?f:"#tmijs"),this._skipMembership=(g=this.opts.options.skipMembership)!=null?g:!1,this.maxReconnectAttempts=(k=this.opts.connection.maxReconnectAttempts)!=null?k:1/0,this.maxReconnectInterval=(w=this.opts.connection.maxReconnectInterval)!=null?w:3e4,this.reconnect=(x=this.opts.connection.reconnect)!=null?x:!0,this.reconnectDecay=(S=this.opts.connection.reconnectDecay)!=null?S:1.5,this.reconnectInterval=(v=this.opts.connection.reconnectInterval)!=null?v:1e3,this.reconnecting=!1,this.reconnections=0,this.reconnectTimer=this.reconnectInterval,this.secure=(r=this.opts.connection.secure)!=null?r:!this.opts.connection.server&&!this.opts.connection.port,this.emotes="",this.emotesets={},this.channels=[],this.currentLatency=0,this.globaluserstate={},this.lastJoined="",this.latency=new Date,this.moderators={},this.pingLoop=null,this.pingTimeout=null,this.reason="",this.username="",this.userstate={},this.wasCloseCalled=!1,this.ws=null,this.log=(a=this.opts.logger)!=null?a:new be;try{this.log.setLevel(this.opts.options.debug?"info":"error")}catch(u){}this.opts.channels.forEach((u,p,_)=>_[p]=h.channel(u)),this.setMaxListeners(0)}emits(e,s){for(let i=0;i<e.length;i++){let o=i<s.length?s[i]:s[s.length-1];this.emit(e[i],...o)}}api(){throw new Error("The Client.api() method has been removed.")}handleMessage(e){var m,f,g,k,w,x,S,v;if(!e)return;this.listenerCount("raw_message")&&this.emit("raw_message",JSON.parse(JSON.stringify(e)),e);let s=h.channel((m=e.params[0])!=null?m:null),i=(f=e.params[1])!=null?f:null,o=(g=e.tags["msg-id"])!=null?g:null,n=e.tags=O.badges(O.badgeInfo(O.emotes(e.tags)));for(let r in n){if(r==="emote-sets"||r==="ban-duration"||r==="bits")continue;let a=n[r];typeof a=="boolean"?a=null:a==="1"?a=!0:a==="0"?a=!1:typeof a=="string"&&(a=h.unescapeIRC(a)),n[r]=a}if(e.prefix===null)switch(e.command){case"PING":this.emit("ping"),this._isConnected()&&this.ws.send("PONG");break;case"PONG":{this.currentLatency=(new Date().getTime()-this.latency.getTime())/1e3,this.emits(["pong","_promisePing"],[[this.currentLatency]]),clearTimeout(this.pingTimeout);break}default:this.log.warn(`Could not parse message with no prefix:
${JSON.stringify(e,null,4)}`);break}else if(e.prefix==="tmi.twitch.tv")switch(e.command){case"002":case"003":case"004":case"372":case"375":case"CAP":break;case"001":this.username=e.params[0];break;case"376":{this.log.info("Connected to server."),this.userstate[this._globalDefaultChannel]={},this.emits(["connected","_promiseConnect"],[[this.server,this.port],[null]]),this.reconnections=0,this.reconnectTimer=this.reconnectInterval,this.pingLoop=setInterval(()=>{var p;this._isConnected()&&this.ws.send("PING"),this.latency=new Date,this.pingTimeout=setTimeout(()=>{this.ws!==null&&(this.wasCloseCalled=!1,this.log.error("Ping timeout."),this.ws.close(),clearInterval(this.pingLoop),clearTimeout(this.pingTimeout))},(p=this.opts.connection.timeout)!=null?p:9999)},6e4);let r=(k=this.opts.options.joinInterval)!=null?k:2e3;r<300&&(r=300);let a=new we(r),u=[...new Set([...this.opts.channels,...this.channels])];this.channels=[];for(let p=0;p<u.length;p++){let _=u[p];a.add(()=>{this._isConnected()&&this.join(_).catch(b=>this.log.error(b))})}a.next();break}case"NOTICE":{let r=[null],a=[s,o,i],u=[o],p=[s,!0],_=[s,!1],b=[a,r],d=[a,u],c=`[${s}] ${i}`;switch(o){case"subs_on":this.log.info(`[${s}] This room is now in subscribers-only mode.`),this.emits(["subscriber","subscribers","_promiseSubscribers"],[p,p,r]);break;case"subs_off":this.log.info(`[${s}] This room is no longer in subscribers-only mode.`),this.emits(["subscriber","subscribers","_promiseSubscribersoff"],[_,_,r]);break;case"emote_only_on":this.log.info(`[${s}] This room is now in emote-only mode.`),this.emits(["emoteonly","_promiseEmoteonly"],[p,r]);break;case"emote_only_off":this.log.info(`[${s}] This room is no longer in emote-only mode.`),this.emits(["emoteonly","_promiseEmoteonlyoff"],[_,r]);break;case"slow_on":case"slow_off":break;case"followers_on_zero":case"followers_on":case"followers_off":break;case"r9k_on":this.log.info(`[${s}] This room is now in r9k mode.`),this.emits(["r9kmode","r9kbeta","_promiseR9kbeta"],[p,p,r]);break;case"r9k_off":this.log.info(`[${s}] This room is no longer in r9k mode.`),this.emits(["r9kmode","r9kbeta","_promiseR9kbetaoff"],[_,_,r]);break;case"room_mods":{let C=i.split(": "),T=(C.length>1?C[1]:"").toLowerCase().split(", ").filter(M=>M);this.emits(["_promiseMods","mods"],[[null,T],[s,T]]);break}case"no_mods":this.emits(["_promiseMods","mods"],[[null,[]],[s,[]]]);break;case"vips_success":{let C=(i.endsWith(".")?i.slice(0,-1):i).split(": "),T=(C.length>1?C[1]:"").toLowerCase().split(", ").filter(M=>M);this.emits(["_promiseVips","vips"],[[null,T],[s,T]]);break}case"no_vips":this.emits(["_promiseVips","vips"],[[null,[]],[s,[]]]);break;case"already_banned":case"bad_ban_admin":case"bad_ban_anon":case"bad_ban_broadcaster":case"bad_ban_global_mod":case"bad_ban_mod":case"bad_ban_self":case"bad_ban_staff":case"usage_ban":this.log.info(c),this.emits(["notice","_promiseBan"],d);break;case"ban_success":this.log.info(c),this.emits(["notice","_promiseBan"],b);break;case"usage_clear":this.log.info(c),this.emits(["notice","_promiseClear"],d);break;case"usage_mods":this.log.info(c),this.emits(["notice","_promiseMods"],[a,[o,[]]]);break;case"mod_success":this.log.info(c),this.emits(["notice","_promiseMod"],b);break;case"usage_vips":this.log.info(c),this.emits(["notice","_promiseVips"],[a,[o,[]]]);break;case"usage_vip":case"bad_vip_grantee_banned":case"bad_vip_grantee_already_vip":case"bad_vip_max_vips_reached":case"bad_vip_achievement_incomplete":this.log.info(c),this.emits(["notice","_promiseVip"],[a,[o,[]]]);break;case"vip_success":this.log.info(c),this.emits(["notice","_promiseVip"],b);break;case"usage_mod":case"bad_mod_banned":case"bad_mod_mod":this.log.info(c),this.emits(["notice","_promiseMod"],d);break;case"unmod_success":this.log.info(c),this.emits(["notice","_promiseUnmod"],b);break;case"unvip_success":this.log.info(c),this.emits(["notice","_promiseUnvip"],b);break;case"usage_unmod":case"bad_unmod_mod":this.log.info(c),this.emits(["notice","_promiseUnmod"],d);break;case"usage_unvip":case"bad_unvip_grantee_not_vip":this.log.info(c),this.emits(["notice","_promiseUnvip"],d);break;case"color_changed":this.log.info(c),this.emits(["notice","_promiseColor"],b);break;case"usage_color":case"turbo_only_color":this.log.info(c),this.emits(["notice","_promiseColor"],d);break;case"commercial_success":this.log.info(c),this.emits(["notice","_promiseCommercial"],b);break;case"usage_commercial":case"bad_commercial_error":this.log.info(c),this.emits(["notice","_promiseCommercial"],d);break;case"hosts_remaining":{this.log.info(c);let C=isNaN(i[0])?0:parseInt(i[0]);this.emits(["notice","_promiseHost"],[a,[null,~~C]]);break}case"bad_host_hosting":case"bad_host_rate_exceeded":case"bad_host_error":case"usage_host":this.log.info(c),this.emits(["notice","_promiseHost"],[a,[o,null]]);break;case"already_r9k_on":case"usage_r9k_on":this.log.info(c),this.emits(["notice","_promiseR9kbeta"],d);break;case"already_r9k_off":case"usage_r9k_off":this.log.info(c),this.emits(["notice","_promiseR9kbetaoff"],d);break;case"timeout_success":this.log.info(c),this.emits(["notice","_promiseTimeout"],b);break;case"delete_message_success":this.log.info(`[${s} ${i}]`),this.emits(["notice","_promiseDeletemessage"],b);break;case"already_subs_off":case"usage_subs_off":this.log.info(c),this.emits(["notice","_promiseSubscribersoff"],d);break;case"already_subs_on":case"usage_subs_on":this.log.info(c),this.emits(["notice","_promiseSubscribers"],d);break;case"already_emote_only_off":case"usage_emote_only_off":this.log.info(c),this.emits(["notice","_promiseEmoteonlyoff"],d);break;case"already_emote_only_on":case"usage_emote_only_on":this.log.info(c),this.emits(["notice","_promiseEmoteonly"],d);break;case"usage_slow_on":this.log.info(c),this.emits(["notice","_promiseSlow"],d);break;case"usage_slow_off":this.log.info(c),this.emits(["notice","_promiseSlowoff"],d);break;case"usage_timeout":case"bad_timeout_admin":case"bad_timeout_anon":case"bad_timeout_broadcaster":case"bad_timeout_duration":case"bad_timeout_global_mod":case"bad_timeout_mod":case"bad_timeout_self":case"bad_timeout_staff":this.log.info(c),this.emits(["notice","_promiseTimeout"],d);break;case"untimeout_success":case"unban_success":this.log.info(c),this.emits(["notice","_promiseUnban"],b);break;case"usage_unban":case"bad_unban_no_ban":this.log.info(c),this.emits(["notice","_promiseUnban"],d);break;case"usage_delete":case"bad_delete_message_error":case"bad_delete_message_broadcaster":case"bad_delete_message_mod":this.log.info(c),this.emits(["notice","_promiseDeletemessage"],d);break;case"usage_unhost":case"not_hosting":this.log.info(c),this.emits(["notice","_promiseUnhost"],d);break;case"whisper_invalid_login":case"whisper_invalid_self":case"whisper_limit_per_min":case"whisper_limit_per_sec":case"whisper_restricted":case"whisper_restricted_recipient":this.log.info(c),this.emits(["notice","_promiseWhisper"],d);break;case"no_permission":case"msg_banned":case"msg_room_not_found":case"msg_channel_suspended":case"tos_ban":case"invalid_user":this.log.info(c),this.emits(["notice","_promiseBan","_promiseClear","_promiseUnban","_promiseTimeout","_promiseDeletemessage","_promiseMods","_promiseMod","_promiseUnmod","_promiseVips","_promiseVip","_promiseUnvip","_promiseCommercial","_promiseHost","_promiseUnhost","_promiseJoin","_promisePart","_promiseR9kbeta","_promiseR9kbetaoff","_promiseSlow","_promiseSlowoff","_promiseFollowers","_promiseFollowersoff","_promiseSubscribers","_promiseSubscribersoff","_promiseEmoteonly","_promiseEmoteonlyoff","_promiseWhisper"],[a,[o,s]]);break;case"msg_rejected":case"msg_rejected_mandatory":this.log.info(c),this.emit("automod",s,o,i);break;case"unrecognized_cmd":this.log.info(c),this.emit("notice",s,o,i);break;case"cmds_available":case"host_target_went_offline":case"msg_censored_broadcaster":case"msg_duplicate":case"msg_emoteonly":case"msg_verified_email":case"msg_ratelimit":case"msg_subsonly":case"msg_timedout":case"msg_bad_characters":case"msg_channel_blocked":case"msg_facebook":case"msg_followersonly":case"msg_followersonly_followed":case"msg_followersonly_zero":case"msg_slowmode":case"msg_suspended":case"no_help":case"usage_disconnect":case"usage_help":case"usage_me":case"unavailable_command":this.log.info(c),this.emit("notice",s,o,i);break;case"host_on":case"host_off":break;default:i.includes("Login unsuccessful")||i.includes("Login authentication failed")?(this.wasCloseCalled=!1,this.reconnect=!1,this.reason=i,this.log.error(this.reason),this.ws.close()):i.includes("Error logging in")||i.includes("Improperly formatted auth")?(this.wasCloseCalled=!1,this.reconnect=!1,this.reason=i,this.log.error(this.reason),this.ws.close()):i.includes("Invalid NICK")?(this.wasCloseCalled=!1,this.reconnect=!1,this.reason="Invalid NICK.",this.log.error(this.reason),this.ws.close()):(this.log.warn(`Could not parse NOTICE from tmi.twitch.tv:
${JSON.stringify(e,null,4)}`),this.emit("notice",s,o,i));break}break}case"USERNOTICE":{let r=n["display-name"]||n.login,a=(w=n["msg-param-sub-plan"])!=null?w:"",u=h.unescapeIRC((x=n["msg-param-sub-plan-name"])!=null?x:"")||null,_={prime:a.includes("Prime"),plan:a,planName:u},b=~~(n["msg-param-streak-months"]||0),d=n["msg-param-recipient-display-name"]||n["msg-param-recipient-user-name"],c=~~n["msg-param-mass-gift-count"];switch(n["message-type"]=o,o){case"resub":this.emits(["resub","subanniversary"],[[s,r,b,i,n,_]]);break;case"sub":this.emits(["subscription","sub"],[[s,r,_,i,n]]);break;case"subgift":this.emit("subgift",s,r,b,d,_,n);break;case"anonsubgift":this.emit("anonsubgift",s,b,d,_,n);break;case"submysterygift":this.emit("submysterygift",s,r,c,_,n);break;case"anonsubmysterygift":this.emit("anonsubmysterygift",s,c,_,n);break;case"primepaidupgrade":this.emit("primepaidupgrade",s,r,_,n);break;case"giftpaidupgrade":{let C=n["msg-param-sender-name"]||n["msg-param-sender-login"];this.emit("giftpaidupgrade",s,r,C,n);break}case"anongiftpaidupgrade":this.emit("anongiftpaidupgrade",s,r,n);break;case"announcement":{let C=n["msg-param-color"];this.emit("announcement",s,n,i,!1,C);break}case"raid":{let C=n["msg-param-displayName"]||n["msg-param-login"],T=+n["msg-param-viewerCount"];this.emit("raided",s,C,T,n);break}default:this.emit("usernotice",o,s,n,i);break}break}case"HOSTTARGET":{let r=i.split(" "),a=~~r[1]||0;r[0]==="-"?(this.log.info(`[${s}] Exited host mode.`),this.emits(["unhost","_promiseUnhost"],[[s,a],[null]])):(this.log.info(`[${s}] Now hosting ${r[0]} for ${a} viewer(s).`),this.emit("hosting",s,r[0],a));break}case"CLEARCHAT":if(e.params.length>1){let r=(S=e.tags["ban-duration"])!=null?S:null;r===null?(this.log.info(`[${s}] ${i} has been banned.`),this.emit("ban",s,i,null,e.tags)):(this.log.info(`[${s}] ${i} has been timed out for ${r} seconds.`),this.emit("timeout",s,i,null,~~r,e.tags))}else this.log.info(`[${s}] Chat was cleared by a moderator.`),this.emits(["clearchat","_promiseClear"],[[s],[null]]);break;case"CLEARMSG":if(e.params.length>1){let r=i,a=n.login;n["message-type"]="messagedeleted",this.log.info(`[${s}] ${a}'s message has been deleted.`),this.emit("messagedeleted",s,a,r,n)}break;case"RECONNECT":this.log.info("Received RECONNECT request from Twitch.."),this.log.info(`Disconnecting and reconnecting in ${Math.round(this.reconnectTimer/1e3)} seconds..`),this.disconnect().catch(r=>this.log.error(r)),setTimeout(()=>this.connect().catch(r=>this.log.error(r)),this.reconnectTimer);break;case"USERSTATE":e.tags.username=this.username,e.tags["user-type"]==="mod"&&(this.moderators[s]||(this.moderators[s]=[]),this.moderators[s].includes(this.username)||this.moderators[s].push(this.username)),!h.isJustinfan(this.getUsername())&&!this.userstate[s]&&(this.userstate[s]=n,this.lastJoined=s,this.channels.push(s),this.log.info(`Joined ${s}`),this.emit("join",s,h.username(this.getUsername()),!0)),e.tags["emote-sets"]!==this.emotes&&(this.emotes=e.tags["emote-sets"],this.emit("emotesets",this.emotes,null)),this.userstate[s]=n;break;case"GLOBALUSERSTATE":this.globaluserstate=n,this.emit("globaluserstate",n),e.tags["emote-sets"]!==void 0&&e.tags["emote-sets"]!==this.emotes&&(this.emotes=e.tags["emote-sets"],this.emit("emotesets",this.emotes,null));break;case"ROOMSTATE":if(h.channel(this.lastJoined)===s&&this.emit("_promiseJoin",null,s),e.tags.channel=s,this.emit("roomstate",s,e.tags),!h.hasOwn(e.tags,"subs-only")){if(h.hasOwn(e.tags,"slow"))if(typeof e.tags.slow=="boolean"&&!e.tags.slow){let r=[s,!1,0];this.log.info(`[${s}] This room is no longer in slow mode.`),this.emits(["slow","slowmode","_promiseSlowoff"],[r,r,[null]])}else{let r=~~e.tags.slow,a=[s,!0,r];this.log.info(`[${s}] This room is now in slow mode.`),this.emits(["slow","slowmode","_promiseSlow"],[a,a,[null]])}if(h.hasOwn(e.tags,"followers-only"))if(e.tags["followers-only"]==="-1"){let r=[s,!1,0];this.log.info(`[${s}] This room is no longer in followers-only mode.`),this.emits(["followersonly","followersmode","_promiseFollowersoff"],[r,r,[null]])}else{let r=~~e.tags["followers-only"],a=[s,!0,r];this.log.info(`[${s}] This room is now in follower-only mode.`),this.emits(["followersonly","followersmode","_promiseFollowers"],[a,a,[null]])}}break;case"SERVERCHANGE":break;default:this.log.warn(`Could not parse message from tmi.twitch.tv:
${JSON.stringify(e,null,4)}`);break}else if(e.prefix==="jtv")switch(e.command){case"MODE":i==="+o"?(this.moderators[s]||(this.moderators[s]=[]),this.moderators[s].includes(e.params[2])||this.moderators[s].push(e.params[2]),this.emit("mod",s,e.params[2])):i==="-o"&&(this.moderators[s]||(this.moderators[s]=[]),this.moderators[s].filter(r=>r!==e.params[2]),this.emit("unmod",s,e.params[2]));break;default:this.log.warn(`Could not parse message from jtv:
${JSON.stringify(e,null,4)}`);break}else switch(e.command){case"353":this.emit("names",e.params[2],e.params[3].split(" "));break;case"366":break;case"JOIN":{let r=e.prefix.split("!")[0],a=this.username===r&&h.isJustinfan(this.getUsername());a&&(this.lastJoined=s,this.channels.push(s),this.log.info(`Joined ${s}`)),this.emit("join",s,r,a);break}case"PART":{let r=e.prefix.split("!")[0],a=this.username===r;if(a){this.userstate[s]&&delete this.userstate[s];let u=this.channels.indexOf(s);u!==-1&&this.channels.splice(u,1),u=this.opts.channels.indexOf(s),u!==-1&&this.opts.channels.splice(u,1),this.log.info(`Left ${s}`),this.emit("_promisePart",null)}this.emit("part",s,r,a);break}case"WHISPER":{let r=e.prefix.split("!")[0];this.log.info(`[WHISPER] <${r}>: ${i}`),h.hasOwn(e.tags,"username")||(e.tags.username=r),e.tags["message-type"]="whisper";let a=h.channel(e.tags.username);this.emits(["whisper","message"],[[a,e.tags,i,!1]]);break}case"PRIVMSG":if(e.tags.username=e.prefix.split("!")[0],e.tags.username==="jtv"){let r=h.username(i.split(" ")[0]),a=i.includes("auto");if(i.includes("hosting you for")){let u=0,p=i.split(" ");for(let _=0;_<p.length;_++)if(h.isInteger(p[_])){u=~~p[_];break}this.emit("hosted",s,r,u,a)}else i.includes("hosting you")&&this.emit("hosted",s,r,0,a)}else{let r=(v=this.opts.options.messagesLogLevel)!=null?v:"info",a=h.actionMessage(i);e.tags["message-type"]=a?"action":"chat";let u=a?a[1]:i;if(h.hasOwn(e.tags,"bits"))this.emit("cheer",s,e.tags,u);else{if(h.hasOwn(e.tags,"msg-id")){if(e.tags["msg-id"]==="highlighted-message"){let p=e.tags["msg-id"];this.emit("redeem",s,e.tags.username,p,e.tags,u)}else if(e.tags["msg-id"]==="skip-subs-mode-message"){let p=e.tags["msg-id"];this.emit("redeem",s,e.tags.username,p,e.tags,u)}}else if(h.hasOwn(e.tags,"custom-reward-id")){let p=e.tags["custom-reward-id"];this.emit("redeem",s,e.tags.username,p,e.tags,u)}a?(this.log[r](`[${s}] *<${e.tags.username}>: ${u}`),this.emits(["action","message"],[[s,e.tags,u,!1]])):(this.log[r](`[${s}] <${e.tags.username}>: ${u}`),this.emits(["chat","message"],[[s,e.tags,u,!1]]))}}break;default:this.log.warn(`Could not parse message:
${JSON.stringify(e,null,4)}`);break}}connect(){return new Promise((e,s)=>{var i,o;this.server=(i=this.opts.connection.server)!=null?i:"irc-ws.chat.twitch.tv",this.port=(o=this.opts.connection.port)!=null?o:80,this.secure&&(this.port=443),this.port===443&&(this.secure=!0),this.reconnectTimer=this.reconnectTimer*this.reconnectDecay,this.reconnectTimer>=this.maxReconnectInterval&&(this.reconnectTimer=this.maxReconnectInterval),this._openConnection(),this.once("_promiseConnect",n=>{n?s(n):e([this.server,~~this.port])})})}_openConnection(){let e=`${this.secure?"wss":"ws"}://${this.server}:${this.port}/`,s={};"agent"in this.opts.connection&&(s.agent=this.opts.connection.agent),this.ws=new _e(e,"irc",s),this.ws.onmessage=this._onMessage.bind(this),this.ws.onerror=this._onError.bind(this),this.ws.onclose=this._onClose.bind(this),this.ws.onopen=this._onOpen.bind(this)}_onOpen(){var e;!this._isConnected()||(this.log.info(`Connecting to ${this.server} on port ${this.port}..`),this.emit("connecting",this.server,~~this.port),this.username=(e=this.opts.identity.username)!=null?e:h.justinfan(),this._getToken().then(s=>{let i=h.password(s);this.log.info("Sending authentication to server.."),this.emit("logon");let o="twitch.tv/tags twitch.tv/commands";this._skipMembership||(o+=" twitch.tv/membership"),this.ws.send(`CAP REQ :${o}`),i?this.ws.send(`PASS ${i}`):h.isJustinfan(this.username)&&this.ws.send("PASS SCHMOOPIIE"),this.ws.send(`NICK ${this.username}`)}).catch(s=>{this.emits(["_promiseConnect","disconnected"],[[s],["Could not get a token."]])}))}_getToken(){let e=this.opts.identity.password,s=typeof e=="function"?e():e;return Promise.resolve(s)}_onMessage(e){e.data.trim().split(`\r
`).forEach(i=>{let o=O.msg(i);o&&this.handleMessage(o)})}_onError(){this.moderators={},this.userstate={},this.globaluserstate={},clearInterval(this.pingLoop),clearTimeout(this.pingTimeout),this.reason=this.ws===null?"Connection closed.":"Unable to connect.",this.emits(["_promiseConnect","disconnected"],[[this.reason]]),this.reconnect&&this.reconnections===this.maxReconnectAttempts&&(this.emit("maxreconnect"),this.log.error("Maximum reconnection attempts reached.")),this.reconnect&&!this.reconnecting&&this.reconnections<=this.maxReconnectAttempts-1&&(this.reconnecting=!0,this.reconnections=this.reconnections+1,this.log.error(`Reconnecting in ${Math.round(this.reconnectTimer/1e3)} seconds..`),this.emit("reconnect"),setTimeout(()=>{this.reconnecting=!1,this.connect().catch(e=>this.log.error(e))},this.reconnectTimer)),this.ws=null}_onClose(){this.moderators={},this.userstate={},this.globaluserstate={},clearInterval(this.pingLoop),clearTimeout(this.pingTimeout),this.wasCloseCalled?(this.wasCloseCalled=!1,this.reason="Connection closed.",this.log.info(this.reason),this.emits(["_promiseConnect","_promiseDisconnect","disconnected"],[[this.reason],[null],[this.reason]])):(this.emits(["_promiseConnect","disconnected"],[[this.reason]]),!this.wasCloseCalled&&this.reconnect&&this.reconnections===this.maxReconnectAttempts&&(this.emit("maxreconnect"),this.log.error("Maximum reconnection attempts reached.")),!this.wasCloseCalled&&this.reconnect&&!this.reconnecting&&this.reconnections<=this.maxReconnectAttempts-1&&(this.reconnecting=!0,this.reconnections=this.reconnections+1,this.log.error(`Could not connect to server. Reconnecting in ${Math.round(this.reconnectTimer/1e3)} seconds..`),this.emit("reconnect"),setTimeout(()=>{this.reconnecting=!1,this.connect().catch(e=>this.log.error(e))},this.reconnectTimer))),this.ws=null}_getPromiseDelay(){return this.currentLatency<=600?600:this.currentLatency+100}_sendCommand(e,s,i,o){return new Promise((n,m)=>{if(this._isConnected())(e===null||typeof e=="number")&&(e===null&&(e=this._getPromiseDelay()),h.promiseDelay(e).then(()=>m("No response from Twitch.")));else return m("Not connected to server.");if(s!==null){let f=h.channel(s);this.log.info(`[${f}] Executing command: ${i}`),this.ws.send(`PRIVMSG ${f} :${i}`)}else this.log.info(`Executing command: ${i}`),this.ws.send(i);typeof o=="function"?o(n,m):n()})}_sendMessage(e,s,i,o){return new Promise((n,m)=>{var x;if(this._isConnected()){if(h.isJustinfan(this.getUsername()))return m("Cannot send anonymous messages.")}else return m("Not connected to server.");let f=h.channel(s);if(this.userstate[f]||(this.userstate[f]={}),i.length>500){let v=i,r=v.slice(0,500).lastIndexOf(" ");r===-1&&(r=500),i=v.slice(0,r),setTimeout(()=>{this._sendMessage(e,s,v.slice(r),()=>{})},350)}this.ws.send(`PRIVMSG ${f} :${i}`);let g=Object.assign({},this.userstate[f],{emotes:null}),k=(x=this.opts.options.messagesLogLevel)!=null?x:"info",w=h.actionMessage(i);w?(g["message-type"]="action",this.log[k](`[${f}] *<${this.getUsername()}>: ${w[1]}`),this.emits(["action","message"],[[f,g,w[1],!0]])):(g["message-type"]="chat",this.log[k](`[${f}] <${this.getUsername()}>: ${i}`),this.emits(["chat","message"],[[f,g,i,!0]])),typeof o=="function"?o(n,m):n()})}getUsername(){return this.username}getOptions(){return this.opts}getChannels(){return this.channels}isMod(e,s){let i=h.channel(e);return this.moderators[i]||(this.moderators[i]=[]),this.moderators[i].includes(h.username(s))}readyState(){return this.ws===null?"CLOSED":["CONNECTING","OPEN","CLOSING","CLOSED"][this.ws.readyState]}_isConnected(){return this.ws!==null&&this.ws.readyState===1}disconnect(){return new Promise((e,s)=>{this.ws!==null&&this.ws.readyState!==3?(this.wasCloseCalled=!0,this.log.info("Disconnecting from server.."),this.ws.close(),this.once("_promiseDisconnect",()=>e([this.server,~~this.port]))):(this.log.error("Cannot disconnect from server. Socket is not opened or connection is already closing."),s("Cannot disconnect from server. Socket is not opened or connection is already closing."))})}};for(let t in ne)L.prototype[t]=ne[t];typeof R!="undefined"&&R.exports&&(R.exports=L);typeof window!="undefined"&&(window.tmi={client:L,Client:L})});var Ce=$((Oe,le)=>{var ce=ae();le.exports={client:ce,Client:ce}});Ce();})();
var tmi=(()=>{var oe=Object.defineProperty;var k=(n,e)=>oe(n,"name",{value:e,configurable:!0});var T=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var j=T(()=>{});var q=T((ke,J)=>{var v=class{constructor(){this._events=new Map,this._maxListeners=0}setMaxListeners(e){return this._maxListeners=e,this}emit(e,...s){if(e==="error"&&(!this._events.has("error")||!this._events.get("error").length))throw s[0]instanceof Error?s[0]:TypeError('Uncaught, unspecified "error" event.');let t=this._events.get(e);return t?(t.forEach(i=>i.apply(this,s)),!0):!1}emits(e,s){for(let t=0;t<e.length;t++){let i=t<s.length?s[t]:s[s.length-1];this.emit(e[t],...i)}}on(e,s){this._events.has(e)||this._events.set(e,[]);let t=this._events.get(e);if(this._maxListeners&&t.length>=this._maxListeners)throw Error(`Max listeners exceeded for event '${e}'`);return t.push(s),this}once(e,s){let t=k((...i)=>{this.removeListener(e,t),s(...i)},"onceListener");return this.on(e,t)}off(e,s){let t=this._events.get(e);if(!t)return this;let i=t.indexOf(s);return i===-1?this:(t.splice(i,1),t.length===0&&this._events.delete(e),this)}removeAllListeners(e){return e?this._events.delete(e):this._events.clear(),this}listeners(e){return this._events.get(e)||[]}listenerCount(e){return this._events.get(e)?this._events.get(e).length:0}};k(v,"EventEmitter");v.prototype.addListener=v.prototype.on;v.prototype.removeListener=v.prototype.off;v.EventEmitter=v;v.defaultMaxListeners=10;J.exports=v});var G=T((Ce,H)=>{var L=class{constructor(){this._levels={trace:0,debug:1,info:2,warn:3,error:4,fatal:5},this._currentLevel="error"}_log(e,s){if(this._levels[e]<this._levels[this._currentLevel])return;let t=new Date,i=t.getHours(),o=t.getMinutes(),h=`${(i<10?"0":"")+i}:${(o<10?"0":"")+o}`;console.log(`[${h}] ${e}: ${s}`)}setLevel(e){this._currentLevel=e}getLevel(){return this._currentLevel}trace(e){this._log("trace",e)}debug(e){this._log("debug",e)}info(e){this._log("info",e)}warn(e){this._log("warn",e)}error(e){this._log("error",e)}fatal(e){this._log("fatal",e)}};k(L,"Logger");H.exports=L});var M=T(($e,F)=>{var ne=/^\u0001ACTION ([^\u0001]+)\u0001$/,re=/^(justinfan)(\d+$)/,ae=/\\([sn:r\\])/g,ce=/([ \n;\r\\])/g,le=/^oauth:/i,V={s:" ",n:"",":":";",r:""},W={" ":"s","\n":"n",";":":","\r":"r"},he=F.exports={hasOwn:(n,e)=>({}).hasOwnProperty.call(n,e),promiseDelay:n=>new Promise(e=>setTimeout(e,n)),isInteger(n){return typeof n!="string"&&typeof n!="number"?!1:!isNaN(Math.round(n))},justinfan:()=>`justinfan${Math.floor(Math.random()*8e4+1e3)}`,isJustinfan:n=>re.test(n),channel(n){let e=(n||"").toLowerCase();return e[0]==="#"?e:`#${e}`},username(n){let e=(n||"").toLowerCase();return e[0]==="#"?e.slice(1):e},token:n=>n?n.replace(le,""):"",password(n){let e=he.token(n);return e?`oauth:${e}`:""},actionMessage:n=>n.match(ne),unescapeHtml:n=>n.replace(/\\&amp\\;/g,"&").replace(/\\&lt\\;/g,"<").replace(/\\&gt\\;/g,">").replace(/\\&quot\\;/g,'"').replace(/\\&#039\\;/g,"'"),unescapeIRC(n){return!n||typeof n!="string"||!n.includes("\\")?n:n.replace(ae,(e,s)=>s in V?V[s]:s)},escapeIRC(n){return!n||typeof n!="string"?n:n.replace(ce,(e,s)=>s in W?`\\${W[s]}`:s)},inherits(n,e){n.super_=e;let s=k(function(){},"TempCtor");s.prototype=e.prototype,n.prototype=new s,n.prototype.constructor=n}}});var z=T((ve,B)=>{var N=M(),E=/\S+/g;function U(n,e,s=",",t="/",i){let o=n[e];if(o===void 0)return n;let h=typeof o=="string";if(n[`${e}-raw`]=h?o:null,o===!0)return n[e]=null,n;if(n[e]={},h){let u=o.split(s);for(let b=0;b<u.length;b++){let w=u[b].split(t),[,C]=w;i!==void 0&&C&&(C=C.split(i)),n[e][w[0]]=C||null}}return n}k(U,"parseComplexTag");B.exports={badges:n=>U(n,"badges"),badgeInfo:n=>U(n,"badge-info"),emotes:n=>U(n,"emotes","/",":",","),emoteRegex(n,e,s,t){E.lastIndex=0;let i=new RegExp(`(\\b|^|\\s)${N.unescapeHtml(e)}(\\b|$|\\s)`),o;for(;(o=E.exec(n))!==null;)i.test(o[0])&&(t[s]=t[s]||[],t[s].push([o.index,E.lastIndex-1]))},emoteString(n,e,s,t){E.lastIndex=0;let i;for(;(i=E.exec(n))!==null;)i[0]===N.unescapeHtml(e)&&(t[s]=t[s]||[],t[s].push([i.index,E.lastIndex-1]))},transformEmotes(n){let e="";return Object.keys(n).forEach(s=>{e=`${e}${s}:`,n[s].forEach(t=>e=`${e}${t.join("-")},`),e=`${e.slice(0,-1)}/`}),e.slice(0,-1)},formTags(n={}){let e=Object.entries(n).map(([s,t])=>`${N.escapeIRC(s)}=${N.escapeIRC(t)}`);return e.length?`@${e.join(";")}`:null},msg(n){let e={raw:n,tags:{},prefix:null,command:null,params:[]},s=0,t=0;if(n.charCodeAt(0)===64){if(t=n.indexOf(" "),t===-1)return null;let i=n.slice(1,t).split(";");for(let o=0;o<i.length;o++){let h=i[o],u=h.split("=");e.tags[u[0]]=h.slice(h.indexOf("=")+1)||!0}s=t+1}for(;n.charCodeAt(s)===32;)s++;if(n.charCodeAt(s)===58){if(t=n.indexOf(" ",s),t===-1)return null;for(e.prefix=n.slice(s+1,t),s=t+1;n.charCodeAt(s)===32;)s++}if(t=n.indexOf(" ",s),t===-1)return n.length>s?(e.command=n.slice(s),e):null;for(e.command=n.slice(s,t),s=t+1;n.charCodeAt(s)===32;)s++;for(;s<n.length;){if(t=n.indexOf(" ",s),n.charCodeAt(s)===58){e.params.push(n.slice(s+1));break}if(t!==-1){for(e.params.push(n.slice(s,t)),s=t+1;n.charCodeAt(s)===32;)s++;continue}if(t===-1){e.params.push(n.slice(s));break}}return e}}});var X=T((xe,Q)=>{var A=class{constructor(e){this.queue=[],this.index=0,this.defaultDelay=e===void 0?3e3:e}add(e,s){this.queue.push({fn:e,delay:s})}next(){let e=this.index++,s=this.queue[e];if(!s)return;let t=this.queue[this.index];if(s.fn(),t){let i=t.delay===void 0?this.defaultDelay:t.delay;setTimeout(()=>this.next(),i)}}};k(A,"Queue");Q.exports=A});var K=T((Te,Z)=>{var me=typeof global!="undefined"?global:typeof window!="undefined"?window:{},Y,ue=(Y=me.WebSocket)!=null?Y:j(),pe=q(),fe=G(),R=z(),de=X(),m=M(),P=class extends pe{constructor(e){var s,t,i,o,h,u,b,w,C,x,S,O,r,a;super(),this.opts=e!=null?e:{},this.opts.channels=(s=this.opts.channels)!=null?s:[],this.opts.connection=(t=this.opts.connection)!=null?t:{},this.opts.identity=(i=this.opts.identity)!=null?i:{},this.opts.options=(o=this.opts.options)!=null?o:{},this.clientId=(h=this.opts.options.clientId)!=null?h:null,this._globalDefaultChannel=m.channel((u=this.opts.options.globalDefaultChannel)!=null?u:"#tmijs"),this._skipMembership=(b=this.opts.options.skipMembership)!=null?b:!1,this.maxReconnectAttempts=(w=this.opts.connection.maxReconnectAttempts)!=null?w:1/0,this.maxReconnectInterval=(C=this.opts.connection.maxReconnectInterval)!=null?C:3e4,this.reconnect=(x=this.opts.connection.reconnect)!=null?x:!0,this.reconnectDecay=(S=this.opts.connection.reconnectDecay)!=null?S:1.5,this.reconnectInterval=(O=this.opts.connection.reconnectInterval)!=null?O:1e3,this.reconnecting=!1,this.reconnections=0,this.reconnectTimer=this.reconnectInterval,this.currentLatency=0,this.latency=new Date,this.secure=(r=this.opts.connection.secure)!=null?r:!this.opts.connection.server&&!this.opts.connection.port,this.pingLoop=null,this.pingTimeout=null,this.wasCloseCalled=!1,this.reason="",this.ws=null,this.emotes="",this.emotesets={},this.username="",this.channels=[],this.globaluserstate={},this.userstate={},this.lastJoined="",this.moderators={},this.log=(a=this.opts.logger)!=null?a:new fe;try{this.log.setLevel(this.opts.options.debug?"info":"error")}catch(p){}this.opts.channels.forEach((p,f,_)=>_[f]=m.channel(p)),this.setMaxListeners(0)}api(){throw new Error("The Client.api() method has been removed.")}handleMessage(e){var h,u,b,w,C,x,S,O;if(!e)return;this.listenerCount("raw_message")&&this.emit("raw_message",JSON.parse(JSON.stringify(e)),e);let s=m.channel((h=e.params[0])!=null?h:null),t=(u=e.params[1])!=null?u:null,i=(b=e.tags["msg-id"])!=null?b:null,o=e.tags=R.badges(R.badgeInfo(R.emotes(e.tags)));for(let r in o){if(r==="emote-sets"||r==="ban-duration"||r==="bits")continue;let a=o[r];typeof a=="boolean"?a=null:a==="1"?a=!0:a==="0"?a=!1:typeof a=="string"&&(a=m.unescapeIRC(a)),o[r]=a}if(e.prefix===null)switch(e.command){case"PING":this.emit("ping"),this._isConnected()&&this.ws.send("PONG");break;case"PONG":{this.currentLatency=(new Date().getTime()-this.latency.getTime())/1e3,this.emits(["pong","_promisePing"],[[this.currentLatency]]),clearTimeout(this.pingTimeout);break}default:this.log.warn(`Could not parse message with no prefix:
${JSON.stringify(e,null,4)}`);break}else if(e.prefix==="tmi.twitch.tv")switch(e.command){case"002":case"003":case"004":case"372":case"375":case"CAP":break;case"001":[this.username]=e.params;break;case"376":{this.log.info("Connected to server."),this.userstate[this._globalDefaultChannel]={},this.emits(["connected","_promiseConnect"],[[this.server,this.port],[null]]),this.reconnections=0,this.reconnectTimer=this.reconnectInterval,this.pingLoop=setInterval(()=>{var f;this._isConnected()&&this.ws.send("PING"),this.latency=new Date,this.pingTimeout=setTimeout(()=>{this.ws!==null&&(this.wasCloseCalled=!1,this.log.error("Ping timeout."),this.ws.close(),clearInterval(this.pingLoop),clearTimeout(this.pingTimeout))},(f=this.opts.connection.timeout)!=null?f:9999)},6e4);let r=(w=this.opts.options.joinInterval)!=null?w:2e3;r<300&&(r=300);let a=new de(r),p=[...new Set([...this.opts.channels,...this.channels])];this.channels=[];for(let f=0;f<p.length;f++){let _=p[f];a.add(()=>{this._isConnected()&&this.join(_).catch(y=>this.log.error(y))})}a.next();break}case"NOTICE":{let r=[null],a=[s,i,t],p=[i],f=[s,!0],_=[s,!1],y=[a,r],d=[a,p],c=`[${s}] ${t}`;switch(i){case"subs_on":this.log.info(`[${s}] This room is now in subscribers-only mode.`),this.emits(["subscriber","subscribers","_promiseSubscribers"],[f,f,r]);break;case"subs_off":this.log.info(`[${s}] This room is no longer in subscribers-only mode.`),this.emits(["subscriber","subscribers","_promiseSubscribersoff"],[_,_,r]);break;case"emote_only_on":this.log.info(`[${s}] This room is now in emote-only mode.`),this.emits(["emoteonly","_promiseEmoteonly"],[f,r]);break;case"emote_only_off":this.log.info(`[${s}] This room is no longer in emote-only mode.`),this.emits(["emoteonly","_promiseEmoteonlyoff"],[_,r]);break;case"slow_on":case"slow_off":break;case"followers_on_zero":case"followers_on":case"followers_off":break;case"r9k_on":this.log.info(`[${s}] This room is now in r9k mode.`),this.emits(["r9kmode","r9kbeta","_promiseR9kbeta"],[f,f,r]);break;case"r9k_off":this.log.info(`[${s}] This room is no longer in r9k mode.`),this.emits(["r9kmode","r9kbeta","_promiseR9kbetaoff"],[_,_,r]);break;case"room_mods":{let $=t.split(": "),I=($.length>1?$[1]:"").toLowerCase().split(", ").filter(D=>D);this.emits(["_promiseMods","mods"],[[null,I],[s,I]]);break}case"no_mods":this.emits(["_promiseMods","mods"],[[null,[]],[s,[]]]);break;case"vips_success":{let $=(t.endsWith(".")?t.slice(0,-1):t).split(": "),I=($.length>1?$[1]:"").toLowerCase().split(", ").filter(D=>D);this.emits(["_promiseVips","vips"],[[null,I],[s,I]]);break}case"no_vips":this.emits(["_promiseVips","vips"],[[null,[]],[s,[]]]);break;case"already_banned":case"bad_ban_admin":case"bad_ban_anon":case"bad_ban_broadcaster":case"bad_ban_global_mod":case"bad_ban_mod":case"bad_ban_self":case"bad_ban_staff":case"usage_ban":this.log.info(c),this.emits(["notice","_promiseBan"],d);break;case"ban_success":this.log.info(c),this.emits(["notice","_promiseBan"],y);break;case"usage_clear":this.log.info(c),this.emits(["notice","_promiseClear"],d);break;case"usage_mods":this.log.info(c),this.emits(["notice","_promiseMods"],[a,[i,[]]]);break;case"mod_success":this.log.info(c),this.emits(["notice","_promiseMod"],y);break;case"usage_vips":this.log.info(c),this.emits(["notice","_promiseVips"],[a,[i,[]]]);break;case"usage_vip":case"bad_vip_grantee_banned":case"bad_vip_grantee_already_vip":case"bad_vip_max_vips_reached":case"bad_vip_achievement_incomplete":this.log.info(c),this.emits(["notice","_promiseVip"],[a,[i,[]]]);break;case"vip_success":this.log.info(c),this.emits(["notice","_promiseVip"],y);break;case"usage_mod":case"bad_mod_banned":case"bad_mod_mod":this.log.info(c),this.emits(["notice","_promiseMod"],d);break;case"unmod_success":this.log.info(c),this.emits(["notice","_promiseUnmod"],y);break;case"unvip_success":this.log.info(c),this.emits(["notice","_promiseUnvip"],y);break;case"usage_unmod":case"bad_unmod_mod":this.log.info(c),this.emits(["notice","_promiseUnmod"],d);break;case"usage_unvip":case"bad_unvip_grantee_not_vip":this.log.info(c),this.emits(["notice","_promiseUnvip"],d);break;case"color_changed":this.log.info(c),this.emits(["notice","_promiseColor"],y);break;case"usage_color":case"turbo_only_color":this.log.info(c),this.emits(["notice","_promiseColor"],d);break;case"commercial_success":this.log.info(c),this.emits(["notice","_promiseCommercial"],y);break;case"usage_commercial":case"bad_commercial_error":this.log.info(c),this.emits(["notice","_promiseCommercial"],d);break;case"hosts_remaining":{this.log.info(c);let $=isNaN(t[0])?0:parseInt(t[0]);this.emits(["notice","_promiseHost"],[a,[null,~~$]]);break}case"bad_host_hosting":case"bad_host_rate_exceeded":case"bad_host_error":case"usage_host":this.log.info(c),this.emits(["notice","_promiseHost"],[a,[i,null]]);break;case"already_r9k_on":case"usage_r9k_on":this.log.info(c),this.emits(["notice","_promiseR9kbeta"],d);break;case"already_r9k_off":case"usage_r9k_off":this.log.info(c),this.emits(["notice","_promiseR9kbetaoff"],d);break;case"timeout_success":this.log.info(c),this.emits(["notice","_promiseTimeout"],y);break;case"delete_message_success":this.log.info(`[${s} ${t}]`),this.emits(["notice","_promiseDeletemessage"],y);break;case"already_subs_off":case"usage_subs_off":this.log.info(c),this.emits(["notice","_promiseSubscribersoff"],d);break;case"already_subs_on":case"usage_subs_on":this.log.info(c),this.emits(["notice","_promiseSubscribers"],d);break;case"already_emote_only_off":case"usage_emote_only_off":this.log.info(c),this.emits(["notice","_promiseEmoteonlyoff"],d);break;case"already_emote_only_on":case"usage_emote_only_on":this.log.info(c),this.emits(["notice","_promiseEmoteonly"],d);break;case"usage_slow_on":this.log.info(c),this.emits(["notice","_promiseSlow"],d);break;case"usage_slow_off":this.log.info(c),this.emits(["notice","_promiseSlowoff"],d);break;case"usage_timeout":case"bad_timeout_admin":case"bad_timeout_anon":case"bad_timeout_broadcaster":case"bad_timeout_duration":case"bad_timeout_global_mod":case"bad_timeout_mod":case"bad_timeout_self":case"bad_timeout_staff":this.log.info(c),this.emits(["notice","_promiseTimeout"],d);break;case"untimeout_success":case"unban_success":this.log.info(c),this.emits(["notice","_promiseUnban"],y);break;case"usage_unban":case"bad_unban_no_ban":this.log.info(c),this.emits(["notice","_promiseUnban"],d);break;case"usage_delete":case"bad_delete_message_error":case"bad_delete_message_broadcaster":case"bad_delete_message_mod":this.log.info(c),this.emits(["notice","_promiseDeletemessage"],d);break;case"usage_unhost":case"not_hosting":this.log.info(c),this.emits(["notice","_promiseUnhost"],d);break;case"whisper_invalid_login":case"whisper_invalid_self":case"whisper_limit_per_min":case"whisper_limit_per_sec":case"whisper_restricted":case"whisper_restricted_recipient":this.log.info(c),this.emits(["notice","_promiseWhisper"],d);break;case"no_permission":case"msg_banned":case"msg_room_not_found":case"msg_channel_suspended":case"tos_ban":case"invalid_user":this.log.info(c),this.emits(["notice","_promiseBan","_promiseClear","_promiseUnban","_promiseTimeout","_promiseDeletemessage","_promiseMods","_promiseMod","_promiseUnmod","_promiseVips","_promiseVip","_promiseUnvip","_promiseCommercial","_promiseHost","_promiseUnhost","_promiseJoin","_promisePart","_promiseR9kbeta","_promiseR9kbetaoff","_promiseSlow","_promiseSlowoff","_promiseFollowers","_promiseFollowersoff","_promiseSubscribers","_promiseSubscribersoff","_promiseEmoteonly","_promiseEmoteonlyoff","_promiseWhisper"],[a,[i,s]]);break;case"msg_rejected":case"msg_rejected_mandatory":this.log.info(c),this.emit("automod",s,i,t);break;case"unrecognized_cmd":this.log.info(c),this.emit("notice",s,i,t);break;case"cmds_available":case"host_target_went_offline":case"msg_censored_broadcaster":case"msg_duplicate":case"msg_emoteonly":case"msg_verified_email":case"msg_ratelimit":case"msg_subsonly":case"msg_timedout":case"msg_bad_characters":case"msg_channel_blocked":case"msg_facebook":case"msg_followersonly":case"msg_followersonly_followed":case"msg_followersonly_zero":case"msg_slowmode":case"msg_suspended":case"no_help":case"usage_disconnect":case"usage_help":case"usage_me":case"unavailable_command":this.log.info(c),this.emit("notice",s,i,t);break;case"host_on":case"host_off":break;default:t.includes("Login unsuccessful")||t.includes("Login authentication failed")?(this.wasCloseCalled=!1,this.reconnect=!1,this.reason=t,this.log.error(this.reason),this.ws.close()):t.includes("Error logging in")||t.includes("Improperly formatted auth")?(this.wasCloseCalled=!1,this.reconnect=!1,this.reason=t,this.log.error(this.reason),this.ws.close()):t.includes("Invalid NICK")?(this.wasCloseCalled=!1,this.reconnect=!1,this.reason="Invalid NICK.",this.log.error(this.reason),this.ws.close()):(this.log.warn(`Could not parse NOTICE from tmi.twitch.tv:
${JSON.stringify(e,null,4)}`),this.emit("notice",s,i,t));break}break}case"USERNOTICE":{let r=o["display-name"]||o.login,a=(C=o["msg-param-sub-plan"])!=null?C:"",p=m.unescapeIRC((x=o["msg-param-sub-plan-name"])!=null?x:"")||null,_={prime:a.includes("Prime"),plan:a,planName:p},y=~~(o["msg-param-streak-months"]||0),d=o["msg-param-recipient-display-name"]||o["msg-param-recipient-user-name"],c=~~o["msg-param-mass-gift-count"];switch(o["message-type"]=i,i){case"resub":this.emits(["resub","subanniversary"],[[s,r,y,t,o,_]]);break;case"sub":this.emits(["subscription","sub"],[[s,r,_,t,o]]);break;case"subgift":this.emit("subgift",s,r,y,d,_,o);break;case"anonsubgift":this.emit("anonsubgift",s,y,d,_,o);break;case"submysterygift":this.emit("submysterygift",s,r,c,_,o);break;case"anonsubmysterygift":this.emit("anonsubmysterygift",s,c,_,o);break;case"primepaidupgrade":this.emit("primepaidupgrade",s,r,_,o);break;case"giftpaidupgrade":{let $=o["msg-param-sender-name"]||o["msg-param-sender-login"];this.emit("giftpaidupgrade",s,r,$,o);break}case"anongiftpaidupgrade":this.emit("anongiftpaidupgrade",s,r,o);break;case"announcement":{let $=o["msg-param-color"];this.emit("announcement",s,o,t,!1,$);break}case"raid":{let $=o["msg-param-displayName"]||o["msg-param-login"],I=+o["msg-param-viewerCount"];this.emit("raided",s,$,I,o);break}default:this.emit("usernotice",i,s,o,t);break}break}case"HOSTTARGET":{let r=t.split(" "),a=~~r[1]||0;r[0]==="-"?(this.log.info(`[${s}] Exited host mode.`),this.emits(["unhost","_promiseUnhost"],[[s,a],[null]])):(this.log.info(`[${s}] Now hosting ${r[0]} for ${a} viewer(s).`),this.emit("hosting",s,r[0],a));break}case"CLEARCHAT":if(e.params.length>1){let r=(S=e.tags["ban-duration"])!=null?S:null;r===null?(this.log.info(`[${s}] ${t} has been banned.`),this.emit("ban",s,t,null,e.tags)):(this.log.info(`[${s}] ${t} has been timed out for ${r} seconds.`),this.emit("timeout",s,t,null,~~r,e.tags))}else this.log.info(`[${s}] Chat was cleared by a moderator.`),this.emits(["clearchat","_promiseClear"],[[s],[null]]);break;case"CLEARMSG":if(e.params.length>1){let r=t,a=o.login;o["message-type"]="messagedeleted",this.log.info(`[${s}] ${a}'s message has been deleted.`),this.emit("messagedeleted",s,a,r,o)}break;case"RECONNECT":this.log.info("Received RECONNECT request from Twitch.."),this.log.info(`Disconnecting and reconnecting in ${Math.round(this.reconnectTimer/1e3)} seconds..`),this.disconnect().catch(r=>this.log.error(r)),setTimeout(()=>this.connect().catch(r=>this.log.error(r)),this.reconnectTimer);break;case"USERSTATE":e.tags.username=this.username,e.tags["user-type"]==="mod"&&(this.moderators[s]||(this.moderators[s]=[]),this.moderators[s].includes(this.username)||this.moderators[s].push(this.username)),!m.isJustinfan(this.getUsername())&&!this.userstate[s]&&(this.userstate[s]=o,this.lastJoined=s,this.channels.push(s),this.log.info(`Joined ${s}`),this.emit("join",s,m.username(this.getUsername()),!0)),e.tags["emote-sets"]!==this.emotes&&(this.emotes=e.tags["emote-sets"],this.emit("emotesets",this.emotes,null)),this.userstate[s]=o;break;case"GLOBALUSERSTATE":this.globaluserstate=o,this.emit("globaluserstate",o),e.tags["emote-sets"]!==void 0&&e.tags["emote-sets"]!==this.emotes&&(this.emotes=e.tags["emote-sets"],this.emit("emotesets",this.emotes,null));break;case"ROOMSTATE":if(m.channel(this.lastJoined)===s&&this.emit("_promiseJoin",null,s),e.tags.channel=s,this.emit("roomstate",s,e.tags),!m.hasOwn(e.tags,"subs-only")){if(m.hasOwn(e.tags,"slow"))if(typeof e.tags.slow=="boolean"&&!e.tags.slow){let r=[s,!1,0];this.log.info(`[${s}] This room is no longer in slow mode.`),this.emits(["slow","slowmode","_promiseSlowoff"],[r,r,[null]])}else{let r=~~e.tags.slow,a=[s,!0,r];this.log.info(`[${s}] This room is now in slow mode.`),this.emits(["slow","slowmode","_promiseSlow"],[a,a,[null]])}if(m.hasOwn(e.tags,"followers-only"))if(e.tags["followers-only"]==="-1"){let r=[s,!1,0];this.log.info(`[${s}] This room is no longer in followers-only mode.`),this.emits(["followersonly","followersmode","_promiseFollowersoff"],[r,r,[null]])}else{let r=~~e.tags["followers-only"],a=[s,!0,r];this.log.info(`[${s}] This room is now in follower-only mode.`),this.emits(["followersonly","followersmode","_promiseFollowers"],[a,a,[null]])}}break;case"SERVERCHANGE":break;default:this.log.warn(`Could not parse message from tmi.twitch.tv:
${JSON.stringify(e,null,4)}`);break}else if(e.prefix==="jtv")switch(e.command){case"MODE":t==="+o"?(this.moderators[s]||(this.moderators[s]=[]),this.moderators[s].includes(e.params[2])||this.moderators[s].push(e.params[2]),this.emit("mod",s,e.params[2])):t==="-o"&&(this.moderators[s]||(this.moderators[s]=[]),this.moderators[s].filter(r=>r!==e.params[2]),this.emit("unmod",s,e.params[2]));break;default:this.log.warn(`Could not parse message from jtv:
${JSON.stringify(e,null,4)}`);break}else switch(e.command){case"353":this.emit("names",e.params[2],e.params[3].split(" "));break;case"366":break;case"JOIN":{let[r]=e.prefix.split("!"),a=this.username===r;a&&m.isJustinfan(this.getUsername())?(this.lastJoined=s,this.channels.push(s),this.log.info(`Joined ${s}`),this.emit("join",s,r,!0)):a||this.emit("join",s,r,!1);break}case"PART":{let[r]=e.prefix.split("!"),a=this.username===r;if(a){this.userstate[s]&&delete this.userstate[s];let p=this.channels.indexOf(s);p!==-1&&this.channels.splice(p,1),p=this.opts.channels.indexOf(s),p!==-1&&this.opts.channels.splice(p,1),this.log.info(`Left ${s}`),this.emit("_promisePart",null)}this.emit("part",s,r,a);break}case"WHISPER":{let[r]=e.prefix.split("!");this.log.info(`[WHISPER] <${r}>: ${t}`),m.hasOwn(e.tags,"username")||(e.tags.username=r),e.tags["message-type"]="whisper";let a=m.channel(e.tags.username);this.emits(["whisper","message"],[[a,e.tags,t,!1]]);break}case"PRIVMSG":if([e.tags.username]=e.prefix.split("!"),e.tags.username==="jtv"){let r=m.username(t.split(" ")[0]),a=t.includes("auto");if(t.includes("hosting you for")){let p=0,f=t.split(" ");for(let _=0;_<f.length;_++)if(m.isInteger(f[_])){p=~~f[_];break}this.emit("hosted",s,r,p,a)}else t.includes("hosting you")&&this.emit("hosted",s,r,0,a)}else{let r=(O=this.opts.options.messagesLogLevel)!=null?O:"info",a=m.actionMessage(t);e.tags["message-type"]=a?"action":"chat";let p=a?a[1]:t;if(m.hasOwn(e.tags,"bits"))this.emit("cheer",s,e.tags,p);else{if(m.hasOwn(e.tags,"msg-id")){if(e.tags["msg-id"]==="highlighted-message"){let f=e.tags["msg-id"];this.emit("redeem",s,e.tags.username,f,e.tags,p)}else if(e.tags["msg-id"]==="skip-subs-mode-message"){let f=e.tags["msg-id"];this.emit("redeem",s,e.tags.username,f,e.tags,p)}}else if(m.hasOwn(e.tags,"custom-reward-id")){let f=e.tags["custom-reward-id"];this.emit("redeem",s,e.tags.username,f,e.tags,p)}a?(this.log[r](`[${s}] *<${e.tags.username}>: ${p}`),this.emits(["action","message"],[[s,e.tags,p,!1]])):(this.log[r](`[${s}] <${e.tags.username}>: ${p}`),this.emits(["chat","message"],[[s,e.tags,p,!1]]))}}break;default:this.log.warn(`Could not parse message:
${JSON.stringify(e,null,4)}`);break}}connect(){return new Promise((e,s)=>{var t,i;this.server=(t=this.opts.connection.server)!=null?t:"irc-ws.chat.twitch.tv",this.port=(i=this.opts.connection.port)!=null?i:80,this.secure&&(this.port=443),this.port===443&&(this.secure=!0),this.reconnectTimer=this.reconnectTimer*this.reconnectDecay,this.reconnectTimer>=this.maxReconnectInterval&&(this.reconnectTimer=this.maxReconnectInterval),this._openConnection(),this.once("_promiseConnect",o=>{o?s(o):e([this.server,~~this.port])})})}_openConnection(){let e=`${this.secure?"wss":"ws"}://${this.server}:${this.port}/`,s={};"agent"in this.opts.connection&&(s.agent=this.opts.connection.agent),this.ws=new ue(e,"irc",s),this.ws.onmessage=this._onMessage.bind(this),this.ws.onerror=this._onError.bind(this),this.ws.onclose=this._onClose.bind(this),this.ws.onopen=this._onOpen.bind(this)}_onOpen(){var e;!this._isConnected()||(this.log.info(`Connecting to ${this.server} on port ${this.port}..`),this.emit("connecting",this.server,~~this.port),this.username=m.username((e=this.opts.identity.username)!=null?e:m.justinfan()),this._getToken().then(s=>{let t=m.password(s);this.log.info("Sending authentication to server.."),this.emit("logon");let i="twitch.tv/tags twitch.tv/commands";this._skipMembership||(i+=" twitch.tv/membership"),this.ws.send(`CAP REQ :${i}`),t?this.ws.send(`PASS ${t}`):m.isJustinfan(this.username)&&this.ws.send("PASS SCHMOOPIIE"),this.ws.send(`NICK ${this.username}`)}).catch(s=>{this.emits(["_promiseConnect","disconnected"],[[s],["Could not get a token."]])}))}_getToken(){let e=this.opts.identity.password,s=typeof e=="function"?e():e;return Promise.resolve(s)}_onMessage(e){e.data.trim().split(`\r
`).forEach(t=>{let i=R.msg(t);i&&this.handleMessage(i)})}_onError(){this.moderators={},this.userstate={},this.globaluserstate={},clearInterval(this.pingLoop),clearTimeout(this.pingTimeout),this.reason=this.ws===null?"Connection closed.":"Unable to connect.",this.emits(["_promiseConnect","disconnected"],[[this.reason]]),this.reconnect&&this.reconnections===this.maxReconnectAttempts&&(this.emit("maxreconnect"),this.log.error("Maximum reconnection attempts reached.")),this.reconnect&&!this.reconnecting&&this.reconnections<=this.maxReconnectAttempts-1&&(this.reconnecting=!0,this.reconnections++,this.log.error(`Reconnecting in ${Math.round(this.reconnectTimer/1e3)} seconds..`),this.emit("reconnect"),setTimeout(()=>{this.reconnecting=!1,this.connect().catch(e=>this.log.error(e))},this.reconnectTimer)),this.ws=null}_onClose(){this.moderators={},this.userstate={},this.globaluserstate={},clearInterval(this.pingLoop),clearTimeout(this.pingTimeout),this.wasCloseCalled?(this.wasCloseCalled=!1,this.reason="Connection closed.",this.log.info(this.reason),this.emits(["_promiseConnect","_promiseDisconnect","disconnected"],[[this.reason],[null],[this.reason]])):(this.emits(["_promiseConnect","disconnected"],[[this.reason]]),!this.wasCloseCalled&&this.reconnect&&this.reconnections===this.maxReconnectAttempts&&(this.emit("maxreconnect"),this.log.error("Maximum reconnection attempts reached.")),!this.wasCloseCalled&&this.reconnect&&!this.reconnecting&&this.reconnections<=this.maxReconnectAttempts-1&&(this.reconnecting=!0,this.reconnections++,this.log.error(`Could not connect to server. Reconnecting in ${Math.round(this.reconnectTimer/1e3)} seconds..`),this.emit("reconnect"),setTimeout(()=>{this.reconnecting=!1,this.connect().catch(e=>this.log.error(e))},this.reconnectTimer))),this.ws=null}_getPromiseDelay(){return Math.max(600,this.currentLatency*1e3+100)}_sendCommand({delay:e,channel:s,command:t,tags:i},o){return new Promise((h,u)=>{if(this._isConnected())(e===null||typeof e=="number")&&(e===null&&(e=this._getPromiseDelay()),m.promiseDelay(e).then(()=>u("No response from Twitch.")));else return u("Not connected to server.");let b=R.formTags(i);if(typeof s=="string"){let w=m.channel(s);this.log.info(`[${w}] Executing command: ${t}`),this.ws.send(`${b?`${b} `:""}PRIVMSG ${w} :${t}`)}else this.log.info(`Executing command: ${t}`),this.ws.send(`${b?`${b} `:""}${t}`);typeof o=="function"?o(h,u):h()})}_sendMessage({channel:e,message:s,tags:t},i){return new Promise((o,h)=>{var S;if(this._isConnected()){if(m.isJustinfan(this.getUsername()))return h("Cannot send anonymous messages.")}else return h("Not connected to server.");let u=m.channel(e);if(this.userstate[u]||(this.userstate[u]={}),s.length>500){let r=s,a=r.slice(0,500).lastIndexOf(" ");a===-1&&(a=500),s=r.slice(0,a),setTimeout(()=>this._sendMessage({channel:e,message:r.slice(a),tags:t}),350)}let b=R.formTags(t);this.ws.send(`${b?`${b} `:""}PRIVMSG ${u} :${s}`);let w=Object.assign({},this.userstate[u],{emotes:null}),C=(S=this.opts.options.messagesLogLevel)!=null?S:"info",x=m.actionMessage(s);x?(w["message-type"]="action",this.log[C](`[${u}] *<${this.getUsername()}>: ${x[1]}`),this.emits(["action","message"],[[u,w,x[1],!0]])):(w["message-type"]="chat",this.log[C](`[${u}] <${this.getUsername()}>: ${s}`),this.emits(["chat","message"],[[u,w,s,!0]])),typeof i=="function"?i(o,h):o()})}getUsername(){return this.username}getOptions(){return this.opts}getChannels(){return this.channels}isMod(e,s){let t=m.channel(e);return this.moderators[t]||(this.moderators[t]=[]),this.moderators[t].includes(m.username(s))}readyState(){return this.ws===null?"CLOSED":["CONNECTING","OPEN","CLOSING","CLOSED"][this.ws.readyState]}_isConnected(){return this.ws!==null&&this.ws.readyState===1}disconnect(){return new Promise((e,s)=>{this.ws!==null&&this.ws.readyState!==3?(this.wasCloseCalled=!0,this.log.info("Disconnecting from server.."),this.ws.close(),this.once("_promiseDisconnect",()=>e([this.server,~~this.port]))):(this.log.error("Cannot disconnect from server. Socket is not opened or connection is already closing."),s("Cannot disconnect from server. Socket is not opened or connection is already closing."))})}};k(P,"ClientBase");Z.exports=P});var se=T((Se,ee)=>{var _e=K(),l=M(),g=class extends _e{action(e,s,t){return s=`ACTION ${s}`,this._sendMessage({delay:this._getPromiseDelay(),channel:e,message:s,tags:t},(i,o)=>i([l.channel(e),s]))}announce(e,s){return this._sendMessage({channel:e,message:`/announce ${s}`},(t,i)=>t([l.channel(e),s]))}ban(e,s,t){return s=l.username(s),t=t!=null?t:"",this._sendCommand({channel:e,command:`/ban ${s} ${t}`},(i,o)=>this.once("_promiseBan",h=>h?o(h):i([l.channel(e),s,t])))}clear(e){return this._sendCommand({channel:e,command:"/clear"},(s,t)=>this.once("_promiseClear",i=>i?t(i):s([l.channel(e)])))}color(e,s){return e=s!=null?s:e,this._sendCommand({channel:this._globalDefaultChannel,command:`/color ${e}`},(t,i)=>this.once("_promiseColor",o=>o?i(o):t([e])))}commercial(e,s){return s=s!=null?s:30,this._sendCommand({channel:e,command:`/commercial ${s}`},(t,i)=>this.once("_promiseCommercial",o=>o?i(o):t([l.channel(e),~~s])))}deletemessage(e,s){return this._sendCommand({channel:e,command:`/delete ${s}`},(t,i)=>this.once("_promiseDeletemessage",o=>o?i(o):t([l.channel(e)])))}emoteonly(e){return this._sendCommand({channel:e,command:"/emoteonly"},(s,t)=>this.once("_promiseEmoteonly",i=>i?t(i):s([l.channel(e)])))}emoteonlyoff(e){return this._sendCommand({channel:e,command:"/emoteonlyoff"},(s,t)=>this.once("_promiseEmoteonlyoff",i=>i?t(i):s([l.channel(e)])))}followersonly(e,s){return s=s!=null?s:30,this._sendCommand({channel:e,command:`/followers ${s}`},(t,i)=>this.once("_promiseFollowers",o=>o?i(o):t([l.channel(e),~~s])))}followersonlyoff(e){return this._sendCommand({channel:e,command:"/followersoff"},(s,t)=>this.once("_promiseFollowersoff",i=>i?t(i):s([l.channel(e)])))}host(e,s){return s=l.username(s),this._sendCommand({delay:2e3,channel:e,command:`/host ${s}`},(t,i)=>this.once("_promiseHost",(o,h)=>o?i(o):t([l.channel(e),s,~~h])))}join(e){return e=l.channel(e),this._sendCommand({delay:void 0,channel:null,command:`JOIN ${e}`},(s,t)=>{let i="_promiseJoin",o=!1,h=k((b,w)=>{e===l.channel(w)&&(this.removeListener(i,h),o=!0,b?t(b):s([e]))},"listener");this.on(i,h);let u=this._getPromiseDelay();l.promiseDelay(u).then(()=>{o||this.emit(i,"No response from Twitch.",e)})})}mod(e,s){return s=l.username(s),this._sendCommand({channel:e,command:`/mod ${s}`},(t,i)=>this.once("_promiseMod",o=>o?i(o):t([l.channel(e),s])))}mods(e){return e=l.channel(e),this._sendCommand({channel:e,command:"/mods"},(s,t)=>{this.once("_promiseMods",(i,o)=>{i?t(i):(o.forEach(h=>{this.moderators[e]||(this.moderators[e]=[]),this.moderators[e].includes(h)||this.moderators[e].push(h)}),s(o))})})}part(e){return this._sendCommand({delay:null,channel:null,command:`PART ${e}`},(s,t)=>this.once("_promisePart",i=>i?t(i):s([l.channel(e)])))}ping(){return this._sendCommand({delay:null,command:"PING"},(e,s)=>{var t;this.latency=new Date,this.pingTimeout=setTimeout(()=>{this.ws!==null&&(this.wasCloseCalled=!1,this.log.error("Ping timeout."),this.ws.close(),clearInterval(this.pingLoop),clearTimeout(this.pingTimeout))},(t=this.opts.connection.timeout)!=null?t:9999),this.once("_promisePing",i=>e([parseFloat(i)]))})}r9kbeta(e){return this._sendCommand({channel:e,command:"/r9kbeta"},(s,t)=>this.once("_promiseR9kbeta",i=>i?t(i):s([l.channel(e)])))}r9kbetaoff(e){return this._sendCommand({channel:e,command:"/r9kbetaoff"},(s,t)=>this.once("_promiseR9kbetaoff",i=>i?t(i):s([l.channel(e)])))}raw(e,s){return this._sendCommand({channel:null,command:e,tags:s},(t,i)=>t([e]))}reply(e,s,t,i={}){if(typeof t=="object"&&(t=t.id),!t||typeof t!="string")throw new Error("replyParentMsgId is required.");return this.say(e,s,{...i,"reply-parent-msg-id":t})}say(e,s,t){return e=l.channel(e),s.startsWith(".")&&!s.startsWith("..")||s.startsWith("/")||s.startsWith("\\")?s.slice(1,4)==="me "?this.action(e,s.slice(4)):this._sendCommand({channel:e,message:s,tags:t},(i,o)=>i([e,s])):this._sendMessage({delay:this._getPromiseDelay(),channel:e,message:s,tags:t},(i,o)=>i([e,s]))}slow(e,s){return s=s!=null?s:300,this._sendCommand({channel:e,command:`/slow ${s}`},(t,i)=>this.once("_promiseSlow",o=>o?i(o):t([l.channel(e),~~s])))}slowoff(e){return this._sendCommand({channel:e,command:"/slowoff"},(s,t)=>this.once("_promiseSlowoff",i=>i?t(i):s([l.channel(e)])))}subscribers(e){return this._sendCommand({channel:e,command:"/subscribers"},(s,t)=>this.once("_promiseSubscribers",i=>i?t(i):s([l.channel(e)])))}subscribersoff(e){return this._sendCommand({channel:e,command:"/subscribersoff"},(s,t)=>this.once("_promiseSubscribersoff",i=>i?t(i):s([l.channel(e)])))}timeout(e,s,t,i){return s=l.username(s),(t!=null?t:!1)&&!l.isInteger(t)&&(i=t,t=300),t=t!=null?t:300,i=i!=null?i:"",this._sendCommand({channel:e,command:`/timeout ${s} ${t} ${i}`},(o,h)=>this.once("_promiseTimeout",u=>u?h(u):o([l.channel(e),s,~~t,i])))}unban(e,s){return s=l.username(s),this._sendCommand({channel:e,command:`/unban ${s}`},(t,i)=>this.once("_promiseUnban",o=>o?i(o):t([l.channel(e),s])))}unhost(e){return this._sendCommand({delay:2e3,channel:e,command:"/unhost"},(s,t)=>this.once("_promiseUnhost",i=>i?t(i):s([l.channel(e)])))}unmod(e,s){return s=l.username(s),this._sendCommand({channel:e,command:`/unmod ${s}`},(t,i)=>this.once("_promiseUnmod",o=>o?i(o):t([l.channel(e),s])))}unvip(e,s){return s=l.username(s),this._sendCommand({channel:e,command:`/unvip ${s}`},(t,i)=>this.once("_promiseUnvip",o=>o?i(o):t([l.channel(e),s])))}vip(e,s){return s=l.username(s),this._sendCommand({channel:e,command:`/vip ${s}`},(t,i)=>this.once("_promiseVip",o=>o?i(o):t([l.channel(e),s])))}vips(e){return this._sendCommand({channel:e,command:"/vips"},(s,t)=>this.once("_promiseVips",(i,o)=>i?t(i):s(o)))}whisper(e,s){return e=l.username(e),e===this.getUsername()?Promise.reject("Cannot send a whisper to the same account."):this._sendCommand({delay:null,channel:this._globalDefaultChannel,command:`/w ${e} ${s}`},(t,i)=>this.once("_promiseWhisper",o=>o&&i(o))).catch(t=>{if(t&&typeof t=="string"&&t.indexOf("No response from Twitch.")!==0)throw t;let i=l.channel(e),o=Object.assign({"message-type":"whisper","message-id":null,"thread-id":null,username:this.getUsername()},this.globaluserstate);return this.emits(["whisper","message"],[[i,o,s,!0]]),[e,s]})}};k(g,"Client");g.prototype.followersmode=g.prototype.followersonly;g.prototype.followersmodeoff=g.prototype.followersonlyoff;g.prototype.leave=g.prototype.part;g.prototype.slowmode=g.prototype.slow;g.prototype.r9kmode=g.prototype.r9kbeta;g.prototype.uniquechat=g.prototype.r9kbeta;g.prototype.r9kmodeoff=g.prototype.r9kbetaoff;g.prototype.uniquechatoff=g.prototype.r9kbeta;g.prototype.slowmodeoff=g.prototype.slowoff;ee.exports=g});var ge=T((Ie,ie)=>{var te=se();ie.exports={client:te,Client:te}});return ge();})();
//# sourceMappingURL=tmi.min.js.map

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

const client = require('./lib/client');
const Client = require('./lib/Client');
module.exports = {
client,
Client: client
client: Client,
Client
};

@@ -50,3 +50,3 @@ /*

const parts = spl[i].split(splB);
let val = parts[1];
let [ , val ] = parts;
if(splC !== undefined && val) {

@@ -115,9 +115,5 @@ val = val.split(splC);

formTags(tags) {
const result = [];
for(const key in tags) {
const value = _.escapeIRC(tags[key]);
result.push(`${key}=${value}`);
}
return `@${result.join(';')}`;
formTags(tags = {}) {
const result = Object.entries(tags).map(([ k, v ]) => `${_.escapeIRC(k)}=${_.escapeIRC(v)}`);
return !result.length ? null : `@${result.join(';')}`;
},

@@ -124,0 +120,0 @@

@@ -6,2 +6,3 @@ // eslint-disable-next-line no-control-regex

const escapeIRCRegex = /([ \n;\r\\])/g;
const tokenRegex = /^oauth:/i;
const ircEscapedChars = { s: ' ', n: '', ':': ';', r: '' };

@@ -45,3 +46,3 @@ const ircUnescapedChars = { ' ': 's', '\n': 'n', ';': ':', '\r': 'r' };

// Return a valid token
token: str => str ? str.toLowerCase().replace('oauth:', '') : '',
token: str => str ? str.replace(tokenRegex, '') : '',

@@ -48,0 +49,0 @@ // Return a valid password

{
"name": "tmi.js",
"version": "1.9.0-pre.0",
"description": "Javascript library for the Twitch Messaging Interface.",
"version": "1.9.0-pre.1",
"description": "JavaScript library for the Twitch Messaging Interface.",
"keywords": [

@@ -16,2 +16,3 @@ "tmi",

"main": "index.js",
"types": "types.d.ts",
"files": [

@@ -21,3 +22,3 @@ "lib",

"index.js",
"LICENSE"
"types.d.ts"
],

@@ -38,9 +39,4 @@ "engines": {

"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/tmijs/tmi.js.git"
},
"bugs": {
"url": "https://github.com/tmijs/tmi.js/issues"
},
"repository": "tmijs/tmi.js",
"bugs": "https://github.com/tmijs/tmi.js/issues",
"dependencies": {

@@ -58,17 +54,10 @@ "ws": "8.8.0"

"browser": {
"ws": false,
"node-fetch": false
"ws": false
},
"browserify": {
"transform": [
[
"babelify",
{
"presets": [
"@babel/preset-env"
]
}
]
]
}
"funding": [
{
"type": "github",
"url": "https://github.com/tmijs/tmi.js?sponsor=1"
}
]
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc