aboutsummaryrefslogtreecommitdiff
path: root/get-attaches.php
blob: 36c12ee554ba62c7be43773fe8efd6af70631e13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php

require_once __DIR__.'/common.php';

$str = file_get_contents('php://stdin');
if (!$str)
    fatalError("no input");

$message_ids = [];
$photo_urls = [];

$on_message = function($doc, $message_id) {
    global $message_ids;
    $message_ids[] = $message_id;
};
$on_photo = function($doc, $href, $link_node) {
    global $photo_urls;
    $photo_urls[] = $href;
};

try {
    onEachMessageOrAttachment($str, $on_message, $on_photo);
} catch (Exception $e) {
    fatalError($e->getMessage());
}

if (!empty($message_ids))
    echo implode("\n", $message_ids)."\n";

if (!empty($photo_urls))
    echo implode("\n", $photo_urls)."\n";