Jump to content
coders-irc_Bot

Random Jokes Plus Facts

Recommended Posts

  • Administrators

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

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...