const TeamSpeak3 = require("ts3-nodejs-library")
const Promise = require("bluebird")
const needednumbertopoke = 30;
const message = "Hi man, you are special trust me!";
var ts3 = new TeamSpeak3({
host: "",
queryport: 10011,
serverport: 9987,
username: "serveradmin",
password: "",
nickname: "r4p3.net",
antispam: true,
antispamtimer: 350,
keepalive: true
});
function pokeOnConnect(client) {
Promise.all([
ts3.serverInfo()
]).then(([{virtualserver_clientsonline}]) => {
// Hack :D exclude query bot
const online = (virtualserver_clientsonline - 1);
if(online >= needednumbertopoke && client.getCache().client_type === 0){
client.poke(message);
}
})
}
ts3.on("clientconnect", ev => {
const client = ev.client;
pokeOnConnect(client);
})
ts3.on("ready", () => {
//This Part subscribes to all events available
Promise.all([
ts3.registerEvent("server"),
ts3.registerEvent("channel", 0),
ts3.registerEvent("textserver"),
ts3.registerEvent("textchannel"),
ts3.registerEvent("textprivate")
]).then(() => {
console.log("Subscribed to all Events")
}).catch(e => {
console.log("CATCHED", e)
})
})
//Error event gets fired when an Error during connecting or an Error during Processing of an Event happens
ts3.on("error", e => {
console.log("Error", e)
})
//Close event gets fired when the Connection to the TeamSpeak Server has been closed
//the e variable is not always set
ts3.on("close", e => {
console.log("Connection has been closed!", e)
})
You don't needJavaScript:const TeamSpeak3 = require("ts3-nodejs-library") const Promise = require("bluebird") const needednumbertopoke = 30; const message = "Hi man, you are special trust me!"; var ts3 = new TeamSpeak3({ host: "", queryport: 10011, serverport: 9987, username: "serveradmin", password: "", nickname: "r4p3.net", antispam: true, antispamtimer: 350, keepalive: true }); function pokeOnConnect(client) { Promise.all([ ts3.serverInfo() ]).then(([{virtualserver_clientsonline}]) => { // Hack :D exclude query bot const online = (virtualserver_clientsonline - 1); if(online >= needednumbertopoke && client.getCache().client_type === 0){ client.poke(message); } }) } ts3.on("clientconnect", ev => { const client = ev.client; pokeOnConnect(client); }) ts3.on("ready", () => { //This Part subscribes to all events available Promise.all([ ts3.registerEvent("server"), ts3.registerEvent("channel", 0), ts3.registerEvent("textserver"), ts3.registerEvent("textchannel"), ts3.registerEvent("textprivate") ]).then(() => { console.log("Subscribed to all Events") }).catch(e => { console.log("CATCHED", e) }) }) //Error event gets fired when an Error during connecting or an Error during Processing of an Event happens ts3.on("error", e => { console.log("Error", e) }) //Close event gets fired when the Connection to the TeamSpeak Server has been closed //the e variable is not always set ts3.on("close", e => { console.log("Connection has been closed!", e) })
Promise.all
.virtualserver_clientsonline - virtualserver_queryclientsonline
instead -1
ts3-nodejs-lib
already writed with promises. Simply use async function
with await
(look at https://github.com/Multivit4min/TS3-NodeJS-Library/blob/master/transport/TS3Query.js#L246)Im still learning node, so tnx for the feedback.You don't needPromise.all
.
Also you should to dovirtualserver_clientsonline - virtualserver_queryclientsonline
instead-1
And as i knowts3-nodejs-lib
already writed with promises. Simply useasync function
withawait
(look at https://github.com/Multivit4min/TS3-NodeJS-Library/blob/master/transport/TS3Query.js#L246)
Of course there is! Don't forgot the ts3 php framework folderThanks mates! ;-)
Is there a PHP version available as well?
<?php
require_once("libraries/TeamSpeak3/TeamSpeak3.php");
TeamSpeak3::init();
// CONFIG
// Teamspeak Server Connection
$ts3['username'] = "serveradmin";
$ts3['password'] = "password";
$ts3['ip'] = "127.0.0.1";
$ts3['qport'] = "10011";
$ts3['vport'] = "9987";
$ts3['nickname'] = "PokerMan";
$neededNumberToPoke = 30;
$message = "Hi man, you are special trust me!";
// CONFIG END
$ts3['nickname'] = urlencode($ts3['nickname']);
echo "Bot Started\n\n";
try
{
TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyServerselected", "onSelect");
$tsHandle = TeamSpeak3::factory("serverquery://{$ts3['username']}:{$ts3['password']}@{$ts3['ip']}:{$ts3['qport']}/?server_port={$ts3['vport']}&timeout=5&blocking=0&nickname={$ts3['nickname']}");
while(1) $tsHandle->getAdapter()->wait();
}
catch(Exception $e)
{
die("[ERROR] " . $e->getMessage() . "\n");
}
function onTimeout($seconds, TeamSpeak3_Adapter_ServerQuery $adapter)
{
if($adapter->getQueryLastTimestamp() < time()-250)
{
$adapter->request("clientupdate");
}
}
function onSelect(TeamSpeak3_Node_Host $host)
{
TeamSpeak3_Helper_Signal::getInstance()->subscribe("serverqueryWaitTimeout", "onTimeout");
TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyCliententerview", "onClientEnter");
$host->serverGetSelected()->notifyRegister("server");
echo "Connected to: " . $host->serverGetSelected()->getProperty("virtualserver_name") . "\n\n";
}
function onClientEnter(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3_Node_Host $host)
{
try {
global $neededNumberToPoke, $message;
$count = $host->serverGetSelected()->getProperty("virtualserver_clientsonline") - $host->serverGetSelected()->getProperty("virtualserver_queryclientsonline");
$client = $host->serverGetSelected()->clientGetById($event["clid"]);
if ($count >= $neededNumberToPoke && $client['client_type'] == 0) {
$client->poke($message);
}
} catch(TeamSpeak3_Exception $e) {
echo "Error ".$e->getCode().": ".$e->getMessage();
}
}
?>