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