]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blob - lib/Ban.php
Use the correct parameter for gline expiry timestamp
[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 * 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 $response = $this->connection->query('server_ban.add', [
29 'name' => $user,
30 'type' => $params['type'],
31 'reason' => $params['reason'],
32 'expire_at' => $params['length'] ?? '1d',
33 ]);
34
35 return $response;
36 }
37
38 /**
39 * Delete a ban.
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 return $response;
54 }
55
56 /**
57 * Return a list of all bans.
58 *
59 * @return stdClass
60 * @throws Exception
61 */
62 public function get(): stdClass
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 /**
74 * Show a specific ban.
75 *
76 * @param array $params
77 * @return stdClass
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 }