Skip to content

Commit

Permalink
DES-167: add banned phrases (#304)
Browse files Browse the repository at this point in the history
* fix: admin messages not showing up in autocomplete

* feat: add banned phrase functionality

* feat: remove /die

* feat: show which banned phrases got filtered

* feat: add invalid phrase error message

* chore: adjust the "msg was filtered" error msg

* Revert "fix: admin messages not showing up in autocomplete"

This reverts commit cd1eb61.

* chore: change 'filtered' to 'blocked' in banned phrase error
  • Loading branch information
vyneer authored Apr 1, 2024
1 parent 256f406 commit 96560e8
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
65 changes: 65 additions & 0 deletions assets/chat/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ class Chat {
this.source.on('MASSGIFT', (data) => this.onMASSGIFT(data));
this.source.on('DONATION', (data) => this.onDONATION(data));
this.source.on('UPDATEUSER', (data) => this.onUPDATEUSER(data));
this.source.on('ADDPHRASE', (data) => this.onADDPHRASE(data));
this.source.on('REMOVEPHRASE', (data) => this.onREMOVEPHRASE(data));
this.source.on('DEATH', (data) => this.onDEATH(data));

this.control.on('SEND', (data) => this.cmdSEND(data));
Expand Down Expand Up @@ -209,6 +211,18 @@ class Chat {
this.control.on('UNMOTD', () => this.cmdUNPIN());
this.control.on('HOST', (data) => this.cmdHOST(data));
this.control.on('UNHOST', () => this.cmdUNHOST());
this.control.on('ADDPHRASE', (data) => this.cmdADDPHRASE(data));
this.control.on('ADDBAN', (data) => this.cmdADDPHRASE(data));
this.control.on('ADDMUTE', (data) => this.cmdADDPHRASE(data));
this.control.on('REMOVEPHRASE', (data) => this.cmdREMOVEPHRASE(data));
this.control.on('REMOVEBAN', (data) => this.cmdREMOVEPHRASE(data));
this.control.on('REMOVEMUTE', (data) => this.cmdREMOVEPHRASE(data));
this.control.on('DELETEPHRASE', (data) => this.cmdREMOVEPHRASE(data));
this.control.on('DELETEBAN', (data) => this.cmdREMOVEPHRASE(data));
this.control.on('DELETEMUTE', (data) => this.cmdREMOVEPHRASE(data));
this.control.on('DPHRASE', (data) => this.cmdREMOVEPHRASE(data));
this.control.on('DBAN', (data) => this.cmdREMOVEPHRASE(data));
this.control.on('DMUTE', (data) => this.cmdREMOVEPHRASE(data));
this.control.on('DIE', () => this.cmdDIE());
this.control.on('SUICIDE', () => this.cmdDIE());
this.control.on('BITLY', () => this.cmdDIE());
Expand Down Expand Up @@ -1245,6 +1259,12 @@ class Chat {
`You are temporarily muted! You can chat again ${this.mutedtimer.getReadableDuration()}. Subscribe to remove the mute immediately.`,
);
break;
case 'bannedphrase': {
message = MessageBuilder.error(
`Your message was blocked because it contained this banned phrase: "${data.filtered}".`,
);
break;
}
default:
message = MessageBuilder.error(errorstrings.get(desc) || desc);
}
Expand Down Expand Up @@ -1315,6 +1335,19 @@ class Chat {
MessageBuilder.donation(data).into(this);
}

onADDPHRASE(data) {
MessageBuilder.command(`Phrase "${data.data}" added.`, data.timestamp).into(
this,
);
}

onREMOVEPHRASE(data) {
MessageBuilder.command(
`Phrase "${data.data}" removed.`,
data.timestamp,
).into(this);
}

onPRIVMSGSENT() {
if (this.mainwindow.visible) {
MessageBuilder.info('Your message has been sent.').into(this);
Expand Down Expand Up @@ -2272,6 +2305,38 @@ class Chat {
this.source.send('PIN', { data: '' });
}

cmdADDPHRASE(parts) {
if (!this.user.hasAnyFeatures(UserFeatures.ADMIN, UserFeatures.MODERATOR)) {
MessageBuilder.error(errorstrings.get('nopermission')).into(this);
return;
}

if (!parts.length) {
MessageBuilder.error('No phrase provided - /addphrase <phrase>').into(
this,
);
return;
}

this.source.send('ADDPHRASE', { data: parts.join(' ') });
}

cmdREMOVEPHRASE(parts) {
if (!this.user.hasAnyFeatures(UserFeatures.ADMIN, UserFeatures.MODERATOR)) {
MessageBuilder.error(errorstrings.get('nopermission')).into(this);
return;
}

if (!parts.length) {
MessageBuilder.error('No phrase provided - /removephrase <phrase>').into(
this,
);
return;
}

this.source.send('REMOVEPHRASE', { data: parts.join(' ') });
}

cmdDIE() {
this.source.send('DIE', { data: '' });
}
Expand Down
21 changes: 21 additions & 0 deletions assets/chat/js/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ const ADMIN_HELP_HEADER = 'Available admin commands: \n';

/** @type CommandList */
const CHAT_COMMANDS = [
{
name: 'addphrase',
description: 'Add a banned phrase to chat.',
alias: ['addban', 'addmute'],
admin: true,
},
{
name: 'ban',
description: 'Stop <nick> from connecting to the chat.',
Expand Down Expand Up @@ -108,6 +114,21 @@ const CHAT_COMMANDS = [
description: 'Post a video embed in chat.',
alias: ['pe'],
},
{
name: 'removephrase',
description: 'Remove a banned phrase from chat.',
alias: [
'removeban',
'removemute',
'deletephrase',
'deleteban',
'deletemute',
'dmute',
'dban',
'dphrase',
],
admin: true,
},
{
name: 'reply',
description: 'Reply to the last whisper you received.',
Expand Down
4 changes: 4 additions & 0 deletions assets/chat/js/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ const errorstrings = new Map(
alreadyvoted: 'You have already voted!',
nochatting:
"You aren't allowed to chat. Either you haven't picked a username, or a mod disabled your privileges.",
duplicatephrase: 'Banned phrase already exists.',
nophrase: "Banned phrase doesn't exist.",
invalidphrase:
'Invalid phrase provided. Either the phrase was empty, or its regex was invalid.',
cantbanprotected: "Protected users can't die.",
}),
);
Expand Down

0 comments on commit 96560e8

Please sign in to comment.