]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/commitdiff
Make the *.get/*.add/*.delete calls return the channel/user/.. directly.
authorBram Matthys <redacted>
Mon, 9 Jan 2023 12:02:15 +0000 (13:02 +0100)
committerBram Matthys <redacted>
Mon, 9 Jan 2023 12:17:03 +0000 (13:17 +0100)
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.

lib/Channel.php
lib/NameBan.php
lib/ServerBan.php
lib/Spamfilter.php
lib/User.php

index b0814319317c0a94924a8b1ba399ca32015f6a88..e98e6cd202cdf7c7cdc206d4009acef859d801ce 100644 (file)
@@ -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.');
index 7218a5d7937b53823558eb9402a10d7b4c82404f..4f969b0f557c6e27fc170ce0f54a8386431b84c6 100644 (file)
@@ -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.');
index 126692ad5e3fb341dcd7f7a80611834a6dab4288..ab8ea2fdbb66fef7f36ef3fb1dc3c103a01b1f50 100644 (file)
@@ -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.');
index a7a0b3917eefde94e77728dd7d3ad9dbab2901b6..56fdfb9b809a5b0121b8d5893d84160b69a7d2b8 100644 (file)
@@ -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.');
index 9cf6f7fc86816635d769fb58a7189f648155c58f..90deaeded05df90985f73a8d3ff078de6c925480 100644 (file)
@@ -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.');