Skip to content

Commit 96560e8

Browse files
authored
DES-167: add banned phrases (#304)
* 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
1 parent 256f406 commit 96560e8

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

assets/chat/js/chat.js

+65
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ class Chat {
145145
this.source.on('MASSGIFT', (data) => this.onMASSGIFT(data));
146146
this.source.on('DONATION', (data) => this.onDONATION(data));
147147
this.source.on('UPDATEUSER', (data) => this.onUPDATEUSER(data));
148+
this.source.on('ADDPHRASE', (data) => this.onADDPHRASE(data));
149+
this.source.on('REMOVEPHRASE', (data) => this.onREMOVEPHRASE(data));
148150
this.source.on('DEATH', (data) => this.onDEATH(data));
149151

150152
this.control.on('SEND', (data) => this.cmdSEND(data));
@@ -209,6 +211,18 @@ class Chat {
209211
this.control.on('UNMOTD', () => this.cmdUNPIN());
210212
this.control.on('HOST', (data) => this.cmdHOST(data));
211213
this.control.on('UNHOST', () => this.cmdUNHOST());
214+
this.control.on('ADDPHRASE', (data) => this.cmdADDPHRASE(data));
215+
this.control.on('ADDBAN', (data) => this.cmdADDPHRASE(data));
216+
this.control.on('ADDMUTE', (data) => this.cmdADDPHRASE(data));
217+
this.control.on('REMOVEPHRASE', (data) => this.cmdREMOVEPHRASE(data));
218+
this.control.on('REMOVEBAN', (data) => this.cmdREMOVEPHRASE(data));
219+
this.control.on('REMOVEMUTE', (data) => this.cmdREMOVEPHRASE(data));
220+
this.control.on('DELETEPHRASE', (data) => this.cmdREMOVEPHRASE(data));
221+
this.control.on('DELETEBAN', (data) => this.cmdREMOVEPHRASE(data));
222+
this.control.on('DELETEMUTE', (data) => this.cmdREMOVEPHRASE(data));
223+
this.control.on('DPHRASE', (data) => this.cmdREMOVEPHRASE(data));
224+
this.control.on('DBAN', (data) => this.cmdREMOVEPHRASE(data));
225+
this.control.on('DMUTE', (data) => this.cmdREMOVEPHRASE(data));
212226
this.control.on('DIE', () => this.cmdDIE());
213227
this.control.on('SUICIDE', () => this.cmdDIE());
214228
this.control.on('BITLY', () => this.cmdDIE());
@@ -1245,6 +1259,12 @@ class Chat {
12451259
`You are temporarily muted! You can chat again ${this.mutedtimer.getReadableDuration()}. Subscribe to remove the mute immediately.`,
12461260
);
12471261
break;
1262+
case 'bannedphrase': {
1263+
message = MessageBuilder.error(
1264+
`Your message was blocked because it contained this banned phrase: "${data.filtered}".`,
1265+
);
1266+
break;
1267+
}
12481268
default:
12491269
message = MessageBuilder.error(errorstrings.get(desc) || desc);
12501270
}
@@ -1315,6 +1335,19 @@ class Chat {
13151335
MessageBuilder.donation(data).into(this);
13161336
}
13171337

1338+
onADDPHRASE(data) {
1339+
MessageBuilder.command(`Phrase "${data.data}" added.`, data.timestamp).into(
1340+
this,
1341+
);
1342+
}
1343+
1344+
onREMOVEPHRASE(data) {
1345+
MessageBuilder.command(
1346+
`Phrase "${data.data}" removed.`,
1347+
data.timestamp,
1348+
).into(this);
1349+
}
1350+
13181351
onPRIVMSGSENT() {
13191352
if (this.mainwindow.visible) {
13201353
MessageBuilder.info('Your message has been sent.').into(this);
@@ -2272,6 +2305,38 @@ class Chat {
22722305
this.source.send('PIN', { data: '' });
22732306
}
22742307

2308+
cmdADDPHRASE(parts) {
2309+
if (!this.user.hasAnyFeatures(UserFeatures.ADMIN, UserFeatures.MODERATOR)) {
2310+
MessageBuilder.error(errorstrings.get('nopermission')).into(this);
2311+
return;
2312+
}
2313+
2314+
if (!parts.length) {
2315+
MessageBuilder.error('No phrase provided - /addphrase <phrase>').into(
2316+
this,
2317+
);
2318+
return;
2319+
}
2320+
2321+
this.source.send('ADDPHRASE', { data: parts.join(' ') });
2322+
}
2323+
2324+
cmdREMOVEPHRASE(parts) {
2325+
if (!this.user.hasAnyFeatures(UserFeatures.ADMIN, UserFeatures.MODERATOR)) {
2326+
MessageBuilder.error(errorstrings.get('nopermission')).into(this);
2327+
return;
2328+
}
2329+
2330+
if (!parts.length) {
2331+
MessageBuilder.error('No phrase provided - /removephrase <phrase>').into(
2332+
this,
2333+
);
2334+
return;
2335+
}
2336+
2337+
this.source.send('REMOVEPHRASE', { data: parts.join(' ') });
2338+
}
2339+
22752340
cmdDIE() {
22762341
this.source.send('DIE', { data: '' });
22772342
}

assets/chat/js/commands.js

+21
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ const ADMIN_HELP_HEADER = 'Available admin commands: \n';
1515

1616
/** @type CommandList */
1717
const CHAT_COMMANDS = [
18+
{
19+
name: 'addphrase',
20+
description: 'Add a banned phrase to chat.',
21+
alias: ['addban', 'addmute'],
22+
admin: true,
23+
},
1824
{
1925
name: 'ban',
2026
description: 'Stop <nick> from connecting to the chat.',
@@ -108,6 +114,21 @@ const CHAT_COMMANDS = [
108114
description: 'Post a video embed in chat.',
109115
alias: ['pe'],
110116
},
117+
{
118+
name: 'removephrase',
119+
description: 'Remove a banned phrase from chat.',
120+
alias: [
121+
'removeban',
122+
'removemute',
123+
'deletephrase',
124+
'deleteban',
125+
'deletemute',
126+
'dmute',
127+
'dban',
128+
'dphrase',
129+
],
130+
admin: true,
131+
},
111132
{
112133
name: 'reply',
113134
description: 'Reply to the last whisper you received.',

assets/chat/js/const.js

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ const errorstrings = new Map(
7979
alreadyvoted: 'You have already voted!',
8080
nochatting:
8181
"You aren't allowed to chat. Either you haven't picked a username, or a mod disabled your privileges.",
82+
duplicatephrase: 'Banned phrase already exists.',
83+
nophrase: "Banned phrase doesn't exist.",
84+
invalidphrase:
85+
'Invalid phrase provided. Either the phrase was empty, or its regex was invalid.',
8286
cantbanprotected: "Protected users can't die.",
8387
}),
8488
);

0 commit comments

Comments
 (0)