]>
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 | */ | |
34d2c0ee | 24 | public function getAll(int $object_detail_level=1): stdClass|array|bool |
8d5a112f | 25 | { |
34d2c0ee BM |
26 | $response = $this->connection->query('channel.list', [ |
27 | 'object_detail_level' => $object_detail_level, | |
28 | ]); | |
8d5a112f | 29 | |
8d5a112f | 30 | if(!is_bool($response)) { |
93f8a3ee | 31 | return $response->list; |
8d5a112f D |
32 | } |
33 | ||
34 | throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); | |
35 | } | |
36 | ||
37 | /** | |
7c7017a2 | 38 | * Get a channel object |
8d5a112f | 39 | * |
93f8a3ee | 40 | * @return stdClass|array|bool |
8d5a112f | 41 | */ |
34d2c0ee | 42 | public function get(string $channel, int $object_detail_level=3): stdClass|array|bool |
8d5a112f | 43 | { |
34d2c0ee BM |
44 | $response = $this->connection->query('channel.get', [ |
45 | 'channel' => $channel, | |
46 | 'object_detail_level' => $object_detail_level, | |
47 | ]); | |
8d5a112f | 48 | |
8d5a112f | 49 | if (!is_bool($response)) { |
13ae2ba6 | 50 | return $response->channel; |
8d5a112f | 51 | } |
31625965 | 52 | return false; /* eg user not found */ |
8d5a112f | 53 | } |
e25853aa BM |
54 | |
55 | /** | |
56 | * Set and unset modes on a channel. | |
57 | * | |
58 | * @return stdClass|array|bool | |
e25853aa BM |
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 | |
e25853aa BM |
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 | |
e25853aa BM |
89 | */ |
90 | public function kick(string $channel, string $nick, string $reason): stdClass|array|bool | |
91 | { | |
c427a4ef | 92 | return $this->connection->query('channel.kick', [ |
e25853aa BM |
93 | 'nick' => $nick, |
94 | 'channel' => $channel, | |
95 | 'reason' => $reason, | |
96 | ]); | |
97 | } | |
8d5a112f | 98 | } |