X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-rpc-php.git/blobdiff_plain/7ad9236a9aa1ae4c8a389ffb40e61bf04b974317..34d2c0ee953a43c2e262079b6226dbdf14a2cbec:/lib/ServerBan.php diff --git a/lib/ServerBan.php b/lib/ServerBan.php index c1c9a2f..5764d54 100644 --- a/lib/ServerBan.php +++ b/lib/ServerBan.php @@ -5,7 +5,7 @@ namespace UnrealIRCd; use Exception; use stdClass; -class Ban implements Contracts\Ban +class ServerBan { public Connection $connection; @@ -19,48 +19,58 @@ class Ban implements Contracts\Ban * Add a ban. * * @param string $user - * @param array $params - * @return stdClass - * @throws Exception + * @return stdClass|array|bool */ - public function add(string $user, array $params): stdClass + public function add(string $name, string $type, string $duration, string $reason): stdClass|array|bool { - return $this->connection->query('server_ban.add', [ - 'name' => $user, - 'type' => $params['type'], - 'reason' => $params['reason'], - 'duration_string' => $params['length'] ?? '1d', + $response = $this->connection->query('server_ban.add', [ + 'name' => $name, + 'type' => $type, + 'reason' => $reason, + 'duration_string' => $duration ?? '1d', ]); + + if (is_bool($response)) + return false; + + if (property_exists($response, 'tkl')) + return $response->tkl; + return FALSE; } /** * Delete a ban. * - * @param string $user - * @param array $params - * @return stdClass - * @throws Exception + * @param string $name + * @return stdClass|array|bool */ - public function delete(string $user, array $params): stdClass + public function delete(string $name, string $type): stdClass|array|bool { - return $this->connection->query('server_ban.del', [ - 'name' => $user, - 'type' => $params['type'], + $response = $this->connection->query('server_ban.del', [ + 'name' => $name, + 'type' => $type, ]); + + if (is_bool($response)) + return false; + + if (property_exists($response, 'tkl')) + return $response->tkl; + return FALSE; } /** * Return a list of all bans. * - * @return stdClass + * @return stdClass|array|bool * @throws Exception */ - public function getAll(): stdClass + public function getAll(): stdClass|array|bool { $response = $this->connection->query('server_ban.list'); if (!is_bool($response)) { - return $response; + return $response->list; } throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); @@ -69,21 +79,20 @@ class Ban implements Contracts\Ban /** * Get a specific ban. * - * @param array $params - * @return stdClass + * @return stdClass|array|bool * @throws Exception */ - public function get(array $params): stdClass + public function get(string $name, string $type): stdClass|array|bool { $response = $this->connection->query('server_ban.get', [ - 'name' => $params['name'], - 'type' => $params['type'] + 'name' => $name, + 'type' => $type ]); if (!is_bool($response)) { - return $response; + return $response->tkl; } - throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); + return false; // didn't exist } }