Giter Site home page Giter Site logo

teamspeak-query's Introduction

teamspeak-query npm version

A small library which exposes an API to talk to your Teamspeak-Server via the Teamspeak-ServerQuery

Installation

$ npm install teamspeak-query

Example

const TeamspeakQuery = require('teamspeak-query');
const query = new TeamspeakQuery('127.0.0.1', 10011);

query.send('login', 'serveradmin', 'changeme')
	.then(() => query.send('use', 1))
	.then(() => query.send('servernotifyregister', { 'event': 'server' }))
	.then(() => console.log('Done! Everything went fine'))
	.catch(err => console.error('An error occured:', err));

// After teamspeak has processed 'servernotifyregister' we will get notified about any connections
query.on('cliententerview', data =>
	console.log(data.client_nickname, 'connected') );

Constructor

The constructor takes 3 parameters

Name Default Description
host 127.0.0.1 The ip of the server
port 10011 The query port of the server
options { } Any options that should be passed to the socket

INFO: The raw socket can be accessed via the instance's sock property.

Methods

TeamspeakQuery.send(cmd, params?, ...flags)

Send a command to the server.
There are 2 ways (which can also be mixed) to specify parameters for the command:

  • params: An object, e.g. { 'parameter': 'value', 'x': 42 }. Only works if the 2nd argument is an object.
  • ...flags: Plain arguments passed to the function, e.g. query.send('login', 'username', 'password').
    You can also use it to set flags, e.g. query.send('clientlist', '-uid').

TeamspeakQuery#parse(str)

Parse the response of the server, returns an object that contains the type of the response (error, notification, etc.) and the parameters that were returned by the server.

TeamspeakQuery#escape(str)

Escape a string according to the specification.

TeamspeakQuery#unescape(str)

Unescape a string according to the specification.

Throttling

Commands are being throttled by default if the host is not set to the local machine (127.0.0.1 or localhost) in order to prevent a ban for flooding (see Whitelisting and Blacklisting in the specs).
The instance of lib/throttle.js can be accessed via TeamspeakQuery.throttle.
If you want to disable throttling, you can do it like this: TeamspeakQuery.throttle.set('enable', false).

teamspeak-query's People

Contributors

schroffl avatar

Watchers

Mehdi Aïssani avatar

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.