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