Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /reloadusers command #449

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 10 additions & 0 deletions assets/chat/js/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const CHAT_COMMANDS = [
name: 'baninfo',
description: 'Check your ban status.',
},
{
name: 'broadcast',
description: 'Broadcast a message to chat.',
admin: true,
},
{
name: 'die',
description: 'Mute yourself for 10 minutes.',
Expand Down Expand Up @@ -114,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