]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blame_incremental - lib/Ban.php
Added version to composer.json and a couple of small (hopefully non-breaking) changes
[irc/unrealircd/unrealircd-rpc-php.git] / lib / Ban.php
... / ...
CommitLineData
1<?php
2
3namespace UnrealIRCd;
4
5use Exception;
6use stdClass;
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 /**
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 get(): 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 * Show a specific ban.
71 *
72 * @param array $params
73 * @return stdClass
74 * @throws Exception
75 */
76 public function show(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}