RandomFunFacts.com Socket

By zak123 on Jun 15, 2009

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
}
}
}
}

Comments

Sign in to comment.
napa182   -  Jun 23, 2010

so true... most are flawed.

 Respond  
Jethro   -  Jun 23, 2010

Don't rely on those socket creators out there. They're flawed.

 Respond  
Raicho Ichisada   -  Jun 23, 2010

yep, looks like u use socket creator :P

 Respond  
zak123   -  Jun 15, 2009

Im not using a socket CREATOR, just a template, I dont know what I can abbreviate just yet, so once I get the hang of it I should be in the clear.

 Respond  
napa182   -  Jun 15, 2009

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 
  }
}
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.