[Script] Create Your own commands with php

hASVAN

Active Member
Jun 7, 2015
76
40
93
PHP:
<?php
require_once("TeamSpeak3/TeamSpeak3.php");

//--------INFO------------//
$login_name = 'serveradmin';
$login_password ='';
$ip = '127.0.0.1';
$query_port = '10011';
$virtualserver_port = '9987';
$bot_name = 'TS3hASVANBot';
$ts3helpchannel = "94";
//--------INFO------------//

$ts3_VirtualServer = TeamSpeak3::factory("serverquery://".$login_name.":".$login_password."@".$ip.":".$query_port."/?server_port=".$virtualserver_port."&nickname=TEST&blocking=0");

$ts3botid = $ts3_VirtualServer->whoamiGet('client_id');
$ts3_VirtualServer->clientMove($ts3botid, $ts3helpchannel);

$arr_ClientList = $ts3_VirtualServer->clientList(array("client_platform" => "ServerQuery"));

foreach($arr_ClientList as $ts3_Client)
{
    if($ts3_Client['client_nickname'] == $bot_name)
    {
        $ts3_VirtualServer->request("quit");
        exit;
    }
}
$ts3_VirtualServer->selfUpdate(array("client_nickname" => $bot_name));

TeamSpeak3_Helper_Signal::getInstance()->subscribe("serverqueryWaitTimeout", "onWaitTimeout");
TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyTextmessage", "onTextMessage");

$ts3_VirtualServer->notifyRegister("server");
$ts3_VirtualServer->notifyRegister("channel");
$ts3_VirtualServer->notifyRegister("textserver");
$ts3_VirtualServer->notifyRegister("textchannel");
$ts3_VirtualServer->notifyRegister("textprivate");


while(1)
{
    $ts3_VirtualServer->getAdapter()->wait();
}

function onWaitTimeout($time, TeamSpeak3_Adapter_Abstract $adapter)
{
    if($adapter->getQueryLastTimestamp() < time()-300)
    {
        $adapter->request('clientupdate');
    }
}

function onTextMessage(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3_Node_Host $host) {

    $info = $event->getData();
    $srv = $host->serverGetSelected();
    if($info["targetmode"] == 2)
    {
          $mystring = $info["msg"];
          $pos1 = strpos($mystring, " ");
          if($pos1 > 0){
          $var = substr($mystring, 0, $pos1);
          }else{
          $var = $mystring;
          }      
          if($var == "!say"){          
            $srv->message("".str_replace('!say ', '', "[b][color=green]".$info["msg"]."[/color][/b]")."");                
          }elseif($var == "!kick"){
            $client = str_replace('!kick ', '', $info["msg"]);
            foreach($srv->clientList() as $ts3_Client)
            {
                  if($client == $ts3_Client)
                  {
                     $srv->clientGetByName("".$client."")->kick(TeamSpeak3::KICK_SERVER, "");
                  }else{
                    $srv->clientGetByName($info["invokername"]->toString())->message("User Not found");
                  }
            }                    
          }else{
             $srv->clientGetByName($info["invokername"]->toString())->message("Command Not found");
          }
    }
            
    


}
?>
Example:
3jTJtDU.png
 
Last edited:

Agusanz

Active Member
Jul 18, 2015
239
148
88
well done.. some people were asking how to do this, you can find it on the main page of the framework..
aaaaaaaaaaaaaaaand learn php.
 

hASVAN

Active Member
Jun 7, 2015
76
40
93
if you need any help with the script or you want to code any kind of script like that send me message
 

decon20

Member
Mar 27, 2016
32
5
43
It's possible edit this to someone who wish, say !create, and the bot create a permanent channel + 3 sub-channels?
 

Agusanz

Active Member
Jul 18, 2015
239
148
88
It's possible edit this to someone who wish, say !create, and the bot create a permanent channel + 3 sub-channels?
everything is possible :rolleyes:..
There's an example for that on the main site of the framework as well
 

decon20

Member
Mar 27, 2016
32
5
43
@hASVAN , thanks for your quickly answer :) Can you do something like, user says !create and the bot create a permanent channel with 2 or 3 sub-channels? I don't know if is possible, edit the code to create on permanent zone (choosed by me), and gave admin channel to the person who creates.. Thanks a lote for your help :p
 

hASVAN

