]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blob - lib/Spamfilter.php
Add Spamfilter support
[irc/unrealircd/unrealircd-rpc-php.git] / lib / Spamfilter.php
1 <?php
2
3 namespace UnrealIRCd;
4
5 use Exception;
6 use stdClass;
7
8 class Spamfilter
9 {
10
11 public Connection $connection;
12
13 public function __construct(Connection $conn)
14 {
15 $this->connection = $conn;
16 }
17
18 /**
19 * Add a spamfilter.
20 *
21 * @return stdClass
22 * @throws Exception
23 */
24 public function add(string $name, string $match_type, string $spamfilter_targets, string $ban_action, string $ban_duration, string $reason): stdClass
25 {
26 return $this->connection->query('spamfilter.add', [
27 'name' => $name,
28 'match_type' => $match_type,
29 'spamfilter_targets' => $spamfilter_targets,
30 'ban_action' => $ban_action,
31 'ban_duration' => $ban_duration,
32 'reason' => $reason,
33 ]);
34 }
35
36 /**
37 * Delete a spamfilter.
38 *
39 * @return stdClass
40 * @throws Exception
41 */
42 public function delete(string $name, string $match_type, string $spamfilter_targets, string $ban_action): stdClass
43 {
44 return $this->connection->query('spamfilter.del', [
45 'name' => $name,
46 'match_type' => $match_type,
47 'spamfilter_targets' => $spamfilter_targets,
48 'ban_action' => $ban_action,
49 ]);
50 }
51
52 /**
53 * Return a list of all spamfilters.
54 *
55 * @return stdClass
56 * @throws Exception
57 */
58 public function getAll(): stdClass
59 {
60 $response = $this->connection->query('spamfilter.list');
61
62 if (!is_bool($response)) {
63 return $response;
64 }
65
66 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
67 }
68
69 /**
70 * Get a specific spamfilter.
71 *
72 * @return stdClass
73 * @throws Exception
74 */
75 public function get(string $name, string $match_type, string $spamfilter_targets, string $ban_action): stdClass
76 {
77 $response = $this->connection->query('spamfilter.get', [
78 'name' => $name,
79 'match_type' => $match_type,
80 'spamfilter_targets' => $spamfilter_targets,
81 'ban_action' => $ban_action,
82 ]);
83
84 if (!is_bool($response)) {
85 return $response;
86 }
87
88 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
89 }
90 }