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