-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathts3_test.go
121 lines (98 loc) · 2.23 KB
/
ts3_test.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
package ts3
import (
"testing"
)
type config struct {
Address string `json:"address"`
Username string `json:"username"`
Password string `json:"password"`
Server int `json:"server"`
}
func TestBasic(t *testing.T) {
var err error
config := config{
"teamspeak.darfk.net:10011",
"test",
"xWUkRRlM",
1,
}
client, err := NewClient(config.Address)
if err != nil {
t.Fatal(err)
}
t.Logf("connected to %s", config.Address)
var response Response
response, err = client.Exec(Login(config.Username, config.Password))
if err != nil {
t.Fatal(err)
}
t.Logf("logged in as %s", config.Username)
response, err = client.Exec(Use(config.Server))
if err != nil {
t.Fatal(err)
}
t.Logf("using server %d", config.Server)
response, err = client.Exec(Version())
if err != nil {
t.Fatal(err)
}
t.Logf("version %q", response)
t.Logf("doing something we're not allowed to do")
response, err = client.Exec(Command{
Command: "serverlist",
})
if err == nil {
t.Fatal("expected error")
}
t.Logf("%s", err)
// Let's see if Nathan's online >:)
var nathanIsOnline bool = false
err = client.WalkClients(func(idx int, client map[string]string) {
if nick, ok := client["client_nickname"]; ok && nick == "Nathan" {
nathanIsOnline = true
}
})
if err != nil {
t.Fatal(err)
}
if nathanIsOnline {
t.Log("Nathan is online!")
} else {
t.Log("Nathan must be asleep!")
}
var lobbyChannelId string
err = client.WalkChannels(func(idx int, channel map[string]string) {
if name, ok := channel["channel_name"]; ok && name == "Lobby" {
t.Log(channel)
if cid, ok := channel["cid"]; ok {
lobbyChannelId = cid
}
}
})
response, err = client.Exec(Command{
Command: "servernotifyregister",
Params: map[string][]string{
"event":[]string{"textchannel"},
"id":[]string{lobbyChannelId},
},
})
if err != nil {
t.Fatal(err)
}
notification := make(chan Notification)
client.NotifyHandler(func (n Notification) {
notification <- n
})
response, err = client.Exec(Command{
Command: "sendtextmessage",
Params: map[string][]string{
"targetmode":[]string{"2"},
"target":[]string{lobbyChannelId},
"msg":[]string{"this is a test"},
},
})
if err != nil {
t.Fatal(err)
}
t.Log(<-notification)
}