Unverified Commit d9536256 authored by fk's avatar fk
Browse files

unpushed code

parent 0347170b
......@@ -14,11 +14,19 @@
"settings": [
{
"key": "AllowedUsers",
"display_name": "Allowed users, separated by spaces",
"display_name": "Allowed Users: Users that are allowed to post normal messages in all channels. Separated by spaces",
"type": "text",
"help_text": "A list of allowed users",
"placeholder": "francis.",
"default": "francis."
"help_text": "A list of allowed Users",
"placeholder": "",
"default": ""
},
{
"key": "AllowedChannels",
"display_name": "Allowed Channels: all members are able to post normal messages here. Separated by spaces",
"type": "text",
"help_text": "A list of allowed Channels",
"placeholder": "shitposting",
"default": ""
}
],
"header": "",
......
......@@ -17,6 +17,7 @@ var SystemEmojis = map[string]string{"policewoman": "1f46e-200d-2640-fe0f", "fam
type configuration struct {
AllowedUsers string
AllowedChannels string
}
// Clone shallow copies the configuration. Your implementation may require a deep copy if
......@@ -123,8 +124,9 @@ func (p *Plugin) FilterPost(post *model.Post) (*model.Post, string) {
return nil, "Failed to find user in post"
}
// Parse allowedUsers
// Parse allowedUsers and channels
allowedUsers := strings.Split(configuration.AllowedUsers, " ")
allowedChannels := strings.Split(configuration.AllowedChannels, " ")
// Filter allowed users
for _, allowedUser := range allowedUsers {
......@@ -133,6 +135,13 @@ func (p *Plugin) FilterPost(post *model.Post) (*model.Post, string) {
}
}
// Filter allowed channels
for _, allowedChannel := range allowedChannels {
if allowedChannel == channel.Name {
return nil, ""
}
}
match, error := regexp.MatchString("^( *:[^:]+: *)+$", post.Message)
if error != nil {
p.API.LogError("Error while matching regex")
......@@ -143,7 +152,6 @@ func (p *Plugin) FilterPost(post *model.Post) (*model.Post, string) {
return nil, "Does not match required format"
}
splitMessage := strings.Split(post.Message, ":")
for _, name := range splitMessage {
......
No preview for this file type
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment