nonebot-plugin-splatoon3-schedule 2.0.4__tar.gz → 2.0.5__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.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/PKG-INFO +2 -1
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/config.py +15 -2
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/util.py +11 -3
- nonebot_plugin_splatoon3_schedule-2.0.5/nonebot_plugin_splatoon3_schedule/utils/cos_upload.py +329 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/utils/utils.py +10 -2
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/pyproject.toml +2 -1
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/LICENSE +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/README.md +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/__init__.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/check.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/data/__init__.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/data/data_source.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/data/db_control.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/data/db_image.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/data/static_data_getter.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/image/__init__.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/image/image.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/image/image_processer.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/image/image_processer_tools.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/10024.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/10025.ico +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/10026.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/AREA.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/CLAM.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Cohozuna.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/GOAL.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Horrorboros.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/LOFT.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Megalodontia.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Random.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Ranked-Challenge.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Ranked-Open.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Ranked.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Regular.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/TURF_WAR.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/Triumvirate.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/X.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/bg.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/bg2.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/bg3.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/big_run.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/black-texture.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/cat_paw_mask.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/coop.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/coop_bg2.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/coop_fish.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/coop_mask.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/event_bg.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/festival_mask.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/fight_mask.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/filleted_corner.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/private.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/swim_ring.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/team_coop.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/ImageData/time_head_bg.png +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/db/image.db +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/font/Splatfont1.otf +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/font/Splatfont2.otf +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/font/cn.ttf +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/resource/font/common.otf +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/utils/__init__.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/utils/bot.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/utils/dataClass.py +0 -0
- {nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/nonebot_plugin_splatoon3_schedule/utils/translation.py +0 -0
{nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/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.5
|
|
4
4
|
Summary: 一个基于nonebot2框架的splatoon3游戏日程查询插件
|
|
5
5
|
License-File: LICENSE
|
|
6
6
|
Author: cypas
|
|
@@ -16,6 +16,7 @@ Classifier: Programming Language :: Python :: 3.14
|
|
|
16
16
|
Requires-Dist: Pillow (>=11.3.0,<12.0.0)
|
|
17
17
|
Requires-Dist: beautifulsoup4 (>=4.12.2,<5.0.0)
|
|
18
18
|
Requires-Dist: cloudscraper (>=1.2.71,<2.0.0)
|
|
19
|
+
Requires-Dist: cos_python_sdk_v5 (>=1.9.30,<2.0.0)
|
|
19
20
|
Requires-Dist: httpx (>=0.28.1,<0.29.0)
|
|
20
21
|
Requires-Dist: nonebot-adapter-kaiheila (>=0.3.4,<0.4.0)
|
|
21
22
|
Requires-Dist: nonebot-adapter-onebot (>=2.4.6,<3.0.0)
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
from typing import List, Union
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
from nonebot import get_driver
|
|
4
4
|
|
|
5
5
|
from nonebot import get_driver, get_plugin_config
|
|
6
|
-
from pydantic import BaseModel, validator
|
|
6
|
+
from pydantic import BaseModel, validator, Field, Extra
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class CosConfig(BaseModel, extra=Extra.ignore):
|
|
10
|
+
enabled: bool = False
|
|
11
|
+
secret_id: str = "AKID开头的ID" # 腾讯云API密钥ID
|
|
12
|
+
secret_key: str = "密钥" # 腾讯云API密钥Key
|
|
13
|
+
region: str = "ap-guangzhou" # 存储桶区域
|
|
14
|
+
bucket_name: str = "" # 存储桶名称
|
|
15
|
+
domain: str = "" # 自定义域名(可选)
|
|
16
|
+
upload_path_prefix: str = "meme/" # 默认上传路径前缀
|
|
17
|
+
max_file_size: int = 30 * 1024 * 1024 # 最大文件大小30MB
|
|
7
18
|
|
|
8
19
|
|
|
9
20
|
# 其他地方出现的类似 from .. import config,均是从 __init__.py 导入的 Config 实例
|
|
@@ -34,6 +45,8 @@ class Config(BaseModel):
|
|
|
34
45
|
splatoon3_kk_channel_waste_chat_id: str | int = ""
|
|
35
46
|
# 部分消息使用qq平台md卡片,开启了也没用,md模版需要在qqbot端进行审核,模板id目前在代码里是写死的
|
|
36
47
|
splatoon3_qq_md_mode: bool = False
|
|
48
|
+
# 腾讯云cos配置
|
|
49
|
+
splatoon3_cos_config: CosConfig = Field(default_factory=CosConfig)
|
|
37
50
|
|
|
38
51
|
|
|
39
52
|
# 本地测试时由于不启动 driver,需要将下面三行注释并取消再下面两行的注释
|
|
@@ -10,6 +10,7 @@ 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, simple_upload_file
|
|
13
14
|
from .utils.utils import get_time_now_china, trigger_with_probability
|
|
14
15
|
from .data import db_control, db_image
|
|
15
16
|
from .utils.bot import *
|
|
@@ -178,12 +179,12 @@ async def send_msg(
|
|
|
178
179
|
await bot.send(event, Tg_File.photo(img))
|
|
179
180
|
elif isinstance(bot, Kook_Bot):
|
|
180
181
|
url = await bot.upload_file(img)
|
|
181
|
-
logger.info("url:" + url)
|
|
182
|
+
# logger.info("url:" + url)
|
|
182
183
|
await bot.send(event, Kook_MsgSeg.image(url), reply_sender=reply_mode)
|
|
183
184
|
elif isinstance(bot, QQ_Bot):
|
|
184
185
|
# 目前q群只支持url图片,得想办法上传图片获取url
|
|
185
186
|
url = await get_image_url(img, is_cache=False)
|
|
186
|
-
logger.info("url:" + url)
|
|
187
|
+
# logger.info("url:" + url)
|
|
187
188
|
try:
|
|
188
189
|
if plugin_config.splatoon3_qq_md_mode:
|
|
189
190
|
image = Image.open(io.BytesIO(img))
|
|
@@ -212,13 +213,20 @@ async def send_msg(
|
|
|
212
213
|
|
|
213
214
|
async def get_image_url(img: bytes, is_cache) -> str:
|
|
214
215
|
"""通过kook获取图片url"""
|
|
216
|
+
url = ""
|
|
217
|
+
# 优先使用腾讯cos上传
|
|
218
|
+
if plugin_config.splatoon3_cos_config.enabled and cos_uploader.client is not None:
|
|
219
|
+
url = simple_upload_file(img)
|
|
220
|
+
if url:
|
|
221
|
+
return url
|
|
222
|
+
|
|
223
|
+
# 使用kook的接口传图片
|
|
215
224
|
kook_bot = None
|
|
216
225
|
bots = nonebot.get_bots()
|
|
217
226
|
for k, b in bots.items():
|
|
218
227
|
if isinstance(b, Kook_Bot):
|
|
219
228
|
kook_bot = b
|
|
220
229
|
break
|
|
221
|
-
url = ""
|
|
222
230
|
if kook_bot is not None:
|
|
223
231
|
# 使用kook的接口传图片
|
|
224
232
|
url = await kook_bot.upload_file(img)
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import os, logging, mimetypes, re, sys, hashlib
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
from typing import Optional, Dict, Any, Tuple
|
|
4
|
+
from io import BytesIO
|
|
5
|
+
|
|
6
|
+
from nonebot import logger
|
|
7
|
+
|
|
8
|
+
from .utils import plugin_config, get_image_size
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
from qcloud_cos import CosConfig, CosS3Client
|
|
12
|
+
from qcloud_cos.cos_exception import CosServiceError, CosClientError
|
|
13
|
+
except:
|
|
14
|
+
CosConfig = CosS3Client = None
|
|
15
|
+
CosServiceError = CosClientError = Exception
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class COSUploader:
|
|
19
|
+
"""腾讯云COS文件上传器
|
|
20
|
+
|
|
21
|
+
提供文件上传、删除、查询等功能
|
|
22
|
+
"""
|
|
23
|
+
def __init__(self):
|
|
24
|
+
"""初始化COS上传器
|
|
25
|
+
|
|
26
|
+
从配置中读取COS相关配置,初始化COS客户端
|
|
27
|
+
"""
|
|
28
|
+
self.config = plugin_config.splatoon3_cos_config
|
|
29
|
+
self.client = None
|
|
30
|
+
self.md5_cache: Dict[str, str] = {} # MD5到URL的缓存
|
|
31
|
+
if self.config.enabled and all([CosConfig, CosS3Client]):
|
|
32
|
+
self._init_client()
|
|
33
|
+
|
|
34
|
+
def _calculate_md5(self, file_data: bytes) -> str:
|
|
35
|
+
"""计算文件数据的MD5值
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
file_data: 文件数据的bytes类型
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
str: 文件的MD5值(32位十六进制字符串)
|
|
42
|
+
"""
|
|
43
|
+
return hashlib.md5(file_data).hexdigest()
|
|
44
|
+
|
|
45
|
+
def _get_cached_url(self, md5: str) -> Optional[str]:
|
|
46
|
+
"""从缓存中获取URL
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
md5: 文件的MD5值
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
Optional[str]: 缓存的URL,如果不存在则返回None
|
|
53
|
+
"""
|
|
54
|
+
return self.md5_cache.get(md5)
|
|
55
|
+
|
|
56
|
+
def _cache_url(self, md5: str, url: str):
|
|
57
|
+
"""缓存URL
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
md5: 文件的MD5值
|
|
61
|
+
url: 文件的URL
|
|
62
|
+
"""
|
|
63
|
+
self.md5_cache[md5] = url
|
|
64
|
+
|
|
65
|
+
def _init_client(self):
|
|
66
|
+
"""初始化COS客户端
|
|
67
|
+
|
|
68
|
+
使用配置中的SecretId、SecretKey和Region初始化腾讯云COS客户端
|
|
69
|
+
"""
|
|
70
|
+
try:
|
|
71
|
+
cos_config = CosConfig(Region=self.config.region, SecretId=self.config.secret_id,
|
|
72
|
+
SecretKey=self.config.secret_key, Scheme='https')
|
|
73
|
+
self.client = CosS3Client(cos_config)
|
|
74
|
+
logger.info(f"[cos_uploader]cos_uploader初始化完成")
|
|
75
|
+
except:
|
|
76
|
+
pass
|
|
77
|
+
|
|
78
|
+
def _validate_file(self, file_data: bytes) -> bool:
|
|
79
|
+
"""文件大小校验
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
file_data: 文件数据的bytes类型
|
|
83
|
+
|
|
84
|
+
Returns:
|
|
85
|
+
bool: 文件大小是否在限制范围内
|
|
86
|
+
"""
|
|
87
|
+
return sys.getsizeof(file_data) <= self.config.max_file_size
|
|
88
|
+
|
|
89
|
+
def _generate_cos_key(self, user_id: str = None,
|
|
90
|
+
md5: str = None, file_data: bytes = None) -> str:
|
|
91
|
+
"""生成COS上传路径
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
user_id: 用户ID
|
|
95
|
+
md5: 文件的MD5值
|
|
96
|
+
file_data: 文件数据的bytes类型(用于获取扩展名)
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
str: COS上传路径,格式为: 用户ID/MD5.扩展名
|
|
100
|
+
"""
|
|
101
|
+
# 使用MD5作为文件名
|
|
102
|
+
ext = self._get_file_extension(file_data)
|
|
103
|
+
filename = f"{md5}{ext}"
|
|
104
|
+
|
|
105
|
+
# 获取上传路径前缀
|
|
106
|
+
upload_prefix = self.config.upload_path_prefix
|
|
107
|
+
|
|
108
|
+
# 确保前缀以/结尾,避免路径拼接问题
|
|
109
|
+
if upload_prefix and not upload_prefix.endswith('/'):
|
|
110
|
+
upload_prefix += '/'
|
|
111
|
+
|
|
112
|
+
if user_id:
|
|
113
|
+
return f"{upload_prefix}{user_id}/{filename}"
|
|
114
|
+
else:
|
|
115
|
+
return f"{upload_prefix}{filename}"
|
|
116
|
+
|
|
117
|
+
def _get_content_type(self, file_data: bytes) -> str:
|
|
118
|
+
"""获取文件的Content-Type
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
file_data: 文件数据的bytes类型
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
str: 文件的MIME类型,默认为image/jpeg
|
|
125
|
+
"""
|
|
126
|
+
# 优先从文件数据获取MIME类型
|
|
127
|
+
if file_data:
|
|
128
|
+
# 读取文件头部字节来判断文件类型
|
|
129
|
+
import imghdr
|
|
130
|
+
image_type = imghdr.what(None, h=file_data[:32])
|
|
131
|
+
if image_type:
|
|
132
|
+
return f'image/{image_type}'
|
|
133
|
+
return 'image/jpeg'
|
|
134
|
+
|
|
135
|
+
def _get_file_extension(self, file_data: bytes) -> str:
|
|
136
|
+
"""从文件数据或文件名获取文件扩展名
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
file_data: 文件数据的bytes类型
|
|
140
|
+
|
|
141
|
+
Returns:
|
|
142
|
+
str: 文件扩展名(包含点),如.jpg
|
|
143
|
+
"""
|
|
144
|
+
# 优先从文件数据获取扩展名
|
|
145
|
+
import imghdr
|
|
146
|
+
image_type = imghdr.what(None, h=file_data[:32])
|
|
147
|
+
if image_type:
|
|
148
|
+
return f'.{image_type}'
|
|
149
|
+
return '.jpg'
|
|
150
|
+
|
|
151
|
+
def upload_file(self, file_data: bytes, user_id: str = None) -> Optional[Dict[str, Any]]:
|
|
152
|
+
"""上传文件到COS
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
file_data: 文件数据的bytes类型
|
|
156
|
+
user_id: 用户ID,用于生成路径
|
|
157
|
+
|
|
158
|
+
Returns:
|
|
159
|
+
Optional[Dict[str, Any]]: 上传结果字典,包含:
|
|
160
|
+
- success: 是否成功
|
|
161
|
+
- cos_key: COS路径
|
|
162
|
+
- file_url: 文件访问URL
|
|
163
|
+
- file_size: 文件大小
|
|
164
|
+
- width: 图片宽度
|
|
165
|
+
- height: 图片高度
|
|
166
|
+
- px: 尺寸字符串
|
|
167
|
+
- cached: 是否来自缓存
|
|
168
|
+
"""
|
|
169
|
+
if not self.config.enabled or not self.client:
|
|
170
|
+
return None
|
|
171
|
+
try:
|
|
172
|
+
if not self._validate_file(file_data):
|
|
173
|
+
return None
|
|
174
|
+
|
|
175
|
+
# 计算文件MD5
|
|
176
|
+
md5 = self._calculate_md5(file_data)
|
|
177
|
+
|
|
178
|
+
# 检查缓存中是否已存在该MD5的URL
|
|
179
|
+
cached_url = self._get_cached_url(md5)
|
|
180
|
+
if cached_url:
|
|
181
|
+
# 从缓存中获取尺寸信息
|
|
182
|
+
try:
|
|
183
|
+
dimensions = get_image_size(file_data)
|
|
184
|
+
except:
|
|
185
|
+
dimensions = (300, 300)
|
|
186
|
+
# 返回缓存的结果
|
|
187
|
+
return {
|
|
188
|
+
'success': True,
|
|
189
|
+
'cos_key': cached_url.replace(_get_cos_base_url() + '/', ''),
|
|
190
|
+
'file_url': cached_url,
|
|
191
|
+
'filename': os.path.basename(cached_url),
|
|
192
|
+
'file_size': sys.getsizeof(file_data),
|
|
193
|
+
'width': dimensions[0],
|
|
194
|
+
'height': dimensions[1],
|
|
195
|
+
'px': f'#{dimensions[0]}px #{dimensions[1]}px',
|
|
196
|
+
'cached': True
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
try:
|
|
200
|
+
dimensions = get_image_size(file_data)
|
|
201
|
+
except:
|
|
202
|
+
dimensions = (300, 300)
|
|
203
|
+
|
|
204
|
+
# 使用MD5作为文件名生成cos_key
|
|
205
|
+
cos_key = self._generate_cos_key(user_id, md5, file_data)
|
|
206
|
+
response = self.client.put_object(Bucket=self.config.bucket_name, Body=BytesIO(file_data),
|
|
207
|
+
Key=cos_key, ContentType=self._get_content_type(file_data))
|
|
208
|
+
base_url = f"https://{self.config.domain}" if self.config.domain else \
|
|
209
|
+
f"https://{self.config.bucket_name}.cos.{self.config.region}.myqcloud.com"
|
|
210
|
+
file_url = f"{base_url}/{cos_key}"
|
|
211
|
+
# 将URL存入缓存
|
|
212
|
+
self._cache_url(md5, file_url)
|
|
213
|
+
return {
|
|
214
|
+
'success': True, 'cos_key': cos_key, 'file_url': file_url,
|
|
215
|
+
'filename': os.path.basename(cos_key), 'file_size': sys.getsizeof(file_data),
|
|
216
|
+
'width': dimensions[0], 'height': dimensions[1], 'px': f'#{dimensions[0]}px #{dimensions[1]}px',
|
|
217
|
+
'cached': False
|
|
218
|
+
}
|
|
219
|
+
except:
|
|
220
|
+
return None
|
|
221
|
+
|
|
222
|
+
def delete_file(self, cos_key: str) -> bool:
|
|
223
|
+
"""删除COS上的文件
|
|
224
|
+
|
|
225
|
+
Args:
|
|
226
|
+
cos_key: COS路径
|
|
227
|
+
|
|
228
|
+
Returns:
|
|
229
|
+
bool: 是否删除成功
|
|
230
|
+
"""
|
|
231
|
+
if not self.client:
|
|
232
|
+
return False
|
|
233
|
+
try:
|
|
234
|
+
self.client.delete_object(Bucket=self.config.bucket_name, Key=cos_key)
|
|
235
|
+
return True
|
|
236
|
+
except:
|
|
237
|
+
return False
|
|
238
|
+
|
|
239
|
+
def get_file_info(self, cos_key: str) -> Optional[Dict[str, Any]]:
|
|
240
|
+
"""获取COS文件信息
|
|
241
|
+
|
|
242
|
+
Args:
|
|
243
|
+
cos_key: COS路径
|
|
244
|
+
|
|
245
|
+
Returns:
|
|
246
|
+
Optional[Dict[str, Any]]: 文件信息字典,包含:
|
|
247
|
+
- cos_key: COS路径
|
|
248
|
+
- content_length: 文件大小
|
|
249
|
+
- content_type: 文件类型
|
|
250
|
+
- last_modified: 最后修改时间
|
|
251
|
+
"""
|
|
252
|
+
if not self.client:
|
|
253
|
+
return None
|
|
254
|
+
try:
|
|
255
|
+
response = self.client.head_object(Bucket=self.config.bucket_name, Key=cos_key)
|
|
256
|
+
return {'cos_key': cos_key, 'content_length': response.get('Content-Length'),
|
|
257
|
+
'content_type': response.get('Content-Type'), 'last_modified': response.get('Last-Modified')}
|
|
258
|
+
except:
|
|
259
|
+
return None
|
|
260
|
+
|
|
261
|
+
def list_files(self, prefix: str = None, max_keys: int = 1000) -> Optional[list]:
|
|
262
|
+
"""列出COS上的文件
|
|
263
|
+
|
|
264
|
+
Args:
|
|
265
|
+
prefix: 路径前缀,用于筛选文件
|
|
266
|
+
max_keys: 最大返回数量
|
|
267
|
+
|
|
268
|
+
Returns:
|
|
269
|
+
Optional[list]: 文件列表,每个元素包含:
|
|
270
|
+
- key: COS路径
|
|
271
|
+
- size: 文件大小
|
|
272
|
+
- last_modified: 最后修改时间
|
|
273
|
+
"""
|
|
274
|
+
if not self.client:
|
|
275
|
+
return None
|
|
276
|
+
try:
|
|
277
|
+
kwargs = {'Bucket': self.config.bucket_name, 'MaxKeys': max_keys}
|
|
278
|
+
if prefix:
|
|
279
|
+
kwargs['Prefix'] = prefix
|
|
280
|
+
response = self.client.list_objects(**kwargs)
|
|
281
|
+
if 'Contents' not in response:
|
|
282
|
+
return []
|
|
283
|
+
return [{'key': obj['Key'], 'size': obj['Size'], 'last_modified': obj['LastModified']} for obj in
|
|
284
|
+
response['Contents']]
|
|
285
|
+
except:
|
|
286
|
+
return None
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
cos_uploader = COSUploader()
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def upload_image(file_data: bytes, user_id: str = None, return_url_only: bool = False):
|
|
293
|
+
"""上传图片到COS
|
|
294
|
+
|
|
295
|
+
Args:
|
|
296
|
+
file_data: 图片数据的bytes类型
|
|
297
|
+
user_id: 用户ID
|
|
298
|
+
return_url_only: 是否只返回URL
|
|
299
|
+
|
|
300
|
+
Returns:
|
|
301
|
+
上传结果或URL
|
|
302
|
+
"""
|
|
303
|
+
result = cos_uploader.upload_file(file_data, user_id)
|
|
304
|
+
return result['file_url'] if result and return_url_only else result
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def upload_file(file_data: bytes, user_id: str = None, return_url_only: bool = False):
|
|
308
|
+
return upload_image(file_data, user_id, return_url_only=return_url_only)
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def simple_upload_file(file_data: bytes, user_id: str = None):
|
|
312
|
+
return upload_image(file_data, user_id, return_url_only=True)
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
def _get_cos_base_url() -> str:
|
|
316
|
+
base_url = f"https://{cos_uploader.config['domain']}" if cos_uploader.config.get('domain') else \
|
|
317
|
+
f"https://{cos_uploader.config['bucket_name']}.cos.{cos_uploader.config['region']}.myqcloud.com"
|
|
318
|
+
return base_url
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def get_upload_url(cos_key: str):
|
|
322
|
+
return f"{_get_cos_base_url()}/{cos_key}"
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def delete_by_url(file_url: str):
|
|
326
|
+
if not file_url:
|
|
327
|
+
return False
|
|
328
|
+
base_url = _get_cos_base_url()
|
|
329
|
+
return cos_uploader.delete_file(file_url[len(base_url):]) if file_url.startswith(base_url) else False
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import datetime
|
|
2
|
+
import io
|
|
2
3
|
import os
|
|
3
4
|
import random
|
|
4
5
|
|
|
5
6
|
import cloudscraper
|
|
6
7
|
import httpx
|
|
7
|
-
from PIL import ImageFont
|
|
8
|
+
from PIL import ImageFont, Image
|
|
8
9
|
from httpx import Response
|
|
9
10
|
|
|
10
11
|
from .dataClass import TimeUtil
|
|
@@ -19,7 +20,6 @@ proxy_address = plugin_config.splatoon3_proxy_address
|
|
|
19
20
|
|
|
20
21
|
proxies = f"http://{proxy_address}" if proxy_address else None
|
|
21
22
|
|
|
22
|
-
|
|
23
23
|
# 背景 rgb颜色
|
|
24
24
|
dict_bg_rgb = {
|
|
25
25
|
"Turf War": (24, 200, 26),
|
|
@@ -170,3 +170,11 @@ def ttf_get_size(font: ImageFont.FreeTypeFont, text: str) -> tuple:
|
|
|
170
170
|
height = bbox[3] - bbox[1] # 文本高度
|
|
171
171
|
time_text_size = (width, height) # 与原 getsize() 返回格式一致
|
|
172
172
|
return time_text_size
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def get_image_size(img_data):
|
|
176
|
+
# 通过pillow库获取图片宽高数据
|
|
177
|
+
image = Image.open(io.BytesIO(img_data))
|
|
178
|
+
width, height = image.size
|
|
179
|
+
image.close()
|
|
180
|
+
return width, height
|
{nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/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.5"
|
|
4
4
|
description = "一个基于nonebot2框架的splatoon3游戏日程查询插件"
|
|
5
5
|
authors = ["cypas <ayano05@outlook.com>"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -21,6 +21,7 @@ nonebot-adapter-kaiheila = "^0.3.4"
|
|
|
21
21
|
nonebot-adapter-qq = "^1.6.6"
|
|
22
22
|
nonebot-plugin-apscheduler = "^0.5.0"
|
|
23
23
|
nonebot_plugin_datastore = "^1.3.0"
|
|
24
|
+
cos_python_sdk_v5 = "^1.9.30"
|
|
24
25
|
|
|
25
26
|
[tool.poetry.group.test.dependencies]
|
|
26
27
|
nonebug = "^0.3.5"
|
|
File without changes
|
{nonebot_plugin_splatoon3_schedule-2.0.4 → nonebot_plugin_splatoon3_schedule-2.0.5}/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
|