mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-12 06:55:49 +08:00
✨ core端增加image和file的url支持 (#13)
* core端增加image和file的url支持
* core端增加image和file的url支持
* 🚨 `pre-commit-ci`修复格式错误
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
699af6dffb
commit
787c9a16d0
@ -25,6 +25,8 @@ class MessageSegment:
|
||||
with open(str(img), 'rb') as fp:
|
||||
img = fp.read()
|
||||
else:
|
||||
if img.startswith('http'):
|
||||
return Message(type='image', data=f'link://{img}')
|
||||
if img.startswith('base64://'):
|
||||
return Message(type='image', data=img)
|
||||
with open(img, 'rb') as fp:
|
||||
@ -53,6 +55,10 @@ class MessageSegment:
|
||||
else:
|
||||
if msg.startswith('base64://'):
|
||||
msg_list.append(Message(type='image', data=msg))
|
||||
elif msg.startswith('http'):
|
||||
msg_list.append(
|
||||
Message(type='image', data=f'link://{msg}')
|
||||
)
|
||||
else:
|
||||
msg_list.append(MessageSegment.text(msg))
|
||||
return Message(type='node', data=msg_list)
|
||||
@ -78,6 +84,13 @@ class MessageSegment:
|
||||
file = fp.read()
|
||||
elif isinstance(content, bytes):
|
||||
file = content
|
||||
else:
|
||||
if content.startswith('http'):
|
||||
link = content
|
||||
return Message(
|
||||
type='file',
|
||||
data=f'{file_name}|link://{link}',
|
||||
)
|
||||
else:
|
||||
with open(content, 'rb') as fp:
|
||||
file = fp.read()
|
||||
|
Loading…
x
Reference in New Issue
Block a user