Skip to content

Instantly share code, notes, and snippets.

@uniacid
Last active August 29, 2015 14:04
Show Gist options
  • Save uniacid/94e18ba164af6ed3d916 to your computer and use it in GitHub Desktop.
Save uniacid/94e18ba164af6ed3d916 to your computer and use it in GitHub Desktop.
on *:TEXT:.random:#: {
sockclose sick
sockopen sick www.sickipedia.org 80
set %sick.chan $chan
}
alias sick {
sockopen sick www.sickipedia.org 80
set %sick.chan $chan
}
on *:sockopen:sick: {
sockwrite -n $sockname GET /ajax/getjokes/random HTTP/1.0
sockwrite -n $sockname Host: www.sickipedia.org
sockwrite -n $sockname Connection: close
sockwrite -n $sockname $crlf
}
on *:sockread:sick: {
sockread %sick.result
while ($sockbr) {
if (<section class="jokeText shortJokeText" itemprop="text"> isin %sick.result) && (%sick.chan) {
set -l %sick.joke $null
set -l %escape 0
while (</section> !isin %sick.result) {
if (id='shortText isin %l) set -l %sick.skip on
elseif (id='fullText isin %l) unset %sick.skip
if (!%skip) set -l %sick.joke %sick.joke $parsehtml(%sick.result)
sockread %sick.result
inc %escape
if (%escape > 2000) { echo -a escaped | break }
}
msg %sick.chan %sick.joke
unset %sick.*
}
sockread %sick.result
}
}
alias -l parsehtml {
set -l %temp $regsubex($1,/<[^>]+[>$]>?/g,)
while ($regex(%temp,/&#(3[2-9]|[4-9]\d|1\d{2}|2[0-4]\d|25[0-5]);/)) set -l %temp $replacex(%temp,$+(&#,$regml(1),;),$chr($regml(1)))
set -l %finished $replacex(%temp,&nbsp;,$chr(160),&quot;,",&middot;,·,&lt;,<,&gt;,>,&amp;,&)
return %finished
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment