Random Joke

By Stewie1k94 on Sep 28, 2011

I made this a while ago, changed it to a dialog, but I've changed it back to a trigger:

To use type: !rjoke

Example: > [2:21pm] <~Stewie> !rjoke
[2:21pm] <&thunderbolt> [Random Joke] A rather confident man walks into a bar and takes a seat next to a very attractive woman. He gives her a quick glance, then casually looks at his watch for a moment.The woman notices this and asks, "Is your date running late?""No," he replies, "I just bought this state-of-the-art watch and I was just testing it."The intrigued woman says, "A state-of-the-art watch? What's so special
[2:21pm] <&thunderbolt> about it?""It uses alpha waves to telepathically talk to me," he explains."What's it telling you now?" she asked."Well, it says you're not wearing any panties." he said.The woman giggles and replies, "Well it must be broken then because I am wearing panties!"The man explains, "Damn thing must be an hour fast."
[2:21pm] <~Stewie> !rjoke
[2:21pm] thunderbolt This command can only be used once ever 6 seconds.

alias -l NoHTML { 
  var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x,&nbsp;) 
  return %x
}
on $*:text:/^!rjoke( |$)/iS:#:{
  if ($($+(%,rjoke,$remove(#,$chr(35))),5) == $null) {
    set -u6 $+(%,rjoke,$remove(#,$chr(35))) flood
    rjoke msg #
  }
  else { .notice $nick This command can only be used once every 6 seconds. }
}
alias -l rjoke {
  if ($sock(rjoke)) sockclose rjoke
  sockopen rjoke www.randomfunnyjokes.com 80
  sockmark rjoke $1-2
}
on *:sockopen:rjoke:{
  sockwrite -nt rjoke GET / HTTP/1.0
  sockwrite -nt rjoke Host: $+($sock(rjoke).addr,$str($crlf,2))
}
on *:sockread:rjoke:{
  var %rjoke | sockread %rjoke
  if ($regex(%rjoke,/<font face="Verdana" size="2">(.+?)</font>/i)) {
    tokenize 32 $sock(rjoke).mark
    $gettok($sock(rjoke).mark,1-2,32) [Random Joke] $NoHTML($regml(1))
  }
}

Comments

Sign in to comment.
dma   -  Jan 20, 2016

thanks stewie i made a change in the colors

 Respond  
Stewie1k94   -  Nov 17, 2012

Changed!

 Respond  
justin-credible   -  Apr 20, 2012

i keep getting error on line 5

 Respond  
Stewie1k94   -  Sep 29, 2011

ok, thanks

 Respond  
Jethro   -  Sep 29, 2011

I'd like to suggest this website below that offers one-line joke, which I believe it's ideal. Keep the joke short but funny. I don't reckon people like to read a bunch of words in paragraph before they can grasp the meaning of and laugh at it.

http://www.jokesclean.com/OneLiner/Random/

P.S. This goes the same when you make a presentation in the public. You don't want people who listen to you to get bored in the middle of your speech as you drag on for too long. Just food for thought.

 Respond  
Jethro   -  Sep 29, 2011

Ask toclafane1 to convert my version into the dialog for you. :p

 Respond  
zNigel-   -  Sep 29, 2011

Cba updating tbh (:

OnT: Still cant get toclafane1's version of this to work at all.. does not even reply in the debug window.

 Respond  
Jethro   -  Sep 29, 2011

Yes, your version supports automatic message split for channel and PM.

Why are you still using 7.1? Not 7.19, the latest version available today? I urge you to upgrade at once.

 Respond  
zNigel-   -  Sep 29, 2011

aiight, so this is for which version? I'm running 7.1 ;o

 Respond  
Jethro   -  Sep 29, 2011

toclafane1, aren't you suppose to send a random joke to the channel? Now it's dialog based and for yourself to see only? Remember that some people are using older mIRC versions so the auto message split won't work for them. I'm pretty sure there are shorter random jokes out there you can take advantage of.

-edit- I see users may have to copy and paste the whole thing to the channel...

 Respond  
Stewie1k94   -  Sep 29, 2011

I changed it to a dialog, maybe that works better.

 Respond  
Stewie1k94   -  Sep 29, 2011

ummmm, there is msg split on mIRC already, you should make sure that's enabled, my version does work, i would never of posted it if i never seen it working. > [2:10pm] <~toclafane|away> !joke
[2:11pm] <&thunderbolt> An Irish man walks into a bar. The bartender looks at him and notices he has a steering wheel stuck down the front of his pants. "Hey," he says, "What's with the steering wheel down your pants?" "Ach," says the Irish man, "it's drivin' me nuts!" my version.

 Respond  
zNigel-   -  Sep 29, 2011

perhaps you should make it split the text in 2 if the input is too long

<- :NICKNAME@HOST PRIVMSG #carebox :!joke
-> port80a.se.quakenet.org PRIVMSG #carebox :After successfully passing the bar exam, a man opened his own law office. He was sitting idle at his desk when his secretary announced that a Mr. Jones had arrived to see him. "Show him right in!" our lawyer replied.As Mr. Jones was being ushered in, our lawyer had an idea. He quickly picked up the phone and shouted into it " ...and you tell them that we won't accept less then fifty thousand dollars, and don't even call me until you agree to that amount!" Slamming the phone down he stood up and greeted Mr. Jones; "Good Morning, Mr. Jones, what can I do for you?""I'm from the phone company," Mr. Jones replied, "I'm here to connect your phone."
<- :port80a.se.quakenet.org 417 NICKNAME :Input line was too long

edit: this is Jethro's version of the code. toclafne1's code didnt work at all for me.
edit2: Some texts even makes me excess flood

 Respond  
Stewie1k94   -  Sep 29, 2011

The reason i was using $nohtml was because, to get rid of the useless characters that should not of been there...and as for Jethro's advise, i like his demonstrations, as it's also teaching me some more

 Respond  
Jethro   -  Sep 28, 2011

Wims, I tend to offer my so-called advices by way of demonstration. Some people may not buy 'em much, but I like the idea of showing what you mean by what you say. (people who use English as a second language may not process the meaning out of you easily) As the saying goes, "a picture is worth a thousand words." I really don't give a flying F I make "enemies" as a result, unless you give out something sensible for me to agree upon. I'm not here to prove people wrong and be argumentative. I do, from time to time, admit my mistakes. Again, you have your own opinion toward this matter, and I have mine. Thanks for your constructive comment.

 Respond  
Wims   -  Sep 28, 2011

err ? the broswer has nothing to do with the problem, a socket is a socket and you are responsible for what you read and what you write to it: what you get from the socket is the same as what the browser get and what OP's script get, he was using $nohtml for a reason :p.
I also think that rewritting every code that are posted on this website is not necessary, giving advice is better than giving a whole new code and saying "use it", users can't learn that way. You also cannot do that on large script, which is why giving advice on the methods used (sockmark for example) is preferable imo :)

 Respond  
Jethro   -  Sep 28, 2011

If that's the case, this edit should do the trick:

on $*:text:/^!joke$/iS:*:{
  if (!$($+(%,fp,.,$site,.,#,.,$network),2)) { 
    inc -u3 $+(%,fp,.,$site,.,#,.,$network)
    var %j = joke. $+ $r(1,9999)
    sockopen %j www.randomfunnyjokes.com 80
    sockmark %j .msg $iif(#,#,$nick)
    halt
  }
  .notice $nick please wait at least 3 seconds before using $1 again!
  .ignore -cpu3 $nick 2
}
on *:sockopen:joke.*:{
  if ($sockerr) { 
    $sock($sockname).mark Error's Occurred! 
    halt 
  }
  sockwrite -nt $sockname GET / HTTP/1.0
  sockwrite -nt $sockname Connection: close
  sockwrite -nt $sockname Host: $+($sock($sockname).addr,$str($crlf,2))
}
on *:sockread:joke.*:{
  if ($sockerr) { 
    $sock($sockname).mark Error's Occurred! 
    halt 
  }
  var %joke 
  sockread %joke
  if (<br><br> isin %joke) { 
    $sock($sockname).mark $regsubex(%joke,/<[^>]*>|&.*/g,)
  }
}
 Respond  
Stewie1k94   -  Sep 28, 2011

i'm using Opera, used to use chrome

 Respond  
Jethro   -  Sep 28, 2011

What browser do you use? I use firefox and I don't get those html bits upon executing the script.

 Respond  
Stewie1k94   -  Sep 28, 2011

when i tryed your version > [11:44pm] <~toclafane> !joke
[11:44pm] <&thunderbolt>

Traffic was backed up for miles, the police were going car to car. When they got to my car I asked the officer what was going on.He said "It's Al Gore. He's up there threatening to set himself on fire! We are going car to car collecting donations.""Donations!" I said, "How much you got so far?"He said "about ten
[11:44pm] <&thunderbolt> gallons."
 
 Respond  
Jethro   -  Sep 28, 2011

Apologies, I was distracted. It did work. lol

Well, you really didn't need regex nor the alias. Here is my take on yours:

on $*:text:/^!joke$/iS:*:{
  if (!$($+(%,fp,.,$site,.,#,.,$network),2)) { 
    inc -u3 $+(%,fp,.,$site,.,#,.,$network)
    var %j = joke. $+ $r(1,9999)
    sockopen %j www.randomfunnyjokes.com 80
    sockmark %j .msg $iif(#,#,$nick)
    halt
  }
  .notice $nick please wait at least 3 seconds before using $1 again!
  .ignore -cpu3 $nick 2
}
on *:sockopen:joke.*:{
  if ($sockerr) { $sock($sockname).mark Connection Error's Occurred! | halt }
  sockwrite -nt $sockname GET / HTTP/1.1
  sockwrite -nt $sockname Connection: close
  sockwrite -nt $sockname Host: $+($sock($sockname).addr,$str($crlf,2))
}
on *:sockread:joke.*:{
  if ($sockerr) { $sock($sockname).mark Connection Error's Occurred! | halt }
  var %joke | sockread %joke
  if (<br><br> isin %joke) { $sock($sockname).mark $remove(%joke,$v1) }
}

I've taken the liberty of adding the trigger flood control and sockerr checks, making the script more secure if someone malicious wants to tamper with you, or the socket runs into errors.

You should learn about the use of sockmark so you don't have to rely on the global variable and then get it unset.

I've made it capable of listening to both channel and pm.

 Respond  
Stewie1k94   -  Sep 28, 2011

and yes i know that changing the host and source code, don't work as each website has it's own html code!!

 Respond  
Stewie1k94   -  Sep 28, 2011

yes i tested it, i wouldn't of posted it if never worked > [10:47pm] <~toclafane> !joke
[10:47pm] <&thunderbolt> A man walks into a drug store with his 8-year-old son. They happen to walk by the condom display, and the boy asks, "What are these, Dad?"The man matter-of-factly replies, "Those are called condoms, son. Men use them to have safe sex." "Oh I see," replied the boy. "I've heard of that in health class at school."He looks over the display and picks up a package of three and asks, "Why are
[10:47pm] <&thunderbolt> there three in this package."The dad replies, "Those are for high-school boys. One for Friday, one for Saturday, and one for Sunday." "Cool!" says the boy. He notices a pack of six and asks "Then who are these for?""Those are for college men," the dad answers, "Two for Friday, two for Saturday, and two for Sunday.""WOW!" exclaimed the boy. "Then who uses these?" he asks, picking up a
[10:47pm] <&thunderbolt> 12-pack.With a sigh, the dad replied, "Those are for married men. One for January, one for February, one for March..."

 Respond  
Jethro   -  Sep 28, 2011

Did you test your work before submitting it? I gave it a quick spin, and it didn't even do a thing. Most beginners think that by changing the host and the source code match will make it work for another website. That isn't quite the case.

 Respond  
Stewie1k94   -  Sep 28, 2011

and that's always how i lay out a socket, as it's the easiest way for me right now, i'm still learning :P

 Respond  
Stewie1k94   -  Sep 28, 2011

i used that to get rid of unnescerry characters inthe text

 Respond  
Jethro   -  Sep 28, 2011

It was a joke buddy. That's how they lay out their socket makers lol

I don't get why you need the generic nohtml alias when you use regex in the socketread. You only need to utilize either one of them.

 Respond  
Stewie1k94   -  Sep 28, 2011

no, i made it myself

 Respond  
Jethro   -  Sep 28, 2011

This looks like the one created from a socket maker. Everybody is making sockets these days. lol

 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.