reywechat 1.0.29__py3-none-any.whl → 1.0.31__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/rreceive.py +113 -4
- reywechat/rwechat.py +4 -1
- {reywechat-1.0.29.dist-info → reywechat-1.0.31.dist-info}/METADATA +1 -1
- {reywechat-1.0.29.dist-info → reywechat-1.0.31.dist-info}/RECORD +6 -6
- {reywechat-1.0.29.dist-info → reywechat-1.0.31.dist-info}/WHEEL +0 -0
- {reywechat-1.0.29.dist-info → reywechat-1.0.31.dist-info}/licenses/LICENSE +0 -0
reywechat/rreceive.py
CHANGED
@@ -133,6 +133,8 @@ 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
|
137
|
+
self._call_text: str | None = None
|
136
138
|
self._is_new_user: bool | None = None
|
137
139
|
self._is_new_room: bool | None = None
|
138
140
|
self._is_new_room_user: bool | None = None
|
@@ -413,7 +415,7 @@ class WeChatMessage(BaseWeChat):
|
|
413
415
|
text = self.data
|
414
416
|
elif self.is_quote:
|
415
417
|
text = self.quote_params['text']
|
416
|
-
pattern = r'
|
418
|
+
pattern = r'@(\w+)\u2005'
|
417
419
|
self._at_names = findall(pattern, text)
|
418
420
|
|
419
421
|
return self._at_names
|
@@ -454,12 +456,102 @@ class WeChatMessage(BaseWeChat):
|
|
454
456
|
return self._is_at_self
|
455
457
|
|
456
458
|
# Judge.
|
457
|
-
|
458
|
-
self._is_at_self = pattern in self.at_names
|
459
|
+
self._is_at_self = self.receiver.wechat.client.login_info['name'] in self.at_names
|
459
460
|
|
460
461
|
return self._is_at_self
|
461
462
|
|
462
463
|
|
464
|
+
@property
|
465
|
+
def is_call(self) -> bool:
|
466
|
+
"""
|
467
|
+
Whether if is message of call self name.
|
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
|
+
# Text.
|
479
|
+
if self.type == 1:
|
480
|
+
text = self.data
|
481
|
+
elif self.is_quote:
|
482
|
+
text = self.quote_params['text']
|
483
|
+
else:
|
484
|
+
self._is_call = False
|
485
|
+
self._call_text = None
|
486
|
+
return self._is_call
|
487
|
+
text = text.strip()
|
488
|
+
|
489
|
+
## At self.
|
490
|
+
at_self_keyword = '@%s\u2005' % self.receiver.wechat.client.login_info['name']
|
491
|
+
if at_self_keyword in text:
|
492
|
+
is_at_self = True
|
493
|
+
text = text.replace(at_self_keyword, '')
|
494
|
+
else:
|
495
|
+
is_at_self = False
|
496
|
+
|
497
|
+
## Call self.
|
498
|
+
pattern = fr'^{self.receiver.call_name}[\s,,]*(.*)$'
|
499
|
+
result: str | None = search(pattern, text)
|
500
|
+
if result is not None:
|
501
|
+
is_call_name = True
|
502
|
+
text = result
|
503
|
+
else:
|
504
|
+
is_call_name = False
|
505
|
+
|
506
|
+
# Judge.
|
507
|
+
if (
|
508
|
+
|
509
|
+
## Private chat.
|
510
|
+
self.room is None
|
511
|
+
|
512
|
+
## At self.
|
513
|
+
or is_at_self
|
514
|
+
|
515
|
+
## Call self.
|
516
|
+
or is_call_name
|
517
|
+
|
518
|
+
## Quote self.
|
519
|
+
or self.is_quote_self
|
520
|
+
|
521
|
+
):
|
522
|
+
is_call = True
|
523
|
+
call_text = text
|
524
|
+
else:
|
525
|
+
is_call = False
|
526
|
+
call_text = None
|
527
|
+
|
528
|
+
self._is_call = is_call
|
529
|
+
self._call_text = call_text
|
530
|
+
|
531
|
+
return self._is_call
|
532
|
+
|
533
|
+
|
534
|
+
@property
|
535
|
+
def call_text(self) -> str:
|
536
|
+
"""
|
537
|
+
Message call text of call self name.
|
538
|
+
|
539
|
+
Returns
|
540
|
+
-------
|
541
|
+
Call text.
|
542
|
+
"""
|
543
|
+
|
544
|
+
# Cache.
|
545
|
+
if self._call_text is not None:
|
546
|
+
return self._call_text
|
547
|
+
|
548
|
+
# Check.
|
549
|
+
if not self.is_call:
|
550
|
+
throw(AssertionError, self.is_call)
|
551
|
+
|
552
|
+
return self._call_text
|
553
|
+
|
554
|
+
|
463
555
|
@property
|
464
556
|
def is_new_user(self) -> bool:
|
465
557
|
"""
|
@@ -797,6 +889,17 @@ class WeChatMessage(BaseWeChat):
|
|
797
889
|
return self._valid
|
798
890
|
|
799
891
|
|
892
|
+
@property
|
893
|
+
def check_call(self) -> None:
|
894
|
+
"""
|
895
|
+
Check if is call self name, if not, throw exception `WeChatTriggerContinueExit`.
|
896
|
+
"""
|
897
|
+
|
898
|
+
# Check.
|
899
|
+
if not self.is_call:
|
900
|
+
self.trigger_continue()
|
901
|
+
|
902
|
+
|
800
903
|
@overload
|
801
904
|
def reply(
|
802
905
|
self,
|
@@ -907,7 +1010,8 @@ class WechatReceiver(BaseWeChat):
|
|
907
1010
|
def __init__(
|
908
1011
|
self,
|
909
1012
|
wechat: WeChat,
|
910
|
-
max_receiver: int
|
1013
|
+
max_receiver: int,
|
1014
|
+
call_name: str | None
|
911
1015
|
) -> None:
|
912
1016
|
"""
|
913
1017
|
Build instance attributes.
|
@@ -916,6 +1020,8 @@ class WechatReceiver(BaseWeChat):
|
|
916
1020
|
----------
|
917
1021
|
wechat : `WeChatClient` instance.
|
918
1022
|
max_receiver : Maximum number of receivers.
|
1023
|
+
call_name : Trigger call name.
|
1024
|
+
- `None`: Use account nickname.
|
919
1025
|
"""
|
920
1026
|
|
921
1027
|
# Import.
|
@@ -924,6 +1030,9 @@ class WechatReceiver(BaseWeChat):
|
|
924
1030
|
# Set attribute.
|
925
1031
|
self.wechat = wechat
|
926
1032
|
self.max_receiver = max_receiver
|
1033
|
+
if call_name is None:
|
1034
|
+
call_name = self.wechat.client.login_info['name']
|
1035
|
+
self.call_name = call_name
|
927
1036
|
self.queue: Queue[WeChatMessage] = Queue()
|
928
1037
|
self.handlers: list[Callable[[WeChatMessage], Any]] = []
|
929
1038
|
self.started: bool | None = False
|
reywechat/rwechat.py
CHANGED
@@ -42,6 +42,7 @@ class WeChat(BaseWeChat):
|
|
42
42
|
self,
|
43
43
|
rrdatabase: Database | dict[Literal['wechat', 'file'], Database] | None,
|
44
44
|
max_receiver: int = 2,
|
45
|
+
call_name: str | None = None,
|
45
46
|
project_dir: str | None = None
|
46
47
|
) -> None:
|
47
48
|
"""
|
@@ -55,6 +56,8 @@ class WeChat(BaseWeChat):
|
|
55
56
|
`Key 'wechat'`: `WeChatDatabase` instance used in WeChat methods.
|
56
57
|
`Key 'file'`: `WeChatDatabase` instance used in file methods.
|
57
58
|
max_receiver : Maximum number of receivers.
|
59
|
+
call_name : Trigger call name.
|
60
|
+
- `None`: Use account nickname.
|
58
61
|
project_dir: Project directory, will create sub folders.
|
59
62
|
- `None`: Use working directory.
|
60
63
|
- `str`: Use this directory.
|
@@ -76,7 +79,7 @@ class WeChat(BaseWeChat):
|
|
76
79
|
self.client = WeChatClient(self)
|
77
80
|
self.cache = WeChatCache(self)
|
78
81
|
self.log = WeChatLog(self)
|
79
|
-
self.receiver = WechatReceiver(self, max_receiver)
|
82
|
+
self.receiver = WechatReceiver(self, max_receiver, call_name)
|
80
83
|
self.trigger = self.receiver.trigger
|
81
84
|
self.sender = WeChatSender(self)
|
82
85
|
self.database = WeChatDatabase(self, rrdatabase)
|
@@ -5,13 +5,13 @@ reywechat/rcache.py,sha256=Hh_HE-t_KUMlrz4gEFPh1AjmhnrSgH520IFJPumWb7A,908
|
|
5
5
|
reywechat/rclient.py,sha256=gtTYaoqhgh9kRFslETKjBJiAAdzJfeOxIJbdCkGAFhM,22577
|
6
6
|
reywechat/rdb.py,sha256=Gcj3d-uIospaacjHY8B4HHdru5OwiS9PO6cceAWvXqY,40333
|
7
7
|
reywechat/rlog.py,sha256=d3S0eHMUZ92OLE7fjP3zzikIYANtnbAxhnE_DIV_1OY,5251
|
8
|
-
reywechat/rreceive.py,sha256=
|
8
|
+
reywechat/rreceive.py,sha256=0S7GZkLuUdLeccSQJT0-ASBqo_IFmNNQfwk_Qn-SC1E,34178
|
9
9
|
reywechat/rschedule.py,sha256=fn11rH0HqxbnJYxARCBBiSdzBpYfQFhcjNmkvihVMTc,1854
|
10
10
|
reywechat/rsend.py,sha256=s2sR6l74reDShBAu_MwpavVunz0g42pIga0zX4ElIuI,13717
|
11
11
|
reywechat/rtrigger.py,sha256=GHfkhNrS8rV4uXWC3N54UTjak7nKGfqJWX6pe57Hsgg,4953
|
12
|
-
reywechat/rwechat.py,sha256=
|
12
|
+
reywechat/rwechat.py,sha256=igeG0XhfBN1BRQ9RDmYrPZIKdnIK2tmS05wb-eMdlzs,4923
|
13
13
|
reywechat/data/client_api.dll,sha256=H9uj-x9Ztg0jFZK0yY6NsnyH5_119dQRFfoVVMidxRs,592384
|
14
|
-
reywechat-1.0.
|
15
|
-
reywechat-1.0.
|
16
|
-
reywechat-1.0.
|
17
|
-
reywechat-1.0.
|
14
|
+
reywechat-1.0.31.dist-info/METADATA,sha256=hx4R2CIjrn41MVLGtuLYKwrdiFZw97UQnzRxYfsc9Es,1551
|
15
|
+
reywechat-1.0.31.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
16
|
+
reywechat-1.0.31.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
17
|
+
reywechat-1.0.31.dist-info/RECORD,,
|
File without changes
|
File without changes
|