-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.php
75 lines (58 loc) · 1.96 KB
/
test.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
<?php
error_reporting(E_ALL);
set_time_limit(0);
ob_implicit_flush();
require __DIR__."/bootstrap/autoload.php";
loadConfig("telegram_bot");
$st = new TeaBot\CaptchaThread(BOT_TOKEN, "/tmp/telegram/captcha_handler");
$address = "0.0.0.0";
$port = 10001;
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
exit(1);
}
if (socket_bind($sock, $address, $port) === false) {
echo "socket_bind() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
exit(1);
}
if (socket_listen($sock, 5) === false) {
echo "socket_listen() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
exit(1);
}
echo "Listening on {$address}:{$port}...\n";
do {
if (($msgsock = socket_accept($sock)) === false) {
echo "socket_accept() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
break;
}
$buf = socket_read($msgsock, 7, PHP_NORMAL_READ);
if (false === ($buf = socket_read($msgsock, (int)$buf, PHP_NORMAL_READ))) {
echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($msgsock)) . "\n";
break;
}
echo $buf."\n";
$json = json_decode($buf, true);
if (isset($json["answer_okx"])) {
$st->cancel(
$json["answer_okx"],
$json["ok_msg_id"],
$json["c_answer_id"],
$json["cancel_sleep"] ?? 60
);
} else {
$msg = (string)$st->dispatch(
$json['type'],
(int)$json['sleep'],
(int)$json['user_id'],
$json['chat_id'],
(int)$json['join_msg_id'],
(int)$json['captcha_msg_id'],
(int)$json['welcome_msg_id'],
$json['banned_hash'],
$json['mention']
);
socket_write($msgsock, $msg, strlen($msg));
}
socket_close($msgsock);
} while (true);
socket_close($sock);