2017 © Pedro Peláez
 

library phergie-irc-plugin-react-chanmodes

Phergie plugin for monitoring and providing access to channel mode information

image

makeklat00/phergie-irc-plugin-react-chanmodes

Phergie plugin for monitoring and providing access to channel mode information

  • Thursday, August 13, 2015
  • by Meroje
  • Repository
  • 3 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

MakeKlat00/phergie-irc-plugin-react-chanmodes

Phergie plugin for monitoring and providing access to channel mode information, forked from the original UserMode plugin by elazar., (*1)

It provides the following functionality: * Parsing and storing the channel mode and prefix maps received from IRC servers * Parsing channel mode changes * Storing and maintaining lists of users and their prefix modes in each channel, (*2)

Build Status, (*3)

Install

The recommended method of installation is through composer., (*4)

{
    "require": {
        "makeklat00/phergie-irc-plugin-react-chanmodes": "dev-master"
    }
}

See Phergie documentation for more information on installing and enabling plugins., (*5)

Configuration

<?php

use \MakeKlat00\Phergie\Irc\Plugin\ChanModes\Plugin as ChanModesPlugin;

$chanModesPlugin = new ChanModesPlugin(array(
    // All optional
    'defaultmodetypes' => array(
        'b' => ChanModesPlugin::CHANMODE_TYPE_LIST,
        't' => ChanModesPlugin::CHANMODE_TYPE_NOPARAM,
        // ...
    ),
    'defaultprefixes' => array(
        '@' => 'o',
        '+' => 'v',
        // ...
    ),
));

return array(

    'connections' => array(
        // ...
    ),

    'plugins' => array(

        $chanModesPlugin,

        new \Plugin\That\Uses\ChanModes\Plugin(array(
            'chanmodes' => $chanModesPlugin,
        )),

        // ...

    ),

);

This plugin has two optional configuration settings: * defaultmodetypes overrides the default mapping of channel modes to mode types, which will be used if no mode map is received from the server. It should be an array of MODE => TYPE pairs, where MODE is a single character and TYPE is one of the class constants CHANMODE_TYPE_*. (You should not override prefix-style channel modes here – use defaultprefixes instead.) * defaultprefixes overrides the default mapping of prefixes to channel modes, which will be used if no prefix map is received from the server. It should be an array of PREFIX => MODE pairs, where PREFIX is a single character and MODE is a single character., (*6)

Public methods

getChannelUsers

``` php array Plugin::getChannelUsers(\Phergie\Irc\ConnectionInterface $connection, string $channel), (*7)

Returns a list of users in a particular channel.

#### getChannelModeType
``` php
mixed Plugin::getChannelModeType(\Phergie\Irc\ConnectionInterface $connection, string $mode)

Get the mode type of a particular channel mode. The return value will be one of the class constants CHANMODE_TYPE_*, or false if no such mode exists., (*8)

getChannelModeFromPrefix

``` php mixed Plugin::getChannelModeFromPrefix(\Phergie\Irc\ConnectionInterface $connection, string $prefix), (*9)

Get the channel mode corresponding to the given prefix, or `false` if the prefix does not exist.

#### getPrefixFromChannelMode
``` php
mixed Plugin::getPrefixFromChannelMode(\Phergie\Irc\ConnectionInterface $connection, string $mode)

Get the prefix corresponding to the given channel mode, or false if the mode does not exist or the mode is not a prefix-type mode., (*10)

getPrefixMap

``` php array Plugin::getPrefixMap(\Phergie\Irc\ConnectionInterface $connection), (*11)

Get the prefix map for the given connection. The return value will be an array of
`PREFIX => MODE` pairs.

#### getUserChannels
``` php
array Plugin::getUserChannels(\Phergie\Irc\ConnectionInterface $connection, string $nick)

Returns a list of active channels for a particular user., (*12)

getUserPrefixModes

``` php array Plugin::getUserPrefixModes(\Phergie\Irc\ConnectionInterface $connection, string $channel, string $nick), (*13)

Returns a list of prefix-type modes held by a given user in a particular channel.

#### isUserInChannel
``` php
bool Plugin::isUserInChannel(\Phergie\Irc\ConnectionInterface $connection, string $channel, string $nick)

Returns whether a user is in a particular channel., (*14)

parseChannelModeChange

``` php array Plugin::parseChannelModeChange(\Phergie\Irc\ConnectionInterface $connection, string $modes [, string $params ]), (*15)

Takes a given mode change string with optional trailing parameters, and separates it into individual modes
with corresponding parameters.

The return value will be an array of arrays corresponding to individual mode changes, containing the following keys:
* `'operation' =>` `'+'` or `'-'`
* `'mode' =>` the individual mode character
* `'prefix' =>` the prefix corresponding to that mode, if applicable
* `'param' =>` the trailing parameter corresponding to that mode, if applicable

There is one special case: a list mode request, where `$modes` contains only list-type modes and `$params` is empty.
In this case, the return value will be an array of arrays which contain a single key:
* `'mode' =>` the individual list mode character

Returns the empty array on failure.

#### userHasPrefixMode
``` php
bool Plugin::userHasPrefixMode(\Phergie\Irc\ConnectionInterface $connection, string $channel, string $nick, string $mode)

Returns whether a user has a particular prefix-type mode in the specified channel., (*16)

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 \MakeKlat00\Phergie\Irc\Plugin\ChanModes\Plugin
     */
    protected $chanModesPlugin;

    public function __construct(array $config)
    {
        // Validate $config['chanmodes']

        $this->chanModesPlugin = $config['chanmodes'];
    }

    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->chanModesPlugin->userHasPrefixMode($connection, $source, $nick, 'o')) {
            return;
        }

        // The user is a channel operator, continue processing the command
        // ...
    }
}

Differences from UserMode

If you are migrating your plugin from the former UserMode plugin, there are some differences to be aware of., (*17)

  1. The following public functions have new names:
    • userHasModeuserHasPrefixMode
    • getUserModesgetUserPrefixModes
  2. The plugin now parses the server's own reported prefix map, meaning that you should never have to specify your own. The option has been made available to provide the default prefix map, but this will only be used if no prefix map is received from the server, which usually means that something's gone wrong. (Note that the name for this config option has changed.)
  3. Channel lists are no longer stored in an array keyed by "connection mask", but are now stored in an object store containing connection instances mapped to ArrayObject objects. This will only be relevant if you are extending the plugin class.

Tests

To run the unit test suite:, (*18)

curl -s https://getcomposer.org/installer | php
php composer.phar install
./vendor/bin/phpunit

License

Released under the BSD License. See LICENSE., (*19)

The Versions

13/08 2015

dev-master

9999999-dev

Phergie plugin for monitoring and providing access to channel mode information

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

plugin bot irc react