Nothing special, really.
This is a IRC Client and/or Bot written in PHP. It should be called via the CLI (Command-Line Interface)
Create a new bot instance (Or client, Bot actually has no functionality right now)
$bot = new Irc\Bot( 'MyAwesomeBot', 'irc.example.com' );
and connect it
$bot->connect();
You can listen to some events and react to them
$bot->on( 'chat', function( $e, $bot ) {
$bot->chat( $e->channel, 'Heeeey, youve written something!!' );
} );
Now open a console and fire this thing up
$ php my-bot-file.php
There are a ton of possible events and methods to call on the bot. A tiny documentation of them can be found below.
This thing may have bugs. Actually, it may have a shitload of bugs because I didn't test most of its features. What I know is, that it works. It can connect, it sends events, it can react to them. It can communicate with your IRC server just fine. Everything else is missing development time.
All event callbacks should have 2 parameters
function( $e, $bot )
or
function( $e, $client )
$e
is always an object with some properties that contain event specific data (Event Args)
$client
is always the sender of the event (The Bot/Client, that called it)
Triggers, when the client starts (dis)connecting
Triggers, whent the client is (dis)connected
Triggers, when the client was disconnected by force and tries reconnecting
Triggers permanently in the receive-loop. Actually, don't use this (unless you specified a tickInterval, not recommended)
Triggers, when the client receives any kind of message from the IRC server.
You can access $e->message
to get the message instance, $e->raw
to get the raw message sent.
Command is the actual command send by the IRC server. You can find them here: http://tools.ietf.org/html/rfc2812
Triggers, when the client sends or sent a message (respectively)
Provides $e->message
and $e->raw
Triggers, when someone joins a channel you're in (Including yourself).
Provides $e->nick
and $e->channel
for you to work with.
Same as join, but for leaving a channel (/part)
Provides $e->nick
and $e->channel
.
Same as join/part, but for users getting kicked out of a channel
Provides $e->nick
and $e->channel
.
Received when someone sends a notice (Probably to yourself, so [To] is pretty useless now that I see it...)
Provides $e->from
, $e->to
and $e->text
. Text is the raw string of text the user sent.
Received when someone sends something in a channel.
Provides $e->from
, $e->channel
and $e->text
.
Received when someone sends you a PM. Same as notice actually.
Received when a NAMES request for a channel was finished.
Provides $e->names
contains an object with a names
and a channel
property.
Self-explanatory
Received when a LIST request is finished.
Provides $e->list
which contains an associative array of channels (keys) and channel data (values).
Channel data contains userCount
, topic
and channel
for you to do awesome stuff with it.
Triggers, whent he server recognizes the client and its authentication the first time. This should be your main entry point for everything. Don't send stuff, before you got this event. It works, but it makes no sense.
Triggers, when the client received an ISUPPORT request that contains a bunch of options of the server. The client parses and saves those cleanly for you to do something with it. Some client methods rely on them (isChannel(), isUser() etc.)
Awesome, isn't it?
Now...
These are the methods you can call on your $bot
-Object.
I won't explain all of them, since the method name is somewhat self-explanatory
The client usually cares about pings etc. automatically, you don't need to handle that.
But you can! RawMode disables automatic handling and you can handle everything by yourself.
This also disables some events, such as names, list, welcome, options, notice, pm, chat etc.
The message
event will still work, though.
Gets a server option. Just dump getOptions() once you're connected to see what options there are.
Checks if some value is contained in either they keys of an array option or the values.
Checks, if the nick provided is a channel or a user. This respects received server options.
Does exactly what you think it does
Automatically formats your desired message parameters and sends them to the IRC server.
This is the main communication method.
If you want to send something, send it with this!
e.g. $bot->send( 'PRIVMSG', 'SomeOtherNick', 'Heey, this is a private message. Awesome, isn\'t it? ' )
Some messages require a prefix which is your own user in most cases.
Right now you gotta put this together by yourself.
It's either a hostname (irc.devmonks.net
) or a user (nickName!userName@userHost
)
Join a channel. Eats either one channel string, an array of channels or an associative array with channel names as keys and passwords as values.
Leaves a channel. Can eat either one channel string or an array of channels.
Sends a NAMES request to one or more channels (array of channels if you want more). NAMES replies with some basic channel info, like the users that are in it and their operator status
Same as names(), but can also be called for the whole server.
Just calling $bot->list()
will list all channels on the server.
chat should be used for channels, pm for users, but actually, it doesn't matter at all. This sends a message to either a channel or a user (private message)
Sets a new nick name for the client.
That was it!
If you want to know more about this, you may contact me anytime. Merge requests for new features are welcome.