mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-30 05:58:58 +01:00
Cleanup
This commit is contained in:
parent
5c09a9a20f
commit
48f2551e6e
@ -81,268 +81,267 @@ $settings->getAppInfo()
|
||||
*/
|
||||
echo 'Loading MadelineProto...'.PHP_EOL;
|
||||
$MadelineProto = new API(__DIR__.'/../testing.madeline', $settings);
|
||||
$MadelineProto->async(true);
|
||||
$MadelineProto->loop(function () use ($MadelineProto) {
|
||||
yield $MadelineProto->start();
|
||||
yield $MadelineProto->fileGetContents('https://google.com');
|
||||
|
||||
try {
|
||||
yield $MadelineProto->getSelf();
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
if ($e->getMessage() === 'TOS action required, check the logs') {
|
||||
yield $MadelineProto->acceptTos();
|
||||
$MadelineProto->start();
|
||||
$MadelineProto->fileGetContents('https://google.com');
|
||||
|
||||
try {
|
||||
$MadelineProto->getSelf();
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
if ($e->getMessage() === 'TOS action required, check the logs') {
|
||||
$MadelineProto->acceptTos();
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump(count($MadelineProto->getPwrChat('@madelineproto')['participants']));
|
||||
|
||||
/*
|
||||
* Test logging
|
||||
*/
|
||||
$MadelineProto->logger('hey', Logger::ULTRA_VERBOSE);
|
||||
$MadelineProto->logger('hey', Logger::VERBOSE);
|
||||
$MadelineProto->logger('hey', Logger::NOTICE);
|
||||
$MadelineProto->logger('hey', Logger::WARNING);
|
||||
$MadelineProto->logger('hey', Logger::ERROR);
|
||||
$MadelineProto->logger('hey', Logger::FATAL_ERROR);
|
||||
|
||||
/**
|
||||
* A small example message to use for tests.
|
||||
*/
|
||||
$message = getenv('GITHUB_SHA') == '' ?
|
||||
'I iz works always (io laborare sembre) (yo lavorar siempre) (mi labori ĉiam) (я всегда работать) (Ik werkuh altijd) (Ngimbonga ngaso sonke isikhathi ukusebenza)' :
|
||||
('Github actions tests in progress: commit '.getenv('GITHUB_SHA').', job '.getenv('GITHUB_JOB').', PHP version: '.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION);
|
||||
|
||||
/*
|
||||
* Try making a phone call
|
||||
*/
|
||||
if (!getenv('GITHUB_SHA') && stripos(($MadelineProto->readline('Do you want to make a call? (y/n): ')) ?? '', 'y') !== false) {
|
||||
$controller = $MadelineProto->requestCall(getenv('TEST_SECRET_CHAT'))->play('input.raw')->then('input.raw')->playOnHold(['input.raw'])->setOutputFile('output.raw');
|
||||
while ($controller->getCallState() < VoIP::CALL_STATE_READY) {
|
||||
$MadelineProto->sleep(1);
|
||||
}
|
||||
$MadelineProto->logger($controller->configuration);
|
||||
while ($controller->getCallState() < VoIP::CALL_STATE_ENDED) {
|
||||
$MadelineProto->sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Try receiving a phone call
|
||||
*/
|
||||
if (!getenv('GITHUB_SHA') && stripos(($MadelineProto->readline('Do you want to handle incoming calls? (y/n): ')) ?? '', 'y') !== false) {
|
||||
$howmany = $MadelineProto->readline('How many calls would you like me to handle? ');
|
||||
$offset = 0;
|
||||
while ($howmany > 0) {
|
||||
$updates = $MadelineProto->getUpdates(['offset' => $offset, 'limit' => 50, 'timeout' => 0]); // Just like in the bot API, you can specify an offset, a limit and a timeout
|
||||
foreach ($updates as $update) {
|
||||
$MadelineProto->logger($update);
|
||||
$offset = $update['update_id'] + 1; // Just like in the bot API, the offset must be set to the last update_id
|
||||
switch ($update['update']['_']) {
|
||||
case 'updatePhoneCall':
|
||||
if (is_object($update['update']['phone_call']) && $update['update']['phone_call']->getCallState() === VoIP::CALL_STATE_INCOMING) {
|
||||
$update['update']['phone_call']->accept()->play('input.raw')->then('input.raw')->playOnHold(['input.raw'])->setOutputFile('output.raw');
|
||||
$howmany--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump(count($MadelineProto->getPwrChat('@madelineproto')['participants']));
|
||||
|
||||
/*
|
||||
* Test logging
|
||||
/*
|
||||
* Secret chat usage
|
||||
*/
|
||||
if (!getenv('GITHUB_SHA') && stripos(($MadelineProto->readline('Do you want to make the secret chat tests? (y/n): ')) ?? '', 'y') !== false) {
|
||||
if (!getenv('TEST_SECRET_CHAT')) {
|
||||
throw new Exception('No TEST_SECRET_CHAT environment variable was provided!');
|
||||
}
|
||||
/**
|
||||
* Request a secret chat.
|
||||
*/
|
||||
$MadelineProto->logger('hey', Logger::ULTRA_VERBOSE);
|
||||
$MadelineProto->logger('hey', Logger::VERBOSE);
|
||||
$MadelineProto->logger('hey', Logger::NOTICE);
|
||||
$MadelineProto->logger('hey', Logger::WARNING);
|
||||
$MadelineProto->logger('hey', Logger::ERROR);
|
||||
$MadelineProto->logger('hey', Logger::FATAL_ERROR);
|
||||
$secret_chat_id = $MadelineProto->requestSecretChat(getenv('TEST_SECRET_CHAT'));
|
||||
echo 'Waiting 10 seconds for '.getenv('TEST_SECRET_CHAT').' (secret chat id '.$secret_chat_id.') to accept the secret chat...'.PHP_EOL;
|
||||
|
||||
$MadelineProto->sleep(10);
|
||||
|
||||
/**
|
||||
* A small example message to use for tests.
|
||||
* Send a markdown-formatted text message with expiration after 10 seconds.
|
||||
*/
|
||||
$message = getenv('GITHUB_SHA') == '' ?
|
||||
'I iz works always (io laborare sembre) (yo lavorar siempre) (mi labori ĉiam) (я всегда работать) (Ik werkuh altijd) (Ngimbonga ngaso sonke isikhathi ukusebenza)' :
|
||||
('Github actions tests in progress: commit '.getenv('GITHUB_SHA').', job '.getenv('GITHUB_JOB').', PHP version: '.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION);
|
||||
$sentMessage = $MadelineProto->messages->sendEncrypted([
|
||||
'peer' => $secret_chat_id,
|
||||
'message' => [
|
||||
'_' => 'decryptedMessage',
|
||||
'media' => ['_' => 'decryptedMessageMediaEmpty'], // No media
|
||||
'ttl' => 10, // This message self-destructs 10 seconds after reception
|
||||
'message' => '```'.$message.'```', // Code Markdown
|
||||
'parse_mode' => 'Markdown',
|
||||
],
|
||||
]);
|
||||
$MadelineProto->logger($sentMessage, Logger::NOTICE);
|
||||
|
||||
/*
|
||||
* Try making a phone call
|
||||
/**
|
||||
* Send secret media.
|
||||
*/
|
||||
if (!getenv('GITHUB_SHA') && stripos((yield $MadelineProto->readline('Do you want to make a call? (y/n): ')) ?? '', 'y') !== false) {
|
||||
$controller = yield $MadelineProto->requestCall(getenv('TEST_SECRET_CHAT'))->play('input.raw')->then('input.raw')->playOnHold(['input.raw'])->setOutputFile('output.raw');
|
||||
while ($controller->getCallState() < VoIP::CALL_STATE_READY) {
|
||||
yield $MadelineProto->sleep(1);
|
||||
}
|
||||
$MadelineProto->logger($controller->configuration);
|
||||
while ($controller->getCallState() < VoIP::CALL_STATE_ENDED) {
|
||||
yield $MadelineProto->sleep(1);
|
||||
}
|
||||
}
|
||||
$secret_media = [];
|
||||
|
||||
/*
|
||||
* Try receiving a phone call
|
||||
*/
|
||||
if (!getenv('GITHUB_SHA') && stripos((yield $MadelineProto->readline('Do you want to handle incoming calls? (y/n): ')) ?? '', 'y') !== false) {
|
||||
$howmany = yield $MadelineProto->readline('How many calls would you like me to handle? ');
|
||||
$offset = 0;
|
||||
while ($howmany > 0) {
|
||||
$updates = yield $MadelineProto->getUpdates(['offset' => $offset, 'limit' => 50, 'timeout' => 0]); // Just like in the bot API, you can specify an offset, a limit and a timeout
|
||||
foreach ($updates as $update) {
|
||||
$MadelineProto->logger($update);
|
||||
$offset = $update['update_id'] + 1; // Just like in the bot API, the offset must be set to the last update_id
|
||||
switch ($update['update']['_']) {
|
||||
case 'updatePhoneCall':
|
||||
if (is_object($update['update']['phone_call']) && $update['update']['phone_call']->getCallState() === VoIP::CALL_STATE_INCOMING) {
|
||||
$update['update']['phone_call']->accept()->play('input.raw')->then('input.raw')->playOnHold(['input.raw'])->setOutputFile('output.raw');
|
||||
$howmany--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Secret chat usage
|
||||
*/
|
||||
if (!getenv('GITHUB_SHA') && stripos((yield $MadelineProto->readline('Do you want to make the secret chat tests? (y/n): ')) ?? '', 'y') !== false) {
|
||||
if (!getenv('TEST_SECRET_CHAT')) {
|
||||
throw new Exception('No TEST_SECRET_CHAT environment variable was provided!');
|
||||
}
|
||||
/**
|
||||
* Request a secret chat.
|
||||
*/
|
||||
$secret_chat_id = yield $MadelineProto->requestSecretChat(getenv('TEST_SECRET_CHAT'));
|
||||
echo 'Waiting 10 seconds for '.getenv('TEST_SECRET_CHAT').' (secret chat id '.$secret_chat_id.') to accept the secret chat...'.PHP_EOL;
|
||||
|
||||
yield $MadelineProto->sleep(10);
|
||||
|
||||
/**
|
||||
* Send a markdown-formatted text message with expiration after 10 seconds.
|
||||
*/
|
||||
$sentMessage = yield $MadelineProto->messages->sendEncrypted([
|
||||
'peer' => $secret_chat_id,
|
||||
'message' => [
|
||||
'_' => 'decryptedMessage',
|
||||
'media' => ['_' => 'decryptedMessageMediaEmpty'], // No media
|
||||
'ttl' => 10, // This message self-destructs 10 seconds after reception
|
||||
'message' => '```'.$message.'```', // Code Markdown
|
||||
'parse_mode' => 'Markdown',
|
||||
],
|
||||
]);
|
||||
$MadelineProto->logger($sentMessage, Logger::NOTICE);
|
||||
|
||||
/**
|
||||
* Send secret media.
|
||||
*/
|
||||
$secret_media = [];
|
||||
|
||||
// Photo uploaded as document, secret chat
|
||||
$secret_media['document_photo'] = [
|
||||
'peer' => $secret_chat_id,
|
||||
'file' => __DIR__.'/faust.jpg', // The file to send
|
||||
'message' => [
|
||||
'_' => 'decryptedMessage',
|
||||
'ttl' => 0, // This message does not self-destruct
|
||||
'message' => '', // No text message, only media
|
||||
'media' => [
|
||||
'_' => 'decryptedMessageMediaDocument',
|
||||
'thumb' => file_get_contents(__DIR__.'/faust.preview.jpg'), // The thumbnail must be generated manually, it must be in jpg format, 90x90
|
||||
'thumb_w' => 90,
|
||||
'thumb_h' => 90,
|
||||
'mime_type' => mime_content_type(__DIR__.'/faust.jpg'), // The file's mime type
|
||||
'caption' => 'This file was uploaded using @MadelineProto', // The caption
|
||||
'file_name' => 'faust.jpg', // The file's name
|
||||
'size' => filesize(__DIR__.'/faust.jpg'), // The file's size
|
||||
'attributes' => [
|
||||
['_' => 'documentAttributeImageSize', 'w' => 1280, 'h' => 914], // Image's resolution
|
||||
],
|
||||
// Photo uploaded as document, secret chat
|
||||
$secret_media['document_photo'] = [
|
||||
'peer' => $secret_chat_id,
|
||||
'file' => __DIR__.'/faust.jpg', // The file to send
|
||||
'message' => [
|
||||
'_' => 'decryptedMessage',
|
||||
'ttl' => 0, // This message does not self-destruct
|
||||
'message' => '', // No text message, only media
|
||||
'media' => [
|
||||
'_' => 'decryptedMessageMediaDocument',
|
||||
'thumb' => file_get_contents(__DIR__.'/faust.preview.jpg'), // The thumbnail must be generated manually, it must be in jpg format, 90x90
|
||||
'thumb_w' => 90,
|
||||
'thumb_h' => 90,
|
||||
'mime_type' => mime_content_type(__DIR__.'/faust.jpg'), // The file's mime type
|
||||
'caption' => 'This file was uploaded using @MadelineProto', // The caption
|
||||
'file_name' => 'faust.jpg', // The file's name
|
||||
'size' => filesize(__DIR__.'/faust.jpg'), // The file's size
|
||||
'attributes' => [
|
||||
['_' => 'documentAttributeImageSize', 'w' => 1280, 'h' => 914], // Image's resolution
|
||||
],
|
||||
],
|
||||
];
|
||||
],
|
||||
];
|
||||
|
||||
// Photo, secret chat
|
||||
$secret_media['photo'] = [
|
||||
'peer' => $secret_chat_id,
|
||||
'file' => __DIR__.'/faust.jpg',
|
||||
'message' => [
|
||||
'_' => 'decryptedMessage',
|
||||
'ttl' => 0,
|
||||
'message' => '',
|
||||
'media' => [
|
||||
'_' => 'decryptedMessageMediaPhoto',
|
||||
'thumb' => file_get_contents(__DIR__.'/faust.preview.jpg'),
|
||||
'thumb_w' => 90,
|
||||
'thumb_h' => 90,
|
||||
'caption' => 'This file was uploaded using @MadelineProto',
|
||||
'size' => filesize(__DIR__.'/faust.jpg'),
|
||||
'w' => 1280,
|
||||
'h' => 914,
|
||||
],
|
||||
// Photo, secret chat
|
||||
$secret_media['photo'] = [
|
||||
'peer' => $secret_chat_id,
|
||||
'file' => __DIR__.'/faust.jpg',
|
||||
'message' => [
|
||||
'_' => 'decryptedMessage',
|
||||
'ttl' => 0,
|
||||
'message' => '',
|
||||
'media' => [
|
||||
'_' => 'decryptedMessageMediaPhoto',
|
||||
'thumb' => file_get_contents(__DIR__.'/faust.preview.jpg'),
|
||||
'thumb_w' => 90,
|
||||
'thumb_h' => 90,
|
||||
'caption' => 'This file was uploaded using @MadelineProto',
|
||||
'size' => filesize(__DIR__.'/faust.jpg'),
|
||||
'w' => 1280,
|
||||
'h' => 914,
|
||||
],
|
||||
];
|
||||
],
|
||||
];
|
||||
|
||||
// GIF, secret chat
|
||||
$secret_media['gif'] = ['peer' => $secret_chat_id, 'file' => __DIR__.'/pony.mp4', 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents(__DIR__.'/pony.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type(__DIR__.'/pony.mp4'), 'caption' => 'test', 'file_name' => 'pony.mp4', 'size' => filesize(__DIR__.'/faust.jpg'), 'attributes' => [['_' => 'documentAttributeAnimated']]]]];
|
||||
// GIF, secret chat
|
||||
$secret_media['gif'] = ['peer' => $secret_chat_id, 'file' => __DIR__.'/pony.mp4', 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents(__DIR__.'/pony.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type(__DIR__.'/pony.mp4'), 'caption' => 'test', 'file_name' => 'pony.mp4', 'size' => filesize(__DIR__.'/faust.jpg'), 'attributes' => [['_' => 'documentAttributeAnimated']]]]];
|
||||
|
||||
// Sticker, secret chat
|
||||
$secret_media['sticker'] = ['peer' => $secret_chat_id, 'file' => __DIR__.'/lel.webp', 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents(__DIR__.'/lel.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type(__DIR__.'/lel.webp'), 'caption' => 'test', 'file_name' => 'lel.webp', 'size' => filesize(__DIR__.'/lel.webp'), 'attributes' => [['_' => 'documentAttributeSticker', 'alt' => 'LEL', 'stickerset' => ['_' => 'inputStickerSetEmpty']]]]]];
|
||||
// Sticker, secret chat
|
||||
$secret_media['sticker'] = ['peer' => $secret_chat_id, 'file' => __DIR__.'/lel.webp', 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents(__DIR__.'/lel.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type(__DIR__.'/lel.webp'), 'caption' => 'test', 'file_name' => 'lel.webp', 'size' => filesize(__DIR__.'/lel.webp'), 'attributes' => [['_' => 'documentAttributeSticker', 'alt' => 'LEL', 'stickerset' => ['_' => 'inputStickerSetEmpty']]]]]];
|
||||
|
||||
// Document, secret chat
|
||||
$secret_media['document'] = ['peer' => $secret_chat_id, 'file' => __DIR__.'/60', 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents(__DIR__.'/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => 'magic/magic', 'caption' => 'test', 'file_name' => 'magic.magic', 'size' => filesize(__DIR__.'/60'), 'attributes' => [['_' => 'documentAttributeFilename', 'file_name' => 'fairy']]]]];
|
||||
// Document, secret chat
|
||||
$secret_media['document'] = ['peer' => $secret_chat_id, 'file' => __DIR__.'/60', 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents(__DIR__.'/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => 'magic/magic', 'caption' => 'test', 'file_name' => 'magic.magic', 'size' => filesize(__DIR__.'/60'), 'attributes' => [['_' => 'documentAttributeFilename', 'file_name' => 'fairy']]]]];
|
||||
|
||||
// Video, secret chat
|
||||
$secret_media['video'] = ['peer' => $secret_chat_id, 'file' => __DIR__.'/swing.mp4', 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents(__DIR__.'/swing.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type(__DIR__.'/swing.mp4'), 'caption' => 'test', 'file_name' => 'swing.mp4', 'size' => filesize(__DIR__.'/swing.mp4'), 'attributes' => [['_' => 'documentAttributeVideo']]]]];
|
||||
// Video, secret chat
|
||||
$secret_media['video'] = ['peer' => $secret_chat_id, 'file' => __DIR__.'/swing.mp4', 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents(__DIR__.'/swing.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type(__DIR__.'/swing.mp4'), 'caption' => 'test', 'file_name' => 'swing.mp4', 'size' => filesize(__DIR__.'/swing.mp4'), 'attributes' => [['_' => 'documentAttributeVideo']]]]];
|
||||
|
||||
// audio, secret chat
|
||||
$secret_media['audio'] = ['peer' => $secret_chat_id, 'file' => __DIR__.'/mosconi.mp3', 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents(__DIR__.'/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type(__DIR__.'/mosconi.mp3'), 'caption' => 'test', 'file_name' => 'mosconi.mp3', 'size' => filesize(__DIR__.'/mosconi.mp3'), 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => false, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]]]];
|
||||
$secret_media['voice'] = ['peer' => $secret_chat_id, 'file' => __DIR__.'/mosconi.mp3', 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents(__DIR__.'/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type(__DIR__.'/mosconi.mp3'), 'caption' => 'test', 'file_name' => 'mosconi.mp3', 'size' => filesize(__DIR__.'/mosconi.mp3'), 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => true, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]]]];
|
||||
// audio, secret chat
|
||||
$secret_media['audio'] = ['peer' => $secret_chat_id, 'file' => __DIR__.'/mosconi.mp3', 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents(__DIR__.'/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type(__DIR__.'/mosconi.mp3'), 'caption' => 'test', 'file_name' => 'mosconi.mp3', 'size' => filesize(__DIR__.'/mosconi.mp3'), 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => false, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]]]];
|
||||
$secret_media['voice'] = ['peer' => $secret_chat_id, 'file' => __DIR__.'/mosconi.mp3', 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents(__DIR__.'/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type(__DIR__.'/mosconi.mp3'), 'caption' => 'test', 'file_name' => 'mosconi.mp3', 'size' => filesize(__DIR__.'/mosconi.mp3'), 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => true, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]]]];
|
||||
|
||||
foreach ($secret_media as $type => $smessage) {
|
||||
$MadelineProto->logger("Encrypting and uploading $type...");
|
||||
$type = yield $MadelineProto->messages->sendEncryptedFile($smessage);
|
||||
foreach ($secret_media as $type => $smessage) {
|
||||
$MadelineProto->logger("Encrypting and uploading $type...");
|
||||
$type = $MadelineProto->messages->sendEncryptedFile($smessage);
|
||||
}
|
||||
}
|
||||
|
||||
if (!getenv('TEST_USERNAME')) {
|
||||
throw new Exception('No TEST_USERNAME environment variable was provided!');
|
||||
}
|
||||
/*$MadelineProto->refreshPeerCache(\getenv('TEST_USERNAME'));
|
||||
$MadelineProto->refreshFullPeerCache(\getenv('TEST_USERNAME'));*/
|
||||
$mention = $MadelineProto->getInfo(getenv('TEST_USERNAME')); // Returns an array with all of the constructors that can be extracted from a username or an id
|
||||
$mention = $mention['user_id']; // Selects only the numeric user id
|
||||
$media = [];
|
||||
|
||||
// Image
|
||||
$media['photo'] = ['_' => 'inputMediaUploadedPhoto', 'file' => __DIR__.'/faust.jpg'];
|
||||
|
||||
// Image by URL
|
||||
$media['photo'] = ['_' => 'inputMediaPhotoExternal', 'url' => 'https://github.com/danog/MadelineProto/raw/v8/tests/faust.jpg'];
|
||||
|
||||
// Sticker
|
||||
$media['sticker'] = ['_' => 'inputMediaUploadedDocument', 'file' => __DIR__.'/lel.webp', 'attributes' => [['_' => 'documentAttributeSticker', 'alt' => 'LEL']]];
|
||||
|
||||
// Video
|
||||
$media['video'] = ['_' => 'inputMediaUploadedDocument', 'file' => __DIR__.'/swing.mp4', 'attributes' => [['_' => 'documentAttributeVideo']]];
|
||||
|
||||
// audio
|
||||
$media['audio'] = ['_' => 'inputMediaUploadedDocument', 'file' => __DIR__.'/mosconi.mp3', 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => false, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]];
|
||||
|
||||
// voice
|
||||
$media['voice'] = ['_' => 'inputMediaUploadedDocument', 'file' => __DIR__.'/mosconi.mp3', 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => true, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]];
|
||||
|
||||
// Document
|
||||
$media['document'] = ['_' => 'inputMediaUploadedDocument', 'file' => __DIR__.'/60', 'mime_type' => 'magic/magic', 'attributes' => [['_' => 'documentAttributeFilename', 'file_name' => 'magic.magic']]];
|
||||
|
||||
// Document by URL
|
||||
$media['document'] = ['_' => 'inputMediaDocumentExternal', 'url' => 'https://github.com/danog/MadelineProto/raw/v8/tests/60'];
|
||||
|
||||
$message = 'yay '.PHP_VERSION_ID;
|
||||
$mention = $MadelineProto->getInfo(getenv('TEST_USERNAME')); // Returns an array with all of the constructors that can be extracted from a username or an id
|
||||
$mention = $mention['user_id']; // Selects only the numeric user id
|
||||
|
||||
$peers = json_decode(getenv('TEST_DESTINATION_GROUPS'), true);
|
||||
if (!$peers) {
|
||||
die("No TEST_DESTINATION_GROUPS array was provided!");
|
||||
}
|
||||
foreach ($peers as $peer) {
|
||||
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message, 'entities' => [['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => mb_strlen($message), 'user_id' => $mention]]]);
|
||||
$MadelineProto->logger($sentMessage, Logger::NOTICE);
|
||||
|
||||
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => str_repeat('a', 4096*4)]);
|
||||
$MadelineProto->logger($sentMessage, \danog\MadelineProto\Logger::NOTICE);
|
||||
|
||||
foreach ($media as $type => $inputMedia) {
|
||||
if ($type !== 'sticker' && $type !== 'voice') {
|
||||
$MadelineProto->logger("Sending multi $type");
|
||||
$MadelineProto->messages->sendMultiMedia(['peer' => $peer, 'multi_media' => [
|
||||
['_' => 'inputSingleMedia', 'media' => $inputMedia, 'message' => '['.$message.'](mention:'.$mention.')', 'parse_mode' => 'markdown'],
|
||||
['_' => 'inputSingleMedia', 'media' => $inputMedia, 'message' => '['.$message.'](mention:'.$mention.')', 'parse_mode' => 'markdown'],
|
||||
]]);
|
||||
}
|
||||
$fileOrig = isset($inputMedia['file'])
|
||||
? read($inputMedia['file'])
|
||||
: $MadelineProto->fileGetContents($inputMedia['url']);
|
||||
$MadelineProto->logger("Sending $type");
|
||||
$dl = $MadelineProto->extractMessage($MadelineProto->messages->sendMedia(['peer' => $peer, 'media' => $inputMedia, 'message' => '['.$message.'](mention:'.$mention.')', 'parse_mode' => 'markdown']));
|
||||
|
||||
$MadelineProto->logger("Downloading $type");
|
||||
$file = $MadelineProto->downloadToDir($dl, '/tmp');
|
||||
if ($type !== 'photo') {
|
||||
Assert::eq(read($file), $fileOrig, "Not equal!");
|
||||
}
|
||||
|
||||
$MadelineProto->logger("Uploading $type");
|
||||
$media = $MadelineProto->messages->uploadMedia(['peer' => '@me', 'media' => $inputMedia]);
|
||||
|
||||
$MadelineProto->logger("Downloading $type");
|
||||
$file = $MadelineProto->downloadToDir($media, '/tmp');
|
||||
if ($type !== 'photo') {
|
||||
Assert::eq(read($file), $fileOrig, "Not equal!");
|
||||
}
|
||||
|
||||
$MadelineProto->logger("Re-sending $type");
|
||||
$inputMedia['file'] = $media;
|
||||
|
||||
$dl = $MadelineProto->messages->uploadMedia(['peer' => '@me', 'media' => $inputMedia]);
|
||||
|
||||
$MadelineProto->logger("Re-downloading $type");
|
||||
$file = $MadelineProto->downloadToDir($dl, '/tmp');
|
||||
if ($type !== 'photo') {
|
||||
Assert::eq(read($file), $fileOrig, "Not equal!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!getenv('TEST_USERNAME')) {
|
||||
throw new Exception('No TEST_USERNAME environment variable was provided!');
|
||||
}
|
||||
/*yield $MadelineProto->refreshPeerCache(\getenv('TEST_USERNAME'));
|
||||
yield $MadelineProto->refreshFullPeerCache(\getenv('TEST_USERNAME'));*/
|
||||
$mention = yield $MadelineProto->getInfo(getenv('TEST_USERNAME')); // Returns an array with all of the constructors that can be extracted from a username or an id
|
||||
$mention = $mention['user_id']; // Selects only the numeric user id
|
||||
$media = [];
|
||||
|
||||
// Image
|
||||
$media['photo'] = ['_' => 'inputMediaUploadedPhoto', 'file' => __DIR__.'/faust.jpg'];
|
||||
|
||||
// Image by URL
|
||||
$media['photo'] = ['_' => 'inputMediaPhotoExternal', 'url' => 'https://github.com/danog/MadelineProto/raw/v8/tests/faust.jpg'];
|
||||
|
||||
// Sticker
|
||||
$media['sticker'] = ['_' => 'inputMediaUploadedDocument', 'file' => __DIR__.'/lel.webp', 'attributes' => [['_' => 'documentAttributeSticker', 'alt' => 'LEL']]];
|
||||
|
||||
// Video
|
||||
$media['video'] = ['_' => 'inputMediaUploadedDocument', 'file' => __DIR__.'/swing.mp4', 'attributes' => [['_' => 'documentAttributeVideo']]];
|
||||
|
||||
// audio
|
||||
$media['audio'] = ['_' => 'inputMediaUploadedDocument', 'file' => __DIR__.'/mosconi.mp3', 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => false, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]];
|
||||
|
||||
// voice
|
||||
$media['voice'] = ['_' => 'inputMediaUploadedDocument', 'file' => __DIR__.'/mosconi.mp3', 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => true, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]];
|
||||
|
||||
// Document
|
||||
$media['document'] = ['_' => 'inputMediaUploadedDocument', 'file' => __DIR__.'/60', 'mime_type' => 'magic/magic', 'attributes' => [['_' => 'documentAttributeFilename', 'file_name' => 'magic.magic']]];
|
||||
|
||||
// Document by URL
|
||||
$media['document'] = ['_' => 'inputMediaDocumentExternal', 'url' => 'https://github.com/danog/MadelineProto/raw/v8/tests/60'];
|
||||
|
||||
$message = 'yay '.PHP_VERSION_ID;
|
||||
$mention = yield $MadelineProto->getInfo(getenv('TEST_USERNAME')); // Returns an array with all of the constructors that can be extracted from a username or an id
|
||||
$mention = $mention['user_id']; // Selects only the numeric user id
|
||||
|
||||
$peers = json_decode(getenv('TEST_DESTINATION_GROUPS'), true);
|
||||
if (!$peers) {
|
||||
die("No TEST_DESTINATION_GROUPS array was provided!");
|
||||
}
|
||||
foreach ($peers as $peer) {
|
||||
$sentMessage = yield $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message, 'entities' => [['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => mb_strlen($message), 'user_id' => $mention]]]);
|
||||
$MadelineProto->logger($sentMessage, Logger::NOTICE);
|
||||
|
||||
$sentMessage = yield $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => str_repeat('a', 4096*4)]);
|
||||
$MadelineProto->logger($sentMessage, \danog\MadelineProto\Logger::NOTICE);
|
||||
|
||||
foreach ($media as $type => $inputMedia) {
|
||||
if ($type !== 'sticker' && $type !== 'voice') {
|
||||
$MadelineProto->logger("Sending multi $type");
|
||||
yield $MadelineProto->messages->sendMultiMedia(['peer' => $peer, 'multi_media' => [
|
||||
['_' => 'inputSingleMedia', 'media' => $inputMedia, 'message' => '['.$message.'](mention:'.$mention.')', 'parse_mode' => 'markdown'],
|
||||
['_' => 'inputSingleMedia', 'media' => $inputMedia, 'message' => '['.$message.'](mention:'.$mention.')', 'parse_mode' => 'markdown'],
|
||||
]]);
|
||||
}
|
||||
$fileOrig = isset($inputMedia['file'])
|
||||
? read($inputMedia['file'])
|
||||
: $MadelineProto->fileGetContents($inputMedia['url']);
|
||||
$MadelineProto->logger("Sending $type");
|
||||
$dl = $MadelineProto->extractMessage(yield $MadelineProto->messages->sendMedia(['peer' => $peer, 'media' => $inputMedia, 'message' => '['.$message.'](mention:'.$mention.')', 'parse_mode' => 'markdown']));
|
||||
|
||||
$MadelineProto->logger("Downloading $type");
|
||||
$file = yield $MadelineProto->downloadToDir($dl, '/tmp');
|
||||
if ($type !== 'photo') {
|
||||
Assert::eq(read($file), $fileOrig, "Not equal!");
|
||||
}
|
||||
|
||||
$MadelineProto->logger("Uploading $type");
|
||||
$media = yield $MadelineProto->messages->uploadMedia(['peer' => '@me', 'media' => $inputMedia]);
|
||||
|
||||
$MadelineProto->logger("Downloading $type");
|
||||
$file = yield $MadelineProto->downloadToDir($media, '/tmp');
|
||||
if ($type !== 'photo') {
|
||||
Assert::eq(read($file), $fileOrig, "Not equal!");
|
||||
}
|
||||
|
||||
$MadelineProto->logger("Re-sending $type");
|
||||
$inputMedia['file'] = $media;
|
||||
|
||||
$dl = yield $MadelineProto->messages->uploadMedia(['peer' => '@me', 'media' => $inputMedia]);
|
||||
|
||||
$MadelineProto->logger("Re-downloading $type");
|
||||
$file = yield $MadelineProto->downloadToDir($dl, '/tmp');
|
||||
if ($type !== 'photo') {
|
||||
Assert::eq(read($file), $fileOrig, "Not equal!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (json_decode(getenv('TEST_DESTINATION_GROUPS'), true) as $peer) {
|
||||
$sentMessage = yield $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message, 'entities' => [['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => mb_strlen($message), 'user_id' => $mention]]]);
|
||||
$MadelineProto->logger($sentMessage, Logger::NOTICE);
|
||||
}
|
||||
foreach (json_decode(getenv('TEST_DESTINATION_GROUPS'), true) as $peer) {
|
||||
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message, 'entities' => [['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => mb_strlen($message), 'user_id' => $mention]]]);
|
||||
$MadelineProto->logger($sentMessage, Logger::NOTICE);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user