21 Commits

Author SHA1 Message Date
XuChenXu
aff02f2666 🔖 2.6.2 2025-02-11 21:10:40 +08:00
XuChenXu
2f725e0808 📌 限制chatrecord到0.7.0以下 2025-02-11 21:07:36 +08:00
XuChenXu
3434a5352f 🔖 Version 2.6.1 2024-12-18 21:06:03 +08:00
XuChenXu
0954eb4f3e ⬆️ 解除python依赖限制 2024-12-18 21:05:18 +08:00
XuChenXu
5b94bc0fff 📝 更新自述文件 2024-11-25 21:42:02 +08:00
XuChenXu
e1a20922c4 🔖 Version 2.6.0 2024-11-25 21:19:14 +08:00
XuChenXu
5e00605dfb 🎨 结构化代码 2024-11-25 21:18:09 +08:00
XuChenXu
833cdb4a75 💄 还是人性化 2024-11-25 21:16:37 +08:00
XuChenXu
29b4598e5f 💄 人性化提示 2024-11-25 21:02:04 +08:00
XuChenXu
10cc5cf278 关键词支持正则 2024-11-25 21:00:00 +08:00
XuChenXu
ed167a56b5 🔖 Version 2.5.2 2024-11-25 20:51:32 +08:00
XuChenXu
b40c7be1f9 🐛 修复转发消息 2024-11-25 20:50:50 +08:00
XuChenXu
07f85be527 🔖 Version 2.5.1 2024-11-24 20:15:43 +08:00
XuChenXu
f2cdfe7f8a 📝 usage 2024-11-24 20:12:32 +08:00
XuChenXu
e0ca7907c0 kkb! 2024-11-24 20:07:42 +08:00
XuChenXu
53b2a33923 合并转发开关! 2024-11-24 19:39:07 +08:00
XuChenXu
4e339bcdb1 🔖 Version 2.4.6 2024-11-20 23:29:39 +08:00
XuChenXu
0b85f6fb34 remove requests 2024-11-20 23:29:23 +08:00
XuChenXu
83d9cda2eb 🥚 Update README.md 2024-11-11 12:56:38 +08:00
XuChenXu
dfde832dba 📝 fix readme 2024-11-10 21:11:58 +08:00
enKl03B
987b34e282 🔀 📝 Update README.md (#44) 2024-11-10 21:03:01 +08:00
8 changed files with 148 additions and 75 deletions

View File

@@ -19,6 +19,7 @@
"pygal", "pygal",
"sqlalchemy", "sqlalchemy",
"timecost", "timecost",
"uninfo",
"userinfo", "userinfo",
"whereclause", "whereclause",
"xaxis", "xaxis",

110
README.md
View File

@@ -26,15 +26,16 @@ nonebot-plugin-dialectlist
## 💿 安装 ## 💿 安装
通过`pip``nb`安装 通过`pip``nb`安装
- 通过 pip 安装
```bash
pip install nonebot-plugin-dialectlist
```
- 通过 nb-cli 安装
```bash
nb plugin install nonebot-plugin-dialectlist
```
>**通过 pip **安装
`pip install nonebot-plugin-dialectlist`
>**通过 nb **安装
`nb plugin install nonebot-plugin-dialectlist`
### ✅ 插件依赖于 ### ✅ 插件依赖于
@@ -53,15 +54,20 @@ nonebot-plugin-dialectlist
在 .env 中,可以添加以下配置项 在 .env 中,可以添加以下配置项
```python ```python
dialectlist__string_format = "第{index}名:\n{nickname},{chatdatanum}条消息、\n" #消息格式 dialectlist__get_num: int = 5 # 获取人数数量
dialectlist__get_num = 10 #获取人数数量 dialectlist__font: str = "SimHei" # 字体格式
dialectlist__visualization = True #是否可视化 dialectlist__suffix: bool = True # 是否显示后缀
# dialectlist__visualization_type = "圆环图" #可视化方案 (不再支持) dialectlist__excluded_self: bool = True # 是否排除自己
dialectlist__font = "SimHei" #字体格式 dialectlist__visualization: bool = True # 是否可视化
dialectlist__excluded_people = [] #排除的人的 QQ 号(或频道号?(未经测试)) dialectlist__show_text_rank: bool = True # 是否显示文本排名
dialectlist__excluded_self = True #是否排除机器人自己 QQ dialectlist__counting_cache: bool = False # 计数缓存(能够提高回复速度)
dialectlist__suffix: bool = False # 是否显示后缀 dialectlist__excluded_people: List[str] = [] # 排除的人的QQ号
dialectlist__string_suffix: str = "统计花费时间{timecost}" # 消息格式后缀 dialectlist__use_user_info_cache: bool = False # 是否使用用户信息缓存
dialectlist__aggregate_transmission: bool = False # 是否聚合转发消息
dialectlist__timezone: Optional[str] = "Asia/Shanghai" # 时区,影响统计时间
dialectlist__string_suffix: str = "统计花费时间:{timecost}秒" # 消息格式后缀
dialectlist__template_path: str = "./template/rank_template.j2" # 模板路径
dialectlist__string_format: str = "第{index}名:\n{nickname},{chatdatanum}条消息\n" # 消息格式
``` ```
💭也可以不进行配置,这将会使插件按照默认配置运行 💭也可以不进行配置,这将会使插件按照默认配置运行
@@ -69,6 +75,8 @@ dialectlist__string_suffix: str = "统计花费时间{timecost}" # 消息格式
> 在旧版插件2.0.0 以下dialectlist 与后面的配置项只隔了一个下划线,若更新到新版本以后需要俩个下划线。 > 在旧版插件2.0.0 以下dialectlist 与后面的配置项只隔了一个下划线,若更新到新版本以后需要俩个下划线。
> 由于插件依赖chatrecord多次引入爆炸性修改建议在遇到问题后优先尝试降级chatrecord插件
## 🗨命令 ## 🗨命令
__注意__ __注意__
新版本指令调用方式改变,改为更易理解也更好打的 B 话榜。 新版本指令调用方式改变,改为更易理解也更好打的 B 话榜。
@@ -76,6 +84,8 @@ __注意__
### 🎨一般用法 ### 🎨一般用法
#### B话榜
-`/B话榜` ————看看有史以来(机器人存在以来)群友们发了多少消息! (好像没写) -`/B话榜` ————看看有史以来(机器人存在以来)群友们发了多少消息! (好像没写)
-`/今日B话榜` ————看看今天的群友发了多少消息! -`/今日B话榜` ————看看今天的群友发了多少消息!
@@ -94,8 +104,14 @@ __注意__
-`/历史B话榜` ————看看历史上(机器人存在以来)的群友发了多少消息! -`/历史B话榜` ————看看历史上(机器人存在以来)的群友发了多少消息!
#### 看看B话kkb
-`/看看B话 [@某人|QQ号]` ————看看这个b人在这个b群发了多少b话
### 🚀进阶用法 ### 🚀进阶用法
#### B话榜
`/{时间类型(今日|年度)?}{B话榜|废话榜} {时间类型?} {ISO8601 格式时间 ?} {群号} {关键词}` `/{时间类型(今日|年度)?}{B话榜|废话榜} {时间类型?} {ISO8601 格式时间 ?} {群号} {关键词}`
如:`/B话榜 历史 2024-01-01~2024-01-02 12345678 女装` 如:`/B话榜 历史 2024-01-01~2024-01-02 12345678 女装`
@@ -108,6 +124,18 @@ __注意__
`/昨日B话榜 -k 女装` `/昨日B话榜 -k 女装`
`/本周B话榜 -g 12345678` `/本周B话榜 -g 12345678`
#### 看看B话
`/看看B话 {@|QQ号} {群号?} {关键词?}`
以下调用方法均合法:
`/kkb 114514 1919810 ♂`
`/kkb @man -k ♂`
> [!IMPORTANT]
> 关键词支持正则表达式!
## 💪 目前支持的平台 ## 💪 目前支持的平台
| 平台 | 是否经过测试 | 是否能够正常工作 | 测试环境 | | 平台 | 是否经过测试 | 是否能够正常工作 | 测试环境 |
@@ -142,6 +170,9 @@ __注意__
</details> </details>
![9c149e99ca747c13892be3f9fbeedf31](https://github.com/user-attachments/assets/d02d108c-1ab3-4ad1-9123-c1a98862e627)
### 💕感谢 ### 💕感谢
本插件的__init__.py 中的处理函数参考了词云中的方法 ~~(其实大部分都是 Ctrl+C Ctr+V~~ 本插件的__init__.py 中的处理函数参考了词云中的方法 ~~(其实大部分都是 Ctrl+C Ctr+V~~
@@ -170,53 +201,10 @@ __注意__
- [x] 查询带某关键词的消息量 - [x] 查询带某关键词的消息量
- [ ] 合并转发 - [x] 合并转发
待补充。..... 待补充。.....
## 📖版本日志
<details>
<summary>点我展开</summary>
### V1.0
- 看看群里群友能有多话痨
### V1.1
- 支持频道咯!(*^_^*)
### V1.2
- 排行榜可视化
### V1.3
- 添加了一些可配置项
### V1.4
- 适配新版本的 chatrecorder, 暂时停止频道支持
### V2.0
- 理论支持全平台!暂停图片支持。
### V2.1
- 恢复图片支持。
### V2.2
- 优化代码,添加一些新的可配置项。
### V2.4
- 添加一些新的可配置项。
</details>
### 👾题外话 ### 👾题外话
~~整个项目快被我写成屎山了~~ ~~整个项目快被我写成屎山了~~

View File

@@ -5,6 +5,7 @@ require("nonebot_plugin_apscheduler")
require("nonebot_plugin_htmlrender") require("nonebot_plugin_htmlrender")
require("nonebot_plugin_userinfo") require("nonebot_plugin_userinfo")
require("nonebot_plugin_alconna") require("nonebot_plugin_alconna")
require("nonebot_plugin_uninfo")
require("nonebot_plugin_cesaa") require("nonebot_plugin_cesaa")
import re import re
@@ -23,13 +24,17 @@ from nonebot.params import Arg, Depends
from nonebot.adapters import Bot, Event from nonebot.adapters import Bot, Event
from nonebot.plugin import PluginMetadata, inherit_supported_adapters from nonebot.plugin import PluginMetadata, inherit_supported_adapters
from nonebot_plugin_alconna import ( from nonebot_plugin_alconna import (
At,
Args, Args,
Field,
Match,
Option, Option,
Alconna, Alconna,
on_alconna, on_alconna,
) )
from nonebot_plugin_chatrecorder import get_message_records from nonebot_plugin_chatrecorder import get_message_records
from nonebot_plugin_session import Session, SessionIdType, extract_session from nonebot_plugin_session import Session, SessionIdType, extract_session
from nonebot_plugin_uninfo import Uninfo
from .storage import get_cache, build_cache from .storage import get_cache, build_cache
from .config import Config, plugin_config from .config import Config, plugin_config
@@ -85,6 +90,63 @@ async def _build_cache(bot: Bot, event: Event):
await saa.Text("重建缓存完成。").send(reply=True) await saa.Text("重建缓存完成。").send(reply=True)
b_cmd = on_alconna(
Alconna(
"看看B话",
Args["at", [str, At], Field(completion=lambda: "请想要查询的人的QQ号")],
Option("-g|--group_id", Args["group_id?", str]),
Option("-k|--keyword", Args["keyword?", str]),
),
aliases={"kkb"},
use_cmd_start=True,
)
@b_cmd.handle()
async def handle_b_cmd(
at: Match[str | At],
group_id: Match[str],
keyword: Match[str],
uninfo: Uninfo,
session: Session = Depends(extract_session),
):
id = at.result
if isinstance(id, At):
id = id.target
if group_id.available:
gid = group_id.result
else:
gid = session.id2
if not gid:
await b_cmd.finish("请指定群号。")
if keyword.available:
keywords = keyword.result
else:
keywords = None
messages = await get_message_records(
id1s=[id],
id2s=[gid],
id_type=SessionIdType.GROUP,
include_bot_id=False,
include_bot_type=False,
types=["message"], # 排除机器人自己发的消息
exclude_id1s=plugin_config.excluded_people,
)
d = msg_counter(messages, keywords)
rank = got_rank(d)
if not rank:
await b_cmd.finish(
f"该用户在群“{uninfo.scene.name}”关于“{keyword}”的B话数量为0。"
)
await saa.Text(
f"该用户在群“{uninfo.scene.name}”关于“{keyword}”的B话数量为{rank[0][1]}"
).send(reply=True)
rank_cmd = on_alconna( rank_cmd = on_alconna(
Alconna( Alconna(
"B话榜", "B话榜",
@@ -267,7 +329,7 @@ async def handle_rank(
t1 = t.time() t1 = t.time()
rank2 = await get_user_infos(bot, event, rank) rank2 = await get_user_infos(bot, event, rank)
logger.debug(f"获取用户信息花费时间:{t.time() - t1}") logger.debug(f"获取用户信息花费时间:{t.time() - t1}")
string: str = "" string: str = ""
if plugin_config.show_text_rank: if plugin_config.show_text_rank:
@@ -275,7 +337,7 @@ async def handle_rank(
string += f"关于{keyword}的话痨榜结果:\n" string += f"关于{keyword}的话痨榜结果:\n"
else: else:
string += "话痨榜:\n" string += "话痨榜:\n"
for i in rank2: for i in rank2:
logger.debug(i.user_name) logger.debug(i.user_name)
for i in range(len(rank2)): for i in range(len(rank2)):
@@ -301,4 +363,7 @@ async def handle_rank(
if not msg: if not msg:
await saa.Text("你把可视化都关了哪来的排行榜?").finish() await saa.Text("你把可视化都关了哪来的排行榜?").finish()
await msg.finish(reply=True) if plugin_config.aggregate_transmission:
await saa.AggregatedMessageFactory([msg]).finish()
else:
await msg.finish(reply=True)

View File

@@ -9,10 +9,11 @@ class ScopedConfig(BaseModel):
suffix: bool = True # 是否显示后缀 suffix: bool = True # 是否显示后缀
excluded_self: bool = True # 是否排除自己 excluded_self: bool = True # 是否排除自己
visualization: bool = True # 是否可视化 visualization: bool = True # 是否可视化
show_text_rank:bool = True # 是否显示文本排名 show_text_rank: bool = True # 是否显示文本排名
counting_cache: bool = False # 计数缓存(能够提高回复速度) counting_cache: bool = False # 计数缓存(能够提高回复速度)
excluded_people: List[str] = [] # 排除的人的QQ号 excluded_people: List[str] = [] # 排除的人的QQ号
use_user_info_cache: bool = False # 是否使用用户信息缓存 use_user_info_cache: bool = False # 是否使用用户信息缓存
aggregate_transmission: bool = False # 是否聚合转发消息
timezone: Optional[str] = "Asia/Shanghai" # 时区,影响统计时间 timezone: Optional[str] = "Asia/Shanghai" # 时区,影响统计时间
string_suffix: str = "统计花费时间:{timecost}" # 消息格式后缀 string_suffix: str = "统计花费时间:{timecost}" # 消息格式后缀
template_path: str = "./template/rank_template.j2" # 模板路径 template_path: str = "./template/rank_template.j2" # 模板路径

View File

@@ -7,6 +7,8 @@ __usage__ = cleandoc(
### 🎨一般用法 ### 🎨一般用法
#### B话榜
-`/B话榜` ————看看有史以来(机器人存在以来)群友们发了多少消息! (好像没写) -`/B话榜` ————看看有史以来(机器人存在以来)群友们发了多少消息! (好像没写)
-`/今日B话榜` ————看看今天的群友发了多少消息! -`/今日B话榜` ————看看今天的群友发了多少消息!
@@ -25,8 +27,14 @@ __usage__ = cleandoc(
-`/历史B话榜` ————看看历史上(机器人存在以来)的群友发了多少消息! -`/历史B话榜` ————看看历史上(机器人存在以来)的群友发了多少消息!
#### 看看B话kkb
-`/看看B话 [@某人|QQ号]` ————看看这个b人在这个b群发了多少b话
### 🚀进阶用法 ### 🚀进阶用法
#### B话榜
`/{时间类型(今日|年度)?}{B话榜|废话榜} {时间类型?} {ISO8601 格式时间 ?} {群号} {关键词}` `/{时间类型(今日|年度)?}{B话榜|废话榜} {时间类型?} {ISO8601 格式时间 ?} {群号} {关键词}`
如:`/B话榜 历史 2024-01-01~2024-01-02 12345678 女装` 如:`/B话榜 历史 2024-01-01~2024-01-02 12345678 女装`
@@ -39,5 +47,14 @@ __usage__ = cleandoc(
`/昨日B话榜 -k 女装` `/昨日B话榜 -k 女装`
`/本周B话榜 -g 12345678` `/本周B话榜 -g 12345678`
#### 看看B话
`/看看B话 {@|QQ号} {群号?} {关键词?}`
以下调用方法均合法:
`/kkb 114514 1919810 ♂`
`/kkb @man -k ♂`
""" """
) )

View File

@@ -1,4 +1,5 @@
import os import os
import re
import httpx import httpx
import asyncio import asyncio
import unicodedata import unicodedata
@@ -94,9 +95,10 @@ def msg_counter(
logger.info("wow , there are {} msgs to count !!!".format(msg_len)) logger.info("wow , there are {} msgs to count !!!".format(msg_len))
for i in msg_list: for i in msg_list:
logger.debug(f"processing msg {i.plain_text}") # logger.debug(f"processing msg {i.plain_text}")
if keyword: if keyword:
if keyword not in i.plain_text: match = re.search(keyword, i.plain_text)
if not match:
continue continue
try: try:
lst[str(i.session_persist_id)] += 1 lst[str(i.session_persist_id)] += 1

8
pdm.lock generated
View File

@@ -5,7 +5,7 @@
groups = ["default", "Test", "dev"] groups = ["default", "Test", "dev"]
strategy = ["inherit_metadata"] strategy = ["inherit_metadata"]
lock_version = "4.5.0" lock_version = "4.5.0"
content_hash = "sha256:882dfc18d7454ced6bb1f46e04172b14b83f90157475153bf0fff7b13e4d41a2" content_hash = "sha256:41c1ac2ec7d9ce3eb477f442e6ccbeda65fb25eb4f22cd696d361dae97cb065c"
[[metadata.targets]] [[metadata.targets]]
requires_python = ">=3.9,<3.13" requires_python = ">=3.9,<3.13"
@@ -267,7 +267,7 @@ name = "charset-normalizer"
version = "3.3.2" version = "3.3.2"
requires_python = ">=3.7.0" requires_python = ">=3.7.0"
summary = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." summary = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet."
groups = ["default", "dev"] groups = ["dev"]
files = [ files = [
{file = "charset-normalizer-3.3.2.tar.gz", hash = "sha256:f30c3cb33b24454a82faecaf01b19c18562b1e89558fb6c56de4d9118a032fd5"}, {file = "charset-normalizer-3.3.2.tar.gz", hash = "sha256:f30c3cb33b24454a82faecaf01b19c18562b1e89558fb6c56de4d9118a032fd5"},
{file = "charset_normalizer-3.3.2-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:25baf083bf6f6b341f4121c2f3c548875ee6f5339300e08be3f2b2ba1721cdd3"}, {file = "charset_normalizer-3.3.2-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:25baf083bf6f6b341f4121c2f3c548875ee6f5339300e08be3f2b2ba1721cdd3"},
@@ -1876,7 +1876,7 @@ name = "requests"
version = "2.32.3" version = "2.32.3"
requires_python = ">=3.8" requires_python = ">=3.8"
summary = "Python HTTP for Humans." summary = "Python HTTP for Humans."
groups = ["default", "dev"] groups = ["dev"]
dependencies = [ dependencies = [
"certifi>=2017.4.17", "certifi>=2017.4.17",
"charset-normalizer<4,>=2", "charset-normalizer<4,>=2",
@@ -2383,7 +2383,7 @@ name = "urllib3"
version = "2.2.1" version = "2.2.1"
requires_python = ">=3.8" requires_python = ">=3.8"
summary = "HTTP library with thread-safe connection pooling, file post, and more." summary = "HTTP library with thread-safe connection pooling, file post, and more."
groups = ["default", "dev"] groups = ["dev"]
files = [ files = [
{file = "urllib3-2.2.1-py3-none-any.whl", hash = "sha256:450b20ec296a467077128bff42b73080516e71b56ff59a60a02bef2232c4fa9d"}, {file = "urllib3-2.2.1-py3-none-any.whl", hash = "sha256:450b20ec296a467077128bff42b73080516e71b56ff59a60a02bef2232c4fa9d"},
{file = "urllib3-2.2.1.tar.gz", hash = "sha256:d0570876c61ab9e520d776c38acbbb5b05a776d3f9ff98a5c8fd5162a444cf19"}, {file = "urllib3-2.2.1.tar.gz", hash = "sha256:d0570876c61ab9e520d776c38acbbb5b05a776d3f9ff98a5c8fd5162a444cf19"},

View File

@@ -1,13 +1,12 @@
[project] [project]
name = "nonebot-plugin-dialectlist" name = "nonebot-plugin-dialectlist"
version = "2.4.5" version = "2.6.2"
description = "看看你群群友有多能说" description = "看看你群群友有多能说"
authors = [ authors = [
{name = "Chen_Xu233", email = "woyerpa@outlook.com"}, {name = "Chen_Xu233", email = "woyerpa@outlook.com"},
] ]
dependencies = [ dependencies = [
"nonebot-plugin-chatrecorder>=0.6.0", "nonebot-plugin-chatrecorder>=0.6.0,<0.7.0",
"requests>=2.32.3",
"nonebot-plugin-orm[default]", "nonebot-plugin-orm[default]",
"nonebot-plugin-apscheduler>=0.4.0", "nonebot-plugin-apscheduler>=0.4.0",
"nonebot-plugin-alconna>=0.50.2", "nonebot-plugin-alconna>=0.50.2",
@@ -18,7 +17,7 @@ dependencies = [
"pillow>=10.4.0", "pillow>=10.4.0",
"nonebot-plugin-uninfo>=0.1.1", "nonebot-plugin-uninfo>=0.1.1",
] ]
requires-python = ">=3.9,<3.13" requires-python = ">=3.9,<4.0"
readme = "README.md" readme = "README.md"
license = {text = "MIT"} license = {text = "MIT"}