]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blob - lib/Channel.php
Merge pull request #1 from unrealircd/wip
[irc/unrealircd/unrealircd-rpc-php.git] / lib / Channel.php
1 <?php
2
3 namespace UnrealIRCd;
4
5 use Exception;
6
7 class Channel implements Contracts\User
8 {
9
10 public Connection $connection;
11
12 public function __construct(string $uri, string $api_login, array $options)
13 {
14 $this->connection = new Connection($uri, $api_login, $options);
15 }
16
17 /**
18 * Return a list of channels users.
19 *
20 * @throws Exception
21 */
22 public function get(): array
23 {
24 $id = random_int(100, 1000);
25
26 $response = $this->connection->query($id, 'channel.list');
27
28 if($id !== $response->id) {
29 throw new Exception('Invalid ID. This is not the expected reply.');
30 }
31
32 if(!is_bool($response)) {
33 return $response;
34 }
35
36 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
37 }
38
39 /**
40 * Return a channel object
41 *
42 * @param array $params
43 * @return object|bool
44 * @throws Exception
45 */
46 public function show(array $params): object|bool
47 {
48 $id = random_int(100, 1000);
49
50 $response = $this->connection->query($id, 'channel.get', ['channel' => $params['channel']]);
51
52 if($id !== $response->id) {
53 throw new Exception('Invalid ID. This is not the expected reply.');
54 }
55
56 if (!is_bool($response)) {
57 return $response;
58 }
59
60 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
61 }
62 }