nonebot-plugin-splatoon3-schedule 2.0.5__tar.gz → 2.0.6__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.6}/PKG-INFO +1 -1
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/util.py +16 -15
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/utils/cos_upload.py +77 -25
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/pyproject.toml +1 -1
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/LICENSE +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/README.md +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/__init__.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/check.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/config.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/data/__init__.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/data/data_source.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/data/db_control.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/data/db_image.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/data/static_data_getter.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/image/__init__.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/image/image.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/image/image_processer.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/image/image_processer_tools.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/10024.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/10025.ico +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/10026.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/AREA.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/CLAM.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Cohozuna.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/GOAL.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Horrorboros.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/LOFT.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Megalodontia.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Random.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Ranked-Challenge.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Ranked-Open.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Ranked.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Regular.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/TURF_WAR.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Triumvirate.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/X.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/bg.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/bg2.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/bg3.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/big_run.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/black-texture.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/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.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/coop.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/coop_bg2.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/coop_fish.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/coop_mask.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/event_bg.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/festival_mask.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/fight_mask.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/filleted_corner.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/private.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/swim_ring.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/ImageData/team_coop.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/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.6}/nonebot_plugin_splatoon3_schedule/resource/db/image.db +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/font/Splatfont1.otf +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/font/Splatfont2.otf +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/font/cn.ttf +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/resource/font/common.otf +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/utils/__init__.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/utils/bot.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/utils/dataClass.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/utils/translation.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/nonebot_plugin_splatoon3_schedule/utils/utils.py +0 -0
|
@@ -10,8 +10,8 @@ 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
|
|
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
15
|
from .data import db_control, db_image
|
|
16
16
|
from .utils.bot import *
|
|
17
17
|
|
|
@@ -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):
|
|
@@ -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
|
|
File without changes
|
{nonebot_plugin_splatoon3_schedule-2.0.5 → nonebot_plugin_splatoon3_schedule-2.0.6}/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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|