Ford

Autotrans test edit

Jul 25th, 2012
508
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Auto Translator by Ford_Lawnmower irc.GeekShed.net #Script-Help
  2. menu Channel {
  3.   .$iif($gettok($hget(autotrans,$+($network,$chan)),3,32) == On && $group(#AutoTrans) == On,$style(1)) AutoTrans
  4.   ..$iif($group(#AutoTrans) == On,$style(1)) Auto Trans Master On/Off: $iif($group(#AutoTrans) == On,.disable,.enable) #AutoTrans  
  5.   ..Auto Trans Setup:dialog $iif($dialog(auto_translator),-v,-m) auto_translator auto_translator
  6.   ..Manage Exclusions:dialog $iif($dialog(auto_translator_exclude),-v,-m) auto_translator_exclude auto_translator_exclude
  7. }
  8. #AutoTrans On
  9. On *:Text:*:#: {
  10.   if (!$timer($+(AutoTrans,$network,$nick))) {
  11.     .timer $+ $+(AutoTrans,$network,$nick) 1 1 noop
  12.     if ($gettok($hget(autotrans,$+($network,$chan)),3,32) == On) && (!$regex($1,/^[!.@.#.+./.:.-.+]/S)) {
  13.       var %text $urlencode($utfdecode($utfencode($exclude($1-))))
  14.       tokenize 32 $hget(autotrans,$+($network,$chan))
  15.       AutoTrans $2 $iif($2 == .Msg,$chan,$iif($2 == Echo,$chan,$me)) $iif($4,$+(09[04,$nick,09]),0) $langpair($1),1,32)) %text 0
  16.     }
  17.   }
  18. }
  19. On *:Action:*:#: {
  20.   if (!$timer($+(AutoTrans,$network,$nick))) {
  21.     .timer $+ $+(AutoTrans,$network,$nick) 1 1 noop
  22.     if ($gettok($hget(autotrans,$+($network,$chan)),3,32) == On) {
  23.       var %text $urlencode($exclude($1-))
  24.       tokenize 32 $hget(autotrans,$+($network,$chan))
  25.       AutoTrans $2 $iif($2 == .Msg,$chan,$iif($2 == Echo,$chan,$me)) $iif($4,$+(09[04,$nick,09]),0) $langpair($1),1,32)) %text 0
  26.     }
  27.   }
  28. }
  29. #AutoTrans End
  30. On *:input:*: {
  31.   if ($left($strip($1),2) == \\) && (!$ctrlenter) {
  32.     haltdef
  33.     var %text $inputencode($2-)
  34.     AutoTrans msg $iif($chan,$chan,$active) $me $remove($1,\\) %text 1
  35.   }  
  36. }
  37. on ^$*:Hotlink:/\[([a-zA-Z]{2})\]-\[([a-zA-Z]{2})\]/:#,?:{
  38.   if ($mouse.key == 16) && ($input(Respond through translator $+($regml(2),-,$regml(1)),yn)) {
  39.     if ($?="Please Input your text to be translated") {
  40.       AutoTrans msg $iif($chan,$chan,$nick) $me $regml(1) $urlencode($!) 1
  41.     }  
  42.   }
  43.   halt
  44. }
  45. alias EchoAutoTrans { AutoTrans echo -a $1- }
  46. alias -l AutoTranslate {
  47.   var %sockname $+(AutoTrans,$network,$3,$ticks,$r(1,$ticks))
  48.   sockopen %sockname translate.google.com 80
  49.   sockmark %sockname $1-2 $+(/translate_t?langpair=,$4,&text=,$5) $3 $6 $4 $5
  50. }
  51. On *:sockopen:AutoTrans*: {
  52.   if (!$sockerr) {
  53.     sockwrite -nt $sockname GET $gettok($sock($sockname).mark,3,32) HTTP/1.1
  54.     sockwrite -n $sockname Host: translate.google.com
  55.     sockwrite -n $sockname Referer: $+(http://,$ip)
  56.     sockwrite -n $sockname $crlf
  57.   }
  58.   else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  59. }
  60. On *:sockread:AutoTrans*: {
  61.   if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  62.   else {
  63.     var %AutoTrans | sockread %AutoTrans
  64.     if ($regex(text,%AutoTrans,/backgroundColor='#fff'">(.*?)<\/span>/gi)) {
  65.       var %counter 1, %text
  66.       while (%counter <= $regml(text,0)) {
  67.         %text = $+(%text,$chr(32),$replace($fixhtml($regml(text,%counter)),quot;,"))
  68.         inc %counter
  69.       }
  70.       var %country $+([,$replace($gettok($sock($sockname).mark,6,32),|,]-[),],)
  71.       if ($gettok($sock($sockname).mark,5,32)) { $gettok($sock($sockname).mark,1-2,32) %text | sockclose $sockname | return }
  72.       elseif ($matches(%text,$recode($mid($gettok($gettok($sock($sockname).mark,3,32),-2,38),3-)))) {
  73.         if ($nopunct(%text) != $nopunct($recode($gettok($sock($sockname).mark,7,32)))) {
  74.           $gettok($sock($sockname).mark,1-2,32) 06Translation07 %country $&
  75.             $iif($gettok($sock($sockname).mark,4,32),$gettok($sock($sockname).mark,4,32)) %text
  76.         }
  77.         sockclose $sockname
  78.         return  
  79.       }
  80.     }    
  81.   }
  82. }
  83. alias -l nopunct { return $regsubex($1-,/[\x2c!"#$%&'()*+\-./:;<=>?@[\\\]^_`{|}~]/g,$null) }
  84. alias -l inputencode { return $regsubex($strip($1-),/([^a-z0-9])/ig,% $+ $base($asc(\t),10,16,2)) }
  85. alias -l exclude { return $regsubex($strip($1-),/(http:\/\/[\S]{1,}|www\.[\S]{1,})/g,$null) }
  86. alias -l urlencode { return $regsubex($1-,/([^a-z0-9])/ig,$urlpairs($asc(\t))) }
  87. alias -l recode { return $regsubex($1-,/%([A-Fa-f0-9]{2})/g,$chr($base(\t,16,10))) }
  88. alias -l fixhtml { return $replace($remove($regsubex($remove($regsubex($1-,/#([\d][\d][\d]?);/g,$chr(\t)),&amp;,gt;,lt;),/\\u([A-Fa-f0-9]{4})/g,$chr($base(\t,16,10))),&amp;,&),&quot;,") }
  89. alias -l notrans { return $iif($hfind(notrans,$1),1,0) }
  90. alias -l matches {
  91.   var %w $numtok($1,32),%x 1,%y 0,%z $numtok($2,32)
  92.   while (%x <= %z) {
  93.     if ($istok($1,$gettok($2,%x,32),32)) || ($notrans($gettok($2,%x,32))) { inc %y }
  94.     inc %x
  95.   }
  96.   return $iif($calc(%y / %w * 100) >= 80,0,1)
  97. }
  98. alias -l UrlPairs {
  99.   if ($1 < 255) { return $+(%,$base($1,10,16)) }
  100.   if ($1 >= 256) && ($1 < 2048) { return $+(%,$base($calc(192 + $div($1,64)),10,16),%,$base($calc(128 + $mod($1,64)),10,16)) }
  101.   if ($1 >= 2048) && ($1 < 65536) { return $+(%,$base($calc(224 + $div($1,4096)),10,16),%,$base($calc(128 + $mod($div($1,64),64)),10,16),%,$base($calc(128 + $mod($1,64)),10,16)) }
  102. }
  103. alias -l div { return $int($calc($1 / $2)) }
  104. alias -l mod {
  105.   var %int $int($calc($1 / $2))
  106.   return $calc($1 - (%int * $2))
  107. }
  108. dialog Auto_Translator {
  109.   title "Auto Translator Setup"
  110.   size -1 -1 118 126
  111.   option dbu
  112.   text "Target Language:", 1, 4 9 45 8, right
  113.   text "Network:", 2, 4 25 45 8, right
  114.   text "Channel:", 3, 4 42 45 8, right
  115.   text "Output Type:", 4, 4 59 45 8, right
  116.   combo 5, 51 8 62 11, drop
  117.   combo 6, 51 24 62 11, drop
  118.   combo 7, 51 41 62 11, drop
  119.   combo 8, 51 58 62 11, drop
  120.   combo 9, 51 77 62 11, drop
  121.   text "Status:", 10, 4 78 45 8, right
  122.   button "Accept", 11, 78 110 34 12
  123.   button "Cancel", 12, 39 110 34 12, cancel
  124.   check "Show Nickname", 13, 63 97 50 10
  125. }
  126. dialog Auto_Translator_Exclude {
  127.   title "Auto Translator Exclusion Manager"
  128.   size -1 -1 144 144
  129.   option dbu
  130.   text "Exclusion:", 1, 4 7 27 8, right
  131.   text "Exclusions", 2, 1 21 142 8, center
  132.   edit "", 3, 33 6 72 10, autohs
  133.   list 4, 6 33 131 94, vsbar
  134.   button "Add", 5, 107 5 29 12
  135.   button "Delete", 6, 50 130 37 12
  136.   button "Close", 7, 97 130 37 12, cancel
  137. }
  138. On *:dialog:Auto_Translator_Exclude:Sclick:5,6: {
  139.   if ($did == 5) && ($did($dname,3).text) { hadd -m notrans $v1 | did -r $dname 3 }
  140.   if ($did == 6) && ($did($dname,4).seltext) { hdel notrans $v1 }
  141.   did -r $dname 4
  142.   didtok $dname 4 32 $regsubex($str(.,$hget(notrans,0).item),/./g,$hget(notrans,\n).item $+ $chr(32))
  143. }
  144. On *:dialog:Auto_Translator_Exclude:init:*: {
  145.   didtok $dname 4 32 $regsubex($str(.,$hget(notrans,0).item),/./g,$hget(notrans,\n).item $+ $chr(32))
  146. }
  147. on *:dialog:Auto_Translator:Sclick:6,7,11: {
  148.   if ($did == 11) {
  149.     tokenize 32 $did($dname,6).seltext $did($dname,7).seltext $did($dname,5).seltext $did($dname,8).seltext $did($dname,9).seltext
  150.     hadd -m autotrans $+($1,$chr(35),$2) $3- $did($dname,13).state
  151.     dialog -x $dname
  152.   }
  153.   if ($did == 6) {
  154.     did -r $dname 7
  155.     didtok $dname 7 35 $chans($did($dname,6).seltext)
  156.     did -fc $dname 7 1
  157.   }
  158.   if ($hget(autotrans,$+($did($dname,6).seltext,$chr(35),$did($dname,7).seltext))) {
  159.     var %match $v1
  160.     did -c $dname 5 $didwm($dname,5,$gettok(%match,1,32))
  161.     did -c $dname 8 $didwm($dname,8,$gettok(%match,2,32))
  162.     did -c $dname 9 $didwm($dname,9,$gettok(%match,3,32))
  163.     did $iif($gettok(%match,4,32),-c,-u) $dname 13
  164.   }
  165. }
  166. on *:dialog:Auto_Translator:init:*: {
  167.   didtok $dname 5 44 AFRIKAANS,ALBANIAN,AMHARIC,ARABIC,ARMENIAN,AZERBAIJANI,BASQUE,BELARUSIAN,BENGALI,BIHARI,BULGARIAN,BURMESE,CATALAN,CHEROKEE
  168.   didtok $dname 5 44 CHINESE,CHINESE_SIMPLIFIED,CHINESE_TRADITIONAL,CROATIAN,CZECH,DANISH,DHIVEHI,DUTCH,ENGLISH,ESPERANTO,ESTONIAN,FILIPINO
  169.   didtok $dname 5 44 FINNISH,FRENCH,GALICIAN,GEORGIAN,GERMAN,GREEK,GUARANI,GUJARATI,HEBREW,HINDI,HUNGARIAN,ICELANDIC,INDONESIAN,INUKTITUT
  170.   didtok $dname 5 44 IRISH,ITALIAN,JAPANESE,KANNADA,KAZAKH,KHMER,KOREAN,KURDISH,KYRGYZ,LAOTHIAN,LATVIAN,LITHUANIAN,MACEDONIAN,MALAY,MALAYALAM
  171.   didtok $dname 5 44 MALTESE,MARATHI,MONGOLIAN,NEPALI,NORWEGIAN,ORIYA,PASHTO,PERSIAN,POLISH,PORTUGUESE,PUNJABI,ROMANIAN,RUSSIAN,SANSKRIT,SERBIAN
  172.   didtok $dname 5 44 SINDHI,SINHALESE,SLOVAK,SLOVENIAN,SPANISH,SWAHILI,SWEDISH,TAJIK,TAMIL,TAGALOG,TELUGU,THAI,TIBETAN,TURKISH,UKRAINIAN
  173.   didtok $dname 5 44 URDU,UZBEK,UIGHUR,VIETNAMESE,WELSH,YIDDISH
  174.   did -c $dname 5 $didwm($dname,5,ENGLISH)
  175.   var %nets $scon(0)
  176.   while (%nets) { scon %nets did -a $dname 6 $!network | dec %nets }
  177.   did -c $dname 6 $didwm($dname,6,$network)
  178.   didtok $dname 7 35 $chans($network)
  179.   did -c $dname 7 $didwm($dname,7,$mid($active,2-))
  180.   didtok $dname 8 44 Echo,.Msg,.Notice
  181.   did -c $dname 8 1
  182.   didtok $dname 9 44 On,Off
  183.   did -c $dname 9 2
  184.   if ($hget(autotrans,$+($network,$active))) {
  185.     var %match $v1
  186.     did -c $dname 5 $didwm($dname,5,$gettok(%match,1,32))
  187.     did -c $dname 8 $didwm($dname,8,$gettok(%match,2,32))
  188.     did -c $dname 9 $didwm($dname,9,$gettok(%match,3,32))
  189.     did $iif($gettok(%match,4,32),-c,-u) $dname 13
  190.   }
  191. }
  192. alias -l LangPair {
  193.   var %return $replace($1-,AFRIKAANS,af,ALBANIAN,sq,AMHARIC,am,ARABIC,ar,ARMENIAN,hy,AZERBAIJANI,az,BASQUE,eu,BELARUSIAN,be,BENGALI,bn,$&
  194.     BIHARI,bh,BULGARIAN,bg,BURMESE,my,CATALAN,ca,CHEROKEE,chr,CHINESE,zh,CHINESE_SIMPLIFIED,CN,CHINESE_TRADITIONAL,TW,$&
  195.     CROATIAN,hr,CZECH,cs,DANISH,da,DHIVEHI,dv,DUTCH,nl,ENGLISH,en,ESPERANTO,eo,ESTONIAN,et,FILIPINO,tl,FINNISH,fi,FRENCH,fr,$&
  196.     GALICIAN,gl,GEORGIAN,ka,GERMAN,de,GREEK,el,GUARANI,gn,GUJARATI,gu,HEBREW,iw,HINDI,hi,HUNGARIAN,hu,ICELANDIC,is,$&
  197.     INDONESIAN,id,INUKTITUT,iu,IRISH,ga,ITALIAN,it,JAPANESE,ja,KANNADA,kn,KAZAKH,kk,KHMER,km,KOREAN,ko,KURDISH,ku,KYRGYZ,ky)
  198.   return $replace(%return,LAOTHIAN,lo,LATVIAN,lv,LITHUANIAN,lt,MACEDONIAN,mk,MALAY,ms,MALAYALAM,ml,MALTESE,mt,MARATHI,mr,MONGOLIAN,mn,NEPALI,ne,$&
  199.     NORWEGIAN,no,ORIYA,or,PASHTO,ps,PERSIAN,fa,POLISH,pl,PORTUGUESE,pt,PUNJABI,pa,ROMANIAN,ro,RUSSIAN,ru,SANSKRIT,sa,$&
  200.     SERBIAN,sr,SINDHI,sd,SINHALESE,si,SLOVAK,sk,SLOVENIAN,sl,SPANISH,es,SWAHILI,sw,SWEDISH,sv,TAJIK,tg,TAMIL,ta,TAGALOG,tl,$&
  201.     TELUGU,te,THAI,th,TIBETAN,bo,TURKISH,tr,UKRAINIAN,uk,URDU,ur,UZBEK,uz,UIGHUR,ug,VIETNAMESE,vi,WELSH,cy,YIDDISH,yi)
  202. }
  203. alias -l chans { scon $netid($1) return $!regsubex($str(.,$chan(0)),/./g,$chan(\n)) }
  204. alias -l netid {
  205.   var %netcount $scon(0)
  206.   while %netcount {
  207.     if ($scon(%netcount).network == $1) { return %netcount }
  208.     dec %netcount
  209.   }
  210. }
  211. On *:Start:{
  212.   hmake AutoTrans 5
  213.   hmake NoTrans 5
  214.   if ($exists(AutoTrans.hsh)) { hload AutoTrans AutoTrans.hsh  }
  215.   if ($exists(NoTrans.hsh)) { hload NoTrans NoTrans.hsh  }
  216. }
  217. On *:Disconnect:{
  218.   if ($hget(AutoTrans)) { hsave AutoTrans AutoTrans.hsh }
  219.   if ($hget(NoTrans)) { hsave NoTrans NoTrans.hsh }  
  220. }
  221. On *:Exit:{
  222.   if ($hget(AutoTrans)) {
  223.     hsave AutoTrans AutoTrans.hsh
  224.     hfree AutoTrans
  225.   }
  226.   if ($hget(NoTrans)) {
  227.     hsave NoTrans NoTrans.hsh
  228.     hfree NoTrans
  229.   }  
  230. }
  231. On *:Unload:{ hfree AutoTrans | hfree NoTrans }
  232. ;;;;;;;Start edit;;;;;;;;;
  233. alias -l AutoTrans {
  234.   var %sockname $+(LanguageDetection,$network,$3,$ticks,$r(1,$ticks))
  235.   sockopen %sockname labs.translated.net 80
  236.   sockmark %sockname $1-2 $+(/language-identifier/?text=,$5) $3 $6 $4 $5
  237. }
  238. On *:sockopen:LanguageDetection*: {
  239.   if (!$sockerr) {
  240.     sockwrite -nt $sockname GET $gettok($sock($sockname).mark,3,32) HTTP/1.0
  241.     sockwrite -n $sockname Host: $sock($sockname).addr
  242.     sockwrite -n $sockname $crlf
  243.   }
  244.   else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  245. }
  246. On *:sockread:LanguageDetection*: {
  247.   if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  248.   else {
  249.     var %LanguageDetection | sockread %LanguageDetection
  250.     if ($regex(%LanguageDetection,/This text seems to be <b>.+?\x28([^<]+)\s/i)) {
  251.       var %l1 $lower($regml(1))
  252.       tokenize 32 $sock($sockname).mark
  253.       if (%l1 != $6) {
  254.         Autotranslate $1-2 $4 $+(%l1,|,$6) $7 $5
  255.       }
  256.       sockclose $sockname
  257.       return
  258.     }
  259.   }
  260. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×