Add function to get message sender ID
[SonOfLokstallBot.git] / goodnight.php
1 <?php declare(strict_types=1);
2
3 require 'common.php';
4
5 use Cmfcmf\OpenWeatherMap;
6
7 $temps =
8 array_values(
9 array_map(function($forecast) {
10 return $forecast->temperature->now->getValue();
11 },
12 array_filter(
13 iterator_to_array(
14 (new OpenWeatherMap(OWM_API_KEY))->getWeatherForecast(2063523, 'metric', 'en', '', 2)
15 ),
16 function($forecast) {
17 $forecastDayLocal = DateTimeImmutable::createFromMutable($forecast->time->from)->setTimezone(new DateTimeZone('Australia/Perth'));
18 return (int)(new DateTimeImmutable())->format('d') + 1 == (int)$forecastDayLocal->format('d');
19 }
20 )));
21
22 getTelegram()->sendMessage(
23 [
24 'chat_id' => array_flip(PARTICIPANT_IDS)['Cam'],
25 'text' => max($temps) > 30
26 ? getString('goodnightWearShorts', ceil($temps[1]) . '°', ceil(max($temps)) . '°')
27 : getString('goodnightNormal', ceil($temps[1]) . '°', ceil(max($temps)) . '°'),
28 ]
29 );
30
31 getTelegram()->sendMessage(['chat_id' => array_flip(PARTICIPANT_IDS)['Cam'], 'text' => getString('goodnight')]);
32 getTelegram()->sendSticker(['chat_id' => array_flip(PARTICIPANT_IDS)['Cam'], 'sticker' => 'CAADBQAD1A4AAsZRxhX9dbtZf_4i_wI',]);