]>
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 | 39 | */ |
93f8a3ee | 40 | public function get(string $channel): stdClass|array|bool |
8d5a112f | 41 | { |
f979c1e0 | 42 | $response = $this->connection->query('channel.get', ['channel' => $channel]); |
8d5a112f | 43 | |
8d5a112f | 44 | if (!is_bool($response)) { |
13ae2ba6 | 45 | return $response->channel; |
8d5a112f | 46 | } |
31625965 | 47 | return false; /* eg user not found */ |
8d5a112f | 48 | } |
e25853aa BM |
49 | |
50 | /** | |
51 | * Set and unset modes on a channel. | |
52 | * | |
53 | * @return stdClass|array|bool | |
e25853aa BM |
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 | |
e25853aa BM |
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 | |
e25853aa BM |
84 | */ |
85 | public function kick(string $channel, string $nick, string $reason): stdClass|array|bool | |
86 | { | |
87 | return $this->connection->query('user.kick', [ | |
88 | 'nick' => $nick, | |
89 | 'channel' => $channel, | |
90 | 'reason' => $reason, | |
91 | ]); | |
92 | } | |
8d5a112f | 93 | } |