thirdplace/irc
Composer 安装命令:
composer require thirdplace/irc
包简介
IRC library and client (bot)
README 文档
README
A very basic IRC library and client (bot).
For hobby purposes, not production ready.
Unclear if the network code is any good.
Tutorial
Install:
composer require thirdplace/irc:dev-main
Examples:
// non-tls
$config = [
'server' => 'irc.libera.chat',
'protocol' => 'tcp',
'port' => 6667,
'nick' => 'botson45',
'channels' => ['#test'],
];
$client = new \Thirdplace\Irc\Client($config);
$client->start();
// tls
$libera = [
'server' => 'irc.libera.chat',
'protocol' => 'tls',
'port' => 6697,
'nick' => 'botson45',
'channels' => ['#test'],
];
$client = new \Thirdplace\Irc\Client($config);
$client->start();
// tls with SASL authentication
$libera2 = [
'server' => 'irc.libera.chat',
'protocol' => 'tls',
'port' => 6697,
'nick' => 'botson45',
'user' => 'botson45',
'auth' => 'sasl',
'password' => 'REPLACE ME',
'channels' => ['#test'],
];
$client = new \Thirdplace\Irc\Client($config);
$client->start();
// tls with twitch authentication (oauth)
$twitch = [
'server' => 'irc.chat.twitch.tv',
'protocol' => 'tls',
'port' => 6697,
'nick' => 'botson45',
'auth' => 'twitch',
'token' => 'REPLACE ME',
'channels' => ['#hasanbi'],
];
$client = new \Thirdplace\Irc\Client($config);
$client->start();
Run unit tests:
./vendor/bin/phpunit --bootstrap=vendor/autoload.php ./test
How-to
How to create a command
// Respond to !hello command with 'world'
$client->addHandler(function(Client $client, Message $message) {
if (
$message->isChannelMessage()
&& preg_match('/^!hello/', $message->getMessageParameter())
) {
$client->write($message->reply('world'));
}
});
How to run handler each 10 seconds
// Write a tick message to #test3 each 10 seconds
$client->addTickHandler(10, function(Client $client) {
$client->write(Message::privmsg('#test3', 'tick!'));
});
How to send raw text to server
Create client wite pipe_file config:
$config = [
'server' => 'irc.libera.chat',
'protocol' => 'tcp',
'port' => 6667,
'nick' => 'botson45',
'channels' => ['#test3'],
'pipe_file' => '/tmp/irc',
];
$client = new \Thirdplace\Irc\Client($config);
$client->start();
Write to it from shell:
echo "PRIVMSG #test3 :hello world" > /tmp/irc
Explanation
The code base is small. Start with src/Client.php to get a feel.
The majority of the irc logic is in Message.php. The client is in Client.php.
The src/handlers folder contains code to be invoked based off of passing irc messages.
Reference
Client config:
$defaults = [
'server' => 'irc.libera.chat',
'protocol' => 'tls', // ['tcp', 'tls']
'port' => 6697,
'auth' => null, // [null, 'nickserv', 'sasl', 'twitch']
'nick' => null,
'user' => null,
'password' => null, // for NickServer or SASL
'token' => null, // oauth auth token (twitch.tv et al)
'channels' => [], // List of channels to join
'pipe_file' => null, // Write raw text to server
];
Handler interface:
interface Handler
{
public function __invoke(Client $client, Message $message): void;
}
Base exception:
final class IrcException extends \Exception
{
}
thirdplace/irc 适用场景与选型建议
thirdplace/irc 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 131 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 07 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「irc」 「ircv3」 「1489」 「rfc1489」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 thirdplace/irc 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 thirdplace/irc 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 thirdplace/irc 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Small utility to connect with an irker service.
Your self hosted service for twitch web-based overlays and custom bot with Laravel.
Phergie IRC bot plugin to calculate
IRC bot for li3.
IRC client library built on React
Phergie plugin for automatically rejoining IRC channels on PART or KICK event.
统计信息
- 总下载量: 131
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2023-07-06