Active Member
Jun 7, 2015
76
40
93
@hASVAN , thanks for your quickly answer :) Can you do something like, user says !create and the bot create a permanent channel with 2 or 3 sub-channels? I don't know if is possible, edit the code to create on permanent zone (choosed by me), and gave admin channel to the person who creates.. Thanks a lote for your help :p
have fun :D
PHP:
<?php
require_once("TeamSpeak3/TeamSpeak3.php");

//--------INFO------------//
$login_name = 'serveradmin';
$login_password ='';
$ip = '127.0.0.1';
$query_port = '10011';
$virtualserver_port = '9987';
$bot_name = 'TS3hASVANBot';
$ts3helpchannel = "94";
//--------INFO------------//

$ts3_VirtualServer = TeamSpeak3::factory("serverquery://".$login_name.":".$login_password."@".$ip.":".$query_port."/?server_port=".$virtualserver_port."&nickname=TEST&blocking=0");

$ts3botid = $ts3_VirtualServer->whoamiGet('client_id');
$ts3_VirtualServer->clientMove($ts3botid, $ts3helpchannel);

$arr_ClientList = $ts3_VirtualServer->clientList(array("client_platform" => "ServerQuery"));

foreach($arr_ClientList as $ts3_Client)
{
    if($ts3_Client['client_nickname'] == $bot_name)
    {
        $ts3_VirtualServer->request("quit");
        exit;
    }
}
$ts3_VirtualServer->selfUpdate(array("client_nickname" => $bot_name));

TeamSpeak3_Helper_Signal::getInstance()->subscribe("serverqueryWaitTimeout", "onWaitTimeout");
TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyTextmessage", "onTextMessage");

$ts3_VirtualServer->notifyRegister("server");
$ts3_VirtualServer->notifyRegister("channel");
$ts3_VirtualServer->notifyRegister("textserver");
$ts3_VirtualServer->notifyRegister("textchannel");
$ts3_VirtualServer->notifyRegister("textprivate");


while(1)
{
    $ts3_VirtualServer->getAdapter()->wait();
}

function onWaitTimeout($time, TeamSpeak3_Adapter_Abstract $adapter)
{
    if($adapter->getQueryLastTimestamp() < time()-300)
    {
        $adapter->request('clientupdate');
    }
}

function onTextMessage(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3_Node_Host $host) {

    $info = $event->getData();
    $srv = $host->serverGetSelected();
    // Channel Admin group ID goes here:
    $channel_admin_group = 5;
    if($info["targetmode"] == 2)
    {
          $mystring = $info["msg"];
          $pos1 = strpos($mystring, " ");
          if($pos1 > 0){
          $var = substr($mystring, 0, $pos1);
          }else{
          $var = $mystring;
          }  
          if($var == "!create"){
      
            $cid = $srv->channelCreate(array(
                                    "channel_name" => "".$info["invokername"]->toString()." Channel",
                                    "channel_topic" => "",
                                    "channel_codec" => TeamSpeak3::CODEC_SPEEX_ULTRAWIDEBAND,
                                    "channel_codec_quality" => 0x08,
                                    "channel_flag_permanent" => true,
                                    ));


                                $Onecid = $srv->channelCreate(array(
                                    "channel_name" => "Channel 1",
                                    "channel_topic" => "Channel 1",
                                    "channel_codec" => TeamSpeak3::CODEC_SPEEX_ULTRAWIDEBAND,
                                    "channel_codec_quality" => 0x08,
                                    "channel_flag_permanent" => true,
                                    "cpid" => $cid,                                
                                    ));

                                $Twocid = $srv->channelCreate(array(
                                    "channel_name" => "Channel 2",
                                    "channel_topic" => "Channel 2",
                                    "channel_codec" => TeamSpeak3::CODEC_SPEEX_ULTRAWIDEBAND,
                                    "channel_codec_quality" => 0x08,
                                    "channel_flag_permanent" => true,
                                    "cpid" => $cid,
                                    ));
          $srv->clientGetByName($info["invokername"]->toString())->setChannelGroup($cid, $channel_admin_group);
          foreach($srv->clientList() as $client) {
          if($info["invokername"]->toString() == $client['client_nickname']) {
          $srv->clientMove($client['clid'], $cid);
          $srv->clientGetByName($info["invokername"]->toString())->message("[b][color=green]Channel Created![/color][/b]");
          }
          }
          }else{
             $srv->clientGetByName($info["invokername"]->toString())->message("Command Not found");
          }
    }
        


}
?>
 
Last edited:

decon20

