} } else { // It's a message! $message =& $update['message']; $text = trim($message['text']); if (is_command($text, '/start')) { // Exists? $exists = $db->getRow(sprintf("SELECT 1 FROM {$db->getTable('spotter')} " . "WHERE spotter_chat_ID = '%d'", $message['chat']['id'])); // Insert if not exists $exists || $db->insertRow('spotter', [new DBCol('spotter_chat_id', $message['chat']['id'], 'd'), new DBCol('spotter_datetime', 'NOW()', '-')]); apiRequest('sendMessage', ['chat_id' => $message['chat']['id'], 'text' => _("Ecco... /ciclo, /mamma o /spotted?")]); } elseif (is_command($text, '/ciclo')) { apiRequest('sendMessage', ['chat_id' => $message['chat']['id'], 'text' => _("Non ho cicli mestruali. Screanzato!")]); } elseif (is_command($text, '/mamma')) { apiRequest('sendMessage', ['chat_id' => $message['chat']['id'], 'text' => _("TUA MADRE?")]); } elseif (is_command($text, '/spotted')) { $spotted = ltrim(str_replace('/spotted', '', $text)); if (strlen($spotted) === 0) { apiRequest('sendMessage', ['chat_id' => $message['chat']['id'], 'text' => _("Questo comando serve a mandare messaggi accazzo.\n Esempio:\n\n/spotted Dio Cane!")]); } else { $spotted = str_truncate($spotted, 300, '...'); $db->insertRow('spotted', [new DBCol('spotted_datetime', 'NOW()', '-'), new DBCol('spotted_message', $spotted, 's'), new DBCol('spotted_chat_id', $message['chat']['id'], 'd')]); $spotted_ID = $db->getLastInsertedID(); $spotters = $db->getResults("SELECT spotter_ID FROM {$db->getTable('spotter')}", 'Spotter'); $fifo_rows = []; foreach ($spotters as $spotter) { $fifo_rows[] = [$spotted_ID, $spotter->spotter_ID]; } $db->insert('fifo', ['spotted_ID' => 'd', 'spotter_ID' => 'd'], $fifo_rows); apiRequest('sendMessage', ['chat_id' => $message['chat']['id'], 'text' => sprintf(_("Sta roba sta per esser mandata a *%d* persone:\n- «%s»\n\nA me pare na gran cazzata... Però sarà fatto fra pochi istanti."), count($spotters), $spotted), 'parse_mode' => 'markdown']); }
$spotters = query_results("SELECT spotter_ID FROM {$T('spotter')}", 'Spotter'); $fifo_rows = []; foreach ($spotters as $spotter) { $fifo_rows[] = [$spotted_ID, $spotter->spotter_ID]; } insert_values('fifo', ['spotted_ID' => 'd', 'spotter_ID' => 'd'], $fifo_rows); } refresh_admin_keyboard($update['message']['chat']['id'], "Messaggio pubblicato"); } elseif (is_command($text, 'Elimina')) { $spotted_ID = (int) trim(str_replace("Elimina", '', $text)); $spotted_ID && query(sprintf("DELETE FROM {$T('spotted')} WHERE spotted_ID = %d", $spotted_ID)); refresh_admin_keyboard($update['message']['chat']['id'], "Messaggio eliminato"); } elseif (is_command($text, '/help')) { $text = ltrim(str_replace('/help', '', $text)); if (strlen($text) === 0) { apiRequest('sendMessage', ['chat_id' => $update['message']['chat']['id'], 'text' => _("Per inviare un messaggio ai programmatori, scrivi <code>/help messaggio</code>.\n" . "(Es. /help Salve, non riesco a mandare uno spot perche'...)"), 'parse_mode' => 'HTML']); } else { apiRequest('sendMessage', ['chat_id' => WANZO, 'text' => _("E' stato richiesto un help con messaggio: " . $text . "\nDa: " . $first_name . " " . $last_name . " @" . $username . " " . $chat_id), 'parse_mode' => 'HTML']); } } elseif (is_command($text, '/messaggio')) { $text = ltrim(str_replace('/messaggio', '', $text)); $text = explode('->', $text); $messaggio = $text[1]; $chat_id = $text[0]; apiRequest('sendMessage', ['chat_id' => $chat_id, 'text' => _("- <b>Messaggio dal team di SpottedUnito</b> -\n\n" . $messaggio), 'parse_mode' => "HTML"]); } else { apiRequest('sendMessage', ['chat_id' => $update['message']['chat']['id'], 'text' => _("Nessun comando disponibile con le parole <code>{$text}</code>. Digita o clicca su /start per rivedere le istruzioni."), 'parse_mode' => "HTML"]); } } // At the end... Try sending some messages... spotted_fifo(3);
<?php //include "../commands.php"; if (!isset($_POST['command'])) { die; } $command = $_POST['command']; $success = "done."; $failure = "<< invalid <<"; if (is_command($command)) { die($success); } die($failure); function is_command($command) { return false; }