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

DES-167: add banned phrases #304

Merged
merged 12 commits into from
Apr 1, 2024
65 changes: 65 additions & 0 deletions assets/chat/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,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 @@ -208,6 +210,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 @@ -1229,6 +1243,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 @@ -1299,6 +1319,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 @@ -2256,6 +2289,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