2025-01-10 19:52:34 +02:00
|
|
|
<?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;
|
|
|
|
|
2025-01-11 08:06:03 +02:00
|
|
|
function normalizeSpecialNumber($input) {
|
|
|
|
if (preg_match('/^B-(\d{5})$/', $input, $matches)) {
|
|
|
|
return 'B' . $matches[1];
|
|
|
|
}
|
|
|
|
return $input;
|
|
|
|
}
|
|
|
|
|
2025-01-10 19:52:34 +02:00
|
|
|
$discord->listenCommand('pozitie', function (Interaction $interaction) {
|
|
|
|
$options = $interaction->data->options;
|
|
|
|
$inmatriculare = $options['inmatriculare']->value;
|
2025-01-11 08:06:03 +02:00
|
|
|
$numarparc = $options['numarparc']->value;
|
|
|
|
|
|
|
|
if (!$inmatriculare && !$numarparc) {
|
|
|
|
$interaction->respondWithMessage(MessageBuilder::new()->setContent('Musai trebuie sa ai ori un numar de inmatriculare, ori un numar de parc.'));
|
|
|
|
return true;
|
|
|
|
} else if (!$inmatriculare) {
|
|
|
|
$stbdb = new PDO("sqlite:" . __DIR__ . "/../stbdb.db");
|
|
|
|
$stmt = $stbdb->prepare("SELECT inmatriculare FROM inmatriculari WHERE parc = :parc");
|
|
|
|
$stmt->bindParam(':parc', $numarparc);
|
|
|
|
$stmt->execute();
|
|
|
|
$inmatriculare = normalizeSpecialNumber($stmt->fetch(PDO::FETCH_COLUMN));
|
|
|
|
}
|
|
|
|
echo $inmatriculare;
|
2025-01-10 19:52:34 +02:00
|
|
|
$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'));
|
|
|
|
});
|
|
|
|
?>
|