diff --git a/packages/rocketchat-lib/i18n/en.i18n.json b/packages/rocketchat-lib/i18n/en.i18n.json index b8680af6882ec..4fa2226074cc5 100644 --- a/packages/rocketchat-lib/i18n/en.i18n.json +++ b/packages/rocketchat-lib/i18n/en.i18n.json @@ -549,6 +549,9 @@ "Message_AllowDeleting_BlockDeleteInMinutes" : "Block Message Deleting After (n) Minutes", "Message_AllowDeleting_BlockDeleteInMinutesDescription" : "Enter 0 to disable blocking.", "Message_AllowEditing" : "Allow Message Editing", + "Message_AllowBadWordsFilter" : "Allow Message bad words filtering", + "Message_BadWordsFilterList" : "Add bad words to the blacklist", + "Message_BadWordsFilterListDescription" : "Add List of Comma-separated list of bad words to filter", "Message_AllowEditing_BlockEditInMinutes" : "Block Message Editing After (n) Minutes", "Message_AllowEditing_BlockEditInMinutesDescription" : "Enter 0 to disable blocking.", "Message_AllowPinning" : "Allow Message Pinning", diff --git a/packages/rocketchat-lib/package.js b/packages/rocketchat-lib/package.js index 9e5ae6a3bd285..6baba59606f70 100644 --- a/packages/rocketchat-lib/package.js +++ b/packages/rocketchat-lib/package.js @@ -5,6 +5,10 @@ Package.describe({ git: '' }); +Npm.depends({ + 'bad-words': '1.3.1' +}); + Package.onUse(function(api) { api.versionsFrom('1.0'); @@ -97,6 +101,7 @@ Package.onUse(function(api) { api.addFiles('server/methods/insertOrUpdateUser.coffee', 'server'); api.addFiles('server/methods/setEmail.js', 'server'); api.addFiles('server/methods/restartServer.coffee', 'server'); + api.addFiles('server/methods/filterBadWords.js', ['server']); // SERVER STARTUP api.addFiles('server/startup/settingsOnLoadCdnPrefix.coffee', 'server'); @@ -147,6 +152,8 @@ Package.onUse(function(api) { api.imply('tap:i18n'); }); + + Package.onTest(function(api) { api.use('coffeescript'); api.use('sanjo:jasmine@0.20.2'); diff --git a/packages/rocketchat-lib/server/methods/filterBadWords.js b/packages/rocketchat-lib/server/methods/filterBadWords.js new file mode 100644 index 0000000000000..04b626c38faa7 --- /dev/null +++ b/packages/rocketchat-lib/server/methods/filterBadWords.js @@ -0,0 +1,25 @@ + +var Filter = Npm.require('bad-words'); + + RocketChat.callbacks.add( 'beforeSaveMessage' , function(message){ + // console.log(message) + + if( RocketChat.settings.get('Message_AllowBadWordsFilter') ) + { + + var badWordsList = RocketChat.settings.get('Message_BadWordsFilterList'); + // console.log(badWordsList) + //Add words to the blacklist + if(!!badWordsList && badWordsList.length) + { + // console.log(badWordsList) + var filter = new Filter({ list: badWordsList.split(',') }); + } + else + var filter = new Filter(); + message.msg = filter.clean(message.msg); + + } + return message; + + },1);