#!/usr/bin/env php . * * @author Daniil Gentili * @copyright 2016-2023 Daniil Gentili * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 * @link https://docs.madelineproto.xyz MadelineProto documentation */ use danog\MadelineProto\API; use danog\MadelineProto\EventHandler; use danog\MadelineProto\Logger; /* * 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 MyEventHandler extends EventHandler { /** * @var int|string Username or ID of bot admin */ const ADMIN = "danogentili"; // Change this /** * Get peer(s) where to report errors. * * @return int|string|array */ public function getReportPeers() { return [self::ADMIN]; } /** * Handle updates from supergroups and channels. * * @param array $update Update */ public function onUpdateNewChannelMessage(array $update): Generator { return $this->onUpdateNewMessage($update); } /** * Handle updates from users. * * @param array $update Update */ public function onUpdateNewMessage(array $update): Generator { if ($update['message']['_'] === 'messageEmpty' || $update['message']['out'] ?? false) { return; } $res = json_encode($update, JSON_PRETTY_PRINT); yield $this->messages->sendMessage(['peer' => $update, 'message' => "$res", 'reply_to_msg_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]); } } } $MadelineProtos = []; foreach ([ 'bot.madeline' => 'Bot Login', 'user.madeline' => 'Userbot login', 'user2.madeline' => 'Userbot login (2)', ] as $session => $message) { Logger::log($message, Logger::WARNING); $MadelineProtos []= new API($session); } API::startAndLoopMulti($MadelineProtos, MyEventHandler::class);