mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
Merge pull request #124 from Nova-Noir/main
Fixed error in custom_welcome_msg and message_builder
This commit is contained in:
commit
a0115309dd
@ -75,7 +75,7 @@ async def custom_group_welcome(
|
|||||||
await AsyncHttpx.download_file(
|
await AsyncHttpx.download_file(
|
||||||
img, DATA_PATH / "custom_welcome_msg" / f"{group_id}.jpg"
|
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} 更换群欢迎消息图片")
|
logger.info(f"USER {user_id} GROUP {group_id} 更换群欢迎消息图片")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"GROUP {group_id} 替换群消息失败 e:{e}")
|
logger.error(f"GROUP {group_id} 替换群消息失败 e:{e}")
|
||||||
|
|||||||
@ -129,7 +129,7 @@ async def _(bot: Bot, event: GroupIncreaseNoticeEvent):
|
|||||||
at_flag = True
|
at_flag = True
|
||||||
if (DATA_PATH / "custom_welcome_msg" / f"{event.group_id}.jpg").exists():
|
if (DATA_PATH / "custom_welcome_msg" / f"{event.group_id}.jpg").exists():
|
||||||
img = image(
|
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:
|
if msg or img:
|
||||||
msg = msg.strip() + img
|
msg = msg.strip() + img
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import os
|
|||||||
def image(
|
def image(
|
||||||
file: Union[str, Path, bytes] = None,
|
file: Union[str, Path, bytes] = None,
|
||||||
path: str = None,
|
path: str = None,
|
||||||
abspath: Union[str, Path] = None,
|
|
||||||
b64: str = None,
|
b64: str = None,
|
||||||
) -> Union[MessageSegment, str]:
|
) -> Union[MessageSegment, str]:
|
||||||
"""
|
"""
|
||||||
@ -20,18 +19,9 @@ def image(
|
|||||||
参数:
|
参数:
|
||||||
:param file: 图片文件名称,默认在 resource/img 目录下
|
:param file: 图片文件名称,默认在 resource/img 目录下
|
||||||
:param path: 图片所在路径,默认在 resource/img 目录下
|
:param path: 图片所在路径,默认在 resource/img 目录下
|
||||||
:param abspath: 图片绝对路径
|
|
||||||
:param b64: 图片base64
|
:param b64: 图片base64
|
||||||
"""
|
"""
|
||||||
if abspath:
|
if isinstance(file, Path):
|
||||||
if isinstance(abspath, Path):
|
|
||||||
return MessageSegment.image(file)
|
|
||||||
return (
|
|
||||||
MessageSegment.image("file:///" + abspath)
|
|
||||||
if os.path.exists(abspath)
|
|
||||||
else ""
|
|
||||||
)
|
|
||||||
elif isinstance(file, Path):
|
|
||||||
if file.exists():
|
if file.exists():
|
||||||
return MessageSegment.image(file)
|
return MessageSegment.image(file)
|
||||||
logger.warning(f"图片 {file.absolute()}缺失...")
|
logger.warning(f"图片 {file.absolute()}缺失...")
|
||||||
@ -41,14 +31,11 @@ def image(
|
|||||||
elif b64:
|
elif b64:
|
||||||
return MessageSegment.image(b64 if "base64://" in b64 else "base64://" + b64)
|
return MessageSegment.image(b64 if "base64://" in b64 else "base64://" + b64)
|
||||||
else:
|
else:
|
||||||
if "http" in file:
|
if file.startswith("http"):
|
||||||
return MessageSegment.image(file)
|
return MessageSegment.image(file)
|
||||||
if len(file.split(".")) == 1:
|
if len(file.split(".")) == 1:
|
||||||
file += ".jpg"
|
file += ".jpg"
|
||||||
file = (
|
if (file := IMAGE_PATH / path / file if path else IMAGE_PATH / file).exists():
|
||||||
IMAGE_PATH / path / file if path else IMAGE_PATH / file
|
|
||||||
)
|
|
||||||
if file.exists():
|
|
||||||
return MessageSegment.image(file)
|
return MessageSegment.image(file)
|
||||||
else:
|
else:
|
||||||
logger.warning(f"图片 {file} 缺失...")
|
logger.warning(f"图片 {file} 缺失...")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user