Beispiel #1
0
 public function processMessage($message, $sender, $senderName, $chatName, $receivedTime)
 {
     //        \Util::debug(self::CHATGROUP);
     $chats = $this->db['chats'] ?: [];
     if (!isset($chats[self::CHATGROUP]) || !in_array($chatName, $chats[self::CHATGROUP])) {
         return true;
     }
     if (substr($message, 0, 1) === '!' && strlen($message) > 1) {
         $arguments = explode(' ', mb_substr($message, 1));
         $command = array_shift($arguments);
         \Util::debug('Command: ' . $command . ' ' . implode(' ', $arguments) . ' in ' . $chatName);
         switch ($command) {
             case 'сколько':
             case 'ск':
                 if (!count($arguments)) {
                     return false;
                 }
                 $pair = trim(strtoupper(array_shift($arguments)));
                 if (!preg_match('/^\\w{6}$/i', $pair)) {
                     return false;
                 }
                 $quantity = count($arguments) ? (double) array_shift($arguments) : 1;
                 $this->sendCrossRate($chatName, $pair, $quantity);
                 return false;
                 break;
             case 'баш':
             case 'bash':
                 if ($sender === 'ejakaaa') {
                     $this->core->send($chatName, 'Хуяш!');
                     return false;
                 }
                 $this->core->send($chatName, $this->bash->getBash());
                 return false;
                 break;
                 //            case 'афоризм':
                 //            case 'а':
                 //            case 'мудрость':
                 //                $afo = $this->getAfo();
                 //                $flag = $afo['country'] !== 'wn' ? ' (flag:' . $afo['country'] . ')' : '';
                 //                $msg = $afo['text'] . PHP_EOL . $afo['author'] . $flag;
                 //                $this->core->send($chatName, $msg);
                 //                break;
             //            case 'афоризм':
             //            case 'а':
             //            case 'мудрость':
             //                $afo = $this->getAfo();
             //                $flag = $afo['country'] !== 'wn' ? ' (flag:' . $afo['country'] . ')' : '';
             //                $msg = $afo['text'] . PHP_EOL . $afo['author'] . $flag;
             //                $this->core->send($chatName, $msg);
             //                break;
             case 'баян':
             case 'bayan':
                 if ($sender === 'ejakaaa') {
                     $this->core->send($chatName, 'Хуян!');
                     return false;
                 }
                 $anek = $this->anekdot->getAnekdot();
                 $this->core->send($chatName, $anek);
                 return false;
                 break;
             case 'tran':
             case 'пер':
                 $direction = strtolower(array_shift($arguments));
                 $subj = implode(' ', $arguments);
                 $this->core->send($chatName, $this->translator->getTranslation($subj, $direction));
                 return false;
                 break;
                 //
                 //            case 'google':
                 //            case 'гугл':
                 //                if ($sender == 'paranoidkilla') {
                 //                    $this->core->send($chatName, 'Вовка, ты заебал!');
                 //                    break;
                 //                };
                 //                if ($sender == 'daniel.lavrushin') {
                 //                    $this->core->send($chatName, 'Даник, ты заебал!');
                 //                    break;
                 //                }
                 //
                 //                $this->sendSearchResult($chatName, $arguments);
                 //
                 //                break;
             //
             //            case 'google':
             //            case 'гугл':
             //                if ($sender == 'paranoidkilla') {
             //                    $this->core->send($chatName, 'Вовка, ты заебал!');
             //                    break;
             //                };
             //                if ($sender == 'daniel.lavrushin') {
             //                    $this->core->send($chatName, 'Даник, ты заебал!');
             //                    break;
             //                }
             //
             //                $this->sendSearchResult($chatName, $arguments);
             //
             //                break;
             case 'курс':
             case 'kurs':
                 $newRates = $this->getRates(1);
                 $this->sendRates($newRates, [$chatName]);
                 return false;
                 break;
             case 'погода':
             case 'pogoda':
                 $city = strtolower(current($arguments));
                 $city = $city ?: 'минск';
                 $this->sendWeather($chatName, $city);
                 return false;
                 break;
             case 'пиво':
             case 'pivo':
                 $this->core->send($chatName, str_repeat('(beer)', mt_rand(1, 9)));
                 return false;
                 break;
                 //            case 'помощь':
                 //            case 'хелп':
                 //            case 'help':
                 //                $this->core->send($chatName,
                 //                    'Список команд: "' .
                 //                    '!курс|баш|баян|погода|пиво|гугл"'
                 //                );
                 //                break;
             //            case 'помощь':
             //            case 'хелп':
             //            case 'help':
             //                $this->core->send($chatName,
             //                    'Список команд: "' .
             //                    '!курс|баш|баян|погода|пиво|гугл"'
             //                );
             //                break;
             case 'сокр':
                 $this->core->send($chatName, $this->shortenUrl($arguments[0]));
                 return false;
                 break;
             case 'имг':
                 if (!count($this->imgurCache)) {
                     $this->imgurCache = $this->imgur->api('gallery')->randomGalleryImages();
                 }
                 /** @var GalleryImage $image */
                 $image = array_pop($this->imgurCache);
                 $title = $image->getTitle();
                 $link = $image->getLink();
                 $link = $image->getAnimated() ? str_replace('.gif', '.gifv', $link) : $link;
                 $this->core->send($chatName, ($title ? $title . ' ' : '') . $link);
                 return false;
                 break;
             case 'нов':
             case 'новости':
                 $topNews = $this->mediametrics->getTopNews();
                 $msg = 'Новости в тренде: ' . PHP_EOL;
                 foreach ($topNews as $index => $newsLine) {
                     if ($index >= 3) {
                         break;
                     }
                     $msg .= "[{$newsLine['visitors']}";
                     //                        $msg .= $newsLine['delta'] ? ':' . (
                     //                            substr($newsLine['delta'], 0, 1) !== '-' ? '+' : ''
                     //                            ) . $newsLine['delta'] : '';
                     $msg .= '] ' . htmlspecialchars_decode($newsLine['title']);
                     //                        $msg .= ' ' . $this->shortenUrl('http://' . $newsLine['url']);
                     $msg .= PHP_EOL . ' http://' . $newsLine['url'];
                     $msg .= PHP_EOL;
                 }
                 $this->core->send($chatName, $msg);
                 return false;
                 break;
             case 'х':
                 $matches = [];
                 preg_match_all('/[А-ЯЁа-яё]+/u', implode(' ', $arguments), $matches);
                 /** @var array $words */
                 $words = end($matches);
                 foreach ($words as $key => $word) {
                     $matches = [];
                     if (preg_match('/^[^ауоыиэяюёе]*(?<glasnaya>[ауоыиэяюёе])(?<konec>.+)/iu', $word, $matches) && $matches && count($matches) && $matches['glasnaya'] && $matches['konec']) {
                         $glas = preg_replace(['/^а/iu', '/^о/iu', '/^э/iu', '/^у/iu', '/^ы/iu'], ['я', 'ё', 'е', 'ю', 'и'], $matches['glasnaya']);
                         $word .= '-' . 'ху' . $glas . $matches['konec'];
                         $words[$key] = $word;
                     }
                 }
                 $this->core->send($chatName, implode(' ', $words));
                 break;
             default:
                 break;
         }
     }
     return true;
 }
