-
Notifications
You must be signed in to change notification settings - Fork 13
/
plugin.go
68 lines (53 loc) · 1.62 KB
/
plugin.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
60
61
62
63
64
65
66
67
68
package main
import (
"sync"
"github.com/pkg/errors"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/plugin"
)
// Plugin implements the interface expected by the Mattermost server to communicate between the server and plugin processes.
type Plugin struct {
plugin.MattermostPlugin
BotUserID string
// configurationLock synchronizes access to the configuration.
configurationLock sync.RWMutex
// configuration is the active plugin configuration. Consult getConfiguration and
// setConfiguration for usage.
configuration *configuration
}
// BuildHash is the full git hash of the build.
var BuildHash string
// BuildHashShort is the short git hash of the build.
var BuildHashShort string
// BuildDate is the build date of the build.
var BuildDate string
// OnActivate runs when the plugin activates and ensures the plugin is properly
// configured.
func (p *Plugin) OnActivate() error {
config := p.getConfiguration()
err := config.IsValid()
if err != nil {
return errors.Wrap(err, "invalid config")
}
bot := &model.Bot{
Username: "wrangler",
DisplayName: "Wrangler",
Description: "Created by the Wrangler plugin.",
}
options := []plugin.EnsureBotOption{
plugin.ProfileImagePath("assets/profile.png"),
}
botID, err := p.Helpers.EnsureBot(bot, options...)
if err != nil {
return errors.Wrap(err, "failed to ensure Wrangler bot")
}
p.BotUserID = botID
err = p.API.RegisterCommand(getCommand(
config.CommandAutoCompleteEnable,
config.MergeThreadEnable,
))
if err != nil {
return errors.Wrap(err, "failed to register wrangler command")
}
return nil
}