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{
|
return ts3.Command{
|
||||||
Command: "clientinfo",
|
Command: "clientinfo",
|
||||||
Params: map[string][]string{
|
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 {
|
func ServerGroupAddClient(sgid string, cldbid string) ts3.Command {
|
||||||
if isError {
|
return ts3.Command{
|
||||||
message = "'[B][COLOR=#ff0000]" + message + "[/B][/COLOR]"
|
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{
|
return ts3.Command{
|
||||||
Command: "sendtextmessage",
|
Command: "sendtextmessage",
|
||||||
Params: map[string][]string{
|
Params: map[string][]string{
|
||||||
"targetmode": []string{"2"},
|
"targetmode": []string{"2"},
|
||||||
"target": []string{"1"},
|
"target": []string{"1"},
|
||||||
"msg": []string{message},
|
"msg": []string{"Cockwomble"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendMessageUser(isError bool, message string, clid string) ts3.Command {
|
func SendMessageUser(isError bool, message string, clid string) ts3.Command {
|
||||||
if isError {
|
//if isError {
|
||||||
message = "'[B][COLOR=#ff0000]" + message + "[/B][/COLOR]"
|
// message = "'[B][COLOR=#ff0000]" + message + "[/COLOR][/B]"
|
||||||
}
|
//}
|
||||||
|
|
||||||
return ts3.Command{
|
return ts3.Command{
|
||||||
Command: "sendtextmessage",
|
Command: "sendtextmessage",
|
||||||
|
35
lockcheck.go
35
lockcheck.go
@ -6,7 +6,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func doLock(client *ts3.Client, clid string) {
|
func doLockandGuest(client *ts3.Client, clid string) {
|
||||||
|
var groupAssigned bool
|
||||||
data, err := client.Exec(ClientInfo(clid))
|
data, err := client.Exec(ClientInfo(clid))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -14,16 +15,38 @@ func doLock(client *ts3.Client, clid string) {
|
|||||||
|
|
||||||
cldbid := data.Params[0]["client_database_id"]
|
cldbid := data.Params[0]["client_database_id"]
|
||||||
groups := strings.Split(data.Params[0]["client_servergroups"], ",")
|
groups := strings.Split(data.Params[0]["client_servergroups"], ",")
|
||||||
|
nickname := data.Params[0]["client_nickname"]
|
||||||
|
|
||||||
for i := range groups {
|
for i := range groups {
|
||||||
if groups[i] == "9" {
|
if groups[i] == "9" {
|
||||||
_, err := client.Exec(ServerGroupDelClient("9",cldbid))
|
_, err := client.Exec(ServerGroupDelClient("9", cldbid))
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
_, err = client.Exec(SendMessageUser(false, "Removed Lock group from you!", clid))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 (
|
import (
|
||||||
"github.com/darfk/ts3"
|
"github.com/darfk/ts3"
|
||||||
"log"
|
"log"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Username and password in Constants.go, not on github :D
|
// Username and password in Constants.go, not on github :D
|
||||||
|
|
||||||
func processNotify(client *ts3.Client, notification chan ts3.Notification) {
|
func processNotify(client *ts3.Client, notification chan ts3.Notification) {
|
||||||
for i := range notification {
|
for i := range notification {
|
||||||
//log.Println(i)
|
switch i.Type {
|
||||||
if i.Type == "notifyclientmoved" {
|
case "notifyclientmoved", "notifycliententerview":
|
||||||
// We need to check for lock group
|
// We need to check for lock group on every move, and guest check is best done at the same time.
|
||||||
doLock(client, i.Params[0]["clid"])
|
doLockandGuest(client, i.Params[0]["clid"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,6 +47,18 @@ func main() {
|
|||||||
log.Fatal(err)
|
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)
|
notification := make(chan ts3.Notification)
|
||||||
|
|
||||||
go processNotify(client, notification)
|
go processNotify(client, notification)
|
||||||
@ -55,5 +68,6 @@ func main() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user