定制 omnicolor/php-irc-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

omnicolor/php-irc-client

最新稳定版本:v1.1.1

Composer 安装命令:

composer require omnicolor/php-irc-client

包简介

PHP IRC client based on React

README 文档

README

A pure PHP IRC client based on ReactPHP.

Documentation

Client

The client is the heart of the library, this object is used to perform all communication between your application and the IRC server. It will manage the connection to the IRC server and has all functions needed to interact with the server.

use Jerodev\PhpIrcClient\IrcClient;

$client = new IrcClient('irc.server:6667', 'Jerodev');
$client->connect();

Connecting to the server

$client->connect()

This function opens the connection to the IRC server. Username has to be set before the connection can be opened.

Sending commands to the server

$client->send(string $command)

Sends a raw IRC command directly to the server. This method should only be used if you really know what you are doing, it is recommended to use the built-in functions below.

Name Type Description
$command string The raw irc command

Joining a channel

$client->join(string $channel)

Joins a specified channel

Name Type Description
$channel string The name of the channel to join.

Leaving a channel

$client->part(string $channel)

Leave a channel. If the specified channel has not yet been joined, nothing will happen.

Name Type Description
$channel string The name of the channel to part.

Sending messages

$client->say(string $target, string $message)

Sends a message to a channel or user.

Name Type Description
$target string A name of a channel staring with # or the nickname of the user to send a message to.
$message string The message to send to the target.

Events

The on() function on the client can be used to register to several different events. This can be done both before and after connecting to the IRC server. Events have variable callback arguments, all are described below.

Registered on server

$client->on('registered', function () { });

Emitted when the server sends the initial welcome message (001). This indicates that you are connected to the server.

Message of the day

$client->on('motd', function (string $motd) { });

Emitted when the server sends the message of the day to the client. If the message of the day is multiple lines, this event might be emitted multiple times.

Name Type Description
$motd string The server's Message Of The Day.

Topic changed

$client->on('topic', function (string $channel, string $topic) { });

Emitted when joining a channel or when the topic of a joined channel changes.

Name Type Description
$channel string The channel where the topic has changed.
$topic string The new topic for this channel.

Channel users received

$client->on('names', function (string $channel, string[] $nicks) { });

Emitted when the server sends a list of nicks for a channel. This happens immediately after joining a channel and on request.

Name Type Description
$channel string The channel name.
$names string[] A list of nicknames who are currently in this channel.

You can also specify the channel you want to listen on by adding #channel to the event.
For example: $client->on('names#channel', function ($names) {})

Message received

$client->on('message', function (string $from, IrcChannel $channel, string $message) { });

Emitted when a message is sent to a connected channel.

Name Type Description
$from string The nickname of the user who sent the message.
$channel IrcChannel The channel where the message was sent.
$message string The received message.

You can also specify the channel you want to listen on by adding #channel to the event.
For example: $client->on('message#channel', function ($from, $channel, $message) {})

Ping received

$client->on('ping', function () { });

Emitted when the server sends a ping request to the client. The pong request has already been sent back to the server before this event is emitted.

统计信息

  • 总下载量: 5.83k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-28