/
CommandResult.go
60 lines (49 loc) · 1.5 KB
/
CommandResult.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"fmt"
"github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/vehsamrak/telegramud/entity"
)
type CommandResult struct {
output *Output
CommandHandler CommandHandler
additionalCommands []GameCommand
}
func (commandResult *CommandResult) Output(player *entity.Player) *Output {
output := commandResult.output
if output != nil && output.ReplyMarkup != nil {
replyMarkup, ok := output.ReplyMarkup.(tgbotapi.ReplyKeyboardMarkup)
if ok {
keyboard := replyMarkup.Keyboard
characteristicsKeyboardRow := []tgbotapi.KeyboardButton{
tgbotapi.NewKeyboardButton(
fmt.Sprintf(
"Персонаж | %d уровень | %d/%d жизнь",
player.Level(),
player.HP(),
player.MaxHP(),
),
),
tgbotapi.NewKeyboardButton(fmt.Sprintf("Инвентарь | %d $", player.Money())),
}
if len(characteristicsKeyboardRow) > 0 {
keyboard = append(keyboard, characteristicsKeyboardRow)
replyMarkup.Keyboard = keyboard
output.ReplyMarkup = tgbotapi.ReplyKeyboardMarkup{
ResizeKeyboard: true,
Keyboard: keyboard,
}
}
}
}
return output
}
func (commandResult *CommandResult) SetOutput(output *Output) {
commandResult.output = output
}
func (commandResult *CommandResult) AfterCommands() []GameCommand {
return commandResult.additionalCommands
}
func (commandResult *CommandResult) AddCommand(command GameCommand) {
commandResult.additionalCommands = append(commandResult.additionalCommands, command)
}