]>
Commit | Line | Data |
---|---|---|
da11ff54 VP |
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 | |
da11ff54 VP |
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 | ||
13ae2ba6 | 38 | $response = $this->connection->query('name_ban.add', $query); |
8fd8402e VP |
39 | |
40 | if (is_bool($response)) | |
41 | return false; | |
2d5f74f2 | 42 | |
13ae2ba6 BM |
43 | if (property_exists($response, 'tkl')) |
44 | return $response->tkl; | |
45 | return FALSE; | |
da11ff54 VP |
46 | } |
47 | ||
48 | /** | |
49 | * Delete a ban. | |
50 | * | |
51 | * @param string $name | |
52 | * @return stdClass|array|bool | |
da11ff54 VP |
53 | */ |
54 | public function delete(string $name): stdClass|array|bool | |
55 | { | |
13ae2ba6 | 56 | $response = $this->connection->query('name_ban.del', [ |
da11ff54 VP |
57 | 'name' => $name, |
58 | ]); | |
8fd8402e VP |
59 | |
60 | if (is_bool($response)) | |
61 | return false; | |
62 | ||
13ae2ba6 BM |
63 | if (property_exists($response, 'tkl')) |
64 | return $response->tkl; | |
65 | return FALSE; | |
da11ff54 VP |
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 | |
da11ff54 VP |
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)) { | |
13ae2ba6 | 98 | return $response->tkl; |
da11ff54 VP |
99 | } |
100 | ||
2d5f74f2 | 101 | return false; // not found |
da11ff54 VP |
102 | } |
103 | } |