Random Thought

By extremity on Jun 10, 2011

Well I was browsing for sites and found a random thought site with over 40k entries. So naturally, I am like.. let's make a little socket for it.

I didn't put in any code to turn it on or off, or many other features other than a flood protect preventing repeated use of command. I am waiting to see if it is liked enough to spend more time on it :/

Load it in remotes, either type /randomthought to activate it yourself .. or anyone can use !rt via the text event.

Only bug I see so far is a few ppl have posted to the site obscene or blank comments.

Input, thoughts, should I spend the extra few minutes to put a channel toggle, etc, etc?

on *:TEXT:!rt*:#: { randomthought }

alias randomthought {
  inc -u2 %rt.flood
  if (%rt.flood > 2) { halt }
  if ($sock(rt)) { sockclose rt }
  sockopen rt randomthoughts.ws 80
  sockmark rt #
}

on *:sockopen:rt: {
  if (!%rt.idx) set %rt.idx 44000
  set %rt.last $r(1,%rt.idx)
  sockwrite -n rt GET /page.php?lim= $+ %rt.last HTTP/1.1 $+($crlf, HOST: randomthoughts.ws, $str($crlf,3))
}

on *:sockread:rt: {
  sockread %rt | if (!%rt || $sockerr) { halt }
  if ($regex(%rt, /<a href="recent_comments.php">(.*)</i)) { set %rt.idx $remove($striphtml($regml(1)),$chr(44)) }
  elseif ($regex(%rt,/<h1>Random Thoughts(.*)<\/span/i)) { 
    msg $sock(rt).mark Random Thought of the Moment (# $+ %rt.last $+ ) : $striphtml($regml(1)) 
    sockclose rt 
  }
}

;not mine, couldn't write one shorter, credit to whoever
alias -l striphtml { return $regsubex($1-, /(<(?:.+?)>)/g, $null) }

Comments

Sign in to comment.
Jethro   -  Jun 11, 2011

lol jasonh_000, you can't expect every person online to type with the actual, correctly spelled vocabulary. "ur" is acceptable in many quick text messages. You'll see many abbreviations used, and I'm sure you already know that if you use iphone, Blackberry, Messengers, or any type of mobile devices...etc...especially IRC chat.

 Respond  
napa182   -  Jun 11, 2011

jasonh_000 Wrote:

"you also spelled random wrong in ur title. "

you spelled "your" wrong.
:D

@jasonh_000, did you make that comment to come off sounding like a smart-ass, or were you trying to be funny?

 Respond  
jasonh_000   -  Jun 11, 2011

"you also spelled random wrong in ur title. "

you spelled "your" wrong.
:D

 Respond  
blackvenomm666   -  Jun 10, 2011

nice jeth

 Respond  
Jethro   -  Jun 10, 2011

Extremity, they have a webpage for mobile, which is completely random. Here is my take on using it:

on *:text:$($iif(!rt = $strip($1),$1)):*:{
  if !%fc { inc -u4 %fc | $rt }
}
on *:sockopen:rt:{
  tokenize 94 $sock(rt).mark
  if !$sockerr {
    $1 GET /gadgets/mobile/index.php HTTP/1.1
    $1 Connection: close 
    $1 HOST: $+($sock(rt).addr,$str($crlf,2))
  }
  else { $3 Problem Connecting to $sock(rt).addr }
}
on *:sockclose:rt:{
  tokenize 94 $sock(rt).mark
  $3 Random Thought: $iif($hget(rt,3).item $hget(rt,3).data = $&
    a random thought:,I'm currently thoughtless; try me again in 4 secs...,$v1)
}
alias rt {
  if ($sock(rt)) sockclose rt 
  sockopen rt randomthoughts.ws 80
  sockmark rt $+(sockwrite -nt rt,^,scon -r hadd -mu4 rt,^,$&
    $+ $iif($isid,.msg $iif(#,#,$nick),echo -a))
}
on *:sockread:rt:{
  if !$sockerr {
    var %rt, %t /(.*)(<\/b>|<br\/>)/i
    sockread %rt | if $regex(%rt,%t) {
      tokenize 62 $regml(1)
      $gettok($sock(rt).mark,2,94) $!remove( $* ,<b style="color:red;",<b)
    }
  }
  else {
    tokenize 94 $sock(rt).mark 
    $3 Problem Reading $sock(rt).addr
  }
}
!rt Random Thought: Is this your life? What do you choose to make it? Sex with a random girl/guy. Drugs and alcohol on the weekends. Life is so much more.... What will you choose to make it. When will you trust God? !rt Random Thought: I'm currently thoughtless; try me again... !rt Random Thought: I wonder if when my cat runs across my face at night scratching me
 Respond  
napa182   -  Jun 10, 2011

an yes i concur with Jethro_ about "Looks can be deceiving."

anyways extremity, you have a lot of unneeded code within this socket that you may want to remove, and clean it up some. 4/10
you also spelled random wrong in ur title. you have it as Randm you may want to fix that ;x

 Respond  
Jethro   -  Jun 10, 2011

Blackvenomm666, as the saying goes, "Looks can be deceiving."

Excuse me, extremity. :P

 Respond  
blackvenomm666   -  Jun 10, 2011

looks good

 Respond  
extremity   -  Jun 10, 2011

I just noticed how the number of thoughts changes from page to page.

44,000 was just the initial number. The socket updates the rt.idx which is the $r value after the socket runs once. But you are right Jethro, I am grabbing the wrong number. I will update to set the initial $r to 40,000 and have the sockread fetch the number of thoughts and not the number of comments.

 Respond  
Jethro   -  Jun 10, 2011

If that's the case, perhaps it's better to locate the line of thought statistic and make the socket out of it to ensure you have the right amount of thoughts to randomize. There are chances you may get "thoughtless." 44000 is an approximate figure in this snippet.

 Respond  
Memoli   -  Jun 10, 2011

Because everyone can add new thoughts

 Respond  
Jethro   -  Jun 10, 2011

I've visted the website, and it gives the randomly generated info about how many random thoughts they offer. Every time you reload the page, it gives you a different statistic.

 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.