-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_vk.php
More file actions
49 lines (41 loc) · 1.96 KB
/
check_vk.php
File metadata and controls
49 lines (41 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
include_once('base_loader.php');
$bots = TelegramBot::getAllBots($db, $config);
$statementUpdateLastMessageTime = $db->getConnect()->prepare('UPDATE `resources` SET `last_monitoring_info` = ? WHERE `id` = ?');
$statementGetAllResources = $db->getConnect()->prepare('SELECT * FROM `resources`');
$statementGetSubscribers = $db->getConnect()->prepare('SELECT * FROM `subscribers` WHERE `resource_id` = ?');
$statementGetAllResources->execute();
$resources = $statementGetAllResources->fetchAll(PDO::FETCH_ASSOC);
while (true) {
echo "start scan bots resource\n";
foreach ($bots as $bot) {
if (!($bot instanceof TelegramBot)) {
continue;
}
// get resource
$botId = $bot->getId();
echo "start scan bot {$botId}\n";
foreach ($resources as &$resource) {
if (empty($resource['bot_id']) || $resource['bot_id'] != $botId) {
continue;
}
echo "start scan resource {$resource['id']}\n";
$result = VKApi::getWallLastItemParsed($resource['id_in_resource'], 1);
var_dump(array(intval($result['date']), intval($resource['last_monitoring_info'])));
if (intval($result['date']) > intval($resource['last_monitoring_info'])) {
echo "resource {$resource['id']} send new message!!!\n";
// update last monitoring info
$statementUpdateLastMessageTime->execute(array($result['date'], $resource['id']));
$resource['last_monitoring_info'] = intval($result['date']);
// send message
$statementGetSubscribers->execute(array($resource['id']));
$subscribers = $statementGetSubscribers->fetchAll(PDO::FETCH_ASSOC);
foreach ($subscribers as $subscriber) {
$bot->getApi()->sendMessage($subscriber['chat_id'], $result['text']);
}
}
}
}
echo "sleep 5 seconds\n";
sleep(5);
}