TeamSpeak 3 Interaction Script v1.4

By Mi9 on Oct 31, 2016

Originally by prulez, edited by dronez4, re-edited by Mi9

v1.2 http://hawkee.com/snippet/7325/ By Prulez
v1.3 http://hawkee.com/snippet/10107/ By dronez4
v1.4 http://hawkee.com/snippet/17536/ By Mi9

Some changes and improvements - by Mi9 - v1.4 (2016.10)

  • Settings Panel
    • has been rearranged to look better on Windows 10;
    • some operational improvements.
  • Help module was completed with new commands and reorganized.
  • Added commands (working only on admin channel):
    • (VOICE/HOP/OP) !TS Hostinfo
    • (HOP/OP) !TS Banlist, Bandel, Bandelall.
  • Added Debug module (ON/OFF from Settings Panel or CRTL+F9)
  • !TS Connect, moved to admin channel
  • Removed
    • !TS ID, IP commands and other lines of code.

Download: TeamSpeak 3 Interaction Script v1.4

;a~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;         TeamSpeak 3 Interaction Script v1.4 (2016.10)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Originally by prulez, edited by dronez4, re-edited by Mi9
; v1.2 http://hawkee.com/snippet/7325/      By Prulez
; v1.3 http://hawkee.com/snippet/10107/     By dronez4
; v1.4 http://hawkee.com/snippet/17536/     By Mi9
;                                         ~~~~~~~~~^~~~~~~~~~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Some changes and improvements - by Mi9 - v1.4 (2016.10)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; - Settings Panel
;   * has been rearranged to look better on Windows 10;
;   * some operational improvements.
; - Help module was completed with new commands and reorganized.
; - Added commands (working only on admin channel):
;   * (VOICE/HOP/OP) !TS Hostinfo
;   * (HOP/OP) !TS Banlist, Bandel, Bandelall.
; - Added Debug module (ON/OFF from Settings Panel or CRTL+F9)
; - !TS Connect, moved to admin channel
; - Removed
;   * !TS ID, IP commands and other lines of code.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;
;================================
;===== on LOAD & START event

alias ts-sversion { set %ts.sversion 1.4 modified by Mi9 (2016.10) }
on *:LOAD: { ts3setup | ts-sversion
  echo -a TeamSpeak 3 Interaction v $+ %ts.sversion has been loaded!
}

