Add basecontract
All checks were successful
Deploy App / deploy (push) Successful in 10s

This commit is contained in:
2025-09-04 17:57:15 +02:00
parent 1565df568d
commit aa27851bd7
7 changed files with 39 additions and 22 deletions

View File

@@ -2,9 +2,10 @@
namespace App\Bots;
use App\Interfaces\ScriptContract;
use Illuminate\Support\Facades\Log;
class BashScript implements BotContract
class BashScript implements ScriptContract
{
protected array $config;
@@ -13,22 +14,20 @@ class BashScript implements BotContract
$this->config = $config;
}
public function run(): void
public function run(): string
{
if (!empty($this->config['script'])) {
// Execute the bash script
$script = $this->config['script'];
$output = [];
$returnVar = null;
exec($script, $output, $returnVar);
// Execute the bash script
$script = $this->config['script'];
$output = [];
$returnVar = null;
exec($script, $output, $returnVar);
if ($returnVar !== 0) {
// Log error if the script failed
\Illuminate\Support\Facades\Log::error("Bash script execution failed: " . implode("\n", $output));
} else {
Log::info("Bash script executed successfully: " . implode("\n", $output));
}
if ($returnVar !== 0) {
Log::error("Bash script execution failed", ['script' => $script, 'output' => $output, 'returnVar' => $returnVar]);
throw new \RuntimeException("Bash script execution failed with return code {$returnVar}");
}
return implode("\n", $output);
}
public static function configSchema(): array

View File

@@ -1,11 +0,0 @@
<?php
namespace App\Bots;
use Illuminate\Http\JsonResponse;
interface BotContract
{
public function run(): JsonResponse;
public static function configSchema(): array;
}

View File

@@ -2,6 +2,7 @@
namespace App\Bots;
use App\Interfaces\BotContract;
use GuzzleHttp\Client;
use Illuminate\Http\JsonResponse;