Untitled

mail@pastecode.io avatar
unknown
php
a year ago
1.4 kB
15
Indexable
Never
<?php
if(preg_match('/[\/\!]?dl (.+)/ius', $msgOrig, $m)){
    $sent = $this->messages->sendMessage(
        peer:$peer,
        message:'Preparing...'
    );
    $id   = $this->extractMessageId($sent);
    $path = parse_url($m[1], PHP_URL_PATH);
    $fileName = basename($path);
    $atr1 = ['_' => 'documentAttributeVideo',
             'round_message' => false,
             'supports_streaming' => true];
    $atr2 = ['_' => 'documentAttributeFilename', 
             'file_name' => $fileName];
    $url  = new \danog\MadelineProto\FileCallback($m[2],
        function($progress, $speed, $time) use ($peer, $id){
            static $prev = 0;
            $now = time();
            if($now - $prev < 10 && $progress < 100){
                return;
            }
            $prev = $now;
            try{
                $this->messages->editMessage(
                    peer: $peer,
                    id: $id,
                    message: "Upload progress: $progress%\nSpeed: $speed mbps\nTime elapsed since start: $time"
                 );
            } catch (Throwable $e) {}
        }
    );
    $this->messages->sendMedia(
        peer: $peer,
        message: 'By @MadelineProto !',
        media: [
            '_' => 'inputMediaUploadedDocument',
            'file' => $url,
            'attributes' => [$atr1,$atr2]
        ]
        
     );
}