适配频道被动消息带本地图

This commit is contained in:
Wuyi无疑 2023-03-11 18:36:31 +08:00
parent 0e3aee4315
commit 36f2ba48ee
3 changed files with 27 additions and 9 deletions

View File

@ -29,16 +29,22 @@ async def send_char_adv(ev: Event):
raw_data = ev.__dict__
group_id = sessions[-2] if len(sessions) >= 2 else None
message: List[Message] = []
msg_id = ''
# ntchat
# qqguild
if '_message' in raw_data:
messages = raw_data['_message']
group_id = str(raw_data['channel_id'])
# qqguild
if 'direct_message' in raw_data and raw_data['direct_message']:
group_id = None
user_id = str(raw_data['guild_id'])
else:
group_id = str(raw_data['channel_id'])
msg_id = raw_data['id']
# ntchat
elif not messages and 'message' in raw_data:
messages = raw_data['message']
# ntchat
elif 'data' in raw_data:
if 'data' in raw_data:
if 'chatroom' in raw_data['data']['to_wxid']:
group_id = raw_data['data']['to_wxid']
if 'image' in raw_data['data']:
@ -75,6 +81,7 @@ async def send_char_adv(ev: Event):
group_id=group_id,
user_id=user_id,
content=message,
msg_id=msg_id,
)
logger.info(f'【发送】[gsuid-core]: {msg.bot_id}')
await gsclient._input(msg)
@ -95,7 +102,8 @@ async def send_start_msg(matcher: Matcher):
@driver.on_bot_connect
async def start_client():
await start()
if gsclient is None:
await start()
await connect()

View File

@ -1,6 +1,6 @@
import base64
import asyncio
from typing import Dict, List, Union, Optional
from typing import Any, Dict, List, Union, Optional
import websockets.client
from nonebot.log import logger
@ -103,6 +103,7 @@ class GsClient:
node,
msg.target_id,
msg.target_type,
msg.msg_id,
)
except Exception as e:
logger.error(e)
@ -199,9 +200,10 @@ async def guild_send(
node: Optional[List[Dict]],
target_id: Optional[str],
target_type: Optional[str],
msg_id: Optional[str],
):
async def _send(content: Optional[str], image: Optional[str]):
result = {}
result: Dict[str, Any] = {'msg_id': msg_id}
if image:
img_bytes = base64.b64decode(image.replace('base64://', ''))
result['file_image'] = img_bytes
@ -213,6 +215,12 @@ async def guild_send(
channel_id=int(target_id) if target_id else 0,
**result,
)
else:
await bot.call_api(
'post_dms_messages',
guild_id=int(target_id) if target_id else 0,
**result,
)
if node:
for _msg in node:

View File

@ -1,4 +1,4 @@
from typing import Any, List, Optional
from typing import Any, List, Literal, Optional
from msgspec import Struct
@ -10,7 +10,8 @@ class Message(Struct):
class MessageReceive(Struct):
bot_id: str = 'Bot'
user_type: Optional[str] = None
msg_id: str = ''
user_type: Literal['group', 'direct', 'channel', 'sub_channel'] = 'group'
group_id: Optional[str] = None
user_id: Optional[str] = None
user_pm: int = 3
@ -30,6 +31,7 @@ class MessageContent(Struct):
class MessageSend(Struct):
bot_id: str = 'Bot'
msg_id: str = ''
target_type: Optional[str] = None
target_id: Optional[str] = None
content: Optional[List[Message]] = None