mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-12 06:55:49 +08:00
🐛 完善link://
发送, 调整部分发送
This commit is contained in:
parent
cdb6905f68
commit
6155b36d2b
@ -11,8 +11,9 @@ from gsuid_core.models import Event, Message, MessageSend
|
|||||||
from gsuid_core.utils.plugins_config.gs_config import core_plugins_config
|
from gsuid_core.utils.plugins_config.gs_config import core_plugins_config
|
||||||
from gsuid_core.segment import MessageSegment, to_markdown, convert_message
|
from gsuid_core.segment import MessageSegment, to_markdown, convert_message
|
||||||
|
|
||||||
is_specific_msg_id = core_plugins_config.get_config('EnableSpecificMsgId').data
|
is_sp_msg_id: str = core_plugins_config.get_config('EnableSpecificMsgId').data
|
||||||
specific_msg_id = core_plugins_config.get_config('SpecificMsgId').data
|
sp_msg_id: str = core_plugins_config.get_config('SpecificMsgId').data
|
||||||
|
is_markdown: List = core_plugins_config.get_config('SendMDPlatform').data
|
||||||
|
|
||||||
|
|
||||||
class _Bot:
|
class _Bot:
|
||||||
@ -37,7 +38,7 @@ class _Bot:
|
|||||||
):
|
):
|
||||||
_message = await convert_message(message)
|
_message = await convert_message(message)
|
||||||
|
|
||||||
if bot_id in ['qqgroup']:
|
if bot_id in is_markdown:
|
||||||
_message = await to_markdown(_message)
|
_message = await to_markdown(_message)
|
||||||
|
|
||||||
if at_sender and sender_id:
|
if at_sender and sender_id:
|
||||||
@ -46,8 +47,8 @@ class _Bot:
|
|||||||
if group_id:
|
if group_id:
|
||||||
_message.append(Message('group', group_id))
|
_message.append(Message('group', group_id))
|
||||||
|
|
||||||
if is_specific_msg_id and not msg_id:
|
if is_sp_msg_id and not msg_id:
|
||||||
msg_id = specific_msg_id
|
msg_id = sp_msg_id
|
||||||
|
|
||||||
send = MessageSend(
|
send = MessageSend(
|
||||||
content=_message,
|
content=_message,
|
||||||
|
@ -55,6 +55,8 @@ class MessageSegment:
|
|||||||
elif isinstance(img, Path):
|
elif isinstance(img, Path):
|
||||||
with open(str(img), 'rb') as fp:
|
with open(str(img), 'rb') as fp:
|
||||||
img = fp.read()
|
img = fp.read()
|
||||||
|
elif isinstance(img, (bytearray, memoryview)):
|
||||||
|
img = bytes(img)
|
||||||
else:
|
else:
|
||||||
if img.startswith('http'):
|
if img.startswith('http'):
|
||||||
return Message(type='image', data=f'link://{img}')
|
return Message(type='image', data=f'link://{img}')
|
||||||
@ -67,7 +69,7 @@ class MessageSegment:
|
|||||||
name = f'{uuid.uuid1()}.jpg'
|
name = f'{uuid.uuid1()}.jpg'
|
||||||
path = image_res / name
|
path = image_res / name
|
||||||
path.write_bytes(img)
|
path.write_bytes(img)
|
||||||
data = f'{pic_srv}/genshinuid/image/{name}'
|
data = f'link://{pic_srv}/genshinuid/image/{name}'
|
||||||
else:
|
else:
|
||||||
data = f'base64://{b64encode(img).decode()}'
|
data = f'base64://{b64encode(img).decode()}'
|
||||||
|
|
||||||
@ -109,6 +111,8 @@ class MessageSegment:
|
|||||||
msg_list.append(msg)
|
msg_list.append(msg)
|
||||||
elif isinstance(msg, bytes):
|
elif isinstance(msg, bytes):
|
||||||
msg_list.append(MessageSegment.image(msg))
|
msg_list.append(MessageSegment.image(msg))
|
||||||
|
elif isinstance(msg, (bytearray, memoryview)):
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
if msg.startswith('base64://'):
|
if msg.startswith('base64://'):
|
||||||
msg_list.append(Message(type='image', data=msg))
|
msg_list.append(Message(type='image', data=msg))
|
||||||
@ -127,6 +131,8 @@ class MessageSegment:
|
|||||||
elif isinstance(content, Path):
|
elif isinstance(content, Path):
|
||||||
with open(str(content), 'rb') as fp:
|
with open(str(content), 'rb') as fp:
|
||||||
content = fp.read()
|
content = fp.read()
|
||||||
|
elif isinstance(content, (bytearray, memoryview)):
|
||||||
|
content = bytes(content)
|
||||||
else:
|
else:
|
||||||
if content.startswith('base64://'):
|
if content.startswith('base64://'):
|
||||||
return Message(type='image', data=content)
|
return Message(type='image', data=content)
|
||||||
@ -141,6 +147,8 @@ class MessageSegment:
|
|||||||
file = fp.read()
|
file = fp.read()
|
||||||
elif isinstance(content, bytes):
|
elif isinstance(content, bytes):
|
||||||
file = content
|
file = content
|
||||||
|
elif isinstance(content, (bytearray, memoryview)):
|
||||||
|
file = bytes(content)
|
||||||
else:
|
else:
|
||||||
if content.startswith('http'):
|
if content.startswith('http'):
|
||||||
link = content
|
link = content
|
||||||
@ -205,9 +213,11 @@ async def _convert_message(
|
|||||||
MessageSegment.image(img_url if img_url else message),
|
MessageSegment.image(img_url if img_url else message),
|
||||||
MessageSegment.image_size(img.size),
|
MessageSegment.image_size(img.size),
|
||||||
]
|
]
|
||||||
|
elif isinstance(message, (bytearray, memoryview)):
|
||||||
|
_message = [MessageSegment.image(bytes(message))]
|
||||||
else:
|
else:
|
||||||
_message = [message]
|
_message = [message]
|
||||||
return _message
|
return _message # type: ignore
|
||||||
|
|
||||||
|
|
||||||
async def convert_message(
|
async def convert_message(
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from typing import List, Literal, Optional, TypedDict
|
from typing import Dict, List, Literal, Optional, TypedDict
|
||||||
|
|
||||||
# https://peps.python.org/pep-0655/#usage-in-python-3-11
|
# https://peps.python.org/pep-0655/#usage-in-python-3-11
|
||||||
if sys.version_info >= (3, 11):
|
if sys.version_info >= (3, 11):
|
||||||
@ -207,6 +207,11 @@ class DailyNoteData(TypedDict):
|
|||||||
# Response from https://api-takumi.mihoyo.com/game_record/app/genshin/api/index
|
# Response from https://api-takumi.mihoyo.com/game_record/app/genshin/api/index
|
||||||
|
|
||||||
|
|
||||||
|
class ExtMap(TypedDict):
|
||||||
|
link: str
|
||||||
|
backup_link: str
|
||||||
|
|
||||||
|
|
||||||
class Stats(TypedDict):
|
class Stats(TypedDict):
|
||||||
active_day_number: int
|
active_day_number: int
|
||||||
achievement_number: int
|
achievement_number: int
|
||||||
@ -223,6 +228,10 @@ class Stats(TypedDict):
|
|||||||
electroculus_number: int
|
electroculus_number: int
|
||||||
magic_chest_number: int
|
magic_chest_number: int
|
||||||
dendroculus_number: int
|
dendroculus_number: int
|
||||||
|
hydroculus_number: int
|
||||||
|
pyroculus_number: int
|
||||||
|
cryoculus_number: int
|
||||||
|
field_ext_map: Dict[str, ExtMap]
|
||||||
|
|
||||||
|
|
||||||
class Offering(TypedDict):
|
class Offering(TypedDict):
|
||||||
|
@ -2,8 +2,11 @@ from pathlib import Path
|
|||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
from http.cookies import SimpleCookie
|
from http.cookies import SimpleCookie
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
from gsuid_core.utils.api.mys_api import mys_api
|
from gsuid_core.utils.api.mys_api import mys_api
|
||||||
from gsuid_core.utils.error_reply import UID_HINT
|
from gsuid_core.utils.error_reply import UID_HINT
|
||||||
|
from gsuid_core.utils.image.convert import convert_img
|
||||||
from gsuid_core.utils.database.utils import SERVER, SR_SERVER
|
from gsuid_core.utils.database.utils import SERVER, SR_SERVER
|
||||||
from gsuid_core.utils.database.models import GsBind, GsUser, GsCache
|
from gsuid_core.utils.database.models import GsBind, GsUser, GsCache
|
||||||
|
|
||||||
@ -99,9 +102,8 @@ async def _deal_ck_to_pic(im: str) -> bytes:
|
|||||||
status_pic = pic_path / 'ck_ok.png'
|
status_pic = pic_path / 'ck_ok.png'
|
||||||
else:
|
else:
|
||||||
status_pic = pic_path / 'all_ok.png'
|
status_pic = pic_path / 'all_ok.png'
|
||||||
with open(status_pic, 'rb') as f:
|
img = Image.open(status_pic).convert('RGB')
|
||||||
img = f.read()
|
return await convert_img(img)
|
||||||
return img
|
|
||||||
|
|
||||||
|
|
||||||
async def get_account_id(simp_dict: SimpleCookie) -> str:
|
async def get_account_id(simp_dict: SimpleCookie) -> str:
|
||||||
|
44
gsuid_core/utils/download_resource/download_image.py
Normal file
44
gsuid_core/utils/download_resource/download_image.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
from io import BytesIO
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Tuple, Optional
|
||||||
|
|
||||||
|
import aiofiles
|
||||||
|
from PIL import Image
|
||||||
|
from aiohttp.client import ClientSession
|
||||||
|
from aiohttp.client_exceptions import ClientConnectorError
|
||||||
|
|
||||||
|
from gsuid_core.logger import logger
|
||||||
|
|
||||||
|
|
||||||
|
async def get_image(
|
||||||
|
url: str,
|
||||||
|
path: Path,
|
||||||
|
size: Optional[Tuple[int, int]] = None,
|
||||||
|
name: Optional[str] = None,
|
||||||
|
) -> Image.Image:
|
||||||
|
if name is None:
|
||||||
|
name = url.split('/')[-1]
|
||||||
|
|
||||||
|
file_path = path / name
|
||||||
|
if file_path.exists():
|
||||||
|
if size:
|
||||||
|
return Image.open(file_path).resize(size)
|
||||||
|
return Image.open(file_path)
|
||||||
|
|
||||||
|
async with ClientSession() as sess:
|
||||||
|
try:
|
||||||
|
logger.info(f'[GsCore]开始下载: {name} | 地址: {url}')
|
||||||
|
async with sess.get(url) as res:
|
||||||
|
content = await res.read()
|
||||||
|
logger.info(f'[GsCore]下载成功: {name}')
|
||||||
|
except ClientConnectorError:
|
||||||
|
logger.warning(f"[GsCore]{name}下载失败")
|
||||||
|
return Image.new('RGBA', (256, 256))
|
||||||
|
|
||||||
|
async with aiofiles.open(path / name, "wb") as f:
|
||||||
|
await f.write(content)
|
||||||
|
stream = BytesIO(content)
|
||||||
|
if size:
|
||||||
|
return Image.open(stream).resize(size)
|
||||||
|
else:
|
||||||
|
return Image.open(stream)
|
@ -328,7 +328,7 @@ class CustomizeImage:
|
|||||||
if abs(light_value - based_light) < temp: # noqa:E203
|
if abs(light_value - based_light) < temp: # noqa:E203
|
||||||
bg_color = bg
|
bg_color = bg
|
||||||
temp = abs(light_value - based_light)
|
temp = abs(light_value - based_light)
|
||||||
return bg_color
|
return bg_color # type:ignore
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_text_color(bg_color: Tuple[int, int, int]) -> Tuple[int, int, int]:
|
def get_text_color(bg_color: Tuple[int, int, int]) -> Tuple[int, int, int]:
|
||||||
|
@ -59,7 +59,8 @@ CONIFG_DEFAULT: Dict[str, GSC] = {
|
|||||||
'EnableSpecificMsgId': GsBoolConfig('启用回复特殊ID', '如不知道请勿开启', False),
|
'EnableSpecificMsgId': GsBoolConfig('启用回复特殊ID', '如不知道请勿开启', False),
|
||||||
'SpecificMsgId': GsStrConfig('特殊返回消息ID', '如不知道请勿填写', ''),
|
'SpecificMsgId': GsStrConfig('特殊返回消息ID', '如不知道请勿填写', ''),
|
||||||
'AutoUpdateDep': GsBoolConfig('自动更新依赖', '更新插件时将会自动更新依赖', False),
|
'AutoUpdateDep': GsBoolConfig('自动更新依赖', '更新插件时将会自动更新依赖', False),
|
||||||
'EnablePicSrv': GsBoolConfig('将图片转链接发送(需公网)', '发送图片转链接', False),
|
'EnablePicSrv': GsBoolConfig('启用将图片转链接发送(需公网)', '发送图片转链接', False),
|
||||||
'PicSrv': GsStrConfig('将图片转链接发送(需公网)', '发送图片转链接', ''),
|
'PicSrv': GsStrConfig('图片转链接为(需公网)', '发送图片转链接', ''),
|
||||||
'ProxyURL': GsStrConfig('安装插件时使用git代理地址', 'git代理地址', ''),
|
'ProxyURL': GsStrConfig('安装插件时使用git代理地址', 'git代理地址', ''),
|
||||||
|
'SendMDPlatform': GsListStrConfig('发送MD的平台列表(用:连接)', '发送MD的平台列表', []),
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user