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