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 2 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
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