jerodev/php-irc-client

php irc client based on react

dev-master 2019-03-12 11:11 UTC

This package is auto-updated.

Last update: 2024-12-12 23:44:22 UTC


README

Build Status StyleCI Scrutinizer Code Quality

A pure PHP IRC client based on ReactPHP.

🔧 This project is under development and will probably not work in its current state.

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.

Joining a channel

$client->join(string $channel)

Joins a specified channel

Leaving a channel

$client->part(string $channel)

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

Sending messages

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

Sends a message to a channel or user.

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.

Topic changed

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

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

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.

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.

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.