nonebot-plugin-dialectlist 2.7.1__tar.gz → 3.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. nonebot_plugin_dialectlist-3.1.0/PKG-INFO +264 -0
  2. nonebot_plugin_dialectlist-3.1.0/README.md +235 -0
  3. {nonebot_plugin_dialectlist-2.7.1 → nonebot_plugin_dialectlist-3.1.0}/nonebot_plugin_dialectlist/__init__.py +30 -49
  4. nonebot_plugin_dialectlist-3.1.0/nonebot_plugin_dialectlist/config.py +28 -0
  5. nonebot_plugin_dialectlist-3.1.0/nonebot_plugin_dialectlist/schema.py +31 -0
  6. {nonebot_plugin_dialectlist-2.7.1 → nonebot_plugin_dialectlist-3.1.0}/nonebot_plugin_dialectlist/template/rank_template.j2 +2 -2
  7. nonebot_plugin_dialectlist-3.1.0/nonebot_plugin_dialectlist/template/res/HarmonyOS_Sans_SC.woff2 +0 -0
  8. nonebot_plugin_dialectlist-3.1.0/nonebot_plugin_dialectlist/time.py +52 -0
  9. {nonebot_plugin_dialectlist-2.7.1 → nonebot_plugin_dialectlist-3.1.0}/nonebot_plugin_dialectlist/usage.py +2 -4
  10. nonebot_plugin_dialectlist-3.1.0/nonebot_plugin_dialectlist/utils.py +323 -0
  11. nonebot_plugin_dialectlist-3.1.0/pyproject.toml +59 -0
  12. nonebot_plugin_dialectlist-3.1.0/tests/screenshot-chromium.png +0 -0
  13. nonebot_plugin_dialectlist-3.1.0/tests/screenshot-firefox.png +0 -0
  14. nonebot_plugin_dialectlist-3.1.0/tests/screenshot-webkit.png +0 -0
  15. nonebot_plugin_dialectlist-3.1.0/tests/temple_render.py +12 -0
  16. nonebot_plugin_dialectlist-2.7.1/MANIFEST.in +0 -3
  17. nonebot_plugin_dialectlist-2.7.1/PKG-INFO +0 -241
  18. nonebot_plugin_dialectlist-2.7.1/README.md +0 -212
  19. nonebot_plugin_dialectlist-2.7.1/nonebot_plugin_dialectlist/config.py +0 -29
  20. nonebot_plugin_dialectlist-2.7.1/nonebot_plugin_dialectlist/migrations/fb88e4d27eb8_update_dialectlist.py +0 -47
  21. nonebot_plugin_dialectlist-2.7.1/nonebot_plugin_dialectlist/model.py +0 -23
  22. nonebot_plugin_dialectlist-2.7.1/nonebot_plugin_dialectlist/storage.py +0 -136
  23. nonebot_plugin_dialectlist-2.7.1/nonebot_plugin_dialectlist/time.py +0 -77
  24. nonebot_plugin_dialectlist-2.7.1/nonebot_plugin_dialectlist/utils.py +0 -263
  25. nonebot_plugin_dialectlist-2.7.1/nonebot_plugin_dialectlist.egg-info/PKG-INFO +0 -241
  26. nonebot_plugin_dialectlist-2.7.1/nonebot_plugin_dialectlist.egg-info/SOURCES.txt +0 -20
  27. nonebot_plugin_dialectlist-2.7.1/nonebot_plugin_dialectlist.egg-info/dependency_links.txt +0 -1
  28. nonebot_plugin_dialectlist-2.7.1/nonebot_plugin_dialectlist.egg-info/requires.txt +0 -20
  29. nonebot_plugin_dialectlist-2.7.1/nonebot_plugin_dialectlist.egg-info/top_level.txt +0 -1
  30. nonebot_plugin_dialectlist-2.7.1/pyproject.toml +0 -44
  31. nonebot_plugin_dialectlist-2.7.1/setup.cfg +0 -4
  32. {nonebot_plugin_dialectlist-2.7.1 → nonebot_plugin_dialectlist-3.1.0}/LICENSE +0 -0
  33. {nonebot_plugin_dialectlist-2.7.1 → nonebot_plugin_dialectlist-3.1.0}/nonebot_plugin_dialectlist/template/avatar/default.jpg +0 -0
  34. {nonebot_plugin_dialectlist-2.7.1 → nonebot_plugin_dialectlist-3.1.0}/nonebot_plugin_dialectlist/template/css/style.css +0 -0
