-
Notifications
You must be signed in to change notification settings - Fork 0
/
responses.go
48 lines (45 loc) · 1.05 KB
/
responses.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
package cmds
import (
//"image/color"
"github.com/Clinet/clinet_services"
"github.com/JoshuaDoes/json"
)
type CmdResp struct {
*services.Message //Take on the fields of a service message
Ready bool //When not ready, a typing event should be sent and a goroutine should wait on a response
}
func NewCmdRespMsg(content string) *CmdResp {
resp := &CmdResp{&services.Message{Content: content}, true}
return resp
}
func NewCmdRespEmbed(title, content string) *CmdResp {
resp := &CmdResp{&services.Message{Title: title, Content: content}, true}
return resp
}
func CmdRespFromMsg(msg *services.Message) *CmdResp {
return &CmdResp{msg, true}
}
func (resp *CmdResp) String() string {
jsonData, err := json.Marshal(resp, true)
if err != nil {
return err.Error()
}
return string(jsonData)
}
func (resp *CmdResp) OnReady(readyCall func(*CmdResp)) {
go func(r *CmdResp) {
for {
if r == nil {
return
}
if r.Ready {
readyCall(r)
return
}
}
}(resp)
}
func (resp *CmdResp) SetReady(ready bool) *CmdResp {
resp.Ready = ready
return resp
}