-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.php
More file actions
55 lines (48 loc) · 1.5 KB
/
background.php
File metadata and controls
55 lines (48 loc) · 1.5 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
50
51
52
53
54
55
<?php
require_once __DIR__ . '/vendor/autoload.php';
$userId = intval($argv[1]);
$chatId = intval($argv[2]);
if($userId == null || $chatId == null) {
error_log('missing parameters');
exit;
}
while (true){
if(
date("H") == "6" ||
date("H") == "10" ||
date("H") == "16"
) {
$memoryRepository = new \Anna\Repository\MemoriesRepository();
$result = $memoryRepository->read([
'user_id' => $userId,
'chat_id' => $chatId
]);
$text = '';
if(!empty($result)) {
$text = "Mi hai detto di ricordarti di:\n";
foreach ($result as $memory) {
$text .= "-\t" . $memory['text'] . "\n";
}
} else {
$userRepository = new \Anna\Repository\UserRepository();
$result = $userRepository->read([
'id' => $userId
]);
if(empty($result)) exit;
}
$BOT_TOKEN = '{{ BOT_TOKEN }}';
$API_URL = 'https://api.telegram.org/bot' . $BOT_TOKEN .'/';
$method = 'sendMessage';
$parameters = [
'chat_id' => $chatId,
'text' => $text
];
$url = $API_URL . $method. '?' . http_build_query($parameters);
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($handle, CURLOPT_TIMEOUT, 60);
$result = curl_exec($handle);
sleep(200);
}
}