Random Chuck Norris fact

By sunslayer on Mar 02, 2009

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,&nbsp;) | return %x }

Comments

Sign in to comment.
FordLawnmower   -  Jul 14, 2009

Ok Solitude :) I just misunderstood your first question because I assumed it was related to this post. Sorry for the confusion :(

 Respond  
Solitude   -  Jul 14, 2009

At least that comment was actually helpful -! Thanks. And I know mIRC has no /browse command. And uh, I don't know about sockets lol, I'm trying to learn.

 Respond  
FordLawnmower   -  Jul 14, 2009

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 ;/

 Respond  
Solitude   -  Jul 14, 2009

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?

 Respond  
FordLawnmower   -  Jul 14, 2009

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),&quot;,")
      unset %chuck.*
      sockclose $sockname
    } 
  } 
}
alias -l htmlfree { var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x,&nbsp;) | return %x }

With this you could search !chuck !vin !mrt or !all
I don't think the site has anymore than that ;/

 Respond  
Solitude   -  Jul 14, 2009

Would it work on something like this, if you were to do..

 sockwrite -n $sockname GET /browse/$2 HTTP/1.1 

With $2 obviously being the second parameter in the users input? like..

.search blah

Being 'blah'? To make it /browse/blah?

 Respond  
sunslayer   -  Jul 03, 2009

the color of the nick? try ALT+B and click Nick Colors other wise i dont get wat u mean

 Respond  
Etalyx   -  Jul 02, 2009

No I meant the actual nickname in the chat. Like, the person/nick actually saying it.

 Respond  
sunslayer   -  Jul 02, 2009
 12[04CHUCK NORRIS12]

change the numbers to w/e combo u want

 Respond  
Etalyx   -  Jul 01, 2009

Works great for me! But I'm curious, how do you get the nickname to change colors in the chat? It turns maroon. Thanks. :D

 Respond  
^Neptune   -  May 31, 2009
$mid($1,1,1) == $chr(64) 

The obvious choice would have been to use $left, but ok.

 Respond  
sunslayer   -  May 31, 2009

L ty minicruzer :p

 Respond  
miniCruzer   -  May 30, 2009

I love it!!!

 Respond  
Kirby   -  Mar 12, 2009

It works for me too.
I found nothing wrong with it.

 Respond  
sunslayer   -  Mar 12, 2009

hmm dunno works fine for me :/

only thing i can think of is upgrade ur version of mIRC

 Respond  
jeesus   -  Mar 09, 2009

Doesn't work for me. :S No errors either.

 Respond  
sunslayer   -  Mar 03, 2009

thanks for the suggestions

May I inquire what Code:

$mid($1,1,1) == $chr(64) 

is?

if the first letter of $1 is @ then it messages the chan instead of noticing the nick

 Respond  
Kirby   -  Mar 02, 2009

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).

 Respond  
TheNitelyfe   -  Mar 02, 2009

Naise

 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.