Random Jokes Plus Facts

By Jethro on Jul 05, 2012

This work below is yet another forum request that I've decided to submit as a part of my snippet collection. For those who find this snippet useful, It's for the bot client, and the trigger is either !facts, @facts, .facts or !jokes, @jokes, .jokes.

on $*:text:/^[!@.](fact|joke)s$/iS:#:{
  if (!%f) { 
    inc -u3 %f
    var %s = $+(rjf,$str($ticks,2),$site)
    if ($sock(%s)) sockclose $v1
    sockopen %s www.randomfunfacts.com 80
    sockmark %s .msg # $regml(1)
  }
}
on *:sockclose:rjf*:{
  tokenize 32 $sock($sockname).mark
  var %s = $+(rjf,$str($ticks,2),$site)
  if ($sock(%s)) sockclose $v1
  sockopen %s www.jokesclean.com 80
  sockmark %s $1-2
}
on *:sockopen:rjf*:{
  tokenize 32 $sock($sockname).mark
  if ($sockerr) {
    $1-2 Error: Connection Issue...
    sockclose $sockname
  }
  else {
    if ($3 == fact) {
      var %rjf = sockwrite -nt $sockname
      %rjf GET / HTTP/1.1
      %rjf Connection: close
      %rjf Host: $+($sock($sockname).addr,$str($crlf,2))
    }
    else {
      var %rjf = sockwrite -nt $sockname
      %rjf GET /OneLiner/Random/ HTTP/1.0
      %rjf Host: $+($sock($sockname).addr,$str($crlf,2))
    }
  }
}
on *:sockread:rjf*:{
  tokenize 32 $sock($sockname).mark
  if ($sockerr) {
    $1-2 Error: Issues in Reading...
    sockclose $sockname
    halt
  }
  goto $iif($3 == fact,fact,joke)
  :fact
  sockread &rjf
  var %info = $regsubex($bvar(&rjf,1-).text,/<[^>]*>|\t$&
    $+ RLOpenInNewWindow|"1";|var RLRepeatKeywords/g,$chr(32))
  if ($gettok($replace(%info,&nbsp;,$chr(94)),2,94)) {
    $1-2 $remove($gettok($v1,11-,32),24c6)
    sockclose $sockname | halt
    :joke
    var %jokes
    sockread %jokes
    if ($regex(%jokes,/(.*)<\/font><\/p>/)) {
      $sock($sockname).mark $replace($gettok($regml(1),3-,62),&nbsp;,$chr(32))
      sockclose $sockname
    }
    halt
  }
}

Comments

Sign in to comment.
TUSK3N   -  Mar 18, 2016

the !facts command work but it will only take the first words in a sentence and not complete it, can someone look at it? I am using this in mirc for twitch chat.

 Respond  
Blasman   -  Dec 14, 2015

The !jokes part still works well. However, the !facts command will only return the first 27 characters of the random fact. Any idea on how to have it display the entire random fact? Thanks!

Example:
A giraffe has a 20-inch ton
The U.S. ranks 29th in over
"Tom Sawyer" was the first
The world's largest amphibi

 Respond  
dma   -  Dec 13, 2015

still working in 2015

 Respond  
nate88   -  Dec 05, 2013

I sometimes get /msg: insufficient parameters (line 50, remote.ini)

Line 50: $1-2 $remove($gettok($v1,11-,32),24c6)

Any idea how to fix this or what may be causing the issue?

The output appears like this:
<&JokeBot> Quiz -

 Respond  
pereba   -  Oct 25, 2013
@facts Approximately 90% of household dust is made up of dead skin cells. 1f27 How to get rid this extra line "1f27" ?
 Respond  
Menteroth   -  Oct 07, 2013

How can I change the output to channel?
I tried changing "sockmark %s .msg # $regml(1)" to like "sockmark %s .msg # Fun Fact: $regml(1)" but it didn't work.

blackvenomm666  -  Oct 07, 2013

it is already set to msg the channel

Menteroth  -  Oct 07, 2013

I know but I want to add "Fun Fact:" in front of the message. you didn't read my question properly. :)

Yawhatnever  -  Oct 07, 2013

You didn't phrase the question very well.

$regml(1) on line 7 would contain either "joke" or "fact". The script needs to know that later. That's not where you should be making changes.

They tokenized $sock($sockname).mark on line 18, so $1-2 contains '.msg #'. I haven't fully examined the script, but I believe you should be focusing on lines 50 & 56.

Menteroth  -  Oct 08, 2013

How would you phrase the qestion instead of "How can I change the output to channel?"?

And you obviously saw I was tampering with the wrong line in the script. I don't see anything wrong with the question itself though.
I am not very good at scripting so of course I made that mistake.

Ah okay. Thanks. Not even sure where I can add the extra text that I want there either. I'll just try randomly and see what works.

Edit: Added the extra text I wanted with some random testing. Thanks for pointing out which lines.

Menteroth  -  Oct 08, 2013

it does give me "1F27 Unknown command"
when I added " $1-2 Fun fact: $remove($gettok($v1,11-,32),24c6)" on line 50 though.
but still sends what I want to the channel.

(10:29:14) (menteroth) !facts
(10:29:15) (mentbot) Fun fact: The human eye blinks an average of 4,200,000 times a year.

Sign in to comment

Dani_l11   -  Nov 26, 2012

$str($ticks,2)

Why? Isn't $ticks as much random as $str($ticks,2)
$r(0,9) is as much random as $str($r(0,9),2) or am I missing something"?

Klim:
Edit the first line to
on $*:text:/^!@.s$/iS:#:{

 Respond  
WorldDMT   -  Nov 22, 2012

hehehe busy :p

 Respond  
Jethro   -  Nov 21, 2012

Thank you, WorldDMT. Wait a minute...where have you been all my life? :p

 Respond  
WorldDMT   -  Nov 19, 2012

nice job dude ;)

 Respond  
Jethro   -  Jul 15, 2012

Kilim, the jokes command is to trigger the joke part of the script. By removing it, the script will cease to send a random line of joke.

 Respond  
Kilim   -  Jul 15, 2012

Excellent Jethro. Is there anyway to remove the !jokes command from this though? I tried going through the code myself but your code is a little too advanced for me to go through editing. If not, anyway thanks for the great script!

 Respond  
blackvenomm666   -  Jul 09, 2012

+like looks good jeth

 Respond  
Jethro   -  Jul 08, 2012

Much obliged!

 Respond  
Stewie1k94   -  Jul 08, 2012

Liked your comment and your Snippet. :)

 Respond  
Jethro   -  Jul 07, 2012

Thank you. Please give me a like for the support of my work.

 Respond  
Stewie1k94   -  Jul 07, 2012

Great Snippet Jethro. Very useful (for me) :P

 Respond  
RIcko   -  Jul 05, 2012

thanks for bringing this into public, no same results anymore :P

 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.