golem-telegram-bot/schedule.php

38 lines
1.2 KiB
PHP
Raw Normal View History

2017-09-24 20:23:45 +00:00
<?php
/*
* This script must be called from the system every hour (i.e. cron)
*/
2017-09-24 20:23:45 +00:00
require_once('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");
// Get current date in MySQL DATETIME default format
2017-11-03 13:41:29 +00:00
$dateID = date('Y-n-d G:00');
// Connect to MySQL DB
2017-09-24 20:23:45 +00:00
$sql = new mysqli('localhost', MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB);
2017-11-03 13:41:29 +00:00
$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)
2017-09-24 20:23:45 +00:00
while ($row = $query->fetch_assoc()) {
info("Publishing message $row[MessageID]");
2017-11-03 13:41:29 +00:00
/*
$bot_query = API_URL . API_TOKEN . '/sendMessage?' .
2017-09-24 20:23:45 +00:00
'chat_id=' . urlencode(API_CHANNEL_ID) .
'&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
* */
forwardMessage(API_CHANNEL_ID, $row['ChatID'], $row['MessageID']);
2017-09-24 20:23:45 +00:00
}
// Remove just posted messages (and any eventual previous one)
2017-09-24 20:23:45 +00:00
$sql->query("DELETE FROM ".MYSQL_TABLE." WHERE DateTime<='".$dateID."'");
$sql->close();
?>