My second working socket script, trying to keep it simple but fun to use. Tell me how you like it!
Syntax: fact (Feel free to change the syntax to whatever, "
fact" is probably taken already >_>)
on *:text:`fact*:#: {
if ($sock(funfact)) .sockclose funfact
set %chan $chan
sockopen funfact www.randomfunfacts.com 80
}
on *:SOCKOPEN:funfact: {
sockwrite -nt $sockname GET / HTTP/1.1
sockwrite -nt $sockname Host: www.randomfunfacts.com
sockwrite -nt $sockname $crlf
}
on *:SOCKREAD:funfact: {
if ($sockerr) {
msg %chan Socket Error: $sockname $+ . Error code: $sockerr Please inform $me of this error message.
halt
}
else {
var %sockreader
sockread %sockreader
if (*<td bordercolor="#FFFFFF"><font face="Verdana" size="4"><strong>* iswm %sockreader-2) {
noop $regex(%sockreader,/<i>(.*?)<\/i>/Si)
set %funfact $regml(1)
msg %chan %funfact
unset %sockreader*
unset %chan
sockclose $sockname
}
if ($len($remove(%sockreader,$chr(9),$chr(32))) > 0) {
var %x = 1
while (%x > -1) {
if ($len(%sockreader [ $+ [ $iif(%x != 0,$+(-,%x)) ] ]) <= 850) set %sockreader [ $+ [ $+(-,$calc(%x + 1)) ] ] %sockreader [ $+ [ $iif(%x != 0,$+(-,%x)) ] ]
dec %x
}
}
}
}
it almost looks like you are useing some messed up socket maker to make these. =/
no need for all them vars an whatnot you could have just done this
on $*:text:/^@fact$/iS:#: {
if ($sock(fact)) sockclose fact
sockopen fact www.randomfunfacts.com 80
sockmark fact msg #
}
on *:sockopen:fact: {
sockwrite -nt $sockname GET / HTTP/1.1
sockwrite -nt $sockname Host: $+($sock(fact).addr,$str($crlf,2))
}
on *:sockread:fact: {
var %fact | sockread %fact
if ($regex(%fact,/<i>(.+)<\/i>/)) {
$sock(fact).mark $regml(1)
sockclose fact
}
}