Exemplo n.º 1
0
 public static function constructFromTelegramUpdate($chat_update, \PDO $db)
 {
     $changed = false;
     $chatSQL = new \GroupBot\Database\Chat($db);
     if ($chat = $chatSQL->getChatById($chat_update['id'])) {
         if (isset($chat_update['title']) && strcmp($chat->title, $chat_update['title']) !== 0) {
             $chat->title = $chat_update['title'];
             $changed = true;
         }
         $chat->id = $chat->chat_id;
         unset($chat->chat_id);
     } else {
         $chat = new Chat();
         $chat->construct($chat_update['id'], $chat->determineChatType($chat_update), isset($chat_update['title']) ? $chat_update['title'] : NULL, 0);
         $changed = true;
     }
     if ($changed) {
         $chat->save($db);
     }
     return $chat;
 }
Exemplo n.º 2
0
 public function main()
 {
     if ($this->Message->Chat->isPrivate()) {
         $this->chat = NULL;
     } else {
         $this->chat = $this->Message->Chat;
     }
     if ($this->noParams() == 2) {
         if (strcmp($this->getParam(), '_view_chat') === 0) {
             $DbChat = new \GroupBot\Database\Chat($this->db);
             if ($this->chat = $DbChat->getChatById($this->getParam(1))) {
                 $out = $this->displayLeaderboard();
                 $out .= $this->displayInstructions();
             } else {
                 $out = emoji(0x1f44e) . " Can't find that chat, displaying the Global Leaderboard instead.\n\n";
                 $this->chat = NULL;
                 $out .= $this->displayLeaderboard();
                 $out .= $this->displayInstructions();
             }
         } else {
             $out = $this->performVote();
             //$out .= $this->displayLeaderboard();
             $out .= $this->displayInstructions();
         }
     } else {
         $out = $this->displayLeaderboard();
         $out .= $this->displayInstructions();
     }
     if ($this->Message->Chat->isPrivate()) {
         if ($this->Message->isCallback()) {
             Telegram::edit_inline_message($this->Message->Chat->id, $this->Message->message_id, $out, $this->keyboard);
         } else {
             Telegram::talk_inline_keyboard($this->Message->Chat->id, $out, $this->keyboard);
         }
     } else {
         Telegram::talk($this->Message->Chat->id, $out);
     }
     return true;
 }