My final socket... Geez, these things are fun to play with once you learn how to use them correctly...
Usage: `pun
on *:text:`pun*:#: {
if ($sock(pun)) .sockclose pun
set %chan $chan
sockopen pun www.punoftheday.com 80
}
on *:SOCKOPEN:pun: {
sockwrite -nt $sockname GET /cgi-bin/randompun.pl HTTP/1.1
sockwrite -nt $sockname Host: www.punoftheday.com
sockwrite -nt $sockname $crlf
}
on *:SOCKREAD:pun: {
if ($sockerr) {
msg %chan Socket Error: $sockname $+ . Error code: $sockerr Please inform $me of this error message.
halt
}
else {
var %sockreader
sockread %sockreader
if (*<div class="dropshadow1">* iswm %sockreader-1) {
noop $regex(%sockreader,/<p>(.*?)<\/p>/Si)
set %pun $regml(1)
msg %chan %pun
unset %sockreader*
unset %chan
sockclose $sockname
}
if ($len($remove(%sockreader,$chr(9),$chr(32))) > 0) {
var %x = 0
while (%x > -1) {
if ($len(%sockreader [ $+ [ $iif(%x != 0,$+(-,%x)) ] ]) <= 850) set %sockreader [ $+ [ $+(-,$calc(%x + 1)) ] ] %sockreader [ $+ [ $iif(%x != 0,$+(-,%x)) ] ]
dec %x
}
}
}
}
you can just do somthing like this
on $*:text:/^@pun$/iS:#: {
if (!%f) {
inc -u3 %f
if ($sock(pun)) sockclose pun
sockopen pun www.punoftheday.com 80
sockmark pun msg #
}
}
on *:sockopen:pun: {
sockwrite -nt $sockname GET /cgi-bin/randompun.pl HTTP/1.1
sockwrite -nt $sockname Host: $+($sock(pun).addr,$str($crlf,2))
}
on *:sockread:pun: {
var %pun | sockread %pun
if ($regex(%pun,/<p>(.+)<\/p>/)) {
$sock(pun).mark $regml(1)
sockclose pun
}
}