github.com/adacta-ru/mattermost-server/v6@v6.0.0/app/slashcommands/command_code.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package slashcommands 5 6 import ( 7 "strings" 8 9 goi18n "github.com/mattermost/go-i18n/i18n" 10 "github.com/adacta-ru/mattermost-server/v6/app" 11 "github.com/adacta-ru/mattermost-server/v6/model" 12 ) 13 14 type CodeProvider struct { 15 } 16 17 const ( 18 CMD_CODE = "code" 19 ) 20 21 func init() { 22 app.RegisterCommandProvider(&CodeProvider{}) 23 } 24 25 func (*CodeProvider) GetTrigger() string { 26 return CMD_CODE 27 } 28 29 func (*CodeProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command { 30 return &model.Command{ 31 Trigger: CMD_CODE, 32 AutoComplete: true, 33 AutoCompleteDesc: T("api.command_code.desc"), 34 AutoCompleteHint: T("api.command_code.hint"), 35 DisplayName: T("api.command_code.name"), 36 } 37 } 38 39 func (*CodeProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse { 40 if len(message) == 0 { 41 return &model.CommandResponse{Text: args.T("api.command_code.message.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} 42 } 43 rmsg := " " + strings.Join(strings.Split(message, "\n"), "\n ") 44 return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL, Text: rmsg, SkipSlackParsing: true} 45 }