BotAdmin - Auto AFK move - Auto kick at Server Full

Agusanz

Active Member
Jul 18, 2015
239
148
88
Hey guys..
I use this script with a crontab each 20 seconds: https://github.com/Agusanz/BotAdmin
It moves automatically people that are AFK for X time (30 mins example).. Also if you dont have tons of slots on your server, you may want to optimize that, so basically it keeps people afk inside till there's no more room, so it kick 1, and so on..
Example, theres 27/32 ppl on my server, kick feature isn't working, but when there's 32/32, bot will automatically kick someone who has been afk for x amount of time.

Remember to edit this script to fit your needs, you need to change the timezone, username, password, ip, AFKChannel ID, default times are 30 mins (1800 secs) AFK before it moves you to the AFKChannel, and 1hours (3600 secs) before it kick you when the server is full.
It auto-detects the amount of slots you have, (public available ones, if you have reserved slots those doesnt count.)
You can also change the Poke afk message and kick afk message.

PHP:
<?php
//Agusanz.com
require_once("libraries/TeamSpeak3/TeamSpeak3.php");
date_default_timezone_set('America/Argentina/Buenos_Aires'); //Change to your timezone. URL: https://secure.php.net/manual/en/timezones.php
TeamSpeak3::init();

//////////Config//////////
$user = ""; //Login user
$pass = ""; //Login password
$serverIP = "127.0.0.1"; //Server IP
$nickname = "BotAdmin"; //Bot Nickname
$BotChannelAFK = 1; //Channel where people will be moved to.
$TimeAFK = 1800; //Time that people will be allowed to stay afk until bot moves him/her. Use seconds.
$TimeKick = 3600; //Time that people will be allowed to stay afk until bot kick him/her when server is full. Use seconds.
//////////Config//////////

try
{
   $ts3 = TeamSpeak3::factory("serverquery://{$user}:{$pass}@{$serverIP}:10011/?server_port=9987&blocking=0&nickname={$nickname}"); //If you want to run this on another Query port or Voice port, change that here, otherwise leave it as it is.
   $statusKick = 0;
   $unixTime = time();
   $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
   echo $realTime."\t[INFO] Connected\n"; //Log
   foreach($ts3->clientList() as $client)
   {
       if($client["client_type"]) continue; //Ignore query clients
       //AFK
       if($client["client_idle_time"]/1000 > $TimeAFK)
       {
           if($client["client_channel_group_inherited_channel_id"] != $BotChannelAFK) //Skip people already in the AFK Channel.
           {
               $unixTime = time();
               $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
               $client->move($BotChannelAFK);
               $client->poke("Moved to AFK Channel because you has been AFK for too long."); //Poke message.
               echo $realTime."\t[AFK IDLE] ".$client["client_nickname"]." UID: ".$client["client_unique_identifier"]." IDLE: ".$client["client_idle_time"]/1000 ."\n"; //Log
           }
           else
           {
               echo $realTime."\t[AFK Already] ".$client["client_nickname"]." UID: ".$client["client_unique_identifier"]." IDLE: ".$client["client_idle_time"]/1000 ."\n"; //Log
           }
       }
       //AFK
       //AUTOKICK
       $unixTime = time();
       $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
       $serverInfo = $ts3->getInfo();
       $maxClients = $serverInfo["virtualserver_maxclients"];
       $clientsOnline = $serverInfo["virtualserver_clientsonline"];
       $slotsReserved = $serverInfo["virtualserver_reserved_slots"];
       $slotsAvailable = $maxClients - $slotsReserved;
       $slotsNow = $slotsAvailable - $clientsOnline;
       if($slotsNow < 1) //Check how many slots are available in the server, if it's less than 1, kick mode turns on.
       {
           $statusKick = 1;
           if(($client["client_channel_group_inherited_channel_id"] == $BotChannelAFK) && ($client["client_idle_time"]/1000 > $TimeKick)) //Bot kick people in the AFK channel only.
           {
               $client->kick(TeamSpeak3::KICK_SERVER, "Server is full and you has been AFK for too long."); //Kick message.
               echo $realTime."\t[KICK] ".$client["client_nickname"]." UID: ".$client["client_unique_identifier"]." IDLE: ".$client["client_idle_time"]/1000 ."\n"; //Log
           }
       }
       //AUTOKICK
   }
   $unixTime = time();
   $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
   if($statusKick == 0)
   {
       echo $realTime."\t[KICK] Disabled. Slots: ".$clientsOnline."/".$slotsAvailable." Remaining: ".$slotsNow."\n"; //Log
   }
   else
   {
       echo $realTime."\t[KICK] Enabled. Slots: ".$clientsOnline."/".$slotsAvailable." Remaining: ".$slotsNow."\n"; //Log
   }
   die($realTime."\t[INFO] Finished.\n"); //Log
}
catch(Exception $e)
{
   $unixTime = time();
   $realTime = date('[Y-m-d] [H:i:s]',$unixTime);
   echo "Failed\n"; //Log
   die($realTime."\t[ERROR]  " . $e->getMessage() . "\n". $e->getTraceAsString() ."\n"); //Log
}
//Agusanz.com



If you want to setup a crontab type this:
Step 1:
Code:
crontab -e
Step 2: write this and save it. Remember to change this path since this is mine, yours WILL BE different.
Code:
*/1 * * * * php /home/agusanz/TSBots/BotAdmin/BotAdmin.php > /dev/null
*/1 * * * * sleep 20; php /home/agusanz/TSBots/BotAdmin/BotAdmin.php > /dev/null
*/1 * * * * sleep 40; php /home/agusanz/TSBots/BotAdmin/BotAdmin.php > /dev/null


//Not included this bot//
I have an advance version of this bot where it have a whitelist (Admins, mods, bots and VIP are ignored)
it gives a warning to people with a disabled mic and it remove pm/poke permissions to avoid someone spamming your server. (I know it doesnt solve the problem, but at least it's something..)
Also people with a disabled mic gets moved to the AFK channel.
Those kinds of modifications are very specific for each server, so i release this version that it's way more friendly than mine.
//Not included this bot//

Enjoy..
-Agusanz
 
Last edited:

0x0539

Retired Staff
Contributor
Jan 30, 2016
1,334
1,146
254
Could definitely use this on R4P3 teamspeak instead of kicking manually when full.
 

Alexis10

New Member
Jun 19, 2018
1
0
3
Hello, i wanted to use your script but i can't save it and i don't know what to do after, can you explain how to install it please?
 
Top