python-wechaty
python-wechaty copied to clipboard
đđ Bug Report: title-of-your-problem
Describe your problem
When I use the example code on GitHub to update the room name, room.topic() does not update automatically, only when the program restarts.
Reproduce your problem
import asyncio
import logging
from typing import List, Optional, Union
from grpclib.const import Status
import wechaty
from wechaty_puppet import FileBox ,RoomPayload # type: ignore
from wechaty_puppet.schemas.event import EventReadyPayload # type: ignore
import datetime
from wechaty import Wechaty, Contact
from wechaty.user import Message, Room
import jenkins
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)
class MyBot(Wechaty):
"""
listen wechaty event with inherited functions, which is more friendly for
oop developer
"""
def __init__(self):
"""initialization function
"""
super().__init__()
self.status = 0
async def on_message(self, msg: Message):
from_contact = msg.talker()
text = msg.text()
room = msg.room()
if text.startswith('set room topic:'):
log.info('set room topic')
if room:
new_topic = text[len('set room topic:') + 1:]
topic: Optional[str] = await room.topic(new_topic=new_topic)
if topic:
await msg.say(topic)
if text.startswith('get room topic'):
log.info('get room topic')
rooms: List[Room] = await self.Room.find_all()
for room in rooms:
log.info('load room<%s>', room)
if room:
topic: Optional[str] = await room.topic()
await msg.say(topic)
async def on_login(self, room: Room):
print('user: %s has login', room)
async def on_room_topic(self, room: Room, new_topic: str, old_topic: str,
changer: Contact, date: datetime):
room.__init__()
async def on_ready(self, payload: EventReadyPayload):
log.info('ready event <%s>', payload)
friends: List[Contact] = await self.Contact.find_all()
for friend in friends:
log.info('load friend<%s>', friend)
rooms: List[Room] = await self.Room.find_all()
for room in rooms:
log.info('load room<%s>', room)
bot: Optional[MyBot] = None
async def main():
global bot
bot = MyBot()
await bot.start()
asyncio.run(main())
Error info
- log info
2021-06-10 19:19:57,160 - Wechaty - INFO - receive message <Message#message_type_text[đŖ Contact <@@58fdb3dd6485ebd30de0b5fe0943630b952d9c10b221dfc694a7106715fc4ef6> <456>@đĨ Room <@@58fdb3dd6485ebd30de0b5fe0943630b952d9c10b221dfc694a7106715fc4ef6 - 678>] äŊ äŋŽæšįž¤åä¸ēâ999â>
2021-06-10 19:20:05,422 - Wechaty - INFO - receive message <Message#message_type_text[đŖ Contact <@23b6238a0f9d3c8faed93710fce6b39b9c6b8b23317bce80368116c017e9f12b>
@đĨ Room <@@58fdb3dd6485ebd30de0b5fe0943630b952d9c10b221dfc694a7106715fc4ef6 - 678>] 678> - screen shot image

Additional context
Add any other context about the problem here.