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