From 35e9de7abc8fd3e192810ce0c5486acd5914d838 Mon Sep 17 00:00:00 2001 From: yzhh <31803608+OasisAkari@users.noreply.github.com> Date: Sat, 24 Feb 2024 16:50:42 +0800 Subject: [PATCH] bugfix --- core/types/message/__init__.py | 9 +++++---- modules/wiki/inline.py | 37 ++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/core/types/message/__init__.py b/core/types/message/__init__.py index 9860df00..b22545a4 100644 --- a/core/types/message/__init__.py +++ b/core/types/message/__init__.py @@ -4,6 +4,7 @@ from typing import List, Union, Dict, Coroutine, Awaitable from core.exceptions import FinishedException from .chain import MessageChain +from .internal import Plain, Image, Voice, Embed, Url, ErrorMessage class MsgInfo: @@ -30,8 +31,8 @@ class MsgInfo: def __repr__(self): return f'MsgInfo(target_id={self.target_id}, sender_id={self.sender_id}, sender_name={self.sender_name},' \ - f' target_from={self.target_from}, sender_from={self.sender_from}, client_name={self.client_name}, ' \ - f'message_id={self.message_id}, reply_id={self.reply_id})' + f' target_from={self.target_from}, sender_from={self.sender_from}, client_name={self.client_name}, ' \ + f'message_id={self.message_id}, reply_id={self.reply_id})' class Session: @@ -87,7 +88,7 @@ class MessageSession: self.tmp = {} async def send_message(self, - message_chain: MessageChain, + message_chain: Union[MessageChain, str, Plain, Image, Voice, Embed, Url, ErrorMessage], quote=True, disable_secret_check=False, allow_split_image=True, @@ -104,7 +105,7 @@ class MessageSession: raise NotImplementedError async def finish(self, - message_chain: MessageChain = None, + message_chain: Union[MessageChain, str, Plain, Image, Voice, Embed, Url, ErrorMessage] = None, quote: bool = True, disable_secret_check: bool = False, allow_split_image: bool = True, diff --git a/modules/wiki/inline.py b/modules/wiki/inline.py index f50293cd..13ce7c78 100644 --- a/modules/wiki/inline.py +++ b/modules/wiki/inline.py @@ -150,25 +150,28 @@ async def _(msg: Bot.MessageSession): await msg.send_message(Image(get_infobox), quote=False) if get_page.invalid_section and wiki_.wiki_info.in_allowlist and web_render: i_msg_lst = [] - session_data = [[str(i + 1), get_page.sections[i]] for i in - range(len(get_page.sections))] - i_msg_lst.append(Plain(msg.locale.t('wiki.message.invalid_section'))) - i_msg_lst.append(Image(await - image_table_render( - ImageTable(session_data, - ['ID', - msg.locale.t('wiki.message.section')])))) + if get_page.sections: + session_data = [[str(i + 1), get_page.sections[i]] for i in + range(len(get_page.sections))] + i_msg_lst.append(Plain(msg.locale.t('wiki.message.invalid_section'))) + i_msg_lst.append(Image(await + image_table_render( + ImageTable(session_data, + ['ID', + msg.locale.t('wiki.message.section')])))) - async def _callback(msg: Bot.MessageSession): - display = msg.as_display(text_only=True) - if display.isdigit(): - display = int(display) - if display <= len(get_page.sections): - get_page.selected_section = display - 1 - await query_pages(msg, title=get_page.title + '#' + - get_page.sections[display - 1]) + async def _callback(msg: Bot.MessageSession): + display = msg.as_display(text_only=True) + if display.isdigit(): + display = int(display) + if display <= len(get_page.sections): + get_page.selected_section = display - 1 + await query_pages(msg, title=get_page.title + '#' + + get_page.sections[display - 1]) - await msg.send_message(i_msg_lst, callback=_callback) + await msg.send_message(i_msg_lst, callback=_callback) + else: + await msg.send_message(Plain(msg.locale.t('wiki.message.invalid_section.prompt'))) if len(query_list) == 1 and img_send: return if msg.Feature.image: