Migrate to use plugin v2 system coming in Mattermost 5.2
parent
25f7aa81f2
commit
8b80a3ffe2
15
plugin.go
15
plugin.go
|
@ -10,10 +10,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/kballard/go-shellquote"
|
shellquote "github.com/kballard/go-shellquote"
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/plugin"
|
"github.com/mattermost/mattermost-server/plugin"
|
||||||
"github.com/mattermost/mattermost-server/plugin/rpcplugin"
|
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-plugin-memes/meme"
|
"github.com/mattermost/mattermost-plugin-memes/meme"
|
||||||
"github.com/mattermost/mattermost-plugin-memes/memelibrary"
|
"github.com/mattermost/mattermost-plugin-memes/memelibrary"
|
||||||
|
@ -101,20 +100,22 @@ func serveTemplateJPEG(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Plugin struct {
|
type Plugin struct {
|
||||||
|
plugin.MattermostPlugin
|
||||||
|
|
||||||
router *mux.Router
|
router *mux.Router
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Plugin) OnActivate(api plugin.API) error {
|
func (p *Plugin) OnActivate() error {
|
||||||
p.router = mux.NewRouter()
|
p.router = mux.NewRouter()
|
||||||
p.router.HandleFunc("/templates/{name}.jpg", serveTemplateJPEG).Methods("GET")
|
p.router.HandleFunc("/templates/{name}.jpg", serveTemplateJPEG).Methods("GET")
|
||||||
return api.RegisterCommand(&model.Command{
|
return p.API.RegisterCommand(&model.Command{
|
||||||
Trigger: "meme",
|
Trigger: "meme",
|
||||||
AutoComplete: true,
|
AutoComplete: true,
|
||||||
AutoCompleteDesc: "Renders custom memes so you can express yourself with culture.",
|
AutoCompleteDesc: "Renders custom memes so you can express yourself with culture.",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Header.Get("Mattermost-User-Id") == "" {
|
if r.Header.Get("Mattermost-User-Id") == "" {
|
||||||
http.Error(w, "please log in", http.StatusForbidden)
|
http.Error(w, "please log in", http.StatusForbidden)
|
||||||
return
|
return
|
||||||
|
@ -123,7 +124,7 @@ func (p *Plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
p.router.ServeHTTP(w, r)
|
p.router.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Plugin) ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
|
func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
|
||||||
input := strings.TrimSpace(strings.TrimPrefix(args.Command, "/meme"))
|
input := strings.TrimSpace(strings.TrimPrefix(args.Command, "/meme"))
|
||||||
|
|
||||||
if input == "" {
|
if input == "" {
|
||||||
|
@ -182,6 +183,6 @@ func main() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rpcplugin.Main(&Plugin{})
|
plugin.ClientMain(&Plugin{})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,4 @@ backend:
|
||||||
executable: plugin.exe
|
executable: plugin.exe
|
||||||
name: Memes
|
name: Memes
|
||||||
description: Gives you the ability to quickly create and post memes via a /meme slash command.
|
description: Gives you the ability to quickly create and post memes via a /meme slash command.
|
||||||
version: '0.1'
|
version: '1.0'
|
||||||
|
|
Loading…
Reference in New Issue