-
Notifications
You must be signed in to change notification settings - Fork 13
/
crone.php
80 lines (69 loc) · 2.12 KB
/
crone.php
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
include 'Telegram.php';
include 'functions.php';
$tg = new Telegram([
'token' => ""
]);
function scan_index($rootDir, $allData=[]) {
$invisibleFileNames = [".", "..", ".htaccess", ".htpasswd", "errors", "index.html"];
$dirContent = array_diff(scandir($rootDir), ['..', '.']);
foreach($dirContent as $key => $content) {
$path = $rootDir.$content;
if ( preg_match('/(.*).json/', $content)) {
$allData[$path] = filemtime($path);
}
}
asort($allData);
return $allData;
}
function send_notifications() {
global $tg;
if (message_status() == 'off') return;
$message = scan_index(dirname(__FILE__) . '/notifications/');
if ( !empty( $message )) {
$x = 0;
foreach ($message as $k => $v) {
if (message_status() == 'off') return;
if($x == 5){
sleep(1);
$x = 0;
}
$item = file_get_contents($k);
$item = json_decode($item, TRUE);
$chat_id = $item['chat_id'];
$tg->set_chatId( $chat_id );
if ( !empty( $item['text'] ) ) {
$res = $tg->send_chatAction('typing')->send_message( $item['text'] )->result();
}
if ( !empty( $item['photo'] ) ) {
$caption = (!empty( $item['caption'])) ? $item['caption'] : '';
$res = $tg->send_chatAction('upload_photo')->send_photo($item['photo'], $caption)->result();
}
if ( !empty( $item['video'] ) ) {
$caption = (!empty( $item['caption'])) ? $item['caption'] : '';
$res = $tg->send_chatAction('upload_video')->send_video($item['video'], $caption)->result();
}
if ( !empty( $item['from_chat_id'] ) ) {
$res = $tg->request('forwardMessage', [
'chat_id' => $chat_id,
'from_chat_id' => $item['from_chat_id'],
'message_id' => $item['message_id']
]);
}
if (!empty($res['ok']) && !empty($res['description'])) {
if($res['description'] == "Forbidden: bot was blocked by the user"){
//@unlink( dirname(__FILE__) . '/data/users/'.$chat_id.'.json' );
}else if(intval($res['error_code']) == 429){
sleep(intval($res['parameters']['retry_after']));
return;
}
}
@unlink($k);
$x++;
}
}
}
while (1){
send_notifications();
sleep(1);
}