Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Fixed by westor on 14/07/2017 02:00
- alias -l active_channels return #test_chan
- alias -l mynick return Announcer
- alias -l ignored_worlds return
- alias -l show_country return 1
- alias -l show_class return 1
- alias -l show_pvp return 1
- alias -l show_clan return 1
- alias -l show_total_players return 1
- on $*:text:/^!tracker +(off|stop)/iS:$($active_channels): {
- if ($nick !isop #) || ($me !== $mynick) return
- if ($timer(worldcheck)) { .timerworldcheck off | .timerworldmsg off }
- if ($window(@rb_output)) { window -c @rb_output }
- cleanup wtracker
- cleanup checkpop
- msg $active_channels Tracker was killed by $nick $+ .
- }
- on $*:text:/^!tracker +(\d+) +(\d+)/Si:$($active_channels):{
- if ($nick !isop #) || ($me !== $mynick) return
- var %diff $regml(1)
- var %secs = $regml(2)
- trackstart %diff %secs
- }
- alias trackstart {
- ;/trackstart <difference> <interval>
- var %diff $1, %secs $2
- ;avoid hammering the server, any more frequently wouldn't be very useful anyway
- if (%secs <= 10) var %secs 10
- ;if the difference is too low the bot might have more lines to send than flood limits allow
- if (%diff <= 10) var %diff 10
- if (!$hget(wtracker)) { hmake wtracker 300 | hadd wtracker silent 1 }
- hadd wtracker diff %diff
- .timerworldcheck 0 %secs checkpop
- .timerworldmsg 0 3 re_msg
- msg $active_channels Tracker booted up by $iif($nick, $nick, $me) checking for a difference of %diff players every $duration(%secs) $+ .
- }
- alias checkpop {
- if ($sock(checkpop).to > 10) cleanup checkpop
- elseif ($sock(checkpop)) return
- sockopen checkpop oldschool.runescape.com 80
- }
- ;<SReject>
- on *:sockopen:checkpop:{
- if ($sockerr) {
- echo -st World tracker sockopen sockerr: $sock($sockname).wsmsg
- cleanup $sockname
- }
- else {
- var %n = sockwrite -nt $sockname
- %n GET /slu HTTP/1.1
- %n Host: oldschool.runescape.com
- %n Connection: close
- %n Cache-control: no-cache
- %n
- var %age $calc($ctime - $hget(wtracker, time))
- hadd wtracker time $ctime
- if (!$hget(wtracker,silent)) { hadd wtracker silent $iif(%age > 600, $true, $false) }
- }
- }
- on *:SOCKWRITE:checkpop:{
- if ($sockerr) {
- echo -st World tracker sockwrite sockerr: $sock($sockname).wsmsg
- cleanup $sockname
- }
- }
- on *:SOCKREAD:checkpop:{
- if ($sockerr) {
- echo -st World tracker sockread sockerr: $sock($sockname).wsmsg
- cleanup $sockname
- }
- else {
- noop $hget($sockname, data, &data)
- sockread $sock($sockname).rq &read
- bcopy &data $calc($bvar(&data, 0) +1) &read 1 -1
- hadd -mb $sockname data &data
- }
- }
- on *:SOCKCLOSE:checkpop:{
- if ($sockerr) {
- echo -st World tracker sockclose sockerr: $sock($sockname).wsmsg
- }
- elseif (!$hget($sockname, data, &data)) {
- echo -st World tracker parse error: No Data recieved
- }
- ;; find end of headers
- elseif ($bfind(&data, 1, 13 10 13 10)) {
- var %body_start = $calc($v1 + 4)
- ;; check response status
- ;echo -s >> $bvar(&data, 1, 12).text
- if (HTTP/1.1 200 ?* !iswmcs $bvar(&data, 1, 14).text) {
- echo -st World tracker parse error: Server Response $bvar(&data, 1, $bfind(&data, 1, 13 10)).text
- }
- else {
- ;; find the <tbody tag and clip everything before it
- var %table_start = $bfind(&data, %body_start, <tbody)
- bcopy -c &data 1 &data %table_start -1
- ;; find the </tbody tag and clip everything after it
- var %table_end = $calc($bfind(&data, 1, </tbody) + 7)
- bcopy -c &data 1 &data 1 %table_end
- ;; write to file
- bwrite checkpop.txt 0 -1 &data
- filter -fk checkpop.txt check_filter *
- .copy -fo checkpop.txt checkpop_OLD.txt
- .remove checkpop.txt
- unset %checkpop_*
- if ($hget(wtracker,silent)) { hdel wtracker silent }
- }
- }
- else {
- echo -st World tracker parse error: Invalid response(No header truncation)
- }
- cleanup $sockname
- }
- alias -l cleanup {
- if ($sock($1)) sockclose $1
- if ($hget($1)) hfree $1
- unset %checkpop_*
- }
- ;</SReject>
- alias -l check_filter {
- tokenize 32 $fixtab($strip($1-))
- ;echo -a IS: $1-
- if (</tr> isin $1-) && (%checkpop_world) && (%checkpop_players) && ($timer(worldmsg)) {
- var %w = @rb_output
- if (!$window(%w)) { window -h %w }
- var %old = $hget(wtracker,%checkpop_world)
- var %diff $calc(%checkpop_players - %old)
- ; echo -a World %checkpop_world $+ : % $+ old = %old ---- % $+ diff = %diff ---- % $+ checkpop_players = %checkpop_players ---- $!hget(wtracker,diff) = $hget(wtracker,diff)
- hadd wtracker %checkpop_world %checkpop_players
- if (!$hget(wtracker, silent)) && (!$istok($ignored_worlds, %checkpop_world, 44)) && (%diff !== %old) && ($abs(%diff) >= $hget(wtracker,diff)) {
- aline -n %w World: %checkpop_world $+($chr(3), $iif($left(%diff,1) == -, 04, 03+), %diff, $chr(3)) $iif($show_total_players,( $+ %checkpop_players $+ )) $iif(%checkpop_class, $+ $v1) $iif(%checkpop_country, - $v1) $iif(%checkpop_pvp, - $v1) $iif(%checkpop_clan, - $v1)
- }
- unset %checkpop_*
- }
- if (<tr isin $1-) && (--pvp isin $1-) && ($show_pvp) { set %checkpop_pvp (7PVP) }
- if (<a id='* iswm $1-) && (*class='* iswm $1-) && (*href='* iswm $1-) {
- var %n = $remove($1-,</a>)
- set %checkpop_world $gettok(%n,$numtok(%n,32),32)
- }
- if ($regex($1-, /(\d+) players<\/td/i)) { set %checkpop_players $regml(1) }
- if (*country* iswm $1-) && ($show_country) { set %checkpop_country (6 $+ $nohtml($1-) $+ ) }
- if (*'>Members</td>* iswm $1-) && ($show_class) { set %checkpop_class (2P2P) }
- if (*'>Free</td>* iswm $1-) && ($show_class) { set %checkpop_class (5F2P) }
- if (*--country* !iswm $1-) && ($show_clan) && (*--type* !iswm $1-) && (*players</td>* !iswm $1-) && (*</td>* iswm $1-) && (*__row-cell* iswm $1-) {
- var %clan = $nohtml($1-)
- if (%clan !== -) { set %checkpop_clan (10 $+ %clan $+ ) }
- }
- }
- alias -l fixtab { return $replace($1-,$chr(9),$chr(32),$chr(10),$chr(32),$chr(13),$chr(32)) }
- alias -l nohtml { return $regsubex($1, /<[^>]+(?:>|$)|^[^<>]+>/g,) }
- alias re_msg {
- var %w = @rb_output
- if (!$window(%w)) || (!$line(%w,0)) || (!$timer(worldcheck)) || (!$timer(worldmsg)) { return }
- var %l = $line(%w,1)
- if (%l) { dline %w 1 | .msg $active_channels %l }
- }
Add Comment
Please, Sign In to add comment