@@ -0,0 +1,264 @@
1
+ Metadata-Version: 2.1
2
+ Name: nonebot-plugin-dialectlist
3
+ Version: 3.1.0
4
+ Summary: 看看你群群友有多能说
5
+ Author-Email: Chen_Xu233 <woyerpa@outlook.com>
6
+ License: MIT
7
+ Requires-Python: <4.0,>=3.10
8
+ Requires-Dist: nonebot2>=2.4.0
9
+ Requires-Dist: nonebot-plugin-chatrecorder>=0.7.0
10
+ Requires-Dist: nonebot-plugin-orm[sqlite]>=0.8.0
11
+ Requires-Dist: nonebot-plugin-alconna>=0.50.2
12
+ Requires-Dist: nonebot-plugin-uninfo>=0.8.0
13
+ Requires-Dist: nonebot-plugin-userinfo>=0.2.6
14
+ Requires-Dist: nonebot-plugin-htmlrender<0.9,>=0.6.6
15
+ Requires-Dist: playwright>=1.48.0
16
+ Requires-Dist: nonebot-plugin-send-anything-anywhere>=0.7.1
17
+ Requires-Dist: httpx>=0.27.0
18
+ Requires-Dist: jinja2>=3.0.3
19
+ Requires-Dist: sqlalchemy>=2.0.0
20
+ Requires-Dist: pillow>=11.3.0
21
+ Provides-Extra: dev
22
+ Requires-Dist: ruff>=0.5.5; extra == "dev"
23
+ Requires-Dist: twine>=6.2.0; extra == "dev"
24
+ Requires-Dist: nb-cli>=1.4.2; extra == "dev"
25
+ Requires-Dist: py-spy>=0.3.14; extra == "dev"
26
+ Provides-Extra: test
27
+ Requires-Dist: nonebot-adapter-onebot>=2.4.4; extra == "test"
28
+ Description-Content-Type: text/markdown
29
+
30
+ <div align="center">
31
+ <a href="https://v2.nonebot.dev/store"><img src="./docs/NoneBotPlugin.svg" width="400" alt="NoneBotPluginLogo"></a>
32
+ <br>
33
+ <p><img src="https://s2.loli.net/2022/06/16/xsVUGRrkbn1ljTD.png" width="240" alt="NoneBotPluginText"></p>
34
+ </div>
35
+
36
+ <div align="center">
37
+
38
+ # 📃 话痨排行榜
39
+
40
+ nonebot-plugin-dialectlist
41
+
42
+ <p align="center">
43
+ <a href="https://pypi.python.org/pypi/nonebot-plugin-dialectlist">
44
+ <img src="https://img.shields.io/pypi/v/nonebot-plugin-dialectlist.svg" alt="pypi">
45
+ </a>
46
+
47
+ <img src="https://img.shields.io/badge/python-3.10+-blue.svg" alt="python">
48
+
49
+ <a href="https://qm.qq.com/q/Yty2yc9Bee">
50
+ <img src="https://img.shields.io/badge/QQ%E7%BE%A4-1128359833-orange?style=flat-square" alt="QQ Chat Group">
51
+ </a>
52
+ </p>
53
+
54
+ [![wakatime](https://wakatime.com/badge/user/114aee90-a5f9-49aa-b441-9eca7eebfda3/project/68aaa2a1-fb8a-4b00-bb66-ee67e8a3f3b0.svg)](https://wakatime.com/badge/user/114aee90-a5f9-49aa-b441-9eca7eebfda3/project/68aaa2a1-fb8a-4b00-bb66-ee67e8a3f3b0)
55
+
56
+ \>💬**看看群友们这些天在群里水了多少话**💬<
57
+
58
+ </div>
59
+
60
+ ## 💿 安装
61
+
62
+ 通过`pip`或`nb`安装:
63
+
64
+ - 通过 pip 安装
65
+
66
+ ```bash
67
+ pip install nonebot-plugin-dialectlist
68
+ ```
69
+
70
+ - 通过 nb-cli 安装
71
+
72
+ ```bash
73
+ nb plugin install nonebot-plugin-dialectlist
74
+ ```
75
+
76
+ ### ✅ 插件依赖于
77
+
78
+ 1. [nonebot-plugin-chatrecorder](https://github.com/noneplugin/nonebot-plugin-chatrecorder) ————实现消息储存
79
+ 2. [nonebot-plugin-orm](https://github.com/nonebot/nonebot-plugin-orm) ————数据库
80
+ 3. [nonebot-plugin-uninfo](https://github.com/nonebot/nonebot-plugin-uninfo) ————跨平台会话信息
81
+ 4. [nonebot-plugin-userinfo](https://github.com/noneplugin/nonebot-plugin-userinfo) ————获取用户信息
82
+ 5. [nonebot-plugin-alconna](https://github.com/ArcletProject/nonebot-plugin-alconna) ————实现命令解析
83
+ 6. [nonebot-plugin-send-anything-anywhere](https://github.com/felinae98/nonebot-plugin-send-anything-anywhere) ————实现多平台发送
84
+ 7. [nonebot-plugin-htmlrender](https://github.com/nonebot/nonebot-plugin-htmlrender) ————渲染排行榜图片
85
+
86
+ **⚠ 注意** 若先前没有安装过`nonebot-plugin-chatrecorder`或者`nonebot-plugin-orm`,则会在启动时报错,请按报错的提示安装数据库!
87
+
88
+ > [!IMPORTANT]
89
+ > **关于 htmlrender 版本**:支持 `nonebot-plugin-htmlrender >= 0.6.6, < 0.9`。
90
+ > 0.6 开箱即用;用 0.7 / 0.8 时上游要求显式指定渲染后端,需要在 `.env` 里加一行:
91
+ >
92
+ > ```dotenv
93
+ > # htmlrender 0.8+
94
+ > RENDER__PROVIDER=playwright
95
+ > # htmlrender 0.7
96
+ > RENDER_BACKEND=playwright
97
+ > ```
98
+ >
99
+ > 模板的样式、字体和头像已全部内联成 data URI,所以 0.8 的本地文件访问限制不影响出图。
100
+ > 首次渲染会自动安装 Chromium,也可以手动执行 `playwright install chromium`。
101
+
102
+ ## ⚙ 配置
103
+
104
+ 需要**提前配置**本插件所**依赖的插件**!
105
+
106
+ 在 .env 中,可以添加以下配置项
107
+
108
+ ```python
109
+ dialectlist__get_num: int = 5 # 获取人数数量
110
+ dialectlist__suffix: bool = True # 是否显示后缀
111
+ dialectlist__visualization: bool = True # 是否可视化
112
+ dialectlist__show_text_rank: bool = True # 是否显示文本排名
113
+ dialectlist__excluded_people: List[str] = [] # 排除的人的 QQ 号
114
+ dialectlist__use_user_info_cache: bool = False # 是否使用用户信息缓存
115
+ dialectlist__aggregate_transmission: bool = False # 是否聚合转发消息
116
+ dialectlist__timezone: Optional[str] = "Asia/Shanghai" # 时区,影响统计时间
117
+ dialectlist__string_suffix: str = "统计花费时间:{timecost}秒" # 消息格式后缀
118
+ dialectlist__template_path: str = "./template/rank_template.j2" # 模板路径
119
+ dialectlist__string_format: str = "第{index}名:\n{nickname},{chatdatanum}条消息\n" # 消息格式
120
+ ```
121
+
122
+ 💭 也可以不进行配置,这将会使插件按照默认配置运行
123
+
124
+ > [!NOTE]
125
+ > 3.1.0 起模板变量有变化:`inline_css`(内联的样式表与字体)、`i.user_avatar_data_uri`(头像 data URI)。
126
+ > 插件不再向缓存目录写头像文件,也不再向模板传入 `cache_path` / `file_path`;自定义模板请改用新变量。
127
+
128
+ ### ⚠ 注意!!
129
+
130
+ > 在旧版插件(2.0.0 以下)中,dialectlist 与后面的配置项只隔了一个下划线,若更新到新版本以后需要俩个下划线。
131
+
132
+ > 由于插件依赖 chatrecord 多次引入爆炸性修改,建议在遇到问题后优先尝试降级 chatrecord 插件
133
+
134
+ ## 🗨 命令
135
+
136
+ **!!注意!!**
137
+ 新版本指令调用方式改变,改为更易理解也更好打的 B 话榜。
138
+ 同时也可以用类似 `/今日废话榜` 的方式(只要改前面的就好了)(算是给 [盘古之白](https://github.com/vinta/pangu.js) 风格爱好者的福利吧?)
139
+
140
+ ### 🎨 一般用法
141
+
142
+ #### B 话榜
143
+
144
+ -`/B 话榜` ————看看有史以来(机器人存在以来)群友们发了多少消息! (好像没写)
145
+
146
+ -`/今日 B 话榜` ————看看今天的群友发了多少消息!
147
+
148
+ -`/昨日 B 话榜` ————看看昨天的群友发了多少消息!
149
+
150
+ -`/本周 B 话榜` ————看看本周的群友发了多少消息!
151
+
152
+ -`/上周 B 话榜` ————看看上周的群友发了多少消息!
153
+
154
+ -`/本月 B 话榜` ————看看这个月的群友发了多少消息!
155
+
156
+ -`/年度 B 话榜` ————看看今年的群友发了多少消息!
157
+
158
+ -`/历史 B 话榜` ————看看历史上(机器人存在以来)的群友发了多少消息!
159
+
160
+ #### 看看 B 话(kkb)
161
+
162
+ -`/看看 B 话 [@某人|QQ 号]` ————看看这个 b 人在这个 b 群发了多少 b 话!
163
+
164
+ ### 🚀 进阶用法
165
+
166
+ #### B 话榜
167
+
168
+ `/{时间类型(今日|年度)?}{B 话榜|废话榜} {时间类型?} {ISO8601 格式时间 ?} {群号} {关键词}`
169
+
170
+ 如:`/B 话榜 历史 2024-01-01~2024-01-02 12345678 女装`
171
+
172
+ 也可以 `/{时间类型(今日|年度)?}{B 话榜|废话榜} {时间类型?} {ISO8601 格式时间 ?} -g {群号} -k {关键词}`
173
+
174
+ 以下调用方法均合法:
175
+
176
+ `/今日 B 话榜 -g 12345678 -k 女装`
177
+ `/昨日 B 话榜 -k 女装`
178
+ `/本周 B 话榜 -g 12345678`
179
+
180
+ #### 看看 B 话
181
+
182
+ `/看看 B 话 {@|QQ 号} {群号?} {关键词?}`
183
+
184
+ 以下调用方法均合法:
185
+
186
+ `/kkb 114514 1919810 ♂`
187
+ `/kkb @man -k ♂`
188
+
189
+ > [!IMPORTANT]
190
+ > 关键词按“包含”匹配(不区分大小写的子串匹配),**不支持正则表达式**;输入中的 `%`、`_` 会按普通字符处理。
191
+
192
+ > [!NOTE]
193
+ > 3.0.2 起移除了从未生效的 `font`(字体固定使用内置字体)与 `excluded_self`(统计本就只算收到的消息)两项配置。
194
+
195
+ ## 💪 目前支持的平台
196
+
197
+ | 平台 | 是否经过测试 | 是否能够正常工作 | 测试环境 |
198
+ | :---------: | :----------: | :--------------: | :---------------: |
199
+ | Onebot | ✅ | ✅ | NapCat + Window11 |
200
+ | 飞书 | ❌ | ❓ | 🤔 |
201
+ | Red | ❌ | ❓ | 🤔 |
202
+ | DoDo | ❌ | ❓ | 🤔 |
203
+ | Mirai | ❌ | ❓ | 🤔 |
204
+ | 开黑啦 | ❌ | ❓ | 🤔 |
205
+ | Kritor | ❌ | ❓ | 🤔 |
206
+ | Ntchat | ❌ | ❓ | 🤔 |
207
+ | Satori | ❌ | ❓ | 🤔 |
208
+ | Telegram | ❌ | ❓ | 🤔 |
209
+ | Discord | ❌ | ❓ | 🤔 |
210
+ | Tailchat | ❌ | ❓ | 🤔 |
211
+ | QQ 官方接口 | ❌ | ❓ | 🤔 |
212
+ | Rocket.Chat | ❌ | ❓ | 🤔 |
213
+
214
+ - 如果你测试过能够使用,请在 Issue 中指出
215
+
216
+ ## 📦 另外
217
+
218
+ ### 😳 加入作者的 BUG 反馈群 ~~(🥵 女装粉丝群)~~
219
+
220
+ [群连接](https://qm.qq.com/q/Yty2yc9Bee)
221
+
222
+ <details>
223
+ <summary>群二维码 点我展开</summary>
224
+
225
+ ![7a4bd22dea47d25d9b632d4b2696d4cd](https://github.com/ChenXu233/nonebot_plugin_dialectlist/assets/91937041/61fd7010-e2b2-4f13-b209-9c0faf8a517f)
226
+
227
+ </details>
228
+
229
+ ![9c149e99ca747c13892be3f9fbeedf31](https://github.com/user-attachments/assets/d02d108c-1ab3-4ad1-9123-c1a98862e627)
230
+
231
+ ### 💕 感谢
232
+
233
+ 本插件的**init**.py 中的处理函数参考了词云中的方法 ~~(其实大部分都是 Ctrl+C Ctr+V)~~
234
+
235
+ [nonebot-plugin-wordcloud](https://github.com/he0119/nonebot-plugin-wordcloud)
236
+
237
+ 感谢以下开发者作出的贡献:
238
+
239
+ <a href="https://github.com/ChenXu233/nonebot_plugin_dialectlist/graphs/contributors">
240
+ <img src="https://contrib.rocks/image?repo=ChenXu233/nonebot_plugin_dialectlist&max=1000" />
241
+ </a>
242
+
243
+ ### 🎀TODO
244
+
245
+ - [x] 适配全平台
246
+
247
+ - [x] 更好看的图片渲染
248
+
249
+ - [x] 添加一些全新的可配置项
250
+ - [x] 尝试利用 jinja2 模板引擎制作可视化图片
251
+
252
+ - [x] 私聊的查询(超级用户可以任意查询群聊的信息)一半完成
253
+
254
+ - [x] 特殊的储存方案优化消息统计
255
+
256
+ - [x] 查询带某关键词的消息量
257
+
258
+ - [x] 合并转发
259
+
260
+ 待补充。.....
261
+
262
+ ### 👾 题外话
263
+
264
+ ~~整个项目快被我写成屎山了~~
@@ -0,0 +1,235 @@
1
+ <div align="center">
2
+ <a href="https://v2.nonebot.dev/store"><img src="./docs/NoneBotPlugin.svg" width="400" alt="NoneBotPluginLogo"></a>
3
+ <br>
4
+ <p><img src="https://s2.loli.net/2022/06/16/xsVUGRrkbn1ljTD.png" width="240" alt="NoneBotPluginText"></p>
5
+ </div>
6
+
7
+ <div align="center">
8
+
9
+ # 📃 话痨排行榜
10
+
11
+ nonebot-plugin-dialectlist
12
+
13
+ <p align="center">
14
+ <a href="https://pypi.python.org/pypi/nonebot-plugin-dialectlist">
15
+ <img src="https://img.shields.io/pypi/v/nonebot-plugin-dialectlist.svg" alt="pypi">
16
+ </a>
17
+
18
+ <img src="https://img.shields.io/badge/python-3.10+-blue.svg" alt="python">
19
+
20
+ <a href="https://qm.qq.com/q/Yty2yc9Bee">
21
+ <img src="https://img.shields.io/badge/QQ%E7%BE%A4-1128359833-orange?style=flat-square" alt="QQ Chat Group">
22
+ </a>
23
+ </p>
24
+
25
+ [![wakatime](https://wakatime.com/badge/user/114aee90-a5f9-49aa-b441-9eca7eebfda3/project/68aaa2a1-fb8a-4b00-bb66-ee67e8a3f3b0.svg)](https://wakatime.com/badge/user/114aee90-a5f9-49aa-b441-9eca7eebfda3/project/68aaa2a1-fb8a-4b00-bb66-ee67e8a3f3b0)
26
+
27
+ \>💬**看看群友们这些天在群里水了多少话**💬<
28
+
29
+ </div>
30
+
31
+ ## 💿 安装
32
+
33
+ 通过`pip`或`nb`安装:
34
+
35
+ - 通过 pip 安装
36
+
37
+ ```bash
38
+ pip install nonebot-plugin-dialectlist
39
+ ```
40
+
41
+ - 通过 nb-cli 安装
42
+
43
+ ```bash
44
+ nb plugin install nonebot-plugin-dialectlist
45
+ ```
46
+
47
+ ### ✅ 插件依赖于
48
+
49
+ 1. [nonebot-plugin-chatrecorder](https://github.com/noneplugin/nonebot-plugin-chatrecorder) ————实现消息储存
50
+ 2. [nonebot-plugin-orm](https://github.com/nonebot/nonebot-plugin-orm) ————数据库
51
+ 3. [nonebot-plugin-uninfo](https://github.com/nonebot/nonebot-plugin-uninfo) ————跨平台会话信息
52
+ 4. [nonebot-plugin-userinfo](https://github.com/noneplugin/nonebot-plugin-userinfo) ————获取用户信息
53
+ 5. [nonebot-plugin-alconna](https://github.com/ArcletProject/nonebot-plugin-alconna) ————实现命令解析
54
+ 6. [nonebot-plugin-send-anything-anywhere](https://github.com/felinae98/nonebot-plugin-send-anything-anywhere) ————实现多平台发送
55
+ 7. [nonebot-plugin-htmlrender](https://github.com/nonebot/nonebot-plugin-htmlrender) ————渲染排行榜图片
56
+
57
+ **⚠ 注意** 若先前没有安装过`nonebot-plugin-chatrecorder`或者`nonebot-plugin-orm`,则会在启动时报错,请按报错的提示安装数据库!
58
+
59
+ > [!IMPORTANT]
60
+ > **关于 htmlrender 版本**:支持 `nonebot-plugin-htmlrender >= 0.6.6, < 0.9`。
61
+ > 0.6 开箱即用;用 0.7 / 0.8 时上游要求显式指定渲染后端,需要在 `.env` 里加一行:
62
+ >
63
+ > ```dotenv
64
+ > # htmlrender 0.8+
65
+ > RENDER__PROVIDER=playwright
66
+ > # htmlrender 0.7
67
+ > RENDER_BACKEND=playwright
68
+ > ```
69
+ >
70
+ > 模板的样式、字体和头像已全部内联成 data URI,所以 0.8 的本地文件访问限制不影响出图。
71
+ > 首次渲染会自动安装 Chromium,也可以手动执行 `playwright install chromium`。
72
+
73
+ ## ⚙ 配置
74
+
75
+ 需要**提前配置**本插件所**依赖的插件**!
76
+
77
+ 在 .env 中,可以添加以下配置项
78
+
79
+ ```python
80
+ dialectlist__get_num: int = 5 # 获取人数数量
81
+ dialectlist__suffix: bool = True # 是否显示后缀
82
+ dialectlist__visualization: bool = True # 是否可视化
83
+ dialectlist__show_text_rank: bool = True # 是否显示文本排名
84
+ dialectlist__excluded_people: List[str] = [] # 排除的人的 QQ 号
85
+ dialectlist__use_user_info_cache: bool = False # 是否使用用户信息缓存
86
+ dialectlist__aggregate_transmission: bool = False # 是否聚合转发消息
87
+ dialectlist__timezone: Optional[str] = "Asia/Shanghai" # 时区,影响统计时间
88
+ dialectlist__string_suffix: str = "统计花费时间:{timecost}秒" # 消息格式后缀
89
+ dialectlist__template_path: str = "./template/rank_template.j2" # 模板路径
90
+ dialectlist__string_format: str = "第{index}名:\n{nickname},{chatdatanum}条消息\n" # 消息格式
91
+ ```
92
+
93
+ 💭 也可以不进行配置,这将会使插件按照默认配置运行
94
+
95
+ > [!NOTE]
96
+ > 3.1.0 起模板变量有变化:`inline_css`(内联的样式表与字体)、`i.user_avatar_data_uri`(头像 data URI)。
97
+ > 插件不再向缓存目录写头像文件,也不再向模板传入 `cache_path` / `file_path`;自定义模板请改用新变量。
98
+
99
+ ### ⚠ 注意!!
100
+
101
+ > 在旧版插件(2.0.0 以下)中,dialectlist 与后面的配置项只隔了一个下划线,若更新到新版本以后需要俩个下划线。
102
+
103
+ > 由于插件依赖 chatrecord 多次引入爆炸性修改,建议在遇到问题后优先尝试降级 chatrecord 插件
104
+
105
+ ## 🗨 命令
106
+
107
+ **!!注意!!**
108
+ 新版本指令调用方式改变,改为更易理解也更好打的 B 话榜。
109
+ 同时也可以用类似 `/今日废话榜` 的方式(只要改前面的就好了)(算是给 [盘古之白](https://github.com/vinta/pangu.js) 风格爱好者的福利吧?)
110
+
111
+ ### 🎨 一般用法
112
+
113
+ #### B 话榜
114
+
115
+ -`/B 话榜` ————看看有史以来(机器人存在以来)群友们发了多少消息! (好像没写)
116
+
117
+ -`/今日 B 话榜` ————看看今天的群友发了多少消息!
118
+
119
+ -`/昨日 B 话榜` ————看看昨天的群友发了多少消息!
120
+
121
+ -`/本周 B 话榜` ————看看本周的群友发了多少消息!
122
+
123
+ -`/上周 B 话榜` ————看看上周的群友发了多少消息!
124
+
125
+ -`/本月 B 话榜` ————看看这个月的群友发了多少消息!
126
+
127
+ -`/年度 B 话榜` ————看看今年的群友发了多少消息!
128
+
129
+ -`/历史 B 话榜` ————看看历史上(机器人存在以来)的群友发了多少消息!
130
+
131
+ #### 看看 B 话(kkb)
132
+
133
+ -`/看看 B 话 [@某人|QQ 号]` ————看看这个 b 人在这个 b 群发了多少 b 话!
134
+
135
+ ### 🚀 进阶用法
136
+
137
+ #### B 话榜
138
+
139
+ `/{时间类型(今日|年度)?}{B 话榜|废话榜} {时间类型?} {ISO8601 格式时间 ?} {群号} {关键词}`
140
+
141
+ 如:`/B 话榜 历史 2024-01-01~2024-01-02 12345678 女装`
142
+
143
+ 也可以 `/{时间类型(今日|年度)?}{B 话榜|废话榜} {时间类型?} {ISO8601 格式时间 ?} -g {群号} -k {关键词}`
144
+
145
+ 以下调用方法均合法:
146
+
147
+ `/今日 B 话榜 -g 12345678 -k 女装`
148
+ `/昨日 B 话榜 -k 女装`
149
+ `/本周 B 话榜 -g 12345678`
150
+
151
+ #### 看看 B 话
152
+
153
+ `/看看 B 话 {@|QQ 号} {群号?} {关键词?}`
154
+
155
+ 以下调用方法均合法:
156
+
157
+ `/kkb 114514 1919810 ♂`
158
+ `/kkb @man -k ♂`
159
+
160
+ > [!IMPORTANT]
161
+ > 关键词按“包含”匹配(不区分大小写的子串匹配),**不支持正则表达式**;输入中的 `%`、`_` 会按普通字符处理。
162
+
163
+ > [!NOTE]
164
+ > 3.0.2 起移除了从未生效的 `font`(字体固定使用内置字体)与 `excluded_self`(统计本就只算收到的消息)两项配置。
165
+
166
+ ## 💪 目前支持的平台
167
+
168
+ | 平台 | 是否经过测试 | 是否能够正常工作 | 测试环境 |
169
+ | :---------: | :----------: | :--------------: | :---------------: |
170
+ | Onebot | ✅ | ✅ | NapCat + Window11 |
171
+ | 飞书 | ❌ | ❓ | 🤔 |
172
+ | Red | ❌ | ❓ | 🤔 |
173
+ | DoDo | ❌ | ❓ | 🤔 |
174
+ | Mirai | ❌ | ❓ | 🤔 |
175
+ | 开黑啦 | ❌ | ❓ | 🤔 |
176
+ | Kritor | ❌ | ❓ | 🤔 |
177
+ | Ntchat | ❌ | ❓ | 🤔 |
178
+ | Satori | ❌ | ❓ | 🤔 |
179
+ | Telegram | ❌ | ❓ | 🤔 |
180
+ | Discord | ❌ | ❓ | 🤔 |
181
+ | Tailchat | ❌ | ❓ | 🤔 |
182
+ | QQ 官方接口 | ❌ | ❓ | 🤔 |
183
+ | Rocket.Chat | ❌ | ❓ | 🤔 |
184
+
185
+ - 如果你测试过能够使用,请在 Issue 中指出
186
+
187
+ ## 📦 另外
188
+
189
+ ### 😳 加入作者的 BUG 反馈群 ~~(🥵 女装粉丝群)~~
190
+
191
+ [群连接](https://qm.qq.com/q/Yty2yc9Bee)
192
+
193
+ <details>
194
+ <summary>群二维码 点我展开</summary>
195
+
196
+ ![7a4bd22dea47d25d9b632d4b2696d4cd](https://github.com/ChenXu233/nonebot_plugin_dialectlist/assets/91937041/61fd7010-e2b2-4f13-b209-9c0faf8a517f)
197
+
198
+ </details>
199
+
200
+ ![9c149e99ca747c13892be3f9fbeedf31](https://github.com/user-attachments/assets/d02d108c-1ab3-4ad1-9123-c1a98862e627)
201
+
202
+ ### 💕 感谢
203
+
204
+ 本插件的**init**.py 中的处理函数参考了词云中的方法 ~~(其实大部分都是 Ctrl+C Ctr+V)~~
205
+
206
+ [nonebot-plugin-wordcloud](https://github.com/he0119/nonebot-plugin-wordcloud)
207
+
208
+ 感谢以下开发者作出的贡献:
209
+
210
+ <a href="https://github.com/ChenXu233/nonebot_plugin_dialectlist/graphs/contributors">
211
+ <img src="https://contrib.rocks/image?repo=ChenXu233/nonebot_plugin_dialectlist&max=1000" />
212
+ </a>
213
+
214
+ ### 🎀TODO
215
+
216
+ - [x] 适配全平台
217
+
218
+ - [x] 更好看的图片渲染
219
+
220
+ - [x] 添加一些全新的可配置项
221
+ - [x] 尝试利用 jinja2 模板引擎制作可视化图片
222
+
223
+ - [x] 私聊的查询(超级用户可以任意查询群聊的信息)一半完成
224
+
225
+ - [x] 特殊的储存方案优化消息统计
226
+
227
+ - [x] 查询带某关键词的消息量
228
+
229
+ - [x] 合并转发
230
+
231
+ 待补充。.....
232
+
233
+ ### 👾 题外话
234
+
235
+ ~~整个项目快被我写成屎山了~~
@@ -1,12 +1,11 @@
1
1
  from nonebot import require
2
2
 
3
3
  require('nonebot_plugin_chatrecorder')
4
- require('nonebot_plugin_apscheduler')
5
4
  require('nonebot_plugin_htmlrender')
6
5
  require('nonebot_plugin_userinfo')
7
6
  require('nonebot_plugin_alconna')
8
7
  require('nonebot_plugin_uninfo')
9
- require('nonebot_plugin_cesaa')
8
+ require('nonebot_plugin_saa')
10
9
 
11
10
  import re
12
11
  import time as t
@@ -16,7 +15,6 @@ from typing import Optional, Union
16
15
  import nonebot_plugin_saa as saa
17
16
  from arclet.alconna import ArparmaBehavior
18
17
  from arclet.alconna.arparma import Arparma
19
- from nonebot import on_command
20
18
  from nonebot.adapters import Bot, Event
21
19
  from nonebot.log import logger
22
20
  from nonebot.params import Arg, Depends
@@ -31,11 +29,9 @@ from nonebot_plugin_alconna import (
31
29
  Option,
32
30
  on_alconna,
33
31
  )
34
- from nonebot_plugin_chatrecorder import get_message_records
35
32
  from nonebot_plugin_uninfo import Session, Uninfo, get_session
36
33
 
37
34
  from .config import Config, plugin_config
38
- # from .storage import build_cache, get_cache
39
35
  from .time import (
40
36
  get_datetime_fromisoformat_with_timezone,
41
37
  get_datetime_now_with_timezone,
@@ -46,8 +42,8 @@ from .utils import (
46
42
  get_rank_image,
47
43
  get_user_infos,
48
44
  got_rank,
49
- msg_counter,
50
45
  persist_id2user_id,
46
+ get_user_message_counts,
51
47
  )
52
48
 
53
49
  __plugin_meta__ = PluginMetadata(
@@ -80,17 +76,6 @@ def wrapper(slot: Union[int, str], content: Optional[str], context) -> str:
80
76
  return '' # pragma: no cover
81
77
 
82
78
 
83
- build_cache_cmd = on_command('build_cache', aliases={'重建缓存'}, block=True)
84
-
85
-
86
- @build_cache_cmd.handle()
87
- async def _build_cache(bot: Bot, event: Event):
88
- return
89
- await saa.Text('正在重建缓存,请稍等。').send(reply=True) # type: ignore
90
- await build_cache()
91
- await saa.Text('重建缓存完成。').send(reply=True)
92
-
93
-
94
79
  b_cmd = on_alconna(
95
80
  Alconna(
96
81
  '看看B话',
@@ -122,26 +107,26 @@ async def handle_b_cmd(
122
107
  if not gid:
123
108
  await b_cmd.finish('请指定群号。')
124
109
 
125
- if keyword.available:
126
- keywords = keyword.result
127
- else:
128
- keywords = None
110
+ # 未使用 -k 时 Match.result 为 None,不能直接拼进文案
111
+ keyword_text = keyword.result if keyword.available else None
112
+ keyword_desc = f'关于“{keyword_text}”的' if keyword_text else ''
129
113
 
130
- messages = await get_message_records(
114
+ d = await get_user_message_counts(
115
+ keyword=keyword_text,
131
116
  scene_ids=[gid],
132
117
  user_ids=[id],
133
- types=['message'], # 排除机器人自己发的消息
118
+ types=['message'], # 只统计收到的消息,机器人自己发的不计入
134
119
  exclude_user_ids=plugin_config.excluded_people,
135
120
  )
136
- d = msg_counter(messages, keywords)
121
+
137
122
  rank = got_rank(d)
138
123
  if not rank:
139
124
  await b_cmd.finish(
140
- f'该用户在群“{uninfo.scene.name}”关于“{keyword.result}”的B话数量为0。'
125
+ f'该用户在群“{uninfo.scene.name}”{keyword_desc}B话数量为0。'
141
126
  )
142
127
 
143
128
  await saa.Text(
144
- f'该用户在群“{uninfo.scene.name}”关于“{keyword.result}”的B话数量为{rank[0][1]}。'
129
+ f'该用户在群“{uninfo.scene.name}”{keyword_desc}B话数量为{rank[0][1]}。'
145
130
  ).send(reply=True)
146
131
 
147
132
 
@@ -197,7 +182,6 @@ async def _group_message(
197
182
  ):
198
183
  t1 = t.time()
199
184
  state['t1'] = t1
200
- dt = get_datetime_now_with_timezone()
201
185
 
202
186
  if not group_id:
203
187
  group_id = session.scene.id
@@ -302,24 +286,16 @@ async def handle_rank(
302
286
 
303
287
  keyword = state['keyword']
304
288
 
305
- if plugin_config.counting_cache:
306
- await saa.Text("缓存暂不支持").finish()
307
- # if keyword:
308
- # await saa.Text('已开启缓存~缓存不支持关键词查询哦').finish()
309
- # t1 = t.time()
310
- # raw_rank = await get_cache(start, stop, id)
311
- # logger.debug(f'获取计数消息花费时间:{t.time() - t1}')
312
- else:
313
- t1 = t.time()
314
- messages = await get_message_records(
315
- scene_ids=[id],
316
- types=['message'], # 排除机器人自己发的消息
317
- time_start=start,
318
- time_stop=stop,
319
- exclude_user_ids=plugin_config.excluded_people,
320
- )
321
- raw_rank = msg_counter(messages, keyword)
322
- logger.debug(f'获取计数消息花费时间:{t.time() - t1}')
289
+ t1 = t.time()
290
+ raw_rank = await get_user_message_counts(
291
+ keyword=keyword,
292
+ scene_ids=[id],
293
+ types=['message'], # 排除机器人自己发的消息
294
+ time_start=start,
295
+ time_stop=stop,
296
+ exclude_user_ids=plugin_config.excluded_people,
297
+ )
298
+ logger.debug(f'获取计数消息花费时间:{t.time() - t1}')
323
299
 
324
300
  if not raw_rank:
325
301
  await saa.Text(
@@ -327,10 +303,15 @@ async def handle_rank(
327
303
  ).finish()
328
304
 
329
305
  rank = got_rank(raw_rank)
330
- ids = await persist_id2user_id([int(i[0]) for i in rank])
331
- for i in range(len(rank)):
332
- rank[i][0] = str(ids[i])
333
- logger.debug(rank[i])
306
+ # 必须按 user_persist_id 精确映射,不能依赖查询返回顺序
307
+ id_map = await persist_id2user_id([item[0] for item in rank])
308
+ for item in rank:
309
+ user_id = id_map.get(item[0])
310
+ if user_id is None:
311
+ logger.warning(f'未找到持久化 id {item[0]} 对应的平台用户')
312
+ user_id = str(item[0])
313
+ item[0] = user_id
314
+ logger.debug(item)
334
315
 
335
316
  t1 = t.time()
336
317
  rank2 = await get_user_infos(bot, event, rank)
@@ -0,0 +1,28 @@
1
+ from typing import List, Optional
2
+
3
+ from nonebot import get_driver, get_plugin_config
4
+ from pydantic import BaseModel
5
+
6
+
7
+ class ScopedConfig(BaseModel):
8
+ get_num: int = 5 # 获取人数数量
9
+ suffix: bool = True # 是否显示后缀
10
+ visualization: bool = True # 是否可视化
11
+ show_text_rank: bool = True # 是否显示文本排名
12
+ excluded_people: List[str] = [] # 排除的人的QQ号
13
+ use_user_info_cache: bool = False # 是否使用用户信息缓存
14
+ aggregate_transmission: bool = False # 是否聚合转发消息
15
+ timezone: Optional[str] = 'Asia/Shanghai' # 时区,影响统计时间
16
+ string_suffix: str = '统计花费时间:{timecost}秒' # 消息格式后缀
17
+ template_path: str = './template/rank_template.j2' # 模板路径
18
+ string_format: str = (
19
+ '第{index}名:\n{nickname},{chatdatanum}条消息\n' # 消息格式
20
+ )
21
+
22
+
23
+ class Config(BaseModel):
24
+ dialectlist: ScopedConfig = ScopedConfig()
25
+
26
+
27
+ global_config = get_driver().config
28
+ plugin_config = get_plugin_config(Config).dialectlist