Initial work

This commit is contained in:
2025-08-30 16:11:06 +02:00
parent 4e5f154492
commit 774d1cf45f
41 changed files with 1217 additions and 281 deletions

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Services;
use App\Models\Bot;
use App\Bots\BotContract;
use Cron\CronExpression;
use Illuminate\Support\Facades\Log;
class BotService
{
public function run(): void
{
$bots = Bot::where('enabled', 1)->get();
foreach ($bots as $bot) {
$cron = new CronExpression($bot->schedule);
if ($cron->isDue()) {
try {
$instance = app($bot->class, ['config' => $bot->config]);
if ($instance instanceof BotContract) {
$instance->run();
}
} catch (\Throwable $e) {
Log::error("Bot [{$bot->name}] failed: " . $e->getMessage());
}
Log::info("Bot [{$bot->name}] executed successfully.");
}
}
}
}