From: Bram Matthys Date: Mon, 9 Jan 2023 12:02:15 +0000 (+0100) Subject: Make the *.get/*.add/*.delete calls return the channel/user/.. directly. X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-rpc-php.git/commitdiff_plain/13ae2ba6570f87dbc7e9272d65b340da4f575d52?ds=sidebyside Make the *.get/*.add/*.delete calls return the channel/user/.. directly. So: $user = $rpc->user()->get("Syzop"); if ($user->client->name == "Syzop") .. Becomes: $user = $rpc->user()->get("Syzop"); if ($user->name == "Syzop") .. And: $spamfilter = $rpc->spamfilter()->add(...etc...) Then not dump $spamfilter->tkl but simply $spamfilter. Makes more sense, I think. --- diff --git a/lib/Channel.php b/lib/Channel.php index b081431..e98e6cd 100644 --- a/lib/Channel.php +++ b/lib/Channel.php @@ -43,7 +43,7 @@ class Channel $response = $this->connection->query('channel.get', ['channel' => $channel]); if (!is_bool($response)) { - return $response; + return $response->channel; } throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); diff --git a/lib/NameBan.php b/lib/NameBan.php index 7218a5d..4f969b0 100644 --- a/lib/NameBan.php +++ b/lib/NameBan.php @@ -36,7 +36,10 @@ class NameBan if ($set_by) $query['set_by'] = $set_by; - return $this->connection->query('name_ban.add', $query); + $response = $this->connection->query('name_ban.add', $query); + if (property_exists($response, 'tkl')) + return $response->tkl; + return FALSE; } /** @@ -48,9 +51,12 @@ class NameBan */ public function delete(string $name): stdClass|array|bool { - return $this->connection->query('name_ban.del', [ + $response = $this->connection->query('name_ban.del', [ 'name' => $name, ]); + if (property_exists($response, 'tkl')) + return $response->tkl; + return FALSE; } /** @@ -84,7 +90,7 @@ class NameBan ]); if (!is_bool($response)) { - return $response; + return $response->tkl; } throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); diff --git a/lib/ServerBan.php b/lib/ServerBan.php index 126692a..ab8ea2f 100644 --- a/lib/ServerBan.php +++ b/lib/ServerBan.php @@ -24,12 +24,15 @@ class ServerBan */ 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 (property_exists($response, 'tkl')) + return $response->tkl; + return FALSE; } /** @@ -41,10 +44,13 @@ class ServerBan */ 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 (property_exists($response, 'tkl')) + return $response->tkl; + return FALSE; } /** @@ -78,7 +84,7 @@ class ServerBan ]); if (!is_bool($response)) { - return $response; + return $response->tkl; } throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); diff --git a/lib/Spamfilter.php b/lib/Spamfilter.php index a7a0b39..56fdfb9 100644 --- a/lib/Spamfilter.php +++ b/lib/Spamfilter.php @@ -23,7 +23,7 @@ class Spamfilter */ public function add(string $name, string $match_type, string $spamfilter_targets, string $ban_action, string $ban_duration, string $reason): stdClass|array|bool { - return $this->connection->query('spamfilter.add', [ + $response = $this->connection->query('spamfilter.add', [ 'name' => $name, 'match_type' => $match_type, 'spamfilter_targets' => $spamfilter_targets, @@ -31,6 +31,9 @@ class Spamfilter 'ban_duration' => $ban_duration, 'reason' => $reason, ]); + if (property_exists($response, 'tkl')) + return $response->tkl; + return FALSE; } /** @@ -41,12 +44,15 @@ class Spamfilter */ public function delete(string $name, string $match_type, string $spamfilter_targets, string $ban_action): stdClass|array|bool { - return $this->connection->query('spamfilter.del', [ + $response = $this->connection->query('spamfilter.del', [ 'name' => $name, 'match_type' => $match_type, 'spamfilter_targets' => $spamfilter_targets, 'ban_action' => $ban_action, ]); + if (property_exists($response, 'tkl')) + return $response->tkl; + return FALSE; } /** @@ -82,7 +88,7 @@ class Spamfilter ]); if (!is_bool($response)) { - return $response; + return $response->tkl; } throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); diff --git a/lib/User.php b/lib/User.php index 9cf6f7f..90deaed 100644 --- a/lib/User.php +++ b/lib/User.php @@ -42,7 +42,7 @@ class User $response = $this->connection->query('user.get', ['nick' => $nick]); if (!is_bool($response)) { - return $response; + return $response->client; } throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');