Member
Mar 27, 2016
32
5
43
have fun :D
PHP:
<?php
require_once("TeamSpeak3/TeamSpeak3.php");

//--------INFO------------//
$login_name = 'serveradmin';
$login_password ='';
$ip = '127.0.0.1';
$query_port = '10011';
$virtualserver_port = '9987';
$bot_name = 'TS3hASVANBot';
$ts3helpchannel = "94";
//--------INFO------------//

$ts3_VirtualServer = TeamSpeak3::factory("serverquery://".$login_name.":".$login_password."@".$ip.":".$query_port."/?server_port=".$virtualserver_port."&nickname=TEST&blocking=0");

$ts3botid = $ts3_VirtualServer->whoamiGet('client_id');
$ts3_VirtualServer->clientMove($ts3botid, $ts3helpchannel);

$arr_ClientList = $ts3_VirtualServer->clientList(array("client_platform" => "ServerQuery"));

foreach($arr_ClientList as $ts3_Client)
{
    if($ts3_Client['client_nickname'] == $bot_name)
    {
        $ts3_VirtualServer->request("quit");
        exit;
    }
}
$ts3_VirtualServer->selfUpdate(array("client_nickname" => $bot_name));

TeamSpeak3_Helper_Signal::getInstance()->subscribe("serverqueryWaitTimeout", "onWaitTimeout");
TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyTextmessage", "onTextMessage");

$ts3_VirtualServer->notifyRegister("server");
$ts3_VirtualServer->notifyRegister("channel");
$ts3_VirtualServer->notifyRegister("textserver");
$ts3_VirtualServer->notifyRegister("textchannel");
$ts3_VirtualServer->notifyRegister("textprivate");


while(1)
{
    $ts3_VirtualServer->getAdapter()->wait();
}

function onWaitTimeout($time, TeamSpeak3_Adapter_Abstract $adapter)
{
    if($adapter->getQueryLastTimestamp() < time()-300)
    {
        $adapter->request('clientupdate');
    }
}

function onTextMessage(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3_Node_Host $host) {

    $info = $event->getData();
    $srv = $host->serverGetSelected();
    // Channel Admin group ID goes here:
    $channel_admin_group = 5;
    if($info["targetmode"] == 2)
    {
          $mystring = $info["msg"];
          $pos1 = strpos($mystring, " ");
          if($pos1 > 0){
          $var = substr($mystring, 0, $pos1);
          }else{
          $var = $mystring;
          } 
          if($var == "!create"){
     
            $cid = $srv->channelCreate(array(
                                    "channel_name" => "".$info["invokername"]->toString()." Channel",
                                    "channel_topic" => "",
                                    "channel_codec" => TeamSpeak3::CODEC_SPEEX_ULTRAWIDEBAND,
                                    "channel_codec_quality" => 0x08,
                                    "channel_flag_permanent" => true,
                                    ));


                                $Onecid = $srv->channelCreate(array(
                                    "channel_name" => "Channel 1",
                                    "channel_topic" => "Channel 1",
                                    "channel_codec" => TeamSpeak3::CODEC_SPEEX_ULTRAWIDEBAND,
                                    "channel_codec_quality" => 0x08,
                                    "channel_flag_permanent" => true,
                                    "cpid" => $cid,                               
                                    ));

                                $Twocid = $srv->channelCreate(array(
                                    "channel_name" => "Channel 2",
                                    "channel_topic" => "Channel 2",
                                    "channel_codec" => TeamSpeak3::CODEC_SPEEX_ULTRAWIDEBAND,
                                    "channel_codec_quality" => 0x08,
                                    "channel_flag_permanent" => true,
                                    "cpid" => $cid,
                                    ));
          $srv->clientGetByName($info["invokername"]->toString())->setChannelGroup($cid, $channel_admin_group);
          foreach($srv->clientList() as $client) {
          if($info["invokername"]->toString() == $client['client_nickname']) {
          $srv->clientMove($client['clid'], $cid);
          $srv->clientGetByName($info["invokername"]->toString())->message("[b][color=green]Channel Created![/color][/b]");
          }
          }
          }else{
             $srv->clientGetByName($info["invokername"]->toString())->message("Command Not found");
          }
    }
       


}
?>


Hi, thanks for your work, but it doesn't work. :p
 

hASVAN

Active Member
Jun 7, 2015
76
40
93
What? O.O Your'e original code of the bot, works fine.. I have more php bots working on my server.. So, I have php in my server...
for me its working i can give you my server to test it
 
Top