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