{"id":16804063,"url":"https://github.com/cmhopesunshine/nonebot-plugin-learning-chat","last_synced_at":"2025-04-09T09:04:26.474Z","repository":{"id":65153788,"uuid":"584668244","full_name":"CMHopeSunshine/nonebot-plugin-learning-chat","owner":"CMHopeSunshine","description":"Nonebot2插件，让Bot学习群友的发言和表情包。/ Nonebot2 plugin to learn what your group members say.","archived":false,"fork":false,"pushed_at":"2023-08-27T03:06:47.000Z","size":113,"stargazers_count":174,"open_issues_count":18,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T07:59:54.827Z","etag":null,"topics":["amis","chat","chatbot","nonebot2","onebot","python","qqbot"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CMHopeSunshine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-03T07:51:57.000Z","updated_at":"2025-03-25T02:13:42.000Z","dependencies_parsed_at":"2024-10-26T21:13:33.030Z","dependency_job_id":"4cd461b5-e4c7-4e63-82db-e923bb392d73","html_url":"https://github.com/CMHopeSunshine/nonebot-plugin-learning-chat","commit_stats":{"total_commits":26,"total_committers":1,"mean_commits":26.0,"dds":0.0,"last_synced_commit":"bf4acb360c1d9d1140b87a436cf21082091d5e8a"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CMHopeSunshine%2Fnonebot-plugin-learning-chat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CMHopeSunshine%2Fnonebot-plugin-learning-chat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CMHopeSunshine%2Fnonebot-plugin-learning-chat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CMHopeSunshine%2Fnonebot-plugin-learning-chat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CMHopeSunshine","download_url":"https://codeload.github.com/CMHopeSunshine/nonebot-plugin-learning-chat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008629,"owners_count":21032556,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amis","chat","chatbot","nonebot2","onebot","python","qqbot"],"created_at":"2024-10-13T09:44:06.718Z","updated_at":"2025-04-09T09:04:26.456Z","avatar_url":"https://github.com/CMHopeSunshine.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://v2.nonebot.dev/store\"\u003e\u003cimg src=\"https://github.com/A-kirami/nonebot-plugin-template/blob/resources/nbp_logo.png\" width=\"180\" height=\"180\" alt=\"NoneBotPluginLogo\"\u003e\u003c/a\u003e\n  \u003cbr\u003e\n  \u003cp\u003e\u003cimg src=\"https://github.com/A-kirami/nonebot-plugin-template/blob/resources/NoneBotPlugin.svg\" width=\"240\" alt=\"NoneBotPluginText\"\u003e\u003c/p\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n# nonebot-plugin-learning-chat\n\n_✨ 让Bot学习群友的发言和表情包! ✨_\n\n\u003ca href=\"./LICENSE\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/license/CMHopeSunshine/nonebot-plugin-learning-chat.svg\" alt=\"license\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://pypi.python.org/pypi/nonebot-plugin-learning-chat\"\u003e\n    \u003cimg src=\"https://img.shields.io/pypi/v/nonebot-plugin-learning-chat.svg\" alt=\"pypi\"\u003e\n\u003c/a\u003e\n\u003cimg src=\"https://img.shields.io/badge/python-3.8+-blue.svg\" alt=\"python\"\u003e\n\n\u003c/div\u003e\n\n## 📖 介绍\n\n一个能够让Bot根据群友的规律性发言，自动选择历史语录或者表情包进行回复的学习插件。\n\n安装完本插件后并不会马上有效果，需要给Bot一段时间积累群聊记录。\n\n学到一定程度后，插件就会变成话唠王，~~把群友们的奇怪发言和表情包通通抢过来~~。\n\n本插件还配备了一个`Web UI`后台管理供Bot主人修改配置，支持**分群**配置。\n\n本插件仅适用于`OneBot V11`适配器和**群聊**。\n\n## 💿 安装\n\n在 nonebot2 项目的根目录下打开命令行, 输入以下指令即可安装\n\n```shell\nnb plugin install nonebot-plugin-learning-chat\n```\n\n## ☀️ 指令\n不同于其它的命令式插件，本插件只有2个命令用于在群聊里管理Bot。\n\n|   指令    |             示例              |                         作用                          |\n|:-------:|:---------------------------:|:---------------------------------------------------:|\n| 开启\\关闭学习 | @bot 开启学习\\学说话\\快学\\关闭学习\\别学\\闭嘴 |                开启或关闭该群的学习能力(需艾特机器人)                 |\n|  禁用回复   |      @bot 不可以\\达咩\\不能说这       | 将某句已学会的回复给禁用掉，以后不会再说这句话，需要有管理员权限者艾特机器人并**回复**机器人的发言 |\n\n\n## ✏️ 工作原理\n该插件会将群友们的发言都记录在数据库中，根据群友的规律性发言进行回复。\n\n每当群友有一条新发言时，插件会将本条发言记录为上一条发言的可选回复之一，然后在数据库中查找符合条件的本发言的历史回复，从中选择一条进行回复。\n\n以下为一个简单的例子:\n```\n群友1:诶嘿\n群友2:诶嘿是什么意思啊\n群友1:诶嘿\n群友2:诶嘿是什么意思啊\n群友1:诶嘿\n群友2:诶嘿是什么意思啊\n群友1:诶嘿\n群友2:诶嘿是什么意思啊\n```\n每次有人说`诶嘿`时，就有人说`诶嘿是什么意思啊`，这组对话就可以看作**规律性发言(表情包同理)**。\n\n`诶嘿是什么意思啊`会被学习为`诶嘿`的回复4次，而`诶嘿`会被学习为`诶嘿是什么意思啊`的回复3次。\n\n在默认配置中，某个回复需要学习次数达到**4**次后才会将其列为可选答案之一。\n\n因此以后当有群友说`诶嘿`时，插件就会从数据中查找所以学习次数大于4的回复，发现目前有`诶嘿是什么意思啊`一种，就会有概率回复`诶嘿是什么意思啊`。\n\n简而言之，本插件就是一个高级一点的复读姬和QA问答人，如果你的群友没有明显的规律性发言，本插件的效果可能会比较差。\n\n## ✨ 其他功能\n\n插件还具备复读和主动发言的功能。\n\n### 复读\n顾名思义，就是复读。当群友复读达到一定次数时(默认为3)，插件就会跟着复读。\n\n以下情况即使达到次数也不会跟随复读:\n- 复读的信息是被ban了的或者过短的\n- 复读的人是被ban了的或者全都为同一个人在复读\n- 达到次数所花费的时间太长(超过一个小时)\n\n### 主动发言\n每隔一分钟，插件就会对群聊热度进行一次排行，从中选取一个群，随机发送一条或多条该群的历史发言。\n\n当日内越活跃的群，就越容易在群**冷场**后触发主动发言来~~发癫~~暖场。\n\n主动发言条件：\n- 该群配置中允许主动发言\n- 该群今日消息数量超过**30**条\n- 该群最新一条消息不是bot发的\n- 该群上次主动发言的时间距今已超过配置中的**主动发言最小阈值**)\n- 该群已沉默的时间大于设定的阈值(阈值计算方式：**该群平均发送消息秒数*****配置中的主动发言阈值**)\n  + 例如：某群今日内平均每120秒产生一条消息，配置的主动发言阈值(默认)为5，那么该群在已沉默600秒后插件就会主动发言\n\n主动发言判断成功后，就会从该群的历史聊天记录从随机挑选消息进行发送。\n\n\n## 🔧 配置项\n本插件使用`yml`文件作为配置文件，因为需要做动态修改和分群配置，因此**没有**采用Nonebot的`.env`形式的配置。\n\n`yml`配置文件位于`Bot目录/data/learing_chat/learning_chat.yml`中，不过个人更推荐你使用`Web UI`后台管理来修改配置。\n\n**每个配置项的作用都在后台管理页面中有较为详细的介绍**，这里只列举几个:\n\n\n|  配置项   | 默认值  |          说明           |\n|:------:|:----:|:---------------------:|\n | 群聊学习开关 | true |         顾名思义          |\n|  屏蔽词   | [ ]  |   含有这些词的聊天记录不会进行学习    |\n|  屏蔽用户  | [ ]  |  与这些用户相关的聊天记录不会进行学习   |\n| 跨群回复阈值 |  3   |  N个群均有相同的回复时，则作为全局回复  |\n| 最高学习次数 |  6   |    学习的回复最高能累计到的次数     |\n| 自定义词典  | [ ]  | 添加自定义词语，让分词能够识别未收录的词汇 |\n|  回复阈值  |  4   |   需要学多少次才会作为可选回复之一    |\n|  复读阈值  |  3   |     群友复读多少次后才跟着复读     |\n| 主动发言阈值 |  5   |        主动发言的概率        |\n\n部分配置为全局配置，部分可设置**分群配置**，具体请在后台管理中查看。\n\n## 🔑 后台管理\n本插件提供了一个简易的`Web UI`后台管理，你可以在后台管理中进行:\n- 分群修改配置项\n- 查看群聊聊天记录\n- 查看本插件已学习的内容\n- 对学习的内容进行禁用\n\n`Web UI`默认启用，访问`http://127.0.0.1:nb端口/learning_chat/login`进行登录。\n\n- 默认用户名: `chat`\n- 默认密码: `admin`\n\n登录成功后会跳转至后台管理页面`http://127.0.0.1:nb端口/learning_chat/admin`。\n\n**请在登入之后，修改默认的用户名、密码以及加密所用的token密钥。**\n\n## 👌 其他\n- 可以尝试安装以下包提高插件性能。\n  + `pip install ujson`\n  + `pip install jieba_fast`\n- 打开`DEBUG`级别日志可以查看到插件的学习和回复过程。\n- [小派蒙](https://github.com/CMHopeSunshine/LittlePaimon)中已内置该插件，就不要重复装啦！\n- 如果你喜欢这个项目，欢迎给个star或者[爱发电](https://afdian.net/a/cherishmoon)，十分感谢。\n\n## 💝 鸣谢\n- [Nonebot](https://github.com/nonebot/nonebot2): 本项目的基础，非常好用的聊天机器人框架。\n- [Pallas-Bot](https://github.com/MistEO/Pallas-Bot): 本项目的核心算法源自于牛牛的复读功能，~~基本上就是抄它的~~。\n- [Amis](https://aisuda.bce.baidu.com/amis/zh-CN/docs/index): 本项目后台管理所用的前端框架。","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmhopesunshine%2Fnonebot-plugin-learning-chat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcmhopesunshine%2Fnonebot-plugin-learning-chat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmhopesunshine%2Fnonebot-plugin-learning-chat/lists"}