一个基于微型IRC的IRC机器人。
lurklite的Python项目详细描述
潜伏岩
luk3yx的“lightweight™”irc和discord bot(不包括命令)。
官方机器人
如果您不能或不想运行自己的bot,您可以请求 官方机器人将添加到您的频道。
官方机器人在以下IRC网络上可用(PM Luk3yx在任何 其中):
- edgyirc:潜伏
- 自由节点:潜伏`(或潜伏3)
- xeroxirc:潜伏{em1}$(或潜伏岩)
或者,如果使用discord,则可以使用https://bit.ly/lurkdiscord来 添加潜伏者(没有任何权限)到您的不和谐公会/服务器。
安装
要安装潜伏者,只需使用pip
安装它。
(sudo pip3 install miniirc
在大多数gnu/linux发行版上)。之后
安装时,您应该能够运行lurklite
(或python3 -m lurklite
)。
配置文件
潜伏者配置文件的格式类似于ini
文件。它一定有一个
[core]
具有以下值的节:
[core]# The tempcmd db, commands added with .tempcmd are stored here.# If you have msgpack installed, this database will be slightly smaller and# faster to read/write to/from.command_db=/path/to/tempcmd/database# The bot's command prefix.prefix=.# (Optional) A list of hostmasks to ignore.# ignored = *!*@*/bot/*, baduser!*@*# (Optional) Disable "Yay!" and "Ouch." replies.# disable_yay = false# disable_ouch = false
连接到IRC服务器
然后可以创建以irc.
开头的节(例如irc.freenode
)
要连接到IRC服务器:
[irc.freenode]ip=chat.freenode.netport=6697nick=testbotchannels=#botwar,#other-channel# List of hostmasks to ignore (optional)# ignored = *!*@*/bot/*, *!*sopel*@*# List of hostnames for admins# admins = unaffiliated/user
以下可选值可以添加到上述配置中,并发送 直接发送到miniirc:
connect_modes=+gident=identns_identity=username passwordquit_message=Quit messagerealname=realnamessl=true
连接到不协调服务器
您还可以使用 以下配置部分:
[discord]# You need miniirc_discord installed for this to work.token=your-discord-token# admins = userid#1234
每个bot进程只能有一个不一致连接,而潜伏者将使用 如果{{CD9}}存在,则将有更多的RAM,因为{{a5}将被导入 (如果不指定不一致的bot标记,miniirc_discord将不会是 已导入)。
创建命令
一旦你的机器人连接到irc(或discord),你可以使用tempcmd
创建(永久)命令。你也可以
.tempcmd <command> <type> <code>
添加具有集合类型的tempcmd,或
.tempcmd <command> <code>
自动检测类型(只要第一个单词
in<code>
不是有效类型)。
目前,tempcmds.py有一个代码类型/格式列表以及它们的作用。
要删除命令,可以使用tempcmd del/delete/remove <command>
。创造
一个名为del
、delete
或remove
的命令,可以预先设置bot的前缀
到命令名。
创建非“tempcmd”命令
如果希望对命令进行更细粒度的控制,可以添加
custom_cmds
指向config.ini的[core]
部分的行。指定的文件
将加载并可以定义更强大的命令,例如:
# A simple version command# The "requires_admin" parameter is optional and defaults to False.@register_command('version',requires_admin=False)defversion_command(irc,hostmask,is_admin,args):# irc: The miniirc.IRC (or miniirc_discord.Discord) object.# hostmask: The hostmask tuple, mostly from miniirc. Note that relayed# messages (for example "<relayed_user> test") will have a hostmask# similar to ('relayed_user@relay_bot', 'relay_bot_ident',# 'relay.bot.host/relayed/relayed_user').# is_admin: Either `False` or a string with the admin match (for example# a hostmask or Discord tag.# args: ["#channel", "command parameters"]# For PMs, "#channel" will be the sender (hostmask[0]).irc.msg(args[0],miniirc.version)
您无需导入任何内容即可获得register_command
。
如果custom_cmds
是一个目录,则该目录中的所有.py
文件都将是
加载。如果你想要你的自定义命令文件/目录在潜伏者的源代码中
目录,可以命名为custom_cmds.py
(或者,对于目录,custom_cmds
)
或者commands
)使git
忽略它。
内置命令
潜伏者有以下内置命令:
reboot
:重新启动bot。tempcmd
:创建和删除命令。version
:显示minirc版本并退出。
从旧版本的潜伏者迁移
旧版本的潜伏者(v0.1.0之前)使用
repr()
。这是缓慢的,效率低下,因此不再受支持。如果你
还有一个v0.1.0之前的版本tempcmds.db
,您可以运行
tempcmds_migrate.py
将其更新为新的msgpack/json格式。