]>
Commit | Line | Data |
---|---|---|
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 | * @throws Exception | |
40 | */ | |
41 | public function get(string $channel): stdClass|array|bool | |
42 | { | |
43 | $response = $this->connection->query('channel.get', ['channel' => $channel]); | |
44 | ||
45 | if (!is_bool($response)) { | |
46 | return $response->channel; | |
47 | } | |
48 | ||
49 | throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); | |
50 | } | |
51 | ||
52 | /** | |
53 | * Set and unset modes on a channel. | |
54 | * | |
55 | * @return stdClass|array|bool | |
56 | * @throws Exception | |
57 | */ | |
58 | public function set_mode(string $channel, string $modes, string $parameters): stdClass|array|bool | |
59 | { | |
60 | return $this->connection->query('channel.set_mode', [ | |
61 | 'channel' => $channel, | |
62 | 'modes' => $modes, | |
63 | 'parameters' => $parameters, | |
64 | ]); | |
65 | } | |
66 | ||
67 | /** | |
68 | * Set the channel topic. | |
69 | * | |
70 | * @return stdClass|array|bool | |
71 | * @throws Exception | |
72 | */ | |
73 | public function set_topic(string $channel, string $topic, | |
74 | string $set_by=null, string $set_at=null): stdClass|array|bool | |
75 | { | |
76 | return $this->connection->query('channel.set_topic', [ | |
77 | 'channel' => $channel, | |
78 | 'topic' => $topic, | |
79 | 'set_by' => $set_by, | |
80 | 'set_at' => $set_at, | |
81 | ]); | |
82 | } | |
83 | ||
84 | /** | |
85 | * Kick a user from the channel. | |
86 | * | |
87 | * @return stdClass|array|bool | |
88 | * @throws Exception | |
89 | */ | |
90 | public function kick(string $channel, string $nick, string $reason): stdClass|array|bool | |
91 | { | |
92 | return $this->connection->query('user.kick', [ | |
93 | 'nick' => $nick, | |
94 | 'channel' => $channel, | |
95 | 'reason' => $reason, | |
96 | ]); | |
97 | } | |
98 | } |