X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-rpc-php.git/blobdiff_plain/8d5a112fcee232ec3d3b57457a5fbbdf393c49fe..94e1459d52b429e3e5d43d36fabada6d0801bdc5:/lib/Channel.php diff --git a/lib/Channel.php b/lib/Channel.php index c969467..7a6a68e 100644 --- a/lib/Channel.php +++ b/lib/Channel.php @@ -3,60 +3,96 @@ namespace UnrealIRCd; use Exception; +use stdClass; -class Channel implements Contracts\User +class Channel { public Connection $connection; - public function __construct(string $uri, string $api_login, array $options) + public function __construct(Connection $conn) { - $this->connection = new Connection($uri, $api_login, $options); + $this->connection = $conn; } /** * Return a list of channels users. * + * @return stdClass|array|bool * @throws Exception */ - public function get(): array + public function getAll(int $object_detail_level=1): stdClass|array|bool { - $id = random_int(100, 1000); - - $response = $this->connection->query($id, 'channel.list'); - - if($id !== $response->id) { - throw new Exception('Invalid ID. This is not the expected reply.'); - } + $response = $this->connection->query('channel.list', [ + 'object_detail_level' => $object_detail_level, + ]); if(!is_bool($response)) { - return $response; + return $response->list; } throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); } /** - * Return a channel object + * Get a channel object * - * @param array $params - * @return object|bool - * @throws Exception + * @return stdClass|array|bool */ - public function show(array $params): object|bool + public function get(string $channel, int $object_detail_level=3): stdClass|array|bool { - $id = random_int(100, 1000); - - $response = $this->connection->query($id, 'channel.get', ['channel' => $params['channel']]); - - if($id !== $response->id) { - throw new Exception('Invalid ID. This is not the expected reply.'); - } + $response = $this->connection->query('channel.get', [ + 'channel' => $channel, + 'object_detail_level' => $object_detail_level, + ]); if (!is_bool($response)) { - return $response; + return $response->channel; } + return false; /* eg user not found */ + } - throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); + /** + * Set and unset modes on a channel. + * + * @return stdClass|array|bool + */ + public function set_mode(string $channel, string $modes, string $parameters): stdClass|array|bool + { + return $this->connection->query('channel.set_mode', [ + 'channel' => $channel, + 'modes' => $modes, + 'parameters' => $parameters, + ]); + } + + /** + * Set the channel topic. + * + * @return stdClass|array|bool + */ + public function set_topic(string $channel, string $topic, + string $set_by=null, string $set_at=null): stdClass|array|bool + { + return $this->connection->query('channel.set_topic', [ + 'channel' => $channel, + 'topic' => $topic, + 'set_by' => $set_by, + 'set_at' => $set_at, + ]); + } + + /** + * Kick a user from the channel. + * + * @return stdClass|array|bool + */ + public function kick(string $channel, string $nick, string $reason): stdClass|array|bool + { + return $this->connection->query('channel.kick', [ + 'nick' => $nick, + 'channel' => $channel, + 'reason' => $reason, + ]); } }