Skip to content

Commit

Permalink
Add /reloadusers command (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitchdev authored Apr 18, 2024
1 parent 60e0445 commit 9b707f5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
46 changes: 24 additions & 22 deletions assets/chat/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions assets/chat/js/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down

0 comments on commit 9b707f5

Please sign in to comment.