Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

phergie/phergie-irc-plugin-react-usermode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

phergie/phergie-irc-plugin-react-usermode

Phergie plugin for monitoring and providing access to user mode information.

Build Status

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.

About

Phergie plugin for monitoring and providing access to user mode information

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages