From 675c667eef2f0b5c820424b54bb3c490b0ff20fd Mon Sep 17 00:00:00 2001 From: Lsm <1914049892@qq.com> Date: Mon, 2 Jun 2025 18:33:40 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BE=A4=E4=BF=AE?= =?UTF-8?q?=E6=94=B9topic=E5=90=8E=EF=BC=8C=E6=9C=AC=E5=9C=B0=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E6=9C=AA=E6=9B=B4=E6=96=B0=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/wechaty/user/room.py | 19 +++++++++++++++---- src/wechaty/wechaty.py | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/wechaty/user/room.py b/src/wechaty/user/room.py index 85ea075a..e0f9d25b 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,15 @@ def load(cls, room_id: str) -> Room: cls._pool[room_id] = room return room + @classmethod + def upload_cache(cls, room_id: str)->None: + """ + dynamic upload + clear the room_id of _pool and upload it use load + """ + cls._pool[room_id] = None + cls.load(room_id) + def __str__(self) -> str: """ string format for room instance @@ -349,7 +360,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..6ae09d54 100644 --- a/src/wechaty/wechaty.py +++ b/src/wechaty/wechaty.py @@ -713,7 +713,7 @@ async def room_leave_listener(payload: EventRoomLeavePayload) -> None: async def room_topic_listener(payload: EventRoomTopicPayload) -> None: log.info('receive event <%s>', payload) - room: Room = self.Room.load(payload.room_id) + room: Room = self.Room.upload_cache(payload.room_id) await room.ready() changer = self.Contact.load(payload.changer_id) From 7cba0c8af225215883588851d5963d3e8f6e2a48 Mon Sep 17 00:00:00 2001 From: Lsm <1914049892@qq.com> Date: Thu, 5 Jun 2025 11:53:51 +0800 Subject: [PATCH 2/6] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9workflows=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=85=8D=E7=BD=AE=E3=80=82python=E7=89=88=E6=9C=AC3.8?= =?UTF-8?q?->3.9=20fix:=E4=BC=98=E5=8C=96wechaty.room.py=E4=B8=AD=20upload?= =?UTF-8?q?=5Fcache=20=E9=80=BB=E8=BE=91=E3=80=82=E6=9B=B4=E8=A7=84?= =?UTF-8?q?=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pypi.yml | 8 ++++---- src/wechaty/user/room.py | 13 +++++++++---- src/wechaty/wechaty.py | 6 +++--- 3 files changed, 16 insertions(+), 11 deletions(-) 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/src/wechaty/user/room.py b/src/wechaty/user/room.py index e0f9d25b..ae885415 100644 --- a/src/wechaty/user/room.py +++ b/src/wechaty/user/room.py @@ -293,13 +293,18 @@ def load(cls, room_id: str) -> Room: return room @classmethod - def upload_cache(cls, room_id: str)->None: + def upload_cache(cls, room_id: str) -> Room: """ dynamic upload - clear the room_id of _pool and upload it use load + 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 """ - cls._pool[room_id] = None - cls.load(room_id) + if room_id in cls._pool: + del cls._pool[room_id] + return cls.load(room_id) def __str__(self) -> str: """ diff --git a/src/wechaty/wechaty.py b/src/wechaty/wechaty.py index 6ae09d54..0f9943a8 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,7 +712,8 @@ async def room_leave_listener(payload: EventRoomLeavePayload) -> None: async def room_topic_listener(payload: EventRoomTopicPayload) -> None: log.info('receive event <%s>', payload) - room: Room = self.Room.upload_cache(payload.room_id) + self.Room.upload_cache(payload.room_id) + room: Room = self.Room.load(payload.room_id) await room.ready() changer = self.Contact.load(payload.changer_id) From 43ea5ef63934e3924e1acd51f5f54b216777a549 Mon Sep 17 00:00:00 2001 From: liuming <1914049892@qq.com> Date: Thu, 19 Jun 2025 15:53:24 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9pylint<3,=E6=96=B0?= =?UTF-8?q?=E7=89=88pylint=E4=B8=8D=E5=85=BC=E5=AE=B9IAstroidChecker?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E3=80=82ci=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements-dev.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index d78af9ee..c2a074b5 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 @@ -24,4 +24,4 @@ mkdocs-material types-requests mkdocstrings mkdocstrings-python-legacy -yapf \ No newline at end of file +yapf From f537071260ce1ed6b96dc92044831828e66793ec Mon Sep 17 00:00:00 2001 From: liuming <1914049892@qq.com> Date: Thu, 19 Jun 2025 16:46:02 +0800 Subject: [PATCH 4/6] =?UTF-8?q?fix::=E4=BF=AE=E5=A4=8D=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9pyee<12.0.0,=E6=96=B0=E7=89=88pyee=E5=BC=95=E7=94=A8As?= =?UTF-8?q?yncIOEventEmitter=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index c2a074b5..cbca7910 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -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 From bc79fd3635d19943fd6b3e9286ee44a1169d33c0 Mon Sep 17 00:00:00 2001 From: liuming <1914049892@qq.com> Date: Thu, 19 Jun 2025 17:16:37 +0800 Subject: [PATCH 5/6] =?UTF-8?q?fix::=E4=BF=AE=E5=A4=8D=20makefile=20=20fla?= =?UTF-8?q?ke8=20=E5=BF=BD=E7=95=A5F824=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8d50093f..0abcf314 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/ @@ -109,7 +109,7 @@ check-python-version: .PHONY: format format: - yapf $(SOURCE_GLOB) + yapf $(SOURCE_GLOB) code: code . From 0f777cfb900abe4027a08e6ffd5864b0a3d7659a Mon Sep 17 00:00:00 2001 From: liuming <1914049892@qq.com> Date: Thu, 19 Jun 2025 18:10:19 +0800 Subject: [PATCH 6/6] =?UTF-8?q?fix::=E4=BF=AE=E5=A4=8D=20CI=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5:=201.=20makefile=20=E5=BF=BD=E7=95=A5R1735=E9=94=99?= =?UTF-8?q?=E8=AF=AF=EF=BC=88=E5=AD=97=E9=9D=A2=E9=87=8F=EF=BC=89=EF=BC=8C?= =?UTF-8?q?=E5=8E=9F=E6=A1=86=E6=9E=B6=E4=B8=AD=E5=86=99=E6=B3=95=E4=B8=BA?= =?UTF-8?q?return(dict{}),=E5=B7=B2=E7=BB=8F=E5=BB=BA=E8=AE=AE=E4=B8=BAret?= =?UTF-8?q?urn({}),=E5=BF=BD=E7=95=A5=E8=BF=99=E7=B1=BB=E9=94=99=E8=AF=AF?= =?UTF-8?q?=202.=20=E6=9B=B4=E6=96=B0urllib3=E7=89=88=E6=9C=AC=E4=B8=BA1.2?= =?UTF-8?q?6,=E5=A4=A7=E4=BA=8E2=20=E7=9A=84=E7=89=88=E6=9C=ACget=5Fhost?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E8=A2=AB=E7=A7=BB=E9=99=A4=203.=20wechaty.py?= =?UTF-8?q?=E4=B8=AD=E6=96=B0=E5=8A=A0=E7=9A=84=E6=96=B9=E6=B3=95=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=B1=BB=E5=9E=8B=E5=BF=BD=E7=95=A5=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=EF=BC=8Cci=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- requirements-dev.txt | 1 + src/wechaty/wechaty.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0abcf314..3e623d58 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/requirements-dev.txt b/requirements-dev.txt index cbca7910..6458c879 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -25,3 +25,4 @@ types-requests mkdocstrings mkdocstrings-python-legacy yapf +urllib3==1.26 diff --git a/src/wechaty/wechaty.py b/src/wechaty/wechaty.py index 0f9943a8..d365eb57 100644 --- a/src/wechaty/wechaty.py +++ b/src/wechaty/wechaty.py @@ -712,7 +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) + self.Room.upload_cache(payload.room_id) # type: ignore[attr-defined] room: Room = self.Room.load(payload.room_id) await room.ready()