diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index 29cc95c3..1fc9a56a 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -10,7 +10,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v1 with: - python-version: 3.8 + python-version: 3.9 - name: Install dependencies run: | python -m pip install --upgrade pip @@ -36,7 +36,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v1 with: - python-version: 3.8 + python-version: 3.9 - name: Install dependencies run: | python -m pip install --upgrade pip @@ -57,7 +57,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v1 with: - python-version: 3.8 + python-version: 3.9 - name: Install dependencies run: | python -m pip install --upgrade pip @@ -75,7 +75,7 @@ jobs: - uses: actions/setup-node@v3 with: node-version: 16 - - name: Building Wechaty-ui + - name: Building Wechaty-ui id: build-ui run: | make ui diff --git a/Makefile b/Makefile index 8d50093f..3e623d58 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ SOURCE_GLOB=$(wildcard bin/*.py src/**/*.py tests/**/*.py examples/*.py) # Huan(202003) # F811: https://github.com/PyCQA/pyflakes/issues/320#issuecomment-469337000 # -IGNORE_PEP=E203,E221,E241,E272,E501,F811,W293 +IGNORE_PEP=E203,E221,E241,E272,E501,F811,W293,F824 # help scripts to find the right place of wechaty module export PYTHONPATH=src/ @@ -32,7 +32,7 @@ lint: pylint pycodestyle flake8 mypy pylint: pylint \ --load-plugins pylint_quotes \ - --disable=W0511,R0801,cyclic-import,C4001 \ + --disable=W0511,R0801,cyclic-import,C4001,R1735 \ $(SOURCE_GLOB) .PHONY: pycodestyle @@ -109,7 +109,7 @@ check-python-version: .PHONY: format format: - yapf $(SOURCE_GLOB) + yapf $(SOURCE_GLOB) code: code . diff --git a/requirements-dev.txt b/requirements-dev.txt index d78af9ee..6458c879 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,7 +4,7 @@ flake8 mypy mypy_extensions pycodestyle -pylint +pylint==2.17.7 pylint-quotes pytest @@ -13,7 +13,7 @@ pytest-asyncio==0.18.3 pytest-cov pytype semver==3.0.0.dev3 -pyee +pyee==11.0.0 requests qrcode apscheduler @@ -24,4 +24,5 @@ mkdocs-material types-requests mkdocstrings mkdocstrings-python-legacy -yapf \ No newline at end of file +yapf +urllib3==1.26 diff --git a/src/wechaty/user/room.py b/src/wechaty/user/room.py index 85ea075a..ae885415 100644 --- a/src/wechaty/user/room.py +++ b/src/wechaty/user/room.py @@ -167,9 +167,10 @@ def filter_func(room: Room) -> bool: payload = room.payload if not payload: return False - if query == payload.id or (query.lower() in payload.topic.lower()): # type: ignore + if query == payload.id or (query.lower() in payload.topic.lower()): # type: ignore return True return False + func = filter_func elif isinstance(query, RoomQueryFilter): def filter_func(room: Room) -> bool: @@ -179,9 +180,10 @@ def filter_func(room: Room) -> bool: if not payload: return False - if query.id == payload.id or (query.topic.lower() in payload.topic.lower()): # noqa + if query.id == payload.id or (query.topic.lower() in payload.topic.lower()): # noqa return True return False + func = filter_func elif isinstance(query, types.FunctionType): func = query @@ -230,7 +232,7 @@ async def find_all(cls, rooms: List[Room] = [cls.load(room_id) for room_id in room_ids] tasks: List[Task] = [asyncio.create_task(room.ready()) for room in rooms] await gather_with_concurrency(PARALLEL_TASK_NUM, tasks) - + # 2. filter the rooms if not query: return rooms @@ -290,6 +292,20 @@ def load(cls, room_id: str) -> Room: cls._pool[room_id] = room return room + @classmethod + def upload_cache(cls, room_id: str) -> Room: + """ + dynamic upload + clear the room_id from _pool and re-upload it using load + Args: + room_id: The Roo ID to refresh + Return: + Room:The refreshed room instance + """ + if room_id in cls._pool: + del cls._pool[room_id] + return cls.load(room_id) + def __str__(self) -> str: """ string format for room instance @@ -349,7 +365,7 @@ async def ready(self, force_sync: bool = False, load_members: bool = False) -> N async def say(self, some_thing: Union[str, Contact, - FileBox, MiniProgram, UrlLink], + FileBox, MiniProgram, UrlLink], mention_ids: Optional[List[str]] = None ) -> Union[None, Message]: """ diff --git a/src/wechaty/wechaty.py b/src/wechaty/wechaty.py index 1591943d..d365eb57 100644 --- a/src/wechaty/wechaty.py +++ b/src/wechaty/wechaty.py @@ -99,7 +99,6 @@ from wechaty.utils import timestamp_to_date, qr_terminal - log: logging.Logger = get_logger('Wechaty') DEFAULT_TIMEOUT = 300 @@ -472,7 +471,7 @@ async def start(self) -> None: loop = asyncio.get_event_loop() loop.stop() - except Exception as e: # pylint: disable=broad-except + except Exception as e: # pylint: disable=broad-except print(e) async def restart(self) -> None: @@ -713,6 +712,7 @@ async def room_leave_listener(payload: EventRoomLeavePayload) -> None: async def room_topic_listener(payload: EventRoomTopicPayload) -> None: log.info('receive event <%s>', payload) + self.Room.upload_cache(payload.room_id) # type: ignore[attr-defined] room: Room = self.Room.load(payload.room_id) await room.ready()