🐛 修复BUG, 新增Bot.send_option()

This commit is contained in:
KimigaiiWuyi 2023-10-03 01:50:57 +08:00
parent 8ac55ceb5e
commit 2c36ff7397
2 changed files with 33 additions and 12 deletions

View File

@ -39,11 +39,16 @@ class _Bot:
if at_sender and sender_id: if at_sender and sender_id:
_message.append(MessageSegment.at(sender_id)) _message.append(MessageSegment.at(sender_id))
send_message = []
for _m in _message:
if _m.type not in ['image_size']:
send_message.append(_m)
if is_specific_msg_id and not msg_id: if is_specific_msg_id and not msg_id:
msg_id = specific_msg_id msg_id = specific_msg_id
send = MessageSend( send = MessageSend(
content=_message, content=send_message,
bot_id=bot_id, bot_id=bot_id,
bot_self_id=bot_self_id, bot_self_id=bot_self_id,
target_type=target_type, target_type=target_type,
@ -90,12 +95,26 @@ class Bot:
def set_event(self): def set_event(self):
self.event.set() self.event.set()
async def send_option(
self,
reply: Optional[
Union[Message, List[Message], List[str], str, bytes]
] = None,
option_list: Optional[List[Union[str, Button]]] = None,
unsuported_platform: bool = False,
):
return await self.receive_resp(
reply, option_list, unsuported_platform, False
)
async def receive_resp( async def receive_resp(
self, self,
reply: Optional[ reply: Optional[
Union[Message, List[Message], List[str], str, bytes] Union[Message, List[Message], List[str], str, bytes]
] = None, ] = None,
option_list: Optional[List[Union[str, Button]]] = None, option_list: Optional[List[Union[str, Button]]] = None,
unsuported_platform: bool = False,
is_recive: bool = True,
timeout: float = 60, timeout: float = 60,
) -> Optional[Event]: ) -> Optional[Event]:
if option_list: if option_list:
@ -112,24 +131,26 @@ class Bot:
_buttons.append(option) _buttons.append(option)
else: else:
_buttons.append(Button(option, option, option)) _buttons.append(Button(option, option, option))
logger.info(_reply_str) logger.debug(_reply_str)
logger.info(_buttons) logger.debug(_buttons)
await self.send(MessageSegment.markdown(_reply_str, _buttons)) await self.send(MessageSegment.markdown(_reply_str, _buttons))
else: else:
_options: List[str] = [] if unsuported_platform:
for option in option_list: _options: List[str] = []
if isinstance(option, Button): for option in option_list:
_options.append(option.text) if isinstance(option, Button):
else: _options.append(option.text)
_options.append(option) else:
_options.append(option)
_reply.append(MessageSegment.text('/'.join(_options))) _reply.append(MessageSegment.text('/'.join(_options)))
await self.send(_reply) await self.send(_reply)
elif reply: elif reply:
await self.send(reply) await self.send(reply)
return await self.wait_for_key(timeout) if is_recive:
return await self.wait_for_key(timeout)
async def send( async def send(
self, self,

View File

@ -160,7 +160,7 @@ async def convert_message(
else: else:
message = [MessageSegment.text(message)] message = [MessageSegment.text(message)]
elif isinstance(message, bytes): elif isinstance(message, bytes):
img = Image.open(message) img = Image.open(BytesIO(message))
message = [ message = [
MessageSegment.image(message), MessageSegment.image(message),
MessageSegment.image_size(img.size), MessageSegment.image_size(img.size),