All pastes #175313 Raw Edit

Abb-State ViceVersa

public text v1 · immutable
·published 2006-09-18 18:12 UTC
rendered paste body
;Idea: Kitten of SwiftIRC.net
;Script by RussellReal
;Source: http://www.cmmei.com/stabb.htm
on $*:TEXT:/^[@!](state|abb)/Si:#:{
  set $+(%,abrev,.,$nick,.,style) $iif($right($1,-1) == state,state,abb)
  if ($($+(%,abrev,.,$nick,.,style),2) == State) {
    if ($len($2-) >= 3) {
      .notice $nick That is too long to be an abbreviation.
      unset $+(%,abrev,.,$nick,.,style)
      halt
    }
  }
  set $+(%,abrev,.,$nick,.,dest) $iif($left($1,1) == @,msg $chan,$iif($left($1,1) == !,.notice $nick,halt))
  set $+(%,abrev,.,$nick,.,lookup) $2-
  sockopen $+(abrev,.,$nick) www.cmmei.com 80
}
on *:SOCKOPEN:abrev.*:{ 
  sockwrite -n $sockname GET /stabb.htm  HTTP/1.1
  sockwrite -n $sockname Host: www.cmmei.com $+ $crlf $+ $crlf
} 
on *:SOCKREAD:abrev.*:{ 
  if ($sockerr) { $($+(%,$sockname,.dest),2) $sockerror | sockclose $sockname }    
  var $+(%,$sockname,.,result) | sockread -f $+(%,$sockname,.result)
  if (*Street Address Abbreviation* iswm $htmlfree($($+(%,$sockname,.result),2))) {
    $($+(%,$sockname,.dest),2) Sorry $right($sockname,-6) Your $replace($($+(%,$sockname,.,style),2),abb,Abbreviation,state,State) search for $($+(%,$sockname,.,lookup),2) Returned no results.
    sockclose $sockname
    unset $+(%,$sockname,.,*)
    halt
  }
  if ($($+(%,$sockname,.,style),2) == state) {
    if ($htmlfree($($+(%,$sockname,.result),2)) == $($+(%,$sockname,.,lookup),2)) {
      sockread -f $+(%,$sockname,.result)
      $($+(%,$sockname,.dest),2) The state for the abbreviation: $($+(%,$sockname,.,lookup),2) is: $htmlfree($($+(%,$sockname,.result),2)) $+ .
      unset $+(%,$sockname,.,*)
      sockclose $sockname
      halt
    }
  }
  if ($($+(%,$sockname,.,style),2) == abb) {
    if ($htmlfree($($+(%,$sockname,.result),2)) == $($+(%,$sockname,.,lookup),2)) {
      $($+(%,$sockname,.dest),2) The Abbreviation for the State: $($+(%,$sockname,.,lookup),2) is: $($+(%,$sockname,.prev),2) $+ .
      sockclose $sockname
      unset $+(%,$sockname,.,*)
      halt
    }
    else {    
      set $+(%,$sockname,.prev) $htmlfree($($+(%,$sockname,.result),2))
    }
  }
}
alias htmlfree { 
  var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x,&nbsp;) 
  return %x 
}