leocavalcante / swoole-irc-client
基于Swoole的IRC(互联网中继聊天)客户端
v0.1.0
2020-10-14 19:36 UTC
Requires
- php: >=7.4
- ext-swoole: ^4.5
- monolog/monolog: ^2.1
Requires (Dev)
- pestphp/pest: ^0.3.9
- phpunit/phpunit: ^9.4
- swoole/ide-helper: ^4.5
README
💬 基于 Swoole 的 IRC (Internet Relay Chat) 客户端。
安装
composer require leocavalcante/swoole-irc-client
使用方法
use SwooleIrc\{HandlerInterface, Reply, Client}; class MyHandler implements HandlerInterface { public function onConnect(Client $irc): void {} public function onReply(Reply $reply, Client $irc): void {} } $irc = Client::withHandler(new MyHandler()); $irc->connect($host, $port); $irc->start();
回调处理程序
此库提供了一个方便的方法来传递常规可调用对象,即使您不想创建一个类并实现一个接口也可以。
use SwooleIrc\{Reply, Client, CallbackHandler}; $handler = static function (Reply $reply): void {}; $irc = Client::withHandler(CallbackHandler::reply($handler)) ->connect($host, $port) ->start();
示例
命令
PASS
$irc->pass($password);
NICK
$irc->nick($nickname);
JOIN
$irc->join([$channel]); $irc->join([$channel], [$key]);
PART
$irc->part([$channel]);
PRIVMSG
$irc->privmsg([$channel], $text);
请现在查看源代码以查看所有支持的命令。
并且您始终可以通过实现 MessageInterface
来发送自己的消息,通过 $irc->send(MessageInterface $message)
或使用 $irc->writeln(string $raw)
发送原始行。