-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.php
53 lines (37 loc) · 1.34 KB
/
bot.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
<?php
// This file gets executed every few seconds and handles everything
require_once 'config.php';
require_once 'lib/Store.php';
require_once 'lib/DevRant.php';
function botLog ($msg) {
if (DEBUG) echo 'Bot > ' . $msg . PHP_EOL;
}
$store = new Store('./store', ['prettify' => true, 'log' => DEBUG]);
$devRant = new DevRant($store);
$notifications = $devRant->getNotifications();
$devRant->clearNotifications();
usort($notifications['items'], function ($a, $b) {
return $a['created_time'] <=> $b['created_time'];
});
require_once 'lib/NotifHandler.php';
$notifHandler = new NotifHandler($store, $devRant);
$didSomething = false;
if (!isset($store('misc')['lastNotifTime']))
$store('misc')['lastNotifTime'] = time();
$lastNotifTime = $store('misc')['lastNotifTime'];
$newLastNotifTime = 0;
foreach ($notifications['items'] as $notification) {
if ($notification['type'] !== 'comment_mention')
continue;
if ($notification['created_time'] > $lastNotifTime || $notification['read'] === 0) {
botLog('Handling a here request notif (RantID: ' . $notification['rant_id'] . ')...');
$notifHandler->handleHereNotif($notification['rant_id'], $notification['uid']);
$didSomething = true;
$newLastNotifTime = $notification['created_time'];
}
}
if ($didSomething) {
$store('misc')['lastNotifTime'] = $newLastNotifTime;
} else {
botLog('Nothing to do...');
}