Пример #1
0
 function isTriggered()
 {
     if (!isset($this->data['text'])) {
         $this->printUsage();
         return;
     }
     switch ($this->data['trigger']) {
         case '!translate':
             $sl = 'auto';
             $tl = $this->getConfig('language');
             break;
         default:
             $trigger = substr($this->data['trigger'], 1);
             list($sl, $tl) = explode('-', $trigger);
             break;
     }
     if (false === ($translation = libInternet::googleTranslate($this->data['text'], $sl, $tl, $sl == 'auto' ? true : false))) {
         $this->reply("Something weird occurred ");
         return;
     }
     if ($sl == 'auto') {
         $this->reply("Translation from " . $translation['source_lang'] . ": " . $translation['translation']);
     } else {
         $this->reply("Translation: " . $translation);
     }
 }
Пример #2
0
 function isTriggered()
 {
     if (!isset($this->info['text'])) {
         $this->sendOutput("Usage: " . $this->info['triggerUsed'] . " text");
         return;
     }
     $trigger = substr($this->info['triggerUsed'], 1);
     $tmp = explode("-", $trigger);
     $sl = $tmp[0];
     $tl = $tmp[1];
     $translation = libInternet::googleTranslate($this->info['text'], $sl, $tl);
     $translation = preg_replace_callback('/\\\\u([0-9a-f]{4})/', create_function('$m', 'return chr(hexdec($m[1]));'), $translation);
     $translation = $this->unhtmlentities($translation);
     $this->sendOutput("Translation: " . $translation);
 }
Пример #3
0
 function onChannelMessage()
 {
     if (!isset($this->interpreters[$this->Server->id . ':' . $this->Channel->id])) {
         return;
     }
     foreach ($this->interpreters[$this->Server->id . ':' . $this->Channel->id] as $lang) {
         $translation = libInternet::googleTranslate($this->data['text'], 'auto', $lang);
         if (empty($translation)) {
             continue;
         }
         if (strtolower($translation) == strtolower($this->data['text'])) {
             continue;
         }
         $this->reply('<' . libIRC::noHighlight($this->User->nick) . '> ' . $translation);
     }
 }