All pastes #924832 Raw Edit

Urbandictionary.com

public text v1 · immutable
·published 2008-03-01 19:32 UTC
rendered paste body
On $*:Text:/^[@!]Urban/Si:#:{
  If ($Sock($+(Urban.,$Nick))) {
    Sockclose $+(Urban.,$Nick)
  }
  Sockopen $+(Urban.,$Nick) www.urbandictionary.com 80
  Sockmark $+(Urban.,$Nick) $Urlencode($2-)
}
Alias Urban {
  If ($Sock($+(Urban.,$Me))) {
    Sockclose $+(Urban.,$Me)
  }
  Sockopen $+(Urban.,$Me) www.urbandictionary.com 80
  Sockmark $+(Urban.,$Me) $Urlencode($1-)
}
On *:Sockopen:Urban.*:{
  Sockwrite -nt $Sockname GET /define.php?term= $+ $Sock($Sockname).Mark HTTP/1.0
  Sockwrite -nt $Sockname Host: www.urbandictionary.com
  Sockwrite -nt $Sockname $Crlf
}
On *:Sockread:Urban.*:{
  Sockread %Urban
  If (!%Text) {
    If ($Regex(%Urban,<p>(.*?)</p>)) {
      Set -u5 %Text $Htmlfree($Regml(1))
    }
  }
  If (!%Author) {
    If $Regex(%Urban,author=(.*?)">) {
      Set -u5 %Author $Regml(1)
    }
  }
  If (!%Term) {
    If ($Regex(%Urban,<td class="def_word">(.*?)</td>)) {
      Set -u5 %Term $Regml(1)
    }
  }
  If (!%Example) {
    If ($Regex(%Urban,<p style="font-style: italic">(.*?)</p>)) {
      Set -u5 %Example $Htmlfree($Regml(1))
    }
  }
  If ($Regex(%Urban,<i>(.*?)</i> (.*?) <a)) {
    Set -u5 %Exists $Regml(1) $Regml(2)
  }
  Unset %Urban
}
On *:Sockclose:Urban.*:{
  If (!%Exists) {
    .Notice $Gettok($Sock($Sockname),2,46) TERM %Term DEFINITION $iif($Len(%Text) > 250,Definition too long,%text) $iif(%example,EXAMPLE) %Example AUTHOR $Replace(%Author,+,$Chr(32))
  }
  Else {
    .Notice $Gettok($Sock($Sockname),2,46) URBAN $iif($Len(%Exists) > 250,Term too long,%Exists)
  }
}
Alias -l Htmlfree { 
  Var %x, %i = $Regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$Null,%x), %x = $Remove(%x,&,$Chr(9)) 
  Return $Regsubex(%x,/\quot;/gSi,") 
}
Alias -l Urlencode { 
  Var %a = $Regsubex($$1,/([^\w\s])/Sg,$+(%,$Base($Asc(\t),10,16,2))) 
  Return $Replace(%a,$Chr(32),$Chr(43)) 
}