]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blob - lib/ServerBanException.php
Add streaming JSON-LOG support. Requires UnrealIRCd 6.1.0+
[irc/unrealircd/unrealircd-rpc-php.git] / lib / ServerBanException.php
1 <?php
2
3 namespace UnrealIRCd;
4
5 use Exception;
6 use stdClass;
7
8 class ServerBanException
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 exceptions.
20 *
21 * @param string $user
22 * @return stdClass|array|bool
23 * @throws Exception
24 */
25 public function add(string $name, string $types, string $reason, string $set_by = NULL, string $duration = NULL): stdClass|array|bool
26 {
27 $query = [
28 'name' => $name,
29 'exception_types' => $types,
30 'reason' => $reason,
31 ];
32 if ($set_by)
33 $query['set_by'] = $set_by;
34
35 if ($duration)
36 $query['duration_string'] = $duration;
37
38 $response = $this->connection->query('server_ban_exception.add', $query);
39
40 if (is_bool($response))
41 return false;
42
43 if (property_exists($response, 'tkl'))
44 return $response->tkl;
45 return FALSE;
46 }
47
48 /**
49 * Delete a ban exceptions.
50 *
51 * @param string $name
52 * @return stdClass|array|bool
53 * @throws Exception
54 */
55 public function delete(string $name): stdClass|array|bool
56 {
57 $response = $this->connection->query('server_ban_exception.del', [
58 'name' => $name,
59 ]);
60
61 if (is_bool($response))
62 return false;
63
64 if (property_exists($response, 'tkl'))
65 return $response->tkl;
66 return FALSE;
67 }
68
69 /**
70 * Return a list of all exceptions.
71 *
72 * @return stdClass|array|bool
73 * @throws Exception
74 */
75 public function getAll(): stdClass|array|bool
76 {
77 $response = $this->connection->query('server_ban_exception.list', []);
78
79 if (!is_bool($response)) {
80 return $response->list;
81 }
82
83 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
84 }
85
86 /**
87 * Get a specific ban exceptions.
88 *
89 * @return stdClass|array|bool
90 * @throws Exception
91 */
92 public function get(string $name): stdClass|array|bool
93 {
94 $response = $this->connection->query('server_ban_exception.get', [
95 'name' => $name,
96 ]);
97
98 if (!is_bool($response)) {
99 return $response->tkl;
100 }
101
102 return false; // didn't exist
103 }
104 }
105