Skip to content

Add warning message when post is rejected #23

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

Merged
merged 8 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
Binary file added .github/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 .github/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.
13 changes: 9 additions & 4 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,4 +23,10 @@ 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**.
You can edit the bad words list in **System Console > Plugins > Profanity Filter > Bad words list**.

Choose to either censor the bad words with a character or reject the post with a custom warning message:

![Post rejected by the plugin](./.github/post-rejected.gif)

![Post censored by the plugin](./.github/post-censored.gif)
10 changes: 9 additions & 1 deletion 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. Use `%s` in the message if you want to cite the forbidden word. 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 All @@ -37,4 +45,4 @@
"header": "",
"footer": ""
}
}
}
1 change: 1 addition & 0 deletions server/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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
6 changes: 6 additions & 0 deletions server/plugin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"strings"
"sync"
"unicode"
Expand Down Expand Up @@ -39,6 +40,11 @@ func (p *Plugin) FilterPost(post *model.Post) (*model.Post, string) {
for i, word := range words {
if p.WordIsBad(word) {
if configuration.RejectPosts {
p.API.SendEphemeralPost(post.UserId, &model.Post{
ChannelId: post.ChannelId,
Message: fmt.Sprintf(configuration.WarningMessage, word),
RootId: post.RootId,
})
return nil, "Profane word not allowed: " + word
}
words[i] = strings.Repeat(configuration.CensorCharacter, len(word))
Expand Down