-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.go
104 lines (94 loc) · 2.47 KB
/
state.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
// import (
// "trade_calc_bot/component"
// "context"
// "github.com/go-telegram/bot"
// "github.com/go-telegram/bot/models"
// )
// type State int
// const (
// Init State = iota
// StartMenu
// OpenPositionMenu
// AddPositionMenu
// InputCapitalState
// InputCapitalErrorState
// InputCapitalLossRadioState
// InputCapitalLossRadioErrorState
// InputLossRatioState
// InputLossRatioErrorState
// )
// type Event int
// const (
// ClickOpenPosition Event = iota + 100
// ClickAddPosition
// ClickInputCapitalButton
// ClickInputCapitalLossRatioButton
// SelectCapitalLossRatio
// ClickInputLossRatioButton
// ClickCancelButton
// ClickCalculateButton
// InvalidAnswer
// BackToOpenPositionMenu
// BackToAddPositionMenu
// BackToStartMenu
// )
// type StateMachine struct {
// State State
// MainMenu *component.MainMenu
// OpenPosition *component.OpenPositionMenu
// }
// func NewStateMachine() *StateMachine {
// return &StateMachine{
// State: State(StartMenu),
// MainMenu: component.NewMainMenu(),
// OpenPosition: component.NewOpenPositionMenu(),
// }
// }
// func (self *StateMachine) HandleEvent(event Event, ctx context.Context, b *bot.Bot, update *models.Update) {
// switch self.State {
// case Init:
// self.State = StartMenu
// case StartMenu:
// switch event {
// case ClickOpenPosition:
// self.State = OpenPositionMenu
// self.OpenPosition.ReplaceShow(
// ctx,
// b,
// update.CallbackQuery.Message.Message.Chat.ID,
// update.CallbackQuery.Message.Message.ID,
// update.CallbackQuery.InlineMessageID,
// )
// case ClickAddPosition:
// self.State = AddPositionMenu
// }
// case OpenPositionMenu:
// switch event {
// case ClickInputCapitalButton:
// self.State = InputCapitalState
// case ClickInputCapitalLossRatioButton:
// self.State = InputCapitalLossRadioState
// case ClickInputLossRatioButton:
// self.State = InputLossRatioState
// case ClickCancelButton:
// self.State = StartMenu
// case ClickCalculateButton:
// // 开始计算
// }
// case AddPositionMenu:
// case InputCapitalState:
// switch event {
// case InvalidAnswer:
// // 提示错误信息
// self.State = InputCapitalState
// case BackToOpenPositionMenu:
// self.State = OpenPositionMenu
// case BackToAddPositionMenu:
// self.State = AddPositionMenu
// case BackToStartMenu:
// // 取消当前计算任务
// self.State = StartMenu
// }
// }
// }