1
0
mirror of https://github.com/Adam-Ant/TeamspeakBot-Go synced 2024-11-05 13:46:22 +00:00
TeamspeakBot-Go/main.go

74 lines
1.4 KiB
Go
Raw Normal View History

2017-12-01 23:15:59 +00:00
package main
import (
"github.com/darfk/ts3"
"log"
2017-12-03 21:53:30 +00:00
"time"
2017-12-01 23:15:59 +00:00
)
// Username and password in Constants.go, not on github :D
func processNotify(client *ts3.Client, notification chan ts3.Notification) {
for i := range notification {
2017-12-03 21:53:30 +00:00
switch i.Type {
case "notifyclientmoved", "notifycliententerview":
// We need to check for lock group on every move, and guest check is best done at the same time.
doLockandGuest(client, i.Params[0]["clid"])
2017-12-01 23:15:59 +00:00
}
}
}
func main() {
client, err := ts3.NewClient("ts3.cwgaming.co.uk:10011")
if err != nil {
log.Fatal(err)
}
_, err = client.Exec(ts3.Login(user, pass))
if err != nil {
log.Fatal(err)
}
_, err = client.Exec(ts3.Use(1))
if err != nil {
log.Fatal(err)
}
// Start listening to client join and move events
_, err = client.Exec(ts3.Command{
Command: "servernotifyregister",
Params: map[string][]string{
"event": []string{"channel"},
"id": []string{"0"},
},
})
if err != nil {
log.Fatal(err)
}
2017-12-03 21:53:30 +00:00
// Start listening to text chat
_, err = client.Exec(ts3.Command{
Command: "servernotifyregister",
Params: map[string][]string{
"event": []string{"textchannel"},
"id": []string{"1"},
},
})
if err != nil {
log.Fatal(err)
}
2017-12-01 23:15:59 +00:00
notification := make(chan ts3.Notification)
go processNotify(client, notification)
client.NotifyHandler(func(n ts3.Notification) {
notification <- n
})
for {
2017-12-03 21:53:30 +00:00
time.Sleep(500 * time.Millisecond)
2017-12-01 23:15:59 +00:00
}
}