Teamspeak 3 IRC Bot

By Aucun50 on Aug 16, 2010

This is a teamspeak irc bot, it will connect to your teamspeak 3 server and reply inforamtion back to a channel in irc like, when a user join, a user quits, list a clients and a list of channels. I might be adding more commands like, ban, kick, poke, message and a few more. If you want a command added just let me know.

Please read this before you try and connect your teamspeak bot with your teamspeak server, this bot will not take any information from your teamspeak server that could open it for attack.

Open your teamspeak and be a Server Admin. When you have Server Admin rights click "Tools" then "ServerQuery Login", type in a username and click "Ok". Now you have a username and a password on the sceen, the username need to replace the username in the client_login alias. Say your username is "Tsbot", your alias should look like "alias client_login return Tsbot" without the quotes. Do the same for your client_password. Make sure you also replace your ts_network alias with your teamspeak address or ip.

Now you need to find your Server Query port, this port for most teamspeaks will be 51234 but it may not be for your teamspeak, like mine is 10011. When you get the port replace your query_port with the right query port for your server.

Now comes the tricky part, giving your bot who is connecting to the server via the Server Query port Server Query Admin rights, or enough to do some simple commands like "serverlist", "clientlist" and "channellist". If you don't know how to do this please view this:

http://www.youtube.com/watch?v=4i_bOWe-MMs

If you don't want to download the program he is using in the video you can do it without by first opening your teamspeak, clicking on "Tools" then Server Query. At this point you will need to know the client id of your bot, run the bot with all the inforamtion below filled out right and your bot will connect but not do anything. Now go to "Primissions" and "List all clients", look for your bot client, it should be something like "Client login from Ip" or just "Client Login". Look at the database id and remember it, now back to the Server Query window, type in the left upper box the following.

login serveradmin password
use sid=1
servergroupaddclient sgid=2 cldbid=Client ID

I hope you remember your serveradmin password from when you first started your teamspeak as it told you to write it down someplace or remember it, if you don't not much you can do without it :(

Replace the password with your severadmin password and client ID with your bots client ID, if your not sure of the client ID DO NOT guess, if you guess most likely some random person will get a Red "S" like Server Admin but Admin Server Query and if they know how to use it... Your server WILL be at risk.

After setting your bot to Admin Server Query you can now run it without any problems.. hopefully. Type !ts_start in the channel with your bot.

