Merge pull request #124 from Nova-Noir/main

Fixed error in custom_welcome_msg and message_builder
This commit is contained in:
HibiKier 2022-02-24 16:12:39 +08:00 committed by GitHub
commit a0115309dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 18 deletions

View File

@ -75,7 +75,7 @@ async def custom_group_welcome(
await AsyncHttpx.download_file(
img, DATA_PATH / "custom_welcome_msg" / f"{group_id}.jpg"
)
img_result = image(abspath=DATA_PATH / "custom_welcome_msg" / f"{group_id}.jpg")
img_result = image(DATA_PATH / "custom_welcome_msg" / f"{group_id}.jpg")
logger.info(f"USER {user_id} GROUP {group_id} 更换群欢迎消息图片")
except Exception as e:
logger.error(f"GROUP {group_id} 替换群消息失败 e:{e}")

View File

@ -129,7 +129,7 @@ async def _(bot: Bot, event: GroupIncreaseNoticeEvent):
at_flag = True
if (DATA_PATH / "custom_welcome_msg" / f"{event.group_id}.jpg").exists():
img = image(
abspath=DATA_PATH / "custom_welcome_msg" / f"{event.group_id}.jpg"
DATA_PATH / "custom_welcome_msg" / f"{event.group_id}.jpg"
)
if msg or img:
msg = msg.strip() + img

View File

@ -10,7 +10,6 @@ import os
def image(
file: Union[str, Path, bytes] = None,
path: str = None,
abspath: Union[str, Path] = None,
b64: str = None,
) -> Union[MessageSegment, str]:
"""
@ -20,18 +19,9 @@ def image(
参数
:param file: 图片文件名称默认在 resource/img 目录下
:param path: 图片所在路径默认在 resource/img 目录下
:param abspath: 图片绝对路径
:param b64: 图片base64
"""
if abspath:
if isinstance(abspath, Path):
return MessageSegment.image(file)
return (
MessageSegment.image("file:///" + abspath)
if os.path.exists(abspath)
else ""
)
elif isinstance(file, Path):
if isinstance(file, Path):
if file.exists():
return MessageSegment.image(file)
logger.warning(f"图片 {file.absolute()}缺失...")
@ -41,14 +31,11 @@ def image(
elif b64:
return MessageSegment.image(b64 if "base64://" in b64 else "base64://" + b64)
else:
if "http" in file:
if file.startswith("http"):
return MessageSegment.image(file)
if len(file.split(".")) == 1:
file += ".jpg"
file = (
IMAGE_PATH / path / file if path else IMAGE_PATH / file
)
if file.exists():
if (file := IMAGE_PATH / path / file if path else IMAGE_PATH / file).exists():
return MessageSegment.image(file)
else:
logger.warning(f"图片 {file} 缺失...")