diff --git a/config.php b/config.php
index b8f5c97..b29ee4d 100644
--- a/config.php
+++ b/config.php
@@ -57,6 +57,7 @@
$WELCOME_MESSAGE = "$EMOJI_BOT GOLEMbot
$EMOJI_MSG Se scrivi un messaggio ti chiedo se inoltrarlo al canale
+Supporto anche **grassetto**, __corsivo__ e `codice
`
$EMOJI_TOOLS Se scrivi un comando eseguo operazioni.
Comandi disponibili: /help, /list";
?>
diff --git a/main.php b/main.php
index 29b3839..0421474 100644
--- a/main.php
+++ b/main.php
@@ -358,7 +358,7 @@ if (isset ($row->callback_query)) {
for ($i = 8; $i <= 21; $i++) {
if ($i < $firstHour)
- $kbd->insertItem(" ", null);
+ $kbd->insertItem(" ", "null");
else
$kbd->insertItem("$i".":00", $i);
@@ -373,7 +373,6 @@ if (isset ($row->callback_query)) {
$text="A che ora vuoi inviare il messaggio?";
- $reply = json_encode($container);
//~ $url = API_URL.API_TOKEN."/editMessageText?chat_id=".($chatID).
//~ "&message_id=".$inlineID .
@@ -491,137 +490,152 @@ elseif (isset($row->message)) {
}
if (DEBUG) info("Starting from status $status");
- switch($status) {
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * entering STATE_IDLE - message *
- * you can: give a command, send messages to forward *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- case STATE_IDLE:
- if (($command = getCommand($row->message)) != null) {
- info("Command received: $command[command] with options $command[options]");
-
- switch ($command['command']) {
- case '/help':
- case '/start':
- // Send some explainations about this bot
- sendMessage($chatID,$WELCOME_MESSAGE);
- break;
-
- case '/edit':
- // not yet implemented
- sendMessage($chatID, "Bravo! Hai trovato un comando non ancora implementato. Apri il codice su GitHub e lavoraci su",
- "HTML", false, false, null, $reply);
- break;
-
- case '/list':
-
- $sql = new mysqli('localhost', MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB);
- $numbers = $sql->query("SELECT COUNT(*) FROM ".MYSQL_TABLE);
- $numbers = $numbers->fetch_array()[0];
- if ($numbers == 0) {
- $query = API_URL.API_TOKEN."/sendmessage?chat_id=".($chatID).
- "&text=Nessun messaggio programmato";
- $answer = file_get_contents($query);
- die();
- }
-
- $query = $sql->query("SELECT DATE_FORMAT(DateTime,'%d/%m/%Y ore %H') as DateTimeFormat,ChatID, MessageID,Text,Author,ID FROM ".MYSQL_TABLE."
- ORDER BY DateTime ASC LIMIT 1") or error("Can't make the query, SQL error ".$sql->error);
-
- //while($row = $query->fetch_assoc()) {
- $row = $query->fetch_assoc();
- $mc->set($chatID.MC_DELETE_SCHEDULED_ID, $row['ID'])
- or $mc->replace($chatID.MC_DELETE_SCHEDULED_ID, $row['ID']);;
-
- $sql->close();
-
- $kbd = new InlineKbd;
- $kbd->insertItem($row['DateTimeFormat'], "null");
- $kbd->pushLine();
- $kbd->insertItem(" ","null");
- $kbd->insertItem("$EMOJI_THUMBSDOWN Canc", MSG_DELETE);
- if ($numbers > 1)
- $kbd->insertItem(">", ">");
- else
- $kbd->insertItem("","null");
- $kbd->pushLine();
-
-
- if ($row['Text'] != ''){
- $text="$row[Text]\n$row[Author]"; // NOME CANALE ".API_CHANNEL_ID."?";
- }
- else
- $text="Non testo puro";
-
-
- $answer = sendMessage($chatID, $text, "HTML", false, false, null, $kbd->getKeyboard());
- $answer = json_decode($answer);
- // Should forward the message if is not pure text
- //forwardMessage($chatID, $row['ChatID'], $row['MessageID']);
-
-
- $mc->set($chatID.MC_INLINE_ID, $answer->result->message_id)
- or $mc->replace($chatID.MC_INLINE_ID, $answer->result->message_id);
-
- $mc->set($chatID.MC_LIST_NUMBER, 0)
- or $mc->replace($chatID.MC_LIST_NUMBER, 0);
- break;
-
- default:
- sendMessage($chatID,"Non è un comando valido, leggi i comandi digitando /help");
- warning("$command[command] is not a valid command");
- }
+ // Reset CMD
+ if (($command = getCommand($row->message))['command'] == '/reset') {
+ warning("Reset command received");
+ $all_keys = $mc->getAllKeys();
+ foreach ($all_keys as $index => $key) {
+ if (strpos($key,$chatID) !== 0) {
+ $mc->delete($key);
+ info("Deleting $key");
}
- else { // not a command (text?)
- // you probably want to forward a message?
-
- // Check what kind of message is this
- $kbd = new InlineKbd;
- $kbd->insertItem("SI ".$EMOJI_THUMBSUP,MSG_YES);
- $kbd->insertItem("NO ".$EMOJI_THUMBSDOWN,MSG_NO);
- $kbd->insertItem("Programma ".$EMOJI_CLOCK,MSG_SCHEDULE);
- $kbd->pushLine();
-
- // This bot accepts only text, images, videos and locations
- if (!(isset($row->message->photo) or isset($row->message->location)
- or isset($row->message->video) or isset($row->message->text) )) {
- sendMessage($chatID, "Questa roba non va bene");
- error("Not supported content");
- // Program stops here
- }
-
- $mc->set($chatID.MC_FORWARD_MSG, $row)
- or $mc->replace($chatID.MC_FORWARD_MSG, $row)
- or error("Something is wrong with memcached");
-
- // SetUp inline messages (OK, NO, SCHEDULE)
-
- $text="Vuoi condividere sul canale?"; // NOME CANALE ".API_CHANNEL_ID."?";
-
- $query = sendMessage($row->message->chat->id,
- $text,
- null, false, false, null,
- $kbd->getKeyboard());
-
- //~ $answer = file_get_contents($query);
- $answer = json_decode($query);
-
- $inlineID = $answer->result->message_id;
- if (DEBUG) info("Callback message id: $inlineID");
-
-
- $mc->replace($chatID.MC_STATUS, STATE_MSG_ANSWER);
- $mc->set($chatID.MC_INLINE_ID, $inlineID) or $mc->replace($chatID.MC_INLINE_ID, $inlineID);
+ else {
+ unset($all_keys[$index]);
}
- break;
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * END STATE_IDLE
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- default:
- wrong_action($chatID);
+ }
+ sendMessage($chatID, "Reset completato");
}
+ else {
+ switch($status) {
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * entering STATE_IDLE - message *
+ * you can: give a command, send messages to forward *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+ case STATE_IDLE:
+ if (($command = getCommand($row->message)) != null) {
+ info("Command received: $command[command] with options $command[options]");
+
+ switch ($command['command']) {
+ case '/help':
+ case '/start':
+ // Send some explainations about this bot
+ sendMessage($chatID,$WELCOME_MESSAGE, "HTML");
+ break;
+
+ case '/edit':
+ // not yet implemented
+ sendMessage($chatID, "Bravo! Hai trovato un comando non ancora implementato. Apri il codice su GitHub e lavoraci su");
+ break;
+
+ case '/list':
+
+ $sql = new mysqli('localhost', MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB);
+ $numbers = $sql->query("SELECT COUNT(*) FROM ".MYSQL_TABLE);
+ $numbers = $numbers->fetch_array()[0];
+ if ($numbers == 0) {
+ $query = API_URL.API_TOKEN."/sendmessage?chat_id=".($chatID).
+ "&text=Nessun messaggio programmato";
+ $answer = file_get_contents($query);
+ die();
+ }
+
+ $query = $sql->query("SELECT DATE_FORMAT(DateTime,'%d/%m/%Y ore %H') as DateTimeFormat,ChatID, MessageID,Text,Author,ID FROM ".MYSQL_TABLE."
+ ORDER BY DateTime ASC LIMIT 1") or error("Can't make the query, SQL error ".$sql->error);
+
+ //while($row = $query->fetch_assoc()) {
+ $row = $query->fetch_assoc();
+ $mc->set($chatID.MC_DELETE_SCHEDULED_ID, $row['ID'])
+ or $mc->replace($chatID.MC_DELETE_SCHEDULED_ID, $row['ID']);;
+ $sql->close();
+
+ $kbd = new InlineKbd;
+ $kbd->insertItem($row['DateTimeFormat'], "null");
+ $kbd->pushLine();
+ $kbd->insertItem(" ","null");
+ $kbd->insertItem("$EMOJI_THUMBSDOWN Canc", MSG_DELETE);
+ if ($numbers > 1)
+ $kbd->insertItem(">", ">");
+ else
+ $kbd->insertItem("","null");
+ $kbd->pushLine();
+
+
+ if ($row['Text'] != ''){
+ $text="$row[Text]\n$row[Author]"; // NOME CANALE ".API_CHANNEL_ID."?";
+ }
+ else
+ $text="Non testo puro";
+
+
+ $answer = sendMessage($chatID, $text, "HTML", false, false, null, $kbd->getKeyboard());
+ $answer = json_decode($answer);
+ // Should forward the message if is not pure text
+ //forwardMessage($chatID, $row['ChatID'], $row['MessageID']);
+
+
+ $mc->set($chatID.MC_INLINE_ID, $answer->result->message_id)
+ or $mc->replace($chatID.MC_INLINE_ID, $answer->result->message_id);
+
+ $mc->set($chatID.MC_LIST_NUMBER, 0)
+ or $mc->replace($chatID.MC_LIST_NUMBER, 0);
+ break;
+
+ default:
+ sendMessage($chatID,"Non è un comando valido, leggi i comandi digitando /help");
+ warning("$command[command] is not a valid command");
+ }
+ }
+ else { // not a command (text?)
+ // you probably want to forward a message?
+
+ // Check what kind of message is this
+ $kbd = new InlineKbd;
+ $kbd->insertItem("SI ".$EMOJI_THUMBSUP,MSG_YES);
+ $kbd->insertItem("NO ".$EMOJI_THUMBSDOWN,MSG_NO);
+ $kbd->insertItem("Programma ".$EMOJI_CLOCK,MSG_SCHEDULE);
+ $kbd->pushLine();
+
+ // This bot accepts only text, images, videos and locations
+ if (!(isset($row->message->photo) or isset($row->message->location)
+ or isset($row->message->video) or isset($row->message->text) )) {
+ sendMessage($chatID, "Questa roba non va bene");
+ error("Not supported content");
+ // Program stops here
+ }
+
+ $mc->set($chatID.MC_FORWARD_MSG, $row)
+ or $mc->replace($chatID.MC_FORWARD_MSG, $row)
+ or error("Something is wrong with memcached");
+
+ // SetUp inline messages (OK, NO, SCHEDULE)
+
+ $text="Vuoi condividere sul canale?"; // NOME CANALE ".API_CHANNEL_ID."?";
+
+ $query = sendMessage($row->message->chat->id,
+ $text,
+ null, false, false, null,
+ $kbd->getKeyboard());
+
+ //~ $answer = file_get_contents($query);
+ $answer = json_decode($query);
+
+ $inlineID = $answer->result->message_id;
+ if (DEBUG) info("Callback message id: $inlineID");
+
+
+ $mc->replace($chatID.MC_STATUS, STATE_MSG_ANSWER);
+ $mc->set($chatID.MC_INLINE_ID, $inlineID) or $mc->replace($chatID.MC_INLINE_ID, $inlineID);
+ }
+ break;
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * END STATE_IDLE
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+ default:
+ wrong_action($chatID);
+ }
+ }
}
// a not supported message (i.e. from a channel)
else {