github.com/vnforks/kid/v5@v5.22.1-0.20200408055009-b89d99c65676/app/command_dnd.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  	goi18n "github.com/mattermost/go-i18n/i18n"
     8  	"github.com/vnforks/kid/v5/model"
     9  )
    10  
    11  type DndProvider struct {
    12  }
    13  
    14  const (
    15  	CMD_DND = "dnd"
    16  )
    17  
    18  func init() {
    19  	RegisterCommandProvider(&DndProvider{})
    20  }
    21  
    22  func (me *DndProvider) GetTrigger() string {
    23  	return CMD_DND
    24  }
    25  
    26  func (me *DndProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
    27  	return &model.Command{
    28  		Trigger:          CMD_DND,
    29  		AutoComplete:     true,
    30  		AutoCompleteDesc: T("api.command_dnd.desc"),
    31  		DisplayName:      T("api.command_dnd.name"),
    32  	}
    33  }
    34  
    35  func (me *DndProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
    36  	status, err := a.GetStatus(args.UserId)
    37  	if err != nil {
    38  		return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_dnd.error")}
    39  	} else {
    40  		if status.Status == "dnd" {
    41  			a.SetStatusOnline(args.UserId, true)
    42  			return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_dnd.disabled")}
    43  		}
    44  	}
    45  
    46  	a.SetStatusDoNotDisturb(args.UserId)
    47  
    48  	return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_dnd.success")}
    49  }