python中的可插入irc-bot框架
pinhook的Python项目详细描述
挂钩
|支持的python版本包许可证pypi包格式| |包装开发状态来自Tilde.Town的爱
用于irc bots和twitch bots的可插入python框架
安装
创建irc bot<;创建irc bot>;
\uu来自配置文件
来自python文件<;来自python文件>;
\uu
创建抽搐机器人<;创建抽搐机器人>;
\uu创建插件<;创建插件>;
\uu示例<;示例>;
安装
pinhook可以从pypi安装:
代码::bash
pip安装销钩
创建IRC bot
可以使用命令行工具初始化pinhook bot 使用配置文件,或者通过将其导入到python文件来扩展 基类。
从配置文件
Pinhook supports configuration files in YAML, TOML, and JSON formats.
Example YAML config:
.. code:: YAML
nickname: "ph-bot"
server: "irc.somewhere.net"
channels:
- "#foo"
- "#bar"
Required configuration keys:
- ``nickname``: (string) nickname for your bot
- ``server``: (string) server for the bot to connect
- ``channels``: (array of strings) list of channels to connect to once
connected
Optional keys:
- ``port``: (default: ``6667``) choose a custom port to connect to the
server
- ``ops``: (default: empty list) list of operators who can do things
like make the bot join other channels or quit
- ``plugin_dir``: (default: ``"plugins"``) directory where the bot
should look for plugins
- ``log_level``: (default: ``"info"``) string indicating logging level.
Logging can be disabled by setting this to ``"off"``
- ``ns_pass``: this is the password to identify with nickserv
- ``server_pass``: password for the server
- ``ssl_required``: (default: ``False``) boolean to turn ssl on or off
Once you have your configuration file ready and your plugins in place,
you can start your bot from the command line:
.. code:: bash
pinhook config.yaml
Pinhook will try to detect the config format from the file extension,
but the format can also be supplied using the ``--format`` option.
.. code:: bash
$ pinhook --help
Usage: pinhook [OPTIONS] CONFIG
Options:
-f, --format [json|yaml|toml]
--help Show this message and exit.
From Python File
要创建bot,只需使用以下命令创建一个python文件:
代码::python
从pinhook.bot导入bot
bot=机器人( 频道=['foo','bar'], 昵称'ph-bot', 服务器='irc.freenode.net' ) bot.start()
这将启动一个基本的机器人,并在"插件"中寻找插件 添加功能的目录。
可选参数为:
端口
:(默认值:6667
)选择要连接到 服务器ops
:(默认值:空列表)可以执行操作的操作员列表 比如让机器人加入其他频道或退出plugin目录(默认值:
"plugins"
)bot所在的目录 应该寻找插件日志级别
:(默认值:"info"
)表示日志级别的字符串。 将此设置为"关闭"可以禁用日志记录ns_pass
:这是用于标识nickserv的密码服务器密码
:服务器密码ssl-required
:(默认值:false
)启用或禁用ssl的布尔值
创建抽搐机器人
Pinhook有一种直接连接到抽搐通道的烘焙方式
代码::python
从pinhook.bot导入twitchbot
机器人=旋转机器人( 昵称'ph-bot', 频道="频道", token='super-secret-oauth-token' ) bot.start()
这个函数的选项要少得多,因为服务器、端口和ssl 已由Twitch处理。
可选参数为:
操作
插件目录
日志级别
IRC和Twitch的这些选项都相同
创建插件
有两种类型的插件,命令和侦听器。仅限命令 如果消息以命令字开头,则激活,而侦听器 接收所有消息并由插件进行最大限度的分析 灵活性。
在您选择的plugins目录中(默认为plugins)创建一个python
带有函数的文件。您可以使用@pinhook.plugin.register
decorator
创建命令插件,或@pinhook.plugin.listener
创建
听众。
函数的结构如下:
代码::python
导入pinhook.plugin
@pinhook.plugin.register('!测试" def test_插件(msg): 消息='{}:这是一个测试!'.格式(msg.nick) 返回pinhook.plugin.message(消息)
函数需要接受单个参数才能接受
消息
来自机器人的对象。
消息
对象具有以下属性:
cmd
:(对于命令插件)触发 功能nick
:触发命令的用户arg
:(对于命令插件)在 命令。这是什么您将用于获取的可选信息 命令文本
:(对于侦听器插件)消息的整个文本频道
:启动命令的频道操作
:机器人操作员列表botnick
:机器人的昵称记录器
:bot的记录器实例datetime
:当消息
对象已创建
时间戳
:当消息
对象已创建bot
:初始化的bot类
它还包含以下IRC功能:
privMsg
:向任意频道或用户发送消息操作
:与privmsg相同,但执行CTCP操作。(即,/me做一件事
)通知
:发送通知
您可以选择使用@pinhook.plugin.ops
装饰符来表示
命令只能由bot操作执行。
- 如果指定可选的第二个参数,则将显示 当非op尝试执行命令时
函数的结构如下:
代码::python
@pinhook.plugin.register('!测试" @pinhook.plugin.ops('!测试','只有操作才能运行此命令!') def test_插件(msg): return pinhook.plugin.message('这是由op运行的!')
plugin函数可以返回下列值之一,以便 对命令的响应:
pinhook.plugin.message
:频道where命令中的基本消息 已触发pinhook.plugin.action
:频道where命令中的ctcp action 被触发(基本上就像使用/me做一件事
)
示例
下面的examples
目录中有一些基本示例
存储库。
下面是使用pinhook的实时机器人列表:
pinhook tilde<;https://github.com/archangelic/pinhook tilde>;
。_- tilde.town的有趣机器人adminbot<;https://github.com/tildetown/adminbot>;
管理员助手 bot for tilde.town,提供了一些更改bot的方法 上课以满足您的需要
|支持的python版本图片:https://img.shields.io/pypi/pyversions/pinhook.svg :目标:https://pypi.org/project/pinhook rel="nofollow">https://pypi.org/project/pinhook …|软件包许可证图片:https://img.shields.io/pypi/l/pinhook.svg :目标:https://github.com/archangelic/pinhook/blob/master/license" rel="nofollow">https://github.com/archangelic/pinhook/blob/master/license …| pypi包格式图像:https://img.shields.io/pypi/format/pinhook.svg :目标:https://pypi.org/project/pinhook rel="nofollow">https://pypi.org/project/pinhook …|包开发状态图像:https://img.shields.io/pypi/status/pinhook.svg :目标:https://pypi.org/project/pinhook rel="nofollow">https://pypi.org/project/pinhook …|带着来自tilde.town的爱图片:https://img.shields.io/badge/with%20love%20from tilde%20town-e0b0ff.svg :目标:https://tilde.town rel="nofollow">https://tilde.town