Skip to content

Commit

Permalink
Add warning message when post is rejected (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanaelhoun committed Oct 8, 2020
1 parent 88f3e76 commit f33bfde
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand All @@ -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`.
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)
Binary file added images/post-censored.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/post-rejected.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions server/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion server/plugin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"regexp"
"strings"
"sync"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f33bfde

Please sign in to comment.