nonebot-plugin-splatoon3-schedule 2.0.5__tar.gz → 2.0.7__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_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/PKG-INFO +2 -1
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/__init__.py +75 -35
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/data/data_source.py +133 -6
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/data/db_image.py +1 -1
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/image/image.py +27 -4
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/image/image_processer.py +25 -5
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/db/image.db +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/util.py +20 -18
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/utils/cos_upload.py +77 -25
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/utils/translation.py +31 -2
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/utils/utils.py +21 -8
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/pyproject.toml +2 -1
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/LICENSE +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/README.md +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/check.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/config.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/data/__init__.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/data/db_control.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/data/static_data_getter.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/image/__init__.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/image/image_processer_tools.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/10024.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/10025.ico +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/10026.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/AREA.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/CLAM.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Cohozuna.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/GOAL.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Horrorboros.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/LOFT.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Megalodontia.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Random.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Ranked-Challenge.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Ranked-Open.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Ranked.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Regular.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/TURF_WAR.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Triumvirate.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/X.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/bg.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/bg2.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/bg3.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/big_run.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/black-texture.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/cat_paw_mask.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/coop.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/coop_bg2.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/coop_fish.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/coop_mask.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/event_bg.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/festival_mask.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/fight_mask.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/filleted_corner.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/private.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/swim_ring.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/team_coop.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/ImageData/time_head_bg.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/font/Splatfont1.otf +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/font/Splatfont2.otf +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/font/cn.ttf +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/resource/font/common.otf +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/utils/__init__.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/utils/bot.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/nonebot_plugin_splatoon3_schedule/utils/dataClass.py +0 -0
{nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nonebot-plugin-splatoon3-schedule
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.7
|
|
4
4
|
Summary: 一个基于nonebot2框架的splatoon3游戏日程查询插件
|
|
5
5
|
License-File: LICENSE
|
|
6
6
|
Author: cypas
|
|
@@ -27,6 +27,7 @@ Requires-Dist: nonebot2 (>=2.4.4,<3.0.0)
|
|
|
27
27
|
Requires-Dist: nonebot_plugin_datastore (>=1.3.0,<2.0.0)
|
|
28
28
|
Requires-Dist: playwright (>=1.40.0,<2.0.0)
|
|
29
29
|
Requires-Dist: pydantic (>=1.0.0,<3.0.0,!=2.5.0,!=2.5.1)
|
|
30
|
+
Requires-Dist: zhconv (>=1.4.3,<2.0.0)
|
|
30
31
|
Description-Content-Type: text/markdown
|
|
31
32
|
|
|
32
33
|
<div align="center">
|
|
@@ -35,6 +35,7 @@ matcher_stage_group = on_regex(
|
|
|
35
35
|
async def _(bot: Bot, event: Event):
|
|
36
36
|
plain_text = event.get_message().extract_plain_text().strip()
|
|
37
37
|
# 触发关键词 替换.。\/ 等前缀触发词
|
|
38
|
+
plain_text = str_convert_to_simplified(plain_text)
|
|
38
39
|
plain_text = multiple_replace(plain_text, dict_keyword_replace)
|
|
39
40
|
logger.info("同义文本替换后触发词为:" + plain_text)
|
|
40
41
|
# 判断是否满足进一步正则
|
|
@@ -99,6 +100,7 @@ matcher_stage = on_regex(
|
|
|
99
100
|
async def _(bot: Bot, event: Event, re_tuple: Tuple = RegexGroup()):
|
|
100
101
|
re_list = []
|
|
101
102
|
for k, v in enumerate(re_tuple):
|
|
103
|
+
v = str_convert_to_simplified(v)
|
|
102
104
|
# 遍历正则匹配字典进行替换文本
|
|
103
105
|
re_list.append(dict_keyword_replace.get(v, v))
|
|
104
106
|
logger.info("同义文本替换后触发词组为:" + json.dumps(re_list, ensure_ascii=False))
|
|
@@ -194,6 +196,7 @@ matcher_coop = on_regex(
|
|
|
194
196
|
@matcher_coop.handle(parameterless=[Depends(_permission_check)])
|
|
195
197
|
async def _(bot: Bot, event: Event):
|
|
196
198
|
plain_text = event.get_message().extract_plain_text().strip()
|
|
199
|
+
plain_text = str_convert_to_simplified(plain_text)
|
|
197
200
|
# 触发关键词 替换.。\/ 等前缀触发词
|
|
198
201
|
plain_text = multiple_replace(plain_text, dict_keyword_replace)
|
|
199
202
|
logger.info("同义文本替换后触发词为:" + plain_text)
|
|
@@ -211,7 +214,7 @@ async def _(bot: Bot, event: Event):
|
|
|
211
214
|
|
|
212
215
|
# 配装 触发器
|
|
213
216
|
matcher_build = on_regex(
|
|
214
|
-
"^[\\/.,,。]
|
|
217
|
+
"^[\\/.,,。]{0,1}配装[\s ]{0,2}([\u4e00-\u9fa5a-zA-Z0-9·\-/\s ]{0,20})$",
|
|
215
218
|
priority=8,
|
|
216
219
|
block=True,
|
|
217
220
|
)
|
|
@@ -220,45 +223,80 @@ matcher_build = on_regex(
|
|
|
220
223
|
# 配装 触发器处理
|
|
221
224
|
@matcher_build.handle(parameterless=[Depends(_permission_check)])
|
|
222
225
|
async def _(bot: Bot, event: Event, re_tuple: Tuple = RegexGroup()):
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
226
|
+
# 分两步处理,外层只过滤前缀,将关键词分离出来
|
|
227
|
+
keywords = re_tuple[0]
|
|
228
|
+
keywords = str(keywords).strip()
|
|
229
|
+
# 第二步再处理是否有模式选项
|
|
230
|
+
# 场景词列表(按长度从长到短排序,优先匹配长词)
|
|
231
|
+
mode_words = [
|
|
232
|
+
"推塔",
|
|
233
|
+
"抢塔",
|
|
234
|
+
"塔楼",
|
|
235
|
+
"蛤蜊",
|
|
236
|
+
"抢鱼",
|
|
237
|
+
"鱼虎",
|
|
238
|
+
"涂地",
|
|
239
|
+
"涂涂",
|
|
240
|
+
"区域",
|
|
241
|
+
"区",
|
|
242
|
+
"塔",
|
|
243
|
+
"蛤",
|
|
244
|
+
"鱼",
|
|
245
|
+
"涂",
|
|
246
|
+
]
|
|
247
|
+
# 第二步场景词剥离正则(核心:匹配末尾的最长场景词)
|
|
248
|
+
# 动态生成正则:(场景词1|场景词2|...) (长词在前)
|
|
249
|
+
mode_pattern = rf"^(.*?)({'|'.join(mode_words)})$"
|
|
250
|
+
scene_regex = re.compile(mode_pattern)
|
|
251
|
+
# 第二步:用正则剥离末尾的场景词
|
|
252
|
+
middle_text = keywords # 默认中间文本=原关键词(无场景词)
|
|
253
|
+
scene = None # 默认无场景词
|
|
254
|
+
|
|
255
|
+
# 匹配末尾的场景词
|
|
256
|
+
scene_match = scene_regex.match(keywords)
|
|
257
|
+
if scene_match:
|
|
258
|
+
# 提取剥离场景词后的中间文本(去首尾空格)
|
|
259
|
+
temp_middle = scene_match.group(1).strip()
|
|
260
|
+
# 校验中间文本长度≥2(核心约束)
|
|
261
|
+
if len(temp_middle) >= 2:
|
|
262
|
+
middle_text = temp_middle
|
|
263
|
+
scene = scene_match.group(2)
|
|
264
|
+
|
|
265
|
+
# 武器名过滤
|
|
266
|
+
middle_text = middle_text.upper()
|
|
267
|
+
middle_text = str_convert_to_simplified(middle_text)
|
|
268
|
+
middle_text = multiple_replace(middle_text, dict_builds_pre_replace)
|
|
269
|
+
if scene:
|
|
270
|
+
scene = dict_keyword_replace.get(scene, scene)
|
|
271
|
+
|
|
272
|
+
logger.info(f"同义文本替换后武器:{middle_text},模式:{scene or '全部'}")
|
|
273
|
+
|
|
274
|
+
if not middle_text:
|
|
275
|
+
msg = "请携带需要查询的武器或模式信息作为参数,若为贴牌需要加上贴牌二字,新贴牌需要加上'新贴牌' 或 '彩牌',如:\n/配装 小绿\n指定模式查询:\n/配装 贴牌碳刷 塔楼"
|
|
240
276
|
await send_msg(bot, event, msg)
|
|
241
277
|
return
|
|
242
278
|
|
|
243
279
|
# 整理参数
|
|
244
|
-
is_deco =
|
|
245
|
-
|
|
246
|
-
weapon_name
|
|
247
|
-
|
|
248
|
-
|
|
280
|
+
is_deco = 0
|
|
281
|
+
weapon_name = middle_text
|
|
282
|
+
if "新贴牌" in weapon_name or "彩牌" in weapon_name:
|
|
283
|
+
is_deco = 2
|
|
284
|
+
weapon_name = weapon_name.replace("新贴牌", "").replace("彩牌", "")
|
|
285
|
+
elif "贴牌" in weapon_name:
|
|
286
|
+
is_deco = 1
|
|
249
287
|
weapon_name = weapon_name.replace("贴牌", "")
|
|
250
288
|
|
|
251
289
|
# 查询对应武器
|
|
252
290
|
build_info = db_image.get_build_info(weapon_name, is_deco)
|
|
253
291
|
if not build_info:
|
|
254
|
-
msg = f"该关键词 {
|
|
255
|
-
logger.warning(f"该关键词未匹配到武器 {
|
|
292
|
+
msg = f"该关键词 {middle_text} 未查询到对应武器,请试试使用官方中文武器名称或其他常用名称后再试,若为贴牌需要加上'贴牌'二字,新贴牌需要加上'新贴牌' 或 '彩牌',如:\n/配装 小绿\n指定模式查询:\n/配装 贴牌碳刷 塔楼"
|
|
293
|
+
logger.warning(f"该关键词未匹配到武器 {middle_text}")
|
|
256
294
|
# 未匹配武器写到指定文件
|
|
257
295
|
file_path = Path(os.path.join(DIR_RESOURCE, "未匹配武器.txt"))
|
|
258
296
|
os.makedirs(os.path.dirname(file_path), exist_ok=True)
|
|
259
297
|
# 以追加模式打开文件,编码指定为utf-8(避免中文乱码)
|
|
260
298
|
with open(file_path, "a", encoding="utf-8") as f:
|
|
261
|
-
f.write(f"{
|
|
299
|
+
f.write(f"{middle_text}\n") # 每行一个关键词
|
|
262
300
|
|
|
263
301
|
await send_msg(bot, event, msg)
|
|
264
302
|
return
|
|
@@ -266,24 +304,23 @@ async def _(bot: Bot, event: Event, re_tuple: Tuple = RegexGroup()):
|
|
|
266
304
|
sendou_name: str = build_info.get("sendou_name")
|
|
267
305
|
|
|
268
306
|
plain_text = "配装"
|
|
269
|
-
|
|
270
|
-
plain_text
|
|
271
|
-
if
|
|
272
|
-
plain_text
|
|
307
|
+
zh_name = f'{zh_name.replace(" ", "")}'
|
|
308
|
+
plain_text += f" {zh_name}"
|
|
309
|
+
if scene:
|
|
310
|
+
plain_text += f" {scene}"
|
|
273
311
|
|
|
274
312
|
# mode
|
|
275
|
-
if
|
|
276
|
-
|
|
277
|
-
mode_str = mode
|
|
313
|
+
if scene:
|
|
314
|
+
mode_str = scene
|
|
278
315
|
else:
|
|
279
316
|
mode_str = "全部"
|
|
280
|
-
msg = f"正在获取武器 {
|
|
317
|
+
msg = f"正在获取武器 {zh_name} 在 {mode_str}模式下的配装推荐,请稍等..."
|
|
281
318
|
await send_msg(bot, event, msg)
|
|
282
319
|
|
|
283
320
|
# 传递函数指针
|
|
284
321
|
func = get_build_image
|
|
285
322
|
# 获取图片
|
|
286
|
-
is_cache, img = await get_save_temp_image(plain_text, func, sendou_name,
|
|
323
|
+
is_cache, img = await get_save_temp_image(plain_text, func, sendou_name, mode_str)
|
|
287
324
|
# 发送图片
|
|
288
325
|
await send_msg(bot, event, img, is_cache=is_cache)
|
|
289
326
|
|
|
@@ -300,6 +337,7 @@ matcher_else = on_regex(
|
|
|
300
337
|
@matcher_else.handle(parameterless=[Depends(_permission_check)])
|
|
301
338
|
async def _(bot: Bot, event: Event):
|
|
302
339
|
plain_text = event.get_message().extract_plain_text().strip()
|
|
340
|
+
plain_text = str_convert_to_simplified(plain_text)
|
|
303
341
|
# 触发关键词 替换.。\/ 等前缀触发词
|
|
304
342
|
plain_text = multiple_replace(plain_text, dict_prefix_replace)
|
|
305
343
|
plain_text = plain_text.replace("help", "帮助")
|
|
@@ -376,6 +414,7 @@ matcher_manage = on_regex(
|
|
|
376
414
|
async def _(bot: Bot, event: Event, state: T_State, re_tuple: Tuple = RegexGroup()):
|
|
377
415
|
re_list = []
|
|
378
416
|
for k, v in enumerate(re_tuple):
|
|
417
|
+
v = str_convert_to_simplified(v)
|
|
379
418
|
re_list.append(v)
|
|
380
419
|
# 触发关键词 替换.。\/ 等前缀触发词
|
|
381
420
|
plain_text = event.get_message().extract_plain_text().strip()
|
|
@@ -433,6 +472,7 @@ matcher_admin = on_regex(
|
|
|
433
472
|
async def _(bot: Bot, event: Event):
|
|
434
473
|
# 触发关键词 替换.。\/ 等前缀触发词
|
|
435
474
|
plain_text = event.get_message().extract_plain_text().strip()
|
|
475
|
+
plain_text = str_convert_to_simplified(plain_text)
|
|
436
476
|
plain_text = multiple_replace(plain_text, dict_prefix_replace)
|
|
437
477
|
err_msg = "执行失败,错误日志为: "
|
|
438
478
|
# 清空图片缓存
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
1
3
|
from playwright.async_api import Browser, async_playwright
|
|
2
4
|
from playwright.sync_api import FloatRect
|
|
3
5
|
|
|
@@ -75,8 +77,8 @@ def get_coop_info(_all=None):
|
|
|
75
77
|
return [
|
|
76
78
|
ImageInfo(
|
|
77
79
|
name=sch["setting"]["weapons"][_i]["name"]
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
+ "_"
|
|
81
|
+
+ sch["setting"]["weapons"][_i]["__splatoon3ink_id"],
|
|
80
82
|
url=sch["setting"]["weapons"][_i]["image"]["url"],
|
|
81
83
|
zh_name=get_trans_weapon(
|
|
82
84
|
sch["setting"]["weapons"][_i]["__splatoon3ink_id"]
|
|
@@ -267,6 +269,131 @@ def get_stage_info(num_list=None, contest_match=None, rule_match=None):
|
|
|
267
269
|
return schedule, num_list, new_contest_match, new_rule_match
|
|
268
270
|
|
|
269
271
|
|
|
272
|
+
def get_newest_event_or_coop():
|
|
273
|
+
"""
|
|
274
|
+
取最新活动或者团工数据
|
|
275
|
+
:return: 文本拼接为 (今天/明天/后天),周一X时会有(活动/团工/BigRun) (名称)
|
|
276
|
+
"""
|
|
277
|
+
|
|
278
|
+
def check_date_relation(target_dt: datetime.datetime) -> tuple:
|
|
279
|
+
"""
|
|
280
|
+
判断指定 datetime 日期是今天/明天/后天,并返回是否近期、日期关系、周几描述
|
|
281
|
+
|
|
282
|
+
参数:
|
|
283
|
+
target_dt: 待判断的 datetime 类型日期
|
|
284
|
+
|
|
285
|
+
返回:
|
|
286
|
+
tuple: (是否近期, 日期关系描述, 周几描述)
|
|
287
|
+
是否近期:bool类型,今天/明天/后天返回True,其他返回False
|
|
288
|
+
日期关系描述:"今天" / "明天" / "后天" / "其他日期"
|
|
289
|
+
周几描述:"周一" / "周二" ... / "周日"
|
|
290
|
+
"""
|
|
291
|
+
# 1. 处理时区和日期截取(只保留年月日,忽略时分秒)
|
|
292
|
+
# 获取当前 UTC+8 时间的日期部分
|
|
293
|
+
today = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=8)
|
|
294
|
+
today_date = today.date()
|
|
295
|
+
|
|
296
|
+
# 提取目标日期的日期部分
|
|
297
|
+
target_date = target_dt.date()
|
|
298
|
+
|
|
299
|
+
# 2. 计算目标日期与今天的差值(天数)
|
|
300
|
+
delta_days = (target_date - today_date).days
|
|
301
|
+
|
|
302
|
+
# 3. 判断日期关系和是否近期
|
|
303
|
+
if delta_days == 0:
|
|
304
|
+
date_relation = "今天"
|
|
305
|
+
is_recent = True
|
|
306
|
+
elif delta_days == 1:
|
|
307
|
+
date_relation = "明天"
|
|
308
|
+
is_recent = True
|
|
309
|
+
elif delta_days == 2:
|
|
310
|
+
date_relation = "后天"
|
|
311
|
+
is_recent = True
|
|
312
|
+
else:
|
|
313
|
+
date_relation = "其他日期"
|
|
314
|
+
is_recent = False
|
|
315
|
+
|
|
316
|
+
# 4. 计算周几
|
|
317
|
+
weekday_num = target_dt.weekday() # weekday() 返回 0(周一)~6(周日)
|
|
318
|
+
weekday_desc = "周" + dict_weekday_trans.get(weekday_num, "")
|
|
319
|
+
|
|
320
|
+
# 是否近期,今天/明天/后天,周一
|
|
321
|
+
return is_recent, date_relation, weekday_desc
|
|
322
|
+
|
|
323
|
+
n_event_st, n_event_name = get_newest_event_data()
|
|
324
|
+
n_coop_st, n_coop_name = get_newest_salmonrun_data()
|
|
325
|
+
msg = ""
|
|
326
|
+
if n_event_st:
|
|
327
|
+
is_recent, date_relation, weekday_desc = check_date_relation(time_converter(n_event_st))
|
|
328
|
+
if is_recent:
|
|
329
|
+
msg += f"{date_relation}{weekday_desc},{time_converter_h(n_event_st)}时开始会有活动:{n_event_name}"
|
|
330
|
+
if n_coop_st:
|
|
331
|
+
is_recent, date_relation, weekday_desc = check_date_relation(time_converter(n_coop_st))
|
|
332
|
+
if is_recent:
|
|
333
|
+
if msg:
|
|
334
|
+
msg += "\n"
|
|
335
|
+
msg += f"{date_relation}{weekday_desc},{time_converter_h(n_coop_st)}时开始会有 {n_coop_name}"
|
|
336
|
+
return msg
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
def get_newest_event_data():
|
|
340
|
+
"""
|
|
341
|
+
取最新活动数据
|
|
342
|
+
返回 (时间(年月日T时分秒Z),名称)
|
|
343
|
+
"""
|
|
344
|
+
# 取日程
|
|
345
|
+
schedule = get_schedule_data()
|
|
346
|
+
events = schedule["eventSchedules"]["nodes"]
|
|
347
|
+
# 如果存在活动
|
|
348
|
+
if len(events) > 0:
|
|
349
|
+
newest_event = events[0]
|
|
350
|
+
# 取时间
|
|
351
|
+
st = newest_event["timePeriods"][0]["startTime"]
|
|
352
|
+
# time_converter_yd(st),
|
|
353
|
+
# "周" + dict_weekday_trans.get(time_converter_weekday(st))
|
|
354
|
+
# 取中文翻译
|
|
355
|
+
cht_event_data = newest_event["leagueMatchSetting"]["leagueMatchEvent"]
|
|
356
|
+
_id = cht_event_data["id"]
|
|
357
|
+
trans_cht_event_data = get_trans_cht_data()["events"][_id]
|
|
358
|
+
# 替换为翻译文本
|
|
359
|
+
cht_event_data["name"] = trans_cht_event_data.get(
|
|
360
|
+
"name", cht_event_data["name"]
|
|
361
|
+
)
|
|
362
|
+
event_name = cht_event_data["name"]
|
|
363
|
+
return st, event_name
|
|
364
|
+
else:
|
|
365
|
+
return "", ""
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
def get_newest_salmonrun_data():
|
|
369
|
+
"""
|
|
370
|
+
取最新big run或者团工 数据
|
|
371
|
+
返回 (时间(年月日T时分秒Z),名称)
|
|
372
|
+
"""
|
|
373
|
+
# 取日程
|
|
374
|
+
schedule = get_schedule_data()
|
|
375
|
+
# 取翻译
|
|
376
|
+
get_trans_cht_data()
|
|
377
|
+
# 团队打工竞赛
|
|
378
|
+
team_schedule = schedule["coopGroupingSchedule"]["teamContestSchedules"]["nodes"]
|
|
379
|
+
# big run 数据
|
|
380
|
+
bigrun_schedule = schedule["coopGroupingSchedule"]["bigRunSchedules"]["nodes"]
|
|
381
|
+
newest_coop = None
|
|
382
|
+
coop_name = ""
|
|
383
|
+
st = ""
|
|
384
|
+
if len(team_schedule) > 0:
|
|
385
|
+
newest_coop = team_schedule[0]
|
|
386
|
+
coop_name = "团队打工"
|
|
387
|
+
elif len(bigrun_schedule) > 0:
|
|
388
|
+
newest_coop = bigrun_schedule[0]
|
|
389
|
+
coop_name = "BigRun"
|
|
390
|
+
|
|
391
|
+
if newest_coop is not None:
|
|
392
|
+
# coop_stage_name = get_trans_stage(newest_coop["setting"]["coopStage"]["id"])
|
|
393
|
+
st = newest_coop["startTime"]
|
|
394
|
+
return st, coop_name
|
|
395
|
+
|
|
396
|
+
|
|
270
397
|
async def init_browser() -> Browser:
|
|
271
398
|
"""初始化 browser 并唤起"""
|
|
272
399
|
global _browser
|
|
@@ -293,10 +420,10 @@ async def get_browser() -> Browser:
|
|
|
293
420
|
|
|
294
421
|
|
|
295
422
|
async def get_screenshot(
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
423
|
+
shot_url,
|
|
424
|
+
mode="pc",
|
|
425
|
+
selector=None,
|
|
426
|
+
shot_path=None,
|
|
300
427
|
) -> bytes:
|
|
301
428
|
"""通过 browser 获取 shot_url 中的网页截图"""
|
|
302
429
|
# playwright 要求不能有多个 browser 被同时唤起
|
|
@@ -299,7 +299,7 @@ class DBIMAGE:
|
|
|
299
299
|
if not is_deco:
|
|
300
300
|
sql = f"select * from BUILDS where keywords LIKE '%|{keyword}|%'"
|
|
301
301
|
else:
|
|
302
|
-
sql = f"select * from BUILDS where keywords LIKE '%|{keyword}|%' AND is_deco=
|
|
302
|
+
sql = f"select * from BUILDS where keywords LIKE '%|{keyword}|%' AND is_deco={is_deco}"
|
|
303
303
|
c = self.conn.cursor()
|
|
304
304
|
c.execute(
|
|
305
305
|
sql,
|
|
@@ -74,21 +74,44 @@ async def get_build_image(*args):
|
|
|
74
74
|
mode = dict_builds_mode_trans.get(mode, mode)
|
|
75
75
|
|
|
76
76
|
url = f"https://sendou.ink/builds/{sendou_name}?limit=6"
|
|
77
|
-
if mode:
|
|
77
|
+
if mode and mode != "全部":
|
|
78
78
|
url += (
|
|
79
79
|
'&f=[{"type":"mode","mode":"'
|
|
80
80
|
+ mode
|
|
81
|
-
+ '"},{"type":"date","date":"
|
|
81
|
+
+ '"},{"type":"date","date":"2026-01-29"}]'
|
|
82
82
|
)
|
|
83
83
|
else:
|
|
84
|
-
url += '&f=[{"type":"date","date":"
|
|
84
|
+
url += '&f=[{"type":"date","date":"2026-01-29"}]'
|
|
85
85
|
|
|
86
86
|
logger.info(f"sendou.ink url: {url}")
|
|
87
87
|
try:
|
|
88
88
|
img = await get_screenshot(shot_url=url, mode="pc", selector=".layout__main")
|
|
89
|
+
im = Image.open(io.BytesIO(img))
|
|
90
|
+
# 裁切顶部虚影部分
|
|
91
|
+
crop_box = (
|
|
92
|
+
0,
|
|
93
|
+
60,
|
|
94
|
+
im.width,
|
|
95
|
+
im.height - 70,
|
|
96
|
+
) # 传入的四个参数可以理解为是 左上角的x点,y点,和右下角的x点,y点
|
|
97
|
+
cropped_img = im.crop(crop_box)
|
|
98
|
+
# 添加一行文本版权声明
|
|
99
|
+
ttf = ImageFont.truetype(ttf_path_chinese, 20)
|
|
100
|
+
img_width = cropped_img.width
|
|
101
|
+
img_height = cropped_img.height
|
|
102
|
+
# 写一行网址
|
|
103
|
+
time_head_text = f"配装数据来源: https://sendou.ink/builds"
|
|
104
|
+
w, h = ttf_get_size(ttf, time_head_text)
|
|
105
|
+
time_head_text_pos = (
|
|
106
|
+
(img_width - w) / 2,
|
|
107
|
+
img_height - 33,
|
|
108
|
+
)
|
|
109
|
+
drawer = ImageDraw.Draw(cropped_img)
|
|
110
|
+
drawer.text(time_head_text_pos, time_head_text, font=ttf, fill=(247, 62, 139))
|
|
111
|
+
return cropped_img
|
|
112
|
+
|
|
89
113
|
except Exception as e:
|
|
90
114
|
return f"bot服务器网络错误,网页截图失败,请稍后再试:{e}"
|
|
91
|
-
return img
|
|
92
115
|
|
|
93
116
|
|
|
94
117
|
async def get_random_weapon_image(*args):
|
|
@@ -182,7 +182,7 @@ def get_events(events: list) -> Image.Image:
|
|
|
182
182
|
event_card_pos = (20, pos_h + 20)
|
|
183
183
|
paste_with_a(image_background, event_card, event_card_pos)
|
|
184
184
|
pos_h += event_card.size[1] + 30
|
|
185
|
-
#
|
|
185
|
+
# 绘制活动说明卡片
|
|
186
186
|
event_desc_card_bg_size = (event_card_bg_size[0], 300)
|
|
187
187
|
event_desc_card = get_event_desc_card(cht_event_data, event_desc_card_bg_size)
|
|
188
188
|
event_card_pos = (20, pos_h)
|
|
@@ -846,7 +846,7 @@ def get_help() -> Image.Image:
|
|
|
846
846
|
def get_nso_help() -> Image.Image:
|
|
847
847
|
"""绘制 nso帮助图片"""
|
|
848
848
|
all_width = 1200
|
|
849
|
-
image_background_size = (all_width,
|
|
849
|
+
image_background_size = (all_width, 4550)
|
|
850
850
|
|
|
851
851
|
# 取背景rgb颜色
|
|
852
852
|
bg_rgb = dict_bg_rgb["活动"]
|
|
@@ -1019,7 +1019,7 @@ def get_nso_help() -> Image.Image:
|
|
|
1019
1019
|
# 绘制 帮助卡片
|
|
1020
1020
|
cmd_list = ["/me"]
|
|
1021
1021
|
desc_list = [
|
|
1022
|
-
("无参数", "显示个人技术,奖牌,对战/打工数量,胜率等信息"),
|
|
1022
|
+
("无参数", "显示个人技术,奖牌,对战/打工数量,胜率等信息(私聊使用该命令时将展示更多信息,如武器分,x分)"),
|
|
1023
1023
|
]
|
|
1024
1024
|
text_card, card_h = drawer_nso_help_card(cmd_list, desc_list, text_width=text_width)
|
|
1025
1025
|
# 贴图
|
|
@@ -1073,7 +1073,7 @@ def get_nso_help() -> Image.Image:
|
|
|
1073
1073
|
cmd_list = ["/report"]
|
|
1074
1074
|
desc_list = [
|
|
1075
1075
|
("无参数", "查询昨天的日报数据(对战/打工情况,胜率变化等)"),
|
|
1076
|
-
("2024-01-30", "
|
|
1076
|
+
("2024-01-30", "查询指定日期到最新日报间的数据变化,日期格式为2024-01-30"),
|
|
1077
1077
|
]
|
|
1078
1078
|
text_card, card_h = drawer_nso_help_card(cmd_list, desc_list, text_width=text_width)
|
|
1079
1079
|
# 贴图
|
|
@@ -1090,6 +1090,26 @@ def get_nso_help() -> Image.Image:
|
|
|
1090
1090
|
text_bg_pos = (title_pos[0] + 30, height)
|
|
1091
1091
|
paste_with_a(image_background, text_card, text_bg_pos)
|
|
1092
1092
|
height += card_h + 10
|
|
1093
|
+
# 绘制 帮助卡片
|
|
1094
|
+
cmd_list = ["/观星导出"]
|
|
1095
|
+
desc_list = [
|
|
1096
|
+
("无参数", "导出观星网站所需要的装备json文件"),
|
|
1097
|
+
]
|
|
1098
|
+
text_card, card_h = drawer_nso_help_card(cmd_list, desc_list, text_width=text_width)
|
|
1099
|
+
# 贴图
|
|
1100
|
+
text_bg_pos = (title_pos[0] + 30, height)
|
|
1101
|
+
paste_with_a(image_background, text_card, text_bg_pos)
|
|
1102
|
+
height += card_h + 10
|
|
1103
|
+
# 绘制 帮助卡片
|
|
1104
|
+
cmd_list = ["/nso网页版"]
|
|
1105
|
+
desc_list = [
|
|
1106
|
+
("无参数", "让你可以在任何支持油猴脚本的浏览器内打开喷三鱿鱼圈,\n适用于网络太差进不去nso或nso不方便升级的时候使用"),
|
|
1107
|
+
]
|
|
1108
|
+
text_card, card_h = drawer_nso_help_card(cmd_list, desc_list, text_width=text_width)
|
|
1109
|
+
# 贴图
|
|
1110
|
+
text_bg_pos = (title_pos[0] + 30, height)
|
|
1111
|
+
paste_with_a(image_background, text_card, text_bg_pos)
|
|
1112
|
+
height += card_h + 10
|
|
1093
1113
|
|
|
1094
1114
|
# 绘制title
|
|
1095
1115
|
title = "stat.ink战绩同步"
|
|
@@ -1169,7 +1189,7 @@ def get_nso_help() -> Image.Image:
|
|
|
1169
1189
|
# 绘制 帮助卡片
|
|
1170
1190
|
cmd_list = ["/report_notify"]
|
|
1171
1191
|
desc_list = [
|
|
1172
|
-
("open", "开启每日日报主动推送(早上
|
|
1192
|
+
("open", "开启每日日报主动推送(早上9点定时发送)"),
|
|
1173
1193
|
("close", "关闭日报主动推送"),
|
|
1174
1194
|
]
|
|
1175
1195
|
text_card, card_h = drawer_nso_help_card(cmd_list, desc_list, text_width=text_width)
|
|
Binary file
|
|
@@ -10,9 +10,9 @@ from .image.image import (
|
|
|
10
10
|
get_coop_stages_image,
|
|
11
11
|
get_events_image,
|
|
12
12
|
)
|
|
13
|
-
from .utils.cos_upload import cos_uploader,
|
|
14
|
-
from .utils.utils import get_time_now_china, trigger_with_probability
|
|
15
|
-
from .data import db_control, db_image
|
|
13
|
+
from .utils.cos_upload import cos_uploader, cos_upload_file
|
|
14
|
+
from .utils.utils import get_time_now_china, trigger_with_probability, get_image_size
|
|
15
|
+
from .data import db_control, db_image, get_newest_event_or_coop
|
|
16
16
|
from .utils.bot import *
|
|
17
17
|
|
|
18
18
|
|
|
@@ -107,7 +107,7 @@ async def send_push(bot: Bot, source_id):
|
|
|
107
107
|
|
|
108
108
|
|
|
109
109
|
async def send_msg(
|
|
110
|
-
|
|
110
|
+
bot: Bot, event: Event, msg: str | bytes, is_ad=False, is_cache=True
|
|
111
111
|
):
|
|
112
112
|
"""公用send_msg"""
|
|
113
113
|
# 指定回复模式
|
|
@@ -183,13 +183,10 @@ async def send_msg(
|
|
|
183
183
|
await bot.send(event, Kook_MsgSeg.image(url), reply_sender=reply_mode)
|
|
184
184
|
elif isinstance(bot, QQ_Bot):
|
|
185
185
|
# 目前q群只支持url图片,得想办法上传图片获取url
|
|
186
|
-
url = await
|
|
186
|
+
url, image_size = await get_image_url_and_size(img)
|
|
187
187
|
# logger.info("url:" + url)
|
|
188
188
|
try:
|
|
189
189
|
if plugin_config.splatoon3_qq_md_mode:
|
|
190
|
-
image = Image.open(io.BytesIO(img))
|
|
191
|
-
image_size = image.size
|
|
192
|
-
image.close()
|
|
193
190
|
user_id = event.get_user_id()
|
|
194
191
|
qq_md = await get_qq_md(user_id, image_size, url)
|
|
195
192
|
await bot.send(event, qq_md)
|
|
@@ -199,7 +196,7 @@ async def send_msg(
|
|
|
199
196
|
if "消息被去重" in str(e):
|
|
200
197
|
pass
|
|
201
198
|
elif "富媒体文件格式不支持" in str(e):
|
|
202
|
-
url = await
|
|
199
|
+
url, image_size = await get_image_url_and_size(img)
|
|
203
200
|
logger.info("图片上传失败,重新强制上传,url:" + url)
|
|
204
201
|
await bot.send(event, message=QQ_MsgSeg.image(url))
|
|
205
202
|
else:
|
|
@@ -211,14 +208,17 @@ async def send_msg(
|
|
|
211
208
|
await send_msg(bot, event, ad_msg, is_ad=True)
|
|
212
209
|
|
|
213
210
|
|
|
214
|
-
async def
|
|
215
|
-
"""通过kook
|
|
211
|
+
async def get_image_url_and_size(img_data: bytes) -> tuple[str, tuple[int, int]]:
|
|
212
|
+
"""通过cos图床或kook图床获取图片url"""
|
|
216
213
|
url = ""
|
|
214
|
+
image_size = (300, 300)
|
|
217
215
|
# 优先使用腾讯cos上传
|
|
218
216
|
if plugin_config.splatoon3_cos_config.enabled and cos_uploader.client is not None:
|
|
219
|
-
url =
|
|
217
|
+
url, image_size = cos_upload_file(img_data)
|
|
220
218
|
if url:
|
|
221
|
-
return url
|
|
219
|
+
return url, image_size
|
|
220
|
+
else:
|
|
221
|
+
logger.warning("腾讯cos上传失败,使用kook上传")
|
|
222
222
|
|
|
223
223
|
# 使用kook的接口传图片
|
|
224
224
|
kook_bot = None
|
|
@@ -229,13 +229,14 @@ async def get_image_url(img: bytes, is_cache) -> str:
|
|
|
229
229
|
break
|
|
230
230
|
if kook_bot is not None:
|
|
231
231
|
# 使用kook的接口传图片
|
|
232
|
-
url = await kook_bot.upload_file(
|
|
233
|
-
|
|
232
|
+
url = await kook_bot.upload_file(img_data)
|
|
233
|
+
image_size = get_image_size(img_data)
|
|
234
|
+
if url:
|
|
234
235
|
channel_id = plugin_config.splatoon3_kk_channel_waste_chat_id
|
|
235
236
|
await kook_bot.send_channel_msg(
|
|
236
237
|
channel_id=channel_id, message=Kook_MsgSeg.image(url)
|
|
237
238
|
)
|
|
238
|
-
return url
|
|
239
|
+
return url, image_size
|
|
239
240
|
|
|
240
241
|
|
|
241
242
|
async def send_channel_msg(bot: Bot, source_id, msg: str | bytes):
|
|
@@ -344,7 +345,8 @@ async def get_qq_md(user_id: str, img_size: tuple[int, int], url: str) -> QQ_Msg
|
|
|
344
345
|
|
|
345
346
|
image_width, image_height = img_size
|
|
346
347
|
|
|
347
|
-
text_start = "发送/帮助查看详细用法"
|
|
348
|
+
text_start = get_newest_event_or_coop() or "发送/帮助查看详细用法"
|
|
349
|
+
text_start = text_start.replace("\n", "\r")
|
|
348
350
|
|
|
349
351
|
# text_end作为公告消息
|
|
350
352
|
text_end = await get_or_set_plugin_data("splatoon3_bot_notice")
|
|
@@ -360,7 +362,7 @@ async def get_qq_md(user_id: str, img_size: tuple[int, int], url: str) -> QQ_Msg
|
|
|
360
362
|
]
|
|
361
363
|
)
|
|
362
364
|
if text_end:
|
|
363
|
-
text_end = text_end.replace("\\n", "\r").replace("\\r", "\r")
|
|
365
|
+
text_end = "\r" + text_end.replace("\\n", "\r").replace("\\r", "\r")
|
|
364
366
|
params.append({"key": "text_end", "values": [f"{text_end}"]})
|
|
365
367
|
md = QQ_MsgMarkdown.model_validate(
|
|
366
368
|
{"custom_template_id": f"{template_id}", "params": params}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import os, logging, mimetypes, re, sys, hashlib
|
|
2
|
+
import traceback
|
|
2
3
|
from datetime import datetime
|
|
3
4
|
from typing import Optional, Dict, Any, Tuple
|
|
4
5
|
from io import BytesIO
|
|
5
6
|
|
|
6
7
|
from nonebot import logger
|
|
7
8
|
|
|
8
|
-
from .utils import
|
|
9
|
+
from .utils import get_image_size
|
|
10
|
+
from .. import plugin_config
|
|
9
11
|
|
|
10
12
|
try:
|
|
11
13
|
from qcloud_cos import CosConfig, CosS3Client
|
|
@@ -20,6 +22,7 @@ class COSUploader:
|
|
|
20
22
|
|
|
21
23
|
提供文件上传、删除、查询等功能
|
|
22
24
|
"""
|
|
25
|
+
|
|
23
26
|
def __init__(self):
|
|
24
27
|
"""初始化COS上传器
|
|
25
28
|
|
|
@@ -87,7 +90,8 @@ class COSUploader:
|
|
|
87
90
|
return sys.getsizeof(file_data) <= self.config.max_file_size
|
|
88
91
|
|
|
89
92
|
def _generate_cos_key(self, user_id: str = None,
|
|
90
|
-
md5: str = None, file_data: bytes = None
|
|
93
|
+
md5: str = None, file_data: bytes = None,
|
|
94
|
+
width: int = 300, height: int = 300) -> str:
|
|
91
95
|
"""生成COS上传路径
|
|
92
96
|
|
|
93
97
|
Args:
|
|
@@ -100,15 +104,15 @@ class COSUploader:
|
|
|
100
104
|
"""
|
|
101
105
|
# 使用MD5作为文件名
|
|
102
106
|
ext = self._get_file_extension(file_data)
|
|
103
|
-
filename = f"{md5}{ext}"
|
|
104
|
-
|
|
107
|
+
filename = f"{md5}_w{width}h{height}{ext}"
|
|
108
|
+
|
|
105
109
|
# 获取上传路径前缀
|
|
106
110
|
upload_prefix = self.config.upload_path_prefix
|
|
107
|
-
|
|
111
|
+
|
|
108
112
|
# 确保前缀以/结尾,避免路径拼接问题
|
|
109
113
|
if upload_prefix and not upload_prefix.endswith('/'):
|
|
110
114
|
upload_prefix += '/'
|
|
111
|
-
|
|
115
|
+
|
|
112
116
|
if user_id:
|
|
113
117
|
return f"{upload_prefix}{user_id}/{filename}"
|
|
114
118
|
else:
|
|
@@ -171,18 +175,24 @@ class COSUploader:
|
|
|
171
175
|
try:
|
|
172
176
|
if not self._validate_file(file_data):
|
|
173
177
|
return None
|
|
174
|
-
|
|
178
|
+
|
|
175
179
|
# 计算文件MD5
|
|
176
180
|
md5 = self._calculate_md5(file_data)
|
|
177
|
-
|
|
181
|
+
|
|
178
182
|
# 检查缓存中是否已存在该MD5的URL
|
|
179
183
|
cached_url = self._get_cached_url(md5)
|
|
180
184
|
if cached_url:
|
|
181
|
-
#
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
185
|
+
# 从URL中提取尺寸信息
|
|
186
|
+
dimensions = get_image_dimensions_from_url(cached_url)
|
|
187
|
+
if dimensions:
|
|
188
|
+
width, height = dimensions
|
|
189
|
+
else:
|
|
190
|
+
# 如果无法从URL中提取尺寸信息,尝试重新获取,否则则使用默认值
|
|
191
|
+
try:
|
|
192
|
+
width, height = get_image_size(file_data)
|
|
193
|
+
except:
|
|
194
|
+
width, height = (300, 300)
|
|
195
|
+
|
|
186
196
|
# 返回缓存的结果
|
|
187
197
|
return {
|
|
188
198
|
'success': True,
|
|
@@ -190,19 +200,21 @@ class COSUploader:
|
|
|
190
200
|
'file_url': cached_url,
|
|
191
201
|
'filename': os.path.basename(cached_url),
|
|
192
202
|
'file_size': sys.getsizeof(file_data),
|
|
193
|
-
'width':
|
|
194
|
-
'height':
|
|
195
|
-
'px': f'#{
|
|
203
|
+
'width': width,
|
|
204
|
+
'height': height,
|
|
205
|
+
'px': f'#{width}px #{height}px',
|
|
196
206
|
'cached': True
|
|
197
207
|
}
|
|
198
|
-
|
|
208
|
+
|
|
209
|
+
# 获取图片尺寸
|
|
199
210
|
try:
|
|
200
211
|
dimensions = get_image_size(file_data)
|
|
201
212
|
except:
|
|
202
213
|
dimensions = (300, 300)
|
|
203
|
-
|
|
214
|
+
width, height = dimensions
|
|
215
|
+
|
|
204
216
|
# 使用MD5作为文件名生成cos_key
|
|
205
|
-
cos_key = self._generate_cos_key(user_id, md5, file_data)
|
|
217
|
+
cos_key = self._generate_cos_key(user_id, md5, file_data, width, height)
|
|
206
218
|
response = self.client.put_object(Bucket=self.config.bucket_name, Body=BytesIO(file_data),
|
|
207
219
|
Key=cos_key, ContentType=self._get_content_type(file_data))
|
|
208
220
|
base_url = f"https://{self.config.domain}" if self.config.domain else \
|
|
@@ -213,10 +225,14 @@ class COSUploader:
|
|
|
213
225
|
return {
|
|
214
226
|
'success': True, 'cos_key': cos_key, 'file_url': file_url,
|
|
215
227
|
'filename': os.path.basename(cos_key), 'file_size': sys.getsizeof(file_data),
|
|
216
|
-
'width':
|
|
228
|
+
'width': width, 'height': height, 'px': f'#{width}px #{height}px',
|
|
217
229
|
'cached': False
|
|
218
230
|
}
|
|
219
231
|
except:
|
|
232
|
+
if response:
|
|
233
|
+
logger.warning(f"cos上传失败:resp为:{response}\ntraceback:{traceback.format_exc()}")
|
|
234
|
+
else:
|
|
235
|
+
logger.warning(f"cos上传失败:traceback:{traceback.format_exc()}")
|
|
220
236
|
return None
|
|
221
237
|
|
|
222
238
|
def delete_file(self, cos_key: str) -> bool:
|
|
@@ -304,17 +320,30 @@ def upload_image(file_data: bytes, user_id: str = None, return_url_only: bool =
|
|
|
304
320
|
return result['file_url'] if result and return_url_only else result
|
|
305
321
|
|
|
306
322
|
|
|
307
|
-
def
|
|
308
|
-
|
|
323
|
+
def cos_upload_file(file_data: bytes, user_id: str = None):
|
|
324
|
+
"""上传文件到COS
|
|
325
|
+
|
|
326
|
+
Args:
|
|
327
|
+
file_data: 文件数据的bytes类型
|
|
328
|
+
user_id: 用户ID
|
|
329
|
+
|
|
330
|
+
Returns:
|
|
331
|
+
上传结果
|
|
332
|
+
"""
|
|
333
|
+
result = upload_image(file_data, user_id)
|
|
334
|
+
url = result.get('file_url')
|
|
335
|
+
width = result.get('width', 300)
|
|
336
|
+
height = result.get('height', 300)
|
|
337
|
+
return url, (width, height)
|
|
309
338
|
|
|
310
339
|
|
|
311
|
-
def
|
|
340
|
+
def cos_simple_upload_file(file_data: bytes, user_id: str = None):
|
|
312
341
|
return upload_image(file_data, user_id, return_url_only=True)
|
|
313
342
|
|
|
314
343
|
|
|
315
344
|
def _get_cos_base_url() -> str:
|
|
316
|
-
base_url = f"https://{cos_uploader.config
|
|
317
|
-
f"https://{cos_uploader.config
|
|
345
|
+
base_url = f"https://{cos_uploader.config.domain}" if cos_uploader.config.domain else \
|
|
346
|
+
f"https://{cos_uploader.config.bucket_name}.cos.{cos_uploader.config.region}.myqcloud.com"
|
|
318
347
|
return base_url
|
|
319
348
|
|
|
320
349
|
|
|
@@ -327,3 +356,26 @@ def delete_by_url(file_url: str):
|
|
|
327
356
|
return False
|
|
328
357
|
base_url = _get_cos_base_url()
|
|
329
358
|
return cos_uploader.delete_file(file_url[len(base_url):]) if file_url.startswith(base_url) else False
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def get_image_dimensions_from_url(url: str) -> Optional[Tuple[int, int]]:
|
|
362
|
+
"""从URL中提取图片的宽高数据
|
|
363
|
+
|
|
364
|
+
Args:
|
|
365
|
+
url: 图片URL,文件名格式为: {md5}_w{width}h{height}{ext}
|
|
366
|
+
|
|
367
|
+
Returns:
|
|
368
|
+
Optional[Tuple[int, int]]: 图片的宽高元组(width, height),如果解析失败则返回None
|
|
369
|
+
"""
|
|
370
|
+
try:
|
|
371
|
+
# 从URL中提取文件名
|
|
372
|
+
filename = os.path.basename(url)
|
|
373
|
+
# 使用正则表达式匹配宽高数据
|
|
374
|
+
match = re.search(r'_w(\d+)h(\d+)', filename)
|
|
375
|
+
if match:
|
|
376
|
+
width = int(match.group(1))
|
|
377
|
+
height = int(match.group(2))
|
|
378
|
+
return (width, height)
|
|
379
|
+
return None
|
|
380
|
+
except:
|
|
381
|
+
return None
|
|
@@ -2,6 +2,7 @@ import datetime
|
|
|
2
2
|
import json
|
|
3
3
|
import random
|
|
4
4
|
|
|
5
|
+
import zhconv
|
|
5
6
|
from nonebot.log import logger
|
|
6
7
|
from .utils import (
|
|
7
8
|
get_time_ymd,
|
|
@@ -125,6 +126,15 @@ def weapon_semantic_word_conversion(word: str):
|
|
|
125
126
|
return word_type[4], random.choice(list(father_class_list))
|
|
126
127
|
|
|
127
128
|
|
|
129
|
+
def str_convert_to_simplified(words: str):
|
|
130
|
+
"""字符串转简体中文"""
|
|
131
|
+
if words:
|
|
132
|
+
simplified_text = zhconv.convert(words, "zh-hans")
|
|
133
|
+
return simplified_text
|
|
134
|
+
else:
|
|
135
|
+
return words
|
|
136
|
+
|
|
137
|
+
|
|
128
138
|
# 翻译字典
|
|
129
139
|
dict_rule_reverse_trans = {
|
|
130
140
|
"LOFT": "真格塔楼",
|
|
@@ -210,13 +220,32 @@ dict_keyword_replace = {
|
|
|
210
220
|
# 配装武器关键词前置处理
|
|
211
221
|
dict_builds_pre_replace = {
|
|
212
222
|
"无印": "",
|
|
223
|
+
"原版": "",
|
|
213
224
|
"炮": "泡",
|
|
214
225
|
"息": "熄",
|
|
215
226
|
"篮": "蓝",
|
|
216
|
-
"斯普拉顿": "
|
|
227
|
+
"斯普拉顿": "斯普拉",
|
|
228
|
+
"斯普拉遁": "斯普拉",
|
|
217
229
|
"拴": "栓",
|
|
218
|
-
"四开": "
|
|
230
|
+
"四开": "4K",
|
|
231
|
+
"四K": "4K",
|
|
232
|
+
"4开": "4K",
|
|
233
|
+
"新形": "新型",
|
|
219
234
|
"设计": "射击",
|
|
235
|
+
"渔工": "鱼弓",
|
|
236
|
+
"渡": "镀",
|
|
237
|
+
"防空露营": "露营防空",
|
|
238
|
+
"锯齿": "巨齿",
|
|
239
|
+
"针筒": "针管",
|
|
240
|
+
"牙膏刀": "太刀",
|
|
241
|
+
"牙膏": "太刀",
|
|
242
|
+
"顶级": "顶尖",
|
|
243
|
+
"酸奶": "奶",
|
|
244
|
+
"牛奶": "奶",
|
|
245
|
+
"笔桶": "笔桶",
|
|
246
|
+
"抢": "枪",
|
|
247
|
+
"雨刮": "雨刷",
|
|
248
|
+
"挂水刀": "刮水刀",
|
|
220
249
|
" ": "",
|
|
221
250
|
".": "",
|
|
222
251
|
"。": "",
|
|
@@ -7,6 +7,7 @@ import cloudscraper
|
|
|
7
7
|
import httpx
|
|
8
8
|
from PIL import ImageFont, Image
|
|
9
9
|
from httpx import Response
|
|
10
|
+
from nonebot import logger
|
|
10
11
|
|
|
11
12
|
from .dataClass import TimeUtil
|
|
12
13
|
from ..config import plugin_config
|
|
@@ -45,12 +46,18 @@ def cf_http_get(url: str):
|
|
|
45
46
|
# 请求报错,可以加上时延
|
|
46
47
|
# scraper = cloudscraper.create_scraper(delay = 6)
|
|
47
48
|
if proxy_address:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
try:
|
|
50
|
+
cf_proxies = {
|
|
51
|
+
"http": "http://{}".format(proxy_address),
|
|
52
|
+
"https": "http://{}".format(proxy_address),
|
|
53
|
+
}
|
|
54
|
+
# 获取网页内容 代理访问
|
|
55
|
+
res = scraper.get(url, proxies=cf_proxies)
|
|
56
|
+
except Exception as e:
|
|
57
|
+
# 可能是代理挂了,切换为直连模式再请求一次
|
|
58
|
+
logger.warning("代理请求失败,将进行直连请求重试")
|
|
59
|
+
res = scraper.get(url)
|
|
60
|
+
|
|
54
61
|
else:
|
|
55
62
|
# 获取网页内容
|
|
56
63
|
res = scraper.get(url)
|
|
@@ -114,6 +121,12 @@ def time_converter_hm(time_str):
|
|
|
114
121
|
return datetime.datetime.strftime(dt, "%H:%M")
|
|
115
122
|
|
|
116
123
|
|
|
124
|
+
def time_converter_h(time_str):
|
|
125
|
+
"""时间转换 时"""
|
|
126
|
+
dt = time_converter(time_str)
|
|
127
|
+
return datetime.datetime.strftime(dt, "%H")
|
|
128
|
+
|
|
129
|
+
|
|
117
130
|
def time_converter_mdhm(time_str):
|
|
118
131
|
"""时间转换 月-日 时:分"""
|
|
119
132
|
dt = time_converter(time_str)
|
|
@@ -155,9 +168,9 @@ def get_time_now_china() -> datetime.datetime:
|
|
|
155
168
|
|
|
156
169
|
def trigger_with_probability():
|
|
157
170
|
"""
|
|
158
|
-
该函数有
|
|
171
|
+
该函数有1/100的概率返回True(触发)
|
|
159
172
|
"""
|
|
160
|
-
return random.random() < 0.
|
|
173
|
+
return random.random() < 0.01
|
|
161
174
|
|
|
162
175
|
|
|
163
176
|
def ttf_get_size(font: ImageFont.FreeTypeFont, text: str) -> tuple:
|
{nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/pyproject.toml
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "nonebot-plugin-splatoon3-schedule"
|
|
3
|
-
version = "2.0.
|
|
3
|
+
version = "2.0.7"
|
|
4
4
|
description = "一个基于nonebot2框架的splatoon3游戏日程查询插件"
|
|
5
5
|
authors = ["cypas <ayano05@outlook.com>"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -22,6 +22,7 @@ nonebot-adapter-qq = "^1.6.6"
|
|
|
22
22
|
nonebot-plugin-apscheduler = "^0.5.0"
|
|
23
23
|
nonebot_plugin_datastore = "^1.3.0"
|
|
24
24
|
cos_python_sdk_v5 = "^1.9.30"
|
|
25
|
+
zhconv = "^1.4.3"
|
|
25
26
|
|
|
26
27
|
[tool.poetry.group.test.dependencies]
|
|
27
28
|
nonebug = "^0.3.5"
|
|
File without changes
|
{nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.7}/README.md
RENAMED
|
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
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|