wildphp / irc-messages
IRC messages implementation for WildPHP
Installs: 1 382
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 2
Requires
- php: >=7.2.0
Requires (Dev)
- phpunit/phpunit: ^8
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-11-30 01:50:48 UTC
README
Implementation of various IRC messages designed for WildPHP.
Installation
To install this package, you need Composer.
$ composer require wildphp/irc-messages ^0.1
Usage
These messages can be used standalone without usage of any other utilities. For example:
// Privmsg(string $channel, string $message) $privmsg = new Privmsg('#channel', 'This is a message'); $rawMessage = (string) $privmsg; //: "PRIVMSG #channel :This is a message" + "\r\n"
IncomingMessage
instances may be created from parsed messages, which is useful if you just want a generic
representation of the message. These can be casted into specialized objects if the message type implements IncomingMessageInterface
.
// IncomingMessage(string $prefix, string $verb, array $args) $incoming = new IncomingMessage('nickname!username@hostname', 'PRIVMSG', ['This is a message']); $privmsg = Privmsg::fromIncomingMessage($incoming);
A utility class is provided which tries to find the most appropriate class to specialize messages to.
$incoming = new IncomingMessage('nickname!username@hostname', 'PRIVMSG', ['This is a message']); $privmsg = MessageCaster::castMessage($incoming); // $privmsg is now an object of the Privmsg class.
Numeric messages are stored in the RPL directory under their official name, because PHP does not support numeric class names.
You can use the RplTranslateEnum
class to translate numeric verbs into the corresponding class names.
Make sure to pass the numerics as strings to account for leading zeroes. A numeric like '3' will not be accepted.
$topicClass = RplTranslateEnum::translateNumeric('332'); // $topicClass is now '\WildPHP\Messages\RPL\Topic'
Implemented messages
Messages can be implemented as incoming or outgoing messages.
An incoming message may be converted from an IncomingMessage
class.
An outgoing message may be converted to a string in order to send it to an IRC server.
Contributors
You can see the full list of contributors in the GitHub repository.