GraiaProject / Application

一个设计精巧, 协议实现完备的, 基于 mirai-api-http 的即时聊天软件自动化框架.
https://graia-document.vercel.app/
GNU Affero General Public License v3.0
438 stars 63 forks source link

FriendMessage无法获取MessageChain #3

Closed oyyq99999 closed 4 years ago

oyyq99999 commented 4 years ago
from graia.broadcast import Broadcast
from graia.application import GraiaMiraiApplication, Session
import asyncio

from graia.application.protocol.entities.message.elements.internal import Plain

from graia.application.protocol.entities.message.chain import MessageChain
from graia.application.protocol.entities.targets.friend import Friend

......

@bcc.receiver("FriendMessage")
async def friend_message_listener(
    # message: MessageChain,
    friend: Friend,
    app: GraiaMiraiApplication,
):
    print('received message')

......

如上代码在收到信息时可以正常打出消息,但把message取消注释之后便不会进入到这个函数。类似代码处理GroupMessage时就没有这样的问题。

oyyq99999 commented 4 years ago

Graia Application、Broadcaster、mirai-console、mirai-api-http、MiraiOK均是当前最新版本

oyyq99999 commented 4 years ago

研究半天发现私聊和群聊从api收到的数据的messageChain部分几乎一样 私聊:{'type': 'FriendMessage', 'messageChain': [{'type': 'Source', 'id': 14031, 'time': 1596045191}, {'type': 'Plain', 'text': '来'}], 'sender': {'id': XXXXXX, 'nickname': 'XXXXX', 'remark': ''}} 群聊:{'type': 'GroupMessage', 'messageChain': [{'type': 'Source', 'id': 444, 'time': 1596045180}, {'type': 'Plain', 'text': '来'}], 'sender': {'id': XXXXXX, 'memberName': 'XXXXX', 'permission': 'OWNER', 'group': {'id': XXXXX, 'name': 'XXXX', 'permission': 'ADMINISTRATOR'}}} parse之后FriendMessage的messageChain项是None,但GroupMessage的messageChain项是正确的值 实在不知道怎么回事了。。

GreyElaina commented 4 years ago

是我脑瘫了...

class FriendMessage(MiraiEvent):
    type: str = "FriendMessage"
    messageChain: MessageChain
    sender: Friend

    @validator("messageChain")
    def _(cls, v):
        return