]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blob - lib/Ban.php
Return types :<
[irc/unrealircd/unrealircd-rpc-php.git] / lib / Ban.php
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(string $uri, string $api_login, array $options)
14 {
15 $this->connection = new Connection($uri, $api_login, $options);
16 }
17
18 /**
19 * @param string $user
20 * @param array $params
21 * @return stdClass
22 * @throws Exception
23 */
24 public function add(string $user, array $params): stdClass
25 {
26 $response = $this->connection->query('server_ban.add', [
27 'name' => $user,
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 array $params
43 * @return stdClass
44 * @throws Exception
45 */
46 public function delete(string $user, array $params): stdClass
47 {
48 $response = $this->connection->query('server_ban.del', [
49 'name' => $user,
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 */
64 public function get(): stdClass
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 */
80 public function show(array $params): stdClass
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 }