Better support for messages forwarding
This commit is contained in:
parent
3c4ab2e0c9
commit
98a1573901
48
main.php
48
main.php
|
@ -31,6 +31,7 @@ $mc->addServer('localhost', MEMCACHED_PORT)
|
|||
* **Generic message**
|
||||
* $row
|
||||
* |_ message § Message
|
||||
* |_ message_id § integer
|
||||
* |_ chat § chat
|
||||
* |_ id (chatID) § integer
|
||||
* |_ username (if set - user name for private chat, else channel or group name) § string
|
||||
|
@ -233,6 +234,11 @@ if (isset ($row->callback_query)) {
|
|||
//~ '&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."_",
|
||||
|
@ -243,7 +249,7 @@ if (isset ($row->callback_query)) {
|
|||
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);
|
||||
|
@ -466,9 +472,17 @@ if (isset ($row->callback_query)) {
|
|||
$value .= $currentTab['day'].' ';
|
||||
$value .= $callback_data.":00:00'";
|
||||
$value .= ",";
|
||||
$value .= "'".$sql->escape_string($msg->message->text)."'";
|
||||
if (isset($msg->message->text))
|
||||
$value .= "'".$sql->escape_string($msg->message->text)."'";
|
||||
else
|
||||
$value .= "''";
|
||||
$value .= ",";
|
||||
$value .= "'".$sql->escape_string($msg->message->from->username)."'"; // andrebbe fatto un isset, vabbé
|
||||
if (isset($msg->message->forward_from->username))
|
||||
$value .= "'".$sql->escape_string($msg->message->forward_from->username)."'";
|
||||
elseif (isset($msg->message->from->username))
|
||||
$value .= "'".$sql->escape_string($msg->message->from->username)."'";
|
||||
else
|
||||
$value .= "''";
|
||||
$value .= ");";
|
||||
|
||||
info("Saving post in ".MYSQL_TABLE.", scheduled date: ".$value);
|
||||
|
@ -550,7 +564,7 @@ elseif (isset($row->message)) {
|
|||
die();
|
||||
}
|
||||
|
||||
$query = $sql->query("SELECT DATE_FORMAT(DateTime,'%d/%m/%Y ore %H') as DateTime,Text,Author,ID FROM ".MYSQL_TABLE."
|
||||
$query = $sql->query("SELECT DATE_FORMAT(DateTime,'%d/%m/%Y ore %H') as ChatID, MessageID,DateTime,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()) {
|
||||
|
@ -592,15 +606,21 @@ elseif (isset($row->message)) {
|
|||
"inline_keyboard" => $container);
|
||||
$reply = json_encode($resp);
|
||||
|
||||
$text="$row[Text]\n_$row[Author]_"; // NOME CANALE ".API_CHANNEL_ID."?";
|
||||
if ($row[Text] != ''){
|
||||
$text="$row[Text]\n_$row[Author]_"; // NOME CANALE ".API_CHANNEL_ID."?";
|
||||
}
|
||||
else
|
||||
$text="Non testo puro";
|
||||
|
||||
$query = API_URL.API_TOKEN."/sendmessage?chat_id=".($chatID).
|
||||
"&text=".urlencode($text).
|
||||
"&parse_mode=".urlencode("Markdown").
|
||||
"&reply_markup=".$reply;
|
||||
"&text=".urlencode($text).
|
||||
"&parse_mode=".urlencode("Markdown").
|
||||
"&reply_markup=".$reply;
|
||||
$answer = file_get_contents($query);
|
||||
$answer = json_decode($answer);
|
||||
|
||||
|
||||
forwardMessage(API_CHANNEL_ID, $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);
|
||||
|
||||
|
@ -624,6 +644,10 @@ elseif (isset($row->message)) {
|
|||
array(
|
||||
"text" => "NO ".$EMOJI_THUMBSDOWN,
|
||||
"callback_data" => MSG_NO
|
||||
),
|
||||
array(
|
||||
"text" => "Programma ".$EMOJI_CLOCK,
|
||||
"callback_data" => MSG_SCHEDULE
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -640,11 +664,7 @@ elseif (isset($row->message)) {
|
|||
}
|
||||
// A common text message
|
||||
elseif (isset($row->message->text)) {
|
||||
$container[0][] =
|
||||
array(
|
||||
"text" => "Programma ".$EMOJI_CLOCK,
|
||||
"callback_data" => MSG_SCHEDULE
|
||||
);
|
||||
//.... nothing
|
||||
}
|
||||
// else... this is not supported
|
||||
else {
|
||||
|
|
12
schedule.php
12
schedule.php
|
@ -4,27 +4,31 @@
|
|||
*/
|
||||
|
||||
require_once('config.php');
|
||||
require_once('functions.php');
|
||||
require_once('shared.php');
|
||||
|
||||
if (DEBUG) botlog("\n\n\n".'[II] Scheduler starting at ' . date('Y-m-d H:i:s') . ' ====================' . "\n\n");
|
||||
|
||||
// Get current date in MySQL DATETIME default format
|
||||
$dateID = date('Y-n-j G:*');
|
||||
$dateID = date('Y-n-d G:00');
|
||||
|
||||
// Connect to MySQL DB
|
||||
$sql = new mysqli('localhost', MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB);
|
||||
$query = $sql->query("SELECT DateTime,Text,Author FROM ".MYSQL_TABLE.
|
||||
"WHERE DateTime='".$dateID."'")
|
||||
$query = $sql->query("SELECT MessageID,ChatID,DateTime,Text,Author FROM ".MYSQL_TABLE.
|
||||
" WHERE DateTime<='".$dateID."'")
|
||||
or error("Can't make the query, SQL error ".$sql->error);
|
||||
|
||||
// Post all messages (only text)
|
||||
while ($row = $query->fetch_assoc()) {
|
||||
info("Publishing message $row[MessageID]");
|
||||
/*
|
||||
$bot_query = API_URL . API_TOKEN . '/sendMessage?' .
|
||||
'chat_id=' . urlencode(API_CHANNEL_ID) .
|
||||
'&text=' . urlencode($row['Text']."\n_".$row['Author']."_").
|
||||
"&parse_mode=".urlencode("Markdown");
|
||||
file_get_contents($bot_query);
|
||||
* */
|
||||
forwardMessage(API_CHANNEL_ID, $row['ChatID'], $row['MessageID']);
|
||||
|
||||
}
|
||||
|
||||
// Remove just posted messages (and any eventual previous one)
|
||||
|
|
|
@ -70,9 +70,9 @@
|
|||
//
|
||||
function forwardMessage($chat_id, $from_chat_id,
|
||||
$message_id,
|
||||
$disable_notification = false) {
|
||||
$disable_notification = null) {
|
||||
|
||||
$query = API_URL . API_TOKEN . "/forwardMessage?" .
|
||||
$query = API_URL.API_TOKEN."/forwardMessage?" .
|
||||
"chat_id=".urlencode($chat_id) .
|
||||
"&from_chat_id=" . urlencode($from_chat_id) .
|
||||
"&message_id=" . urlencode($message_id);
|
||||
|
@ -80,7 +80,10 @@
|
|||
if ($disable_notification != null) $query .= "&disable_notification=$disable_notification";
|
||||
|
||||
$answer = file_get_contents($query);
|
||||
if ($answer === false) warning("Something is wrong in forwardMessage - chat_id: $chat_id - message_id: $message_id");
|
||||
if ($answer === false) {
|
||||
warning("Something is wrong in forwardMessage - chat_id: $chat_id - message_id: $message_id");
|
||||
warning($answer);
|
||||
}
|
||||
return $answer;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue