]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blob - lib/Channel.php
Add $rpc->stats()->get();
[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
9 {
10
11 public Connection $connection;
12
13 public function __construct(Connection $conn)
14 {
15 $this->connection = $conn;
16 }
17
18 /**
19 * Return a list of channels users.
20 *
21 * @return stdClass|array|bool
22 * @throws Exception
23 */
24 public function getAll(int $object_detail_level=1): stdClass|array|bool
25 {
26 $response = $this->connection->query('channel.list', [
27 'object_detail_level' => $object_detail_level,
28 ]);
29
30 if(!is_bool($response)) {
31 return $response->list;
32 }
33
34 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
35 }
36
37 /**
38 * Get a channel object
39 *
40 * @return stdClass|array|bool
41 */
42 public function get(string $channel, int $object_detail_level=3): stdClass|array|bool
43 {
44 $response = $this->connection->query('channel.get', [
45 'channel' => $channel,
46 'object_detail_level' => $object_detail_level,
47 ]);
48
49 if (!is_bool($response)) {
50 return $response->channel;
51 }
52 return false; /* eg user not found */
53 }
54
55 /**
56 * Set and unset modes on a channel.
57 *
58 * @return stdClass|array|bool
59 */
60 public function set_mode(string $channel, string $modes, string $parameters): stdClass|array|bool
61 {
62 return $this->connection->query('channel.set_mode', [
63 'channel' => $channel,
64 'modes' => $modes,
65 'parameters' => $parameters,
66 ]);
67 }
68
69 /**
70 * Set the channel topic.
71 *
72 * @return stdClass|array|bool
73 */
74 public function set_topic(string $channel, string $topic,
75 string $set_by=null, string $set_at=null): stdClass|array|bool
76 {
77 return $this->connection->query('channel.set_topic', [
78 'channel' => $channel,
79 'topic' => $topic,
80 'set_by' => $set_by,
81 'set_at' => $set_at,
82 ]);
83 }
84
85 /**
86 * Kick a user from the channel.
87 *
88 * @return stdClass|array|bool
89 */
90 public function kick(string $channel, string $nick, string $reason): stdClass|array|bool
91 {
92 return $this->connection->query('channel.kick', [
93 'nick' => $nick,
94 'channel' => $channel,
95 'reason' => $reason,
96 ]);
97 }
98 }