Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

纯文本私信已实现 #97

Closed
Starry-OvO opened this issue Feb 7, 2023 · 2 comments
Closed

纯文本私信已实现 #97

Starry-OvO opened this issue Feb 7, 2023 · 2 comments
Labels
discussion discussion

Comments

@Starry-OvO
Copy link
Owner

Starry-OvO commented Feb 7, 2023

与极速版9.1.0.0实现一致
支持多对多收发
支持设置已读状态,接收已读状态

一个auto-echo的demo如下
请使用develop分支版本

import asyncio

import aiotieba as tb


async def main():
    async with tb.Client('listener') as brow:

        async def on_receive(ws: tb.core.WsCore, data: bytes, _: int) -> None:

            notifies = push_notify.parse_body(data)
            print(notifies)
            for notify in notifies:
                ws.mid_manager.update_msg_id(notify.group_id, notify.msg_id)

            groups = await brow.get_group_msg([n.group_id for n in notifies])
            print(groups)

            for group in groups:
                if group.group_type != tb.enums.GroupType.PRIVATE_MSG:
                    continue
                if not group.messages:
                    continue
                msg = group.messages[-1]
                if msg.text != 'ping':
                    continue
                await brow.send_msg(msg.user.user_id, 'pong')

        from aiotieba.client import push_notify

        brow._ws_core.callbacks[push_notify.CMD] = on_receive
        await brow.init_websocket()

        await asyncio.sleep(600.0)


asyncio.run(main())

期望的日志输出

<2023-02-07 11:12:38.698> [INFO] [on_receive] notifies: [{'note_type': 0, 'group_type': 6, 'group_id': 2582091924, 'msg_id': 290663630549}]
<2023-02-07 11:12:39.206> [INFO] [on_receive] msg_groups: [{'group_type': 8, 'group_id': 9, 'messages': [{'text': '{"fans":1,"replyme":1,"atme":0,"zan":2,"agree":2,"feed":0,"gift":0,"ueg":[],"absmsg":{"replyme":"\\u8d34\\u5427\\u7528\\u6237_GytRRAR \\u56de\\u590d\\u4f60: \\u6211\\u4e0d\\u9ea6\\u7247~\\u8cbc\\u91cc\\u4e00\\u4e2a\\u4eba\\u6084\\u6084\\u7684","atme":"\\u4e1c\\u5934\\u4f0a\\u4f50\\u5948\\u4e0d\\u61c2\\u604b\\u7231? \\u5728\\u8fd9\\u7bc7\\u795e\\u8d34\\u4e0b@\\u4e86\\u4f60\\uff0c\\u5e26\\u4e0a\\u74dc\\u5b50\\u53bb\\u56f4\\u89c2>>","agree":"\\u65b0\\u6536\\u52301\\u4e2a\\u70b9\\u8d5e"},"godfeed":1,"is_invite":0,"new_invite_num":0}', 'user': {'user_id': 0, 'user_name': '', 'portrait': ''}}]}, {'group_type': 6, 'group_id': 2582091924, 'messages': [{'text': 'ping', 'user': {'user_id': 6050811555, 'user_name': 'v_b0t', 'portrait': 'tb.1.2fc1394a.ukuFqA26BTuAeXqYr1Nmwg'}}]}]
<2023-02-07 11:12:39.407> [INFO] [set_msg_readed] Suceeded. user_id=6050811555 msg_id=290663630549
<2023-02-07 11:12:40.272> [INFO] [send_msg] Suceeded. user_id=6050811555
<2023-02-07 11:12:41.175> [INFO] [on_receive] notifies: [{'note_type': 22, 'group_type': 6, 'group_id': 2582091924, 'msg_id': 290663632981}]
<2023-02-07 11:12:41.563> [INFO] [on_receive] msg_groups: [{'group_type': 8, 'group_id': 9, 'messages': [{'text': '{"fans":1,"replyme":1,"atme":0,"zan":2,"agree":2,"feed":0,"gift":0,"ueg":[],"absmsg":{"replyme":"\\u8d34\\u5427\\u7528\\u6237_GytRRAR \\u56de\\u590d\\u4f60: \\u6211\\u4e0d\\u9ea6\\u7247~\\u8cbc\\u91cc\\u4e00\\u4e2a\\u4eba\\u6084\\u6084\\u7684","atme":"\\u4e1c\\u5934\\u4f0a\\u4f50\\u5948\\u4e0d\\u61c2\\u604b\\u7231? \\u5728\\u8fd9\\u7bc7\\u795e\\u8d34\\u4e0b@\\u4e86\\u4f60\\uff0c\\u5e26\\u4e0a\\u74dc\\u5b50\\u53bb\\u56f4\\u89c2>>","agree":"\\u65b0\\u6536\\u52301\\u4e2a\\u70b9\\u8d5e"},"godfeed":1,"is_invite":0,"new_invite_num":0}', 'user': {'user_id': 0, 'user_name': '', 'portrait': ''}}]}, {'group_type': 6, 'group_id': 2582091924, 'messages': [{'text': '{"eventId":22001,"eventParam":{"groupId":2582091924,"readMsgId":290663632235}}', 'user': {'user_id': 6050811555, 'user_name': 'v_b0t', 'portrait': 'tb.1.2fc1394a.ukuFqA26BTuAeXqYr1Nmwg'}}]}]

客户端内效果

Screenshot_2023-02-07-11-06-21-192-edit_com baidu tieba_mini

@Starry-OvO Starry-OvO added the discussion discussion label Feb 7, 2023
@Starry-OvO
Copy link
Owner Author

@HuanCheng65

@n0099
Copy link

n0099 commented Feb 7, 2023

贴吧黑灰产广告机狂喜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion discussion
Projects
None yet
Development

No branches or pull requests

2 participants