reywechat 1.0.46__py3-none-any.whl → 1.0.48__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/__init__.py +1 -1
- reywechat/rbase.py +4 -4
- reywechat/rcache.py +2 -2
- reywechat/rclient.py +3 -3
- reywechat/rdb.py +150 -14
- reywechat/rlog.py +8 -8
- reywechat/rreceive.py +28 -9
- reywechat/rschedule.py +2 -2
- reywechat/rsend.py +28 -18
- reywechat/rtrigger.py +5 -5
- reywechat/rwechat.py +3 -3
- {reywechat-1.0.46.dist-info → reywechat-1.0.48.dist-info}/METADATA +1 -1
- reywechat-1.0.48.dist-info/RECORD +17 -0
- reywechat-1.0.46.dist-info/RECORD +0 -17
- {reywechat-1.0.46.dist-info → reywechat-1.0.48.dist-info}/WHEEL +0 -0
- {reywechat-1.0.46.dist-info → reywechat-1.0.48.dist-info}/licenses/LICENSE +0 -0
reywechat/__init__.py
CHANGED
reywechat/rbase.py
CHANGED
@@ -13,7 +13,7 @@ from reykit.rbase import Base, Error, Exit
|
|
13
13
|
|
14
14
|
|
15
15
|
__all__ = (
|
16
|
-
'
|
16
|
+
'WeChatBase',
|
17
17
|
'WeChatError',
|
18
18
|
'WeChatClientErorr',
|
19
19
|
'WeChatTriggerError',
|
@@ -22,19 +22,19 @@ __all__ = (
|
|
22
22
|
)
|
23
23
|
|
24
24
|
|
25
|
-
class
|
25
|
+
class WeChatBase(Base):
|
26
26
|
"""
|
27
27
|
WeChat Base type.
|
28
28
|
"""
|
29
29
|
|
30
30
|
|
31
|
-
class WeChatError(
|
31
|
+
class WeChatError(WeChatBase, Error):
|
32
32
|
"""
|
33
33
|
WeChat error type.
|
34
34
|
"""
|
35
35
|
|
36
36
|
|
37
|
-
class WeChatExit(
|
37
|
+
class WeChatExit(WeChatBase, Exit):
|
38
38
|
"""
|
39
39
|
WeChat exit type.
|
40
40
|
"""
|
reywechat/rcache.py
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
from reykit.ros import FileCache, join_path
|
13
13
|
|
14
|
-
from .rbase import
|
14
|
+
from .rbase import WeChatBase
|
15
15
|
from .rwechat import WeChat
|
16
16
|
|
17
17
|
|
@@ -20,7 +20,7 @@ __all__ = (
|
|
20
20
|
)
|
21
21
|
|
22
22
|
|
23
|
-
class WeChatCache(
|
23
|
+
class WeChatCache(WeChatBase, FileCache):
|
24
24
|
"""
|
25
25
|
WeChat file cache type.
|
26
26
|
"""
|
reywechat/rclient.py
CHANGED
@@ -17,7 +17,7 @@ from reykit.ros import find_relpath
|
|
17
17
|
from reykit.rsys import run_cmd, search_process, memory_read, memory_write, popup_select
|
18
18
|
from reykit.rtime import wait
|
19
19
|
|
20
|
-
from .rbase import
|
20
|
+
from .rbase import WeChatBase, WeChatClientErorr
|
21
21
|
from .rwechat import WeChat
|
22
22
|
|
23
23
|
|
@@ -42,7 +42,7 @@ CLIENT_VERSION_MEMORY_OFFSETS = (
|
|
42
42
|
)
|
43
43
|
|
44
44
|
|
45
|
-
class WeChatClient(
|
45
|
+
class WeChatClient(WeChatBase):
|
46
46
|
"""
|
47
47
|
WeChat client type.
|
48
48
|
"""
|
@@ -348,7 +348,7 @@ class WeChatClient(BaseWeChat):
|
|
348
348
|
- `Key 'head_image'`: Head image URL.
|
349
349
|
- `Key 'account_data_path'`: Current account data save path.
|
350
350
|
- `Key 'wechat_data_path'`: WeChat data save path.
|
351
|
-
- `Key 'decrypt_key'`:
|
351
|
+
- `Key 'decrypt_key'`: Database decrypt key.
|
352
352
|
"""
|
353
353
|
|
354
354
|
# Handle parameter.
|
reywechat/rdb.py
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
@Time : 2023-10-23 20:55:58
|
6
6
|
@Author : Rey
|
7
7
|
@Contact : reyxbo@163.com
|
8
|
-
@Explain :
|
8
|
+
@Explain : Database methods.
|
9
9
|
"""
|
10
10
|
|
11
11
|
|
12
|
-
from typing import
|
12
|
+
from typing import Literal
|
13
13
|
from json import loads as json_loads
|
14
14
|
from reydb.rdb import Database
|
15
15
|
from reykit.rbase import throw
|
@@ -17,7 +17,7 @@ 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
|
|
20
|
-
from .rbase import
|
20
|
+
from .rbase import WeChatBase
|
21
21
|
from .rreceive import WeChatMessage
|
22
22
|
from .rsend import WeChatSendTypeEnum, WeChatSendParameter
|
23
23
|
from .rwechat import WeChat
|
@@ -28,7 +28,7 @@ __all__ = (
|
|
28
28
|
)
|
29
29
|
|
30
30
|
|
31
|
-
class WeChatDatabase(
|
31
|
+
class WeChatDatabase(WeChatBase):
|
32
32
|
"""
|
33
33
|
WeChat database type.
|
34
34
|
Can create database used `self.build` method.
|
@@ -96,14 +96,14 @@ class WeChatDatabase(BaseWeChat):
|
|
96
96
|
self.__start_from_message_send()
|
97
97
|
|
98
98
|
|
99
|
-
def
|
99
|
+
def build_db(self) -> None:
|
100
100
|
"""
|
101
101
|
Check and build all standard databases and tables, by `self.db_names`.
|
102
102
|
"""
|
103
103
|
|
104
104
|
# Set parameter.
|
105
105
|
|
106
|
-
##
|
106
|
+
## Database.
|
107
107
|
databases = [
|
108
108
|
{
|
109
109
|
'name': self.db_names['wechat']
|
@@ -444,7 +444,7 @@ class WeChatDatabase(BaseWeChat):
|
|
444
444
|
'path': (self.db_names['wechat'], self.db_names['wechat.stats']),
|
445
445
|
'items': [
|
446
446
|
{
|
447
|
-
'name': '
|
447
|
+
'name': 'receive_count',
|
448
448
|
'select': (
|
449
449
|
'SELECT COUNT(1)\n'
|
450
450
|
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.message_receive']}`'
|
@@ -452,7 +452,7 @@ class WeChatDatabase(BaseWeChat):
|
|
452
452
|
'comment': 'Message receive count.'
|
453
453
|
},
|
454
454
|
{
|
455
|
-
'name': '
|
455
|
+
'name': 'send_count',
|
456
456
|
'select': (
|
457
457
|
'SELECT COUNT(1)\n'
|
458
458
|
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.message_send']}`\n'
|
@@ -461,7 +461,7 @@ class WeChatDatabase(BaseWeChat):
|
|
461
461
|
'comment': 'Message send count.'
|
462
462
|
},
|
463
463
|
{
|
464
|
-
'name': '
|
464
|
+
'name': 'user_count',
|
465
465
|
'select': (
|
466
466
|
'SELECT COUNT(1)\n'
|
467
467
|
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.contact_user']}`'
|
@@ -469,7 +469,7 @@ class WeChatDatabase(BaseWeChat):
|
|
469
469
|
'comment': 'Contact user count.'
|
470
470
|
},
|
471
471
|
{
|
472
|
-
'name': '
|
472
|
+
'name': 'room_count',
|
473
473
|
'select': (
|
474
474
|
'SELECT COUNT(1)\n'
|
475
475
|
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.contact_room']}`'
|
@@ -477,7 +477,7 @@ class WeChatDatabase(BaseWeChat):
|
|
477
477
|
'comment': 'Contact room count.'
|
478
478
|
},
|
479
479
|
{
|
480
|
-
'name': '
|
480
|
+
'name': 'room_user_count',
|
481
481
|
'select': (
|
482
482
|
'SELECT COUNT(1)\n'
|
483
483
|
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.contact_room_user']}`'
|
@@ -485,7 +485,142 @@ class WeChatDatabase(BaseWeChat):
|
|
485
485
|
'comment': 'Contact room user count.'
|
486
486
|
},
|
487
487
|
{
|
488
|
-
'name': '
|
488
|
+
'name': 'past_day_receive_count',
|
489
|
+
'select': (
|
490
|
+
'SELECT COUNT(1)\n'
|
491
|
+
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.message_receive']}`'
|
492
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) = 0'
|
493
|
+
),
|
494
|
+
'comment': 'Message receive count in the past day.'
|
495
|
+
},
|
496
|
+
{
|
497
|
+
'name': 'past_day_send_count',
|
498
|
+
'select': (
|
499
|
+
'SELECT COUNT(1)\n'
|
500
|
+
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.message_send']}`'
|
501
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) = 0'
|
502
|
+
),
|
503
|
+
'comment': 'Message send count in the past day.'
|
504
|
+
},
|
505
|
+
{
|
506
|
+
'name': 'past_day_user_count',
|
507
|
+
'select': (
|
508
|
+
'SELECT COUNT(1)\n'
|
509
|
+
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.contact_user']}`'
|
510
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) = 0'
|
511
|
+
),
|
512
|
+
'comment': 'Contact user count in the past day.'
|
513
|
+
},
|
514
|
+
{
|
515
|
+
'name': 'past_day_room_count',
|
516
|
+
'select': (
|
517
|
+
'SELECT COUNT(1)\n'
|
518
|
+
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.contact_room']}`'
|
519
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) = 0'
|
520
|
+
),
|
521
|
+
'comment': 'Contact room count in the past day.'
|
522
|
+
},
|
523
|
+
{
|
524
|
+
'name': 'past_day_room_user_count',
|
525
|
+
'select': (
|
526
|
+
'SELECT COUNT(1)\n'
|
527
|
+
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.contact_room_user']}`'
|
528
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) = 0'
|
529
|
+
),
|
530
|
+
'comment': 'Contact room user count in the past day.'
|
531
|
+
},
|
532
|
+
{
|
533
|
+
'name': 'past_week_receive_count',
|
534
|
+
'select': (
|
535
|
+
'SELECT COUNT(1)\n'
|
536
|
+
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.message_receive']}`'
|
537
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 6'
|
538
|
+
),
|
539
|
+
'comment': 'Message receive count in the past week.'
|
540
|
+
},
|
541
|
+
{
|
542
|
+
'name': 'past_week_send_count',
|
543
|
+
'select': (
|
544
|
+
'SELECT COUNT(1)\n'
|
545
|
+
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.message_send']}`'
|
546
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 6'
|
547
|
+
),
|
548
|
+
'comment': 'Message send count in the past week.'
|
549
|
+
},
|
550
|
+
{
|
551
|
+
'name': 'past_week_user_count',
|
552
|
+
'select': (
|
553
|
+
'SELECT COUNT(1)\n'
|
554
|
+
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.contact_user']}`'
|
555
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 6'
|
556
|
+
),
|
557
|
+
'comment': 'Contact user count in the past week.'
|
558
|
+
},
|
559
|
+
{
|
560
|
+
'name': 'past_week_room_count',
|
561
|
+
'select': (
|
562
|
+
'SELECT COUNT(1)\n'
|
563
|
+
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.contact_room']}`'
|
564
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 6'
|
565
|
+
),
|
566
|
+
'comment': 'Contact room count in the past week.'
|
567
|
+
},
|
568
|
+
{
|
569
|
+
'name': 'past_week_room_user_count',
|
570
|
+
'select': (
|
571
|
+
'SELECT COUNT(1)\n'
|
572
|
+
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.contact_room_user']}`'
|
573
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 6'
|
574
|
+
),
|
575
|
+
'comment': 'Contact room user count in the past week.'
|
576
|
+
},
|
577
|
+
{
|
578
|
+
'name': 'past_month_receive_count',
|
579
|
+
'select': (
|
580
|
+
'SELECT COUNT(1)\n'
|
581
|
+
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.message_receive']}`'
|
582
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 29'
|
583
|
+
),
|
584
|
+
'comment': 'Message receive count in the past month.'
|
585
|
+
},
|
586
|
+
{
|
587
|
+
'name': 'past_month_send_count',
|
588
|
+
'select': (
|
589
|
+
'SELECT COUNT(1)\n'
|
590
|
+
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.message_send']}`'
|
591
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 29'
|
592
|
+
),
|
593
|
+
'comment': 'Message send count in the past month.'
|
594
|
+
},
|
595
|
+
{
|
596
|
+
'name': 'past_month_user_count',
|
597
|
+
'select': (
|
598
|
+
'SELECT COUNT(1)\n'
|
599
|
+
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.contact_user']}`'
|
600
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 29'
|
601
|
+
),
|
602
|
+
'comment': 'Contact user count in the past month.'
|
603
|
+
},
|
604
|
+
{
|
605
|
+
'name': 'past_month_room_count',
|
606
|
+
'select': (
|
607
|
+
'SELECT COUNT(1)\n'
|
608
|
+
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.contact_room']}`'
|
609
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 29'
|
610
|
+
),
|
611
|
+
'comment': 'Contact room count in the past month.'
|
612
|
+
},
|
613
|
+
{
|
614
|
+
'name': 'past_month_room_user_count',
|
615
|
+
'select': (
|
616
|
+
'SELECT COUNT(1)\n'
|
617
|
+
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.contact_room_user']}`'
|
618
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 29'
|
619
|
+
),
|
620
|
+
'comment': 'Contact room user count in the past month.'
|
621
|
+
},
|
622
|
+
{
|
623
|
+
'name': 'receive_last_time',
|
489
624
|
'select': (
|
490
625
|
'SELECT MAX(`message_time`)\n'
|
491
626
|
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.message_receive']}`'
|
@@ -493,7 +628,7 @@ class WeChatDatabase(BaseWeChat):
|
|
493
628
|
'comment': 'Message last receive time.'
|
494
629
|
},
|
495
630
|
{
|
496
|
-
'name': '
|
631
|
+
'name': 'send_last_time',
|
497
632
|
'select': (
|
498
633
|
'SELECT MAX(`status_time`)\n'
|
499
634
|
f'FROM `{self.db_names['wechat']}`.`{self.db_names['wechat.message_send']}`\n'
|
@@ -502,6 +637,7 @@ class WeChatDatabase(BaseWeChat):
|
|
502
637
|
'comment': 'Message last send time.'
|
503
638
|
}
|
504
639
|
]
|
640
|
+
|
505
641
|
}
|
506
642
|
|
507
643
|
]
|
@@ -512,7 +648,7 @@ class WeChatDatabase(BaseWeChat):
|
|
512
648
|
self.database_wechat.build.build(databases, tables, views_stats=views_stats)
|
513
649
|
|
514
650
|
## File.
|
515
|
-
self.database_file.file.
|
651
|
+
self.database_file.file.build_db()
|
516
652
|
|
517
653
|
# Update.
|
518
654
|
self.update_contact_user()
|
reywechat/rlog.py
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
from reykit.rlog import Log
|
13
13
|
from reykit.ros import Folder, join_path
|
14
14
|
|
15
|
-
from .rbase import
|
15
|
+
from .rbase import WeChatBase
|
16
16
|
from .rreceive import WeChatMessage
|
17
17
|
from .rsend import WeChatSendParameter
|
18
18
|
from .rwechat import WeChat
|
@@ -23,7 +23,7 @@ __all__ = (
|
|
23
23
|
)
|
24
24
|
|
25
25
|
|
26
|
-
class WeChatLog(
|
26
|
+
class WeChatLog(WeChatBase):
|
27
27
|
"""
|
28
28
|
WeChat log type.
|
29
29
|
"""
|
@@ -163,9 +163,9 @@ class WeChatLog(BaseWeChat):
|
|
163
163
|
level = self.rrlog.INFO
|
164
164
|
else:
|
165
165
|
level = self.rrlog.ERROR
|
166
|
-
|
167
|
-
content_print = '%s\n%s' % (content_print,
|
168
|
-
content_file = '%s\n%s' % (content_file,
|
166
|
+
exc_text = '\n'.join(message.exc_reports)
|
167
|
+
content_print = '%s\n%s' % (content_print, exc_text)
|
168
|
+
content_file = '%s\n%s' % (content_file, exc_text)
|
169
169
|
|
170
170
|
## Add color.
|
171
171
|
if self.rrlog.print_colour:
|
@@ -205,9 +205,9 @@ class WeChatLog(BaseWeChat):
|
|
205
205
|
level = self.rrlog.INFO
|
206
206
|
else:
|
207
207
|
level = self.rrlog.ERROR
|
208
|
-
|
209
|
-
content_print = '%s\n%s' % (content_print,
|
210
|
-
content_file = '%s\n%s' % (content_file,
|
208
|
+
exc_text = '\n'.join(send_param.exc_reports)
|
209
|
+
content_print = '%s\n%s' % (content_print, exc_text)
|
210
|
+
content_file = '%s\n%s' % (content_file, exc_text)
|
211
211
|
|
212
212
|
## Add color.
|
213
213
|
if self.rrlog.print_colour:
|
reywechat/rreceive.py
CHANGED
@@ -23,10 +23,10 @@ from reykit.rnet import listen_socket
|
|
23
23
|
from reykit.ros import File, os_exists
|
24
24
|
from reykit.rre import search, search_batch, findall
|
25
25
|
from reykit.rtask import ThreadPool
|
26
|
-
from reykit.rtime import sleep, wait
|
26
|
+
from reykit.rtime import now, sleep, wait, to_time, time_to
|
27
27
|
from reykit.rwrap import wrap_thread, wrap_exc
|
28
28
|
|
29
|
-
from .rbase import
|
29
|
+
from .rbase import WeChatBase, WeChatTriggerError
|
30
30
|
from .rsend import WeChatSendTypeEnum
|
31
31
|
from .rwechat import WeChat
|
32
32
|
|
@@ -62,7 +62,7 @@ MessageParameter = TypedDict(
|
|
62
62
|
)
|
63
63
|
|
64
64
|
|
65
|
-
class WeChatMessage(
|
65
|
+
class WeChatMessage(WeChatBase):
|
66
66
|
"""
|
67
67
|
WeChat message type.
|
68
68
|
"""
|
@@ -94,6 +94,10 @@ class WeChatMessage(BaseWeChat):
|
|
94
94
|
display : Message description text.
|
95
95
|
data : Message source data.
|
96
96
|
window : Message sende window ID.
|
97
|
+
|
98
|
+
Attributes
|
99
|
+
----------
|
100
|
+
is_test : Whether add test text to before reply text.
|
97
101
|
"""
|
98
102
|
|
99
103
|
# Import.
|
@@ -114,6 +118,7 @@ class WeChatMessage(BaseWeChat):
|
|
114
118
|
self.trigger_break = self.receiver.trigger.break_
|
115
119
|
self.replied: bool = False
|
116
120
|
self.exc_reports: list[str] = []
|
121
|
+
self.is_test: bool = False
|
117
122
|
|
118
123
|
## Room and user.
|
119
124
|
if self.window.endswith('chatroom'):
|
@@ -127,7 +132,6 @@ class WeChatMessage(BaseWeChat):
|
|
127
132
|
self.user = self.window
|
128
133
|
|
129
134
|
## Cache.
|
130
|
-
self._window: str | None = None
|
131
135
|
self._user_name: str | None = None
|
132
136
|
self._room_name: str | None = None
|
133
137
|
self._window_name: str | None = None
|
@@ -1060,10 +1064,25 @@ class WeChatMessage(BaseWeChat):
|
|
1060
1064
|
text = 'can only be used by reply trigger'
|
1061
1065
|
throw(WeChatTriggerError, self.trigger_rule, text=text)
|
1062
1066
|
|
1067
|
+
# Test.
|
1068
|
+
if (
|
1069
|
+
self.is_test
|
1070
|
+
and send_type in (WeChatSendTypeEnum.TEXT, WeChatSendTypeEnum.TEXT_AT)
|
1071
|
+
):
|
1072
|
+
message_time = time_to(to_time(self.time).time())
|
1073
|
+
receive_time = now('time_str')
|
1074
|
+
send_time = ':time:'
|
1075
|
+
test_text = f'{message_time} M\n{receive_time} R\n{send_time} S'
|
1076
|
+
if params['text'] == '':
|
1077
|
+
params['text'] = test_text
|
1078
|
+
else:
|
1079
|
+
params['text'] = f'{test_text}\n\n{params['text']}'
|
1080
|
+
params['is_test'] = True
|
1081
|
+
|
1063
1082
|
# Status.
|
1064
1083
|
self.replied = True
|
1065
1084
|
|
1066
|
-
#
|
1085
|
+
# Send.
|
1067
1086
|
self.receiver.wechat.sender.send(
|
1068
1087
|
send_type,
|
1069
1088
|
receive_id=self.window,
|
@@ -1071,7 +1090,7 @@ class WeChatMessage(BaseWeChat):
|
|
1071
1090
|
)
|
1072
1091
|
|
1073
1092
|
|
1074
|
-
class WechatReceiver(
|
1093
|
+
class WechatReceiver(WeChatBase):
|
1075
1094
|
"""
|
1076
1095
|
WeChat receiver type.
|
1077
1096
|
"""
|
@@ -1201,17 +1220,17 @@ class WechatReceiver(BaseWeChat):
|
|
1201
1220
|
# Handle.
|
1202
1221
|
|
1203
1222
|
## Define.
|
1204
|
-
def handle_handler_exception(
|
1223
|
+
def handle_handler_exception(exc_text, *_) -> None:
|
1205
1224
|
"""
|
1206
1225
|
Handle Handler exception.
|
1207
1226
|
|
1208
1227
|
Parameters
|
1209
1228
|
----------
|
1210
|
-
|
1229
|
+
exc_text : Exception report text.
|
1211
1230
|
"""
|
1212
1231
|
|
1213
1232
|
# Save.
|
1214
|
-
message.exc_reports.append(
|
1233
|
+
message.exc_reports.append(exc_text)
|
1215
1234
|
|
1216
1235
|
|
1217
1236
|
## Loop.
|
reywechat/rschedule.py
CHANGED
@@ -14,12 +14,12 @@ from typing import Any, Literal
|
|
14
14
|
from collections.abc import Callable
|
15
15
|
from reykit.rschedule import Schedule
|
16
16
|
|
17
|
-
from .rbase import
|
17
|
+
from .rbase import WeChatBase
|
18
18
|
from .rsend import WeChatSendTypeEnum
|
19
19
|
from .rwechat import WeChat
|
20
20
|
|
21
21
|
|
22
|
-
class WeChatSchedule(
|
22
|
+
class WeChatSchedule(WeChatBase):
|
23
23
|
"""
|
24
24
|
WeChat schedule type.
|
25
25
|
"""
|
reywechat/rsend.py
CHANGED
@@ -18,10 +18,10 @@ from queue import Queue
|
|
18
18
|
from re import escape as re_escape
|
19
19
|
from reykit.rbase import throw, catch_exc
|
20
20
|
from reykit.rre import sub
|
21
|
-
from reykit.rtime import sleep
|
21
|
+
from reykit.rtime import now, sleep
|
22
22
|
from reykit.rwrap import wrap_thread, wrap_exc
|
23
23
|
|
24
|
-
from .rbase import
|
24
|
+
from .rbase import WeChatBase, WeChatTriggerContinueExit, WeChatTriggerBreakExit
|
25
25
|
from .rwechat import WeChat
|
26
26
|
|
27
27
|
|
@@ -32,7 +32,7 @@ __all__ = (
|
|
32
32
|
)
|
33
33
|
|
34
34
|
|
35
|
-
class WeChatSendTypeEnum(
|
35
|
+
class WeChatSendTypeEnum(WeChatBase, IntEnum):
|
36
36
|
"""
|
37
37
|
WeChat send type enumeration type.
|
38
38
|
|
@@ -58,13 +58,13 @@ class WeChatSendTypeEnum(BaseWeChat, IntEnum):
|
|
58
58
|
FORWARD = 7
|
59
59
|
|
60
60
|
|
61
|
-
class WeChatSendStatusEnum(
|
61
|
+
class WeChatSendStatusEnum(WeChatBase, IntEnum):
|
62
62
|
"""
|
63
63
|
WeChat send status enumeration type.
|
64
64
|
|
65
65
|
Attributes
|
66
66
|
----------
|
67
|
-
INIT : After initialization, before inserting into database queue.
|
67
|
+
INIT : After initialization, before inserting into the database queue.
|
68
68
|
WAIT : After get from database queue, before sending.
|
69
69
|
SENT : After sending.
|
70
70
|
"""
|
@@ -74,7 +74,7 @@ class WeChatSendStatusEnum(BaseWeChat, IntEnum):
|
|
74
74
|
SENT = 2
|
75
75
|
|
76
76
|
|
77
|
-
class WeChatSendParameter(
|
77
|
+
class WeChatSendParameter(WeChatBase):
|
78
78
|
"""
|
79
79
|
WeChat send parameters type.
|
80
80
|
"""
|
@@ -181,7 +181,7 @@ class WeChatSendParameter(BaseWeChat):
|
|
181
181
|
- `Literal[WeChatSendTypeEnum.FORWARD]`: Forward message, use `WeChatClient.send_forward`: method.
|
182
182
|
receive_id : User ID or chat room ID of receive message.
|
183
183
|
send_id : Send ID of database.
|
184
|
-
- `None`: Not inserted into database.
|
184
|
+
- `None`: Not inserted into the database.
|
185
185
|
params : Send parameters.
|
186
186
|
"""
|
187
187
|
|
@@ -195,7 +195,7 @@ class WeChatSendParameter(BaseWeChat):
|
|
195
195
|
self.status: WeChatSendStatusEnum
|
196
196
|
|
197
197
|
|
198
|
-
class WeChatSender(
|
198
|
+
class WeChatSender(WeChatBase):
|
199
199
|
"""
|
200
200
|
WeChat sender type.
|
201
201
|
|
@@ -247,7 +247,7 @@ class WeChatSender(BaseWeChat):
|
|
247
247
|
break
|
248
248
|
|
249
249
|
send_param = self.queue.get()
|
250
|
-
handle_handler_exception = lambda
|
250
|
+
handle_handler_exception = lambda exc_text, *_: send_param.exc_reports.append(exc_text)
|
251
251
|
|
252
252
|
## Handler.
|
253
253
|
for handler in self.handlers:
|
@@ -259,13 +259,13 @@ class WeChatSender(BaseWeChat):
|
|
259
259
|
self.__send(send_param)
|
260
260
|
|
261
261
|
## Exception.
|
262
|
-
except:
|
262
|
+
except BaseException:
|
263
263
|
|
264
264
|
# Catch exception.
|
265
|
-
|
265
|
+
exc_text, *_ = catch_exc()
|
266
266
|
|
267
267
|
# Save.
|
268
|
-
send_param.exc_reports.append(
|
268
|
+
send_param.exc_reports.append(exc_text)
|
269
269
|
|
270
270
|
send_param.status = send_param.StatusEnum.SENT
|
271
271
|
|
@@ -290,6 +290,16 @@ class WeChatSender(BaseWeChat):
|
|
290
290
|
send_param : `WeChatSendParameter` instance.
|
291
291
|
"""
|
292
292
|
|
293
|
+
# Test.
|
294
|
+
if (
|
295
|
+
send_param.params.get('is_test')
|
296
|
+
and send_param.send_type in (WeChatSendTypeEnum.TEXT, WeChatSendTypeEnum.TEXT_AT)
|
297
|
+
):
|
298
|
+
text: str = send_param.params['text']
|
299
|
+
now_time = now('time_str')
|
300
|
+
modify_text = text.replace(':time:', now_time, 1)
|
301
|
+
send_param.params['text'] = modify_text
|
302
|
+
|
293
303
|
# Send.
|
294
304
|
match send_param.send_type:
|
295
305
|
|
@@ -453,7 +463,7 @@ class WeChatSender(BaseWeChat):
|
|
453
463
|
**params
|
454
464
|
)
|
455
465
|
send_param.status = send_param.StatusEnum.INIT
|
456
|
-
handle_handler_exception = lambda
|
466
|
+
handle_handler_exception = lambda exc_text, *_: send_param.exc_reports.append(exc_text)
|
457
467
|
|
458
468
|
# Handler.
|
459
469
|
for handler in self.handlers:
|
@@ -470,7 +480,7 @@ class WeChatSender(BaseWeChat):
|
|
470
480
|
) -> None:
|
471
481
|
"""
|
472
482
|
Add send handler function.
|
473
|
-
Call at the after initialization, before inserting into database queue.
|
483
|
+
Call at the after initialization, before inserting into the database queue.
|
474
484
|
Call at the after get from database queue, before sending.
|
475
485
|
Call at the after sending.
|
476
486
|
Can be use `WeChatSendParameter.status` judge status.
|
@@ -572,18 +582,18 @@ class WeChatSender(BaseWeChat):
|
|
572
582
|
*arg,
|
573
583
|
**kwargs
|
574
584
|
)
|
575
|
-
except:
|
576
|
-
*_,
|
585
|
+
except BaseException:
|
586
|
+
*_, exc, _ = catch_exc()
|
577
587
|
|
578
588
|
# Report.
|
579
589
|
if not isinstance(
|
580
|
-
|
590
|
+
exc,
|
581
591
|
(WeChatTriggerContinueExit, WeChatTriggerBreakExit)
|
582
592
|
):
|
583
593
|
text = '\n'.join(
|
584
594
|
[
|
585
595
|
str(arg)
|
586
|
-
for arg in
|
596
|
+
for arg in exc.args
|
587
597
|
]
|
588
598
|
)
|
589
599
|
for receive_id in receive_ids:
|
reywechat/rtrigger.py
CHANGED
@@ -13,7 +13,7 @@ from typing import Any, TypedDict, NoReturn
|
|
13
13
|
from collections.abc import Callable
|
14
14
|
from reykit.rbase import catch_exc
|
15
15
|
|
16
|
-
from .rbase import
|
16
|
+
from .rbase import WeChatBase, WeChatTriggerContinueExit, WeChatTriggerBreakExit
|
17
17
|
from .rreceive import WeChatMessage, WechatReceiver
|
18
18
|
|
19
19
|
|
@@ -25,7 +25,7 @@ __all__ = (
|
|
25
25
|
TriggerRule = TypedDict('TriggerRule', {'level': float, 'execute': Callable[[WeChatMessage], None], 'is_reply': bool})
|
26
26
|
|
27
27
|
|
28
|
-
class WeChatTrigger(
|
28
|
+
class WeChatTrigger(WeChatBase):
|
29
29
|
"""
|
30
30
|
WeChat trigger type.
|
31
31
|
"""
|
@@ -98,13 +98,13 @@ class WeChatTrigger(BaseWeChat):
|
|
98
98
|
break
|
99
99
|
|
100
100
|
# Exception.
|
101
|
-
except:
|
101
|
+
except BaseException:
|
102
102
|
|
103
103
|
## Catch exception.
|
104
|
-
|
104
|
+
exc_text, *_ = catch_exc()
|
105
105
|
|
106
106
|
## Save.
|
107
|
-
message.exc_reports.append(
|
107
|
+
message.exc_reports.append(exc_text)
|
108
108
|
|
109
109
|
finally:
|
110
110
|
message.trigger_rule = None
|
reywechat/rwechat.py
CHANGED
@@ -14,7 +14,7 @@ from os import getcwd as os_getcwd
|
|
14
14
|
from reydb.rdb import Database
|
15
15
|
from reykit.rbase import block
|
16
16
|
|
17
|
-
from .rbase import
|
17
|
+
from .rbase import WeChatBase
|
18
18
|
|
19
19
|
|
20
20
|
__all__ = (
|
@@ -22,7 +22,7 @@ __all__ = (
|
|
22
22
|
)
|
23
23
|
|
24
24
|
|
25
|
-
class WeChat(
|
25
|
+
class WeChat(WeChatBase):
|
26
26
|
"""
|
27
27
|
WeChat type.
|
28
28
|
|
@@ -109,7 +109,7 @@ class WeChat(BaseWeChat):
|
|
109
109
|
self.wrap_try_send = self.sender.wrap_try_send
|
110
110
|
|
111
111
|
## Database.
|
112
|
-
self.database_build = self.database.
|
112
|
+
self.database_build = self.database.build_db
|
113
113
|
|
114
114
|
## Schedule.
|
115
115
|
self.schedule_add_task = self.schedule.add_task
|
@@ -0,0 +1,17 @@
|
|
1
|
+
reywechat/__init__.py,sha256=jnk8xZKR7nkRXIcM7fvtX46WcDp-lPx1ctLnWvCi4S4,507
|
2
|
+
reywechat/rall.py,sha256=zEW-mLL2uP8aT2_foCMFGmMi_3RCrGl8qutnSVkmY1E,397
|
3
|
+
reywechat/rbase.py,sha256=hbxn5spvcl_C_Bw8A9teulOXT9GMlxUw145_YbXIOzc,1124
|
4
|
+
reywechat/rcache.py,sha256=7UsHHfgFOgxuSqlTSAO6CprgUUOeBCXYus0kxmRBQxk,908
|
5
|
+
reywechat/rclient.py,sha256=lc1CPle9h08mwP8NlJN0ybzcNJxtpV0ma6q6cz1RIxk,22518
|
6
|
+
reywechat/rdb.py,sha256=9WI0sxMscGMu-PnXKGxHThoO-kr2v8VPqQbxbZdjedw,47334
|
7
|
+
reywechat/rlog.py,sha256=4EsTgrgC05JvWeKAucUaWGga638CRRJISJN6qncBCAw,5249
|
8
|
+
reywechat/rreceive.py,sha256=dVKCGv6oTrmMK-v_zf5j0Zr04p0r2kbkWWAnkFYBuSY,36181
|
9
|
+
reywechat/rschedule.py,sha256=JzjYdjtFnbNNnpRGnCUJJThh3QreD271GXO6Emz216U,1865
|
10
|
+
reywechat/rsend.py,sha256=GTMAe-w8j8vEqxoqjFEb0tEg8z1qf3RtJyZgckVgvW4,17994
|
11
|
+
reywechat/rtrigger.py,sha256=WdOQwobPdGPyyE9J-qtQFPd60713T0aWqKk02PLdCRE,4966
|
12
|
+
reywechat/rwechat.py,sha256=YW8guhhZQde-Ic0akvh_NpIf3C2xNSw71sTi6CpLVo8,4877
|
13
|
+
reywechat/data/client_api.dll,sha256=H9uj-x9Ztg0jFZK0yY6NsnyH5_119dQRFfoVVMidxRs,592384
|
14
|
+
reywechat-1.0.48.dist-info/METADATA,sha256=T58AXNaq9iq0qzYZZwPHB5cjFFqxdsxFQ7-R9mz5Aww,1551
|
15
|
+
reywechat-1.0.48.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
16
|
+
reywechat-1.0.48.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
17
|
+
reywechat-1.0.48.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=Hh_HE-t_KUMlrz4gEFPh1AjmhnrSgH520IFJPumWb7A,908
|
5
|
-
reywechat/rclient.py,sha256=MEvQB3pHb5ORukKbKntalRtFcKIOP9BGtDsMt5ihQfM,22524
|
6
|
-
reywechat/rdb.py,sha256=akIQsx4CZIt-H6kXWn2vpUYjo5MgD8MluzBMnSdmLaM,40051
|
7
|
-
reywechat/rlog.py,sha256=IJL2WquiOYfB9iEai9xjojkuxPxiRHkdzZ5vCeaSA98,5261
|
8
|
-
reywechat/rreceive.py,sha256=zANspJOxn2sQLW0CdA-vFsIeqG1OuVwDyytGM5LxQvQ,35483
|
9
|
-
reywechat/rschedule.py,sha256=X9kreXdClTeItJHmNPJNqb_lct-BiLCyusMQxsj5hWU,1865
|
10
|
-
reywechat/rsend.py,sha256=GfCv5O1-81r-o-RLzMMW_MQE99KwO9gZ3-93HaJ97W8,17595
|
11
|
-
reywechat/rtrigger.py,sha256=n8kUNovh62r7crlXrp33uaKvbILT-wcfvUqeyGt7YhM,4956
|
12
|
-
reywechat/rwechat.py,sha256=OcElINAi9jM-eDb_OTtseBW3kyG_3jD4V4QmltR6MeE,4874
|
13
|
-
reywechat/data/client_api.dll,sha256=H9uj-x9Ztg0jFZK0yY6NsnyH5_119dQRFfoVVMidxRs,592384
|
14
|
-
reywechat-1.0.46.dist-info/METADATA,sha256=R7vaJAjsObdA7VXgbOaB-Sj4k8kasY9i5EJhSg564JQ,1551
|
15
|
-
reywechat-1.0.46.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
16
|
-
reywechat-1.0.46.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
17
|
-
reywechat-1.0.46.dist-info/RECORD,,
|
File without changes
|
File without changes
|