A lot of things

This commit is contained in:
2026-06-16 16:21:43 +02:00
parent 4415a2e8c4
commit 73471162bf
37 changed files with 654 additions and 4 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace RomhackPlaza\Master\Service\Discord;
use XF\Service\AbstractService;
class BotService extends AbstractService
{
protected string $dbPath;
protected ?\PDO $pdo = null;
protected function setup()
{
$this->dbPath = \XF::config('discord_db_path');
}
protected function getDb(): \PDO
{
if (!$this->pdo) {
$this->pdo = new \PDO("sqlite:" . $this->dbPath);
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$this->pdo->exec('PRAGMA journal_mode=WAL;');
$this->pdo->exec('PRAGMA busy_timeout=5000;');
}
return $this->pdo;
}
public function createAction( string $action, array $data ): bool
{
try {
$db = $this->getDb();
$stmt = $db->prepare("INSERT INTO actions (action, data) VALUES (:action, :data)");
return $stmt->execute([
':action' => $action,
':data' => json_encode($data)
]);
} catch (\PDOException $e) {
\XF::logException($e, messagePrefix: "BotService error: ");
return false;
}
}
}