]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blobdiff - lib/ServerBan.php
Channel: add optional $object_detail_level argument to getAll() and get().
[irc/unrealircd/unrealircd-rpc-php.git] / lib / ServerBan.php
index 8e97e80409c6817de115e88f954fb74aa26b50f0..5764d542d8ef93d100df09af51bd452cde90a8ef 100644 (file)
@@ -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
     }
 }