mirror of
				https://github.com/Adam-Ant/TeamspeakBot-Go
				synced 2025-11-04 04:27:18 +00:00 
			
		
		
		
	Initial Commit
This commit is contained in:
		
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
Constants.go
 | 
			
		||||
.idea/
 | 
			
		||||
							
								
								
									
										88
									
								
								helpers.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								helpers.go
									
									
									
									
									
										Normal file
									
								
							@@ -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},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										29
									
								
								lockcheck.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								lockcheck.go
									
									
									
									
									
										Normal file
									
								
							@@ -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)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										59
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							@@ -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 {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user