nonebot-plugin-dialectlist 1.3.3__tar.gz → 2.0.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.
- nonebot_plugin_dialectlist-2.0.0/PKG-INFO +148 -0
- nonebot_plugin_dialectlist-2.0.0/README.md +129 -0
- nonebot_plugin_dialectlist-2.0.0/nonebot_plugin_dialectlist/__init__.py +265 -0
- nonebot_plugin_dialectlist-2.0.0/nonebot_plugin_dialectlist/config.py +29 -0
- nonebot_plugin_dialectlist-2.0.0/nonebot_plugin_dialectlist/utils.py +442 -0
- nonebot_plugin_dialectlist-2.0.0/nonebot_plugin_dialectlist.egg-info/PKG-INFO +148 -0
- {nonebot-plugin-dialectlist-1.3.3 → nonebot_plugin_dialectlist-2.0.0}/nonebot_plugin_dialectlist.egg-info/SOURCES.txt +2 -2
- nonebot_plugin_dialectlist-2.0.0/nonebot_plugin_dialectlist.egg-info/requires.txt +11 -0
- nonebot_plugin_dialectlist-2.0.0/pyproject.toml +35 -0
- nonebot-plugin-dialectlist-1.3.3/PKG-INFO +0 -12
- nonebot-plugin-dialectlist-1.3.3/README.md +0 -107
- nonebot-plugin-dialectlist-1.3.3/nonebot_plugin_dialectlist/__init__.py +0 -206
- nonebot-plugin-dialectlist-1.3.3/nonebot_plugin_dialectlist/config.py +0 -19
- nonebot-plugin-dialectlist-1.3.3/nonebot_plugin_dialectlist/function.py +0 -191
- nonebot-plugin-dialectlist-1.3.3/nonebot_plugin_dialectlist.egg-info/PKG-INFO +0 -12
- nonebot-plugin-dialectlist-1.3.3/nonebot_plugin_dialectlist.egg-info/requires.txt +0 -6
- nonebot-plugin-dialectlist-1.3.3/setup.py +0 -19
- {nonebot-plugin-dialectlist-1.3.3 → nonebot_plugin_dialectlist-2.0.0}/nonebot_plugin_dialectlist.egg-info/dependency_links.txt +0 -0
- {nonebot-plugin-dialectlist-1.3.3 → nonebot_plugin_dialectlist-2.0.0}/nonebot_plugin_dialectlist.egg-info/top_level.txt +0 -0
- {nonebot-plugin-dialectlist-1.3.3 → nonebot_plugin_dialectlist-2.0.0}/setup.cfg +0 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: nonebot_plugin_dialectlist
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Default template for PDM package
|
|
5
|
+
Author-email: Chen_Xu233 <woyerpa@outlook.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: <4.0,>=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Requires-Dist: nonebot2>=2.3.1
|
|
10
|
+
Requires-Dist: nonebot-plugin-chatrecorder>=0.6.0
|
|
11
|
+
Requires-Dist: pygal>=3.0.4
|
|
12
|
+
Requires-Dist: requests>=2.32.3
|
|
13
|
+
Requires-Dist: nonebot-plugin-apscheduler>=0.4.0
|
|
14
|
+
Requires-Dist: nonebot-plugin-alconna>=0.46.6
|
|
15
|
+
Requires-Dist: nonebot-plugin-cesaa>=0.4.0
|
|
16
|
+
Requires-Dist: nonebot-plugin-userinfo>=0.2.4
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: ruff>=0.4.9; extra == "dev"
|
|
19
|
+
|
|
20
|
+
<div align="center">
|
|
21
|
+
<a href="https://v2.nonebot.dev/store"><img src="https://s2.loli.net/2022/06/16/opBDE8Swad5rU3n.png" width="180" height="180" alt="NoneBotPluginLogo"></a>
|
|
22
|
+
<br>
|
|
23
|
+
<p><img src="https://s2.loli.net/2022/06/16/xsVUGRrkbn1ljTD.png" width="240" alt="NoneBotPluginText"></p>
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<div align="center">
|
|
27
|
+
|
|
28
|
+
# 话痨排行榜
|
|
29
|
+
nonebot-plugin-dialectlist
|
|
30
|
+
|
|
31
|
+
\>💬**看看群友们这些天在群里水了多少话**💬<
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
## 💿安装
|
|
35
|
+
|
|
36
|
+
通过`pip`或`nb`安装;
|
|
37
|
+
|
|
38
|
+
>**通过 pip **安装
|
|
39
|
+
|
|
40
|
+
`pip install nonebot-plugin-dialectlist`
|
|
41
|
+
|
|
42
|
+
>**通过 nb **安装
|
|
43
|
+
|
|
44
|
+
`nb plugin install nonebot-plugin-dialectlist`
|
|
45
|
+
|
|
46
|
+
### ✅插件依赖于
|
|
47
|
+
|
|
48
|
+
1. [nonebot-plugin-datastore](https://github.com/he0119/nonebot-plugin-datastore) ————储存历史的消息
|
|
49
|
+
2. saa 和 定时管理 (下次写个更清晰的)
|
|
50
|
+
|
|
51
|
+
## ⚙配置
|
|
52
|
+
|
|
53
|
+
需要**提前配置**本插件所**依赖的插件**!
|
|
54
|
+
|
|
55
|
+
在 .env 中,可以添加以下配置项
|
|
56
|
+
```python
|
|
57
|
+
dialectlist__string_format = '第{index}名:\n{nickname},{chatdatanum}条消息、n' #消息格式
|
|
58
|
+
dialectlist__string_suffix_format = '你们的职业是水群吗?————MYX\n 计算花费时间:{timecost}秒' #消息后缀格式
|
|
59
|
+
dialectlist__get_num = 10 #获取人数数量
|
|
60
|
+
dialectlist__visualization = True #是否可视化
|
|
61
|
+
dialectlist__visualization_type = '圆环图' #可视化方案
|
|
62
|
+
dialectlist__font = 'SimHei'#字体格式
|
|
63
|
+
dialectlist__excluded_people = []#排除的人的 QQ 号(或频道号?(未经测试))
|
|
64
|
+
dialectlist__excluded_self = True #是否排除机器人自己 QQ
|
|
65
|
+
```
|
|
66
|
+
💭也可以不进行配置,这将会使插件按照默认配置运行
|
|
67
|
+
|
|
68
|
+
### ⚠ 注意!!
|
|
69
|
+
|
|
70
|
+
需要提前安装好 [GTK+](https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer)(仅 Windows 环境下需要安装 GTK+)
|
|
71
|
+
|
|
72
|
+
在 Windows 以外的环境中可能不存在插件默认的字体!请自行改为系统中拥有的字体!
|
|
73
|
+
|
|
74
|
+
## 🗨命令
|
|
75
|
+
__!!注意!!__
|
|
76
|
+
新版本指令调用方式改变,改为更易理解也更好打的 B 话榜。
|
|
77
|
+
所以下面的调用需要把群话痨改成 B 话,排行榜改成榜。
|
|
78
|
+
即 群话痨 -> B 话 , 排行榜 -> 榜
|
|
79
|
+
比如 今日群话痨排行榜 -> 今日 B 话榜
|
|
80
|
+
以此类推。
|
|
81
|
+
|
|
82
|
+
-`/群话痨排行榜` ————看看有史以来(机器人存在以来)群友们发了多少消息!
|
|
83
|
+
|
|
84
|
+
-`/今日群话痨排行榜` ————看看今天的群友发了多少消息!
|
|
85
|
+
|
|
86
|
+
-`/昨日群话痨排行榜` ————看看昨天的群友发了多少消息!
|
|
87
|
+
|
|
88
|
+
-`/前日群话痨排行榜` ————看看前天的群友发了多少消息!
|
|
89
|
+
|
|
90
|
+
-`/本周群话痨排行榜` ————看看本周的群友发了多少消息!
|
|
91
|
+
|
|
92
|
+
-`/上周群话痨排行榜` ————看看上周的群友发了多少消息!
|
|
93
|
+
|
|
94
|
+
-`/本月群话痨排行榜` ————看看这个月的群友发了多少消息!
|
|
95
|
+
|
|
96
|
+
-`/年度群话痨排行榜` ————看看今年的群友发了多少消息!
|
|
97
|
+
|
|
98
|
+
-`/历史群话痨排行榜` ————看看历史上(机器人存在以来)的群友发了多少消息!
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
## 📖版本
|
|
102
|
+
|
|
103
|
+
### V1.0
|
|
104
|
+
|
|
105
|
+
- 看看群里群友能有多话痨
|
|
106
|
+
|
|
107
|
+
### V1.1
|
|
108
|
+
|
|
109
|
+
- 支持频道咯!(*^_^*)
|
|
110
|
+
|
|
111
|
+
### V1.2
|
|
112
|
+
|
|
113
|
+
- 排行榜可视化
|
|
114
|
+
|
|
115
|
+
### V1.3
|
|
116
|
+
|
|
117
|
+
- 添加了一些可配置项
|
|
118
|
+
|
|
119
|
+
### V1.4
|
|
120
|
+
|
|
121
|
+
- 适配新版本的 chatrecorder, 暂时停止频道支持
|
|
122
|
+
|
|
123
|
+
### V2.0
|
|
124
|
+
|
|
125
|
+
- 理论支持全平台!暂停图片支持。
|
|
126
|
+
|
|
127
|
+
## 💧另外
|
|
128
|
+
|
|
129
|
+
### 感谢
|
|
130
|
+
|
|
131
|
+
本插件的__init__.py 中的处理函数参考了词云中的方法 ~~(其实大部分都是 Ctrl+C Ctr+V)~~
|
|
132
|
+
|
|
133
|
+
[nonebot-plugin-wordcloud](https://github.com/he0119/nonebot-plugin-wordcloud)
|
|
134
|
+
|
|
135
|
+
## TODO
|
|
136
|
+
|
|
137
|
+
- [x] 适配全平台
|
|
138
|
+
|
|
139
|
+
- [ ] 私聊的查询(超级用户可以任意查询群聊的信息)
|
|
140
|
+
|
|
141
|
+
- [ ] 关键词查询
|
|
142
|
+
|
|
143
|
+
- [ ] 尝试利用 jinja2 模板引擎制作可视化图片 (((真的可以吗?))
|
|
144
|
+
|
|
145
|
+
待补充。.....
|
|
146
|
+
|
|
147
|
+
## 题外话
|
|
148
|
+
~~整个项目快被我写成屎山了~~
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://v2.nonebot.dev/store"><img src="https://s2.loli.net/2022/06/16/opBDE8Swad5rU3n.png" width="180" height="180" 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
|
+
nonebot-plugin-dialectlist
|
|
11
|
+
|
|
12
|
+
\>💬**看看群友们这些天在群里水了多少话**💬<
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
## 💿安装
|
|
16
|
+
|
|
17
|
+
通过`pip`或`nb`安装;
|
|
18
|
+
|
|
19
|
+
>**通过 pip **安装
|
|
20
|
+
|
|
21
|
+
`pip install nonebot-plugin-dialectlist`
|
|
22
|
+
|
|
23
|
+
>**通过 nb **安装
|
|
24
|
+
|
|
25
|
+
`nb plugin install nonebot-plugin-dialectlist`
|
|
26
|
+
|
|
27
|
+
### ✅插件依赖于
|
|
28
|
+
|
|
29
|
+
1. [nonebot-plugin-datastore](https://github.com/he0119/nonebot-plugin-datastore) ————储存历史的消息
|
|
30
|
+
2. saa 和 定时管理 (下次写个更清晰的)
|
|
31
|
+
|
|
32
|
+
## ⚙配置
|
|
33
|
+
|
|
34
|
+
需要**提前配置**本插件所**依赖的插件**!
|
|
35
|
+
|
|
36
|
+
在 .env 中,可以添加以下配置项
|
|
37
|
+
```python
|
|
38
|
+
dialectlist__string_format = '第{index}名:\n{nickname},{chatdatanum}条消息、n' #消息格式
|
|
39
|
+
dialectlist__string_suffix_format = '你们的职业是水群吗?————MYX\n 计算花费时间:{timecost}秒' #消息后缀格式
|
|
40
|
+
dialectlist__get_num = 10 #获取人数数量
|
|
41
|
+
dialectlist__visualization = True #是否可视化
|
|
42
|
+
dialectlist__visualization_type = '圆环图' #可视化方案
|
|
43
|
+
dialectlist__font = 'SimHei'#字体格式
|
|
44
|
+
dialectlist__excluded_people = []#排除的人的 QQ 号(或频道号?(未经测试))
|
|
45
|
+
dialectlist__excluded_self = True #是否排除机器人自己 QQ
|
|
46
|
+
```
|
|
47
|
+
💭也可以不进行配置,这将会使插件按照默认配置运行
|
|
48
|
+
|
|
49
|
+
### ⚠ 注意!!
|
|
50
|
+
|
|
51
|
+
需要提前安装好 [GTK+](https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer)(仅 Windows 环境下需要安装 GTK+)
|
|
52
|
+
|
|
53
|
+
在 Windows 以外的环境中可能不存在插件默认的字体!请自行改为系统中拥有的字体!
|
|
54
|
+
|
|
55
|
+
## 🗨命令
|
|
56
|
+
__!!注意!!__
|
|
57
|
+
新版本指令调用方式改变,改为更易理解也更好打的 B 话榜。
|
|
58
|
+
所以下面的调用需要把群话痨改成 B 话,排行榜改成榜。
|
|
59
|
+
即 群话痨 -> B 话 , 排行榜 -> 榜
|
|
60
|
+
比如 今日群话痨排行榜 -> 今日 B 话榜
|
|
61
|
+
以此类推。
|
|
62
|
+
|
|
63
|
+
-`/群话痨排行榜` ————看看有史以来(机器人存在以来)群友们发了多少消息!
|
|
64
|
+
|
|
65
|
+
-`/今日群话痨排行榜` ————看看今天的群友发了多少消息!
|
|
66
|
+
|
|
67
|
+
-`/昨日群话痨排行榜` ————看看昨天的群友发了多少消息!
|
|
68
|
+
|
|
69
|
+
-`/前日群话痨排行榜` ————看看前天的群友发了多少消息!
|
|
70
|
+
|
|
71
|
+
-`/本周群话痨排行榜` ————看看本周的群友发了多少消息!
|
|
72
|
+
|
|
73
|
+
-`/上周群话痨排行榜` ————看看上周的群友发了多少消息!
|
|
74
|
+
|
|
75
|
+
-`/本月群话痨排行榜` ————看看这个月的群友发了多少消息!
|
|
76
|
+
|
|
77
|
+
-`/年度群话痨排行榜` ————看看今年的群友发了多少消息!
|
|
78
|
+
|
|
79
|
+
-`/历史群话痨排行榜` ————看看历史上(机器人存在以来)的群友发了多少消息!
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
## 📖版本
|
|
83
|
+
|
|
84
|
+
### V1.0
|
|
85
|
+
|
|
86
|
+
- 看看群里群友能有多话痨
|
|
87
|
+
|
|
88
|
+
### V1.1
|
|
89
|
+
|
|
90
|
+
- 支持频道咯!(*^_^*)
|
|
91
|
+
|
|
92
|
+
### V1.2
|
|
93
|
+
|
|
94
|
+
- 排行榜可视化
|
|
95
|
+
|
|
96
|
+
### V1.3
|
|
97
|
+
|
|
98
|
+
- 添加了一些可配置项
|
|
99
|
+
|
|
100
|
+
### V1.4
|
|
101
|
+
|
|
102
|
+
- 适配新版本的 chatrecorder, 暂时停止频道支持
|
|
103
|
+
|
|
104
|
+
### V2.0
|
|
105
|
+
|
|
106
|
+
- 理论支持全平台!暂停图片支持。
|
|
107
|
+
|
|
108
|
+
## 💧另外
|
|
109
|
+
|
|
110
|
+
### 感谢
|
|
111
|
+
|
|
112
|
+
本插件的__init__.py 中的处理函数参考了词云中的方法 ~~(其实大部分都是 Ctrl+C Ctr+V)~~
|
|
113
|
+
|
|
114
|
+
[nonebot-plugin-wordcloud](https://github.com/he0119/nonebot-plugin-wordcloud)
|
|
115
|
+
|
|
116
|
+
## TODO
|
|
117
|
+
|
|
118
|
+
- [x] 适配全平台
|
|
119
|
+
|
|
120
|
+
- [ ] 私聊的查询(超级用户可以任意查询群聊的信息)
|
|
121
|
+
|
|
122
|
+
- [ ] 关键词查询
|
|
123
|
+
|
|
124
|
+
- [ ] 尝试利用 jinja2 模板引擎制作可视化图片 (((真的可以吗?))
|
|
125
|
+
|
|
126
|
+
待补充。.....
|
|
127
|
+
|
|
128
|
+
## 题外话
|
|
129
|
+
~~整个项目快被我写成屎山了~~
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
from nonebot import require
|
|
2
|
+
|
|
3
|
+
require("nonebot_plugin_chatrecorder")
|
|
4
|
+
require("nonebot_plugin_apscheduler")
|
|
5
|
+
require("nonebot_plugin_userinfo")
|
|
6
|
+
require("nonebot_plugin_alconna")
|
|
7
|
+
require("nonebot_plugin_cesaa")
|
|
8
|
+
|
|
9
|
+
import re
|
|
10
|
+
import os
|
|
11
|
+
import time
|
|
12
|
+
|
|
13
|
+
import nonebot_plugin_saa as saa
|
|
14
|
+
|
|
15
|
+
from typing import Tuple, Union, Optional, List
|
|
16
|
+
from datetime import datetime, timedelta
|
|
17
|
+
from arclet.alconna import ArparmaBehavior
|
|
18
|
+
from arclet.alconna.arparma import Arparma
|
|
19
|
+
|
|
20
|
+
from nonebot import on_command, get_driver
|
|
21
|
+
from nonebot.log import logger
|
|
22
|
+
from nonebot.params import Command, CommandArg, Arg, Depends
|
|
23
|
+
from nonebot.typing import T_State
|
|
24
|
+
from nonebot.matcher import Matcher
|
|
25
|
+
from nonebot import get_driver
|
|
26
|
+
from nonebot.adapters import Bot, Event, Message
|
|
27
|
+
from nonebot.params import Arg, Depends
|
|
28
|
+
from nonebot.permission import SUPERUSER
|
|
29
|
+
from nonebot.plugin import PluginMetadata, inherit_supported_adapters
|
|
30
|
+
from nonebot.typing import T_State
|
|
31
|
+
from nonebot_plugin_alconna import (
|
|
32
|
+
Alconna,
|
|
33
|
+
AlconnaMatch,
|
|
34
|
+
AlconnaMatcher,
|
|
35
|
+
AlconnaQuery,
|
|
36
|
+
Args,
|
|
37
|
+
Match,
|
|
38
|
+
Option,
|
|
39
|
+
Query,
|
|
40
|
+
image_fetch,
|
|
41
|
+
on_alconna,
|
|
42
|
+
store_true,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
from nonebot_plugin_chatrecorder import get_message_records
|
|
46
|
+
from nonebot_plugin_userinfo import EventUserInfo, UserInfo, get_user_info
|
|
47
|
+
from nonebot_plugin_session import Session, SessionIdType, extract_session
|
|
48
|
+
from nonebot_plugin_cesaa import get_messages_plain_text
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# from . import migrations #抄词云的部分代码,还不知道这有什么用
|
|
52
|
+
# from .function import *
|
|
53
|
+
from .config import Config, plugin_config
|
|
54
|
+
from .utils import (
|
|
55
|
+
get_datetime_fromisoformat_with_timezone,
|
|
56
|
+
get_datetime_now_with_timezone,
|
|
57
|
+
got_rank,
|
|
58
|
+
msg_counter,
|
|
59
|
+
persist_id2user_id,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
with open(os.path.dirname(__file__) + "/usage.md") as f:
|
|
63
|
+
usage = f.read()
|
|
64
|
+
|
|
65
|
+
__plugin_meta__ = PluginMetadata(
|
|
66
|
+
name="B话排行榜",
|
|
67
|
+
description="调查群U的B话数量,以一定的顺序排序后排序出来。",
|
|
68
|
+
usage=usage,
|
|
69
|
+
homepage="https://github.com/ChenXu233/nonebot_plugin_dialectlist",
|
|
70
|
+
type="application",
|
|
71
|
+
supported_adapters=inherit_supported_adapters(
|
|
72
|
+
"nonebot_plugin_chatrecorder", "nonebot_plugin_saa", "nonebot_plugin_alconna"
|
|
73
|
+
),
|
|
74
|
+
config=Config,
|
|
75
|
+
# extra={"orm_version_location": migrations},
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# 抄的词云,不过真的很适合B话榜。
|
|
80
|
+
class SameTime(ArparmaBehavior):
|
|
81
|
+
def operate(self, interface: Arparma):
|
|
82
|
+
type = interface.query("type")
|
|
83
|
+
time = interface.query("time")
|
|
84
|
+
if type is None and time:
|
|
85
|
+
interface.behave_fail()
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
rank_cmd = on_alconna(
|
|
89
|
+
Alconna(
|
|
90
|
+
"B话榜",
|
|
91
|
+
Args["type?", ["今日", "昨日", "本周", "上周", "本月", "上月", "年度", "历史"]][
|
|
92
|
+
"time?", str
|
|
93
|
+
],
|
|
94
|
+
behaviors=[SameTime()],
|
|
95
|
+
),
|
|
96
|
+
use_cmd_start=True,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def wrapper(slot: Union[int, str], content: Optional[str]) -> str:
|
|
101
|
+
if slot == "type" and content:
|
|
102
|
+
return content
|
|
103
|
+
return "" # pragma: no cover
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
rank_cmd.shortcut(
|
|
107
|
+
r"(?P<type>今日|昨日|本周|上周|本月|上月|年度|历史)B话榜",
|
|
108
|
+
{
|
|
109
|
+
"prefix": True,
|
|
110
|
+
"command": "B话榜 ",
|
|
111
|
+
"wrapper": wrapper,
|
|
112
|
+
"args": ["{type}"],
|
|
113
|
+
},
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def parse_datetime(key: str):
|
|
118
|
+
"""解析数字,并将结果存入 state 中"""
|
|
119
|
+
|
|
120
|
+
async def _key_parser(
|
|
121
|
+
matcher: AlconnaMatcher,
|
|
122
|
+
state: T_State,
|
|
123
|
+
input: Union[datetime, Message] = Arg(key),
|
|
124
|
+
):
|
|
125
|
+
if isinstance(input, datetime):
|
|
126
|
+
return
|
|
127
|
+
|
|
128
|
+
plaintext = input.extract_plain_text()
|
|
129
|
+
try:
|
|
130
|
+
state[key] = get_datetime_fromisoformat_with_timezone(plaintext)
|
|
131
|
+
except ValueError:
|
|
132
|
+
await matcher.reject_arg(key, "请输入正确的日期,不然我没法理解呢!")
|
|
133
|
+
|
|
134
|
+
return _key_parser
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
# TODO 处理函数更新
|
|
138
|
+
# 参考词云
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
# 这段函数完全抄的词云
|
|
142
|
+
@rank_cmd.handle()
|
|
143
|
+
async def _group_message(
|
|
144
|
+
state: T_State,
|
|
145
|
+
type: Optional[str] = None,
|
|
146
|
+
time: Optional[str] = None,
|
|
147
|
+
):
|
|
148
|
+
|
|
149
|
+
dt = get_datetime_now_with_timezone()
|
|
150
|
+
|
|
151
|
+
if not type:
|
|
152
|
+
await rank_cmd.finish(__plugin_meta__.usage)
|
|
153
|
+
|
|
154
|
+
dt = get_datetime_now_with_timezone()
|
|
155
|
+
|
|
156
|
+
if type == "今日":
|
|
157
|
+
state["start"] = dt.replace(hour=0, minute=0, second=0, microsecond=0)
|
|
158
|
+
state["stop"] = dt
|
|
159
|
+
elif type == "昨日":
|
|
160
|
+
state["stop"] = dt.replace(hour=0, minute=0, second=0, microsecond=0)
|
|
161
|
+
state["start"] = state["stop"] - timedelta(days=1)
|
|
162
|
+
elif type == "本周":
|
|
163
|
+
state["start"] = dt.replace(
|
|
164
|
+
hour=0, minute=0, second=0, microsecond=0
|
|
165
|
+
) - timedelta(days=dt.weekday())
|
|
166
|
+
state["stop"] = dt
|
|
167
|
+
elif type == "上周":
|
|
168
|
+
state["stop"] = dt.replace(
|
|
169
|
+
hour=0, minute=0, second=0, microsecond=0
|
|
170
|
+
) - timedelta(days=dt.weekday())
|
|
171
|
+
state["start"] = state["stop"] - timedelta(days=7)
|
|
172
|
+
elif type == "本月":
|
|
173
|
+
state["start"] = dt.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
|
|
174
|
+
state["stop"] = dt
|
|
175
|
+
elif type == "上月":
|
|
176
|
+
state["stop"] = dt.replace(
|
|
177
|
+
day=1, hour=0, minute=0, second=0, microsecond=0
|
|
178
|
+
) - timedelta(microseconds=1)
|
|
179
|
+
state["start"] = state["stop"].replace(
|
|
180
|
+
day=1, hour=0, minute=0, second=0, microsecond=0
|
|
181
|
+
)
|
|
182
|
+
elif type == "年度":
|
|
183
|
+
state["start"] = dt.replace(
|
|
184
|
+
month=1, day=1, hour=0, minute=0, second=0, microsecond=0
|
|
185
|
+
)
|
|
186
|
+
state["stop"] = dt
|
|
187
|
+
elif type == "历史":
|
|
188
|
+
if time:
|
|
189
|
+
plaintext = time
|
|
190
|
+
if match := re.match(r"^(.+?)(?:~(.+))?$", plaintext):
|
|
191
|
+
start = match[1]
|
|
192
|
+
stop = match[2]
|
|
193
|
+
try:
|
|
194
|
+
state["start"] = get_datetime_fromisoformat_with_timezone(start)
|
|
195
|
+
if stop:
|
|
196
|
+
state["stop"] = get_datetime_fromisoformat_with_timezone(stop)
|
|
197
|
+
else:
|
|
198
|
+
# 如果没有指定结束日期,则认为是所给日期的当天的词云
|
|
199
|
+
state["start"] = state["start"].replace(
|
|
200
|
+
hour=0, minute=0, second=0, microsecond=0
|
|
201
|
+
)
|
|
202
|
+
state["stop"] = state["start"] + timedelta(days=1)
|
|
203
|
+
except ValueError:
|
|
204
|
+
await rank_cmd.finish("请输入正确的日期,不然我没法理解呢!")
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
@rank_cmd.got(
|
|
208
|
+
"start",
|
|
209
|
+
prompt="请输入你要查询的起始日期(如 2022-01-01)",
|
|
210
|
+
parameterless=[Depends(parse_datetime("start"))],
|
|
211
|
+
)
|
|
212
|
+
@rank_cmd.got(
|
|
213
|
+
"stop",
|
|
214
|
+
prompt="请输入你要查询的结束日期(如 2022-02-22)",
|
|
215
|
+
parameterless=[Depends(parse_datetime("stop"))],
|
|
216
|
+
)
|
|
217
|
+
async def handle_rank(
|
|
218
|
+
bot: Bot,
|
|
219
|
+
event: Event,
|
|
220
|
+
session: Session = Depends(extract_session),
|
|
221
|
+
start: datetime = Arg(),
|
|
222
|
+
stop: datetime = Arg(),
|
|
223
|
+
):
|
|
224
|
+
"""生成词云"""
|
|
225
|
+
messages = await get_message_records(
|
|
226
|
+
session=session,
|
|
227
|
+
id_type=SessionIdType.GROUP,
|
|
228
|
+
include_bot_id=False,
|
|
229
|
+
include_bot_type=False,
|
|
230
|
+
types=["message"], # 排除机器人自己发的消息
|
|
231
|
+
time_start=start,
|
|
232
|
+
time_stop=stop,
|
|
233
|
+
exclude_id1s=plugin_config.excluded_people,
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
rank = got_rank(msg_counter(messages))
|
|
237
|
+
ids = await persist_id2user_id([int(i[0]) for i in rank])
|
|
238
|
+
for i in range(len(rank)):
|
|
239
|
+
rank[i][0] = str(ids[i])
|
|
240
|
+
|
|
241
|
+
string: str = ""
|
|
242
|
+
nicknames: List = []
|
|
243
|
+
for i in rank:
|
|
244
|
+
if user_info := await get_user_info(bot, event, user_id=str(i[0])):
|
|
245
|
+
(
|
|
246
|
+
nicknames.append(user_info.user_displayname)
|
|
247
|
+
if user_info.user_displayname
|
|
248
|
+
else (
|
|
249
|
+
nicknames.append(user_info.user_name)
|
|
250
|
+
if user_info.user_name
|
|
251
|
+
else nicknames.append(user_info.user_id)
|
|
252
|
+
)
|
|
253
|
+
)
|
|
254
|
+
else:
|
|
255
|
+
nicknames.append(None)
|
|
256
|
+
logger.debug(nicknames)
|
|
257
|
+
for i in range(len(rank)):
|
|
258
|
+
index = i + 1
|
|
259
|
+
nickname, chatdatanum = nicknames[i], rank[i][1]
|
|
260
|
+
str_example = plugin_config.string_format.format(
|
|
261
|
+
index=index, nickname=nickname, chatdatanum=chatdatanum
|
|
262
|
+
)
|
|
263
|
+
string += str_example
|
|
264
|
+
|
|
265
|
+
await saa.Text(string).finish(reply=True)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from typing import Optional, Literal, List
|
|
2
|
+
from nonebot import get_driver, get_plugin_config
|
|
3
|
+
from pydantic import BaseModel, field_validator
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ScopedConfig(BaseModel):
|
|
7
|
+
font: str = "SimHei" # 字体格式
|
|
8
|
+
get_num: int = 5 # 获取人数数量
|
|
9
|
+
timezone: Optional[str] = "Asia/Shanghai"
|
|
10
|
+
excluded_self: bool = True
|
|
11
|
+
string_format: str = "第{index}名:\n{nickname},{chatdatanum}条消息\n" # 消息格式
|
|
12
|
+
visualization: bool = True # 是否可视化
|
|
13
|
+
excluded_people: List[str] = [] # 排除的人的QQ号
|
|
14
|
+
visualization_type: Literal["饼图", "圆环图", "柱状图"] = "圆环图" # 可视化方案
|
|
15
|
+
|
|
16
|
+
@field_validator("get_num")
|
|
17
|
+
@classmethod
|
|
18
|
+
def check_priority(cls, v: int) -> int:
|
|
19
|
+
if v >= 1:
|
|
20
|
+
return v
|
|
21
|
+
raise ValueError("表中的人数必须大于一")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Config(BaseModel):
|
|
25
|
+
dialectlist: ScopedConfig = ScopedConfig()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
global_config = get_driver().config
|
|
29
|
+
plugin_config = get_plugin_config(Config).dialectlist
|