From 0bf6f71dadc924b6ba3449fb99e6725fecef1bcb Mon Sep 17 00:00:00 2001 From: Adam Dodman Date: Fri, 1 Dec 2017 23:15:59 +0000 Subject: [PATCH] Initial Commit --- .gitignore | 2 ++ helpers.go | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lockcheck.go | 29 +++++++++++++++++ main.go | 59 +++++++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+) create mode 100644 .gitignore create mode 100644 helpers.go create mode 100644 lockcheck.go create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..602d253 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Constants.go +.idea/ \ No newline at end of file diff --git a/helpers.go b/helpers.go new file mode 100644 index 0000000..0118eec --- /dev/null +++ b/helpers.go @@ -0,0 +1,88 @@ +package main + +import "github.com/darfk/ts3" + +func ClientGetDbIdFromUid(uid string) ts3.Command { + return ts3.Command{ + Command: "´clientgetdbidfromuid", + Params: map[string][]string{ + "cluid": []string{uid}, + }, + } +} + +func ClientGetIds(uid string) ts3.Command { + return ts3.Command{ + Command: "´clientgetids", + Params: map[string][]string{ + "cluid": []string{uid}, + }, + } +} + +func ClientGetNameFromUid(uid string) ts3.Command { + return ts3.Command{ + Command: "´clientgetnamefromuid", + Params: map[string][]string{ + "cluid": []string{uid}, + }, + } +} + +func ClientGetNameFromDbId(dbid string) ts3.Command { + return ts3.Command{ + Command: "´clientgetnamefromdbid", + Params: map[string][]string{ + "cldbid": []string{dbid}, + }, + } +} + +func ClientInfo(clid string) ts3.Command { + return ts3.Command{ + Command: "clientinfo", + Params: map[string][]string{ + "clid": []string{"5"}, + }, + } +} + +func ServerGroupDelClient(sgid string, cldbid string) ts3.Command { + return ts3.Command{ + Command: "servergroupdelclient", + 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 + "[/B][/COLOR]" + } + + return ts3.Command{ + Command: "sendtextmessage", + Params: map[string][]string{ + "targetmode": []string{"2"}, + "target": []string{"1"}, + "msg": []string{message}, + }, + } +} + +func SendMessageUser(isError bool, message string, clid string) ts3.Command { + if isError { + message = "'[B][COLOR=#ff0000]" + message + "[/B][/COLOR]" + } + + return ts3.Command{ + Command: "sendtextmessage", + Params: map[string][]string{ + "targetmode": []string{"1"}, + "target": []string{clid}, + "msg": []string{message}, + }, + } +} diff --git a/lockcheck.go b/lockcheck.go new file mode 100644 index 0000000..13a2c98 --- /dev/null +++ b/lockcheck.go @@ -0,0 +1,29 @@ +package main + +import ( + "github.com/darfk/ts3" + "log" + "strings" +) + +func doLock(client *ts3.Client, clid string) { + data, err := client.Exec(ClientInfo(clid)) + if err != nil { + log.Fatal(err) + } + + cldbid := data.Params[0]["client_database_id"] + groups := strings.Split(data.Params[0]["client_servergroups"], ",") + 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)) + if err != nil { + log.Fatal(err) + } + } + } +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..dc26e06 --- /dev/null +++ b/main.go @@ -0,0 +1,59 @@ +package main + +import ( + "github.com/darfk/ts3" + "log" +) + +// 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"]) + } + } +} + +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) + } + + notification := make(chan ts3.Notification) + + go processNotify(client, notification) + + client.NotifyHandler(func(n ts3.Notification) { + notification <- n + }) + + for { + } +}