59 lines
2.2 KiB
PHP
59 lines
2.2 KiB
PHP
<?php
|
|
use Discord\Discord;
|
|
use Discord\Parts\Channel\Message;
|
|
use Discord\WebSockets\Event;
|
|
use Discord\Parts\Interactions\Command\Command;
|
|
use Discord\Parts\Interactions\Interaction;
|
|
use Discord\Builders\MessageBuilder;
|
|
|
|
use \DantSu\OpenStreetMapStaticAPI\OpenStreetMap;
|
|
use \DantSu\OpenStreetMapStaticAPI\LatLng;
|
|
use \DantSu\OpenStreetMapStaticAPI\Polygon;
|
|
use \DantSu\OpenStreetMapStaticAPI\Markers;
|
|
|
|
$discord->listenCommand('pozitie', function (Interaction $interaction) {
|
|
$options = $interaction->data->options;
|
|
$inmatriculare = $options['inmatriculare']->value;
|
|
|
|
$client = new \GuzzleHttp\Client();
|
|
$request = $client->request('GET', 'https://maps.mo-bi.ro/api/busData');
|
|
if ($request->getStatusCode() !== 200) {
|
|
$interaction->respondWithMessage(
|
|
MessageBuilder::new()->setContent(
|
|
'OOPSIE WOOPSIE!! Uwu We made a fucky wucky!! A wittle fucko boingo! The code monkeys at our headquarters are working VEWY HAWD to fix this'
|
|
)
|
|
);
|
|
return true;
|
|
}
|
|
|
|
$response = json_decode($request->getBody(), true);
|
|
$vehicle = null;
|
|
|
|
foreach ($response as $v) {
|
|
if ($v['vehicle']['vehicle']['licensePlate'] == $inmatriculare) {
|
|
$vehicle = $v;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!$vehicle) {
|
|
$interaction->respondWithMessage(MessageBuilder::new()->setContent('Vehiculul nu a putut fi gasit.'));
|
|
return true;
|
|
}
|
|
|
|
$latitude = $vehicle['vehicle']['position']['latitude'];
|
|
$longitude = $vehicle['vehicle']['position']['longitude'];
|
|
|
|
(new OpenStreetMap(new LatLng($vehicle['vehicle']['position']['latitude'], $vehicle['vehicle']['position']['longitude']), 16, 600, 300))
|
|
->addMarkers(
|
|
(new Markers(__DIR__ . '/../resources/marker.png'))
|
|
->setAnchor(Markers::ANCHOR_CENTER, Markers::ANCHOR_BOTTOM)
|
|
->addMarker(new LatLng($vehicle['vehicle']['position']['latitude'], $vehicle['vehicle']['position']['longitude']))
|
|
)
|
|
->GetImage()
|
|
->saveJPG(__DIR__ . '/../pozitie.jpg', 70);
|
|
|
|
$interaction->respondWithMessage(MessageBuilder::new()->addFile(__DIR__ . '/../pozitie.jpg'));
|
|
});
|
|
?>
|