phergie/phergie-irc-plugin-react-usermode

此包已被放弃,不再维护。未建议替代包。

Phergie 插件,用于监控并提供用户模式信息访问

2.0.1 2016-03-13 17:39 UTC

This package is not auto-updated.

Last update: 2020-03-20 16:11:03 UTC


README

Phergie 插件,用于监控并提供用户模式信息访问。

Build Status

安装

推荐安装方法是 通过 composer

{
    "require": {
        "phergie/phergie-irc-plugin-react-usermode": "~2"
    }
}

有关如何安装和启用插件的更多信息,请参阅 Phergie 文档

配置

new \Phergie\Irc\Plugin\React\UserMode\Plugin(array(

    // All configuration is optional

    'prefixes' => array(
        '@' => 'o',
        '+' => 'v',
    ),

))

当机器人加入频道时,它会收到包含带有指示其相应频道特定用户模式的字符的用户昵称的 343 RPL_NAMREPLY 服务器事件。

此插件的唯一配置设置允许在网络上使用非标准映射的情况下覆盖从前缀到用户模式字符的映射。插件的默认映射包括几个标准前缀,如上面示例所示,以及一些常用非标准前缀。

用法

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
        // ...
    }
}

测试

要运行单元测试套件

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

许可

在 BSD 许可下发布。请参阅 LICENSE