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