Guest User

сломал бот

a guest
Oct 31st, 2020
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. <?php
  2. if (!file_exists('madeline.php')) {
  3. copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
  4. }
  5. include 'madeline.php';
  6.  
  7. use danog\MadelineProto\EventHandler;
  8. use danog\MadelineProto\Tools;
  9. use danog\MadelineProto\API;
  10. use danog\MadelineProto\Logger;
  11. use danog\MadelineProto\RPCErrorException;
  12.  
  13. /**
  14. * Event handler class.
  15. */
  16. class MyEventHandler extends EventHandler
  17. {
  18. /**
  19. * @var int|string Username or ID of bot admin
  20. */
  21. const ADMIN = "@buntov2"; // Change this
  22. private $file;
  23. /**
  24. * Get peer(s) where to report errors
  25. *
  26. * @return int|string|array
  27. */
  28. public function getReportPeers()
  29. {
  30. return [self::ADMIN];
  31. }
  32. /**
  33. * Called on startup, can contain async calls for initialization of the bot
  34. *
  35. * @return \Generator
  36. */
  37. public function onStart()
  38. {
  39. $this->file = yield $this->messages->uploadMedia([
  40. 'peer' => self::ADMIN,
  41. 'media' => [
  42. '_' => 'inputMediaUploadedDocument',
  43. 'file' => 'https://greenteams.ru/my_bot/video/lector1.mp4',
  44. 'attributes' => [
  45. ['_' => 'documentAttributeVideo', 'round_message' => false, 'supports_streaming' => true]
  46. ]
  47. ],
  48. ]);
  49. $botAPI_file = yield $this->MTProtoToBotAPI($this->file);
  50. foreach (['audio', 'document', 'photo', 'sticker', 'video', 'voice', 'video_note'] as $type) {
  51. if (isset($botAPI_file[$type]) && is_array($botAPI_file[$type])) {
  52. $method = $type;
  53. }
  54. }
  55. $result['file_type'] = $method;
  56. if ($result['file_type'] == 'photo') {
  57. $result['file_size'] = $botAPI_file[$method][0]['file_size'];
  58. if (isset($botAPI_file[$method][0]['file_name'])) {
  59. $result['file_name'] = $botAPI_file[$method][0]['file_name'];
  60. $result['file_id'] = $botAPI_file[$method][0]['file_id'];
  61. }
  62. } else {
  63. if (isset($botAPI_file[$method]['file_name'])) {
  64. $result['file_name'] = $botAPI_file[$method]['file_name'];
  65. }
  66. if (isset($botAPI_file[$method]['file_size'])) {
  67. $result['file_size'] = $botAPI_file[$method]['file_size'];
  68. }
  69. if (isset($botAPI_file[$method]['mime_type'])) {
  70. $result['mime_type'] = $botAPI_file[$method]['mime_type'];
  71. }
  72. $result['file_id'] = $botAPI_file[$method]['file_id'];
  73. }
  74. if (!isset($result['mime_type'])) {
  75. $result['mime_type'] = 'application/octet-stream';
  76. }
  77. if (!isset($result['file_name'])) {
  78. $result['file_name'] = $result['file_id'].($method === 'sticker' ? '.webp' : '');
  79. }
  80. $this->report(print_r($result,true));
  81. }
  82. /**
  83. * Handle updates from supergroups and channels
  84. *
  85. * @param array $update Update
  86. *
  87. * @return void
  88. */
  89. public function onUpdateNewChannelMessage(array $update): \Generator
  90. {
  91. return $this->onUpdateNewMessage($update);
  92. }
  93. /**
  94. * Handle updates from users.
  95. *
  96. * @param array $update Update
  97. *
  98. * @return \Generator
  99. */
  100. public function onUpdateNewMessage(array $update): \Generator
  101. {
  102. if ($update['message']['_'] === 'messageEmpty' || $update['message']['out'] ?? false) {
  103. return;
  104. }
  105. yield $this->messages->sendMedia(['peer' => $update, 'media' => $this->file]);
  106. }
  107. }
  108.  
  109. $MadelineProto = new API('bot.madeline');
  110. $MadelineProto->startAndLoop(MyEventHandler::class);
Add Comment
Please, Sign In to add comment