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