Translates whatever text is put in the channel if these conditions are met:
It fetches a result from google and can translate the whole channel from (auto - but you can set primary) language to a specified language (Defaults to english). This is made for a bot - not yourself - it messages the channel whenever someone speaks if it finds a translation
Commands
!translate on - Turns autotranslation on for the channel you are in
!translate off - Turns autotranslation off for the channel you are in
!translate primary - Sets the primary speaking language (Just updates a var in the url not sure if it does much xD)
!translate tolang - Sets the language you want the bot to return in for example es will make it translate into spanish
Credits - other than myself ;)
FordLawnmower - For the UrlEncode alias
JimmyJames - idea :P
; Url Encode Alias made by FordLawnmower
alias UrlEncode return $regsubex($1-,/([^\d\w])/g,$+(%,$base($asc(\t),10,16)))
;End Short alias
on *:TEXT:*:#:{
if ($me != TransBot) halt
if ($readini(translation.ini,settings,$chan) == on && !* !iswm $1) {
translate $strip($remove($1-,>,<,$chr(58)),burcmo)
}
elseif ($1 == !translate) {
if ($2 == on || $2 == off) {
writeini translation.ini settings $chan $2
msg $chan Auto Translation for $chan is now $2 $+ .
}
elseif ($2 == primary) {
writeini translation.ini settings p $+ $chan $3
msg $chan Changed the primary speaking language to $3 $+ . If the script does not work after this, please make sure you are using the language code - IE: en, es, it.
}
elseif ($2 == tolang) {
writeini translation.ini settings tl $+ $chan $3
msg $chan Changed the translation language to $3 $+ . If the script does not work after this, please make sure you are using the language code - IE: en, es, it.
}
}
}
alias translate {
var %sname translate. $+ $r(1,9999999)
sockopen %sname translate.google.com 80
sockmark %sname $chan $+ : $+ $remove($1-,\)
}
on *:SOCKOPEN:translate.*:{
var %hl $iif($readini(translation.ini,settings,p $+ $gettok($sock($sockname).mark,1,58)),$v1,en)
var %tl $iif($readini(translation.ini,settings,tl $+ $gettok($sock($sockname).mark,1,58)),$v1,en)
sockwrite -n $sockname GET /translate_a/t?client=t&text= $+ $urlencode($gettok($sock($sockname).mark,2,58)) $+ &hl= $+ %hl $+ &sl=auto&tl= $+ %tl $+ &multires=1&otf=2&ssel=0&tsel=0¬lr=0&sc=1 HTTP/1.1
sockwrite $sockname Host: translate.google.com $+ $crlf $+ $crlf
}
on *:SOCKREAD:translate.*:{
sockread -n &data
var %regy $+(/,$chr(34),(.+?),$chr(34),$chr(44),/)
noop $regex($bvar(&data,1,$bvar(&data,0)).text,%regy)
if ($regml(1) && $remove($regml(1),\) != $gettok($sock($sockname).mark,2,58)) {
msg $gettok($sock($sockname).mark,1,58) [Translation] $remove($regml(1),\)
}
}