]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blob - lib/ServerBan.php
Create NameBan class for adding QLines
[irc/unrealircd/unrealircd-rpc-php.git] / lib / ServerBan.php
1 <?php
2
3 namespace UnrealIRCd;
4
5 use Exception;
6 use stdClass;
7
8 class ServerBan
9 {
10
11 public Connection $connection;
12
13 public function __construct(Connection $conn)
14 {
15 $this->connection = $conn;
16 }
17
18 /**
19 * Add a ban.
20 *
21 * @param string $user
22 * @return stdClass|array|bool
23 * @throws Exception
24 */
25 public function add(string $name, string $type, string $duration, string $reason): stdClass|array|bool
26 {
27 return $this->connection->query('server_ban.add', [
28 'name' => $name,
29 'type' => $type,
30 'reason' => $reason,
31 'duration_string' => $duration ?? '1d',
32 ]);
33 }
34
35 /**
36 * Delete a ban.
37 *
38 * @param string $name
39 * @return stdClass|array|bool
40 * @throws Exception
41 */
42 public function delete(string $name, string $type): stdClass|array|bool
43 {
44 return $this->connection->query('server_ban.del', [
45 'name' => $name,
46 'type' => $type,
47 ]);
48 }
49
50 /**
51 * Return a list of all bans.
52 *
53 * @return stdClass|array|bool
54 * @throws Exception
55 */
56 public function getAll(): stdClass|array|bool
57 {
58 $response = $this->connection->query('server_ban.list');
59
60 if (!is_bool($response)) {
61 return $response->list;
62 }
63
64 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
65 }
66
67 /**
68 * Get a specific ban.
69 *
70 * @return stdClass|array|bool
71 * @throws Exception
72 */
73 public function get(string $name, string $type): stdClass|array|bool
74 {
75 $response = $this->connection->query('server_ban.get', [
76 'name' => $name,
77 'type' => $type
78 ]);
79
80 if (!is_bool($response)) {
81 return $response;
82 }
83
84 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
85 }
86 }