]>
Commit | Line | Data |
---|---|---|
b0cc6f59 BM |
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 | * | |
93f8a3ee | 21 | * @return stdClass|array|bool |
b0cc6f59 BM |
22 | * @throws Exception |
23 | */ | |
93f8a3ee | 24 | public function add(string $name, string $match_type, string $spamfilter_targets, string $ban_action, string $ban_duration, string $reason): stdClass|array|bool |
b0cc6f59 BM |
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 | * | |
93f8a3ee | 39 | * @return stdClass|array|bool |
b0cc6f59 BM |
40 | * @throws Exception |
41 | */ | |
93f8a3ee | 42 | public function delete(string $name, string $match_type, string $spamfilter_targets, string $ban_action): stdClass|array|bool |
b0cc6f59 BM |
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 | * | |
93f8a3ee | 55 | * @return stdClass|array|bool |
b0cc6f59 BM |
56 | * @throws Exception |
57 | */ | |
93f8a3ee | 58 | public function getAll(): stdClass|array|bool |
b0cc6f59 BM |
59 | { |
60 | $response = $this->connection->query('spamfilter.list'); | |
61 | ||
62 | if (!is_bool($response)) { | |
93f8a3ee | 63 | return $response->list; |
b0cc6f59 BM |
64 | } |
65 | ||
66 | throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); | |
67 | } | |
68 | ||
69 | /** | |
70 | * Get a specific spamfilter. | |
71 | * | |
93f8a3ee | 72 | * @return stdClass|array|bool |
b0cc6f59 BM |
73 | * @throws Exception |
74 | */ | |
93f8a3ee | 75 | public function get(string $name, string $match_type, string $spamfilter_targets, string $ban_action): stdClass|array|bool |
b0cc6f59 BM |
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 | } |