adauga posibilitatea ca comanda /pozitie sa ia un numar de parc ca si argument
This commit is contained in:
parent
b4a0c23212
commit
2b904abc48
@ -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.
|
||||
|
8
bot.php
8
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
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
15
devel/compose.yml
Normal file
15
devel/compose.yml
Normal 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
|
||||
|
Loading…
Reference in New Issue
Block a user