Beispiel #2
0
 public function processMessage($message, $sender, $senderName, $chatName, $receivedTime)
 {
     //        \Util::debug(self::CHATGROUP);
     if (1 && $this->checkFlood($sender, $chatName) && ($reactiveChats = $this->db['chats']['reactive'] ?: []) && in_array($chatName, $reactiveChats)) {
         if ($message === '$' || $message === ';') {
             $this->sendBucks($chatName);
             return false;
         } elseif (preg_match('/((?:http(?:s?)\\:\\/\\/)?(?:www\\.)?youtu[^\\s]+)/i', $message, $matches)) {
             $this->sendYoutubeDescription($chatName, $matches);
             return false;
         } elseif (preg_match('/(http(?:s?):\\/\\/[\\w\\.\\/\\-\\_0-9\\%]+\\.gif(?:[\\?#]|$)|http:\\/\\/img\\.leprosorium\\.com\\/\\d+)/i', $message, $matches)) {
             $this->sendGifSize($chatName, $matches);
             return false;
         } elseif (preg_match('#((?:http(?:s?)\\://)?[^\\s]+/[^\\s]*)$#i', $message, $matches)) {
             $this->sendOpenGraphDescription($chatName, $matches);
             return false;
         } elseif (preg_match('/^(t**s|сиси|сись?ки|сисечки|груд[и]?|boob.+|t**s|titties)$/iu', $message)) {
             $num = str_pad(mt_rand(0, 3000), 5, '0', STR_PAD_LEFT);
             $link = 'http://media.oboobs.ru/boobs_preview/' . $num . '.jpg';
             $this->core->send($chatName, 'NSFW ' . $link);
             return false;
         } elseif (preg_match('/(^|\\s)п[еия][з][д][аоеыу]/iu', $message)) {
             $c**t = (int) $this->db['c**t'] ?: 0;
             $c**t++;
             $this->db['c**t'] = $c**t;
             $this->core->send($chatName, 'Пизда помянута ' . \Util::writtenNum($c**t, 'раз,раза,раз', 'male'));
             return false;
         } elseif (preg_match('/^(попк.?|butt|поп.?|попочк.?|зад|жоп.?)$/iu', $message)) {
             $num = str_pad(mt_rand(0, 2000), 5, '0', STR_PAD_LEFT);
             $link = 'http://media.obutts.ru/butts_preview/' . $num . '.jpg';
             $this->core->send($chatName, 'NSFW ' . $link);
             return false;
         } else {
             $langs = ['be', 'uk', 'bg', 'la'];
             $randomLang = $langs[mt_rand(0, count($langs) - 1)];
             $words = [];
             preg_match_all('/[А-ЯЁа-яё]+/u', $message, $words);
             //if (rand(1, 10000) > 9990 && count($words) && count($words[0]) > 1) {
             //    $this->core->send($chatName, implode(' ', $words[0]) . ', Карл');
             //} else
             if (mt_rand(1, 1000) > 995 && count($words) && count($words[0]) < 4) {
                 $huified = $this->huifyString(implode(' ', $words[0]));
                 if ($huified) {
                     $this->core->send($chatName, $huified . ', ' . $senderName);
                 }
                 return false;
             } elseif (mt_rand(1, 1000) > 995 && count($words) && count($words[0]) > 4) {
                 $this->core->send($chatName, $this->translator->getTranslation(implode(' ', $words[0]), 'ru-' . $randomLang) . ', ' . $senderName);
                 return false;
             } elseif (strlen($message) > 1 && preg_match('/\\?\\)*\\(*$/', $message) && mt_rand(1, 100) > 95) {
                 // TODO move to file
                 $answers = ["Мне кажется — да", "Бесспорно", "Решено - да", "Вероятнее всего", "Хорошие перспективы", "Знаки говорят — да", "Никаких сомнений", "Да", "Определённо да", "Можешь положиться", "Пока не ясно, попробуй снова", "Спроси позже", "Лучше не рассказывать", "Сейчас нельзя предсказать", "Сконцентрируйся и спроси опять", "Даже не думай", "Мой ответ — нет", "По моим данным — нет", "Перспективы не очень хорошие", "Весьма сомнительно", "Подожди час", "Демура утверждал обратное", "Это все Тёркин", "Нет времени объяснять", "Все не так однозначно", "Теперь Вы дипломированный экономист", "А в Африке дети голодают", "Что ты как маленький", "Ой все", "Не знаю", "Йован жив", "Быть или не быть? Вот в чем вопрос"];
                 $answer = $answers[mt_rand(0, count($answers) - 1)];
                 if ($answer) {
                     $this->core->send($chatName, $answer . ', ' . $senderName);
                 }
                 return false;
             } elseif (mt_rand(1, 1000) > 995 || preg_match('/' . mb_strtolower(Linux::$botName) . '/iu', $message) && mt_rand(1, 100) > 80) {
                 if ($sender === 'ejakaaa') {
                     return true;
                 }
                 // no more random jokes, let it be greetings
                 $msg = \Util::getRandomGreeting($senderName);
                 if ($msg) {
                     $this->core->send($chatName, $msg);
                 }
                 return false;
             }
         }
     }
     return true;
 }