diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index 790fc5fb..53960cb5 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -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)); @@ -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()); @@ -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); } @@ -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); @@ -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 ').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 ').into( + this, + ); + return; + } + + this.source.send('REMOVEPHRASE', { data: parts.join(' ') }); + } + cmdDIE() { this.source.send('DIE', { data: '' }); } diff --git a/assets/chat/js/commands.js b/assets/chat/js/commands.js index f03deace..5a3a716f 100644 --- a/assets/chat/js/commands.js +++ b/assets/chat/js/commands.js @@ -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 from connecting to the chat.', @@ -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.', diff --git a/assets/chat/js/const.js b/assets/chat/js/const.js index 2e7ef903..38d6d47e 100644 --- a/assets/chat/js/const.js +++ b/assets/chat/js/const.js @@ -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.", }), );