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