phergie / phergie-irc-plugin-react-usermode
Phergie plugin for monitoring and providing access to user mode information
Requires
Requires (Dev)
- phake/phake: 2.0.0-beta2
- phpunit/phpunit: 4.1.*
This package is not auto-updated.
Last update: 2020-03-20 16:11:03 UTC
README
Phergie plugin for monitoring and providing access to user mode information.
Install
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.
Configuration
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.
Usage
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 // ... } }
Tests
To run the unit test suite:
curl -s https://getcomposer.org/installer | php
php composer.phar install
./vendor/bin/phpunit
License
Released under the BSD License. See LICENSE
.