All pastes #332226 Raw Edit

Untitled

public text v1 · immutable
#332226 ·published 2007-01-29 20:37 UTC
rendered paste body
on $*:TEXT:/^[!@](cash|price|pricecheck|gold)/Si:#:{
  if (!$2) {
    notice $nick *** [Price Guide]: You must supply a item - !price <item>
  }
  else {
    inc %q
    inc %time.price
    set %price.item. [ $+ [ %q ] ] $replace($2-,$chr(32),$chr(37) $+ 20)
    set %price.style. [ $+ [ %q ] ] $iif($left($1,1) == @,msg $chan,notice $nick) *** [Price Guide]:
    set %price.real. [ $+ [ %q ] ] $2-
    sockopen price. $+ %q zybez.net 80
  }
}
on *:SOCKOPEN:price.*:{
  sockwrite -nt $sockname GET /priceguide.php?search_terms= $+ %price.item. [ $+ [ %q ] ] $+ &search_area=1&price_low=&price_high=&member=1 HTTP/1.1
  sockwrite -nt $sockname Host: www.zybez.net
  sockwrite -nt $sockname $crlf $crlf
}
on *:SOCKREAD:price.*:{
  var %style = %price.style. [ $+ [ %q ] ], %item = %price.item. [ $+ [ %q ] ], %real = %price.real. [ $+ [ %q ] ]
  if ($sockerr) {
    %style An error occured while connecting
    clean.up %q
    sockclose $sockname
  }
  else {
    var %read
    sockread %read

    if (<td class="tablebottom" colspan="5">Your search did not return any results. Please make sure your spelling is correct and that you are typing full words.</td> isin %read) {
      %style No results were found for " $+ %real $+ "
      clean.up %q
      sockclose $sockname
    }
    elseif (<!--name--><td class='tablebottom'>*</td> iswm %read) {
      tokenize 32 $nohtml(%read)
      set %price.name. [ $+ [ %q ] ] $1-
    }
    elseif (<!--price--><td class="tablebottom">*</td> iswm %read) {
      tokenize 32 $nohtml(%read)
      set %price.price. [ $+ [ %q ] ] $1-
    }
    elseif (<td class="tablebottom"><a href="/priceguide.php?category=*">*</a></td> iswm %read) {
      tokenize 32 $nohtml(%read)
      set %price.cat. [ $+ [ %q ] ] $1-
    }
    if (%price.name. [ $+ [ %q ] ] && %price.price. [ $+ [ %q ] ] && %price.cat. [ $+ [ %q ] ]) {
      inc %price.times. [ $+ [ %q ] ]
      if (%price.times. [ $+ [ %q ] ] > 5) {
        %style Max results of 5 allowed. Try making your search for " $+ %real $+ " more specific.
        clean.up %q
        sockclose $sockname
      }
      elseif (%price.times. [ $+ [ %q ] ] < 5 || %price.times. [ $+ [ %q ] ] == 5) {
        %style Item - %price.name. [ $+ [ %q ] ] $&
          Price - %price.price. [ $+ [ %q ] ] $&
          Category - %price.cat. [ $+ [ %q ] ] $&
          Served - %time.price
        unset %price.name. [ $+ [ %q ] ]
        unset %price.price. [ $+ [ %q ] ]
        unset %price.cat. [ $+ [ %q ] ]
      }
    }
    if (</html> isin %read) {
      clean.up %q
      sockclose $sockname
    }
  }
}
alias -l clean.up {
  unset %price.*. [ $+ [ $1 ] ]
  sockclose price. $+ $1
  halt
}
alias -l nohtml {
  var %x,%i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x)
  %x = $replace(%x,&nbsp;,$null)
  return %x
}