generated from mattermost/mattermost-plugin-starter-template
-
Notifications
You must be signed in to change notification settings - Fork 10
/
bot.go
59 lines (48 loc) · 1.31 KB
/
bot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) 2019-present Mattermost, Inc. All Rights Reserved.
// See License for license information.
package bot
import (
"github.com/mattermost/mattermost-server/v5/plugin"
)
type Bot interface {
Poster
Logger
Admin
WithConfig(BotConfig) Bot
}
type BotConfig struct {
// AdminUserIDs contains a comma-separated list of user IDs that are allowed
// to administer plugin functions, even if not Mattermost sysadmins.
AdminUserIDs string
// AdminLogLevel is "debug", "info", "warn", or "error".
AdminLogLevel string
// AdminLogVerbose: set to include full context with admin log messages.
AdminLogVerbose bool
}
func (c BotConfig) ToStorable(configMap map[string]interface{}) map[string]interface{} {
if configMap == nil {
configMap = map[string]interface{}{}
}
configMap["AdminUserIDs"] = c.AdminUserIDs
configMap["AdminLogLevel"] = c.AdminLogLevel
configMap["AdminLogVerbose"] = c.AdminLogVerbose
return configMap
}
type bot struct {
BotConfig
pluginAPI plugin.API
mattermostUserID string
logContext LogContext
}
// NewBot creates a new bot poster.
func NewBot(api plugin.API, botUserID string) Bot {
return &bot{
pluginAPI: api,
mattermostUserID: botUserID,
}
}
func (bot *bot) WithConfig(conf BotConfig) Bot {
newbot := *bot
newbot.BotConfig = conf
return &newbot
}