From 9b707f50664057c4372407d750cab8fbb2a51fef Mon Sep 17 00:00:00 2001 From: Mitch Date: Fri, 19 Apr 2024 05:43:03 +1200 Subject: [PATCH] Add /reloadusers command (#449) --- assets/chat/js/chat.js | 46 ++++++++++++++++++++------------------ assets/chat/js/commands.js | 5 +++++ 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index effbf508..b2c51b37 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -135,6 +135,7 @@ class Chat { this.source.on('SOCKETERROR', (data) => this.onSOCKETERROR(data)); this.source.on('SUBONLY', (data) => this.onSUBONLY(data)); this.source.on('BROADCAST', (data) => this.onBROADCAST(data)); + this.source.on('RELOAD', () => this.onRELOAD()); this.source.on('PRIVMSGSENT', (data) => this.onPRIVMSGSENT(data)); this.source.on('PRIVMSG', (data) => this.onPRIVMSG(data)); this.source.on('POLLSTART', (data) => this.onPOLLSTART(data)); @@ -171,6 +172,7 @@ class Chat { ); this.control.on('TIMESTAMPFORMAT', (data) => this.cmdTIMESTAMPFORMAT(data)); this.control.on('BROADCAST', (data) => this.cmdBROADCAST(data)); + this.control.on('RELOADUSERS', () => this.cmdRELOADUSERS()); this.control.on('CONNECT', (data) => this.cmdCONNECT(data)); this.control.on('TAG', (data) => this.cmdTAG(data)); this.control.on('UNTAG', (data) => this.cmdUNTAG(data)); @@ -1295,28 +1297,24 @@ class Chat { } onBROADCAST(data) { - // TODO kind of ... hackey - if (data.data === 'reload') { - if (!this.backlogloading) { - const retryMilli = Math.floor(Math.random() * 30000) + 4000; - setTimeout(() => window.location.reload(true), retryMilli); - - MessageBuilder.broadcast( - `Restart incoming in ${Math.round(retryMilli / 1000)} seconds...`, - new ChatUser({ - nick: 'System', - id: -1, - }), - data.timestamp, - ).into(this); - } - } else { - MessageBuilder.broadcast( - data.data, - new ChatUser(data.user), - data.timestamp, - ).into(this); - } + MessageBuilder.broadcast( + data.data, + new ChatUser(data.user), + data.timestamp, + ).into(this); + } + + onRELOAD() { + const retryMilli = Math.floor(Math.random() * 30000) + 4000; + setTimeout(() => window.location.reload(true), retryMilli); + + MessageBuilder.broadcast( + `Reload incoming in ${Math.round(retryMilli / 1000)} seconds...`, + new ChatUser({ + nick: 'System', + id: -1, + }), + ).into(this); } onSUBSCRIPTION(data) { @@ -1836,6 +1834,10 @@ class Chat { this.source.send('BROADCAST', { data: parts.join(' ') }); } + cmdRELOADUSERS() { + this.source.send('RELOADUSERS', {}); + } + cmdWHISPER(parts) { if (!parts[0] || !nickregex.test(parts[0])) { MessageBuilder.error('Invalid nick - /msg nick message').into(this); diff --git a/assets/chat/js/commands.js b/assets/chat/js/commands.js index b4521397..4533cf5b 100644 --- a/assets/chat/js/commands.js +++ b/assets/chat/js/commands.js @@ -119,6 +119,11 @@ const CHAT_COMMANDS = [ description: 'Post a video embed in chat.', alias: ['pe'], }, + { + name: 'reloadusers', + description: 'Reload all users in chat.', + admin: true, + }, { name: 'removephrase', description: 'Remove a banned phrase from chat.',