Skip to content

Commit a69851c

Browse files
authored
修改群修改topic后,本地缓存未更新的bug (#438)
* 修改群修改topic后,本地缓存未更新的bug * fix:修改workflows文件配置。python版本3.8->3.9 fix:优化wechaty.room.py中 upload_cache 逻辑。更规范 * 修改pylint<3,新版pylint不兼容IAstroidChecker接口。ci报错 * fix::修复 修改pyee<12.0.0,新版pyee引用AsyncIOEventEmitter报错 * fix::修复 makefile flake8 忽略F824错误 * fix::修复 CI失败: 1. makefile 忽略R1735错误(字面量),原框架中写法为return(dict{}),已经建议为return({}),忽略这类错误 2. 更新urllib3版本为1.26,大于2 的版本get_host方法被移除 3. wechaty.py中新加的方法增加类型忽略注释,ci失败
1 parent e9a04a9 commit a69851c

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

.github/workflows/pypi.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- uses: actions/checkout@v2
1111
- uses: actions/setup-python@v1
1212
with:
13-
python-version: 3.8
13+
python-version: 3.9
1414
- name: Install dependencies
1515
run: |
1616
python -m pip install --upgrade pip
@@ -36,7 +36,7 @@ jobs:
3636
- uses: actions/checkout@v2
3737
- uses: actions/setup-python@v1
3838
with:
39-
python-version: 3.8
39+
python-version: 3.9
4040
- name: Install dependencies
4141
run: |
4242
python -m pip install --upgrade pip
@@ -57,7 +57,7 @@ jobs:
5757
- name: Set up Python
5858
uses: actions/setup-python@v1
5959
with:
60-
python-version: 3.8
60+
python-version: 3.9
6161
- name: Install dependencies
6262
run: |
6363
python -m pip install --upgrade pip
@@ -75,7 +75,7 @@ jobs:
7575
- uses: actions/setup-node@v3
7676
with:
7777
node-version: 16
78-
- name: Building Wechaty-ui
78+
- name: Building Wechaty-ui
7979
id: build-ui
8080
run: |
8181
make ui

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ SOURCE_GLOB=$(wildcard bin/*.py src/**/*.py tests/**/*.py examples/*.py)
1111
# Huan(202003)
1212
# F811: https://github.com/PyCQA/pyflakes/issues/320#issuecomment-469337000
1313
#
14-
IGNORE_PEP=E203,E221,E241,E272,E501,F811,W293
14+
IGNORE_PEP=E203,E221,E241,E272,E501,F811,W293,F824
1515

1616
# help scripts to find the right place of wechaty module
1717
export PYTHONPATH=src/

requirements-dev.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ flake8
44
mypy
55
mypy_extensions
66
pycodestyle
7-
pylint
7+
pylint==2.17.7
88
pylint-quotes
99
pytest
1010

@@ -13,7 +13,7 @@ pytest-asyncio==0.18.3
1313
pytest-cov
1414
pytype
1515
semver==3.0.0.dev3
16-
pyee
16+
pyee==11.0.0
1717
requests
1818
qrcode
1919
apscheduler
@@ -24,4 +24,5 @@ mkdocs-material
2424
types-requests
2525
mkdocstrings
2626
mkdocstrings-python-legacy
27-
yapf
27+
yapf
28+
urllib3==1.26

src/wechaty/user/room.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@ def filter_func(room: Room) -> bool:
167167
payload = room.payload
168168
if not payload:
169169
return False
170-
if query == payload.id or (query.lower() in payload.topic.lower()): # type: ignore
170+
if query == payload.id or (query.lower() in payload.topic.lower()): # type: ignore
171171
return True
172172
return False
173+
173174
func = filter_func
174175
elif isinstance(query, RoomQueryFilter):
175176
def filter_func(room: Room) -> bool:
@@ -179,9 +180,10 @@ def filter_func(room: Room) -> bool:
179180
if not payload:
180181
return False
181182

182-
if query.id == payload.id or (query.topic.lower() in payload.topic.lower()): # noqa
183+
if query.id == payload.id or (query.topic.lower() in payload.topic.lower()): # noqa
183184
return True
184185
return False
186+
185187
func = filter_func
186188
elif isinstance(query, types.FunctionType):
187189
func = query
@@ -230,7 +232,7 @@ async def find_all(cls,
230232
rooms: List[Room] = [cls.load(room_id) for room_id in room_ids]
231233
tasks: List[Task] = [asyncio.create_task(room.ready()) for room in rooms]
232234
await gather_with_concurrency(PARALLEL_TASK_NUM, tasks)
233-
235+
234236
# 2. filter the rooms
235237
if not query:
236238
return rooms
@@ -290,6 +292,20 @@ def load(cls, room_id: str) -> Room:
290292
cls._pool[room_id] = room
291293
return room
292294

295+
@classmethod
296+
def upload_cache(cls, room_id: str) -> Room:
297+
"""
298+
dynamic upload
299+
clear the room_id from _pool and re-upload it using load
300+
Args:
301+
room_id: The Roo ID to refresh
302+
Return:
303+
Room:The refreshed room instance
304+
"""
305+
if room_id in cls._pool:
306+
del cls._pool[room_id]
307+
return cls.load(room_id)
308+
293309
def __str__(self) -> str:
294310
"""
295311
string format for room instance
@@ -349,7 +365,7 @@ async def ready(self, force_sync: bool = False, load_members: bool = False) -> N
349365

350366
async def say(self,
351367
some_thing: Union[str, Contact,
352-
FileBox, MiniProgram, UrlLink],
368+
FileBox, MiniProgram, UrlLink],
353369
mention_ids: Optional[List[str]] = None
354370
) -> Union[None, Message]:
355371
"""

src/wechaty/wechaty.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@
9999

100100
from wechaty.utils import timestamp_to_date, qr_terminal
101101

102-
103102
log: logging.Logger = get_logger('Wechaty')
104103

105104
DEFAULT_TIMEOUT = 300
@@ -472,7 +471,7 @@ async def start(self) -> None:
472471
loop = asyncio.get_event_loop()
473472
loop.stop()
474473

475-
except Exception as e: # pylint: disable=broad-except
474+
except Exception as e: # pylint: disable=broad-except
476475
print(e)
477476

478477
async def restart(self) -> None:
@@ -713,6 +712,7 @@ async def room_leave_listener(payload: EventRoomLeavePayload) -> None:
713712
async def room_topic_listener(payload: EventRoomTopicPayload) -> None:
714713
log.info('receive <room-topic> event <%s>', payload)
715714

715+
self.Room.upload_cache(payload.room_id) # type: ignore[attr-defined]
716716
room: Room = self.Room.load(payload.room_id)
717717
await room.ready()
718718

0 commit comments

Comments
 (0)