Public feed #528790

Mine

public text v1 · immutable
Raw Edit
·published 2007-06-01 17:57 UTC
rendered paste body
on $*:TEXT:/^[!@]((poke)?dex|entry)( .+)?$/Si:#:{
  if ((Chesticles ison $chan) && ($me != Chesticles)) { halt }
  elseif (!$2) { .notice $nick You must specify something to search for. }
  elseif ($3) { .notice $nick The command is only 2 words. The pokemon's name must be 1 word long. }
  else {
    var %x = 1
    :loop
    if ($sock($+(Dex.,%x))) {
      inc %x
      goto loop
    }
    else {
      set $+(%,dex.search.,%x) $2
      set $+(%,dex.msg.,%x) $iif(@* iswm $1,msg $chan,.notice $nick)
      sockopen $+(Dex,.,%x) www.serebii.net 80
    }
  }
} 


on *:SOCKOPEN:Dex.*:{
  sockwrite -nt $sockname GET /pokedex-dp/ HTTP/1.1
  sockwrite -nt $sockname Host: www.serebii.net
  sockwrite -nt $sockname $crlf
}


on *:SOCKREAD:Dex.*:{
  var %x = $gettok($sockname,2,46)
  var %search = $($+(%,dex.search.,%x),2), %msg = $($+(%,dex.msg.,%x),2)
  var %regex = /<option value="(.+)">([0-9]{3}) $(%search,2)/
  if ($sockerr) {
    write SockErr.txt $sockerr
    echo -a Socket Error - Check SockErr.txt
    halt
  }
  var %read
  sockread %read
  if ($regex(%read,%regex)) {
    %msg Entry for $+(%search,:) $+(http://www.serebii.net,$regml(1))
    cleanup %x
  }
  elseif (*Most Pokémon* iswm %read) {
    %msg No entry for $qt(%search) was found.
    cleanup %x
  }
} 


alias -l cleanup {
  unset $+(%,dex.*.,$1)
  sockclose $+(Dex.,$1)
}