Git Product home page Git Product logo

ts3's Introduction

ts3

TeamSpeak 3 Server Query Library

Simple usage

package main

import (
    "fmt"
    "time"

    "github.com/toqueteos/ts3"
)

func main() {
    conn := ts3.Dial(":10011")
    defer conn.Close()

    bot(conn)
}

func bot(conn *ts3.Conn) {
    defer conn.Cmd("quit")

    s := "version"
    r := conn.Cmd(s)
    fmt.Printf("> %s\n%s", s, r)
}

Notifications support

Check examples/bot_notifications.go

ts3's People

Contributors

toqueteos avatar zerozshadow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ts3's Issues

Register on Servernotifications does not work (like in example)

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 =)

Empty response

Sometimes I receive no error and an empty response. This happens in 1/5th of my requests, and I suspect it's down to the parsing of responses.

Ideas for V2

  • Keypair response? Instead of the response being a string, it may be possible to pass back a struct of key pair values correlating to the command. Example:
// Unformatted
cluid=e2PADQ8fVw9MhhxdN3fjlUSSZTQ= cldbid=3 name=Toby\son\slinux

// Formatted
{
  {"cluid": "e2PADQ8fVw9MhhxdN3fjlUSSZTQ="},
  {"cldbid": "3"},
  {"name": "Toby\son\slinux"},
}

Here is some code I use to do something similar to this.

//Response contains the formatting for telnet responses in a key:pair format
type Response struct {
    Key   string
    Value string
}

//FmtResponse takes a string response from the ServerQuery and returns a formatted string array
func FmtResponse(input string) ([]Response, error) {
    if input != "" {

        var ResponseList []Response

        fields := strings.Fields(input)
        for _, e := range fields {
            keyvalue := strings.SplitN(e, "=", 2)
            new := Response{
                Key:   Sanitize(keyvalue[0]),
                Value: Sanitize(keyvalue[1]),
            }
            newList := append(ResponseList, new)
            ResponseList = newList
        }
        //Broke out of for loop and returns list
        return ResponseList, nil
    }
    return nil, errors.New("input is empty")
}
  • Parsing of response strings. Example:
// Unparsed
Toby\son\slinux

//Parsed
Toby on linux

Here is the code I use to do this:

//Sanitize trims spaces and replaces escape codes with their readable counterparts.
func Sanitize(input string) string {
    res := strings.TrimSpace(input)
    res = strings.Replace(res, `\s`, " ", -1)
    return res
}
  • Channels for notifications? This way, to set up a notification listener it would be as simple as:
func listener(notif chan Notificaion) {
  for _, e := range notif {
    fmt.Printf("Notification: %s", e)
  }
}

These are just my ideas, and I'd love some feedback on them.

Doubled up response

Sometimes the end of the response will contain the start, too.

Example:

// Correct response
cluid=e2PADQ8fVw9MhhxdN3fjlUSSZTQ= cldbid=3 name=Toby\son\slinux

//Broken response
cluid=e2PADQ8fVw9MhhxdN3fjlUSSZTQ= cldbid=3 name=Toby\son\slinuxcluid=e2PADQ8fVw9MhhxdN3fjlUSSZTQ= cldbid=3 name=Toby\son\slinux

Code to reproduce:

package main

import "github.com/toqueteos/ts3"
import "fmt"
import "time"

const (
    queryUsername = ""
    queryPassword = ""
    userid        = ""
)

func main() {

    conn, e := ts3.Dial("localhost", false)
    if e != nil {
        panic(e)
    }
    login := fmt.Sprintf("login %s %s", queryUsername, queryPassword)
    resp, err := conn.Cmd(login)
    if err.Id != 0 {
        panic(err.Msg)
    }
    fmt.Println(resp)
    re, err := conn.Cmd("use sid=1")
    if err.Id != 0 {
        panic(err.Msg)
    }
    fmt.Println(re)

    command := fmt.Sprintf("clientgetnamefromuid cluid=%s", userid)
    for i := 0; i < 20; i++ {

        res, err := conn.Cmd(command)
        if err.Id != 0 {
            panic(err.Msg)
        }
        fmt.Println(res)

        time.Sleep(500 * time.Millisecond)
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.