]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blame - lib/Ban.php
Update Connection::query to listen for a "reply" response rather than "response"...
[irc/unrealircd/unrealircd-rpc-php.git] / lib / Ban.php
CommitLineData
8d5a112f
D
1<?php
2
3namespace UnrealIRCd;
4
5use Exception;
65d96dd6 6use stdClass;
8d5a112f
D
7
8class 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 /**
7951221f
D
19 * Add a ban.
20 *
8d5a112f 21 * @param string $user
8d5a112f 22 * @param array $params
9ef4c6af 23 * @return stdClass
8d5a112f
D
24 * @throws Exception
25 */
9ef4c6af 26 public function add(string $user, array $params): stdClass
8d5a112f
D
27 {
28 $response = $this->connection->query('server_ban.add', [
9ef4c6af 29 'name' => $user,
8d5a112f
D
30 'type' => $params['type'],
31 'reason' => $params['reason'],
1fd745b7 32 'duration_string' => $params['length'] ?? '1d',
8d5a112f
D
33 ]);
34
7951221f 35 return $response;
8d5a112f
D
36 }
37
38 /**
7951221f
D
39 * Delete a ban.
40 *
8d5a112f 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
7951221f 53 return $response;
8d5a112f
D
54 }
55
56 /**
7951221f
D
57 * Return a list of all bans.
58 *
59 * @return stdClass
8d5a112f
D
60 * @throws Exception
61 */
65d96dd6 62 public function get(): stdClass
8d5a112f
D
63 {
64 $response = $this->connection->query('server_ban.list');
65
66 if (!is_bool($response)) {
67 return $response;
68 }
69
70 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
71 }
72
73 /**
7951221f
D
74 * Show a specific ban.
75 *
8d5a112f 76 * @param array $params
7951221f 77 * @return stdClass
8d5a112f
D
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}