1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-30 08:18:59 +01:00

Make stories downloadable and repostable

This commit is contained in:
Daniil Gentili 2023-07-21 19:38:35 +02:00
parent 7c871d977b
commit 82917126e5
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 19 additions and 4 deletions

View File

@ -171,6 +171,10 @@ class MyEventHandler extends SimpleEventHandler
/**
* Downloads all telegram stories of a user (including protected ones).
*
* The bot must be started via web for this command to work.
*
* You can also start it via CLI but you'll have to specify a download script URL in the settings: https://docs.madelineproto.xyz/docs/FILES.html#getting-a-download-link-cli-bots.
*/
#[FilterCommand('dlStories')]
public function dlStoriesCommand(Message $message): void
@ -183,11 +187,16 @@ class MyEventHandler extends SimpleEventHandler
$stories = $this->stories->getUserStories(user_id: $message->commandArgs[0])['stories']['stories'];
// Skip deleted stories
$stories = array_filter($stories, fn (array $s): bool => $s['_'] === 'storyItem');
// Sort by date
usort($stories, fn ($a, $b) => $a['date'] <=> $b['date']);
$result = "Total stories: ".count($stories)."\n\n";
foreach ($stories as $story) {
$message = self::markdownEscape($story['caption']);
$result .= "[$message]({$this->getDownloadLink($story)})\n";
$cur = "- ID {$story['id']}, posted ".date(DATE_RFC850, $story['date']);
if (isset($story['caption'])) {
$cur .= ', "'.self::markdownEscape($story['caption']).'": ';
}
$result .= "$cur; [click here to download »]({$this->getDownloadLink($story)})\n";
}
$message->reply($result, parseMode: ParseMode::MARKDOWN);
@ -247,6 +256,10 @@ class MyEventHandler extends SimpleEventHandler
/**
* Gets a download link for any file up to 4GB!
*
* The bot must be started via web for this command to work.
*
* You can also start it via CLI but you'll have to specify a download script URL in the settings: https://docs.madelineproto.xyz/docs/FILES.html#getting-a-download-link-cli-bots.
*/
#[FilterCommand('dl')]
public function downloadLink(Incoming&Message $message): void

View File

@ -249,7 +249,7 @@ trait FilesLogic
} elseif (\is_array($file)) {
return $this->uploadFromTgfile($file, $cb, $encrypted);
}
if ($file instanceof ReadableStream) {
if ($file instanceof ReadableStream || \is_resource($file)) {
return $this->uploadFromStream($file, 0, '', $fileName, $cb, $encrypted);
}
if ($file instanceof LocalFile) {

View File

@ -160,12 +160,14 @@ trait BotAPI
$newd = [];
if (!isset($data['_'])) {
foreach ($data as $key => $element) {
$newd[$key] = ($this->MTProtoToBotAPI($element));
$newd[$key] = $this->MTProtoToBotAPI($element);
}
return $newd;
}
$res = null;
switch ($data['_']) {
case 'storyItem':
return $this->MTProtoToBotAPI($data['media']);
case 'updates':
case 'updatesCombined':
case 'updateShort':