Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!file_exists('madeline.php')) {
- copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
- }
- include 'madeline.php';
- use danog\MadelineProto\EventHandler;
- use danog\MadelineProto\Tools;
- use danog\MadelineProto\API;
- use danog\MadelineProto\Logger;
- use danog\MadelineProto\RPCErrorException;
- /**
- * Event handler class.
- */
- class MyEventHandler extends EventHandler
- {
- /**
- * @var int|string Username or ID of bot admin
- */
- const ADMIN = "@buntov2"; // Change this
- private $file;
- /**
- * Get peer(s) where to report errors
- *
- * @return int|string|array
- */
- public function getReportPeers()
- {
- return [self::ADMIN];
- }
- /**
- * Called on startup, can contain async calls for initialization of the bot
- *
- * @return \Generator
- */
- public function onStart()
- {
- $this->file = yield $this->messages->uploadMedia([
- 'peer' => self::ADMIN,
- 'media' => [
- '_' => 'inputMediaUploadedDocument',
- 'file' => 'https://greenteams.ru/my_bot/video/lector1.mp4',
- 'attributes' => [
- ['_' => 'documentAttributeVideo', 'round_message' => false, 'supports_streaming' => true]
- ]
- ],
- ]);
- $botAPI_file = yield $this->MTProtoToBotAPI($this->file);
- foreach (['audio', 'document', 'photo', 'sticker', 'video', 'voice', 'video_note'] as $type) {
- if (isset($botAPI_file[$type]) && is_array($botAPI_file[$type])) {
- $method = $type;
- }
- }
- $result['file_type'] = $method;
- if ($result['file_type'] == 'photo') {
- $result['file_size'] = $botAPI_file[$method][0]['file_size'];
- if (isset($botAPI_file[$method][0]['file_name'])) {
- $result['file_name'] = $botAPI_file[$method][0]['file_name'];
- $result['file_id'] = $botAPI_file[$method][0]['file_id'];
- }
- } else {
- if (isset($botAPI_file[$method]['file_name'])) {
- $result['file_name'] = $botAPI_file[$method]['file_name'];
- }
- if (isset($botAPI_file[$method]['file_size'])) {
- $result['file_size'] = $botAPI_file[$method]['file_size'];
- }
- if (isset($botAPI_file[$method]['mime_type'])) {
- $result['mime_type'] = $botAPI_file[$method]['mime_type'];
- }
- $result['file_id'] = $botAPI_file[$method]['file_id'];
- }
- if (!isset($result['mime_type'])) {
- $result['mime_type'] = 'application/octet-stream';
- }
- if (!isset($result['file_name'])) {
- $result['file_name'] = $result['file_id'].($method === 'sticker' ? '.webp' : '');
- }
- $this->report(print_r($result,true));
- }
- /**
- * Handle updates from supergroups and channels
- *
- * @param array $update Update
- *
- * @return void
- */
- public function onUpdateNewChannelMessage(array $update): \Generator
- {
- return $this->onUpdateNewMessage($update);
- }
- /**
- * Handle updates from users.
- *
- * @param array $update Update
- *
- * @return \Generator
- */
- public function onUpdateNewMessage(array $update): \Generator
- {
- if ($update['message']['_'] === 'messageEmpty' || $update['message']['out'] ?? false) {
- return;
- }
- yield $this->messages->sendMedia(['peer' => $update, 'media' => $this->file]);
- }
- }
- $MadelineProto = new API('bot.madeline');
- $MadelineProto->startAndLoop(MyEventHandler::class);
Add Comment
Please, Sign In to add comment