34 lines
1.1 KiB
PHP
34 lines
1.1 KiB
PHP
<?php
|
|
/*
|
|
* This script must be called from the system every hour (i.e. cron)
|
|
*/
|
|
|
|
require_once('config.php');
|
|
require_once('functions.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:*');
|
|
|
|
// 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."'")
|
|
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);
|
|
}
|
|
|
|
// Remove just posted messages (and any eventual previous one)
|
|
$sql->query("DELETE FROM ".MYSQL_TABLE." WHERE DateTime<='".$dateID."'");
|
|
$sql->close();
|
|
?>
|