From 3edc54048dbdd4a7f03e66178946a70b4fbbd7fc Mon Sep 17 00:00:00 2001 From: Jacob Foster Date: Sat, 15 Jun 2024 07:07:29 -0500 Subject: [PATCH] client: remove updateEmoteset timers and options --- lib/client.js | 60 ++------------------------------------------------- 1 file changed, 2 insertions(+), 58 deletions(-) diff --git a/lib/client.js b/lib/client.js index 937c027..9afeaef 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1,6 +1,5 @@ const _global = typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : {}; const _WebSocket = _global.WebSocket || require('ws'); -const _fetch = _global.fetch || require('node-fetch'); const commands = require('./commands'); const EventEmitter = require('./events').EventEmitter; const logger = require('./logger'); @@ -20,9 +19,6 @@ const client = function client(opts) { this.clientId = _.get(this.opts.options.clientId, null); this._globalDefaultChannel = _.channel(_.get(this.opts.options.globalDefaultChannel, '#tmijs')); this._skipMembership = _.get(this.opts.options.skipMembership, false); - this._skipUpdatingEmotesets = _.get(this.opts.options.skipUpdatingEmotesets, false); - this._updateEmotesetsTimer = null; - this._updateEmotesetsTimerDelay = _.get(this.opts.options.updateEmotesetsTimer, 60000); this.maxReconnectAttempts = _.get(this.opts.connection.maxReconnectAttempts, Infinity); this.maxReconnectInterval = _.get(this.opts.connection.maxReconnectInterval, 30000); @@ -184,7 +180,6 @@ client.prototype.handleMessage = function handleMessage(message) { clearInterval(this.pingLoop); clearTimeout(this.pingTimeout); - clearTimeout(this._updateEmotesetsTimer); } }, _.get(this.opts.connection.timeout, 9999)); }, 60000); @@ -811,7 +806,7 @@ client.prototype.handleMessage = function handleMessage(message) { // Emote-sets has changed, update it.. if(message.tags['emote-sets'] !== this.emotes) { - this._updateEmoteset(message.tags['emote-sets']); + this.emit('emotesets', message.tags['emote-sets'], {}); } this.userstate[channel] = tags; @@ -824,7 +819,7 @@ client.prototype.handleMessage = function handleMessage(message) { // Received emote-sets.. if(typeof message.tags['emote-sets'] !== 'undefined') { - this._updateEmoteset(message.tags['emote-sets']); + this.emit('emotesets', message.tags['emote-sets'], {}); } break; @@ -1155,7 +1150,6 @@ client.prototype._onError = function _onError() { // Stop the internal ping timeout check interval.. clearInterval(this.pingLoop); clearTimeout(this.pingTimeout); - clearTimeout(this._updateEmotesetsTimer); this.reason = this.ws === null ? 'Connection closed.' : 'Unable to connect.'; @@ -1188,7 +1182,6 @@ client.prototype._onClose = function _onClose() { // Stop the internal ping timeout check interval.. clearInterval(this.pingLoop); clearTimeout(this.pingTimeout); - clearTimeout(this._updateEmotesetsTimer); // User called .disconnect(), don't try to reconnect. if(this.wasCloseCalled) { @@ -1331,55 +1324,6 @@ client.prototype._sendMessage = function _sendMessage(delay, channel, message, f } }); }; -// Grab the emote-sets object from the API.. -client.prototype._updateEmoteset = function _updateEmoteset(sets) { - let setsChanges = sets !== undefined; - if(setsChanges) { - if(sets === this.emotes) { - setsChanges = false; - } - else { - this.emotes = sets; - } - } - if(this._skipUpdatingEmotesets) { - if(setsChanges) { - this.emit('emotesets', sets, {}); - } - return; - } - const setEmotesetTimer = () => { - if(this._updateEmotesetsTimerDelay > 0) { - clearTimeout(this._updateEmotesetsTimer); - this._updateEmotesetsTimer = setTimeout(() => this._updateEmoteset(sets), this._updateEmotesetsTimerDelay); - } - }; - this._getToken() - .then(token => { - const url = `https://api.twitch.tv/kraken/chat/emoticon_images?emotesets=${sets}`; - /** @type {import('node-fetch').RequestInit} */ - const fetchOptions = {}; - if('fetchAgent' in this.opts.connection) { - fetchOptions.agent = this.opts.connection.fetchAgent; - } - /** @type {import('node-fetch').Response} */ - return _fetch(url, { - ...fetchOptions, - headers: { - 'Accept': 'application/vnd.twitchtv.v5+json', - 'Authorization': `OAuth ${_.token(token)}`, - 'Client-ID': this.clientId - } - }); - }) - .then(res => res.json()) - .then(data => { - this.emotesets = data.emoticon_sets || {}; - this.emit('emotesets', sets, this.emotesets); - setEmotesetTimer(); - }) - .catch(() => setEmotesetTimer()); -}; // Get current username.. client.prototype.getUsername = function getUsername() { return this.username;