]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blame - lib/Ban.php
This should be enough for some preliminary usage.
[irc/unrealircd/unrealircd-rpc-php.git] / lib / Ban.php
CommitLineData
8d5a112f
D
1<?php
2
3namespace UnrealIRCd;
4
5use Exception;
6
7class Ban implements Contracts\Ban
8{
9
10 public Connection $connection;
11
12 public function __construct(string $uri, string $api_login, array $options)
13 {
14 $this->connection = new Connection($uri, $api_login, $options);
15 }
16
17 /**
18 * @param string $user
19 * @param string $type
20 * @param array $params
21 * @return bool
22 * @throws Exception
23 */
24 public function add(string $user, string $type, array $params): bool
25 {
26 $response = $this->connection->query('server_ban.add', [
27 'name' => $params['name'],
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
42 * @param string $type
43 * @param array $params
44 * @return bool
45 * @throws Exception
46 */
47 public function delete(string $user, string $type, array $params): bool
48 {
49 $response = $this->connection->query('server_ban.del', [
50 'name' => $params['name'],
51 'type' => $params['type'],
52 ]);
53
54 if (is_bool($response)) {
55 return $response;
56 }
57
58 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
59 }
60
61 /**
62 * @return array|bool
63 * @throws Exception
64 */
65 public function get(): array|bool
66 {
67 $response = $this->connection->query('server_ban.list');
68
69 if (!is_bool($response)) {
70 return $response;
71 }
72
73 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
74 }
75
76 /**
77 * @param array $params
78 * @return object|bool
79 * @throws Exception
80 */
81 public function show(array $params): object|bool
82 {
83 $response = $this->connection->query('server_ban.get', [
84 'name' => $params['name'],
85 'type' => $params['type']
86 ]);
87
88 if (!is_bool($response)) {
89 return $response;
90 }
91
92 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
93 }
94}