mirror of
https://github.com/Adam-Ant/TeamspeakBot-Go
synced 2024-12-20 07:24:34 +00:00
Add guest check, small refactor
This commit is contained in:
parent
0bf6f71dad
commit
4aa1e5075e
26
helpers.go
26
helpers.go
@ -42,7 +42,7 @@ func ClientInfo(clid string) ts3.Command {
|
||||
return ts3.Command{
|
||||
Command: "clientinfo",
|
||||
Params: map[string][]string{
|
||||
"clid": []string{"5"},
|
||||
"clid": []string{clid},
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -57,25 +57,35 @@ func ServerGroupDelClient(sgid string, cldbid string) ts3.Command {
|
||||
}
|
||||
}
|
||||
|
||||
func SendMessageChannel(isError bool, message string) ts3.Command {
|
||||
if isError {
|
||||
message = "'[B][COLOR=#ff0000]" + message + "[/B][/COLOR]"
|
||||
func ServerGroupAddClient(sgid string, cldbid string) ts3.Command {
|
||||
return ts3.Command{
|
||||
Command: "servergroupaddclient",
|
||||
Params: map[string][]string{
|
||||
"sgid": []string{sgid},
|
||||
"cldbid": []string{cldbid},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func SendMessageChannel(isError bool, message string) ts3.Command {
|
||||
//if isError {
|
||||
// message = "'[B][COLOR=#ff0000]" + message + "[/COLOR][/B]"
|
||||
//}
|
||||
|
||||
return ts3.Command{
|
||||
Command: "sendtextmessage",
|
||||
Params: map[string][]string{
|
||||
"targetmode": []string{"2"},
|
||||
"target": []string{"1"},
|
||||
"msg": []string{message},
|
||||
"msg": []string{"Cockwomble"},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func SendMessageUser(isError bool, message string, clid string) ts3.Command {
|
||||
if isError {
|
||||
message = "'[B][COLOR=#ff0000]" + message + "[/B][/COLOR]"
|
||||
}
|
||||
//if isError {
|
||||
// message = "'[B][COLOR=#ff0000]" + message + "[/COLOR][/B]"
|
||||
//}
|
||||
|
||||
return ts3.Command{
|
||||
Command: "sendtextmessage",
|
||||
|
29
lockcheck.go
29
lockcheck.go
@ -6,7 +6,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func doLock(client *ts3.Client, clid string) {
|
||||
func doLockandGuest(client *ts3.Client, clid string) {
|
||||
var groupAssigned bool
|
||||
data, err := client.Exec(ClientInfo(clid))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -14,16 +15,38 @@ func doLock(client *ts3.Client, clid string) {
|
||||
|
||||
cldbid := data.Params[0]["client_database_id"]
|
||||
groups := strings.Split(data.Params[0]["client_servergroups"], ",")
|
||||
nickname := data.Params[0]["client_nickname"]
|
||||
|
||||
for i := range groups {
|
||||
if groups[i] == "9" {
|
||||
_, err := client.Exec(ServerGroupDelClient("9", cldbid))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
_, err = client.Exec(SendMessageUser(false, "Removed Lock group from you!", clid))
|
||||
|
||||
log.Println("Removed lock group from client " + nickname)
|
||||
|
||||
//_, err = client.Exec(SendMessageChannel(false, "Removed Lock group from you!"))
|
||||
//if err != nil {
|
||||
// log.Println(err)
|
||||
//}
|
||||
|
||||
}
|
||||
if groups[i] == "8" {
|
||||
groupAssigned = true
|
||||
}
|
||||
}
|
||||
|
||||
log.Println(groupAssigned)
|
||||
|
||||
if !groupAssigned {
|
||||
// Guest group missing, needs assigning.
|
||||
_, err := client.Exec(ServerGroupAddClient("8", cldbid))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Println("Gave guest group to client " + nickname)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
22
main.go
22
main.go
@ -3,16 +3,17 @@ package main
|
||||
import (
|
||||
"github.com/darfk/ts3"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Username and password in Constants.go, not on github :D
|
||||
|
||||
func processNotify(client *ts3.Client, notification chan ts3.Notification) {
|
||||
for i := range notification {
|
||||
//log.Println(i)
|
||||
if i.Type == "notifyclientmoved" {
|
||||
// We need to check for lock group
|
||||
doLock(client, i.Params[0]["clid"])
|
||||
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"])
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -46,6 +47,18 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
notification := make(chan ts3.Notification)
|
||||
|
||||
go processNotify(client, notification)
|
||||
@ -55,5 +68,6 @@ func main() {
|
||||
})
|
||||
|
||||
for {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user