alias ts_network { return Server }
alias query_port { return 10011 }
alias ts_channel { return #Channel }
alias client_login { return User }
alias client_password { return Password }

alias msg_style { return $+(5[4,$1-,5]) }

on *:exit: { 
  .remove ts3_clients.txt 
  if ($exists(ts3_clients_temp.txt)) { .remove ts3_clients_temp.txt }
}

on $*:text:/[!@`~](tsinfo|users|channels|ts_start)/Si:#: {
  if ($regml(1) == tsinfo) { $iif($sock(ts3),sockwrite -n ts3 serverlist,msg $chan $msg_style(Error) Not Connected) }
  else if ($regml(1) == users) { $iif($sock(ts3),sockwrite -n ts3 clientlist,msg $chan $msg_style(Error) Not Connected) }
  else if ($regml(1) == channels) { $iif($sock(ts3),sockwrite -n ts3 channellist,msg $chan $msg_style(Error) Not Connected) }
  else if ($regml(1) == ts_start) { ts }
}

alias ts {
  if ($sock(ts3)) { sockclose ts3 } 
  if ($exists(ts3_clients_temp.txt)) { .remove ts3_clients_temp.txt }
  .remove ts3_clients.txt
  sockopen ts3 $ts_network $query_port
  sockmark ts3 $ts_channel
}

alias checkclients {
  if ($sock(ts3)) {
    set %checking_clients yes 
    sockwrite -n ts3 clientlist
    .timerclients 1 3 checkclients
  }
  else { ts #Hangout }
}

on *:sockopen:ts3: {
  if ($sockerr) { echo -s Socket Error }
  else {
    sockwrite -n ts3 login client_login_name= $+ $client_login client_login_password= $+ $client_password
    sockwrite -n ts3 use sid=1
    checkclients
  }
}

on *:sockread:ts3: {
  var %read | sockread %read 
  ;echo -s %read
  if (virtualserver_id isin %read) {
    var %clients = $replace($gettok(%read,4,32),virtualserver_clientsonline,Clients Online:,=,$chr(32))
    var %status = $replace($gettok(%read,3,32),virtualserver_status,Status:,=,$chr(32))
    var %uptime = $remove($gettok(%read,7,32),virtualserver_uptime=)
    msg $sock(ts3).mark $msg_style(Server Information) %clients %status $+(Server Uptime:,$chr(32),$duration(%uptime))
  }
  else if (client_nickname isin %read) {
    if (!%checking_clients) {
      msg $gettok($sock(ts3).mark,1,32) $msg_style(Searching) Please Wait...
      var %tokens = 1 
      while (%tokens <= $numtok(%read,32)) {
        if (client_database_id isin $gettok(%read,%tokens,32)) { 
          if (\sfrom\s !isin $gettok(%read,$calc(%tokens + 1),32)) {
            msg $gettok($sock(ts3).mark,1,32) $msg_style(User) $+(,$replace($remove($gettok(%read,$calc(%tokens + 1),32),client_nickname=),\s,$chr(32)),) ID $+  $remove($gettok(%read,%tokens,32),client_database_id=)
          }
        }
        inc %tokens
      }
    }
    else {
      var %tokens = 1 
      while (%tokens <= $numtok(%read,32)) {
        if (client_database_id isin $gettok(%read,%tokens,32)) {     
          if ($exists(ts3_clients.txt)) { write ts3_clients_temp.txt $replace($remove($gettok(%read,$calc(%tokens + 1),32),client_nickname=),\s,$chr(32)) ID $remove($gettok(%read,%tokens,32),client_database_id=) }
          else { write ts3_clients.txt $replace($remove($gettok(%read,$calc(%tokens + 1),32),client_nickname=),\s,$chr(32)) ID $remove($gettok(%read,%tokens,32),client_database_id=) | halt }
        }
        inc %tokens
      }
      var %line = 1
      while (%line <= $lines(ts3_clients_temp.txt)) {
        if (!$read(ts3_clients.txt,w,$read(ts3_clients_temp.txt,%line))) { 
          msg $sock(ts3).mark $msg_style(User Connected) $read(ts3_clients_temp.txt,%line)
        }
        inc %line
      }
      var %line = 1
      while (%line <= $lines(ts3_clients.txt)) {
        if (!$read(ts3_clients_temp.txt,w,$read(ts3_clients.txt,%line))) {
          msg $sock(ts3).mark $msg_style(User Disconnected) $read(ts3_clients.txt,%line)
        }
        inc %line
      }
      .remove ts3_clients.txt
      .rename ts3_clients_temp.txt ts3_clients.txt
      unset %checking_clients
    }
  }
  else if (channel_name isin %read) {
    msg $gettok($sock(ts3).mark,1,32) $msg_style(Searching) Please Wait...
    var %tokens = 1
    while (%tokens <= $numtok(%read,32)) {
      if (channel_name isin $gettok(%read,%tokens,32)) {
        msg $gettok($sock(ts3).mark,1,32) $msg_style(Channel) $+(,$replace($remove($gettok(%read,%tokens,32),channel_name=),\s,$chr(32)),) Clients  $+ $remove($gettok(%read,$calc(%tokens + 1),32),total_clients=)
      }
      inc %tokens
    }
  }
}

Comments

Sign in to comment.
Saadi490   -  Dec 16, 2012

Please update this. I really need it :(

 Respond  
Aucun50   -  Aug 12, 2012

This probably isn't working any more :/ I never updated it, I could if anyone till uses it.

 Respond  
Bekir   -  Aug 12, 2012

nice

 Respond  
Gummo   -  Aug 19, 2010

Using an identifier as generic as $msg_style is likely to cause problems.
Edit: It doesn't describe its function, either, where style_msg would be more appropriate. :s

 Respond  
Aucun50   -  Aug 19, 2010

It's not that you have to be server admin it's that the connection to the server query that has to be Admin Server Query, you could make another class called "IRC Server Query" and give it permission for "Serverlist", "Channellist" and "Clientlist". That would allow the bot to run fine.

 Respond  
cutiechan   -  Aug 18, 2010

Apparently not...You have to be a server admin. Is there anyway you dont have to be a server admin to do this....

 Respond  
Aucun50   -  Aug 18, 2010

Did you take the time to even read the description? It IS for other teamspeak servers, why would I post something that ISN'T for other servers then take all the time to write that description on how to setup the script?

If you read the description it's not all that hard to setup, if you need any help with it just tell me and I'l be happy to help you.

 Respond  
cutiechan   -  Aug 17, 2010

This is just for YOUR own team speak sever.

It would be nice if you made a script that would feed information for a TS3 sever that is not own by you.

 Respond  
Jethro   -  Aug 17, 2010

Yeah WorldDMT, I thought about using the $replace identifier, but I was keeping it basic to simulate what Auncun50 has used with if statements.

 Respond  
WorldDMT   -  Aug 17, 2010

can be also

on $*:text:/[!@`~](tsinfo|users|channels|ts_start)/Si:#: {
  if ($regml(1) == ts_start) ts
  else $iif($sock(ts3),sockwrite -n ts3 $replace($regml(1),tsinfo,serverlist,users,clientlist,channels,channellist),msg # $msg_style(Error) Not Connected)
}
 Respond  
Aucun50   -  Aug 17, 2010

Not all the commands use serverlist, only !tsinfo, the others use clientlist and channellist. Thanks, it took a while to get the commands list and find out how to set the right primissions for the bot :)

 Respond  
Jethro   -  Aug 17, 2010

Nice effort you've put into this script. As for the regex part, you could do:

on $*:text:/^[!@`~](tsinfo|users|channels|ts_start)$/Si:#: {
  var %e = $iif($sock(ts3),sockwrite -n ts3 serverlist,msg $chan $msg_style(Error) Not Connected)
  if ($regml(1) == tsinfo) { %e }
  else if ($regml(1) == users) { %e }
  else if ($regml(1) == channels) { %e }
  else { ts }
}

You already specified the three matches, the last one has to be ts_start. So there was no need for another elseif statement but an else condition. Also, make sure your regex starts with the command symbols and ends exactly as the matched trigger strings.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.