All pastes #370233 Raw Edit

clan lookup

public text v1 · immutable
#370233 ·published 2007-02-24 11:43 UTC
rendered paste body
alias col1 { return $+( $1-,04) }
alias col2 { return $+( $1-,02) } 
on *:TEXT:?clan*:#:{
  if (!$2) {
    notice $nick *** [ $+ $col1(Clan) $+ $col2(]: You must supply a name)
    halt
  }
  elseif ($2 == zezima || $2 == n0valyfe) {
    notice $nick *** [$+ $col1(Clan) $+ $col2(]: You are not aloud to do that)
  }
  else {
    inc %x 1
    set %clan.name. [ $+ [ %x ] ] $replace($2- ,$chr(32),+)
    set %clan.style. [ $+ [ %x ] ] $iif($left($1,1) == @,msg $chan,.notice $nick)
    sockopen clan. $+ %x runehead.com 80
  }
}
on *:SOCKOPEN:clan.*:{
  sockwrite -n $sockname GET /clans/search.php?search= $+ %clan.name. [ $+ [ %x ] ] $+ &searchtype=exact
  sockwrite -n $sockname Host: $+(www.runehead.com,$crlf,$crlf)   
}
on *:SOCKREAD:clan.*:{
  if ($sockerr) {
    %clan.style. [ $+ [ %x ] ] *** [ $+ $col1(Clan) $+ $col2(]: Error while connecting)
    sockclose $sockname
    halt
  }
  else {
    var %tmp
    sockread %tmp

    if $regex(results,%tmp,/<p>No results were found for the <b>exact</b> search <b>(.*)</b/) {
      %clan.style. [ $+ [ %x ] ] *** [ $+ $col1(Clan) $+ $col2(]: %clan.name. [ $+ [ %x ] ]) $col1(is not in any clans on) $col2(RuneHead)
      sockclose $sockname
      halt
    }
    elseif $regex(results,%tmp,/<p>The <b>exact<\/b> search <b>(.*)<\/b> returned <b>(\d+)/) {
      %clan.style. [ $+ [ %x ] ] *** [ $+ $col1(Clan) $+ $col2(]: $regml(results,2)) $col1(result(s) were found for) $col2(%clan.name. [ $+ [ %x ] ])
    }
    if $regex(clan,%tmp,/<td style='width:90px; border-color:#404040;'><a href='(.*)'>(.*)</a></td>/) { 
      %clan.style. [ $+ [ %x ] ] *** [ $+ $col1(Clan) $+ $col2(]: %clan.name. [ $+ [ %x ] ]) $col1(is in clan:) $col2($regml(clan,2)) $col1($+(http://runehead.com/clans/,$regml(clan,1)))
    }
    if </html> iswm %tmp {
      sockclose $sockname
    }
  }
}
on *:SOCKCLOSE:clan.*:{
  unset %clan.*
  halt
}