-
Notifications
You must be signed in to change notification settings - Fork 1
/
message.go
123 lines (102 loc) · 3.2 KB
/
message.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package go_ts3
type Message struct {
MessageId int `json:"msgid,string"`
ClientId string `json:"cluid"`
Subject string `json:"subject"`
Message string `json:"message"`
}
// gm `manage_scope`
type gmRequest struct {
Text string `schema:"msg,required"`
}
func (c *TeamspeakHttpClient) GlobalMessage(message string) error {
return c.requestWithParams("gm", gmRequest{Text: message}, nil)
}
// messageadd `manage_scope, write_scope`
type messageAddRequest struct {
ClientUid string `schema:"cluid"`
Subject string `schema:"subject"`
Message string `schema:"message"`
}
func (c *TeamspeakHttpClient) MessageAdd(clientUid string, subject string, message string) error {
return c.requestWithParams("messageadd", messageAddRequest{
ClientUid: clientUid,
Subject: subject,
Message: message,
}, nil)
}
// messagedel `manage_scope, write_scope`
type messageDeleteRequest struct {
MessageId int `schema:"msgid,required"`
}
func (c *TeamspeakHttpClient) MessageDel(messageId int) error {
return c.requestWithParams("messageget", messageDeleteRequest{MessageId: messageId}, nil)
}
// messageget `manage_scope, write_scope, read_scope`
type messageGetRequest struct {
MessageId int `schema:"msgid,required"`
}
func (c *TeamspeakHttpClient) MessageGet(messageId int) (*Message, error) {
var messages []Message
err := c.requestWithParams("messageget", messageGetRequest{MessageId: messageId}, &messages)
if err != nil {
return nil, err
}
return &messages[0], nil
}
// messagelist `manage_scope, write_scope, read_scope`
func (c *TeamspeakHttpClient) MessageList() (*[]Message, error) {
var messages []Message
err := c.request("messagelist", &messages)
if err != nil {
return nil, err
}
return &messages, nil
}
// messageupdateflag `manage_scope, write_scope`
type messageUpdateFlagRequest struct {
MessageId string `schema:"msgid,required"`
Flag int `schema:"flag,required"`
}
func (c *TeamspeakHttpClient) MessageSetRead(messageId string) error {
return c.requestWithParams("messageupdateflag", messageUpdateFlagRequest{
MessageId: messageId,
Flag: 1,
}, nil)
}
func (c *TeamspeakHttpClient) MessageSetUnread(messageId string) error {
return c.requestWithParams("messageupdateflag", messageUpdateFlagRequest{
MessageId: messageId,
Flag: 1,
}, nil)
}
// sendtextmessage `manage_scope, write_scope`
type sendMessageRequest struct {
TargetMode int `schema:"targetmode,required"`
TargetId int `schema:"target,required"`
Message string `schema:"msg,required"`
}
func (c *TeamspeakHttpClient) SendClientMessage(targetId int, message string) error {
return c.sendMessage(sendMessageRequest{
TargetMode: 1,
TargetId: targetId,
Message: message,
})
}
func (c *TeamspeakHttpClient) SendChannelMessage(message string) error {
return c.sendMessage(sendMessageRequest{
TargetMode: 2,
TargetId: 1,
Message: message,
})
}
func (c *TeamspeakHttpClient) SendVirtualServerMessage(targetId int, message string) error {
return c.sendMessage(sendMessageRequest{
TargetMode: 3,
TargetId: targetId,
Message: message,
})
}
func (c *TeamspeakHttpClient) sendMessage(request sendMessageRequest) error {
return c.requestWithParams("sendtextmessage", request, nil)
}