listenCommand('pozitie', function (Interaction $interaction) { $options = $interaction->data->options; $inmatriculare = $options['inmatriculare']->value; $numarparc = $options['numarparc']->value; if (!$inmatriculare && !$numarparc) { $inmatriculare = null; } 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; $random = false; if (!$inmatriculare && !$numarparc) { $vehicle = $response[array_rand($response)]; $random = true; } else { 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); if ($random) { $stbdb = new PDO("sqlite:" . __DIR__ . "/../stbdb.db"); $stmt = $stbdb->prepare("SELECT parc FROM inmatriculari WHERE inmatriculare = :inmatriculare"); $stmt->bindParam(':inmatriculare', reverseNormalizeSpecialNumber($vehicle['vehicle']['vehicle']['licensePlate'])); $stmt->execute(); $vehParc = $stmt->fetch(PDO::FETCH_COLUMN); if (!$vehParc && $vehicle['vehicle']['vehicle']['licensePlate']) { $vehParc = $vehicle['vehicle']['vehicle']['licensePlate']; } else if (!$vehParc && !$vehicle['vehicle']['vehicle']['licensePlate']) { $vehParc = "Nu am putut identifica acest vehicul."; } $interaction->respondWithMessage(MessageBuilder::new()->setContent("**" . $vehParc . "**")->addFile(__DIR__ . '/../pozitie.jpg')); } else { $interaction->respondWithMessage(MessageBuilder::new()->addFile(__DIR__ . '/../pozitie.jpg')); } }); ?>