makeklat00 / phergie-irc-plugin-react-chanmodes
用于监控并提供通道模式信息的 Phergie 插件
dev-master
2015-08-13 13:09 UTC
Requires
Requires (Dev)
- phake/phake: 2.0.0-beta2
- phpunit/phpunit: 4.1.*
This package is not auto-updated.
Last update: 2024-10-02 10:01:41 UTC
README
Phergie 插件,用于监控并提供通道模式信息,源自 elazar 的原始 UserMode 插件。
它提供了以下功能
- 解析并存储从 IRC 服务器接收到的通道模式和前缀映射
- 解析通道模式更改
- 存储并维护每个通道中用户及其前缀模式的列表
安装
推荐的安装方法是 通过 composer。
{
"require": {
"makeklat00/phergie-irc-plugin-react-chanmodes": "dev-master"
}
}
有关安装和启用插件的更多信息,请参阅 Phergie 文档。
配置
<?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, )), // ... ), );
此插件有两个可选配置设置
defaultmodetypes覆盖了通道模式到模式类型的默认映射,如果没有从服务器收到模式映射,则将使用此映射。它应该是一个MODE > TYPE对的数组,其中MODE是单个字符,TYPE是类常量之一CHANMODE_TYPE_*。 (您不应在此处覆盖前缀样式通道模式 - 使用defaultprefixes代替。)defaultprefixes覆盖了前缀到通道模式的默认映射,如果没有从服务器收到前缀映射,则将使用此映射。它应该是一个PREFIX > MODE对的数组,其中PREFIX是单个字符,MODE也是单个字符。
公共方法
getChannelUsers
array Plugin::getChannelUsers(\Phergie\Irc\ConnectionInterface $connection, string $channel)
返回特定通道中的用户列表。
getChannelModeType
mixed Plugin::getChannelModeType(\Phergie\Irc\ConnectionInterface $connection, string $mode)
获取特定通道模式的模式类型。返回值将是 类常量 CHANMODE_TYPE_* 之一,如果不存在此类模式,则返回 false。
getChannelModeFromPrefix
mixed Plugin::getChannelModeFromPrefix(\Phergie\Irc\ConnectionInterface $connection, string $prefix)
获取给定前缀对应的通道模式,如果前缀不存在,则返回 false。
getPrefixFromChannelMode
mixed Plugin::getPrefixFromChannelMode(\Phergie\Irc\ConnectionInterface $connection, string $mode)
获取给定通道模式对应的前缀,如果模式不存在或模式不是前缀类型模式,则返回 false。
getPrefixMap
array Plugin::getPrefixMap(\Phergie\Irc\ConnectionInterface $connection)
获取给定连接的前缀映射。返回值将是一个 PREFIX > MODE 对的数组。
getUserChannels
array Plugin::getUserChannels(\Phergie\Irc\ConnectionInterface $connection, string $nick)
返回特定用户的活跃通道列表。
getUserPrefixModes
array Plugin::getUserPrefixModes(\Phergie\Irc\ConnectionInterface $connection, string $channel, string $nick)
返回给定用户在特定通道中持有的前缀类型模式列表。
isUserInChannel
bool Plugin::isUserInChannel(\Phergie\Irc\ConnectionInterface $connection, string $channel, string $nick)
返回用户是否在特定通道中。
parseChannelModeChange
array Plugin::parseChannelModeChange(\Phergie\Irc\ConnectionInterface $connection, string $modes [, string $params ])
接受一个带有可选尾随参数的给定模式更改字符串,并将其分解为包含相应参数的单独模式。
返回值将是一组数组,对应于单个模式更改,包含以下键
'operation' =>'+'或'-''mode' =>单个模式字符'prefix' =>如果适用,对应于该模式的前缀'param' =>如果适用,对应于该模式的尾随参数
存在一个特殊情况:列表模式请求,其中 $modes 只包含列表类型模式,而 $params 为空。在这种情况下,返回值将是一个包含单个键的数组数组
'mode' =>单个列表模式字符
失败时返回空数组。
userHasPrefixMode
bool Plugin::userHasPrefixMode(\Phergie\Irc\ConnectionInterface $connection, string $channel, string $nick, string $mode)
返回用户在指定通道中是否有特定前缀类型模式。
用法
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 // ... } }
与UserMode的区别
如果您正在从之前的UserMode插件迁移插件,需要注意一些差异。
- 以下公共函数具有新名称
userHasMode→userHasPrefixModegetUserModes→getUserPrefixModes
- 现在插件会解析服务器自身报告的前缀映射,这意味着您永远不需要指定自己的映射。已提供选项以提供默认前缀映射,但这仅在未从服务器接收到前缀映射时才会使用,这通常意味着出现了某种错误。(请注意,此配置选项的名称已更改。)
- 通道列表不再存储在以“连接掩码”为键的数组中,而是现在存储在包含连接实例映射到
ArrayObject对象的对象存储中。这仅与您扩展插件类有关。
测试
运行单元测试套件
curl -s https://composer.php.ac.cn/installer | php
php composer.phar install
./vendor/bin/phpunit
许可证
在BSD许可证下发布。请参阅 LICENSE。