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

Bad word filter Feature (Ready to Use) :D #2940

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/rocketchat-lib/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions packages/rocketchat-lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Package.describe({
git: ''
});

Npm.depends({
'bad-words': '1.3.1'
});

Package.onUse(function(api) {
api.versionsFrom('1.0');

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -147,6 +152,8 @@ Package.onUse(function(api) {
api.imply('tap:i18n');
});



Package.onTest(function(api) {
api.use('coffeescript');
api.use('sanjo:[email protected]');
Expand Down
25 changes: 25 additions & 0 deletions packages/rocketchat-lib/server/methods/filterBadWords.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

var Filter = Npm.require('bad-words');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RocketChat.callbacks.add( 'beforeSaveMessage' , function(message){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// console.log(message)

if( RocketChat.settings.get('Message_AllowBadWordsFilter') )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{

var badWordsList = RocketChat.settings.get('Message_BadWordsFilterList');
// console.log(badWordsList)
//Add words to the blacklist
if(!!badWordsList && badWordsList.length)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// console.log(badWordsList)
var filter = new Filter({ list: badWordsList.split(',') });
}
else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var filter = new Filter();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message.msg = filter.clean(message.msg);

}
return message;

},1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.