-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocol.go
65 lines (53 loc) · 1.43 KB
/
protocol.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
package bearychat
import (
"fmt"
"strings"
)
type Image struct {
URL string `json:"url"`
}
type Attachment struct {
Title string `json:"title"`
Text string `json:"text"`
Color string `json:"color"`
Images []Image `json:"images"`
}
type Message struct {
Text string `json:"text"`
Notification string `json:"notification"`
Markdown bool `json:"markdown"`
Channel string `json:"channel"`
User string `json:"user"`
Attachments []Attachment `json:"attachments"`
}
type OutgoingRequest struct {
Token string `json:"token"`
Timestamp int `json:"ts"`
Text string `json:"text"`
TriggerWord string `json:"trigger_word"`
Subdomain string `json:"subdomain"`
ChannelName string `json:"channel_name"`
UserName string `json:"user_name"`
Commands []string `json:"-"`
}
func (p *OutgoingRequest) Args() []string {
strArgs := strings.TrimSpace(strings.TrimPrefix(p.Text, p.TriggerWord))
for i := 0; i < len(p.Commands); i++ {
strArgs = strings.TrimSpace(strings.TrimPrefix(strArgs, p.Commands[i]))
}
if len(strArgs) == 0 {
return nil
}
return strings.Fields(strArgs)
}
type IncomingResponse struct {
Code int `json:"code"`
Error string `json:"error"`
Result interface{} `json:"result"`
}
func (p *IncomingResponse) Err() error {
if p.Code != 0 {
return fmt.Errorf("code: %d, %s", p.Code, p.Error)
}
return nil
}