-
Notifications
You must be signed in to change notification settings - Fork 0
/
poll.php
38 lines (28 loc) · 894 Bytes
/
poll.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
<?php
declare(strict_types=1);
if (!isset($_SERVER['LNBITS_API_KEY'])) {
die('LNBITS_API_KEY env var is not defined' . PHP_EOL);
}
require_once __DIR__ . '/vendor/autoload.php';
touch(__DIR__ . '/.last-payment');
$lastPayment = file_get_contents(__DIR__ . '/.last-payment');
$response = (new \GuzzleHttp\Client())->get(
'https://legend.lnbits.com/api/v1/payments?limit=20',
['headers' => ['X-Api-Key' => $_SERVER['LNBITS_API_KEY']]]
);
$data = json_decode((string) $response->getBody());
$triggerBot = false;
foreach ($data as $payment) {
if ($payment->checking_id === $lastPayment) {
break;
}
if ($payment->amount >= 100000) {
$triggerBot = true;
}
}
if ($triggerBot) {
echo shell_exec('php ' . __DIR__ . '/bot.php | noscl publish -');
}
if (!empty($data)) {
file_put_contents(__DIR__ . '/.last-payment', $data[0]->checking_id);
}