#!/usr/bin/env php . * * @author Daniil Gentili * @copyright 2016-2019 Daniil Gentili * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 * * @link https://docs.madelineproto.xyz MadelineProto documentation */ /* * Various ways to load MadelineProto */ if (\file_exists('vendor/autoload.php')) { include 'vendor/autoload.php'; } else { if (!\file_exists('madeline.php')) { \copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php'); } include 'madeline.php'; } /** * Event handler class. */ class EventHandler extends \danog\MadelineProto\EventHandler { public function onUpdateNewChannelMessage($update) { yield $this->onUpdateNewMessage($update); } public function onUpdateNewMessage($update) { if ($update['message']['_'] === 'messageEmpty' || $update['message']['out'] ?? false) { return; } $res = \json_encode($update, JSON_PRETTY_PRINT); try { yield $this->messages->sendMessage(['peer' => $update, 'message' => "$res", 'reply_to_msg_id' => isset($update['message']['id']) ? $update['message']['id'] : null, 'parse_mode' => 'HTML']); if (isset($update['message']['media']) && $update['message']['media']['_'] !== 'messageMediaGame') { yield $this->messages->sendMedia(['peer' => $update, 'message' => $update['message']['message'], 'media' => $update]); /* '_' => 'inputMediaUploadedDocument', 'file' => $update, 'attributes' => [ ['_' => 'documentAttributeFilename', 'file_name' => 'document.txt'] ] ],]);*/ //yield $this->downloadToDir($update, '/tmp'); } } catch (\danog\MadelineProto\RPCErrorException $e) { $this->logger((string) $e, \danog\MadelineProto\Logger::FATAL_ERROR); } catch (\danog\MadelineProto\Exception $e) { if (\stripos($e->getMessage(), 'invalid constructor given') === false) { $this->logger((string) $e, \danog\MadelineProto\Logger::FATAL_ERROR); } //$this->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]); } } } $settings = [ 'logger' => [ 'logger_level' => 5 ], 'serialization' => [ 'serialization_interval' => 30, ], ]; $MadelineProto = new \danog\MadelineProto\API('bot.madeline', $settings); $MadelineProto->async(true); $MadelineProto->loop(function () use ($MadelineProto) { yield $MadelineProto->start(); yield $MadelineProto->setEventHandler('\EventHandler'); }); $MadelineProto->loop();