mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-12 22:00:57 +00:00
修复bot自己给别人发消息时没有PushContent字段导致判断错误,并修复bot自己发消息自己回复问题
This commit is contained in:
@@ -171,6 +171,7 @@ class PlatformManager:
|
|||||||
|
|
||||||
tasks.append(exception_wrapper(adapter))
|
tasks.append(exception_wrapper(adapter))
|
||||||
|
|
||||||
|
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
self.ap.task_mgr.create_task(
|
self.ap.task_mgr.create_task(
|
||||||
task,
|
task,
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class GewechatMessageConverter(adapter.MessageConverter):
|
|||||||
if message["Data"]["MsgType"] == 1:
|
if message["Data"]["MsgType"] == 1:
|
||||||
# 检查消息开头,如果有 wxid_sbitaz0mt65n22:\n 则删掉
|
# 检查消息开头,如果有 wxid_sbitaz0mt65n22:\n 则删掉
|
||||||
regex = re.compile(r"^wxid_.*:")
|
regex = re.compile(r"^wxid_.*:")
|
||||||
# print(message)
|
print(message)
|
||||||
|
|
||||||
line_split = message["Data"]["Content"]["string"].split("\n")
|
line_split = message["Data"]["Content"]["string"].split("\n")
|
||||||
|
|
||||||
@@ -78,15 +78,20 @@ class GewechatMessageConverter(adapter.MessageConverter):
|
|||||||
pattern = r'@\S+'
|
pattern = r'@\S+'
|
||||||
at_string = f"@{bot_account_id}"
|
at_string = f"@{bot_account_id}"
|
||||||
content_list = []
|
content_list = []
|
||||||
|
if message['Wxid'] == message['Data']['FromUserName']['string']:
|
||||||
|
return platform_message.MessageChain()
|
||||||
if at_string in message["Data"]["Content"]["string"]:
|
if at_string in message["Data"]["Content"]["string"]:
|
||||||
content_list.append(platform_message.At(target=bot_account_id))
|
content_list.append(platform_message.At(target=bot_account_id))
|
||||||
content_list.append(platform_message.Plain(message["Data"]["Content"]["string"].replace(at_string, '', 1)))
|
content_list.append(platform_message.Plain(message["Data"]["Content"]["string"].replace(at_string, '', 1)))
|
||||||
# 更优雅的替换改名后@机器人,仅仅限于单独AT的情况
|
# 更优雅的替换改名后@机器人,仅仅限于单独AT的情况
|
||||||
elif '在群聊中@了你' in message["Data"]["PushContent"]:
|
elif "PushContent" in message['Data'] and '在群聊中@了你' in message["Data"]["PushContent"]:
|
||||||
content_list.append(platform_message.At(target=bot_account_id))
|
content_list.append(platform_message.At(target=bot_account_id))
|
||||||
content_list.append(platform_message.Plain(re.sub(pattern, '', message["Data"]["Content"]["string"])))
|
content_list.append(platform_message.Plain(re.sub(pattern, '', message["Data"]["Content"]["string"])))
|
||||||
else:
|
else:
|
||||||
content_list = [platform_message.Plain(message["Data"]["Content"]["string"])]
|
if message['Wxid'] == message['Data']['FromUserName']['string']:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
content_list = [platform_message.Plain(message["Data"]["Content"]["string"])]
|
||||||
|
|
||||||
return platform_message.MessageChain(content_list)
|
return platform_message.MessageChain(content_list)
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ import asyncio
|
|||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def get_gewechat_image_base64(
|
async def get_gewechat_image_base64(
|
||||||
gewechat_url: str,
|
gewechat_url: str,
|
||||||
gewechat_file_url: str,
|
gewechat_file_url: str,
|
||||||
@@ -67,6 +70,7 @@ async def get_gewechat_image_base64(
|
|||||||
}
|
}
|
||||||
) as response:
|
) as response:
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
|
print(response)
|
||||||
raise Exception(f"获取gewechat图片下载失败: {await response.text()}")
|
raise Exception(f"获取gewechat图片下载失败: {await response.text()}")
|
||||||
|
|
||||||
resp_data = await response.json()
|
resp_data = await response.json()
|
||||||
@@ -108,6 +112,9 @@ async def get_gewechat_image_base64(
|
|||||||
raise Exception(f"获取图片失败: {str(e)}") from e
|
raise Exception(f"获取图片失败: {str(e)}") from e
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def get_wecom_image_base64(pic_url: str) -> tuple[str, str]:
|
async def get_wecom_image_base64(pic_url: str) -> tuple[str, str]:
|
||||||
"""
|
"""
|
||||||
下载企业微信图片并转换为 base64
|
下载企业微信图片并转换为 base64
|
||||||
|
|||||||
Reference in New Issue
Block a user