listenCommand('pozitie', function (Interaction $interaction) { $options = $interaction->data->options; $inmatriculare = $options['inmatriculare']->value; $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; $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')); }); ?>