X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-rpc-php.git/blobdiff_plain/1a3fda209889ea4e5d449587665a71871c3c99a4..34d2c0ee953a43c2e262079b6226dbdf14a2cbec:/lib/ServerBan.php diff --git a/lib/ServerBan.php b/lib/ServerBan.php index 8e97e80..5764d54 100644 --- a/lib/ServerBan.php +++ b/lib/ServerBan.php @@ -19,46 +19,58 @@ class ServerBan * Add a ban. * * @param string $user - * @return stdClass|bool - * @throws Exception + * @return stdClass|array|bool */ - public function add(string $name, string $type, string $duration, string $reason): stdClass|bool + public function add(string $name, string $type, string $duration, string $reason): stdClass|array|bool { - return $this->connection->query('server_ban.add', [ + $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 $name - * @return stdClass|bool - * @throws Exception + * @return stdClass|array|bool */ - public function delete(string $name, string $type): stdClass|bool + public function delete(string $name, string $type): stdClass|array|bool { - return $this->connection->query('server_ban.del', [ + $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|bool + * @return stdClass|array|bool * @throws Exception */ - public function getAll(): stdClass|bool + 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.'); @@ -67,10 +79,10 @@ class ServerBan /** * Get a specific ban. * - * @return stdClass|bool + * @return stdClass|array|bool * @throws Exception */ - public function get(string $name, string $type): stdClass|bool + public function get(string $name, string $type): stdClass|array|bool { $response = $this->connection->query('server_ban.get', [ 'name' => $name, @@ -78,9 +90,9 @@ class ServerBan ]); if (!is_bool($response)) { - return $response; + return $response->tkl; } - throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); + return false; // didn't exist } }