diff --git a/bot.php b/bot.php index 2a82176..1b31363 100644 --- a/bot.php +++ b/bot.php @@ -35,6 +35,19 @@ function ellipse($str,$n_chars,$crop_str=' [...]') return $buff; } +function download($url, $outFile) { + $options = array( + CURLOPT_FILE => fopen($outFile, 'w'), + CURLOPT_TIMEOUT => 28800, // set this to 8 hours so we dont timeout on big files + CURLOPT_URL => $url + ); + + $ch = curl_init(); + curl_setopt_array($ch, $options); + curl_exec($ch); + curl_close($ch); +} + $string = get_text('https://ifhub.club/rss/new/'); $service = new \Sabre\Xml\Service(); $service->elementMap = [ @@ -98,10 +111,12 @@ foreach ($articles as $article) { $mdescription .= ": $link"; /* if ($image) { + download('https://ifhub.club'.$image, './'.basename($image)); $attachment = $mastodon->post('/media', [ - 'file' => $image + 'file' => file_get_contents('./'.basename($image)) ]); var_dump($attachment); + unlink('./'.basename($image)); $mdescription .= $attachment->url; }*/ $mastodon->status_post($mdescription); diff --git a/config.yml.example b/config.yml.example index 768289c..fb7a030 100644 --- a/config.yml.example +++ b/config.yml.example @@ -1,8 +1,6 @@ DRY_RUN: true TELEGRAM: true MASTODON: true -MASTODON_CLIENT_ID: some-id -MASTODON_SECRET: oauth_secret MASTODON_ACCESS_TOKEN: token MASTODON_SERVER: https://botsin.space MASTODON_USER: user