]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace UnrealIRCd; | |
4 | ||
5 | use Exception; | |
6 | use stdClass; | |
7 | ||
8 | class NameBan | |
9 | { | |
10 | ||
11 | public Connection $connection; | |
12 | ||
13 | public function __construct(Connection $conn) | |
14 | { | |
15 | $this->connection = $conn; | |
16 | } | |
17 | ||
18 | /** | |
19 | * Add a name ban (QLine). | |
20 | * | |
21 | * @param string $name | |
22 | * @param string $reason | |
23 | * @param string $duration Optional | |
24 | * @param string $set_by Optional | |
25 | * @return stdClass|array|bool | |
26 | */ | |
27 | public function add(string $name, string $reason, string $duration = NULL, $set_by = NULL): stdClass|array|bool | |
28 | { | |
29 | $query = [ | |
30 | 'name' => $name, | |
31 | 'reason' => $reason, | |
32 | 'duration_string' => $duration ?? '0', | |
33 | ]; | |
34 | ||
35 | if ($set_by) | |
36 | $query['set_by'] = $set_by; | |
37 | ||
38 | $response = $this->connection->query('name_ban.add', $query); | |
39 | ||
40 | if (is_bool($response)) | |
41 | return false; | |
42 | ||
43 | if (property_exists($response, 'tkl')) | |
44 | return $response->tkl; | |
45 | return FALSE; | |
46 | } | |
47 | ||
48 | /** | |
49 | * Delete a ban. | |
50 | * | |
51 | * @param string $name | |
52 | * @return stdClass|array|bool | |
53 | */ | |
54 | public function delete(string $name): stdClass|array|bool | |
55 | { | |
56 | $response = $this->connection->query('name_ban.del', [ | |
57 | 'name' => $name, | |
58 | ]); | |
59 | ||
60 | if (is_bool($response)) | |
61 | return false; | |
62 | ||
63 | if (property_exists($response, 'tkl')) | |
64 | return $response->tkl; | |
65 | return FALSE; | |
66 | } | |
67 | ||
68 | /** | |
69 | * Return a list of all bans. | |
70 | * | |
71 | * @return stdClass|array|bool | |
72 | * @throws Exception | |
73 | */ | |
74 | public function getAll(): stdClass|array|bool | |
75 | { | |
76 | $response = $this->connection->query('name_ban.list'); | |
77 | ||
78 | if (!is_bool($response)) { | |
79 | return $response->list; | |
80 | } | |
81 | ||
82 | throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); | |
83 | } | |
84 | ||
85 | /** | |
86 | * Get a specific ban. | |
87 | * | |
88 | * @param string $name | |
89 | * @return stdClass|array|bool | |
90 | */ | |
91 | public function get(string $name): stdClass|array|bool | |
92 | { | |
93 | $response = $this->connection->query('name_ban.get', [ | |
94 | 'name' => $name, | |
95 | ]); | |
96 | ||
97 | if (!is_bool($response)) { | |
98 | return $response->tkl; | |
99 | } | |
100 | ||
101 | return false; // not found | |
102 | } | |
103 | } |