2023-09-28 19:33:23 +02:00
|
|
|
<?php declare(strict_types=1);
|
2019-10-28 22:39:23 +01:00
|
|
|
/**
|
|
|
|
* Secret chat bot.
|
|
|
|
*
|
2020-02-17 14:13:46 +01:00
|
|
|
* Copyright 2016-2020 Daniil Gentili
|
2019-10-28 22:39:23 +01:00
|
|
|
* (https://daniil.it)
|
|
|
|
* This file is part of MadelineProto.
|
|
|
|
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU Affero General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License along with MadelineProto.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @author Daniil Gentili <daniil@daniil.it>
|
2023-01-04 12:43:01 +01:00
|
|
|
* @copyright 2016-2023 Daniil Gentili <daniil@daniil.it>
|
2019-10-28 22:39:23 +01:00
|
|
|
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
|
2019-10-31 15:07:35 +01:00
|
|
|
* @link https://docs.madelineproto.xyz MadelineProto documentation
|
2019-10-28 22:39:23 +01:00
|
|
|
*/
|
|
|
|
|
2023-09-28 19:33:23 +02:00
|
|
|
use danog\MadelineProto\EventHandler\Attributes\Handler;
|
2023-12-14 18:05:04 +01:00
|
|
|
use danog\MadelineProto\EventHandler\Message\PrivateMessage;
|
2023-09-28 19:33:23 +02:00
|
|
|
use danog\MadelineProto\EventHandler\Message\SecretMessage;
|
|
|
|
use danog\MadelineProto\EventHandler\SimpleFilter\Incoming;
|
2024-04-19 16:31:11 +02:00
|
|
|
use danog\MadelineProto\LocalFile;
|
2023-01-20 15:30:13 +01:00
|
|
|
use danog\MadelineProto\Logger;
|
2021-12-09 13:25:14 +01:00
|
|
|
use danog\MadelineProto\Settings;
|
2023-09-28 19:33:23 +02:00
|
|
|
use danog\MadelineProto\SimpleEventHandler;
|
2020-02-25 19:10:49 +01:00
|
|
|
|
2018-03-23 16:39:58 +01:00
|
|
|
/*
|
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
|
|
|
* Various ways to load MadelineProto
|
|
|
|
*/
|
2022-12-08 20:16:40 +01:00
|
|
|
if (file_exists(__DIR__.'/../vendor/autoload.php')) {
|
2019-10-28 22:39:23 +01:00
|
|
|
include 'vendor/autoload.php';
|
|
|
|
} else {
|
2022-12-08 20:16:40 +01:00
|
|
|
if (!file_exists('madeline.php')) {
|
|
|
|
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
|
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
|
|
|
}
|
|
|
|
include 'madeline.php';
|
2017-06-01 22:21:15 +02:00
|
|
|
}
|
|
|
|
|
2023-09-28 19:33:23 +02:00
|
|
|
class SecretHandler extends SimpleEventHandler
|
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
|
|
|
{
|
2023-01-20 13:49:44 +01:00
|
|
|
private array $sent = [];
|
2020-02-23 19:28:42 +01:00
|
|
|
/**
|
|
|
|
* @var int|string Username or ID of bot admin
|
|
|
|
*/
|
2023-11-11 16:55:29 +01:00
|
|
|
public const ADMIN = "danogentili"; // Change this
|
2020-02-23 19:28:42 +01:00
|
|
|
/**
|
|
|
|
* Get peer(s) where to report errors.
|
|
|
|
*
|
|
|
|
* @return int|string|array
|
|
|
|
*/
|
|
|
|
public function getReportPeers()
|
|
|
|
{
|
|
|
|
return [self::ADMIN];
|
|
|
|
}
|
2023-12-09 17:12:39 +01:00
|
|
|
public function onStart(): void
|
|
|
|
{
|
|
|
|
}
|
2020-02-23 19:28:42 +01:00
|
|
|
/**
|
|
|
|
* Handle updates from users.
|
|
|
|
*/
|
2023-12-14 18:05:04 +01:00
|
|
|
#[Handler]
|
|
|
|
public function handleNormalMessage(Incoming&PrivateMessage $update): void
|
2020-02-23 19:28:42 +01:00
|
|
|
{
|
2023-12-14 18:05:04 +01:00
|
|
|
if ($update->message === 'request') {
|
|
|
|
$this->requestSecretChat($update->senderId);
|
2020-02-23 19:28:42 +01:00
|
|
|
}
|
2023-12-14 18:05:04 +01:00
|
|
|
if ($update->message === 'ping') {
|
|
|
|
$update->reply('pong');
|
2020-10-18 18:41:53 +02:00
|
|
|
}
|
2020-02-23 19:28:42 +01:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Handle secret chat messages.
|
|
|
|
*/
|
2023-09-28 19:33:23 +02:00
|
|
|
#[Handler]
|
2023-12-14 18:05:04 +01:00
|
|
|
public function handle(Incoming&SecretMessage $update): void
|
2018-03-23 16:39:58 +01:00
|
|
|
{
|
2023-12-14 18:05:04 +01:00
|
|
|
if ($update->media) {
|
|
|
|
$path = $update->media->downloadToDir('/tmp');
|
|
|
|
$update->reply($path);
|
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
|
|
|
}
|
2023-12-14 18:05:04 +01:00
|
|
|
if (isset($this->sent[$update->chatId])) {
|
2020-10-18 15:41:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Photo, secret chat
|
2024-04-19 16:31:11 +02:00
|
|
|
$this->sendPhoto(
|
|
|
|
peer: $update->chatId,
|
|
|
|
file: new LocalFile('tests/faust.jpg'),
|
|
|
|
caption: 'This file was uploaded using MadelineProto',
|
|
|
|
);
|
2020-10-18 15:41:06 +02:00
|
|
|
|
2024-04-19 20:51:19 +02:00
|
|
|
// Photo as document, secret chat
|
|
|
|
$this->sendDocumentPhoto(
|
|
|
|
peer: $update->chatId,
|
|
|
|
file: new LocalFile('tests/faust.jpg'),
|
|
|
|
caption: 'This file was uploaded using MadelineProto',
|
|
|
|
);
|
|
|
|
|
2020-10-18 15:41:06 +02:00
|
|
|
// GIF, secret chat
|
2024-04-19 16:31:11 +02:00
|
|
|
$this->sendGif(
|
|
|
|
peer: $update->chatId,
|
|
|
|
file: new LocalFile('tests/pony.mp4'),
|
|
|
|
caption: 'This file was uploaded using MadelineProto',
|
|
|
|
);
|
2020-10-18 15:41:06 +02:00
|
|
|
|
|
|
|
// Sticker, secret chat
|
2024-04-19 16:31:11 +02:00
|
|
|
$this->sendSticker(
|
|
|
|
peer: $update->chatId,
|
|
|
|
file: new LocalFile('tests/lel.webp'),
|
|
|
|
mimeType: "image/webp"
|
|
|
|
);
|
|
|
|
|
|
|
|
// Document, secret chat
|
|
|
|
$this->sendDocument(
|
|
|
|
peer: $update->chatId,
|
|
|
|
file: new LocalFile('tests/60'),
|
|
|
|
fileName: 'fairy'
|
|
|
|
);
|
2020-10-18 15:41:06 +02:00
|
|
|
|
|
|
|
// Video, secret chat
|
2024-04-19 16:31:11 +02:00
|
|
|
$this->sendVideo(
|
|
|
|
peer: $update->chatId,
|
|
|
|
file: new LocalFile('tests/swing.mp4'),
|
|
|
|
);
|
2020-10-18 15:41:06 +02:00
|
|
|
|
|
|
|
// audio, secret chat
|
2024-04-19 16:31:11 +02:00
|
|
|
$this->sendAudio(
|
|
|
|
peer: $update->chatId,
|
|
|
|
file: new LocalFile('tests/mosconi.mp3'),
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->sendVoice(
|
|
|
|
peer: $update->chatId,
|
|
|
|
file: new LocalFile('tests/mosconi.mp3'),
|
|
|
|
);
|
2020-10-18 15:41:06 +02:00
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
while ($i < 10) {
|
2023-09-28 19:33:23 +02:00
|
|
|
$this->logger("SENDING MESSAGE $i TO ".$update->chatId);
|
2020-10-18 15:41:06 +02:00
|
|
|
// You can also use the sendEncrypted parameter for more options in secret chats
|
2023-09-28 19:33:23 +02:00
|
|
|
$this->sendMessage(peer: $update->chatId, message: (string) ($i++));
|
2020-10-18 15:41:06 +02:00
|
|
|
}
|
2023-12-14 18:05:04 +01:00
|
|
|
$this->sent[$update->chatId] = true;
|
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
|
|
|
}
|
2017-06-01 22:21:15 +02:00
|
|
|
}
|
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
|
|
|
|
2021-12-09 13:25:14 +01:00
|
|
|
$settings = new Settings;
|
2023-01-20 15:30:13 +01:00
|
|
|
$settings->getLogger()->setLevel(Logger::ULTRA_VERBOSE);
|
2018-03-30 18:07:54 +02:00
|
|
|
|
2021-12-09 13:25:14 +01:00
|
|
|
SecretHandler::startAndLoop('secret.madeline', $settings);
|