All pastes #2109889 Raw Edit

Miscellany

public text v1 · immutable
#2109889 ·published 2012-02-05 09:15 UTC
rendered paste body
;!@uncyclopedia 
;Uncyclopedia Search Script by Ford_Lawnmower -- irc.mindforge.org #USA-Chat
menu Channel,Status {
  .$iif($group(#uncyclopedia) == On,$style(1)) Uncyclopedia uncyclopedia Trigger
  ..$iif($group(#uncyclopedia) == On,$style(2)) On: .enable #uncyclopedia
  ..$iif($group(#uncyclopedia) == Off,$style(2)) Off: .disable #uncyclopedia
}
#uncyclopedia on
on $*:text:/^[@!.](uncyclopedia|uncyclo)/Si:#:{
  if ($timer($+(uncyclopedia,$network,$nick))) { return }
  .timer $+ $+(uncyclopedia,$network,$nick) 1 4 noop
  var %method $iif($regml(1) == !,.notice $nick,$iif($regex($nick($chan,$nick).pnick,/(~|&|@|%)/),.msg $chan,.notice $nick))
  uncyclopediaS %method $2-
}
#uncyclopedia end
alias uncyclopedia { uncyclopediaS echo -a $1- }
alias -l uncyclopediaS {
  $1-2 Searching.......
  var %sockname $+(uncyclopediaS,$network,$2,$ticks)
  sockopen %sockname uncyclopedia.wikia.com 80
  sockmark %sockname $1-2 $iif($3,$+(/wiki/Special:Search/,$replace($3-,$chr(32),+)),/wiki/Special:Random) 0 $iif(!$3,1,0)
}
alias -l uncyclopediaR {
  var %sockname $+(uncyclopediaR,$network,$2,$ticks)
  sockopen %sockname uncyclopedia.wikia.com 80
  sockmark %sockname $1-2 $+(/wiki/,$3) 0 $iif($4,1,0)
}
On *:sockopen:uncyclopedia*: {
  if (!$sockerr) {
    sockwrite -nt $sockname GET $gettok($sock($sockname).mark,3,32) HTTP/1.0
    sockwrite -n $sockname Host: uncyclopedia.wikia.com
    sockwrite -n $sockname $crlf
  }
  else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
}
On *:sockread:uncyclopediaS*: {
  if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  else {
    var %uncyclopediaS | sockread %uncyclopediaS
    if (Page title matches isincs %uncyclopediaS) { sockmark $sockname $puttok($sock($sockname).mark,1,4,32) }
    if (Page text matches isincs %uncyclopediaS) { sockmark $sockname $puttok($sock($sockname).mark,1,4,32) }    
    if ($gettok($sock($sockname).mark,4,32)) && ($regex(%uncyclopediaS,/\Q<li><a href="/wiki/\E(.*)\Q" title="\E/)) {
      uncyclopediaR $gettok($sock($sockname).mark,1-2,32) $regml(1) 
      sockclose $sockname
      return
    }
    if (Location: isin %uncyclopediaS) {
      uncyclopediaR $gettok($sock($sockname).mark,1-2,32) $nopath(%uncyclopediaS) $gettok($sock($sockname).mark,5,32)
      sockclose $sockname
      return
    }
  }
}
On *:sockread:uncyclopediaR*: {
  if ($sockerr) { echo -st socket error $nopath($script) }
  else {
    var %uncyclopediaR | sockread %uncyclopediaR
    if (*<p>*<b>* iswm %uncyclopediaR) { 
      sockmark $sockname $puttok($sock($sockname).mark,$calc($gettok($sock($sockname).mark,4,32) + 1),4,32) 
    }
    if ($gettok($sock($sockname).mark,4,32)) && ($httpstrip(%uncyclopediaR)) { 
      put $gettok($sock($sockname).mark,1-2,32) $v1 $+(,http://uncyclopedia.wikia.com,$gettok($sock($sockname).mark,3,32))
      sockclose $sockname
      return
    }
  }
}
On *:sockclose:uncyclopedia*: {
  if ($gettok($sock($sockname).mark,5,32)) && (uncyclopediaR* iswm $sockname) { uncyclopediaS $gettok($sock($sockname).mark,1-2,32) }
  else { $gettok($sock($sockname).mark,1-2,32) Sorry No results found for your Search }
}
alias -l httpstrip { var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x) | return $remove($replace(%x,&amp;,&),&nbsp;,&mdash;) }
alias -l Put {
  if (!$regex($1,/(\.|^)(msg|notice|echo)$/Si)) || (!$3) { echo -st **Put error** Syntax /Put msg #channel text - or - /Put notice nickname text  | return }
  tokenize 32 $regsubex($1-,/([$\|%\[\]\}\{][^\s]*)/g,$+($chr(2),$chr(2),\t))
  var %tokens $0, %Tstart 3, %Dtimer 1500
  if ($timer($+(Put,$2,$network)).secs) { %Dtimer = $calc($v1 * 1000) }  
  while ($len($($+($,%Tstart,-,%tokens),2)) > 430) {
    dec %tokens
    if ($len($($+($,%Tstart,-,%tokens),2)) <= 430) {
      .timer -m 1 %Dtimer $1-2 $($+($,%Tstart,-,%tokens),2))
      inc %Dtimer 1500
      %Tstart = $calc(%tokens + 1)
      %tokens = $0
    }
  }
  .timer -m 1 %Dtimer $1-2 $($+($,%Tstart,-,%tokens),2))
  .timer $+ $+(Put,$2,$network) -m 1 $calc(%Dtimer + 1500) noop 
}