2017-09-24 20:23:45 +00:00
|
|
|
<?php
|
2017-09-28 19:41:43 +00:00
|
|
|
/*
|
|
|
|
* This script must be called from the system every hour (i.e. cron)
|
|
|
|
*/
|
|
|
|
|
2020-12-05 21:51:01 +00:00
|
|
|
require_once('/data/config.php');
|
2017-11-03 13:41:29 +00:00
|
|
|
require_once('shared.php');
|
2017-09-24 20:23:45 +00:00
|
|
|
|
|
|
|
if (DEBUG) botlog("\n\n\n".'[II] Scheduler starting at ' . date('Y-m-d H:i:s') . ' ====================' . "\n\n");
|
|
|
|
|
2020-12-05 18:28:53 +00:00
|
|
|
// Get current date in sqlite datetime format
|
|
|
|
$dateID = date('Y-m-d H:i:s');
|
2017-09-28 19:41:43 +00:00
|
|
|
|
|
|
|
// Connect to MySQL DB
|
2020-12-05 18:28:53 +00:00
|
|
|
$sql = new Sqlite3(DBFILE);
|
|
|
|
$query = $sql->query("SELECT MessageID,ChatID,DateTime,Text,Author FROM telegram_post WHERE DateTime<='".$dateID."'")
|
2017-09-28 19:41:43 +00:00
|
|
|
or error("Can't make the query, SQL error ".$sql->error);
|
|
|
|
|
|
|
|
// Post all messages (only text)
|
2020-12-05 18:28:53 +00:00
|
|
|
while ($row = $query->fetchArray()) {
|
2017-09-24 20:23:45 +00:00
|
|
|
info("Publishing message $row[MessageID]");
|
2017-11-03 13:41:29 +00:00
|
|
|
/*
|
2017-09-28 19:41:43 +00:00
|
|
|
$bot_query = API_URL . API_TOKEN . '/sendMessage?' .
|
2017-09-24 20:23:45 +00:00
|
|
|
'chat_id=' . urlencode(API_CHANNEL_ID) .
|
2017-09-28 19:41:43 +00:00
|
|
|
'&text=' . urlencode($row['Text']."\n_".$row['Author']."_").
|
|
|
|
"&parse_mode=".urlencode("Markdown");
|
2017-09-24 20:23:45 +00:00
|
|
|
file_get_contents($bot_query);
|
2017-11-03 13:41:29 +00:00
|
|
|
* */
|
2018-01-01 21:09:45 +00:00
|
|
|
forwardMessage(API_CHANNEL_ID, $row['ChatID'], $row['MessageID'], FORWARD_SILENT) or
|
2017-11-21 22:54:42 +00:00
|
|
|
error("Scheduler couldn't forward the message. I'll try next hour");
|
2017-11-03 13:41:29 +00:00
|
|
|
|
2017-09-24 20:23:45 +00:00
|
|
|
}
|
|
|
|
|
2020-12-05 18:28:53 +00:00
|
|
|
// Remove just posted messages (and possibly any previous one)
|
|
|
|
$sql->query("DELETE FROM telegram_post WHERE DateTime<='".$dateID."'");
|
2017-09-24 20:23:45 +00:00
|
|
|
$sql->close();
|
|
|
|
?>
|