Last active
August 29, 2015 14:04
-
-
Save uniacid/94e18ba164af6ed3d916 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, ,$chr(160),",",·,·,<,<,>,>,&,&) | |
return %finished | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment