Migrate to use plugin v2 system coming in Mattermost 5.2

master
JoramWilander 2018-07-10 09:08:33 -04:00
parent 25f7aa81f2
commit 8b80a3ffe2
2 changed files with 9 additions and 8 deletions

View File

@ -10,10 +10,9 @@ import (
"strings"
"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/plugin"
"github.com/mattermost/mattermost-server/plugin/rpcplugin"
"github.com/mattermost/mattermost-plugin-memes/meme"
"github.com/mattermost/mattermost-plugin-memes/memelibrary"
@ -101,20 +100,22 @@ func serveTemplateJPEG(w http.ResponseWriter, r *http.Request) {
}
type Plugin struct {
plugin.MattermostPlugin
router *mux.Router
}
func (p *Plugin) OnActivate(api plugin.API) error {
func (p *Plugin) OnActivate() error {
p.router = mux.NewRouter()
p.router.HandleFunc("/templates/{name}.jpg", serveTemplateJPEG).Methods("GET")
return api.RegisterCommand(&model.Command{
return p.API.RegisterCommand(&model.Command{
Trigger: "meme",
AutoComplete: true,
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") == "" {
http.Error(w, "please log in", http.StatusForbidden)
return
@ -123,7 +124,7 @@ func (p *Plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
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"))
if input == "" {
@ -182,6 +183,6 @@ func main() {
os.Exit(1)
}
} else {
rpcplugin.Main(&Plugin{})
plugin.ClientMain(&Plugin{})
}
}

View File

@ -3,4 +3,4 @@ backend:
executable: plugin.exe
name: Memes
description: Gives you the ability to quickly create and post memes via a /meme slash command.
version: '0.1'
version: '1.0'