diff --git a/core/bots/aiocqhttp/client.py b/core/bots/aiocqhttp/client.py index 50571695..f194e708 100644 --- a/core/bots/aiocqhttp/client.py +++ b/core/bots/aiocqhttp/client.py @@ -1,4 +1,4 @@ from aiocqhttp import CQHttp -bot = CQHttp() \ No newline at end of file +bot = CQHttp() diff --git a/core/bots/aiocqhttp/message.py b/core/bots/aiocqhttp/message.py index 9bf245d5..544bc3fc 100644 --- a/core/bots/aiocqhttp/message.py +++ b/core/bots/aiocqhttp/message.py @@ -4,7 +4,7 @@ import traceback from typing import List from pathlib import Path -from aiocqhttp import Message, MessageSegment, Event +from aiocqhttp import MessageSegment from core.bots.aiocqhttp.client import bot from core.bots.aiocqhttp.tasks import MessageTaskManager, FinishedTasks from core.elements import Plain, Image, MessageSession as MS, MsgInfo, Session, Voice, FetchTarget as FT @@ -32,17 +32,19 @@ class MessageSession(MS): if quote: msg = MessageSegment.reply(self.session.message.message_id) if isinstance(msgchain, str): - msg = msg + MessageSegment.text(msgchain) - if isinstance(msgchain, (list, tuple)): - count = 0 + msg = msg + (MessageSegment.text(msgchain) if msgchain != '' else '发生错误:机器人尝试发送空文本消息,请联系机器人开发者解决问题。' + '\n错误汇报地址:https://github.com/Teahouse-Studios/bot/issues/new?assignees=OasisAkari&labels=bug&template=5678.md&title=') + elif isinstance(msgchain, (list, tuple)): for x in msgchain: if isinstance(x, Plain): msg = msg + MessageSegment.text(x.text) - if isinstance(x, Image): + elif isinstance(x, Image): msg = msg + MessageSegment.image(Path(await x.get()).as_uri()) - if isinstance(x, Voice): + elif isinstance(x, Voice): msg = msg + MessageSegment.record(Path(x.path).as_uri()) - count += 1 + else: + msg = msg + MessageSegment.text('发生错误:机器人尝试发送非法消息链,请联系机器人开发者解决问题。' + '\n错误汇报地址:https://github.com/Teahouse-Studios/bot/issues/new?assignees=OasisAkari&labels=bug&template=5678.md&title=') if self.target.targetFrom == 'QQ|Group': send = await bot.send_group_msg(group_id=self.session.target, message=msg) else: diff --git a/core/bots/aiogram/message.py b/core/bots/aiogram/message.py index 91955859..c8f81553 100644 --- a/core/bots/aiogram/message.py +++ b/core/bots/aiogram/message.py @@ -26,35 +26,41 @@ class MessageSession(MS): async def sendMessage(self, msgchain, quote=True): if isinstance(msgchain, str): + if msgchain == '': + msgchain = '发生错误:机器人尝试发送空文本消息,请联系机器人开发者解决问题。\n错误汇报地址:https://github.com/Teahouse-Studios/bot/issues/new?assignees=OasisAkari&labels=bug&template=5678.md&title=' send = await bot.send_message(self.session.target, msgchain, reply_to_message_id=self.session.message.message_id if quote and self.session.message else None) - return MessageSession(target=MsgInfo(targetId=0, senderId=0, senderName='', targetFrom='Telegram|Bot', - senderFrom='Telegram|Bot'), - session=Session(message=send, target=send.chat.id, sender=send.from_user.id)) - if isinstance(msgchain, (list, tuple)): + elif isinstance(msgchain, (list, tuple)): count = 0 - send_list = [] + send = [] for x in msgchain: if isinstance(x, Plain): - send = await bot.send_message(self.session.target, x.text, + send_ = await bot.send_message(self.session.target, x.text, reply_to_message_id=self.session.message.message_id if quote and count == 0 and self.session.message else None) - if isinstance(x, Image): + elif isinstance(x, Image): with open(await x.get(), 'rb') as image: - send = await bot.send_photo(self.session.target, image, + send_ = await bot.send_photo(self.session.target, image, reply_to_message_id=self.session.message.message_id if quote and count == 0 and self.session.message else None) - if isinstance(x, Voice): + elif isinstance(x, Voice): with open(x.path, 'rb') as voice: - send = await bot.send_audio(self.session.target, voice, + send_ = await bot.send_audio(self.session.target, voice, reply_to_message_id=self.session.message.message_id if quote and count == 0 and self.session.message else None) - send_list.append(send) + else: + send_ = False + if send_: + send.append(send_) count += 1 - return MessageSession(target=MsgInfo(targetId=0, senderId=0, senderName='', targetFrom='Telegram|Bot', + else: + msgchain = '发生错误:机器人尝试发送非法消息链,请联系机器人开发者解决问题。\n错误汇报地址:https://github.com/Teahouse-Studios/bot/issues/new?assignees=OasisAkari&labels=bug&template=5678.md&title=' + send = await bot.send_message(self.session.target, msgchain, + reply_to_message_id=self.session.message.message_id if quote and self.session.message else None) + return MessageSession(target=MsgInfo(targetId=0, senderId=0, senderName='', targetFrom='Telegram|Bot', senderFrom='Telegram|Bot'), - session=Session(message=send_list, target=send.chat.id, sender=send.from_user.id)) + session=Session(message=send, target=send.chat.id, sender=send.from_user.id)) async def waitConfirm(self, msgchain=None, quote=True): send = None diff --git a/core/bots/discord/message.py b/core/bots/discord/message.py index 926d9a87..1c4182f9 100644 --- a/core/bots/discord/message.py +++ b/core/bots/discord/message.py @@ -30,29 +30,35 @@ class MessageSession(MS): msgchain = '发生错误:机器人尝试发送空文本消息,请联系机器人开发者解决问题。\n错误汇报地址:https://github.com/Teahouse-Studios/bot/issues/new?assignees=OasisAkari&labels=bug&template=5678.md&title=' send = await self.session.target.send(msgchain, reference=self.session.message if quote and self.session.message else None) - return MessageSession(target=MsgInfo(targetId=0, senderId=0, senderName='', targetFrom='Discord|Bot', - senderFrom='Discord|Bot'), - session=Session(message=send, target=send.channel, sender=send.author)) - if isinstance(msgchain, (list, tuple)): + elif isinstance(msgchain, (list, tuple)): count = 0 - send_list = [] + send = [] for x in msgchain: if isinstance(x, Plain): - send = await self.session.target.send(x.text, reference=self.session.message if quote and count == 0 - and self.session.message else None) - if isinstance(x, Image): - send = await self.session.target.send(file=discord.File(await x.get()), - reference=self.session.message if quote and count == 0 - and self.session.message else None) - send_list.append(send) + send_ = await self.session.target.send(x.text, + reference=self.session.message if quote and count == 0 + and self.session.message else None) + elif isinstance(x, Image): + send_ = await self.session.target.send(file=discord.File(await x.get()), + reference=self.session.message if quote and count == 0 + and self.session.message else None) + else: + send_ = False + if send_: + send.append(send_) count += 1 - return MessageSession(target=MsgInfo(targetId=0, senderId=0, senderName='', targetFrom='Discord|Bot', - senderFrom='Discord|Bot'), - session=Session(message=send_list, target=send.channel, sender=send.author)) + else: + msgchain = '发生错误:机器人尝试发送非法消息链,请联系机器人开发者解决问题。\n错误汇报地址:https://github.com/Teahouse-Studios/bot/issues/new?assignees=OasisAkari&labels=bug&template=5678.md&title=' + send = await self.session.target.send(msgchain, + reference=self.session.message if quote and self.session.message else None) + return MessageSession(target=MsgInfo(targetId=0, senderId=0, senderName='', targetFrom='Discord|Bot', + senderFrom='Discord|Bot'), + session=Session(message=send, target=send.channel, sender=send.author)) async def waitConfirm(self, msgchain=None, quote=True): def check(m): return m.channel == self.session.message.channel and m.author == self.session.message.author + send = None if msgchain is not None: msgchain = convert2lst(msgchain)