From 2b904abc486a0dfd5eb0684fbb2eadafb88ce4ed Mon Sep 17 00:00:00 2001 From: fzorb Date: Sat, 11 Jan 2025 08:06:03 +0200 Subject: [PATCH] adauga posibilitatea ca comanda /pozitie sa ia un numar de parc ca si argument --- README.md | 5 +++++ bot.php | 8 +++++++- commands/infovehicul.php | 2 +- commands/pozitie.php | 21 ++++++++++++++++++++- devel/compose.yml | 15 +++++++++++++++ readme.md | 2 -- db.db => stbdb.db | Bin 7 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 devel/compose.yml delete mode 100644 readme.md rename db.db => stbdb.db (100%) diff --git a/README.md b/README.md index e69de29..d14caf0 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,5 @@ +# ikarusbot +Acesta este un bot facut in PHP care arata diverse lucruri despre vehiculele TPBI. Foloseste biblioteca Discord-PHP. + +As vrea sa multumesc persoanelor care au contribuit la spreadsheet-ul https://docs.google.com/spreadsheets/d/1p67Te4ls3RJmtvIlGjy4fH28nzqJQEK_MTwFNkQDGZI/edit. Fara contributia lor, acest bot n-ar putea folosi numerele de parc pentru unele comenzi. + diff --git a/bot.php b/bot.php index a72aa1c..3898409 100644 --- a/bot.php +++ b/bot.php @@ -39,7 +39,13 @@ $discord->on('init', function (Discord $discord) { 'name' => 'inmatriculare', 'description' => 'Numarul de inmatriculare', 'type' => 3, - 'required' => true + 'required' => false + ], + [ + 'name' => 'numarparc', + 'description' => 'Numarul de parc al vehicului', + 'type' => 4, + 'required' => false ] ] ]); diff --git a/commands/infovehicul.php b/commands/infovehicul.php index da8f92a..7054279 100644 --- a/commands/infovehicul.php +++ b/commands/infovehicul.php @@ -9,7 +9,7 @@ use Discord\Builders\MessageBuilder; $discord->listenCommand('infovehicul', function (Interaction $interaction) { $options = $interaction->data->options; $parc = $options['numarparc']->value; - + echo $parc; $client = new \GuzzleHttp\Client(); $request = $client->request('GET', 'https://maps.mo-bi.ro/api/passenger-data'); if ($request->getStatusCode() !== 200) { diff --git a/commands/pozitie.php b/commands/pozitie.php index 2489531..efbd42c 100644 --- a/commands/pozitie.php +++ b/commands/pozitie.php @@ -11,10 +11,29 @@ use \DantSu\OpenStreetMapStaticAPI\LatLng; use \DantSu\OpenStreetMapStaticAPI\Polygon; use \DantSu\OpenStreetMapStaticAPI\Markers; +function normalizeSpecialNumber($input) { + if (preg_match('/^B-(\d{5})$/', $input, $matches)) { + return 'B' . $matches[1]; + } + return $input; +} + $discord->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) { diff --git a/devel/compose.yml b/devel/compose.yml new file mode 100644 index 0000000..b86b3e4 --- /dev/null +++ b/devel/compose.yml @@ -0,0 +1,15 @@ +version: '3.8' +services: + ikarus: + build: + context: .. + dockerfile: Dockerfile + volumes: + - ../token.txt:/bot/token.txt + command: php bot.php + restart: always + develop: + watch: + - action: rebuild + path: ../bot + diff --git a/readme.md b/readme.md deleted file mode 100644 index 8d51270..0000000 --- a/readme.md +++ /dev/null @@ -1,2 +0,0 @@ -# Ikarusbot -blah blah blah facut in php diff --git a/db.db b/stbdb.db similarity index 100% rename from db.db rename to stbdb.db