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