!function s(o,i,r){function a(t,e){if(!i[t]){if(!o[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(c)return c(t,!0);throw(n=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",n}n=i[t]={exports:{}},o[t][0].call(n.exports,function(e){return a(o[t][1][e]||e)},n,n.exports,s,o,i,r)}return i[t].exports}for(var c="function"==typeof require&&require,e=0;e: ").concat(m)),t.tags.hasOwnProperty("username")||(t.tags.username=M),t.tags["message-type"]="whisper";var J=H.channel(t.tags.username);this.emits(["whisper","message"],[[J,t.tags,m,!1]]);break;case"PRIVMSG":t.tags.username=t.prefix.split("!")[0],"jtv"===t.tags.username?(a=H.username(m.split(" ")[0]),c=m.includes("auto"),m.includes("hosting you for")?(J=H.extractNumber(m),this.emit("hosted",l,a,J,c)):m.includes("hosting you")&&this.emit("hosted",l,a,0,c)):(a=H.get(this.opts.options.messagesLogLevel,"info"),c=H.actionMessage(m),t.tags["message-type"]=c?"action":"chat",m=c?c[1]:m,t.tags.hasOwnProperty("bits")?this.emit("cheer",l,t.tags,m):(t.tags.hasOwnProperty("msg-id")?"highlighted-message"!==t.tags["msg-id"]&&"skip-subs-mode-message"!==t.tags["msg-id"]||(u=t.tags["msg-id"],this.emit("redeem",l,t.tags.username,u,t.tags,m)):t.tags.hasOwnProperty("custom-reward-id")&&(u=t.tags["custom-reward-id"],this.emit("redeem",l,t.tags.username,u,t.tags,m)),c?(this.log[a]("[".concat(l,"] *<").concat(t.tags.username,">: ").concat(m)),this.emits(["action","message"],[[l,t.tags,m,!1]])):(this.log[a]("[".concat(l,"] <").concat(t.tags.username,">: ").concat(m)),this.emits(["chat","message"],[[l,t.tags,m,!1]]))));break;default:this.log.warn("Could not parse message:\n".concat(JSON.stringify(t,null,4)))}}},n.prototype.connect=function(){var s=this;return new Promise(function(t,n){s.server=H.get(s.opts.connection.server,"irc-ws.chat.twitch.tv"),s.port=H.get(s.opts.connection.port,80),s.secure&&(s.port=443),443===s.port&&(s.secure=!0),s.reconnectTimer=s.reconnectTimer*s.reconnectDecay,s.reconnectTimer>=s.maxReconnectInterval&&(s.reconnectTimer=s.maxReconnectInterval),s._openConnection(),s.once("_promiseConnect",function(e){e?n(e):t([s.server,~~s.port])})})},n.prototype._openConnection=function(){this.ws=new r("".concat(this.secure?"wss":"ws","://").concat(this.server,":").concat(this.port,"/"),"irc"),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)},n.prototype._onOpen=function(){var t=this;H.isNull(this.ws)||1!==this.ws.readyState||(this.log.info("Connecting to ".concat(this.server," on port ").concat(this.port,"..")),this.emit("connecting",this.server,~~this.port),this.username=H.get(this.opts.identity.username,H.justinfan()),this._getToken().then(function(e){e=H.password(e);t.log.info("Sending authentication to server.."),t.emit("logon"),t.ws.send("CAP REQ :twitch.tv/tags twitch.tv/commands twitch.tv/membership"),e?t.ws.send("PASS ".concat(e)):H.isJustinfan(t.username)&&t.ws.send("PASS SCHMOOPIIE"),t.ws.send("NICK ".concat(t.username))}).catch(function(e){t.emits(["_promiseConnect","disconnected"],[[e],["Could not get a token."]])}))},n.prototype._getToken=function(){var e,t=this.opts.identity.password;return"function"==typeof t?(e=t())instanceof Promise?e:Promise.resolve(e):Promise.resolve(t)},n.prototype._onMessage=function(e){var t=this;e.data.split("\r\n").forEach(function(e){H.isNull(e)||t.handleMessage(q.msg(e))})},n.prototype._onError=function(){var t=this;this.moderators={},this.userstate={},this.globaluserstate={},clearInterval(this.pingLoop),clearTimeout(this.pingTimeout),this.reason=H.isNull(this.ws)?"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 ".concat(Math.round(this.reconnectTimer/1e3)," seconds..")),this.emit("reconnect"),setTimeout(function(){t.reconnecting=!1,t.connect().catch(function(e){return t.log.error(e)})},this.reconnectTimer)),this.ws=null},n.prototype._onClose=function(){var t=this;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.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("Could not connect to server. Reconnecting in ".concat(Math.round(this.reconnectTimer/1e3)," seconds..")),this.emit("reconnect"),setTimeout(function(){t.reconnecting=!1,t.connect().catch(function(e){return t.log.error(e)})},this.reconnectTimer))),this.ws=null},n.prototype._getPromiseDelay=function(){return this.currentLatency<=600?600:this.currentLatency+100},n.prototype._sendCommand=function(s,o,i,r){var a=this;return new Promise(function(e,t){if(H.isNull(a.ws)||1!==a.ws.readyState)return t("Not connected to server.");var n;"number"==typeof s&&H.promiseDelay(s).then(function(){return t("No response from Twitch.")}),H.isNull(o)?(a.log.info("Executing command: ".concat(i)),a.ws.send(i)):(n=H.channel(o),a.log.info("[".concat(n,"] Executing command: ").concat(i)),a.ws.send("PRIVMSG ".concat(n," :").concat(i))),"function"==typeof r?r(e,t):e()})},n.prototype._sendMessage=function(c,u,l,m){var h=this;return new Promise(function(e,t){if(H.isNull(h.ws)||1!==h.ws.readyState)return t("Not connected to server.");if(H.isJustinfan(h.getUsername()))return t("Cannot send anonymous messages.");var n,s=H.channel(u);h.userstate[s]||(h.userstate[s]={}),500<=l.length&&(n=H.splitLine(l,500),l=n[0],setTimeout(function(){h._sendMessage(c,u,n[1],function(){})},350)),h.ws.send("PRIVMSG ".concat(s," :").concat(l));var o={};Object.keys(h.emotesets).forEach(function(e){return h.emotesets[e].forEach(function(e){return(H.isRegex(e.code)?q.emoteRegex:q.emoteString)(l,e.code,e.id,o)})});var i=H.merge(h.userstate[s],q.emotes({emotes:q.transformEmotes(o)||null})),r=H.get(h.opts.options.messagesLogLevel,"info"),a=H.actionMessage(l);a?(i["message-type"]="action",h.log[r]("[".concat(s,"] *<").concat(h.getUsername(),">: ").concat(a[1])),h.emits(["action","message"],[[s,i,a[1],!0]])):(i["message-type"]="chat",h.log[r]("[".concat(s,"] <").concat(h.getUsername(),">: ").concat(l)),h.emits(["chat","message"],[[s,i,l,!0]])),"function"==typeof m?m(e,t):e()})},n.prototype._updateEmoteset=function(s){var o=this;this.emotes=s,this._getToken().then(function(e){return o.api({url:"/chat/emoticon_images?emotesets=".concat(s),headers:{Authorization:"OAuth ".concat(H.token(e)),"Client-ID":o.clientId}},function(e,t,n){return e?void setTimeout(function(){return o._updateEmoteset(s)},6e4):(o.emotesets=n.emoticon_sets||{},o.emit("emotesets",s,o.emotesets))})}).catch(function(){return setTimeout(function(){return o._updateEmoteset(s)},6e4)})},n.prototype.getUsername=function(){return this.username},n.prototype.getOptions=function(){return this.opts},n.prototype.getChannels=function(){return this.channels},n.prototype.isMod=function(e,t){e=H.channel(e);return this.moderators[e]||(this.moderators[e]=[]),this.moderators[e].includes(H.username(t))},n.prototype.readyState=function(){return H.isNull(this.ws)?"CLOSED":["CONNECTING","OPEN","CLOSING","CLOSED"][this.ws.readyState]},n.prototype._isConnected=function(){return null!==this.ws&&1===this.ws.readyState},n.prototype.disconnect=function(){var n=this;return new Promise(function(e,t){H.isNull(n.ws)||3===n.ws.readyState?(n.log.error("Cannot disconnect from server. Socket is not opened or connection is already closing."),t("Cannot disconnect from server. Socket is not opened or connection is already closing.")):(n.wasCloseCalled=!0,n.log.info("Disconnecting from server.."),n.ws.close(),n.once("_promiseDisconnect",function(){return e([n.server,~~n.port])}))})},void 0!==u&&u.exports&&(u.exports=n),"undefined"!=typeof window&&(window.tmi={},window.tmi.client=n,window.tmi.Client=n)}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./api":2,"./commands":4,"./events":5,"./logger":6,"./parser":7,"./timer":8,"./utils":9,ws:10}],4:[function(e,t,n){"use strict";var u=e("./utils");function s(s,o){var e=this;return s=u.channel(s),o=u.get(o,30),this._sendCommand(this._getPromiseDelay(),s,"/followers ".concat(o),function(t,n){e.once("_promiseFollowers",function(e){e?n(e):t([s,~~o])})})}function o(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/followersoff",function(t,n){e.once("_promiseFollowersoff",function(e){e?n(e):t([s])})})}function i(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),null,"PART ".concat(s),function(t,n){e.once("_promisePart",function(e){e?n(e):t([s])})})}function r(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/r9kbeta",function(t,n){e.once("_promiseR9kbeta",function(e){e?n(e):t([s])})})}function a(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/r9kbetaoff",function(t,n){e.once("_promiseR9kbetaoff",function(e){e?n(e):t([s])})})}function c(s,o){var e=this;return s=u.channel(s),o=u.get(o,300),this._sendCommand(this._getPromiseDelay(),s,"/slow ".concat(o),function(t,n){e.once("_promiseSlow",function(e){e?n(e):t([s,~~o])})})}function l(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/slowoff",function(t,n){e.once("_promiseSlowoff",function(e){e?n(e):t([s])})})}t.exports={action:function(n,s){return n=u.channel(n),s="ACTION ".concat(s,""),this._sendMessage(this._getPromiseDelay(),n,s,function(e,t){e([n,s])})},ban:function(s,o,i){var e=this;return s=u.channel(s),o=u.username(o),i=u.get(i,""),this._sendCommand(this._getPromiseDelay(),s,"/ban ".concat(o," ").concat(i),function(t,n){e.once("_promiseBan",function(e){e?n(e):t([s,o,i])})})},clear:function(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/clear",function(t,n){e.once("_promiseClear",function(e){e?n(e):t([s])})})},color:function(e,s){var o=this;return s=u.get(s,e),this._sendCommand(this._getPromiseDelay(),"#tmijs","/color ".concat(s),function(t,n){o.once("_promiseColor",function(e){e?n(e):t([s])})})},commercial:function(s,o){var e=this;return s=u.channel(s),o=u.get(o,30),this._sendCommand(this._getPromiseDelay(),s,"/commercial ".concat(o),function(t,n){e.once("_promiseCommercial",function(e){e?n(e):t([s,~~o])})})},deletemessage:function(s,e){var o=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/delete ".concat(e),function(t,n){o.once("_promiseDeletemessage",function(e){e?n(e):t([s])})})},emoteonly:function(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/emoteonly",function(t,n){e.once("_promiseEmoteonly",function(e){e?n(e):t([s])})})},emoteonlyoff:function(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/emoteonlyoff",function(t,n){e.once("_promiseEmoteonlyoff",function(e){e?n(e):t([s])})})},followersonly:s,followersmode:s,followersonlyoff:o,followersmodeoff:o,host:function(o,i){var e=this;return o=u.channel(o),i=u.username(i),this._sendCommand(2e3,o,"/host ".concat(i),function(n,s){e.once("_promiseHost",function(e,t){e?s(e):n([o,i,~~t])})})},join:function(a){var c=this;return a=u.channel(a),this._sendCommand(null,null,"JOIN ".concat(a),function(s,o){var i="_promiseJoin",r=!1,e=function e(t,n){a===u.channel(n)&&(c.removeListener(i,e),r=!0,t?o(t):s([a]))};c.on(i,e);e=c._getPromiseDelay();u.promiseDelay(e).then(function(){r||c.emit(i,"No response from Twitch.",a)})})},mod:function(s,o){var e=this;return s=u.channel(s),o=u.username(o),this._sendCommand(this._getPromiseDelay(),s,"/mod ".concat(o),function(t,n){e.once("_promiseMod",function(e){e?n(e):t([s,o])})})},mods:function(o){var i=this;return o=u.channel(o),this._sendCommand(this._getPromiseDelay(),o,"/mods",function(n,s){i.once("_promiseMods",function(e,t){e?s(e):(t.forEach(function(e){i.moderators[o]||(i.moderators[o]=[]),i.moderators[o].includes(e)||i.moderators[o].push(e)}),n(t))})})},part:i,leave:i,ping:function(){var n=this;return this._sendCommand(this._getPromiseDelay(),null,"PING",function(t,e){n.latency=new Date,n.pingTimeout=setTimeout(function(){null!==n.ws&&(n.wasCloseCalled=!1,n.log.error("Ping timeout."),n.ws.close(),clearInterval(n.pingLoop),clearTimeout(n.pingTimeout))},u.get(n.opts.connection.timeout,9999)),n.once("_promisePing",function(e){return t([parseFloat(e)])})})},r9kbeta:r,r9kmode:r,r9kbetaoff:a,r9kmodeoff:a,raw:function(n){return this._sendCommand(this._getPromiseDelay(),null,n,function(e,t){e([n])})},say:function(n,s){return n=u.channel(n),s.startsWith(".")&&!s.startsWith("..")||s.startsWith("/")||s.startsWith("\\")?"me "===s.substr(1,3)?this.action(n,s.substr(4)):this._sendCommand(this._getPromiseDelay(),n,s,function(e,t){e([n,s])}):this._sendMessage(this._getPromiseDelay(),n,s,function(e,t){e([n,s])})},slow:c,slowmode:c,slowoff:l,slowmodeoff:l,subscribers:function(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/subscribers",function(t,n){e.once("_promiseSubscribers",function(e){e?n(e):t([s])})})},subscribersoff:function(s){var e=this;return s=u.channel(s),this._sendCommand(this._getPromiseDelay(),s,"/subscribersoff",function(t,n){e.once("_promiseSubscribersoff",function(e){e?n(e):t([s])})})},timeout:function(s,o,i,r){var e=this;return s=u.channel(s),o=u.username(o),u.isNull(i)||u.isInteger(i)||(r=i,i=300),i=u.get(i,300),r=u.get(r,""),this._sendCommand(this._getPromiseDelay(),s,"/timeout ".concat(o," ").concat(i," ").concat(r),function(t,n){e.once("_promiseTimeout",function(e){e?n(e):t([s,o,~~i,r])})})},unban:function(s,o){var e=this;return s=u.channel(s),o=u.username(o),this._sendCommand(this._getPromiseDelay(),s,"/unban ".concat(o),function(t,n){e.once("_promiseUnban",function(e){e?n(e):t([s,o])})})},unhost:function(s){var e=this;return s=u.channel(s),this._sendCommand(2e3,s,"/unhost",function(t,n){e.once("_promiseUnhost",function(e){e?n(e):t([s])})})},unmod:function(s,o){var e=this;return s=u.channel(s),o=u.username(o),this._sendCommand(this._getPromiseDelay(),s,"/unmod ".concat(o),function(t,n){e.once("_promiseUnmod",function(e){e?n(e):t([s,o])})})},unvip:function(s,o){var e=this;return s=u.channel(s),o=u.username(o),this._sendCommand(this._getPromiseDelay(),s,"/unvip ".concat(o),function(t,n){e.once("_promiseUnvip",function(e){e?n(e):t([s,o])})})},vip:function(s,o){var e=this;return s=u.channel(s),o=u.username(o),this._sendCommand(this._getPromiseDelay(),s,"/vip ".concat(o),function(t,n){e.once("_promiseVip",function(e){e?n(e):t([s,o])})})},vips:function(e){var t=this;return e=u.channel(e),this._sendCommand(this._getPromiseDelay(),e,"/vips",function(n,s){t.once("_promiseVips",function(e,t){e?s(e):n(t)})})},whisper:function(n,s){var o=this;return(n=u.username(n))===this.getUsername()?Promise.reject("Cannot send a whisper to the same account."):this._sendCommand(this._getPromiseDelay(),"#tmijs","/w ".concat(n," ").concat(s),function(e,t){o.once("_promiseWhisper",function(e){e&&t(e)})}).catch(function(e){if(e&&"string"==typeof e&&0!==e.indexOf("No response from Twitch."))throw e;var t=u.channel(n),e=u.merge({"message-type":"whisper","message-id":null,"thread-id":null,username:o.getUsername()},o.globaluserstate);return o.emits(["whisper","message"],[[t,e,s,!0],[t,e,s,!0]]),[n,s]})}}},{"./utils":9}],5:[function(e,t,n){"use strict";function s(e){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function c(e){return"function"==typeof e}function u(e){return"object"===s(e)&&null!==e}function a(e){return void 0===e}((t.exports=o).EventEmitter=o).prototype._events=void 0,o.prototype._maxListeners=void 0,o.defaultMaxListeners=10,o.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},o.prototype.emit=function(e){var t,n,s,o,i,r;if(this._events||(this._events={}),"error"===e&&(!this._events.error||u(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(a(n=this._events[e]))return!1;if(c(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:o=Array.prototype.slice.call(arguments,1),n.apply(this,o)}else if(u(n))for(o=Array.prototype.slice.call(arguments,1),s=(r=n.slice()).length,i=0;in&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},o.prototype.once=function(e,t){if(!c(t))throw TypeError("listener must be a function");var n=!1;if(this._events.hasOwnProperty(e)&&"_"===e.charAt(0)){var s,o=1,i=e;for(s in this._events)this._events.hasOwnProperty(s)&&s.startsWith(i)&&o++;e+=o}function r(){"_"!==e.charAt(0)||isNaN(e.substr(e.length-1))||(e=e.substring(0,e.length-1)),this.removeListener(e,r),n||(n=!0,t.apply(this,arguments))}return r.listener=t,this.on(e,r),this},o.prototype.removeListener=function(e,t){var n,s,o,i;if(!c(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(o=(n=this._events[e]).length,s=-1,n===t||c(n.listener)&&n.listener===t){if(delete this._events[e],this._events.hasOwnProperty(e+"2")&&"_"===e.charAt(0)){var r,a=e;for(r in this._events)this._events.hasOwnProperty(r)&&r.startsWith(a)&&(isNaN(parseInt(r.substr(r.length-1)))||(this._events[e+parseInt(r.substr(r.length-1)-1)]=this._events[r],delete this._events[r]));this._events[e]=this._events[e+"1"],delete this._events[e+"1"]}this._events.removeListener&&this.emit("removeListener",e,t)}else if(u(n)){for(i=o;0n?(t.command=e.slice(n),t):null;for(t.command=e.slice(n,s),n=s+1;32===e.charCodeAt(n);)n++;for(;ne.length)&&(t=e.length);for(var n=0,s=new Array(t);n").replace(/\\"\\;/g,'"').replace(/\\'\\;/g,"'")},unescapeIRC:function(e){return e&&e.includes("\\")?e.replace(a,function(e,t){return t in u?u[t]:t}):e},escapeIRC:function(e){return e&&e.replace(c,function(e,t){return t in l?"\\".concat(l[t]):t})},actionMessage:function(e){return e.match(i)},addWord:function(e,t){return e.length?e+" "+t:e+t},channel:function(e){var t=(e||"").toLowerCase();return"#"===t[0]?t:"#"+t},extractNumber:function(e){for(var t=e.split(" "),n=0;n