nonebot-plugin-dialectlist 2.1.9__tar.gz → 2.2.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.1.9 → nonebot_plugin_dialectlist-2.2.0}/PKG-INFO +1 -1
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/nonebot_plugin_dialectlist/__init__.py +48 -36
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/nonebot_plugin_dialectlist/model.py +2 -2
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/nonebot_plugin_dialectlist/utils.py +36 -22
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/nonebot_plugin_dialectlist.egg-info/PKG-INFO +1 -1
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/pyproject.toml +1 -1
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/MANIFEST.in +0 -0
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/README.md +0 -0
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/nonebot_plugin_dialectlist/config.py +0 -0
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/nonebot_plugin_dialectlist/storage.py +0 -0
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/nonebot_plugin_dialectlist/template/avatar/default.jpg +0 -0
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/nonebot_plugin_dialectlist/template/avatar/master.jpg +0 -0
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/nonebot_plugin_dialectlist/template/css/style.css +0 -0
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/nonebot_plugin_dialectlist/template/rank_template.j2 +0 -0
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/nonebot_plugin_dialectlist/time.py +0 -0
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/nonebot_plugin_dialectlist/usage.py +0 -0
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/nonebot_plugin_dialectlist.egg-info/SOURCES.txt +0 -0
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/nonebot_plugin_dialectlist.egg-info/dependency_links.txt +0 -0
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/nonebot_plugin_dialectlist.egg-info/requires.txt +0 -0
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/nonebot_plugin_dialectlist.egg-info/top_level.txt +0 -0
- {nonebot_plugin_dialectlist-2.1.9 → nonebot_plugin_dialectlist-2.2.0}/setup.cfg +0 -0
|
@@ -41,8 +41,6 @@ from nonebot_plugin_alconna import (
|
|
|
41
41
|
)
|
|
42
42
|
|
|
43
43
|
from nonebot_plugin_chatrecorder import get_message_records
|
|
44
|
-
from nonebot_plugin_localstore import get_cache_file
|
|
45
|
-
from nonebot_plugin_htmlrender import html_to_pic
|
|
46
44
|
from nonebot_plugin_userinfo import get_user_info
|
|
47
45
|
from nonebot_plugin_session import Session, SessionIdType, extract_session
|
|
48
46
|
|
|
@@ -50,14 +48,19 @@ from nonebot_plugin_session import Session, SessionIdType, extract_session
|
|
|
50
48
|
# from .function import *
|
|
51
49
|
from .config import Config, plugin_config
|
|
52
50
|
from .usage import __usage__
|
|
53
|
-
from .time import
|
|
51
|
+
from .time import (
|
|
52
|
+
get_datetime_fromisoformat_with_timezone,
|
|
53
|
+
get_datetime_now_with_timezone,
|
|
54
|
+
parse_datetime,
|
|
55
|
+
)
|
|
54
56
|
from .model import UserRankInfo
|
|
55
57
|
from .utils import (
|
|
56
58
|
got_rank,
|
|
57
59
|
msg_counter,
|
|
58
60
|
persist_id2user_id,
|
|
59
61
|
user_id2persist_id,
|
|
60
|
-
|
|
62
|
+
group_id2persist_id,
|
|
63
|
+
get_rank_image,
|
|
61
64
|
)
|
|
62
65
|
|
|
63
66
|
__plugin_meta__ = PluginMetadata(
|
|
@@ -83,17 +86,20 @@ class SameTime(ArparmaBehavior):
|
|
|
83
86
|
interface.behave_fail()
|
|
84
87
|
|
|
85
88
|
|
|
86
|
-
def wrapper(slot: Union[int, str], content: Optional[str],context) -> str:
|
|
89
|
+
def wrapper(slot: Union[int, str], content: Optional[str], context) -> str:
|
|
87
90
|
if slot == "type" and content:
|
|
88
91
|
return content
|
|
89
92
|
return "" # pragma: no cover
|
|
90
93
|
|
|
94
|
+
|
|
91
95
|
rank_cmd = on_alconna(
|
|
92
96
|
Alconna(
|
|
93
97
|
"B话榜",
|
|
94
98
|
Args["type?", ["今日", "昨日", "本周", "上周", "本月", "上月", "年度", "历史"]][
|
|
95
|
-
"time?",
|
|
96
|
-
|
|
99
|
+
"time?",
|
|
100
|
+
str,
|
|
101
|
+
],
|
|
102
|
+
Option("-g|--group_id", Args["group_id?", str]),
|
|
97
103
|
behaviors=[SameTime()],
|
|
98
104
|
),
|
|
99
105
|
aliases={"废话榜"},
|
|
@@ -206,10 +212,7 @@ async def _group_message(
|
|
|
206
212
|
prompt="请输入你要查询的结束日期(如 2022-02-22)",
|
|
207
213
|
parameterless=[Depends(parse_datetime("stop"))],
|
|
208
214
|
)
|
|
209
|
-
@rank_cmd.got(
|
|
210
|
-
"group_id",
|
|
211
|
-
prompt="请输入你要查询的群号。"
|
|
212
|
-
)
|
|
215
|
+
@rank_cmd.got("group_id", prompt="请输入你要查询的群号。")
|
|
213
216
|
async def handle_rank(
|
|
214
217
|
state: T_State,
|
|
215
218
|
bot: Bot,
|
|
@@ -217,10 +220,9 @@ async def handle_rank(
|
|
|
217
220
|
session: Session = Depends(extract_session),
|
|
218
221
|
start: datetime = Arg(),
|
|
219
222
|
stop: datetime = Arg(),
|
|
220
|
-
# group_id: str = Arg(),
|
|
221
223
|
):
|
|
222
224
|
if id := state["group_id"]:
|
|
223
|
-
|
|
225
|
+
id = str(id)
|
|
224
226
|
logger.debug(f"group_id: {id}")
|
|
225
227
|
else:
|
|
226
228
|
id = session.id2
|
|
@@ -239,10 +241,10 @@ async def handle_rank(
|
|
|
239
241
|
time_stop=stop,
|
|
240
242
|
exclude_id1s=plugin_config.excluded_people,
|
|
241
243
|
)
|
|
242
|
-
|
|
244
|
+
|
|
243
245
|
if not messages:
|
|
244
246
|
await saa.Text("明明这个时间段都没有人说话怎么会有话痨榜呢?").finish()
|
|
245
|
-
|
|
247
|
+
|
|
246
248
|
rank = got_rank(msg_counter(messages))
|
|
247
249
|
logger.debug(rank)
|
|
248
250
|
rank2: List[UserRankInfo] = []
|
|
@@ -256,37 +258,47 @@ async def handle_rank(
|
|
|
256
258
|
for i in rank:
|
|
257
259
|
if user_info := await get_user_info(bot, event, user_id=str(i[0])):
|
|
258
260
|
logger.debug(user_info)
|
|
259
|
-
user_nickname =
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
261
|
+
user_nickname = (
|
|
262
|
+
user_info.user_displayname
|
|
263
|
+
if user_info.user_displayname
|
|
264
|
+
else user_info.user_name if user_info.user_name else user_info.user_id
|
|
265
|
+
)
|
|
266
|
+
user_avatar = (
|
|
267
|
+
await user_info.user_avatar.get_image()
|
|
268
|
+
if user_info.user_avatar
|
|
269
|
+
else open(
|
|
270
|
+
os.path.dirname(os.path.abspath(__file__))
|
|
271
|
+
+ "/template/avatar/default.jpg",
|
|
272
|
+
"rb",
|
|
273
|
+
).read()
|
|
274
|
+
)
|
|
275
|
+
user = UserRankInfo(
|
|
276
|
+
**model_dump(user_info),
|
|
277
|
+
user_bnum=i[1],
|
|
278
|
+
user_proportion=round(i[1] / total * 100, 2),
|
|
279
|
+
user_index=cn2an.an2cn(index),
|
|
280
|
+
user_nickname=user_nickname,
|
|
281
|
+
user_avatar_bytes=user_avatar,
|
|
282
|
+
)
|
|
283
|
+
user.user_gender = (
|
|
284
|
+
"她"
|
|
285
|
+
if user_info.user_gender == "female"
|
|
286
|
+
else "他" if user_info.user_gender == "male" else "ta"
|
|
274
287
|
)
|
|
275
|
-
user.user_gender="她" if user_info.user_gender == "female" else "他" if user_info.user_gender == "male" else "ta"
|
|
276
288
|
rank2.append(user)
|
|
277
289
|
index += 1
|
|
278
|
-
|
|
290
|
+
|
|
279
291
|
string: str = ""
|
|
280
292
|
for i in rank2:
|
|
281
293
|
logger.debug(i.user_name)
|
|
282
294
|
for i in range(len(rank2)):
|
|
283
295
|
str_example = plugin_config.string_format.format(
|
|
284
|
-
index=rank2[i].user_index,
|
|
285
|
-
nickname=rank2[i].user_nickname,
|
|
286
|
-
chatdatanum=rank2[i].user_bnum
|
|
296
|
+
index=rank2[i].user_index,
|
|
297
|
+
nickname=rank2[i].user_nickname,
|
|
298
|
+
chatdatanum=rank2[i].user_bnum,
|
|
287
299
|
)
|
|
288
300
|
string += str_example
|
|
289
|
-
|
|
301
|
+
|
|
290
302
|
image = await get_rank_image(rank2)
|
|
291
303
|
|
|
292
304
|
await (saa.Text(string) + saa.Image(image)).finish(reply=True)
|
|
@@ -16,7 +16,7 @@ from nonebot_plugin_orm import get_session
|
|
|
16
16
|
from nonebot_plugin_session import Session, SessionLevel, extract_session
|
|
17
17
|
from nonebot_plugin_session_orm import SessionModel
|
|
18
18
|
from nonebot_plugin_userinfo import EventUserInfo, UserInfo
|
|
19
|
-
from nonebot_plugin_htmlrender import html_to_pic,template_to_pic
|
|
19
|
+
from nonebot_plugin_htmlrender import html_to_pic, template_to_pic
|
|
20
20
|
from nonebot_plugin_apscheduler import scheduler
|
|
21
21
|
from nonebot_plugin_chatrecorder import MessageRecord
|
|
22
22
|
from nonebot_plugin_localstore import get_cache_dir
|
|
@@ -49,7 +49,7 @@ async def persist_id2user_id(ids: List) -> List[str]:
|
|
|
49
49
|
user_ids = []
|
|
50
50
|
async with get_session() as db_session:
|
|
51
51
|
for i in ids:
|
|
52
|
-
user_id = (await db_session.scalar(select(SessionModel).where(or_(*[SessionModel.id == i])))).id1
|
|
52
|
+
user_id = (await db_session.scalar(select(SessionModel).where(or_(*[SessionModel.id == i])))).id1 # type: ignore
|
|
53
53
|
user_ids.append(user_id)
|
|
54
54
|
return user_ids
|
|
55
55
|
|
|
@@ -65,16 +65,15 @@ async def user_id2persist_id(ids: List[str]) -> List[int]:
|
|
|
65
65
|
records = (await db_session.scalars(statement)).all()
|
|
66
66
|
return [i.id for i in records]
|
|
67
67
|
|
|
68
|
+
|
|
68
69
|
async def group_id2persist_id(ids: List[str]) -> List[int]:
|
|
69
|
-
|
|
70
|
-
whereclause.append(or_(*[SessionModel.id2 == id for id in ids]))
|
|
71
|
-
statement = (
|
|
72
|
-
select(SessionModel).where(*whereclause)
|
|
73
|
-
# .join(SessionModel, SessionModel.id == MessageRecord.session_persist_id)
|
|
74
|
-
)
|
|
70
|
+
persist_ids = []
|
|
75
71
|
async with get_session() as db_session:
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
for i in ids:
|
|
73
|
+
persist_id = (await db_session.scalar(select(SessionModel).where(or_(*[SessionModel.id2 == i])))).id # type: ignore
|
|
74
|
+
persist_ids.append(persist_id)
|
|
75
|
+
return persist_ids
|
|
76
|
+
|
|
78
77
|
|
|
79
78
|
async def persist_id2group_id(ids: List[str]) -> List[str]:
|
|
80
79
|
whereclause: List[ColumnElement[bool]] = []
|
|
@@ -87,6 +86,7 @@ async def persist_id2group_id(ids: List[str]) -> List[str]:
|
|
|
87
86
|
records = (await db_session.scalars(statement)).all()
|
|
88
87
|
return [i.id2 for i in records]
|
|
89
88
|
|
|
89
|
+
|
|
90
90
|
def msg_counter(msg_list: List[MessageRecord]) -> Dict[str, int]:
|
|
91
91
|
"""### 计算每个人的消息量
|
|
92
92
|
|
|
@@ -137,6 +137,7 @@ def got_rank(msg_dict: Dict[str, int]) -> List:
|
|
|
137
137
|
|
|
138
138
|
return rank
|
|
139
139
|
|
|
140
|
+
|
|
140
141
|
def remove_control_characters(string: str) -> str:
|
|
141
142
|
"""### 将字符串中的控制符去除
|
|
142
143
|
|
|
@@ -148,27 +149,40 @@ def remove_control_characters(string: str) -> str:
|
|
|
148
149
|
"""
|
|
149
150
|
return "".join(ch for ch in string if unicodedata.category(ch)[0] != "C")
|
|
150
151
|
|
|
152
|
+
|
|
151
153
|
async def get_rank_image(rank: List[UserRankInfo]) -> bytes:
|
|
152
154
|
for i in rank:
|
|
153
155
|
if i.user_avatar:
|
|
154
156
|
try:
|
|
155
157
|
user_avatar = i.user_avatar_bytes
|
|
156
158
|
except NotImplementedError:
|
|
157
|
-
user_avatar = open(
|
|
159
|
+
user_avatar = open(
|
|
160
|
+
os.path.dirname(os.path.abspath(__file__))
|
|
161
|
+
+ "/template/avatar/default.jpg",
|
|
162
|
+
"rb",
|
|
163
|
+
).read()
|
|
158
164
|
# if not os.path.exists(cache_path / str(i.user_id)):
|
|
159
165
|
with open(cache_path / (str(i.user_id) + ".jpg"), "wb") as f:
|
|
160
166
|
f.write(user_avatar)
|
|
161
|
-
|
|
162
|
-
if plugin_config.template_path[:2] ==
|
|
163
|
-
path =
|
|
167
|
+
|
|
168
|
+
if plugin_config.template_path[:2] == "./":
|
|
169
|
+
path = (
|
|
170
|
+
os.path.dirname(os.path.abspath(__file__)) + plugin_config.template_path[1:]
|
|
171
|
+
)
|
|
164
172
|
else:
|
|
165
173
|
path = plugin_config.template_path
|
|
166
|
-
|
|
174
|
+
|
|
167
175
|
path_dir, filename = os.path.split(path)
|
|
168
|
-
logger.debug(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
176
|
+
logger.debug(
|
|
177
|
+
os.path.dirname(os.path.abspath(__file__)) + plugin_config.template_path[1:]
|
|
178
|
+
)
|
|
179
|
+
return await template_to_pic(
|
|
180
|
+
path_dir,
|
|
181
|
+
filename,
|
|
182
|
+
{
|
|
183
|
+
"users": rank,
|
|
184
|
+
"cache_path": cache_path,
|
|
185
|
+
"file_path": os.path.dirname(os.path.abspath(__file__)),
|
|
186
|
+
},
|
|
187
|
+
pages={"viewport": {"width": 1100, "height": 10}},
|
|
188
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|