adauga posibilitatea ca comanda /pozitie sa ia un numar de parc ca si argument

This commit is contained in:
fzorb 2025-01-11 08:06:03 +02:00
parent b4a0c23212
commit 2b904abc48
7 changed files with 48 additions and 5 deletions

View File

@ -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.

View File

@ -39,7 +39,13 @@ $discord->on('init', function (Discord $discord) {
'name' => 'inmatriculare', 'name' => 'inmatriculare',
'description' => 'Numarul de inmatriculare', 'description' => 'Numarul de inmatriculare',
'type' => 3, 'type' => 3,
'required' => true 'required' => false
],
[
'name' => 'numarparc',
'description' => 'Numarul de parc al vehicului',
'type' => 4,
'required' => false
] ]
] ]
]); ]);

View File

@ -9,7 +9,7 @@ use Discord\Builders\MessageBuilder;
$discord->listenCommand('infovehicul', function (Interaction $interaction) { $discord->listenCommand('infovehicul', function (Interaction $interaction) {
$options = $interaction->data->options; $options = $interaction->data->options;
$parc = $options['numarparc']->value; $parc = $options['numarparc']->value;
echo $parc;
$client = new \GuzzleHttp\Client(); $client = new \GuzzleHttp\Client();
$request = $client->request('GET', 'https://maps.mo-bi.ro/api/passenger-data'); $request = $client->request('GET', 'https://maps.mo-bi.ro/api/passenger-data');
if ($request->getStatusCode() !== 200) { if ($request->getStatusCode() !== 200) {

View File

@ -11,10 +11,29 @@ use \DantSu\OpenStreetMapStaticAPI\LatLng;
use \DantSu\OpenStreetMapStaticAPI\Polygon; use \DantSu\OpenStreetMapStaticAPI\Polygon;
use \DantSu\OpenStreetMapStaticAPI\Markers; 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) { $discord->listenCommand('pozitie', function (Interaction $interaction) {
$options = $interaction->data->options; $options = $interaction->data->options;
$inmatriculare = $options['inmatriculare']->value; $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(); $client = new \GuzzleHttp\Client();
$request = $client->request('GET', 'https://maps.mo-bi.ro/api/busData'); $request = $client->request('GET', 'https://maps.mo-bi.ro/api/busData');
if ($request->getStatusCode() !== 200) { if ($request->getStatusCode() !== 200) {

15
devel/compose.yml Normal file
View File

@ -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

View File

@ -1,2 +0,0 @@
# Ikarusbot
blah blah blah facut in php

View File