]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blob - lib/Spamfilter.php
Add nameban to Connection.php and various bugfixes
[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|array|bool
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|array|bool
25 {
26 $response = $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 if (is_bool($response))
36 return false;
37
38 if (property_exists($response, 'tkl'))
39 return $response->tkl;
40 return FALSE;
41 }
42
43 /**
44 * Delete a spamfilter.
45 *
46 * @return stdClass|array|bool
47 * @throws Exception
48 */
49 public function delete(string $name, string $match_type, string $spamfilter_targets, string $ban_action): stdClass|array|bool
50 {
51 $response = $this->connection->query('spamfilter.del', [
52 'name' => $name,
53 'match_type' => $match_type,
54 'spamfilter_targets' => $spamfilter_targets,
55 'ban_action' => $ban_action,
56 ]);
57
58 if (is_bool($response))
59 return false;
60
61 if (property_exists($response, 'tkl'))
62 return $response->tkl;
63 return FALSE;
64 }
65
66 /**
67 * Return a list of all spamfilters.
68 *
69 * @return stdClass|array|bool
70 * @throws Exception
71 */
72 public function getAll(): stdClass|array|bool
73 {
74 $response = $this->connection->query('spamfilter.list');
75
76 if (!is_bool($response)) {
77 return $response->list;
78 }
79
80 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
81 }
82
83 /**
84 * Get a specific spamfilter.
85 *
86 * @return stdClass|array|bool
87 * @throws Exception
88 */
89 public function get(string $name, string $match_type, string $spamfilter_targets, string $ban_action): stdClass|array|bool
90 {
91 $response = $this->connection->query('spamfilter.get', [
92 'name' => $name,
93 'match_type' => $match_type,
94 'spamfilter_targets' => $spamfilter_targets,
95 'ban_action' => $ban_action,
96 ]);
97
98 if (!is_bool($response)) {
99 return $response->tkl;
100 }
101
102 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
103 }
104 }