Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register on Servernotifications does not work (like in example) #7

Open
sushi86 opened this issue Jun 16, 2017 · 1 comment
Open

Register on Servernotifications does not work (like in example) #7

sushi86 opened this issue Jun 16, 2017 · 1 comment

Comments

@sushi86
Copy link

sushi86 commented Jun 16, 2017

First of all thank you for this nice API, good work =)

I'm not that experienced in golang yet, for me as a learning project I started to work on a ts3 bot with your API.

I will try to see each connect and disconnect for every client on my server and then notify another programm.

Unfortunately I was not able to register. Your example doesn't work.
Following Line is broken:
ch := conn.Chans()

Maybe you can update your examples?

Would be really cool =)

@sushi86
Copy link
Author

sushi86 commented Jun 16, 2017

Ok maybe I was to early with my issue.
I figured it out bei myself somehow...

Here is my code:


package main

import (
	"fmt"
	"time"

	"github.com/toqueteos/ts3"
	"log"
)

func main() {
	conn, err := ts3.Dial(":10011", false)
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	bot(conn)
}

// bot is a simple bot that checks version, signs in and sends a text message to
// channel#1 then exits.
func bot(conn *ts3.Conn) {
	defer conn.Cmd("quit")

	conn.NotifyFunc(func (e string, s string) {
		fmt.Println(e + " " + s)
	})

	var cmds = []string{
		// Show version
		"version",
		// Login
		"login serveradmin 123456",
		// Choose virtual server
		"use 1",
		// Update nickname
		`clientupdate client_nickname=Sushi\sBot`,
		// "clientlist",
		// Send message to channel with id=1
		`sendtextmessage targetmode=2 target=1 msg=Big\sBrother\sis\snow\swatching\syou`,
		// Register to notify
		"servernotifyregister event=server",
	}

	for _, s := range cmds {
		// Send command and wait for its response
		r,_ := conn.Cmd(s)
		// Display as:
		//     > request
		//     response
		fmt.Printf("> %s\n%s", s, r)
		// Wait a bit after each command so we don't get banned. By default you
		// can issue 10 commands within 3 seconds.  More info on the
		// WHITELISTING AND BLACKLISTING section of TS3 ServerQuery Manual
		// (http://goo.gl/OpJXz).
		time.Sleep(350 * time.Millisecond)
	}

	for { select {} }
}

The important part is of course to register to the server notify:
"servernotifyregister event=server",
and register the notifyFunc:
conn.NotifyFunc(func (e string, s string) { fmt.Println(e + " " + s) })
At least I made the program run forever:
for { select {} }

Of course there are more elegant ways, but I'm a beginner ;)

Maybe you can suggest a more professional way within your examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant