承接 makeklat00/phergie-irc-plugin-react-chanmodes 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

makeklat00/phergie-irc-plugin-react-chanmodes

Composer 安装命令:

composer require makeklat00/phergie-irc-plugin-react-chanmodes

包简介

Phergie plugin for monitoring and providing access to channel mode information

README 文档

README

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

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

Build Status

Install

The recommended method of installation is through composer.

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

See Phergie documentation for more information on installing and enabling plugins.

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.

Public methods

getChannelUsers

array Plugin::getChannelUsers(\Phergie\Irc\ConnectionInterface $connection, string $channel)

Returns a list of users in a particular channel.

getChannelModeType

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.

getChannelModeFromPrefix

mixed Plugin::getChannelModeFromPrefix(\Phergie\Irc\ConnectionInterface $connection, string $prefix)

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

getPrefixFromChannelMode

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.

getPrefixMap

array Plugin::getPrefixMap(\Phergie\Irc\ConnectionInterface $connection)

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

getUserChannels

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

Returns a list of active channels for a particular user.

getUserPrefixModes

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

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

isUserInChannel

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

Returns whether a user is in a particular channel.

parseChannelModeChange

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

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

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.

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.

  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:

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

License

Released under the BSD License. See LICENSE.

makeklat00/phergie-irc-plugin-react-chanmodes 适用场景与选型建议

makeklat00/phergie-irc-plugin-react-chanmodes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「plugin」 「bot」 「irc」 「react」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 makeklat00/phergie-irc-plugin-react-chanmodes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 makeklat00/phergie-irc-plugin-react-chanmodes 我们能提供哪些服务?
定制开发 / 二次开发

基于 makeklat00/phergie-irc-plugin-react-chanmodes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 22
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-2-Clause
  • 更新时间: 2015-08-13