diff --git a/README.md b/README.md index 41cea26..84b4e2a 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,11 @@ [![Release](https://img.shields.io/github/v/release/mattermost/mattermost-plugin-profanity-filter)](https://github.com/mattermost/mattermost-plugin-profanity-filter/releases/latest) [![HW](https://img.shields.io/github/issues/mattermost/mattermost-plugin-profanity-filter/Up%20For%20Grabs?color=dark%20green&label=Help%20Wanted)](https://github.com/mattermost/mattermost-plugin-profanity-filter/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22Up+For+Grabs%22+label%3A%22Help+Wanted%22) - -This plugin allows you to censor profanity on your Mattermost server. The plugin checks all messages for matches against the configured "Bad Words List" before they are posted to any channel. The characters in any word matches are replaced with a series of "*"s. +This plugin allows you to censor profanity on your Mattermost server. The plugin checks all messages for matches against the configured "Bad words list" before they are posted to any channel. The characters in any word matches are replaced with a series of "\*"s. **Supported Mattermost Server Versions: 5.2+** -## Plugin Marketplace +## Plugin Marketplace 1. Go to **Main Menu > Plugin Marketplace** in Mattermost. 2. Search for "Profanity Filter" or manually find the plugin from the list and click **Install** @@ -24,5 +23,11 @@ This plugin allows you to censor profanity on your Mattermost server. The plugin ### Usage -You can edit the bad words list in **System Console > Plugins > Profanity Filter > Bad Words list**. -In this list, you can use Regular Expressions to match bad words. For example, `bad[[:space:]]?word` will match both `badword` and `bad word`. \ No newline at end of file +You can edit the bad words list in **System Console > Plugins > Profanity Filter > Bad words list**. +In this list, you can use Regular Expressions to match bad words. For example, `bad[[:space:]]?word` will match both `badword` and `bad word`. + +Choose to either censor the bad words with a character or reject the post with a custom warning message: + +![Post rejected by the plugin](./images/post-rejected.gif) + +![Post censored by the plugin](./images/post-censored.gif) diff --git a/images/post-censored.gif b/images/post-censored.gif new file mode 100644 index 0000000..533617f Binary files /dev/null and b/images/post-censored.gif differ diff --git a/images/post-rejected.gif b/images/post-rejected.gif new file mode 100644 index 0000000..7a0c400 Binary files /dev/null and b/images/post-rejected.gif differ diff --git a/plugin.json b/plugin.json index 4ac821d..75a7e49 100644 --- a/plugin.json +++ b/plugin.json @@ -18,6 +18,14 @@ "type": "bool", "help_text": "If set the plugin will reject posts containing profanity instead of censoring." }, + { + "key": "WarningMessage", + "display_name": "Warning Message", + "type": "text", + "help_text": "If Reject Posts is enabled, this message will be sent to the user to warn him. Place `%s` where you want to cite the forbidden word in the message. Markdown formatted.", + "placeholder": "Ex. Your post has been rejected by the Profanity Filter, because the following word is not allowed: `%s`.", + "default": "Your post has been rejected by the Profanity Filter, because the following word is not allowed: `%s`." + }, { "key": "CensorCharacter", "display_name": "Censor Character", diff --git a/server/configuration.go b/server/configuration.go index 66fc2e2..0a5bc96 100644 --- a/server/configuration.go +++ b/server/configuration.go @@ -25,6 +25,7 @@ type configuration struct { RejectPosts bool CensorCharacter string BadWordsList string + WarningMessage string `json:"WarningMessage"` } // Clone shallow copies the configuration. Your implementation may require a deep copy if diff --git a/server/plugin.go b/server/plugin.go index 7fb794c..ad3a500 100644 --- a/server/plugin.go +++ b/server/plugin.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "regexp" "strings" "sync" @@ -38,7 +39,13 @@ func (p *Plugin) FilterPost(post *model.Post) (*model.Post, string) { detectedBadWords := p.badWordsRegex.FindAllString(postMessageWithoutAccents, -1) if configuration.RejectPosts { - return nil, "Profane word not allowed: `" + strings.Join(detectedBadWords, ", ") + "`" + p.API.SendEphemeralPost(post.UserId, &model.Post{ + ChannelId: post.ChannelId, + Message: fmt.Sprintf(configuration.WarningMessage, strings.Join(detectedBadWords, ", ")), + RootId: post.RootId, + }) + + return nil, fmt.Sprintf("Profane word not allowed: %s", strings.Join(detectedBadWords, ", ")) } for _, word := range detectedBadWords {