]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blob - lib/ServerBan.php
ab8ea2fdbb66fef7f36ef3fb1dc3c103a01b1f50
[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 $response = $this->connection->query('server_ban.add', [
28 'name' => $name,
29 'type' => $type,
30 'reason' => $reason,
31 'duration_string' => $duration ?? '1d',
32 ]);
33 if (property_exists($response, 'tkl'))
34 return $response->tkl;
35 return FALSE;
36 }
37
38 /**
39 * Delete a ban.
40 *
41 * @param string $name
42 * @return stdClass|array|bool
43 * @throws Exception
44 */
45 public function delete(string $name, string $type): stdClass|array|bool
46 {
47 $response = $this->connection->query('server_ban.del', [
48 'name' => $name,
49 'type' => $type,
50 ]);
51 if (property_exists($response, 'tkl'))
52 return $response->tkl;
53 return FALSE;
54 }
55
56 /**
57 * Return a list of all bans.
58 *
59 * @return stdClass|array|bool
60 * @throws Exception
61 */
62 public function getAll(): stdClass|array|bool
63 {
64 $response = $this->connection->query('server_ban.list');
65
66 if (!is_bool($response)) {
67 return $response->list;
68 }
69
70 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
71 }
72
73 /**
74 * Get a specific ban.
75 *
76 * @return stdClass|array|bool
77 * @throws Exception
78 */
79 public function get(string $name, string $type): stdClass|array|bool
80 {
81 $response = $this->connection->query('server_ban.get', [
82 'name' => $name,
83 'type' => $type
84 ]);
85
86 if (!is_bool($response)) {
87 return $response->tkl;
88 }
89
90 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
91 }
92 }