on *:START: {
  if (%ts.sversion == $null) ts-sversion
  echo -a ::: 7TeamSpeak 3 Interaction9 v $+ %ts.sversion is loaded! :::
  if ($group(#ts3-sdebug).status == on) .disable #ts3-sdebug
}

;================================
;===== Menu & Settings Dialog

menu menubar,channel,status,query,nicklist,statusbar,@TS3-sDebug { 
  TS3 Interaction
  .Settings Panel:/ts3setup
  .-
  ;.Readme://run $scriptdir $+ ts3readme.txt
  .-
  .Display Server Info:/ts3info %ts.channels
  .Display Users:/ts3users %ts.channels
  .Display Channels:/ts3channels %ts.channels
  .-
  .Kick Client:/ts3kick $$input(What is the nickname of the client you want to kick?, e) $+ ; $+ $$input(What is the reason you want to kick this user?, e) $+ ; $+ $me $+ ; $+ %ts.channels
  .Ban Client:/ts3ban $$input(What is the nickname of the client you want to ban?, e) $+ ; $+ $$input(What is the reason you want to ban this user?, e) $+ ; $+ $me $+ ; $+ %ts.channels
  .-
  .Message Server:/ts3msg $me $+ ; $+ $$input(What's the message that you want to send?, e)
  .PM Client:/ts3pm $$input(What is the nickname of the client you want to PM?, e) $+ ; $+ $$input(What's the message that you want to send?, e) $+ ; $+ $me $+ ; $+ %ts.channels
  .Poke Client:ts3poke $$input(What is the nickname of the client you want to Poke?, e) $+ ; $+ $$input(What's the message that you want to send?, e) $+ ; $+ $me $+ ; $+ %ts.channels
  .-
  .Advertise Script:/ts3version %ts.channels
}

dialog ts3setup {
  ;MAIN DIALOG INFO
  title TS3 Interaction Settings - Version %ts.sversion
  size -1 -1 200 260
  option dbu

  ;MAIN BOXES
  box "Channels", 1, 1 1 99 116 
  box "Server Info", 2, 101 1 98 116
  box "Timeout", 3, 1 118 99 52
  box "Login Info", 4, 101 118 98 52

  ;CHANNELS
  edit "#", 5, 4 9 70 10, default
  button "Add", 6, 77 9 20 10, disable
  list 7, 4 21 93 89
  button "Delete Channel", 8, 3 105 95 10, disable

  ;SERVER INFO
  box "Server IP", 9, 103 8 94 20
  edit %ts.ip, 10, 105 16 90 10,%ts.ip
  box "Query Port", 11, 103 28 94 20
  edit %ts.qport, 12, 105 36 90 10,%ts.qport
  box "Public IP", 13, 103 49 94 32
  edit %ts.ip.public, 14, 105 57 90 10,%ts.ip.public
  text "The IP clients have to enter in the TS3 client to connect to the server.", 15, 107 67 90 15
  box "Server Port", 16, 103 82 94 32
  edit %ts.sport, 17, 105 90 90 10, %ts.sport
  text "The port clients have to enter in the TS3 client to connect to the server.", 18, 107 100 90 15

  ;TIMEOUT
  edit %ts.timeout, 19, 4 127 93 10,%ts.timeout
  text "The amount of seconds before the script assumes the server has timed out when it has stopped responding.", 20, 5 140 90 20

  ;LOGIN INFO
  box "Username", 21, 103 126 94 20
  edit %ts.slogin, 22, 105 134 90 10, %ts.slogin
  box "Password", 23, 103 147 94 20
  edit %ts.spass, 24, 105 155 90 10, %ts.spass

  ;ADMIN CHANNEL
  box "Admin Channel", 31, 1 171 99 33
  edit "", 28, 4 179 93 10
  button "Add channel", 27, 3 192 95 10

  ;TSLog DIRECTORY
  box "TSLog Directory", 33, 1 205 99 33
  edit "", 30, 4 213 93 10
  button "Add directory", 29, 3 226 95 10

  ;SCRIPT DEBUG
  box "Script Debug", 34, 101 171 98 33
  radio "ON", 35, 105 180 15 10
  radio "OFF", 36, 105 190 18 10
  text "Activate this function only if you need to troubleshoot this script.", 37, 135 179 62 27

  ;OK & CANCEL BUTTONS
  button "Save and Exit", 25, 60 243 40 10, ok
  button "Cancel", 26, 101 243 30 10, cancel
}

on *:DIALOG:ts3setup:*:*: {
  if ($devent == sclick) {
    if ($did == 29) {
      if ($did(30) != $null) { set %ts.directory $did(30) }
      else { did -r ts3setup 30 | did -a ts3setup 30 Fill this in. }
    }
    if ($did == 27) {
      if ($did(28) != $null) { set %ts.admin $did(28) }
      else { did -r ts3setup 28 | did -a ts3setup 28 Fill this in. }
    }
    if ($did == 6) { did -a ts3setup 7 $did(ts3setup,5) | did -ra ts3setup 5 [ $chr(35) ] }
    if ($did(ts3setup,7).seltext != $null) { did -e ts3setup 8
      if ($did == 8) { did -d ts3setup 7 $did(ts3setup,7).sel }
    }
    if ($did == 25) { set %ts.channels $didtok(ts3setup,7,44) }
    if ($did == 35 || $did == 36) { ts-debug } 
  }
  if ($devent == edit) {
    if ($did(5) != $null && $left($did(5),1) == $chr(35) && $len($did(5)) > 1) { did -e ts3setup 6 }
    else { did -i ts3setup 5 1 $chr(35) | did -a ts3setup 5 | did -b ts3setup 6 }
  }
  if ($devent == init) {
    did -a ts3setup 5
    did -a ts3setup 28 %ts.admin
    did -a ts3setup 30 %ts.directory
    if ($group(#ts3-sdebug).status == on) did -c ts3setup 35 | else did -c ts3setup 36
    didtok ts3setup 7 44 %ts.channels
  }
}

;==========================
;====== Aliases

alias ts-debug {
  if $group(#ts3-sdebug).status == on { .disable #ts3-sdebug | var %cgr 4 } 
  else { .enable #ts3-sdebug | var %cgr 3 } 
  echo  $+ %cgr $+ :.: TS3 Script Debug is $upper($group(#ts3-sdebug).status)
}
alias CF9 ts-debug

alias ts3setup { dialog -m ts3setup ts3setup }

; ***Converting HTML output to readable output***
alias htmlconv {
  var %t, %u = $regsub($replace($1,<br>,$crlf),/^[^<]*>|<[^>]*>|<[^>]*$/g,,%t)
  if (!$regex(%t,/&\S+?;/)) return %t
  if ($prop == rem) { !.echo -q $regsub(%t,/&\S+?;/g,,%t) | return %t }
  %t = $replace(%t,&nbsp;,$chr(160),&quot;,",&lt;,<,&gt;,>,&amp;,&,&hellip;,...,&reg;,®, $&
    &copy;,©,,&trade;,™,&frac14;,¼,&frac12;,½,&frac34;,¾,&sup3;,³,&sup2;,²,&deg;,°,&bull;,•, $&
    &rsaquo;,›,&lsaquo;,‹,&raquo;,»,&laquo;,&rsquo;,’,&lsquo;,‘,&rdguo;,”,&ldquo;,“,&ndash;, $&
    –,&mdash;,—,&apos;,',&tilde;,~,&times;,×,&divide;,÷,&para;,¶,&ecute;,é,&Ecute;,É,&cent;, $&
    ¢,&pound;,£,&yen;,¥,&sect;,§)
  if ($version < 6.14) || (!$regex(%t,/&\S+?;/)) return %t
  var %html = html $+ $ticks, %body = body $+ $ticks
  .comopen %html htmlfile
  if ($comerr) return %t
  %t = $com(%html,write,1,bstr*,$+(<html><body>,%t,</body></html>))
  %t = $com(%html,body,2,dispatch* %body) $com(%body,innertext,2)
  %t = $com(%body).result
  :error
  if ($com(%body)) .comclose %body
  if ($com(%html)) .comclose %html
  return %t
}

; ***Connecting to the server***
alias ts.connect { sockclose ts3 | if $hget(ts3) { .hfree ts3 } | msg %ts.channels 7[TS3] Attempting to connect to the TS3 server.. | sockopen ts3 %ts.ip %ts.qport | .timertsconfail 1 15 ts.sockclose cc }

; ***Writing to the server***
alias ts3.d { if $sock(ts3) { sockwrite -n ts3 $1- } }

; ***"Translating" output from the server to normal things that's readable***
alias ts.clean { return $htmlconv($remove($replace($replace($replace($1-, \s, $chr(32)), \p, $chr(124)), \/, /),<,>,,,,,,,)) }

; ***"Translating" input (Messages) to blahblah that the TS3 server can read***
alias ts.input { return $replace($replace($1-,$chr(32),\s),$chr(124),\p) }

; ***!TS Info***
alias ts3info {
  set %ts.getclientlist 1
  set %ts.infochan $1-
  ts3.d channellist
  ts3.d clientlist -away
  ts3.d serverinfo
}

; ***!TS Hostinfo***
alias ts3hostinfo {
  set %ts.gethostinfo 1
  ts3.d hostinfo
}

; ***!TS Users***
alias ts3users {
  set %ts.getclientlist 1
  set %ts.userchan $1-
  set %ts.showclientlist 1
  ts3.d channellist
  ts3.d clientlist -away
}

; ***!TS Channels***
alias ts3channels {
  set %ts.displaychanlist 1
  set %ts.chanchan $1-
  ts3.d channellist
}

; ***!TS Msg***
alias ts3msg {
  var %nick = $gettok($1-,1,59)
  var %msg = $gettok($1-,2,59)
  var %message = $ts.input(( $+ %nick $+ @IRC) %msg)
  ts3.d gm msg= $+ %message
}

; ***!TS PM***
alias ts3pm {
  var %client = $gettok($1-,1,59)
  var %message = $gettok($1-,2,59)
  var %pmer  $gettok($1-,3,59)
  var %chan $gettok($1-,4,59)
  var %hash = $hfind(ts3,%client $+ *,1,w)
  if (!%hash) { msg %chan 7[TS3] 9[PM] 11Unable to find client. | HALT }
  else {
    var %nick = $gettok(%hash,1,59)
    var %clid = $gettok(%hash,2,59)
    var %msg = $ts.input(( $+ %pmer $+ @IRC) %message)
    ts3.d sendtextmessage targetmode=1 target= $+ %clid msg= $+ %msg
    msg %chan 7[TS3] 9[PM] 3PM sent to %nick - 11( $+ %pmer $+ @IRC) %message
  }
}

; ***!TS Poke***
alias ts3poke {
  var %client = $gettok($1-,1,59)
  var %message = $gettok($1-,2,59)
  var %poker = $gettok($1-,3,59)
  var %chan $gettok($1-,4,59)
  var %hash = $hfind(ts3,%client $+ *,1,w)
  if (!%hash) { msg %chan 7[TS3] 9[Poke] 11Unable to find client. | HALT }
  else {
    var %nick = $gettok(%hash,1,59)
    var %clid = $gettok(%hash,2,59)
    var %msg = $ts.input(( $+ %poker $+ @IRC) %message)
    ts3.d clientpoke clid= $+ %clid msg= $+ %msg
    msg %chan 7[TS3] 9[Poke] 3Poked %nick - 11Message: ( $+ %poker $+ @IRC) %message
  }
}

; ***!TS Ban***
alias ts3ban {
  var %client = $gettok($1-,1,59)
  var %reason = $gettok($1-,2,59)
  var %banner = $gettok($1-,3,59)
  var %chan = $gettok($1-,4,59)
  var %hash = $hfind(ts3,%client $+ *,1,w)
  if (!%hash) { msg $1- 7[TS3] 9[Ban] 11Unable to find client. | HALT }
  else {
    var %nick = $gettok(%hash,1,59)
    var %clid = $gettok(%hash,2,59)
    var %msg = $ts.input(( $+ %banner $+ @IRC) %reason)
    set %ts.act ban
    set %ts.banchan %chan
    ts3.d banclient clid= $+ %clid banreason= $+ %msg
    msg %ts.channels 7[TS3] 9[Ban] 3Attempting to ban %nick - 11( $+ %banner $+ @IRC) %reason
  }
}

; ***!TS Banlist***
alias ts3banlist {
  set %ts.getbanlist 1
  set %ts.act banlist
  ts3.d banlist
}

; ***!TS Bandel***
alias ts3bandel {
  if ($1 != $null && $1 isnum) {
    set %ts.bandel 1
    set %ts.banid $1
    set %ts.act bandel
    ts3.d bandel banid= $+ %ts.banid
  }
  else {
    msg $chan 7[TS3] BanID is mandatary and must be a number. | HALT
  }
}

; ***!TS Bandelall***
alias ts3bandelall {
  ts3.d bandelall
  msg %ts.admin 7[TS3] 9[Bandelall]3 $nick $+ , Removed all active ban rules from the server.
}

; ***!TS Kick***
alias ts3kick {
  var %client = $gettok($1-,1,59)
  var %message = $gettok($1-,2,59)
  var %kicker  $gettok($1-,3,59)
  var %chan $gettok($1-,4,59)
  var %hash = $hfind(ts3,%client $+ *,1,w)
  if (!%hash) { msg %chan 7[TS3] 9[Kick] 11Unable to find client. | HALT }
  else {
    var %nick = $gettok(%hash,1,59)
    var %clid = $gettok(%hash,2,59)
    var %msg = $ts.input(( $+ %kicker $+ @IRC) %message)
    set %ts.act kick
    set %ts.kickchan %chan
    if ($len(%msg) > 40) { msg %chan 7[TS3] 9[Kick] 11Kick message is too long. Limiting it to 40 characters.. | var %msg = $left(%msg,40) }
    ts3.d clientkick clid= $+ %clid reasonid=5 reasonmsg= $+ %msg
    msg %chan 7[TS3] 9[Kick] 3Attempting to kick %nick - 11( $+ %kicker $+ @IRC) %message
  }
}

; ***!TS Version***
alias ts3version {
  if (%ts.sversion == $null) ts-sversion
  msg $1- 7[TS3] 3[Author] 11This script has been made by Prulez, modified by dronez4 and re-edited by Mi9.
  msg $1- 7[TS3] 3[Script Version]11 %ts.sversion 
}

; ***Displaying the userlist when requested***
alias ts.displaylist {
  var %totalhash = $hget(ts3,0).item
  if (%totalhash == 0) {
    msg %ts.userchan 7[TS3] 9No users are currently online.
  }
  if (%totalhash != 0) {
    var %a = 1 
    while (%a <= %totalhash) {
      var %hashname = $hget(ts3, %a).item
      var %cid = $gettok($gettok($hget(ts3, %hashname),1,59),2,61)
      var %channame = $ts.clean($gettok($hget(ts3chan,%cid),1,59))
      var %away = $gettok($gettok($hget(ts3, %hashname),2,59),2,61)
      var %awaymessage = $ts.clean($gettok($gettok($hget(ts3,%hashname),3,59),2,61))
      var %clnick = $ts.clean($gettok(%hashname,1,59))
      msg %ts.userchan 7[TS3] 9[User %a $+ ] 11 $+ %clnick 3( $+ %channame $+ ) $iif(%away == 1, $iif(%awaymessage, 5(Away: %awaymessage $+ ), 5(Away)))
      inc %a 
    }
  }
  unset %ts.userchan
}

; ***Help reply***
alias ts.help {
  if ($chan == %ts.admin) var %adm.chcmd Connect, Banlist, Bandel, Bandelall, Hostinfo $+ $chr(44)
  msg $chan 7[TS3] 3TeamSpeak Commands: 9!TS %adm.chcmd Users, Channels, Kick, Ban, Msg, PM, Poke, Info, Version - 11"!TS help [command]" for more information. 
}

; ***Unknown command reply***
alias ts.unknoun { msg # 7[TS3] $1 4Unknown command. }

;============================
;==== Connecting & Commands

; ***Connects to TS when you join one of the channels (and if the socket isn't already active)***
on *:join:#:if $nick == $me && $findtok(%ts.channels,$chan,1,44) && !$sock(ts3) { ts.connect }

; ***Referring commands to aliases***
on *:TEXT:*:#: {
  ; ignores text typed anywhere except the ts channels
  if (!$findtok(%ts.channels,$chan,1,44)) { halt }

  ; command help
  if ($1 == !ts && $2 == $null || $2 == help && $3 == $null) { ts.help }
  elseif ($1 == !ts && !$findtok(connect.bandelall.hostinfo.users.info.channels.msg.pm.poke.kick.ban.banlist.bandel.version.help,$2,0,46)) { ts.unknoun $2 }
  elseif ($2 == help && $3 != $null) {
    if $3 == users { msg # 7[TS3] 9!TS Users - 11Displays information about the currently connected users. }    
    elseif $3 == info { msg # 7[TS3] 9!TS Info - 11Lists basic information about the TeamSpeak Server. }
    elseif $3 == channels { msg # 7[TS3] 9!TS Channels - 11Displays all channels and the number of users in them. }
    elseif $3 == msg { msg # 7[TS3] 9!TS Msg <message> - 11Sends a message to the server. }
    elseif $3 == pm { msg # 7[TS3] 9!TS PM <user> <message> - 11Sends a private message to an user. }
    elseif $3 == poke { msg # 7[TS3] 9!TS Poke <user> <message> - 11Pokes an user with the specified message (if any). }
    elseif $3 == kick { msg # 7[TS3] 9!TS Kick <user> <reason> - 11Kicks an user from the server. }
    elseif $3 == ban { msg # 7[TS3] 9!TS Ban <user> <reason> - 11Bans an user from the server. }
    elseif $3 == version { msg # 7[TS3] 9!TS Version - 11Displays information about the script and its author. }
    elseif ($chan == %ts.admin) {
      if $3 == connect { msg # 7[TS3] 9!TS connect - 11Connect or re-connect TS3 Script to TeamSpeak Server. }
      elseif $3 == banlist { msg # 7[TS3] 9!TS Banlist - 11Displays a list of active bans on the virtual server. }
      elseif $3 == bandel { msg # 7[TS3] 9!TS Bandel <banid> - 11Deletes the ban rule with ID banid from the server. }
      elseif $3 == bandelall { msg # 7[TS3] 9!TS Bandelall - 11Deletes all active ban rules from the server. }
      elseif $3 == hostinfo { msg # 7[TS3] 9!TS Hostinfo - 11Displays detailed connection information about the server instance including uptime, number of virtual servers online, traffic information, etc. }      
      else { ts.unknoun $3 }
    }
    else { ts.unknoun $3 }
  }
  else { if ($findtok(connect.banlist.bandel.bandelall.hostinfo,$2,0,46) && $chan != %ts.admin) ts.unknoun $2 }

  ; commands
  if ($1-2 == !ts info) { ts3info $chan }
  if ($1-2 == !ts users) { ts3users $chan }
  if ($1-2 == !ts version) { ts3version $chan }
  if ($1-2 == !ts channels) { ts3channels $chan }
  if ($1-2 == !ts msg) { ts3msg $nick $+ ; $+ $3- }
  if ($1-2 == !ts poke) { ts3poke $3 $+ ; $+ $4- $+ ; $+ $nick $+ ; $+ $chan }
  if ($1-2 == !ts pm) { ts3pm $3 $+ ; $+ $4- $+ ; $+ $nick $+ ; $+ $chan }

  ;commands for admin channel
  if ($chan == %ts.admin && $nick isvoice $chan || $nick ishop $chan || $nick isop $chan) {
    if ($1-2 == !ts hostinfo) { ts3hostinfo $chan }

    if ($nick ishop $chan || $nick isop $chan) {
      if $1-2 == !ts connect { ts.connect } 
      elseif $1 == !ts && $2 != connect && !$sock(ts3) { msg # [TS3] Error: Not connected to the TeamSpeak Server, connecting to server.. | ts.connect }
      if ($1-2 == !ts ban) { ts3ban $3 $+ ; $+ $4- $+ ; $+ $nick $+ ; $+ $chan }
      if ($1-2 == !ts kick) {
        msg %ts.admin [TS3] [Akick] $3 has been kicked by $nick $+ @IRC for: $4- $+ .
        ts3kick $3 $+ ; $+ $4- $+ ; $+ $nick $+ ; $+ $chan
      }
      if ($1-2 == !ts banlist) { ts3banlist $chan }
      if ($1-2 == !ts bandel) { ts3bandel $3 $chan }
      if ($1-2 == !ts bandelall) { ts3bandelall $chan }
    }
    else { msg $chan 7[TS3] $chr(91) $+ $2 $+ $chr(93) You lack the required permissions to use this command. | HALT }
  }
  else { msg $chan 7[TS3] $chr(91) $+ $2 $+ $chr(93) You lack the required permissions to use this command. | HALT }
}

;=======================================
;===== Reading & Responding or Relaying

on *:sockread:ts3: {
  ; puts the information recieved from the ts sever into %tsl, and then throws it into $*
  var %tsl | sockread -n %tsl | tokenize 32 %tsl
  var %tsl2 = $right(%tsl, -1)
  if %tsl == TS3 {
    .timertsconfail off 
    msg %ts.channels 7[TS3] Connection Establised...Logging in as a server admin.
    set %ts.act login
    ts3.d login client_login_name= $+ %ts.slogin client_login_password= $+ %ts.spass
  }
  elseif (error id=*msg=* iswm %tsl2) && (%tsl2 != error id=0 msg=ok) {
    if (%ts.act == banlist) {
      msg %ts.admin 7[TS3] 9[Banlist] There are no active bans in list.
      unset %ts.act %ts.getbanlist
    }
    elseif (%ts.act == ban) {
      msg %ts.banchan 7[TS3] 9[Ban] The bot does not have the permissions needed to ban the client specified. Reasons for this could be:
      msg %ts.banchan 7[TS3] 9[Ban] 1) The client you are trying to ban is a serveradmin, or is in a group with the permission "b_client_ignore_bans" granted.
      msg %ts.banchan 7[TS3] 9[Ban] 2) The bot does not have the permissions to ban. Please check if the bot is in the "Admin ServerQuery" group. 
      unset %ts.act %ts.banchan
    }
    elseif (%ts.act == bandel) {
      msg %ts.channels 7[TS3] 9[Bandel] BanID: %ts.banid $+ , Not found. 11Use !TS Banlist to display active bans.
      unset %ts.act %ts.bandel %ts.banid
    }
    elseif (%ts.act == kick) {
      msg %ts.kickchan 7[TS3] 9[Kick] The bot does not have the permissions needed to kick the client specified. Reasons for this could be:
      msg %ts.kickchan 7[TS3] 9[Kick] 1) The bot does not have the permissions to kick. Please check if the bot is in the "Admin ServerQuery" group. 
      unset %ts.act %ts.kickchan
    }
    elseif (%ts.act == login) {
      msg %ts.channels 7[TS3] Unable to login on the server, are you sure you have entered the username/password correctly?
      ts.sockclose silent
      unset %ts.act
    }
    elseif (%ts.act == sid) {
      msg %ts.channels 7[TS3] Unable to find a server. Reasons for this could be:
      msg %ts.channels 7[TS3] 1) The bot does not have the required permissions to request the server ID. Please doublecheck the permissions the bot has on the TS3 server.
      msg %ts.channels 7[TS3] 2) The server port you have entered in the script is incorrect. 
      ts.sockclose silent
      unset %ts.act
    }
    else {
      msg %ts.channels 7[TS3] Permission error! ( $+ $ts.clean(%tsl2) $+ )
      msg %ts.channels 7[TS3] Please check if the bot has the required permissions to take the action that's needed.
      msg %ts.channels 7[TS3] If you don't know what could be causing this error message, please contact the author of the script. (!TS Version)
    }
  }
  if (cid=*pid=*channel_order=*channel_name=*total_clients=*channel_needed_subscribe_power=* iswm %tsl2) {
    var %ts.chanlist = %tsl2
    var %totalchannels = $gettok(%ts.chanlist,0,124) 
    if (%totalchannels == 0) { HALT }
    if ($hget(ts3chan)) { hfree ts3chan }
    hmake ts3chan 10
    var %a = 1
    while (%a <= %totalchannels) {
      var %rawline = $gettok(%ts.chanlist, %a $+ ,124)
      tokenize 32 %rawline
      var %cid = $gettok($1,2,61)
      var %pid = $gettok($2,2,61)
      var %chan = $gettok($4,2,61)
      var %totclients = $gettok($5,2,61)
      hadd ts3chan %cid %chan $+ ; $+ %totclients
      if (%ts.displaychanlist == 1) {
        msg %ts.chanchan 7[TS3] $iif(%pid != 0, 9--, 3) $+ $ts.clean(%chan) $iif(%totclients != 0, 11[ $+ %totclients $iif(%totclients == 1, client, clients) $+ ])
      }
      inc %a
    } 
    unset %ts.chanchan %ts.displaychanlist
  }
  if (clid=*cid=*client_database_id=*client_nickname=* iswm %tsl2) && (%ts.getclientlist == 1) {
    set %ts.clients %tsl2
    var %totalclients = $gettok(%ts.clients,0,124) 
    if (%totalclients == 0) { HALT }
    hdel -w ts3 *
    var %a = 1
    while (%a <= %totalclients) {
      var %rawline = $gettok(%ts.clients, %a $+ ,124)
      tokenize 32 %rawline
      var %clid = $gettok($1,2,61)
      var %cid = $gettok($2,2,61)
      var %ts3nick = $gettok($4,2,61)
      var %away = $gettok($6,2,61)
      var %awaymessage = $iif($gettok($7,2,61), $gettok($7,2,61))
      var %connectionmethod = $gettok($5,2,61)
      if (%connectionmethod != 1) {
        var %ts.online = $addtok(%ts.online, %ts3nick, 44)
        hadd ts3 %ts3nick $+ ; $+ %clid cid= $+ %cid $+ ;away= $+ %away $+ ;awaymessage= $+ %awaymessage
      }
      inc %a
    } 
    unset %ts.clients %ts.getclientlist

    if (%ts.showclientlist == 1) {
      ts.displaylist
      unset %ts.showclientlist
    }
  }
  if (instance_uptime=*host_timestamp_utc=*virtualservers_running_total=*virtualservers_total_maxclients=* $&
    virtualservers_total_clients_online=*virtualservers_total_channels_online=* iswm %tsl2) && (%ts.gethostinfo == 1) {
    set %ts.hostinfo %tsl2
    var %i_u = $time($gettok($1,2,61))
    ;var %h_t_u = $chr(44) 11Time: $asctime($gettok($2,2,61))
    var %v_r_t = $gettok($3,2,61)
    var %v_t_mc = $gettok($4,2,61)
    var %v_t_c_o = $gettok($5,2,61)
    var %v_t_ch_o = $gettok($6,2,61)
    msg %ts.admin 7[TS3] 09[Hostinfo]: 11Servers: %v_r_t $+ , 11Max. clients: %v_t_mc $+ , 11Clients Online: %v_t_c_o $+ , 11Channels formed: %v_t_ch_o $+ , 11Uptime: %i_u $+ %h_t_u
    unset %ts.hostinfo %ts.gethostinfo
  }
  if (banid=*ip=*name=*uid=*lastnickname created=*duration=*invokername=*invokercldbid=*reason=*enforcements=* iswm %tsl2) && (%ts.getbanlist == 1) {
    set %ts.blist %tsl2
    var %totalbans = $gettok(%ts.blist,0,124) 
    if (%totalbans == 0) { halt }
    var %b = 1
    msg %ts.admin 7[TS3] 09[Banlist] 11 $+ Tolat: $+ %totalbans 
    while (%b <= %totalbans) {
      var %rawline = $gettok(%ts.blist, %b $+ ,124)
      tokenize 32 %rawline
      var %banid = $gettok($1,2,61)
      var %ip = $remove($gettok($2,2,61), \\,)
      var %name = $gettok($3,2,61)
      var %lastnickname = $gettok($5,2,61)
      var %created = ( $+ $asctime($gettok($6,2,61)) $+ )
      var %invokername = $gettok($8,2,61)
      var %reason = $ts.clean($gettok($11,2,61))
      msg %ts.admin 7[TS3] 09[BanID %banid $+ ]: $chr(91) $+ %b $+ $chr(93) %name $+ $chr(64) $+ %ip %lastnickname 14 %created -7 $chr(91) $+ by %invokername $+ $chr(93)  $+ :1 %reason 
      inc %b
    }
    unset %ts.blist %ts.getbanlist %ts.act
  }
  if (%ts.bandel == 1)  {
    msg %ts.channels 7[TS3] 9[Bandel] 11BanID: %ts.banid $+ , 11Removed from banlist by $nick 
    unset %ts.bandel %ts.banid %ts.act
  }
  if ((server_id=* iswm %tsl2) && (%ts.act == sid)) {
    var %sid = $gettok(%tsl2,2,61)
    msg %ts.channels 7[TS3] Selecting server on ID %sid with port %ts.sport $+ ...
    set %ts.act use
    ts3.d use sid= $+ %sid
  }
  if (virtualserver_unique_identifier=*virtualserver_name=*virtualserver_welcomemessage=*virtualserver_platform=*virtualserver_version=*virtualserver_maxclients=* iswm %tsl2) {
    var %name = $ts.clean($gettok($2,2,61))
    var %platform = $ts.clean($gettok($4,2,61))
    var %version = $ts.clean($gettok($5,2,61))
    var %maxclients = $gettok($6,2,61)
    var %currclients = $gettok($8,2,61)
    var %channels = $gettok($9,2,61)
    msg %ts.infochan 7[TS3] 9[Name] 03 $+ %name
    msg %ts.infochan 7[TS3] 9[IP $+ $chr(58) $+ Port] 03 $+ %ts.ip.public $+ : $+ %ts.sport
    msg %ts.infochan 7[TS3] 9[Clients] 03[ $+ %currclients $+ / $+ %maxclients $+ ] - 11Type !TS Users for more information
    msg %ts.infochan 7[TS3] 9[Channels] 03 $+ %channels channels - 11Type !TS Channels for more information
    msg %ts.infochan 7[TS3] 9[Version] 03 $+ %platform %version
    unset %ts.infochan
  }
  if (notifytextmessage* iswm %tsl2) {
    var %targetmode = $gettok($2,2,61)
    if (%targetmode == 3) {
      var %msg = $ts.clean($right($3, -4))
      var %messager = $ts.clean($gettok($5,2,61))
      msg %ts.channels 7[TS3] 09[User] 11 $+ %messager $+ : 03 $+ %msg $+ 
    }
  }
  if (notifyclientleftview* iswm %tsl2) {
    var %clid = $gettok($6,2,61)
    var %leavemsg = $ts.clean($gettok($5, 2, 61))
    var %hashname = $hfind(ts3, *; $+ %clid, 1, w)
    if (!%hashname) { HALT }
    var %leavenick = $gettok(%hashname, 1, 59)
    msg %ts.channels 7[TS3] 9[Player Left] 11 $+ %leavenick -3 Quitmessage: %leavemsg $+ 
    hdel ts3 %hashname
    set %ts.getclientlist 1
    ts3.d clientlist -away
  }
  if (*notifycliententerview* iswm %tsl2) {
    var %clid = $gettok($5, 2, 61)
    var %identifier = $gettok($6, 2, 61)
    var %clnick = $ts.clean($gettok($7, 2, 61))
    var %inputhardware = $gettok($11, 2, 61)
    var %outputhardware = $gettok($12, 2, 61)
    if ((%identifier != ServerQuery) && (%inputhardware == 1) && (%outputhardware == 1)) {
      hadd ts3 %clnick $+ ; $+ %clid
      msg %ts.channels 7[TS3] 9[Player Join] 11 $+ %clnick
      set %ts.getclientlist 1
      ts3.d clientlist -away
    }
  }
  ; The following is triggered when "OK" is sent to the server, based on %ts.act, it reacts accordingly
  elseif (%tsl2 == error id=0 msg=ok) {
    if %ts.act == use {
      msg %ts.channels 7[TS3] TS3 Virtual Server selected successfully, ready for duty.
      .timertspingout 1 %ts.timeout ts.sockclose
      set %ts.act getsid
      ts3.d servernotifyregister event=server
      ts3.d servernotifyregister event=textserver
      ts3.d clientupdate client_nickname= $+ $me
      if ($hget(ts3chan)) { hfree ts3chan }
      if (!$hget(ts3chan)) { hmake ts3chan 10 }
      if ($hget(ts3)) { hfree ts3 }
      if (!$hget(ts3)) { hmake ts3 10 }
      set %ts.getclientlist 1
      ts3.d clientlist -away
      .timertscheckok 0 5 ts.checkok
    }
    elseif %ts.act == ban {
      msg %ts.banchan 7[TS3] 9[Ban] 3The client has been banned successfully.
      unset %ts.act
      unset %ts.banchan
    }
    elseif %ts.act == kick {
      msg %ts.kickchan 7[TS3] 9[Kick] 3The client has been kicked successfully.
      unset %ts.act
      unset %ts.kickchan
    }
    elseif %ts.act == login {
      msg %ts.channels 7[TS3] Logged in successfully, Searching for server id...
      set %ts.act sid
      ts3.d serveridgetbyport virtualserver_port= $+ %ts.sport
    }
    elseif $gettok(%ts.act,1,32) == pl {
      unset %ts.act
    }
    elseif $gettok(%ts.act,1,32) == bl {
      unset %ts.act
    }
    elseif %ts.checkok == check { .timertspingout 1 %ts.timeout ts.sockclose | unset %ts.checkok }
  }
  ;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
  ;; ~~~~~~~~~~~~~~~~~~ Script  Debug ~~~~~~~~~~~~~~~~~~~ ;
  if ($group(#ts3-sdebug).status == on) { $ts3-sd(%tsl2) }
  ;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
}

; ***Checks if the server is still responding every 5 seconds***
alias ts.checkok {
  ts3.d whoami
  set %ts.checkok check
}

; activates if the connection is lost
on *:sockclose:ts3: { ts.sockclose }
; activates when a socket times out, kills the timers
alias ts.sockclose {
  if !$1 {
    sockclose ts3
    msg %ts.channels 7[TS3] TS Error: Socket timed out.
    .timergettslogs off
    .timertscheckok off
  }
  elseif $1 == cc {
    msg %ts.channels 7[TS3] TeamSpeak failed to connect! Reasons for this could be:
    msg %ts.channels 7[TS3] 1) The server is offline 
    msg %ts.channels 7[TS3] 2) The IP or Query Port you have entered is incorrect.
    .timergettslogs off
    .timertscheckok off
    sockclose ts3
    .timertspingout off
  }
  elseif $1 == silent { 
    .timergettslogs off
    .timertscheckok off
    .timertspingout off
    sockclose ts3
  }
}

;============================
;==== Groups

; ***Script Debug***
#ts3-sdebug off
alias ts3-sd {
  if ($1- != $null) { window -e0k0 @TS3-sDebug
    if ($gettok($1-,1,32) iswm Welcome) { return }
    elseif ($gettok($1-,1,61) iswm server_id) { return }
    elseif ($gettok($1-,1,61) == virtualserver_status) {
      if ($gettok($gettok($1-,2,61),1,32) == online) { return }
      else {
        echo @TS3-sDebug 12:: $time Event :: $gettok($1-,1,61) 12::
        echo @TS3-sDebug $1- | echo @TS3-sDebug 12:: -------------- :: 
      }
    }
    elseif $findtok(virtualserver_unique_identifier.instance_uptime.cid.clid.banid,$gettok($1-,1,61),0,46) {
      echo @TS3-sDebug 12:: $time Event :: $gettok($1-,1,61) 12::
      echo @TS3-sDebug $1- | echo @TS3-sDebug 12:: -------------- :: 
    }
    elseif $findtok(notifytextmessage.notifycliententerview.notifyclientleftview,$gettok($1-,1,32),0,46) {
      echo @TS3-sDebug 12:: $time Event :: $gettok($1-,1,32) 12::
      echo @TS3-sDebug $1- | echo @TS3-sDebug 12:: -------------- :: 
    } 
    elseif ($gettok($1-,1,32) == error) {
      if ($gettok($gettok($1-,2,61),1,32) == 0) { return }
      else { 
        echo @TS3-sDebug 4:: $time Event :: $gettok($1-,1,32) 4::
        echo @TS3-sDebug $1- | echo @TS3-sDebug 4:: -------------- :: 
      } 
    }
    else {
      echo @TS3-sDebug 4:: $time ??? ::----------------
      echo @TS3-sDebug 3::: $gettok($1-,1,32) 3::: $gettok($1-,1,61) $gettok($gettok($1-,2,61),1,32)
      echo @TS3-sDebug $1-
      echo @TS3-sDebug 4 :: ------------ ::      
    }
  }
}
#ts3-sdebug end

;

Comments

Sign in to comment.
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.