reywechat 1.0.28__py3-none-any.whl → 1.0.30__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- reywechat/rcache.py +3 -2
- reywechat/rdb.py +4 -3
- reywechat/rlog.py +1 -1
- reywechat/rreceive.py +72 -9
- reywechat/rsend.py +0 -1
- reywechat/rwechat.py +5 -3
- {reywechat-1.0.28.dist-info → reywechat-1.0.30.dist-info}/METADATA +1 -1
- reywechat-1.0.30.dist-info/RECORD +17 -0
- reywechat-1.0.28.dist-info/RECORD +0 -17
- {reywechat-1.0.28.dist-info → reywechat-1.0.30.dist-info}/WHEEL +0 -0
- {reywechat-1.0.28.dist-info → reywechat-1.0.30.dist-info}/licenses/LICENSE +0 -0
reywechat/rcache.py
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
"""
|
10
10
|
|
11
11
|
|
12
|
-
from reykit.ros import FileCache
|
12
|
+
from reykit.ros import FileCache, join_path
|
13
13
|
|
14
14
|
from .rbase import BaseWeChat
|
15
15
|
from .rwechat import WeChat
|
@@ -40,7 +40,8 @@ class WeChatCache(BaseWeChat, FileCache):
|
|
40
40
|
|
41
41
|
# Set attribute.
|
42
42
|
self.wechat = wechat
|
43
|
-
|
43
|
+
path = join_path(self.wechat.project_dir, 'cache')
|
44
|
+
self.cache = FileCache(path)
|
44
45
|
self.folder = self.cache.folder
|
45
46
|
self.index = self.cache.index
|
46
47
|
self.store = self.cache.store
|
reywechat/rdb.py
CHANGED
@@ -13,7 +13,7 @@ from typing import Any, Literal, overload
|
|
13
13
|
from json import loads as json_loads
|
14
14
|
from reydb.rdb import Database
|
15
15
|
from reykit.rbase import throw
|
16
|
-
from reykit.ros import File
|
16
|
+
from reykit.ros import File
|
17
17
|
from reykit.rtime import to_time, time_to, sleep
|
18
18
|
from reykit.rwrap import wrap_thread
|
19
19
|
|
@@ -56,7 +56,7 @@ class WeChatDatabase(BaseWeChat):
|
|
56
56
|
self.wechat = wechat
|
57
57
|
match rdatabase:
|
58
58
|
case Database():
|
59
|
-
self.rdatabase_wechat
|
59
|
+
self.rdatabase_wechat = self.rdatabase_file = rdatabase
|
60
60
|
case dict():
|
61
61
|
self.rdatabase_wechat: Database = rdatabase.get('wechat')
|
62
62
|
self.rdatabase_file: Database = rdatabase.get('file')
|
@@ -1234,7 +1234,8 @@ class WeChatDatabase(BaseWeChat):
|
|
1234
1234
|
if 'file_name' in params:
|
1235
1235
|
file_name: str = params.pop('file_name')
|
1236
1236
|
else:
|
1237
|
-
|
1237
|
+
file = File(file_path)
|
1238
|
+
file_name = file.name_suffix
|
1238
1239
|
|
1239
1240
|
## Cache.
|
1240
1241
|
cache_path = self.wechat.cache.store(file_path, file_name)
|
reywechat/rlog.py
CHANGED
@@ -100,7 +100,7 @@ class WeChatLog(BaseWeChat):
|
|
100
100
|
self.rrlog_print.add_print(format_=format_)
|
101
101
|
|
102
102
|
## Add handler file.
|
103
|
-
file_path = self.
|
103
|
+
file_path = self.folder + 'wechat'
|
104
104
|
self.rrlog_file.add_file(
|
105
105
|
file_path,
|
106
106
|
time='m',
|
reywechat/rreceive.py
CHANGED
@@ -16,10 +16,10 @@ from queue import Queue
|
|
16
16
|
from json import loads as json_loads
|
17
17
|
from bs4 import BeautifulSoup as BSBeautifulSoup
|
18
18
|
from bs4.element import Tag as BSTag
|
19
|
-
from reykit.rbase import throw
|
19
|
+
from reykit.rbase import throw
|
20
20
|
from reykit.rimage import decode_qrcode
|
21
21
|
from reykit.rnet import listen_socket
|
22
|
-
from reykit.ros import File,
|
22
|
+
from reykit.ros import File, os_exists
|
23
23
|
from reykit.rre import search, findall
|
24
24
|
from reykit.rtask import ThreadPool
|
25
25
|
from reykit.rtime import sleep, wait
|
@@ -133,6 +133,7 @@ class WeChatMessage(BaseWeChat):
|
|
133
133
|
self._at_names: list[str] = None
|
134
134
|
self._is_at: bool | None = None
|
135
135
|
self._is_at_self: bool | None = None
|
136
|
+
self._is_call: bool | None = None
|
136
137
|
self._is_new_user: bool | None = None
|
137
138
|
self._is_new_room: bool | None = None
|
138
139
|
self._is_new_room_user: bool | None = None
|
@@ -416,6 +417,8 @@ class WeChatMessage(BaseWeChat):
|
|
416
417
|
pattern = r'@\w+\u2005'
|
417
418
|
self._at_names = findall(pattern, text)
|
418
419
|
|
420
|
+
return self._at_names
|
421
|
+
|
419
422
|
|
420
423
|
@property
|
421
424
|
def is_at(self) -> bool:
|
@@ -458,6 +461,53 @@ class WeChatMessage(BaseWeChat):
|
|
458
461
|
return self._is_at_self
|
459
462
|
|
460
463
|
|
464
|
+
@property
|
465
|
+
def is_call(self) -> bool:
|
466
|
+
"""
|
467
|
+
Whether if is message of call self.
|
468
|
+
|
469
|
+
Returns
|
470
|
+
-------
|
471
|
+
Judge result.
|
472
|
+
"""
|
473
|
+
|
474
|
+
# Cache.
|
475
|
+
if self._is_call is not None:
|
476
|
+
return self._is_call
|
477
|
+
|
478
|
+
# Judge.
|
479
|
+
is_call = False
|
480
|
+
if (
|
481
|
+
|
482
|
+
## Private chat.
|
483
|
+
self.room is None
|
484
|
+
|
485
|
+
## At self.
|
486
|
+
or self.is_at_self
|
487
|
+
|
488
|
+
## Quote self.
|
489
|
+
or self.is_quote_self
|
490
|
+
):
|
491
|
+
is_call = True
|
492
|
+
|
493
|
+
## Call name.
|
494
|
+
if self.type == 1:
|
495
|
+
text = self.data
|
496
|
+
elif self.is_quote:
|
497
|
+
text = self.quote_params['text']
|
498
|
+
else:
|
499
|
+
self._is_call = False
|
500
|
+
return self._is_call
|
501
|
+
pattern = fr'^\s*{self.receiver.call_name}[\s,,]*(.*?)\s*$'
|
502
|
+
result: str | None = search(pattern, text)
|
503
|
+
if result is not None:
|
504
|
+
is_call = True
|
505
|
+
|
506
|
+
self._is_call = is_call
|
507
|
+
|
508
|
+
return self._is_call
|
509
|
+
|
510
|
+
|
461
511
|
@property
|
462
512
|
def is_new_user(self) -> bool:
|
463
513
|
"""
|
@@ -905,7 +955,8 @@ class WechatReceiver(BaseWeChat):
|
|
905
955
|
def __init__(
|
906
956
|
self,
|
907
957
|
wechat: WeChat,
|
908
|
-
max_receiver: int
|
958
|
+
max_receiver: int,
|
959
|
+
call_name: str | None
|
909
960
|
) -> None:
|
910
961
|
"""
|
911
962
|
Build instance attributes.
|
@@ -914,6 +965,8 @@ class WechatReceiver(BaseWeChat):
|
|
914
965
|
----------
|
915
966
|
wechat : `WeChatClient` instance.
|
916
967
|
max_receiver : Maximum number of receivers.
|
968
|
+
call_name : Trigger call name.
|
969
|
+
- `None`: Use account nickname.
|
917
970
|
"""
|
918
971
|
|
919
972
|
# Import.
|
@@ -922,6 +975,9 @@ class WechatReceiver(BaseWeChat):
|
|
922
975
|
# Set attribute.
|
923
976
|
self.wechat = wechat
|
924
977
|
self.max_receiver = max_receiver
|
978
|
+
if call_name is None:
|
979
|
+
call_name = self.wechat.client.login_info['name']
|
980
|
+
self.call_name = call_name
|
925
981
|
self.queue: Queue[WeChatMessage] = Queue()
|
926
982
|
self.handlers: list[Callable[[WeChatMessage], Any]] = []
|
927
983
|
self.started: bool | None = False
|
@@ -1121,7 +1177,8 @@ class WechatReceiver(BaseWeChat):
|
|
1121
1177
|
case 3:
|
1122
1178
|
pattern = r' md5="([\da-f]{32})"'
|
1123
1179
|
file_md5: str = search(pattern, message.data)
|
1124
|
-
|
1180
|
+
file_name = f'{file_md5}.jpg'
|
1181
|
+
cache_path = self.wechat.cache.index(file_md5, file_name, copy=True)
|
1125
1182
|
|
1126
1183
|
### Download.
|
1127
1184
|
if cache_path is None:
|
@@ -1133,6 +1190,8 @@ class WechatReceiver(BaseWeChat):
|
|
1133
1190
|
|
1134
1191
|
## Voice.
|
1135
1192
|
case 34:
|
1193
|
+
file_name = None
|
1194
|
+
file_name_suffix = 'amr'
|
1136
1195
|
cache_path = None
|
1137
1196
|
|
1138
1197
|
### Download.
|
@@ -1146,7 +1205,8 @@ class WechatReceiver(BaseWeChat):
|
|
1146
1205
|
case 43:
|
1147
1206
|
pattern = r' md5="([\da-f]{32})"'
|
1148
1207
|
file_md5: str = search(pattern, message.data)
|
1149
|
-
|
1208
|
+
file_name = f'{file_md5}.mp4'
|
1209
|
+
cache_path = self.wechat.cache.index(file_md5, file_name, copy=True)
|
1150
1210
|
|
1151
1211
|
### Download.
|
1152
1212
|
if cache_path is None:
|
@@ -1197,15 +1257,18 @@ class WechatReceiver(BaseWeChat):
|
|
1197
1257
|
sleep(0.2)
|
1198
1258
|
|
1199
1259
|
## Cache.
|
1260
|
+
download_file = File(download_path)
|
1261
|
+
if file_name is None:
|
1262
|
+
file_name = f'{download_file.md5}.{file_name_suffix}'
|
1200
1263
|
cache_path = self.wechat.cache.store(download_path, file_name, delete=True)
|
1201
1264
|
|
1202
1265
|
# Set parameter.
|
1203
|
-
|
1266
|
+
cache_file = File(cache_path)
|
1204
1267
|
message_file: MessageParameterFile = {
|
1205
1268
|
'path': cache_path,
|
1206
|
-
'name':
|
1207
|
-
'md5':
|
1208
|
-
'size':
|
1269
|
+
'name': cache_file.name_suffix,
|
1270
|
+
'md5': cache_file.md5,
|
1271
|
+
'size': cache_file.size
|
1209
1272
|
}
|
1210
1273
|
message.file = message_file
|
1211
1274
|
|
reywechat/rsend.py
CHANGED
@@ -17,7 +17,6 @@ from functools import wraps as functools_wraps
|
|
17
17
|
from queue import Queue
|
18
18
|
from re import escape as re_escape
|
19
19
|
from reykit.rbase import throw, catch_exc
|
20
|
-
from reykit.ros import File
|
21
20
|
from reykit.rre import sub
|
22
21
|
from reykit.rtime import sleep
|
23
22
|
from reykit.rwrap import wrap_thread, wrap_exc
|
reywechat/rwechat.py
CHANGED
@@ -13,7 +13,6 @@ from typing import Literal
|
|
13
13
|
from os import getcwd as os_getcwd
|
14
14
|
from reydb.rdb import Database
|
15
15
|
from reykit.rbase import block
|
16
|
-
from reykit.ros import Folder, join_path
|
17
16
|
|
18
17
|
from .rbase import BaseWeChat
|
19
18
|
|
@@ -43,6 +42,7 @@ class WeChat(BaseWeChat):
|
|
43
42
|
self,
|
44
43
|
rrdatabase: Database | dict[Literal['wechat', 'file'], Database] | None,
|
45
44
|
max_receiver: int = 2,
|
45
|
+
call_name: str | None = None,
|
46
46
|
project_dir: str | None = None
|
47
47
|
) -> None:
|
48
48
|
"""
|
@@ -56,6 +56,8 @@ class WeChat(BaseWeChat):
|
|
56
56
|
`Key 'wechat'`: `WeChatDatabase` instance used in WeChat methods.
|
57
57
|
`Key 'file'`: `WeChatDatabase` instance used in file methods.
|
58
58
|
max_receiver : Maximum number of receivers.
|
59
|
+
call_name : Trigger call name.
|
60
|
+
- `None`: Use account nickname.
|
59
61
|
project_dir: Project directory, will create sub folders.
|
60
62
|
- `None`: Use working directory.
|
61
63
|
- `str`: Use this directory.
|
@@ -77,7 +79,7 @@ class WeChat(BaseWeChat):
|
|
77
79
|
self.client = WeChatClient(self)
|
78
80
|
self.cache = WeChatCache(self)
|
79
81
|
self.log = WeChatLog(self)
|
80
|
-
self.receiver = WechatReceiver(self, max_receiver)
|
82
|
+
self.receiver = WechatReceiver(self, max_receiver, call_name)
|
81
83
|
self.trigger = self.receiver.trigger
|
82
84
|
self.sender = WeChatSender(self)
|
83
85
|
self.database = WeChatDatabase(self, rrdatabase)
|
@@ -107,7 +109,7 @@ class WeChat(BaseWeChat):
|
|
107
109
|
self.wrap_try_send = self.sender.wrap_try_send
|
108
110
|
|
109
111
|
## Database.
|
110
|
-
self.send = self.database.send
|
112
|
+
self.send = self.sender.send = self.database.send
|
111
113
|
|
112
114
|
## Schedule.
|
113
115
|
self.schedule_add_task = self.schedule.add_task
|
@@ -0,0 +1,17 @@
|
|
1
|
+
reywechat/__init__.py,sha256=BL4PUpTguszJ612qsZf4-sOXxRIsiYRQ_m__FGMd1RQ,513
|
2
|
+
reywechat/rall.py,sha256=zEW-mLL2uP8aT2_foCMFGmMi_3RCrGl8qutnSVkmY1E,397
|
3
|
+
reywechat/rbase.py,sha256=0NunIUIXra2ML2N6odwMk5oENTE0r6VSBHWXUvgI-lc,1124
|
4
|
+
reywechat/rcache.py,sha256=Hh_HE-t_KUMlrz4gEFPh1AjmhnrSgH520IFJPumWb7A,908
|
5
|
+
reywechat/rclient.py,sha256=gtTYaoqhgh9kRFslETKjBJiAAdzJfeOxIJbdCkGAFhM,22577
|
6
|
+
reywechat/rdb.py,sha256=Gcj3d-uIospaacjHY8B4HHdru5OwiS9PO6cceAWvXqY,40333
|
7
|
+
reywechat/rlog.py,sha256=d3S0eHMUZ92OLE7fjP3zzikIYANtnbAxhnE_DIV_1OY,5251
|
8
|
+
reywechat/rreceive.py,sha256=VgDMNc_Lrnnm-eYinK-aCt1qXK1bEuyGYePSGrZtObk,32892
|
9
|
+
reywechat/rschedule.py,sha256=fn11rH0HqxbnJYxARCBBiSdzBpYfQFhcjNmkvihVMTc,1854
|
10
|
+
reywechat/rsend.py,sha256=s2sR6l74reDShBAu_MwpavVunz0g42pIga0zX4ElIuI,13717
|
11
|
+
reywechat/rtrigger.py,sha256=GHfkhNrS8rV4uXWC3N54UTjak7nKGfqJWX6pe57Hsgg,4953
|
12
|
+
reywechat/rwechat.py,sha256=igeG0XhfBN1BRQ9RDmYrPZIKdnIK2tmS05wb-eMdlzs,4923
|
13
|
+
reywechat/data/client_api.dll,sha256=H9uj-x9Ztg0jFZK0yY6NsnyH5_119dQRFfoVVMidxRs,592384
|
14
|
+
reywechat-1.0.30.dist-info/METADATA,sha256=ajAREqSPl0WJjajG78Ogwz7dftRrwy1-BtQykfUMqLg,1551
|
15
|
+
reywechat-1.0.30.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
16
|
+
reywechat-1.0.30.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
17
|
+
reywechat-1.0.30.dist-info/RECORD,,
|
@@ -1,17 +0,0 @@
|
|
1
|
-
reywechat/__init__.py,sha256=BL4PUpTguszJ612qsZf4-sOXxRIsiYRQ_m__FGMd1RQ,513
|
2
|
-
reywechat/rall.py,sha256=zEW-mLL2uP8aT2_foCMFGmMi_3RCrGl8qutnSVkmY1E,397
|
3
|
-
reywechat/rbase.py,sha256=0NunIUIXra2ML2N6odwMk5oENTE0r6VSBHWXUvgI-lc,1124
|
4
|
-
reywechat/rcache.py,sha256=yPGOaotZJ-Ps_6hKXm0jtQXAkdIEHLqr2nR-42syzmQ,856
|
5
|
-
reywechat/rclient.py,sha256=gtTYaoqhgh9kRFslETKjBJiAAdzJfeOxIJbdCkGAFhM,22577
|
6
|
-
reywechat/rdb.py,sha256=WOIdaDp6KENu5Pq9Nbd4uZlSh_SV8SSWcGbL-mu3WZI,40299
|
7
|
-
reywechat/rlog.py,sha256=zbdhPAL5fkJ0HKQuz9DBonJ1dxJ1N8GKROHvBmA6UaE,5262
|
8
|
-
reywechat/rreceive.py,sha256=byrT8MeIKELDRd9CLakk1WfOvxvpMeMiv2SIdcfkLAE,31158
|
9
|
-
reywechat/rschedule.py,sha256=fn11rH0HqxbnJYxARCBBiSdzBpYfQFhcjNmkvihVMTc,1854
|
10
|
-
reywechat/rsend.py,sha256=ShQLsKF6YXXD8SjixMFgqY1VGtIKt4f3odkXvP2dVDk,13746
|
11
|
-
reywechat/rtrigger.py,sha256=GHfkhNrS8rV4uXWC3N54UTjak7nKGfqJWX6pe57Hsgg,4953
|
12
|
-
reywechat/rwechat.py,sha256=tsCwtZN7YVmgrHti0qVoifjC2XcIkjBYYWDK-ZP-YfM,4811
|
13
|
-
reywechat/data/client_api.dll,sha256=H9uj-x9Ztg0jFZK0yY6NsnyH5_119dQRFfoVVMidxRs,592384
|
14
|
-
reywechat-1.0.28.dist-info/METADATA,sha256=Brbyp2S4e_9JJg1mYEeioYkTvDCaOvSYWAV_ZkQv75Y,1551
|
15
|
-
reywechat-1.0.28.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
16
|
-
reywechat-1.0.28.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
17
|
-
reywechat-1.0.28.dist-info/RECORD,,
|
File without changes
|
File without changes
|