]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blobdiff - lib/Spamfilter.php
Whoops.. i was wrong.. microtime() w/$as_float=true... duh :D
[irc/unrealircd/unrealircd-rpc-php.git] / lib / Spamfilter.php
index a426530a3e7e4902ad911934fef1c4fbb953efe9..fbb889a8cf68475b5069730c6839eb576d8ffcfb 100644 (file)
@@ -18,12 +18,11 @@ class Spamfilter
     /**
      * Add a spamfilter.
      *
-     * @return stdClass
-     * @throws Exception
+     * @return stdClass|array|bool
      */
-    public function add(string $name, string $match_type, string $spamfilter_targets, string $ban_action, string $ban_duration, string $reason): stdClass
+    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,36 +30,49 @@ class Spamfilter
             'ban_duration' => $ban_duration,
             'reason' => $reason,
         ]);
+
+        if (is_bool($response))
+            return false;
+
+        if (property_exists($response, 'tkl'))
+            return $response->tkl;
+        return FALSE;
     }
 
     /**
      * Delete a spamfilter.
      *
-     * @return stdClass
-     * @throws Exception
+     * @return stdClass|array|bool
      */
-    public function delete(string $name, string $match_type, string $spamfilter_targets, string $ban_action): stdClass
+    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 (is_bool($response))
+            return false;
+
+        if (property_exists($response, 'tkl'))
+            return $response->tkl;
+        return FALSE;
     }
 
     /**
      * Return a list of all spamfilters.
      *
-     * @return stdClass
+     * @return stdClass|array|bool
      * @throws Exception
      */
-    public function getAll(): stdClass
+    public function getAll(): stdClass|array|bool
     {
         $response = $this->connection->query('spamfilter.list');
 
         if (!is_bool($response)) {
-            return $response;
+            return $response->list;
         }
 
         throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
@@ -69,10 +81,9 @@ class Spamfilter
     /**
      * Get a specific spamfilter.
      *
-     * @return stdClass
-     * @throws Exception
+     * @return stdClass|array|bool
      */
-    public function get(string $name, string $match_type, string $spamfilter_targets, string $ban_action): stdClass
+    public function get(string $name, string $match_type, string $spamfilter_targets, string $ban_action): stdClass|array|bool
     {
         $response = $this->connection->query('spamfilter.get', [
             'name' => $name,
@@ -82,9 +93,9 @@ class Spamfilter
         ]);
 
         if (!is_bool($response)) {
-            return $response;
+            return $response->tkl;
         }
 
-        throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
+        return false; // not found
     }
 }