Skip to main content

nonebot-plugin-FG

简介

一个基于Nonebot2的QQ群每日总结生成插件,可以根据每日的聊天信息生成每日热词

2.0版本的FG将以插件的形式存在

1.0版本请访问:FG

所用技术

首先会获取群内聊天记录进行数据预处理,包括Q号什么的进行数据脱敏。

FG的核心是一个称为TextRank的算法,它源自于Google的PageRank,基本思想采用类似投票机制来找出一篇文章的关键词,这里为了稳定性,所以是调库。

如果想要更深入了解TextRank算法,可以阅读这篇论文《TextRank: Bringing Order into Texts》。同时,我自己也对论文的关键词提取做了实现MyTextRankDemo.py。步骤上基本还原了论文的步骤。对于词组的匹配,由于我是使用结巴分词,可以用户自定义,所以这一步并没有按照论文实现。

自写代码运行效果如下所示:

环境

其他的适配器我没有测过,因为在代码中from nonebot.adapters.onebot.v11.event import GroupMessageEvent,所以感觉如果不用该适配器可能会有问题

安装

  • 使用pip进行安装
pip install nonebot-plugin-fg
  • 然后在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配置项中,有以下规定:

  • 使用\n表示换行
  • 使用${word}表示一个热词的填充位置
  • 使用${begin_time}表示记录开始时间
  • 使用${end_time}表示记录结束时间

至于template_failed配置项,暂时只支持纯文本

下面是一个配置例子:

[
  {
    "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 2.0版本,修复导包问题

致谢

Note

FG也即Fifth Generation,第五代超级计算机,灵感来自于刘慈欣长篇科幻,《超新星纪元》

Metadata

Release files for nonebot-plugin-fg 2.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nonebot-plugin-fg 2.0.2
File Size Uploaded
nonebot-plugin-fg-2.0.2.tar.gz 24.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nonebot-plugin-fg 2.0.2
File Interpreter ABI Platform
nonebot_plugin_fg-2.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 50.0 kB

Release files / nonebot-plugin-fg-2.0.2.tar.gz

Download URL nonebot-plugin-fg-2.0.2.tar.gz
Size 24.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d1a5f2e08d91858c4fe461e702b07829da6a00272fe9da206209807465922d88
BLAKE2b-256 checksum
How to use checksums
495ac96bfcc39ac0012f64ff059ec0ef33a55b58b5a801cd68d54d4d6c95f9cd
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 / nonebot_plugin_fg-2.0.2-py3-none-any.whl

Download URL nonebot_plugin_fg-2.0.2-py3-none-any.whl
Size 26.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7af25c260c6a7ce6318c74383387b9c0e4d56149adfa814943bfdc9b50320e47
BLAKE2b-256 checksum
How to use checksums
61701209456bd499c32aff6ddd677a7d3e0520b84424325964ffab5b0a0f5133
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 history Release notifications | RSS feed

This release

2.0.2 This release

2 release files

2.0.1

2 release files

2.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page