Skip to content

Instantly share code, notes, and snippets.

@ShiSHcat
Created April 16, 2020 17:06
Show Gist options
  • Save ShiSHcat/28854392e93b89db771fd810a8257dfe to your computer and use it in GitHub Desktop.
Save ShiSHcat/28854392e93b89db771fd810a8257dfe to your computer and use it in GitHub Desktop.
<?php
use Amp\Promise;
use Amp\Success;
use function Amp\call;
function generate($message){
$callable = function($message) {
if(($message["media"]??false)) {
foreach($message["media"]as $k=>$v) {
if(is_array($v)) {
$k2e = $v;
} else {
$type1 = $v;
}
}
foreach($k2e["sizes"]??[] as $k=>$v){
if(isset($v["bytes"])) {
$k2e["sizes"][$k]["bytes"] = base64_encode((string)$k2e["sizes"][$k]["bytes"]);
}
}
$id = bin2hex(random_bytes(5));
$fs = [
"dwid"=> $id,
"msgid"=>$message["id"],
"id"=>$k2e["id"],
"id_chat"=>json_encode($message["to_id"]),
"access_hash"=>$k2e["access_hash"],
"bytes"=>base64_encode((string)$k2e["file_reference"]),
"date_"=>$k2e["date"],
"type1"=>$type1,
"type2"=>$k2e["_"],
"mime"=>$k2e["mime_type"]??"",
"size"=>$k2e["size"]??0,
"dc"=>$k2e["dc_id"],
"attributes"=>json_encode($k2e["attributes"]??($k2e["sizes"]??[]))
];
$ede = explode(".",$k2e["attributes"][0]["file_name"]??"");
return "https://dwgram.cf/_media".(($ede[count($ede)-1])?".".($ede[count($ede)-1]):"")."?".http_build_query($fs);
} else {
throw new Exception("No media found!");
}
};
return call($callable,$message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment