]>
Commit | Line | Data |
---|---|---|
8d5a112f D |
1 | <?php |
2 | ||
3 | namespace UnrealIRCd; | |
4 | ||
5 | use Exception; | |
80bc3098 | 6 | use stdClass; |
8d5a112f | 7 | |
78796043 | 8 | class Channel |
8d5a112f D |
9 | { |
10 | ||
11 | public Connection $connection; | |
12 | ||
7c7017a2 | 13 | public function __construct(Connection $conn) |
8d5a112f | 14 | { |
7c7017a2 | 15 | $this->connection = $conn; |
8d5a112f D |
16 | } |
17 | ||
18 | /** | |
19 | * Return a list of channels users. | |
20 | * | |
93f8a3ee | 21 | * @return stdClass|array|bool |
8d5a112f D |
22 | * @throws Exception |
23 | */ | |
93f8a3ee | 24 | public function getAll(): stdClass|array|bool |
8d5a112f | 25 | { |
267b314e | 26 | $response = $this->connection->query('channel.list'); |
8d5a112f | 27 | |
8d5a112f | 28 | if(!is_bool($response)) { |
93f8a3ee | 29 | return $response->list; |
8d5a112f D |
30 | } |
31 | ||
32 | throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); | |
33 | } | |
34 | ||
35 | /** | |
7c7017a2 | 36 | * Get a channel object |
8d5a112f | 37 | * |
93f8a3ee | 38 | * @return stdClass|array|bool |
8d5a112f D |
39 | * @throws Exception |
40 | */ | |
93f8a3ee | 41 | public function get(string $channel): stdClass|array|bool |
8d5a112f | 42 | { |
f979c1e0 | 43 | $response = $this->connection->query('channel.get', ['channel' => $channel]); |
8d5a112f | 44 | |
8d5a112f D |
45 | if (!is_bool($response)) { |
46 | return $response; | |
47 | } | |
48 | ||
49 | throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); | |
50 | } | |
e25853aa BM |
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 | } | |
8d5a112f | 98 | } |