Phergie plugin for monitoring and providing access to user mode information.
The recommended method of installation is through composer.
{
"require": {
"phergie/phergie-irc-plugin-react-usermode": "~2"
}
}
See Phergie documentation for more information on installing and enabling plugins.
new \Phergie\Irc\Plugin\React\UserMode\Plugin(array(
// All configuration is optional
'prefixes' => array(
'@' => 'o',
'+' => 'v',
),
))
When the bot joins a channel, it receives a 343 RPL_NAMREPLY
server event
containing user nicks prefixed with characters indicative of their respective
channel-specific user modes.
This plugin's only configuration setting allows this mapping of prefix to user mode characters to be overridden in cases where a network uses non-standard mappings. The plugin's default mapping includes several standard prefixes, which are shown in the example above, and several commonly used non-standard prefixes.
use Phergie\Irc\Bot\React\PluginInterface;
use Phergie\Irc\Bot\React\EventQueueInterface;
use Phergie\Irc\Plugin\React\Command\CommandEvent;
class FooPlugin implements PluginInterface
{
/**
* @var \Phergie\Irc\Plugin\React\UserMode\Plugin
*/
protected $userMode;
public function __construct(array $config)
{
// Validate $config['userMode']
$this->userMode = $config['userMode'];
}
public function getSubscribedEvents()
{
return array(
'command.foo' => 'handleFooCommand',
);
}
public function handleFooCommand(CommandEvent $event, EventQueueInterface $queue)
{
$connection = $event->getConnection();
$nick = $event->getNick();
$params = $event->getParams();
$source = $event->getCommand() === 'PRIVMSG'
? $params['receivers']
: $params['nickname'];
// Ignore events sent directly to the bot rather than to a channel
if ($connection->getNickname() === $source) {
return;
}
// Don't process the command if the user is not a channel operator
if (!$this->userMode->userHasMode($connection, $source, $nick, 'o')) {
return;
}
// The user is a channel operator, continue processing the command
// ...
}
}
To run the unit test suite:
curl -s https://getcomposer.org/installer | php
php composer.phar install
./vendor/bin/phpunit
Released under the BSD License. See LICENSE
.