wechaty / python-wechaty

Python Wechaty is a Conversational RPA SDK for Chatbot Makers written in Python
https://wechaty.readthedocs.io/zh_CN/latest/
Apache License 2.0
1.63k stars 234 forks source link

Bug for 'room-join' event #129

Closed YangTe1 closed 3 years ago

YangTe1 commented 4 years ago

Describe the bug When i add a listener for 'room-join' bot.on('room-join', on_room_join) It shows

2020-08-19 13:48:58,761 - Wechaty - INFO - receive <room-join> event <%s>
2020-08-19 13:48:58,851 - Contact - INFO - load contact <Contact <xxx> <xxx>>
2020-08-19 13:48:58,883 - Contact - INFO - load contact <Contact <xxx> <xxx>>
2020-08-19 13:48:58,912 - Contact - INFO - load contact <Contact <xxx> <xxx>>
2020-08-19 13:48:59,749 - Wechaty - ERROR - internal error <year 52602 is out of range>

And I found the source code is: (wechaty/wechaty.py line 593)

            elif event_name == 'room-join':
                async def room_join_listener(payload: EventRoomJoinPayload):
                    log.info('receive <room-join> event <%s>')
                    room = self.Room.load(payload.room_id)
                    await room.ready()

                    invitees = [self.Contact.load(invitee_id)
                                for invitee_id in payload.invited_ids]
                    for invitee in invitees:
                        await invitee.ready()

                    inviter = self.Contact.load(payload.inviter_id)
                    await inviter.ready()

                    date = datetime.fromtimestamp(payload.time_stamp)        -> it caused error
                    self.emit('room-join', room, invitees, inviter, date)
                    await self.on_room_join(room, invitees, inviter, date)

                    room.emit('join', invitees, inviter, date)

                    # emit the room-join event to plugins
                    await self._plugin_manager.emit_events(
                        'room-join', room,
                        invitees, inviter, date
                    )

                puppet.on('room-join', room_join_listener)

payload.time_stamp -> 1597809084043. It's a milliseconds timestamp. datetime.fromtimestamp() -> This function should pass a seconds time stamp instead of milliseconds.

wj-Mcat commented 4 years ago

It run correctly at my room-join event. Can you reproduce it again ?

And more, what version of your python-wechaty, python-wechaty-puppet, python-wechaty-puppet-hostie. Thanks for your issue.

YangTe1 commented 4 years ago

Emm.. It caused ERROR again. wechaty 0.6.10 wechaty-puppet 0.0.16 wechaty-puppet-hostie 0.2.12

wj-Mcat commented 4 years ago

Please keep eyes on this issue, we will mention you if a new version is deployed. 👾. 👾

YangTe1 commented 4 years ago

Ok, thanks

why2lyj commented 4 years ago

@YangTe1 try as below , pay attention to room_join parameter payload: EventRoomJoinPayload:

async def main():
    global bot
    bot = Wechaty()
    bot.on('room-join', room_join)
    bot.start()

from wechaty_puppet import EventRoomJoinPayload
async def room_join(payload: EventRoomJoinPayload, room: Room, invitees: list, inviter: Contact, date: datetime):
    pass

I'm not test for the newest version, but it works on

wechaty                            0.6.8
wechaty-puppet                     0.0.16
wechaty-puppet-hostie              0.2.12
YangTe1 commented 4 years ago

@why2lyj 不行的,还是同样的报错 所以如果这些py库版本都相同,却返回不同的结果会不会是因为某些环境的不同,服务端这个时间戳返回的格式不一样? 我那个hostie用的也是wechaty/wechaty的最新镜像

FYI,我测试时手机端微信用的是安卓机登录,不知道和这个是否有关? @wj-Mcat

wj-Mcat commented 4 years ago

For my suggestion, you can edit your python-wechaty source package files by hand and keep eyes on this pr .

why2lyj commented 4 years ago

:thinking: Interesting, I'm not meeting this issue ...

why2lyj commented 4 years ago

@YangTe1 are you still facing this issue? Let me know, pls.

wj-Mcat commented 4 years ago

@YangTe1 please keep eyes on this #137 pr. When it has been merged, you can update your wechaty version to check for your problem. Hope it will resolve your problem. Thanks a lot.

wj-Mcat commented 4 years ago

@YangTe1 A new version has been released, you can have a try to check for your problem.