A lot of things
This commit is contained in:
44
Service/Discord/BotService.php
Normal file
44
Service/Discord/BotService.php
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user