]>
Commit | Line | Data |
---|---|---|
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 | */ | |
23 | public function add(string $name, string $match_type, string $spamfilter_targets, string $ban_action, string $ban_duration, string $reason): stdClass|array|bool | |
24 | { | |
25 | $response = $this->connection->query('spamfilter.add', [ | |
26 | 'name' => $name, | |
27 | 'match_type' => $match_type, | |
28 | 'spamfilter_targets' => $spamfilter_targets, | |
29 | 'ban_action' => $ban_action, | |
30 | 'ban_duration' => $ban_duration, | |
31 | 'reason' => $reason, | |
32 | ]); | |
33 | ||
34 | if (is_bool($response)) | |
35 | return false; | |
36 | ||
37 | if (property_exists($response, 'tkl')) | |
38 | return $response->tkl; | |
39 | return FALSE; | |
40 | } | |
41 | ||
42 | /** | |
43 | * Delete a spamfilter. | |
44 | * | |
45 | * @return stdClass|array|bool | |
46 | */ | |
47 | public function delete(string $name, string $match_type, string $spamfilter_targets, string $ban_action): stdClass|array|bool | |
48 | { | |
49 | $response = $this->connection->query('spamfilter.del', [ | |
50 | 'name' => $name, | |
51 | 'match_type' => $match_type, | |
52 | 'spamfilter_targets' => $spamfilter_targets, | |
53 | 'ban_action' => $ban_action, | |
54 | ]); | |
55 | ||
56 | if (is_bool($response)) | |
57 | return false; | |
58 | ||
59 | if (property_exists($response, 'tkl')) | |
60 | return $response->tkl; | |
61 | return FALSE; | |
62 | } | |
63 | ||
64 | /** | |
65 | * Return a list of all spamfilters. | |
66 | * | |
67 | * @return stdClass|array|bool | |
68 | * @throws Exception | |
69 | */ | |
70 | public function getAll(): stdClass|array|bool | |
71 | { | |
72 | $response = $this->connection->query('spamfilter.list'); | |
73 | ||
74 | if (!is_bool($response)) { | |
75 | return $response->list; | |
76 | } | |
77 | ||
78 | throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); | |
79 | } | |
80 | ||
81 | /** | |
82 | * Get a specific spamfilter. | |
83 | * | |
84 | * @return stdClass|array|bool | |
85 | */ | |
86 | public function get(string $name, string $match_type, string $spamfilter_targets, string $ban_action): stdClass|array|bool | |
87 | { | |
88 | $response = $this->connection->query('spamfilter.get', [ | |
89 | 'name' => $name, | |
90 | 'match_type' => $match_type, | |
91 | 'spamfilter_targets' => $spamfilter_targets, | |
92 | 'ban_action' => $ban_action, | |
93 | ]); | |
94 | ||
95 | if (!is_bool($response)) { | |
96 | return $response->tkl; | |
97 | } | |
98 | ||
99 | return false; // not found | |
100 | } | |
101 | } |