github.com/vnforks/kid/v5@v5.22.1-0.20200408055009-b89d99c65676/app/command_code.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package app
     5  
     6  import (
     7  	"strings"
     8  
     9  	goi18n "github.com/mattermost/go-i18n/i18n"
    10  	"github.com/vnforks/kid/v5/model"
    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_CLASS, Text: rmsg, SkipSlackParsing: true}
    44  }