-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.go
47 lines (39 loc) · 1.02 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
package botform
import (
"github.com/vmihailenco/msgpack/v5"
)
type State struct {
Values map[string]string
Key BfcKey
CancelActionLabel string
SaveAndNextActionLabel string
NextActionLabel string
PrevActionLabel string
IsFinished bool
IsCanceled bool
}
func (s *State) GetValues() map[string]string {
return s.Values
}
func (s *State) Store(k, v string) {
s.Values[k] = v
}
func (s *State) Delete(k string) {
delete(s.Values, k)
}
func (s *State) Marshal() (string, error) {
m, e := msgpack.Marshal(s)
return string(m), e
}
func NewState(data map[string]string, key BfcKey) *State {
ss := &State{Values: data, Key: key, IsCanceled: false, IsFinished: false, CancelActionLabel: "[X]", PrevActionLabel: "<=", SaveAndNextActionLabel: "Save and next", NextActionLabel: "Skip step"}
return ss
}
func UnmarshalState(data []byte) (s *State, e error) {
s = &State{}
e = msgpack.Unmarshal(data, &s)
if e != nil {
return nil, e
}
return s, nil
}