i learned sockets like last week and made this :D
gets a random quote from www.4q.cc bout chuck norris
comment/rate :D
and p.s. i no someone would have bitched bout it: i didnt make the $htmlfree got it from a socket tut. http://www.mirc.net/tutorial.php?file=sockets[05-24][1057960975].zip
on $*:TEXT:/^[!.@]chuck/Si:#: {
if ($sock(chuck)) sockclose chuck
sockopen chuck 4q.cc 80
set %chuck.msg $iif($mid($1,1,1) == $chr(64),msg #,.notice $nick)
}
on *:sockopen:chuck: {
if ($sockerr) HALT
else {
sockwrite -n $sockname GET /index.php?pid=fact&person=chuck HTTP/1.1
sockwrite -n $sockname HOST: 4q.cc
sockwrite -n $sockname $crlf
}
}
on *:sockread:chuck: {
if ($sockerr) HALT
else {
sockread %chuck
if ((*</div>* iswm %chuck) && (Chuck Norris isin %chuck)) {
%chuck.msg 12[04CHUCK NORRIS12] $replace($htmlfree(%chuck),$quot;,")
}
}
}
alias -l htmlfree { var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, ) | return %x }
No one is attempting to seem cool Solitude. You are an obvious Noob that has no idea what he/she is talking about. It is clear that you know nothing about sockets.
I was just trying to help you.
There are no magic tricks here Solitude.
Every site is unique and has to be parsed individually. There is no /browse function in mIRC.
By the way Solitude. This post is about Random Chuck Norris fact. If you need help that is not related to this script, you should be posting it in the help forum ;/
I never said I wanted it to specifically connect to that site o_o; I was talking in general. So how about you stop attempting to seem cool by making pointless code? lol.
I just mean, if the script were meant to connect to say, a dictionary website, and /browse was the part to enter the word you wish to find a definition for in, and $2 being that word (input by the user)? Would it work to do that?
I don't think that site has a /browse/ and $2 does not exist at that point in the script.
4q.cc is just a web site. It just does what it does ;/
If you go to the website you will see it has chuck norris, vin diesel, mr. T and All. You could add vin diesel, mr T and all if you changed the script a little.
on $*:TEXT:/^[!.@](chuck|vin|mrt|all)/Si:#: {
if ($sock(chuck)) sockclose chuck
sockopen chuck 4q.cc 80
sockmark chuck $regml(1) 0
set %chuck.msg $iif($mid($1,1,1) == $chr(64),msg #,.notice $nick)
}
on *:sockopen:chuck: {
if ($sockerr) HALT
else {
sockwrite -n $sockname GET $+(/index.php?pid=fact&person=,$gettok($sock($sockname).mark,1,32)) HTTP/1.1
sockwrite -n $sockname HOST: 4q.cc
sockwrite -n $sockname $crlf
}
}
on *:sockread:chuck: {
if ($sockerr) HALT
else {
sockread %chuck
if (<div id="factbox"> isin %chuck) { sockmark $sockname $puttok($sock($sockname).mark,1,2,32) }
if (*</div>* iswm %chuck) && ($gettok($sock($sockname).mark,2,32)) {
%chuck.msg $+(12[04,$upper($gettok($sock($sockname).mark,1,32)),12]) $replace($htmlfree(%chuck),",")
unset %chuck.*
sockclose $sockname
}
}
}
alias -l htmlfree { var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, ) | return %x }
With this you could search !chuck !vin !mrt or !all
I don't think the site has anymore than that ;/
Instead of
if ($sock(chuck)) sockclose chuck
, you could do:
if (!$sock(chuck))
and then continue what you were doing. After sockread (when the file reaches its end), the sock always closes.
You could also use /sockmark instead of a variable.
So you can replace
set %chuck.msg $iif($mid($1,1,1) == $chr(64),msg #,.notice $nick)
with
sockmark chuck $iif($mid($1,1,1) == $chr(64),msg #,.notice $nick)
and then
%chuck.msg 12[04CHUCK NORRIS12] $replace($htmlfree(%chuck),$quot;,")
with
$sock(chuck).mark 12[04CHUCK NORRIS12] $replace($htmlfree(%chuck),$quot;,")
.
Also:
if ($sockerr) HALT
in the sockopen.
You can't have an error in the socket if you haven't even asked the socket for anything, so you can take that out of the sockopen.
May I inquire what
$mid($1,1,1) == $chr(64)
is?
Otherwise, nice small socket script.
Edit: I've realized that /sockclose may be necessary since the site is running a little slow (for me that is).