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
|
|
|
|
2020-08-12 12:29:58 -04:00
|
|
|
package slashcommands
|
2017-07-24 14:55:37 -04:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
|
2023-06-11 01:24:35 -04:00
|
|
|
"github.com/mattermost/mattermost/server/public/model"
|
|
|
|
|
"github.com/mattermost/mattermost/server/public/shared/i18n"
|
2023-09-05 03:47:30 -04:00
|
|
|
"github.com/mattermost/mattermost/server/public/shared/request"
|
2023-06-11 01:24:35 -04:00
|
|
|
"github.com/mattermost/mattermost/server/v8/channels/app"
|
2017-07-24 14:55:37 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type CodeProvider struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const (
|
2021-01-04 01:02:29 -05:00
|
|
|
CmdCode = "code"
|
2017-07-24 14:55:37 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
2020-08-12 12:29:58 -04:00
|
|
|
app.RegisterCommandProvider(&CodeProvider{})
|
2017-07-24 14:55:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-12-11 10:45:18 -05:00
|
|
|
func (*CodeProvider) GetTrigger() string {
|
2021-01-04 01:02:29 -05:00
|
|
|
return CmdCode
|
2017-07-24 14:55:37 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-26 02:12:49 -05:00
|
|
|
func (*CodeProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
|
2017-07-24 14:55:37 -04:00
|
|
|
return &model.Command{
|
2021-01-04 01:02:29 -05:00
|
|
|
Trigger: CmdCode,
|
2017-07-24 14:55:37 -04:00
|
|
|
AutoComplete: true,
|
|
|
|
|
AutoCompleteDesc: T("api.command_code.desc"),
|
|
|
|
|
AutoCompleteHint: T("api.command_code.hint"),
|
|
|
|
|
DisplayName: T("api.command_code.name"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-10 09:11:32 -04:00
|
|
|
func (*CodeProvider) DoCommand(a *app.App, rctx request.CTX, args *model.CommandArgs, message string) *model.CommandResponse {
|
2021-01-25 05:15:17 -05:00
|
|
|
if message == "" {
|
2021-07-12 14:05:36 -04:00
|
|
|
return &model.CommandResponse{Text: args.T("api.command_code.message.app_error"), ResponseType: model.CommandResponseTypeEphemeral}
|
2017-07-24 14:55:37 -04:00
|
|
|
}
|
|
|
|
|
rmsg := " " + strings.Join(strings.Split(message, "\n"), "\n ")
|
2021-07-12 14:05:36 -04:00
|
|
|
return &model.CommandResponse{ResponseType: model.CommandResponseTypeInChannel, Text: rmsg, SkipSlackParsing: true}
|
2017-07-24 14:55:37 -04:00
|
|
|
}
|