Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Tornstats Spy Bot IRC link - v3.0

PMV Mar 11th, 2017 370 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. ON 1:START:{ unset %tornstats* | unset %tsspy.* | tornstats.init }
  2.  
  3. alias -l tornstats.cfgfile { return $qt($scriptdir $+ tornstats.ini) }
  4. alias -l tornstats.localfile { return $qt($scriptdir $+ spy.db) }
  5. alias -l tornstats.botvers { return 3.0 }
  6.  
  7. alias -l tornstats.init {
  8.   if (!$exists($tornstats.cfgfile)) { tornstats.upg | echo -ag www.tornstats.com Spy Database script: Default values have been written. Right click channel section for config panel. }
  9.   if ($readini($tornstats.cfgfile,n,Spy,vers) != $tornstats.botvers) { tornstats.upg | echo -ag www.tornstats.com Spy Database script: Thank you for updating, new config entries have been populated with default values. }
  10.   set %tornstats.chanlist $addtok(%tornstats.chanlist,$readini($tornstats.cfgfile,n,Spy,chan),44)
  11.   echo -sg 10tornstats.com Spy Database script made by:7 PMV 10[07157799310] v07 $+ $tornstats.botvers 10- Initialized Successfully!    
  12. }
  13.  
  14.  
  15. ; ##################################################################### CONFIG CODE #####################################################################
  16.  
  17.  
  18. dialog -l tornstats.cfgview {
  19.   title "www.tornstats.com Spy Database Config"
  20.   size -1 -1 260 125
  21.   option dbu
  22.   check "Enable Script (warning: Disable the spy bot on Universal TC Bot if using this script!)",1,4 4 220 10
  23.   text "Channel(s):",1001,4 18 40 10, right
  24.   text "Tornstats Key:",1002,4 32 40 10, right
  25.   text "API Key:",1003,4 44 40 10, right
  26.   edit "",100,50 16 150 10, autohs
  27.   edit "",101,50 30 150 10, autohs
  28.   edit "",102,50 42 150 10, autohs
  29.   button "Set",10,220 20 25 25
  30.   check "Cache Saved Spies Locally (works with Asshole v5.0 or higher/Universal TC Bot)",2,4 56 200 10
  31.   check "Display Socket Errors",3,4 68 200 10
  32.   text "",999,4 115 252 10, center
  33. }
  34.  
  35. on 1:DIALOG:tornstats.cfgview:sclick:1:{
  36.   if ($readini($tornstats.cfgfile,n,Spy,enable) == no) { writeini -n $tornstats.cfgfile Spy enable yes | did -c tornstats.cfgview 1 | did -a tornstats.cfgview 999 Script is now ENABLED. }
  37.   else { writeini -n $tornstats.cfgfile Spy enable no | did -u tornstats.cfgview 1 | did -a tornstats.cfgview 999 Script is now DISABLED. }
  38.   flushini $tornstats.cfgfile
  39. }
  40.  
  41. on 1:DIALOG:tornstats.cfgview:sclick:2:{
  42.   if ($readini($tornstats.cfgfile,n,Spy,cache) == no) { writeini -n $tornstats.cfgfile Spy cache yes | did -c tornstats.cfgview 2 | did -a tornstats.cfgview 999 Script will now save spy updates locally as well. }
  43.   else { writeini -n $tornstats.cfgfile Spy cache no | did -u tornstats.cfgview 2 | did -a tornstats.cfgview 999 Script will NOT save updates locally. }
  44.   flushini $tornstats.cfgfile
  45. }
  46.  
  47. on 1:DIALOG:tornstats.cfgview:sclick:3:{
  48.   if ($readini($tornstats.cfgfile,n,Spy,sockerr) == no) { writeini -n $tornstats.cfgfile Spy sockerr yes | did -c tornstats.cfgview 3 | did -a tornstats.cfgview 999 Script will now display socket errors if any. }
  49.   else { writeini -n $tornstats.cfgfile Spy sockerr no | did -u tornstats.cfgview 3 | did -a tornstats.cfgview 999 Script will hide socket errors. }
  50.   flushini $tornstats.cfgfile
  51. }
  52.  
  53. on 1:DIALOG:tornstats.cfgview:sclick:10:{
  54.   if ($did(tornstats.cfgview,100).text != $null) { writeini -n $tornstats.cfgfile Spy chan $remove($did(tornstats.cfgview,100).text,$chr(32)) }
  55.   else { if ($readini($tornstats.cfgfile,n,Spy,chan) != $null) { remini $tornstats.cfgfile Spy chan } }
  56.   if ($did(tornstats.cfgview,101).text != $null) { writeini -n $tornstats.cfgfile Spy key $did(tornstats.cfgview,101).text }
  57.   else { if ($readini($tornstats.cfgfile,n,Spy,key) != $null) { remini $tornstats.cfgfile Spy key } }
  58.   if ($did(tornstats.cfgview,102).text != $null) { writeini -n $tornstats.cfgfile Spy api $did(tornstats.cfgview,102).text }
  59.   else { if ($readini($tornstats.cfgfile,n,Spy,api) != $null) { remini $tornstats.cfgfile Spy api } }
  60.   set %tornstats.chanlist $readini($tornstats.cfgfile,n,Spy,chan)
  61.   did -ra tornstats.cfgview 999 Channel list and both keys saved.
  62.   did -ra tornstats.cfgview 100 $readini($tornstats.cfgfile,n,Spy,chan)
  63.   did -ra tornstats.cfgview 101 $readini($tornstats.cfgfile,n,Spy,key)
  64.   did -ra tornstats.cfgview 102 $readini($tornstats.cfgfile,n,Spy,api)
  65.   flushini $tornstats.cfgfile
  66. }
  67.  
  68. menu status,channel {
  69.   www.tornstats.com Spy Database v $+ $tornstats.botvers Config:tornstats.cfg
  70. }
  71.  
  72. alias -l tornstats.cfg {
  73.   if ($dialog(tornstats.cfgview)) { halt } | dialog -m tornstats.cfgview tornstats.cfgview
  74.   if ($readini($tornstats.cfgfile,n,Spy,enable) == yes) { did -c tornstats.cfgview 1 } | else { did -u tornstats.cfgview 1 }
  75.   if ($readini($tornstats.cfgfile,n,Spy,cache) == yes) { did -c tornstats.cfgview 2 } | else { did -u tornstats.cfgview 2 }
  76.   if ($readini($tornstats.cfgfile,n,Spy,sockerr) == yes) { did -c tornstats.cfgview 3 } | else { did -u tornstats.cfgview 3 }
  77.   did -ra tornstats.cfgview 100 $readini($tornstats.cfgfile,n,Spy,chan)
  78.   did -ra tornstats.cfgview 101 $readini($tornstats.cfgfile,n,Spy,key)
  79.   did -ra tornstats.cfgview 102 $readini($tornstats.cfgfile,n,Spy,api)
  80. }
  81.  
  82. alias -l tornstats.cfgcheck { if (!$exists($tornstats.cfgfile)) { tornstats.upg | echo -ag www.tornstats.com Spy Database script: Default values have been written. Right click channel section for config panel. } }
  83.  
  84.  
  85. ; ##################################################################### SOCKET CODE #####################################################################
  86.  
  87.  
  88.  
  89. on *:sockopen:getinfo:{
  90.   if ($sockerr) { echo -s 4Socket Error. Socket: $sockname --- Message: $sock($sockname).wsmsg --- Num: $sock($sockname).wserr }
  91.   else {
  92.     if (%tsspy.oldspy != $null) { var %table = tsspy. $+ %tsspy.oldspy }
  93.     else { var %table = tsspy. $+ %tsspy.spy }
  94.     sockwrite -nt $sockname GET /user/ $+ $hget(%table,id) $+ ?selections=profile&key= $+ $readini($tornstats.cfgfile,n,Spy,api) HTTP/1.1
  95.     sockwrite -nt $sockname Host: api.torn.com
  96.     sockwrite -nt $sockname $crlf
  97.   }
  98. }
  99.  
  100. on *:sockread:getinfo:{
  101.   if ($sockerr && $readini($tornstats.cfgfile,n,Spy,sockerr) == yes) { echo -s 4Socket Error. Socket: $sockname --- Message: $sock($sockname).wsmsg --- Num: $sock($sockname).wserr }
  102.   else {
  103.     var %read | sockRead %read | var %readln $remove(%read, $chr(9))  
  104.     ;write $qt($scriptdirtest.htm) %readln
  105.     if (%tsspy.oldspy != $null) { var %table = tsspy. $+ %tsspy.oldspy }
  106.     else { var %table = tsspy. $+ %tsspy.spy }
  107.     if ($regex(%readln,error":"(.+?)")) {
  108.       msg %tsspy.postchan 04API Error: $regml(1)
  109.       tornstats.spywrite
  110.     }
  111.     if ($regex(%readln,level":(.+?)")) { hadd %table lvl $tornstats.cleanN($regml(1)) }  
  112.     if ($regex(%readln,faction_name":"(.+?)")) { hadd %table fact $tornstats.cleanW($regml(1))) }
  113.     if (($hget(%table,lvl) != $null) && ($hget(%table,fact) != $null)) { tornstats.spywrite }
  114.   }
  115. }
  116.  
  117.  
  118. on *:SOCKOPEN:spysave: {
  119.   if ($sockerr && $readini($tornstats.cfgfile,n,Spy,sockerr) == yes) { echo -s 4Socket Error. Socket: $sockname --- Message: $sock($sockname).wsmsg --- Num: $sock($sockname).wserr }
  120.   else {
  121.     if (%tsspy.oldspy != $null) { var %table = tsspy. $+ %tsspy.oldspy }
  122.     else { var %table = tsspy. $+ %tsspy.spy }
  123.     var %a = /tornbot/someelusivebotscript.php?action=spy&step=save
  124.     var %a = %a $+ &key= $+ $tornstats.uencode($readini($tornstats.cfgfile,n,Spy,key))
  125.     var %a = %a $+ &name= $+ $tornstats.uencode($hget(%table,name))    
  126.     var %a = %a $+ &id= $+ $tornstats.uencode($hget(%table,id))
  127.     var %a = %a $+ &lvl= $+ $tornstats.uencode($hget(%table,lvl))
  128.     var %a = %a $+ &faction= $+ $tornstats.uencode($hget(%table,fact))
  129.     var %a = %a $+ &str= $+ $tornstats.uencode($hget(%table,str))
  130.     var %a = %a $+ &def= $+ $tornstats.uencode($hget(%table,def))
  131.     var %a = %a $+ &spd= $+ $tornstats.uencode($hget(%table,spd))
  132.     var %a = %a $+ &dex= $+ $tornstats.uencode($hget(%table,dex))
  133.     var %a = %a $+ &tot= $+ $tornstats.uencode($hget(%table,totb))
  134.     sockwrite -nt $sockname GET %a HTTP/1.1
  135.     sockwrite -nt $sockname User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
  136.     sockwrite -nt $sockname Host: www.tornstats.com
  137.     sockwrite -nt $sockname Accept-Language: en-us
  138.     sockwrite -nt $sockname Accept: */*
  139.     sockwrite -nt $sockname $crlf
  140.   }
  141. }
  142.  
  143. on *:SOCKREAD:spysave: {
  144.   if ($sockerr && $readini($tornstats.cfgfile,n,Spy,sockerr) == yes) { echo -s 4Socket Error. Socket: $sockname --- Message: $sock($sockname).wsmsg --- Num: $sock($sockname).wserr }
  145.   else {
  146.     :nextread
  147.     sockread -f %tsspy.str
  148.     ;write $qt($scriptdirtest $+ $gmt $+ .htm) %tsspy.str
  149.     if ($sockbr == 0) { return }
  150.     if (%tsspy.str == $null) { %tsspy.str = - }
  151.     if (<p> isin %tsspy.str) {
  152.       set %tsspy.response $remove(%tsspy.str,<p>,</p>)
  153.       tornstats.savetosite
  154.       sockclose spyget
  155.     }
  156.     else { goto nextread }
  157.   }
  158. }
  159.  
  160. on *:SOCKCLOSE:spysave:{ tornstats.savetosite }
  161.  
  162. alias -l tornstats.savetosite {
  163.   if (%tsspy.postchan != $null) {
  164.     if (%tsspy.response != $null) { msg %tsspy.postchan 10 $+ %tsspy.response }
  165.     else { msg %tsspy.postchan 04Oops! The server did not send a valid response, please check your settings! }
  166.     if (%tsspy.oldspy != $null) { var %table = tsspy. $+ %tsspy.oldspy }
  167.     else { var %table = tsspy. $+ %tsspy.spy }
  168.     hfree %table
  169.     .timer0.tornstats.spyauto off
  170.     unset %tsspy.* | unset %tsprofsw.*
  171.   }
  172. }
  173.  
  174. on *:SOCKOPEN:spyget: {
  175.   if ($sockerr && $readini($tornstats.cfgfile,n,Spy,sockerr) == yes) { echo -s 4Socket Error. Socket: $sockname --- Message: $sock($sockname).wsmsg --- Num: $sock($sockname).wserr }
  176.   else {
  177.     var %a = /tornbot/someelusivebotscript.php?action=spy&step=get
  178.     var %a = %a $+ &key= $+ $tornstats.uencode($readini($tornstats.cfgfile,n,Spy,key))
  179.     if ($gettok(%tsspy.search,1,32) == i) { var %a = %a $+ &id= $+ $tornstats.uencode($gettok(%tsspy.search,2,32)) }
  180.     else { var %a = %a $+ &name= $+ $tornstats.uencode($gettok(%tsspy.search,2,32)) }
  181.     sockwrite -nt $sockname GET %a HTTP/1.1
  182.     sockwrite -nt $sockname User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
  183.     sockwrite -nt $sockname Host: www.tornstats.com
  184.     sockwrite -nt $sockname Accept-Language: en-us
  185.     sockwrite -nt $sockname Accept: */*
  186.     sockwrite -nt $sockname $crlf
  187.   }
  188. }
  189.  
  190. on *:SOCKREAD:spyget: {
  191.   if ($sockerr && $readini($tornstats.cfgfile,n,Spy,sockerr) == yes) { echo -s 4Socket Error. Socket: $sockname --- Message: $sock($sockname).wsmsg --- Num: $sock($sockname).wserr }
  192.   else {
  193.     :nextread
  194.     sockread -f %tsspy.read
  195.     ;write $qt($scriptdirtest $+ $gmt $+ .htm) %tsspy.read
  196.     if ($sockbr == 0) { return }
  197.     if (%tsspy.read == $null) { %tsspy.read = - }
  198.     if (Name: isin %tsspy.read) { set %tsspy.name $gettok(%tsspy.read,2,32) }
  199.     if (ID: isin %tsspy.read) { set %tsspy.id $gettok(%tsspy.read,2,32) }
  200.     if (Level: isin %tsspy.read) {
  201.       set %tsspy.lvl $gettok(%tsspy.read,2,32)
  202.       if ($calc(%tsspy.lvl) == 0 || %tsspy.lvl == $null) { set %tsspy.lvl 04N/A }
  203.     }
  204.     if (Faction: isin %tsspy.read) {
  205.       set %tsspy.fac $remove(%tsspy.read,Faction:)
  206.       if (%tsspy.fac == 0 || %tsspy.fac == $null || %tsspy.fac == $chr(32)) { set %tsspy.fac 04N/A }
  207.     }
  208.     if (Strength: isin %tsspy.read) {
  209.       set %tsspy.str $gettok(%tsspy.read,2,32)
  210.       if ($calc(%tsspy.str) == 0 || %tsspy.str == $null) { set %tsspy.str 04N/A }
  211.     }
  212.     if (Defense: isin %tsspy.read) {
  213.       set %tsspy.def $gettok(%tsspy.read,2,32)
  214.       if ($calc(%tsspy.def) == 0 || %tsspy.def == $null) { set %tsspy.def 04N/A }
  215.     }
  216.     if (Speed: isin %tsspy.read) {
  217.       set %tsspy.spd $gettok(%tsspy.read,2,32)
  218.       if ($calc(%tsspy.spd) == 0 || %tsspy.spd == $null) { set %tsspy.spd 04N/A }
  219.     }
  220.     if (Dexterity: isin %tsspy.read) {
  221.       set %tsspy.dex $gettok(%tsspy.read,2,32)
  222.       if ($calc(%tsspy.dex) == 0 || %tsspy.dex == $null) { set %tsspy.dex 04N/A }
  223.     }
  224.     if (Total: isin %tsspy.read) {
  225.       set %tsspy.tot $gettok(%tsspy.read,2,32)
  226.       if ($calc(%tsspy.tot) == 0 || %tsspy.tot == $null) { set %tsspy.tot 04N/A }
  227.     }
  228.     if (Updated: isin %tsspy.read) { set %tsspy.upd $gettok($remove(%tsspy.read,</p>),2,32) }
  229.     if (Error: isin %tsspy.read) { set %tsspy.err $deltok($remove(%tsspy.read,</p>,<p>),1,32) }
  230.     if (</p> isin %tsspy.read) {
  231.       tornstats.displayspy
  232.       sockclose spyget
  233.     }
  234.     else { goto nextread }
  235.   }
  236. }
  237.  
  238. on *:SOCKCLOSE:spyget:{ tornstats.displayspy }
  239.  
  240. alias -l tornstats.displayspy {
  241.   if (%tsspy.name != $null) {
  242.     var %age = $calc($gmt - %tsspy.upd)
  243.     if (%age >= 2592000) { var %oldtag = 04[OLD] }
  244.     else { var %oldtag = $null }
  245.     msg %tsspy.postchan 10Spy Entry for07 %tsspy.name 10[07 $+ %tsspy.id $+ 10] (Lv:07 %tsspy.lvl 10- Fact:07 %tsspy.fac $+ 10) - Added on:07 $asctime(%tsspy.upd,mmm d) 10@07 $asctime(%tsspy.upd,h:nn:ss tt) 06( $+ $duration(%age) ago) %oldtag
  246.     msg %tsspy.postchan 10Strength:07 $tornstats.addComma(%tsspy.str)
  247.     msg %tsspy.postchan 10Defense:07 $tornstats.addComma(%tsspy.def)
  248.     msg %tsspy.postchan 10Speed:07 $tornstats.addComma(%tsspy.spd)
  249.     msg %tsspy.postchan 10Dexterity:07 $tornstats.addComma(%tsspy.dex)
  250.     msg %tsspy.postchan 10Total:07 $tornstats.addComma(%tsspy.tot)
  251.   }
  252.   else {
  253.     if (%tsspy.err != $null) { msg %tsspy.postchan 04 $+ %tsspy.err }
  254.     else { msg %tsspy.postchan 04Oops! A problem has occurred, check your settings! }
  255.   }
  256.   unset %tsspy.*
  257. }
  258.  
  259. on *:SOCKOPEN:spyfind: {
  260.   if ($sockerr && $readini($tornstats.cfgfile,n,Spy,sockerr) == yes) { echo -s 4Socket Error. Socket: $sockname --- Message: $sock($sockname).wsmsg --- Num: $sock($sockname).wserr }
  261.   else {
  262.     var %a = /tornbot/someelusivebotscript.php?action=spy&step=search $+ %tsspy.find
  263.     var %a = %a $+ &key= $+ $tornstats.uencode($readini($tornstats.cfgfile,n,Spy,key))
  264.     sockwrite -nt $sockname GET %a HTTP/1.1
  265.     sockwrite -nt $sockname User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
  266.     sockwrite -nt $sockname Host: www.tornstats.com
  267.     sockwrite -nt $sockname Accept-Language: en-us
  268.     sockwrite -nt $sockname Accept: */*
  269.     sockwrite -nt $sockname $crlf
  270.   }
  271. }
  272.  
  273. on *:SOCKREAD:spyfind: {
  274.   if ($sockerr && $readini($tornstats.cfgfile,n,Spy,sockerr) == yes) { echo -s 4Socket Error. Socket: $sockname --- Message: $sock($sockname).wsmsg --- Num: $sock($sockname).wserr }
  275.   else {
  276.     :nextread
  277.     sockread -f %tsspy.read
  278.     ;write $qt($scriptdirtest $+ $gmt $+ .htm) %tsspy.read
  279.     if ($sockbr == 0) { return }
  280.     if (%tsspy.read == $null) { %tsspy.read = - }  
  281.     if (Found: isin %tsspy.read) { tornstats.spypost $gettok(%tsspy.read,2,32) $gettok(%tsspy.read,3,32) }
  282.     if (</p> isin %tsspy.read) {
  283.       tornstats.spysearchres
  284.       sockclose spyget
  285.     }
  286.     else { goto nextread }
  287.   }
  288. }
  289.  
  290. on *:SOCKCLOSE:spyfind:{ tornstats.spysearchres }
  291.  
  292. alias -l tornstats.spysearchres {
  293.   if (%tsspy.postchan != $null) {
  294.     if (%tsspy.post != $null) { msg %tsspy.postchan $left(%tsspy.post, $calc($len(%tsspy.post) - 1)) $+ $chr(46) }
  295.     if (%tsspy.found != $null) { msg %tsspy.postchan 10Total:7 %tsspy.found 10spies! }
  296.     else { msg %tsspy.postchan 04There were no spies found for that query. }
  297.     unset %tsspy.*
  298.   }
  299. }
  300.  
  301.  
  302. ; ##################################################################### ALIAS CODE #####################################################################
  303.  
  304.  
  305. alias -l tornstats.addComma { var %a, %b = $regsub($ticks,$1,/\G([+-]?\d+?)(?=(?:\d{3})++(?=\.\d++$|$))/g,\1 $+ $chr(44),%a) | return %a }
  306.  
  307. ; strips all input ascii chars aside from decimals and numbers. Used to clean accidental/intentional letters in inputs that expect numbers.
  308. alias -l tornstats.cleanN {
  309.   var %a = 0 | var %b = $1
  310.   while (%a < 255) { if (%a != 46 && %a !isnum 48-57) { var %b = $remove(%b, $chr(%a)) } | inc %a }
  311.   return %b
  312. }
  313.  
  314. ; strips leading and trailing whitespace
  315. alias -l tornstats.cleanW { var %a, %b = $regsub($ticks,$1,^[ \t]+|[ \t]+$,$null,%a) | return %a }  
  316.  
  317. alias -l tornstats.uencode {
  318.   var %a = $replace($1-,$chr(37),$+($chr(37),25)), %ptr = 32
  319.   while (%ptr <= 126) {
  320.     if (%ptr == 37) { inc %ptr | continue }
  321.     if (%ptr >= 48 && %ptr <= 57) { inc %ptr | continue }
  322.     if (%ptr >= 65 && %ptr <= 90) { inc %ptr | continue }
  323.     if (%ptr >= 97 && %ptr <= 122) { inc %ptr | continue }
  324.     var %a = $replace(%a,$chr(%ptr),$+($chr(37),$base(%ptr,10,16)))
  325.     inc %ptr
  326.   }  
  327.   return %a
  328. }
  329.  
  330. alias -l tornstats.spywrite {
  331.   sockclose getinfo
  332.   if ($timer(0.tornstats.spyscrape)) { .timer $+ 0.tornstats.spyscrape off }
  333.   if (%tsspy.oldspy != $null) { var %table = tsspy. $+ %tsspy.oldspy }
  334.   else { var %table = tsspy. $+ %tsspy.spy }
  335.   if ($hget(%table,id) != $null) {
  336.     msg %tsspy.postchan 10Saving spy entry for07 $hget(%table,name) 10[07 $+ $hget(%table,id) $+ 10] to tornstats.com...
  337.     if (!$hfind(%table,fact) || $hget(%table,fact) == $null) { hadd -m %table fact N/A }
  338.     if (!$hfind(%table,lvl) || $hget(%table,lvl) !isnum) { hadd -m %table lvl 0 }
  339.     if ($readini($tornstats.cfgfile,n,Spy,cache) == yes) {
  340.       var %savestring = $hget(%table,name) $+ $chr(9) $+ $hget(%table,id) $+ $chr(9) $+  $hget(%table,lvl) $+ $chr(9) $+ $hget(%table,fact) $+ $chr(9) $+ $hget(%table,spd) $+ $chr(9) $+ $hget(%table,str) $+ $chr(9) $+ $hget(%table,def) $+ $chr(9) $+ $hget(%table,dex) $+ $chr(9) $+ $hget(%table,totb) $+ $chr(9) $+ $hget(%table,man) $+ $chr(9) $+ $hget(%table,int) $+ $chr(9) $+ $hget(%table,end) $+ $chr(9) $+ $hget(%table,totw) $+ $chr(9) $+ $hget(%table,cash) $+ $chr(9) $+ %tsspy.spy $+ $chr(9) $+ $hget(%table,adate)
  341.       if ($exists($tornstats.localfile)) {
  342.         var %eof = $lines($tornstats.localfile), %ptr = 1
  343.         while (%ptr <= %eof) {
  344.           var %readid = $gettok($read($tornstats.localfile,%ptr),2,9)
  345.           if (%readid == $hget(%table,id)) { var %spyold = 1 | write -dl $+ %ptr $tornstats.localfile | break }
  346.           inc %ptr
  347.         }
  348.       }
  349.       write $tornstats.localfile %savestring
  350.     }    
  351.     sockclose spysave
  352.     sockopen -e spysave www.tornstats.com 443
  353.   }
  354.   else {
  355.     msg %tsspy.postchan 04I somehow do not have the ID so I cannot save the spy. Cancelling.
  356.     tornstats.spyclean
  357.   }
  358. }
  359.  
  360. alias -l tornstats.spysave {
  361.   if (%tsspy.oldspy != $null) { var %table = tsspy. $+ %tsspy.oldspy }
  362.   else { var %table = tsspy. $+ %tsspy.spy }
  363.   if ($hget(%table,id) == $null) {
  364.     msg %tsspy.postchan 04The ID was not successfully read. Paste your spy exactly how Torn sends it to you without modification.
  365.     msg %tsspy.postchan 10Use:07 !addspy 10to see manual input help.
  366.   }
  367.   else {
  368.     if (!$hfind(%table,str) || $hget(%table,str) !isnum) { hadd -m %table str 0 }
  369.     if (!$hfind(%table,spd) || $hget(%table,spd) !isnum) { hadd -m %table spd 0 }
  370.     if (!$hfind(%table,dex) || $hget(%table,dex) !isnum) { hadd -m %table dex 0 }
  371.     if (!$hfind(%table,def) || $hget(%table,def) !isnum) { hadd -m %table def 0 }
  372.     if (!$hfind(%table,totb) || $hget(%table,totb) !isnum) { hadd -m %table totb 0 }
  373.     if (!$hfind(%table,man) || $hget(%table,man) !isnum) { hadd -m %table man 0 }
  374.     if (!$hfind(%table,int) || $hget(%table,int) !isnum) { hadd -m %table int 0 }
  375.     if (!$hfind(%table,end) || $hget(%table,end) !isnum) { hadd -m %table end 0 }
  376.     if (!$hfind(%table,totw) || $hget(%table,totw) !isnum) { hadd -m %table totw 0 }
  377.     if (!$hfind(%table,cash) || $hget(%table,cash) !isnum) { hadd -m %table cash -1 }
  378.     if (!$hfind(%table,adate)) { hadd -m %table adate $gmt }
  379.     sockclose getinfo
  380.     sockopen -e getinfo www.torn.com 443
  381.     msg %tsspy.postchan 06Attempting to get additional info from the API (5 seconds max)...
  382.     .timer $+ 0.tornstats.spyscrape 1 5 tornstats.spywrite
  383.   }
  384. }
  385.  
  386. alias -l tornstats.spycancel {
  387.   msg %tsspy.postchan 10Spy auto-entry cancelled.
  388.   tornstats.spyclean
  389. }
  390.  
  391. ; called in a few places
  392. alias -l tornstats.spyclean {
  393.   if ($hget(tsspy. $+ %tsspy.spy)) { hfree tsspy. $+ %tsspy.spy }
  394.   unset %tsspy.spy | unset %tsspy.postchan
  395. }
  396.  
  397. alias -l tornstats.spypost {
  398.   ; $1 is name, $2 is id
  399.   if (%tsspy.found == $null) { set %tsspy.found 0 }
  400.   if (%tsspy.ptr == $null) { set %tsspy.ptr 1 }
  401.   set %tsspy.post %tsspy.post 07 $+ $1 10[07 $+ $2 $+ 10] $+ $chr(44)
  402.   inc %tsspy.ptr    
  403.   inc %tsspy.found
  404.   if (%tsspy.ptr == 7) {
  405.     msg %tsspy.postchan %tsspy.post
  406.     set %tsspy.ptr 1
  407.     set %tsspy.post $null
  408.   }
  409. }
  410.  
  411. alias -l tornstats.bq {
  412.   ; query string builder for findspy
  413.   var %src = $1, %query = $null, %count = $numtok(%src,32), %ptr = 1
  414.   while (%ptr <= %count) {
  415.     var %prop = $gettok(%src,%ptr,32)
  416.     var %data = $right(%prop,-4)    
  417.     if (%data == $null) {
  418.       msg %tsspy.postchan 04Don't understand your query, use !findspy without params to see some examples
  419.       unset %tsspy.*
  420.       halt
  421.     }
  422.     if ($left(%prop,4) == Fac:) { var %query = %query $+ &faction= $+ %data }
  423.     if ($left(%prop,3) == Str) {
  424.       if ($mid(%prop,4,1) == $chr(60)) { var %param = l } | else { var %param = g }
  425.       var %query = %query $+ &str= $+ $replace(%data,k,000,m,000000,b,000000000,t,000000000000) $+ &strd= $+ %param
  426.     }
  427.     if ($left(%prop,3) == Spd) {
  428.       if ($mid(%prop,4,1) == $chr(60)) { var %param = l } | else { var %param = g }
  429.       var %query = %query $+ &spd= $+ $replace(%data,k,000,m,000000,b,000000000,t,000000000000) $+ &spdd= $+ %param
  430.     }
  431.     if ($left(%prop,3) == Dex) {
  432.       if ($mid(%prop,4,1) == $chr(60)) { var %param = l } | else { var %param = g }
  433.       var %query = %query $+ &dex= $+ $replace(%data,k,000,m,000000,b,000000000,t,000000000000) $+ &dexd= $+ %param
  434.     }
  435.     if ($left(%prop,3) == Def) {
  436.       if ($mid(%prop,4,1) == $chr(60)) { var %param = l } | else { var %param = g }
  437.       var %query = %query $+ &def= $+ $replace(%data,k,000,m,000000,b,000000000,t,000000000000) $+ &defd= $+ %param
  438.     }
  439.     if ($left(%prop,3) == Tot) {
  440.       if ($mid(%prop,4,1) == $chr(60)) { var %param = l } | else { var %param = g }
  441.       var %query = %query $+ &tot= $+ $replace(%data,k,000,m,000000,b,000000000,t,000000000000) $+ &totd= $+ %param
  442.     }
  443.     inc %ptr
  444.   }
  445.   return %query
  446.   ;msg #pmv src = %src | msg #pmv query = %query | halt
  447. }
  448.  
  449. alias -l tornstats.addspyhelp { return 03Adds a spy to the bot. Manual usage: 07!addspy Name TornID Str Spd Dex Def Total 10Faction (optional). 10To add automatically, use: 07!addspy auto 10if you have the full paste, or 07!addspy Name TornID auto 10if you only have the stats portion. 06For automatic pre-RESPO reports, use: !addspy old }
  450.  
  451.  
  452. ; ##################################################################### CHANNEL CODE #####################################################################
  453.  
  454.  
  455. on *:text:*:%tornstats.chanlist: {
  456.   if ($readini($tornstats.cfgfile,n,Spy,enable) == yes) {
  457.     tornstats.cfgcheck
  458.     tokenize 32 $strip($replace($1-, $chr(9), $chr(32)))
  459.     if ($eval($findfile,0) isin $1-) { halt }
  460.     if ($nick isop #) {
  461.       if (%tsspy.spy == $nick) {
  462.         var %tablename = tsspy. $+ %tsspy.spy
  463.         if ($istok(Strength: Speed: Defense: Dexterity: Total:,$1,32)) {
  464.           .timer $+ 0.tornstats.spyauto off
  465.           .timer $+ %tsspy.spy $+ .spy -co 1 5 tornstats.spysave
  466.         }
  467.         if ($1 == Name:) {
  468.           hadd -m %tablename name $2
  469.           hadd -m %tablename id $remove($3,$chr(91),$chr(93))
  470.         }
  471.         if ($1 == Level:) { hadd -m %tablename lvl $2 }
  472.         if ($1 == Strength:) { hadd -m %tablename str $remove($2,$chr(44),$chr(32)) }
  473.         if ($1 == Speed:) { hadd -m %tablename spd $remove($2,$chr(44),$chr(32)) }
  474.         if ($1 == Defense:) { hadd -m %tablename def $remove($2,$chr(44),$chr(32)) }
  475.         if ($1 == Dexterity:) { hadd -m %tablename dex $remove($2,$chr(44),$chr(32)) }
  476.         if ($1 == Total:) {
  477.           if ($hget(%tablename,end)) { hadd -m %tablename totw $remove($2,$chr(44),$chr(32)) }
  478.           else { hadd -m %tablename totb $remove($2,$chr(44),$chr(32)) }
  479.         }
  480.       }
  481.       if (%tsspy.oldspy == $nick) {
  482.         var %tablename = tsspy. $+ %tsspy.oldspy
  483.         if ($istok(Name: Level: Strength: Speed: Defense: Dexterity: Total: Manual Intelligence: Endurance: Money:,$1,32)) {
  484.           .timer $+ 0.tornstats.spyauto off
  485.           .timer $+ %tsspy.spy $+ .spy -co 1 5 tornstats.spysave
  486.         }
  487.         if ($1 == Name:) {
  488.           hadd -m %tablename name $2
  489.           hadd -m %tablename id $remove($3,$chr(91),$chr(93))
  490.         }
  491.         if ($1 == Level:) { hadd -m %tablename lvl $2 }
  492.         if ($1 == Strength:) { hadd -m %tablename str $remove($2,$chr(44),$chr(32)) }
  493.         if ($1 == Speed:) { hadd -m %tablename spd $remove($2,$chr(44),$chr(32)) }
  494.         if ($1 == Defense:) { hadd -m %tablename def $remove($2,$chr(44),$chr(32)) }
  495.         if ($1 == Dexterity:) { hadd -m %tablename dex $remove($2,$chr(44),$chr(32)) }
  496.         if ($1 == Total:) {
  497.           if ($hget(%tablename,end)) { hadd -m %tablename totw $remove($2,$chr(44),$chr(32)) }
  498.           else { hadd -m %tablename totb $remove($2,$chr(44),$chr(32)) }
  499.         }
  500.         if ($1 == Manual) { hadd -m %tablename man $remove($3,$chr(44),$chr(32)) }
  501.         if ($1 == Intelligence:) { hadd -m %tablename int $remove($2,$chr(44),$chr(32)) }
  502.         if ($1 == Endurance:) { hadd -m %tablename end $remove($2,$chr(44),$chr(32)) }
  503.         if ($1 == Money:) { hadd -m %tablename cash $remove($2,$chr(36),$chr(44),$chr(32)) }
  504.       }
  505.  
  506.       if ($1 == !purgespy || $1 == !spypurge) {
  507.         msg # 10The spy storage script should be 'unstuck' now. Sorry about that...
  508.         unset %tsspy.*
  509.       }
  510.  
  511.       if ($1 == !addspy || $1 == !storespy) {
  512.         if (%tsspy.oldspy != $null || %tsspy.spy != $null) { msg # 04I'm already watching for a spy paste! | halt }
  513.         elseif (($2 == $null) || (auto !isin $2- && $numtok($2-,32) < 7)) { msg # $tornstats.addspyhelp | halt }      
  514.         elseif ($2 == old && $3 == $null) { var %spyoldauto = 1 }
  515.         elseif ($3 == old && $4 == $null) { var %spyoldauto = 1 }
  516.         elseif ($4 == old && $5 == $null) { var %spyoldauto = 1, %spyname = $remove($2,$chr(32)), %spyid = $remove($3,$chr(32),$chr(93),$chr(91)) }
  517.         elseif ($2 == auto && $3 == $null) { var %spyauto = 1 }
  518.         elseif ($3 == auto && $4 == $null) { msg # $tornstats.addspyhelp | halt }
  519.         elseif ($4 == auto && $5 == $null) { var %spyauto = 1, %spyname = $remove($2,$chr(32)), %spyid = $remove($3,$chr(32),$chr(93),$chr(91)) }
  520.         else {        
  521.           set %tsspy.postchan #
  522.           set %tsspy.spy $nick
  523.           var %tablename = tsspy. $+ $nick
  524.           var %chk = 1, %chkstr = $replace($2-,Strength:,$chr(32) $+ Strength:,Speed:,$chr(32) $+ Speed:,Dexterity:,$chr(32) $+ Dexterity:,Defense:,$chr(32) $+ Defense:,Total:,$chr(32) $+ Total:)
  525.           while (%chk < $numtok(%chkstr,32)) {
  526.             if ($gettok(%chkstr,%chk,32) == Speed:) { var %spd = $tornstats.cleanN($gettok(%chkstr,$calc(%chk + 1),32)) }
  527.             if ($gettok(%chkstr,%chk,32) == Strength:) { var %str = $tornstats.cleanN($gettok(%chkstr,$calc(%chk + 1),32)) }
  528.             if ($gettok(%chkstr,%chk,32) == Defense:) { var %def = $tornstats.cleanN($gettok(%chkstr,$calc(%chk + 1),32)) }
  529.             if ($gettok(%chkstr,%chk,32) == Dexterity:) { var %dex = $tornstats.cleanN($gettok(%chkstr,$calc(%chk + 1),32)) }
  530.             if ($gettok(%chkstr,%chk,32) == Total:) { var %tot = $tornstats.cleanN($gettok(%chkstr,$calc(%chk + 1),32)) | var %totmark = $calc(%chk + 1) }
  531.             inc %chk
  532.           }
  533.           if (%spd == $null) {
  534.             var %chkspd = $tornstats.cleanN($5)
  535.             if (%chkspd isnum) { var %spd = %chkspd }
  536.           }
  537.           if (%str == $null) {
  538.             var %chkstr = $tornstats.cleanN($4)
  539.             if (%chkstr isnum) { var %str = %chkstr }
  540.           }
  541.           if (%def == $null) {
  542.             var %chkdef = $tornstats.cleanN($7)
  543.             if (%chkdef isnum) { var %def = %chkdef }
  544.           }
  545.           if (%dex == $null) {
  546.             var %chkdex = $tornstats.cleanN($6)
  547.             if (%chkdex isnum) { var %dex = %chkdex) }
  548.           }
  549.           if (%tot == $null) {
  550.             var %chktot = $tornstats.cleanN($8)
  551.             if (%chktot isnum) { var %tot = %chktot }
  552.           }
  553.           if (%totmark != $null) {
  554.             var %clnstart = 1, %fac = $2-
  555.             while (%clnstart <= %totmark) { var %fac = $deltok(%fac,1,32) | inc %clnstart }
  556.           }
  557.           elseif ($9 != $null) { var %fac = $9- }
  558.           else { var %fac = $null }
  559.           hadd -m %tablename name $2
  560.           hadd -m %tablename id $remove($3,$chr(91),$chr(93))
  561.           hadd -m %tablename spd %spd
  562.           hadd -m %tablename str %str
  563.           hadd -m %tablename def %def
  564.           hadd -m %tablename dex %dex
  565.           hadd -m %tablename totb %tot
  566.           if (%fac != $null) { hadd -m %tablename fact %fac }    
  567.           tornstats.spysave
  568.         }
  569.         if (%spyoldauto != $null) {
  570.           set %tsspy.oldspy $nick
  571.           set %tsspy.postchan #
  572.           if (%tablename == $null) { var %tablename = tsspy. $+ $nick }
  573.           if (%spyname != $null) { hadd -m %tablename name %spyname }
  574.           if (%spyid != $null) { hadd -m %tablename id %spyid }
  575.           .timer $+ 0.tornstats.spyauto 1 10 tornstats.spycancel
  576.           msg # 10Go ahead and paste your pre-RESPO spy report07 $nick $+ 10, I'm watching for it...        
  577.         }
  578.         if (%spyauto != $null) {
  579.           set %tsspy.spy $nick
  580.           set %tsspy.postchan #
  581.           if (%tablename == $null) { var %tablename = tsspy. $+ $nick }
  582.           if (%spyname != $null) { hadd -m %tablename name %spyname }
  583.           if (%spyid != $null) { hadd -m %tablename id %spyid }
  584.           .timer $+ 0.tornstats.spyauto 1 10 tornstats.spycancel
  585.           msg # 10Go ahead and paste your spy report7 $nick $+ 10, I'm watching for it...        
  586.         }
  587.       }
  588.  
  589.       if ($1 == !spy || $1 == !read) {
  590.         if ($2 == $null) { msg # 03Displays stored spy record. 10Usage:07 !spy Name 10or07 !read ID | halt }
  591.         if (!$timer(0.tornstats.spam)) {      
  592.           set %tsspy.postchan #
  593.           if ($1 == !read) { set %tsspy.search i $2 }
  594.           else { set %tsspy.search n $2 }
  595.           sockclose spyget
  596.           sockopen -e spyget www.tornstats.com 443
  597.           .timer $+ 0.tornstats.spam -o 1 10 noop
  598.         }
  599.         else { msg # 04No can do, too many requests too often. You can try again in07 $timer(0.tornstats.spam).secs 04seconds. }
  600.       }
  601.  
  602.       if ($1 == !findspy || $1 == !spyfind) {
  603.         if ($2 == $null || Fac: !isin $2-) {
  604.           msg # 03Searches for a spy. 10Usage:07 !findspy Query 10- Param List:07 Fac(reqd) Str Dex Def Spd Tot
  605.           msg # 06Example:13 !findspy Fac:test Str>100k Dex<2m Tot:6m 10will search for anyone in faction "test", over 100k str, under 2m dex, and over 6m total stats.
  606.           halt
  607.         }
  608.         if (!$timer(0.tornstats.spam)) {
  609.           set %tsspy.postchan #
  610.           set %tsspy.find $tornstats.bq($2-)
  611.           msg # 10Searching for spies, one sec...
  612.           sockclose spyfind
  613.           sockopen -e spyfind www.tornstats.com 443
  614.           .timer $+ 0.tornstats.spam -o 1 5 noop
  615.         }
  616.         else { msg # 04No can do, too many requests too often. You can try again in07 $timer(0.tornstats.spam).secs 04seconds. }
  617.       }
  618.  
  619.       if ($1 == !botinfo) { msg # 10 $+ www.tornstats.com Spy Database script made by: $+ 07 PMV 10[07157799310] v $+ 07 $+ $tornstats.botvers }
  620.     }
  621.   }
  622. }
  623.  
  624. ; --------------------------------- initial file generators and setup script ---------------------------------
  625.  
  626. alias -l tornstats.upg {
  627.   writeini -n $tornstats.cfgfile Spy vers $tornstats.botvers
  628.   if ($readini($tornstats.cfgfile,n,Spy,enable) == $null) { writeini -n $tornstats.cfgfile Spy enable no }
  629.   if ($readini($tornstats.cfgfile,n,Spy,cache) == $null) { writeini -n $tornstats.cfgfile Spy cache no }
  630.   if ($readini($tornstats.cfgfile,n,Spy,sockerr) == $null) { writeini -n $tornstats.cfgfile Spy sockerr no }
  631.   flushini $tornstats.cfgfile
  632. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top