From 2c36ff739733bf6f4543ca1885b41d7211868162 Mon Sep 17 00:00:00 2001 From: KimigaiiWuyi <444835641@qq.com> Date: Tue, 3 Oct 2023 01:50:57 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8DBUG,=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E`Bot.send=5Foption()`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gsuid_core/bot.py | 43 ++++++++++++++++++++++++++++++++----------- gsuid_core/segment.py | 2 +- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/gsuid_core/bot.py b/gsuid_core/bot.py index be77d74..4b7d6ff 100644 --- a/gsuid_core/bot.py +++ b/gsuid_core/bot.py @@ -39,11 +39,16 @@ class _Bot: if at_sender and 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: msg_id = specific_msg_id send = MessageSend( - content=_message, + content=send_message, bot_id=bot_id, bot_self_id=bot_self_id, target_type=target_type, @@ -90,12 +95,26 @@ class Bot: def set_event(self): 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( self, reply: Optional[ Union[Message, List[Message], List[str], str, bytes] ] = None, option_list: Optional[List[Union[str, Button]]] = None, + unsuported_platform: bool = False, + is_recive: bool = True, timeout: float = 60, ) -> Optional[Event]: if option_list: @@ -112,24 +131,26 @@ class Bot: _buttons.append(option) else: _buttons.append(Button(option, option, option)) - logger.info(_reply_str) - logger.info(_buttons) + logger.debug(_reply_str) + logger.debug(_buttons) await self.send(MessageSegment.markdown(_reply_str, _buttons)) else: - _options: List[str] = [] - for option in option_list: - if isinstance(option, Button): - _options.append(option.text) - else: - _options.append(option) + if unsuported_platform: + _options: List[str] = [] + for option in option_list: + if isinstance(option, Button): + _options.append(option.text) + else: + _options.append(option) - _reply.append(MessageSegment.text('/'.join(_options))) + _reply.append(MessageSegment.text('/'.join(_options))) await self.send(_reply) elif 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( self, diff --git a/gsuid_core/segment.py b/gsuid_core/segment.py index 6430f97..14685ed 100644 --- a/gsuid_core/segment.py +++ b/gsuid_core/segment.py @@ -160,7 +160,7 @@ async def convert_message( else: message = [MessageSegment.text(message)] elif isinstance(message, bytes): - img = Image.open(message) + img = Image.open(BytesIO(message)) message = [ MessageSegment.image(message), MessageSegment.image_size(img.size),