Browse Source

New function for message listing

master
giuliof 5 years ago
parent
commit
d889e59a31
  1. 143
      main.php
  2. 56
      shared.php

143
main.php

@ -100,89 +100,39 @@ if (isset ($row->callback_query)) {
case STATE_IDLE:
switch ($callback_data){
case MSG_DELETE:
// remove current message
$sql = new mysqli('localhost', MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB);
$IDdelete = $mc->get($chatID.MC_DELETE_SCHEDULED_ID) or error("No ID to delete");
$sql->query("DELETE FROM ".MYSQL_TABLE." WHERE ID=$IDdelete")
or error("Can't make the query, SQL error ".$sql->error);
$numbers = $sql->query("SELECT COUNT(*) FROM ".MYSQL_TABLE);
$numbers = $numbers->fetch_array()[0];
info("Number of pages: $numbers");
$sql->close();
$offset = $mc->get($chatID.MC_LIST_NUMBER);
if ($numbers == 0) {
editMessageText($chatID, $inlineID, "Non ce n'è più");
$sql->close();
die();
}
elseif ($offset > 0) {
if ($offset > 0) {
$offset--;
}
//~ die();
break;
case '>':
$sql = new mysqli('localhost', MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB);
$numbers = $sql->query("SELECT COUNT(*) FROM ".MYSQL_TABLE);
$numbers = $numbers->fetch_array()[0];
info("Number of pages: $numbers");
$offset = $mc->get($chatID.MC_LIST_NUMBER);
// gestire meglio qui
$offset++;
$offset++; // nobody cares if goes over # of programmed messages
break;
case '<':
$sql = new mysqli('localhost', MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB);
$numbers = $sql->query("SELECT COUNT(*) FROM ".MYSQL_TABLE);
$numbers = $numbers->fetch_array()[0];
info("Number of pages: $numbers");
$offset = $mc->get($chatID.MC_LIST_NUMBER);
// gestire meglio qui
$offset--;
if ($offset > 0)
$offset--;
break;
default:
if (DEBUG) warning("Callback request is not accepted in status $status");
die();
}
$query = $sql->query("SELECT DATE_FORMAT(DateTime,'%d/%m/%Y ore %H') as DateTimeFormat,Text,Author,ID FROM ".MYSQL_TABLE."
ORDER BY DateTime ASC LIMIT 1 OFFSET $offset") 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']);
//~ $query = API_URL . API_TOKEN . '/forwardMessage?' .
//~ 'chat_id=' . urlencode($chatID) .
//~ '&from_chat_id=' . urlencode($row['ChatID']) .
//~ '&message_id=' . urlencode($row['MessageID']);
//~ $answer = file_get_contents($query);
//~ $answer = json_decode($answer);
$sql->close();
$archivedMsg = navigateMsgArchive($offset, $mc, $chatID);
$kbd = new InlineKbd;
$kbd->insertItem($row['DateTimeFormat'], "null");
$kbd->pushLine();
if ($offset > 0)
$kbd->insertItem("<","<");
else
$kbd->insertItem(" ","null");
$kbd->insertItem("$EMOJI_THUMBSDOWN Canc",MSG_DELETE);
if ($offset < $numbers-1)
$kbd->insertItem(">",">");
else
$kbd->insertItem(" ","null");
$kbd->pushLine();
$text="$row[Text]\n<i>$row[Author]</i>"; // NOME CANALE ".API_CHANNEL_ID."?";
//~ $query = API_URL.API_TOKEN."/editMessageText?chat_id=".($chatID).
//~ "&message_id=".$inlineID.
//~ "&text=".urlencode($text).
//~ "&parse_mode=".urlencode("Markdown").
//~ "&reply_markup=".$reply;
//~ $answer = file_get_contents($query);
$answer = editMessageText($chatID, $inlineID, $text,
"HTML", false, $kbd->getKeyboard() );
$answer = editMessageText($chatID, $inlineID, $archivedMsg['text'],
"HTML", false, $archivedMsg['kbd'] );
$answer = json_decode($answer);
$mc->set($chatID.MC_LIST_NUMBER, $offset)
@ -218,28 +168,8 @@ if (isset ($row->callback_query)) {
$msg = $mc->get($chatID.MC_FORWARD_MSG)
or error("Can't forward message\n");
//~ $query = API_URL . API_TOKEN . '/sendmessage?' .
//~ 'chat_id=' . urlencode(API_CHANNEL_ID) .
//~ '&text='.urlencode($msg->message->text."\n_".$msg->message->chat->username."_").
//~ "&parse_mode=".urlencode("Markdown"); //bah, un isset un ce lo vedrei male
//~ $result = file_get_contents($query);
// A new test
forwardMessage(API_CHANNEL_ID, $msg->message->chat->id, $msg->message->message_id, true);
/*
if (isset($msg->message->text)) {
$result = sendMessage(API_CHANNEL_ID,
$msg->message->text."\n_".$msg->message->chat->username."_",
"Markdown");
if(DEBUG) botlog("[LOG] $result\n");
}
elseif (isset($msg->message->photo)) {
sendPhoto(API_CHANNEL_ID,$msg->message->photo[0]->file_id,
isset($msg->message->caption) ? $msg->message->caption : null);
}
*/
// Remove kbd
$text = "Invio effettuato correttamente";
editMessageText($chatID, $inlineID, $text);
@ -256,10 +186,6 @@ if (isset ($row->callback_query)) {
// destroy saved message?
$text = "Invio annullato correttamente";
editMessageText($chatID, $inlineID, $text);
//~ $url = API_URL.API_TOKEN."/editMessageText?chat_id=".($chatID).
//~ "&message_id=".$inlineID .
//~ "&text=".urlencode($text);
//~ file_get_contents($url);
break;
case MSG_SCHEDULE:
@ -276,14 +202,8 @@ if (isset ($row->callback_query)) {
$mc->set($chatID.MC_DATE_MSG, $currentTab) or $mc->replace($chatID.MC_DATE_MSG, $currentTab) or die ();
$text="Quando vuoi inviare il messaggio?";
//~ $url = API_URL.API_TOKEN."/editMessageText?chat_id=".($chatID).
//~ "&message_id=".$inlineID .
//~ "&text=".urlencode($text).
//~ "&reply_markup=".$reply;
editMessageText($chatID, $inlineID, $text, "HTML", false, $reply);
//~ file_get_contents($url);
$mc->set($chatID.MC_INLINE_ID, $inlineID) or $mc->replace($chatID.MC_INLINE_ID, $inlineID)
or error("Something is wrong with memcached");
// == end ==
@ -529,46 +449,9 @@ elseif (isset($row->message)) {
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<i>$row[Author]</i>"; // NOME CANALE ".API_CHANNEL_ID."?";
}
else
$text="Non testo puro";
$archivedMsg = navigateMsgArchive(0, $mc, $chatID);
$answer = sendMessage($chatID, $text, "HTML", false, false, null, $kbd->getKeyboard());
$answer = sendMessage($chatID, $archivedMsg['text'], "HTML", false, false, null, $archivedMsg['kbd']);
$answer = json_decode($answer);
// Should forward the message if is not pure text
//forwardMessage($chatID, $row['ChatID'], $row['MessageID']);

56
shared.php

@ -189,6 +189,62 @@
}
// Function used to get an archived message
// and make an appropriate keyboard
// -- I dont' like so much --
function navigateMsgArchive ($msgNumber, $mc, $chatID) {
$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) {
return array( "text" => "Nessun messaggio programmato",
"kbd" => null);
$sql->close();
//~ $query = API_URL.API_TOKEN."/sendmessage?chat_id=".($chatID).
//~ "&text=Nessun messaggio programmato";
//~ $answer = file_get_contents($query);
//~ die();
}
else {
$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 OFFSET $msgNumber") 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();
if ($msgNumber == 0)
$kbd->insertItem(" ","null");
else
$kbd->insertItem("<","<");
$kbd->insertItem("Rimuovi", MSG_DELETE);
if ($numbers - $msgNumber > 1)
$kbd->insertItem(">", ">");
else
$kbd->insertItem(" ","null");
$kbd->pushLine();
$kbd = $kbd->getKeyboard();
if ($row['Text'] != ''){
$text="$row[Text]\n<i>$row[Author]</i>"; // NOME CANALE ".API_CHANNEL_ID."?";
}
else
$text="Non testo puro";
return array( "text" => $text,
"kbd" => $kbd);
}
}
function not_authorized($chatID) {
$query = API_URL . API_TOKEN . '/sendMessage?' .
'chat_id=' . urlencode($chatID) .

Loading…
Cancel
Save