-
Notifications
You must be signed in to change notification settings - Fork 4
/
base3.php
54 lines (48 loc) · 1.96 KB
/
base3.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
<?php
set_include_path(get_include_path().':'.realpath(dirname(__FILE__).'/MadelineProto/'));
if (!file_exists('madeline.php')) {
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
}
define('MADELINE_BRANCH', 'deprecated');
include 'madeline.php';
class EventHandler extends \danog\MadelineProto\EventHandler
{
public function onAny($update)
{
if ($update['message']['out']?? null) {
return;
}
$res = json_encode($update, JSON_PRETTY_PRINT);
if ($res == '') {
$res = var_export($update, true);
}
try {
$this->messages->sendMessage([
'peer' => $update,
'message' => $res,
'reply_to_msg_id' => $update['message']['id']?? null,
'entities' => [[
'_' => 'messageEntityPre',
'offset' => 0,
'length' => strlen($res),
'language' => 'json'
]]
]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
\danog\MadelineProto\Logger::log((string) $e, \danog\MadelineProto\Logger::FATAL_ERROR);
} catch (\danog\MadelineProto\Exception $e) {
\danog\MadelineProto\Logger::log((string) $e, \danog\MadelineProto\Logger::FATAL_ERROR);
//$this->messages->sendMessage([
// 'peer' => '@danogentili',
// 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()
//]);
}
}
}
if (file_exists('MadelineProto.log')) {unlink('MadelineProto.log');}
$settings['logger']['logger_level'] = \danog\MadelineProto\Logger::ULTRA_VERBOSE;
$settings['logger']['logger'] = \danog\MadelineProto\Logger::FILE_LOGGER;
$MadelineProto = new \danog\MadelineProto\API('session.madeline', $settings);
$MadelineProto->start();
$MadelineProto->setEventHandler('\EventHandler');
$MadelineProto->loop();