Ejemplo n.º 1
0
 public function run()
 {
     $this->db = $this->container->get('db');
     $this->db['last_run'] = date('Y-m-d H:i:s');
     \Util::debug('Connecting to Skype');
     $this->core->initSkypeConnection();
     \Util::debug('Initializing plugins');
     $this->container->get('Bot\\Plugins\\Infrastructure\\Broker')->initPlugins();
     /** @var LoopInterface $loop */
     $loop = $this->container->get('loop');
     /** @var EventEmitter $ev */
     $ev = $this->container->get('event');
     if (isset($this->db['restart']) && $this->db['restart']) {
         list($chatName, $restartTime) = $this->db['restart'];
         $this->core->send($chatName, 'Я сделяль!');
         unset($this->db['restart']);
     }
     $loop->addPeriodicTimer(0.0001, function () use($ev, $loop) {
         $this->core->poll();
         //                $this->webCore->poll();
         $ev->emit('tick', [microtime(true)]);
     });
     \Util::debug('Running main loop');
     $loop->run();
 }
Ejemplo n.º 2
0
 private function startQuiz($chatName, $sender, $senderName)
 {
     $chats = $this->db['chats'] ?: [];
     if (isset($chats[self::CHATGROUP]) && in_array($chatName, $chats[self::CHATGROUP])) {
         //            \Util::debug('Quiz: start request in ' . $chatName);
         $running = \Util::store('quiz') ?: [];
         if (!isset($running[$chatName])) {
             \Util::console('Quiz: Starting quiz in ' . $chatName);
             //                $scores = $this->quizDb['scores'];
             //                $score = 0;
             //                if (isset($scores[$chatName]) && isset($scores[$chatName][$sender])) {
             //                    $score = $scores[$chatName][$sender];
             //                }
             $quiz = $this->createRound(1);
             //                \Util::debug($quiz);
             $msg = '(mp) В моих чертогах разума ' . $this->questionsCount . ' каверзных вопроса. Вызов принят, ' . $senderName . '!' . PHP_EOL;
             $msg .= '(mp) Первый раунд, вопрос №' . $quiz['number'] . ':' . PHP_EOL . $quiz['question'] . ' (' . mb_strlen($quiz['answer']) . ' букв)';
             $this->core->send($chatName, $msg);
             $running[$chatName]['quiz'] = $quiz;
             $running[$chatName]['scores'] = [];
             \Util::store('quiz', $running);
             //                \Util::debug('Quiz: not running in ' . $chatName);
         } else {
             //                \Util::debug('Quiz: running in ' . $chatName);
             $this->core->send($chatName, "Сорян, {$senderName}, но твоя принцесса в другом замке! Дождись конца текущей игры.");
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * @param string $sender
  * @param string $senderName
  * @param string $chatName
  * @param array $usersAdded
  */
 public function processJoin($sender, $senderName, $chatName, $usersAdded)
 {
     //        \Util::debug([$sender, $senderName, $chatName, $usersAdded]);
     if (array_key_exists(Admin::GROUP_MODERATED, $this->db['chats']) && in_array($chatName, $this->db['chats'][Admin::GROUP_MODERATED])) {
         $joiners = $this->db['joiners'] ?: [];
         if (!array_key_exists($chatName, $joiners)) {
             $joiners[$chatName] = [];
         }
         foreach ($usersAdded as $user) {
             $joiners[$chatName][$user] = time();
             try {
                 $this->core->send($chatName, "/setrole {$user} listener");
             } catch (\Exception $e) {
                 // all good
             } finally {
                 //                $this->core->send(
                 //                    $chatName,
                 //                    "Привет, {$user}. В чате действует предмодерация входа, поэтому ты не сможешь писать еще две минуты."
                 //                );
             }
         }
         $this->db['joiners'] = $joiners;
     }
 }