on *:TEXT:!rand:#:{
if ($isfile(top.txt)) .play $+(-nq10t,$ini(top.txt,$rand(1,$ini(top.txt,0)))) $nick top.txt 2000
else {
set %_top.txt $chan $nick
msg $chan Initializing quote file...
www.bash.org
}
}
on *:START: .timer 00:00 0 86400 www.bash.org
alias www.bash.org sockopen www.bash.org www.bash.org 80
on *:SOCKOPEN:www.bash.org:{
sockwrite -n $sockname GET ?top HTTP/1.1
sockwrite -n $sockname Host: www.bash.org
sockwrite $sockname $crlf
write -c top.html
}
on *:SOCKREAD:www.bash.org:{
var %string
if ($sockerr) return
while 1 {
sockread %string
if (!$sockbr) return
if ($numtok(%string,32) == 1) && ($base(%string,16,10) isnum) continue
if %string != $null write top.html $replace(%string, ,$chr(160),",")
}
}
on *:SOCKCLOSE:www.bash.org:{
var %line | ; Holds the working line
var %item = 0 | ; Ignore everything before the first quote
var %section = 1 | ; Used to create [sections]
var %i = 1 | ; Current line
window -nh @ 1
window -nh @ 2
loadbuf -r @ 1 top.html
while ($line(@ 1,%i)) {
%line = $ifmatch
if (!%item) && (*p class="quote"* iswm %line) %item = 1
elseif (</td></tr> == %line) break
if %item {
if %section {
if $regex(v1,%line,/(quote\.\"\>\<b\>\#[0-9]{1,}\<\/b\>)/) {
%section = 0
aline @ 2 $+($crlf,[,$gettok($gettok($regml(v1,1),2,35),1,60),])
}
elseif ($remove($replace(%line,&lt;,<,&gt;,>),<br />,</p>)) aline @ 2 $ifmatch
}
if (!%section) && $regex(v2,%line,/(\<p class=\"qt\"\>)/) {
%section = 1
%line = $remove($replace($mid(%line,$calc($regml(v2,1).pos + 14)),&lt;,<,&gt;,>),<br />,</p>)
if (%line) aline @ 2 %line
}
}
inc %i
}
savebuf @ 2 top.txt
write -dl1 top.txt
.remove top.html
close -@ @ *
if (%_top.txt) {
msg $gettok(%_top.txt,1,32) Quote file initialized...
.play $+(-nq10t,$ini(top.txt,$rand(1,$ini(top.txt,0)))) $gettok(%_top.txt,2,32) top.txt 2000
unset %_top.txt
}
}