Autogenerate thumbnail

This commit is contained in:
Daniil Gentili 2024-04-24 17:04:49 +02:00
parent 37e68d81ce
commit 716b969365
2 changed files with 19 additions and 17 deletions

29
bot.php
View File

@ -57,6 +57,11 @@ if (class_exists(API::class)) {
require_once 'madeline.php'; require_once 'madeline.php';
} }
if (PHP_SAPI !== 'cli') {
echo("Please run this bot via CLI in a screen session or docker image: https://docs.madelineproto.xyz/docs/DOCKER.html!".PHP_EOL);
die(1);
}
$process = Process::start([ $process = Process::start([
'yt-dlp', 'yt-dlp',
'--version' '--version'
@ -204,10 +209,14 @@ class MyEventHandler extends SimpleEventHandler
{ {
try { try {
$sent = $message->reply('Preparing...'); $sent = $message->reply('Preparing...');
$file = new FileCallback( $prev = 0;
$file, $this->sendVideo(
static function ($progress, $speed, $time) use ($sent): void { peer : $message->chatId,
static $prev = 0; replyToMsgId: $message->id,
fileName: $name,
file: $file,
caption: 'Powered by @MadelineProto!',
callback: static function ($progress, $speed, $time) use ($sent, &$prev): void {
$now = time(); $now = time();
if ($now - $prev < 10 && $progress < 100) { if ($now - $prev < 10 && $progress < 100) {
return; return;
@ -220,18 +229,6 @@ class MyEventHandler extends SimpleEventHandler
} }
}, },
); );
$this->messages->sendMedia(
peer : $message->chatId,
reply_to_msg_id: $message->id,
media : [
'_' => 'inputMediaUploadedDocument',
'file' => $file,
'attributes' => [
['_' => 'documentAttributeFilename', 'file_name' => $name],
],
],
message : 'Powered by @MadelineProto!'
);
$sent->delete(); $sent->delete();
} catch (Throwable $e) { } catch (Throwable $e) {
if (!str_contains($e->getMessage(), 'Could not connect to URI') && !($e instanceof UriException) && !str_contains($e->getMessage(), 'URI')) { if (!str_contains($e->getMessage(), 'Could not connect to URI') && !($e instanceof UriException) && !str_contains($e->getMessage(), 'URI')) {

View File

@ -12,5 +12,10 @@
"name": "Daniil Gentili", "name": "Daniil Gentili",
"email": "daniil@daniil.it" "email": "daniil@daniil.it"
} }
] ],
"config": {
"allow-plugins": {
"symfony/thanks": true
}
}
} }