Skip to main content

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

Project description

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_oktemplate_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版本

致谢

Note

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nonbot-plugin-fg2-2.0.0.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nonbot_plugin_fg2-2.0.0-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file nonbot-plugin-fg2-2.0.0.tar.gz.

File metadata

  • Download URL: nonbot-plugin-fg2-2.0.0.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for nonbot-plugin-fg2-2.0.0.tar.gz
Algorithm Hash digest
SHA256 e96018acf69cd4485db41f481c92d7b15bc601c9faa379456fd4742a32b4f68e
MD5 d0c251880ebe7e01f9c3bed209201777
BLAKE2b-256 d3720c8f7019939d35af130e1bd075f20be4bb0994c619edcd4faef608fdf500

See more details on using hashes here.

File details

Details for the file nonbot_plugin_fg2-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: nonbot_plugin_fg2-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for nonbot_plugin_fg2-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 02f4376313a480f922bc644cb42097014f3fbb0bc89682c7446d5351d492b4c7
MD5 8531f24fd194ae63d904257699968324
BLAKE2b-256 5a823e99fbba4dfb8b3c8fbead38708ee15002e19953221c86cdc6c8f7ac8030

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page