All pastes #805255 Raw Edit

1

public text v1 · immutable
·published 2007-12-04 04:16 UTC
rendered paste body
alias c1 return $+($chr(3),12,$1)
alias c2 return $+($chr(3),04,$1)
on $*:TEXT:/^[@!]([^_]+)_([^ ]+) (.+)$/:#:{
  if ($me == stupidbot) noop
  elseif (%dchan [ $+ [ $chan ] ] == yes) { halt }
  var %to = $regml(2), %from = $regml(1), %text = $regml(3)
  var %from = $lang(%from), %to = $lang(%to)
  if (*NoExist* !iswm $+(%from,~,%to)) {
    var %sn = $+(trans.,$ticks), %h = hadd -m %sn
    %h disp $iif($left($1,1) == @,msg $chan,notice $nick)
    %h from %from
    %h to %to
    %h text %text
    sockopen %sn www.tranexp.com 2000
  }
}
on *:SOCKOPEN:trans.*:{
  var %r = sockwrite -nt $sockname 
  %r GET $+(/InterTran?type=text&from=,$hget($sockname,from),&to=,$hget($sockname,to),&text=,$hget($sockname,text)) HTTP/1.1
  %r Host: www.tranexp.com $+ $crlf $+ $crlf
}
on *:SOCKREAD:trans.*:{
  var %s | sockread %s
  if ($regex(%s,/name="translation" >(.*?)<\/textarea>/i)) {
    var %a = $regml(1)
    $hget($sockname,disp) $c1(Translator Translating:) $c2($hget($sockname,text))
    $hget($sockname,disp) $c1(From:) $c2($bw($hget($sockname,from))) $c1(To:) $c2($bw($hget($sockname,to)))
    $hget($sockname,disp) $c1(Result:) $c2(%a)
    hfree $sockname
    sockclose $sockname
    halt
  }
}
alias -l bw {
  if ($1 == eng) return English
  if ($1 == poe) return Portugese
  if ($1 == bul) return Bulgarian
  if ($1 == cro) return Croatian
  if ($1 == che) return Czech
  if ($1 == dan) return Danish
  if ($1 == dut) return Dutch
  if ($1 == fin) return Finnish
  if ($1 == fre) return French
  if ($1 == ger) return German
  if ($1 == grk) return Greek
  if ($1 == spa) return Spanish
  if ($1 == hun) return Hungarian
  if ($1 == ice) return Icelandic
  if ($1 == ita) return Italian
  if ($1 == nor) return Norwegian
  if ($1 == tag) return Filipino/Tagalog
  if ($1 == pol) return Polish
  if ($1 == rom) return Romanian
  if ($1 == rus) return Russian
  if ($1 == sel) return Serbian
  if ($1 == slo) return Slovenian
  if ($1 == swe) return Swedish
  if ($1 == tur) return Turkish
  if ($1 == ltt) return Latin
}
alias -l lang {
  if ($regex($1,/^en(?:g|glish)?$/i)) return eng
  if ($regex($1,/^port(?:ugal|ugese)?$/i)) return poe
  if ($regex($1,/^cro(?:ation)?$/i)) return cro
  if ($regex($1,/^dan(?:ish)?$/i)) retun dan
  if ($regex($1,/^dut(?:ch)?$/i)) return dut
  if ($regex($1,/^fin(?:land|nish|ny?)?$/i)) return fin
  if ($regex($1,/^french$/i)) return fre
  if ($regex($1,/^german$/i)) return ger
  if ($regex($1,/^gr(?:e[ea])?k$/i)) return grk
  if ($regex($1,/^spa(?:n(?:ish)?)?$/i)) return spa
  if ($regex($1,/^hun(?:garian)?$/i)) return hun
  if ($regex($1,/^ita(?:lian|ly)?$/i)) return ita
  if ($regex($1,/^nor(?:w(?:ay|egian))?$/i)) return nor=>Norwegian
  if ($regex($1,/^(?:tagalog|(?:ph|f)ilip(?:ines?|ino))$/i)) return tag
  if ($regex($1,/^polish$/i)) return pol
  if ($regex($1,/^russian$/i)) return rus
  if ($regex($1,/^swee?d(?:[iae]n|ish)?$/i)) return swe
  if ($regex($1,/^turk(?:ish)?$/i)) return tur
  if ($regex($1,/^latin$/i)) return ltt
  return NoExist
}