2019-11-29 06:59:40 -05:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See LICENSE.txt for license information.
|
2017-07-24 14:55:37 -04:00
|
|
|
|
|
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
|
2019-04-23 09:33:42 -04:00
|
|
|
goi18n "github.com/mattermost/go-i18n/i18n"
|
2019-11-28 08:39:38 -05:00
|
|
|
"github.com/mattermost/mattermost-server/v5/model"
|
2017-07-24 14:55:37 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type CodeProvider struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
CMD_CODE = "code"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
RegisterCommandProvider(&CodeProvider{})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (me *CodeProvider) GetTrigger() string {
|
|
|
|
|
return CMD_CODE
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-09 15:46:20 -05:00
|
|
|
func (me *CodeProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
|
2017-07-24 14:55:37 -04:00
|
|
|
return &model.Command{
|
|
|
|
|
Trigger: CMD_CODE,
|
|
|
|
|
AutoComplete: true,
|
|
|
|
|
AutoCompleteDesc: T("api.command_code.desc"),
|
|
|
|
|
AutoCompleteHint: T("api.command_code.hint"),
|
|
|
|
|
DisplayName: T("api.command_code.name"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-14 13:01:44 -04:00
|
|
|
func (me *CodeProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
|
2017-07-24 14:55:37 -04:00
|
|
|
if len(message) == 0 {
|
|
|
|
|
return &model.CommandResponse{Text: args.T("api.command_code.message.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
|
|
|
|
}
|
|
|
|
|
rmsg := " " + strings.Join(strings.Split(message, "\n"), "\n ")
|
2020-01-17 02:34:11 -05:00
|
|
|
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL, Text: rmsg, SkipSlackParsing: true}
|
2017-07-24 14:55:37 -04:00
|
|
|
}
|