Skip to content

omnicolor/php-irc-client

 
 

Repository files navigation

PHP IRC Client

Build Status StyleCI Scrutinizer Code Quality

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.

About

PHP IRC client based on ReactPHP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%