nonebot-plugin-FG
简介
一个基于Nonebot2的QQ群每日总结生成插件,可以根据每日的聊天信息生成每日热词
2.0版本的FG将以插件的形式存在
所用技术
首先会获取群内聊天记录进行数据预处理,包括Q号什么的进行数据脱敏。
FG的核心是一个称为TextRank的算法,它源自于Google的PageRank,基本思想采用类似投票机制来找出一篇文章的关键词,这里为了稳定性,所以是调库。
如果想要更深入了解TextRank算法,可以阅读这篇论文《TextRank: Bringing Order into Texts》。同时,我自己也对论文的关键词提取做了实现MyTextRankDemo.py。步骤上基本还原了论文的步骤。对于词组的匹配,由于我是使用结巴分词,可以用户自定义,所以这一步并没有按照论文实现。
自写代码运行效果如下所示:
环境
- Python 3.7+
- nonebot 2
安装
- 使用pip进行安装
pip install nonbot-plugin-fg2
- 然后在bot中加载插件
nonebot.load_plugin('nonebot_plugin_fg')
配置
.env.*配置
以下配置请配置在nonbot项目的.env.*配置文件中:
# 启动定时任务
APSCHEDULER_AUTOSTART=true
# =====FG的配置开始=====
# 插件配置文件存放目录
FG_CONFIG_LOCATION=/path/to/fg/conf/json
# 群聊天记录存放目录前缀
FG_CHATLOG_DIR_PREFIX=/path/to/chatlog/dir/prefix
# 用户自定义字典位置
FG_USER_DICT_LOCATION=/path/to/user/dict/txt
# 用户自定义敏感词位置
FG_USER_SENSITIVE_DICT_LOCATION=/path/to/user/sensitive/words/txt
# =====FG的配置结束=====
FG自身的配置文件
FG使用JSON格式来编写配置文件:
[
{
"group_id": "string", // qq群号
"trigger_hour": "int", // 触发时间(小时)
"trigger_min": "int", // 触发时间(分钟)
"word_num": "int", // 需要展示的热词数量
"word_len": "int", // 单个关键词长度(小于该长度的关键词将不会被展示)
"template_ok": "string", // 有热词时的模版 (热词数量 >= 配置数)
"template_failed": "string" // 没有热词时的模版 (热词数量 < 配置数)
},
...
]
每一个Q群是一个配置项,整体是一个JSON数组。
在template_ok与template_failed配置项中,有以下规定:
- 使用
\n表示换行- 使用
${word}表示一个热词的填充位置- 使用
${begin_time}表示记录开始时间- 使用
${end_time}表示记录结束时间
下面是一个配置例子:
[
{
"group_id": "123456",
"trigger_hour": 23,
"trigger_min": 0,
"word_num": 2,
"word_len": 3,
"template_ok": "大家好,我是FG~\n本次产生热词的时间范围为:${begin_time}~${end_time}\n热词为:\n${word}\n${word}",
"template_failed": "今天群里不够热闹哦~"
}
]
自定义词典配置
用户可以设置自定义词典,来避免一些专有词被分词工具分割的情况。
例如:三体人是一整个词,如果不使用自定义词典,那么可能被分词工具分割成三体和人两个词,这是不合适的。
自定义词典的格式如下:
终产者 n // 空格前为词名,空格后为词性,由于关键词一般是名词,所以使用n(noun)
自定义敏感词配置
有时候我们可能不想某些词出现在最终的结果中,这些词可能是违规的,可能导致bot被封禁。因此,需要有自定义的敏感词配置。敏感词被放置在一个txt文本文件中,每一个词占一行
XXOO
是更
ScreenShots
修订日志
- 2022.01.29 0.1版本
致谢
- 机器人-丹尼尔·奥利瓦
- 来福
- -禾呈-
- 部分代码修改自TextRank4ZH
Note
FG也即Fifth Generation,第五代超级计算机,灵感来自于刘慈欣长篇科幻,《超新星纪元》
Metadata
Release files for nonbot-plugin-fg2 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nonbot-plugin-fg2-2.0.0.tar.gz | 18.3 kB | Without provenance | Details for nonbot-plugin-fg2-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nonbot_plugin_fg2-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for nonbot_plugin_fg2-2.0.0-py3-none-any.whl |
Total release size: 39.4 kB
Release files / nonbot-plugin-fg2-2.0.0.tar.gz
| Download URL | nonbot-plugin-fg2-2.0.0.tar.gz |
|---|---|
| Size | 18.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e96018acf69cd4485db41f481c92d7b15bc601c9faa379456fd4742a32b4f68e
|
|
BLAKE2b-256 checksum How to use checksums |
d3720c8f7019939d35af130e1bd075f20be4bb0994c619edcd4faef608fdf500
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.1
|
Release files / nonbot_plugin_fg2-2.0.0-py3-none-any.whl
| Download URL | nonbot_plugin_fg2-2.0.0-py3-none-any.whl |
|---|---|
| Size | 21.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
02f4376313a480f922bc644cb42097014f3fbb0bc89682c7446d5351d492b4c7
|
|
BLAKE2b-256 checksum How to use checksums |
5a823e99fbba4dfb8b3c8fbead38708ee15002e19953221c86cdc6c8f7ac8030
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.1
|
Security for nonbot-plugin-fg2 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.