reywechat 1.0.22__py3-none-any.whl → 1.0.24__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/rclient.py +8 -8
- reywechat/rdb.py +257 -195
- reywechat/rlog.py +4 -4
- reywechat/rreceive.py +169 -107
- reywechat/rschedule.py +5 -49
- reywechat/rsend.py +108 -228
- reywechat/rtrigger.py +6 -4
- reywechat/rwechat.py +22 -24
- {reywechat-1.0.22.dist-info → reywechat-1.0.24.dist-info}/METADATA +1 -1
- reywechat-1.0.24.dist-info/RECORD +16 -0
- reywechat-1.0.22.dist-info/RECORD +0 -16
- {reywechat-1.0.22.dist-info → reywechat-1.0.24.dist-info}/WHEEL +0 -0
- {reywechat-1.0.22.dist-info → reywechat-1.0.24.dist-info}/licenses/LICENSE +0 -0
reywechat/rdb.py
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
"""
|
10
10
|
|
11
11
|
|
12
|
-
from typing import Literal
|
12
|
+
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
|
@@ -36,16 +36,16 @@ class WeChatDatabase(BaseWeChat):
|
|
36
36
|
|
37
37
|
def __init__(
|
38
38
|
self,
|
39
|
-
|
40
|
-
|
39
|
+
wechat: WeChat,
|
40
|
+
rdatabase: Database | dict[Literal['wechat', 'file'], Database]
|
41
41
|
) -> None:
|
42
42
|
"""
|
43
43
|
Build instance attributes.
|
44
44
|
|
45
45
|
Parameters
|
46
46
|
----------
|
47
|
-
|
48
|
-
|
47
|
+
wechat : `WeChatClient` instance.
|
48
|
+
rdatabase : `WeChatDatabase` instance of `reykit` package.
|
49
49
|
- `WeChatDatabase`, Set all `WeChatDatabase`: instances.
|
50
50
|
- `dict`, Set each `WeChatDatabase`: instance, all item is required.
|
51
51
|
`Key 'wechat'`: `WeChatDatabase` instance used in WeChat methods.
|
@@ -53,23 +53,23 @@ class WeChatDatabase(BaseWeChat):
|
|
53
53
|
"""
|
54
54
|
|
55
55
|
# Set attribute.
|
56
|
-
self.
|
57
|
-
match
|
56
|
+
self.wechat = wechat
|
57
|
+
match rdatabase:
|
58
58
|
case Database():
|
59
|
-
self.
|
59
|
+
self.rdatabase_wechat = self.rdatabase_file = rdatabase
|
60
60
|
case dict():
|
61
|
-
self.
|
62
|
-
self.
|
61
|
+
self.rdatabase_wechat = rdatabase.get('wechat')
|
62
|
+
self.rdatabase_file = rdatabase.get('file')
|
63
63
|
if (
|
64
|
-
self.
|
65
|
-
or self.
|
64
|
+
self.rdatabase_wechat
|
65
|
+
or self.rdatabase_file
|
66
66
|
):
|
67
|
-
throw(ValueError,
|
67
|
+
throw(ValueError, rdatabase)
|
68
68
|
case _:
|
69
|
-
throw(TypeError,
|
69
|
+
throw(TypeError, rdatabase)
|
70
70
|
|
71
71
|
# Check.
|
72
|
-
if 'sqlite' in (self.
|
72
|
+
if 'sqlite' in (self.rdatabase_wechat.backend, self.rdatabase_file.backend):
|
73
73
|
text='not suitable for SQLite databases'
|
74
74
|
throw(AssertionError, text=text)
|
75
75
|
|
@@ -77,12 +77,14 @@ class WeChatDatabase(BaseWeChat):
|
|
77
77
|
self.build()
|
78
78
|
|
79
79
|
# Add handler.
|
80
|
-
self.
|
81
|
-
self.
|
82
|
-
self.
|
83
|
-
self.
|
84
|
-
self.
|
85
|
-
|
80
|
+
self.__add_handler_to_contact_user()
|
81
|
+
self.__add_handler_to_contact_room()
|
82
|
+
self.__add_handler_to_contact_room_user()
|
83
|
+
self.__add_handler_to_message_receive()
|
84
|
+
self.__add_handler_update_send_status()
|
85
|
+
|
86
|
+
# Loop.
|
87
|
+
self.__start_from_message_send()
|
86
88
|
|
87
89
|
|
88
90
|
def build(self) -> None:
|
@@ -401,10 +403,13 @@ class WeChatDatabase(BaseWeChat):
|
|
401
403
|
'name': 'parameter',
|
402
404
|
'type': 'json',
|
403
405
|
'constraint': 'NOT NULL',
|
404
|
-
'comment':
|
405
|
-
|
406
|
-
|
407
|
-
|
406
|
+
'comment': 'Send parameters.'
|
407
|
+
},
|
408
|
+
{
|
409
|
+
'name': 'file_id',
|
410
|
+
'type': 'mediumint unsigned',
|
411
|
+
'constraint': 'DEFAULT NULL',
|
412
|
+
'comment': 'Send file ID, from the file database.'
|
408
413
|
}
|
409
414
|
],
|
410
415
|
'primary': 'send_id',
|
@@ -498,10 +503,10 @@ class WeChatDatabase(BaseWeChat):
|
|
498
503
|
# Build.
|
499
504
|
|
500
505
|
## WeChat.
|
501
|
-
self.
|
506
|
+
self.rdatabase_wechat.build.build(databases, tables, views_stats=views_stats)
|
502
507
|
|
503
508
|
## File.
|
504
|
-
self.
|
509
|
+
self.rdatabase_file.file.build()
|
505
510
|
|
506
511
|
# Update.
|
507
512
|
self.update_contact_user()
|
@@ -515,7 +520,7 @@ class WeChatDatabase(BaseWeChat):
|
|
515
520
|
"""
|
516
521
|
|
517
522
|
# Get data.
|
518
|
-
contact_table = self.
|
523
|
+
contact_table = self.wechat.client.get_contact_table('user')
|
519
524
|
|
520
525
|
user_data = [
|
521
526
|
{
|
@@ -531,7 +536,7 @@ class WeChatDatabase(BaseWeChat):
|
|
531
536
|
]
|
532
537
|
|
533
538
|
# Insert and update.
|
534
|
-
conn = self.
|
539
|
+
conn = self.rdatabase_wechat.connect()
|
535
540
|
|
536
541
|
## Insert.
|
537
542
|
if contact_table != []:
|
@@ -571,7 +576,7 @@ class WeChatDatabase(BaseWeChat):
|
|
571
576
|
"""
|
572
577
|
|
573
578
|
# Get data.
|
574
|
-
contact_table = self.
|
579
|
+
contact_table = self.wechat.client.get_contact_table('room')
|
575
580
|
|
576
581
|
room_data = [
|
577
582
|
{
|
@@ -587,7 +592,7 @@ class WeChatDatabase(BaseWeChat):
|
|
587
592
|
]
|
588
593
|
|
589
594
|
# Insert and update.
|
590
|
-
conn = self.
|
595
|
+
conn = self.rdatabase_wechat.connect()
|
591
596
|
|
592
597
|
## Insert.
|
593
598
|
if contact_table != []:
|
@@ -639,7 +644,7 @@ class WeChatDatabase(BaseWeChat):
|
|
639
644
|
|
640
645
|
## All.
|
641
646
|
if room_id is None:
|
642
|
-
contact_table = self.
|
647
|
+
contact_table = self.wechat.client.get_contact_table('room')
|
643
648
|
|
644
649
|
## Given.
|
645
650
|
else:
|
@@ -654,7 +659,7 @@ class WeChatDatabase(BaseWeChat):
|
|
654
659
|
}
|
655
660
|
for row in contact_table
|
656
661
|
for user_id, name
|
657
|
-
in self.
|
662
|
+
in self.wechat.client.get_room_member_dict(row['id']).items()
|
658
663
|
]
|
659
664
|
room_user_ids = [
|
660
665
|
'%s,%s' % (
|
@@ -665,7 +670,7 @@ class WeChatDatabase(BaseWeChat):
|
|
665
670
|
]
|
666
671
|
|
667
672
|
# Insert and update.
|
668
|
-
conn = self.
|
673
|
+
conn = self.rdatabase_wechat.connect()
|
669
674
|
|
670
675
|
## Insert.
|
671
676
|
if room_user_data != []:
|
@@ -709,7 +714,7 @@ class WeChatDatabase(BaseWeChat):
|
|
709
714
|
conn.close()
|
710
715
|
|
711
716
|
|
712
|
-
def
|
717
|
+
def __add_handler_to_contact_user(self) -> None:
|
713
718
|
"""
|
714
719
|
Add handler, write record to table `contact_user`.
|
715
720
|
"""
|
@@ -729,7 +734,7 @@ class WeChatDatabase(BaseWeChat):
|
|
729
734
|
if message.is_new_user:
|
730
735
|
|
731
736
|
## Generate data.
|
732
|
-
name = self.
|
737
|
+
name = self.wechat.client.get_contact_name(message.user)
|
733
738
|
data = {
|
734
739
|
'user_id': message.user,
|
735
740
|
'name': name,
|
@@ -737,7 +742,7 @@ class WeChatDatabase(BaseWeChat):
|
|
737
742
|
}
|
738
743
|
|
739
744
|
## Insert.
|
740
|
-
self.
|
745
|
+
self.rdatabase_wechat.execute_insert(
|
741
746
|
('wechat', 'contact_user'),
|
742
747
|
data,
|
743
748
|
'update'
|
@@ -745,10 +750,10 @@ class WeChatDatabase(BaseWeChat):
|
|
745
750
|
|
746
751
|
|
747
752
|
# Add handler.
|
748
|
-
self.
|
753
|
+
self.wechat.receiver.add_handler(handler_to_contact_user)
|
749
754
|
|
750
755
|
|
751
|
-
def
|
756
|
+
def __add_handler_to_contact_room(self) -> None:
|
752
757
|
"""
|
753
758
|
Add handler, write record to table `contact_room`.
|
754
759
|
"""
|
@@ -768,7 +773,7 @@ class WeChatDatabase(BaseWeChat):
|
|
768
773
|
if message.is_new_room:
|
769
774
|
|
770
775
|
## Generate data.
|
771
|
-
name = self.
|
776
|
+
name = self.wechat.client.get_contact_name(message.room)
|
772
777
|
data = {
|
773
778
|
'room_id': message.room,
|
774
779
|
'name': name,
|
@@ -778,7 +783,7 @@ class WeChatDatabase(BaseWeChat):
|
|
778
783
|
## Insert.
|
779
784
|
|
780
785
|
### 'contact_room'.
|
781
|
-
self.
|
786
|
+
self.rdatabase_wechat.execute_insert(
|
782
787
|
('wechat', 'contact_room'),
|
783
788
|
data,
|
784
789
|
'update'
|
@@ -800,7 +805,7 @@ class WeChatDatabase(BaseWeChat):
|
|
800
805
|
}
|
801
806
|
|
802
807
|
## Update.
|
803
|
-
self.
|
808
|
+
self.rdatabase_wechat.execute_update(
|
804
809
|
('wechat', 'contact_room'),
|
805
810
|
data
|
806
811
|
)
|
@@ -822,17 +827,17 @@ class WeChatDatabase(BaseWeChat):
|
|
822
827
|
}
|
823
828
|
|
824
829
|
## Update.
|
825
|
-
self.
|
830
|
+
self.rdatabase_wechat.execute_update(
|
826
831
|
('wechat', 'contact_room'),
|
827
832
|
data
|
828
833
|
)
|
829
834
|
|
830
835
|
|
831
836
|
# Add handler.
|
832
|
-
self.
|
837
|
+
self.wechat.receiver.add_handler(handler_to_contact_room)
|
833
838
|
|
834
839
|
|
835
|
-
def
|
840
|
+
def __add_handler_to_contact_room_user(self) -> None:
|
836
841
|
"""
|
837
842
|
Add handler, write record to table `contact_room_user`.
|
838
843
|
"""
|
@@ -859,10 +864,10 @@ class WeChatDatabase(BaseWeChat):
|
|
859
864
|
|
860
865
|
|
861
866
|
# Add handler.
|
862
|
-
self.
|
867
|
+
self.wechat.receiver.add_handler(handler_to_contact_room_user)
|
863
868
|
|
864
869
|
|
865
|
-
def
|
870
|
+
def __add_handler_to_message_receive(self) -> None:
|
866
871
|
"""
|
867
872
|
Add handler, write record to table `message_receive`.
|
868
873
|
"""
|
@@ -882,7 +887,7 @@ class WeChatDatabase(BaseWeChat):
|
|
882
887
|
if message.file is None:
|
883
888
|
file_id = None
|
884
889
|
else:
|
885
|
-
file_id = self.
|
890
|
+
file_id = self.rdatabase_file.file.upload(
|
886
891
|
message.file['path'],
|
887
892
|
message.file['name'],
|
888
893
|
'WeChat'
|
@@ -902,7 +907,7 @@ class WeChatDatabase(BaseWeChat):
|
|
902
907
|
}
|
903
908
|
|
904
909
|
# Insert.
|
905
|
-
self.
|
910
|
+
self.rdatabase_wechat.execute_insert(
|
906
911
|
('wechat', 'message_receive'),
|
907
912
|
data,
|
908
913
|
'ignore'
|
@@ -910,69 +915,45 @@ class WeChatDatabase(BaseWeChat):
|
|
910
915
|
|
911
916
|
|
912
917
|
# Add handler.
|
913
|
-
self.
|
918
|
+
self.wechat.receiver.add_handler(handler_to_message_receive)
|
914
919
|
|
915
920
|
|
916
|
-
def
|
921
|
+
def __add_handler_update_send_status(self) -> None:
|
917
922
|
"""
|
918
|
-
|
923
|
+
In the thread, loop read record from table `message_send`, put send queue.
|
919
924
|
"""
|
920
925
|
|
921
926
|
|
922
927
|
# Define.
|
923
|
-
def
|
928
|
+
def handler_update_send_status(sendparam: WeChatSendParameter) -> None:
|
924
929
|
"""
|
925
|
-
|
930
|
+
Update field `status` of table `message_send`.
|
926
931
|
|
927
932
|
Parameters
|
928
933
|
----------
|
929
934
|
sendparam : `WeChatSendParameter` instance.
|
930
935
|
"""
|
931
936
|
|
932
|
-
#
|
933
|
-
if sendparam.send_id is not None:
|
934
|
-
return
|
935
|
-
|
936
|
-
# Generate data.
|
937
|
-
path = sendparam.params.get('path')
|
938
|
-
params = {
|
939
|
-
key: value
|
940
|
-
for key, value in sendparam.params.items()
|
941
|
-
if key not in (
|
942
|
-
'send_type',
|
943
|
-
'receive_id',
|
944
|
-
'path'
|
945
|
-
)
|
946
|
-
}
|
947
|
-
|
948
|
-
## Upload file.
|
949
|
-
if path is not None:
|
950
|
-
file_id = self.rrdatabase_file.file.upload(
|
951
|
-
path,
|
952
|
-
note='WeChat'
|
953
|
-
)
|
954
|
-
params['file_id'] = file_id
|
955
|
-
|
937
|
+
# Get parameter.
|
956
938
|
if sendparam.exc_reports == []:
|
957
939
|
status = 2
|
958
940
|
else:
|
959
941
|
status = 3
|
960
942
|
data = {
|
943
|
+
'send_id': sendparam.send_id,
|
961
944
|
'status': status,
|
962
|
-
'
|
963
|
-
'receive_id': sendparam.receive_id,
|
964
|
-
'parameter': params
|
945
|
+
'limit': 1
|
965
946
|
}
|
966
947
|
|
967
|
-
#
|
968
|
-
self.
|
948
|
+
# Update.
|
949
|
+
self.rdatabase_wechat.execute_update(
|
969
950
|
('wechat', 'message_send'),
|
970
951
|
data
|
971
952
|
)
|
972
953
|
|
973
954
|
|
974
955
|
# Add handler.
|
975
|
-
self.
|
956
|
+
self.wechat.sender.add_handler(handler_update_send_status)
|
976
957
|
|
977
958
|
|
978
959
|
def __download_file(
|
@@ -992,147 +973,112 @@ class WeChatDatabase(BaseWeChat):
|
|
992
973
|
"""
|
993
974
|
|
994
975
|
# Select.
|
995
|
-
file_info = self.
|
976
|
+
file_info = self.rdatabase_file.file.query(file_id)
|
977
|
+
file_name = file_info['name']
|
978
|
+
file_md5 = file_info['md5']
|
996
979
|
|
997
980
|
# Check.
|
998
|
-
|
999
|
-
rfolder = Folder(self.rwechat.dir_file)
|
981
|
+
rfolder = Folder(self.wechat.dir_cache)
|
1000
982
|
pattern = f'^{file_md5}$'
|
1001
|
-
|
983
|
+
cache_path = rfolder.search(pattern)
|
1002
984
|
|
1003
985
|
# Download.
|
1004
|
-
if
|
1005
|
-
|
1006
|
-
self.
|
986
|
+
if cache_path is None:
|
987
|
+
cache_path = '%s/%s' % (
|
988
|
+
self.wechat.dir_cache,
|
1007
989
|
file_md5
|
1008
990
|
)
|
1009
|
-
|
991
|
+
self.rdatabase_file.file.download(
|
1010
992
|
file_id,
|
1011
|
-
|
993
|
+
cache_path
|
1012
994
|
)
|
1013
|
-
else:
|
1014
|
-
save_path = search_path
|
1015
|
-
|
1016
|
-
file_name = file_info['name']
|
1017
|
-
return save_path, file_name
|
1018
|
-
|
1019
|
-
|
1020
|
-
def __from_message_send(self) -> None:
|
1021
|
-
"""
|
1022
|
-
Read record from table `message_send`, put send queue.
|
1023
|
-
"""
|
1024
995
|
|
1025
|
-
|
1026
|
-
conn = self.rrdatabase_wechat.connect()
|
1027
|
-
|
1028
|
-
# Read.
|
1029
|
-
where = (
|
1030
|
-
'(\n'
|
1031
|
-
' `status` = 0\n'
|
1032
|
-
' AND (\n'
|
1033
|
-
' `plan_time` IS NULL\n'
|
1034
|
-
' OR `plan_time` < NOW()\n'
|
1035
|
-
' )\n'
|
1036
|
-
')'
|
1037
|
-
)
|
1038
|
-
result = conn.execute_select(
|
1039
|
-
('wechat', 'message_send'),
|
1040
|
-
['send_id', 'type', 'receive_id', 'parameter'],
|
1041
|
-
where,
|
1042
|
-
order='`plan_time` DESC, `send_id`'
|
1043
|
-
)
|
1044
|
-
|
1045
|
-
# Convert.
|
1046
|
-
if result.empty:
|
1047
|
-
return
|
1048
|
-
table = result.to_table()
|
1049
|
-
|
1050
|
-
# Update.
|
1051
|
-
send_ids = [
|
1052
|
-
row['send_id']
|
1053
|
-
for row in table
|
1054
|
-
]
|
1055
|
-
sql = (
|
1056
|
-
'UPDATE `wechat`.`message_send`\n'
|
1057
|
-
'SET `status` = 1\n'
|
1058
|
-
'WHERE `send_id` IN :send_ids'
|
1059
|
-
)
|
1060
|
-
conn.execute(
|
1061
|
-
sql,
|
1062
|
-
send_ids=send_ids
|
1063
|
-
)
|
1064
|
-
|
1065
|
-
# Send.
|
1066
|
-
for row in table:
|
1067
|
-
send_id, type_, receive_id, parameter = row.values()
|
1068
|
-
send_type = WeChatSendEnum(type_)
|
1069
|
-
parameter: dict = json_loads(parameter)
|
1070
|
-
|
1071
|
-
## Save file.
|
1072
|
-
file_id = parameter.get('file_id')
|
1073
|
-
if file_id is not None:
|
1074
|
-
file_path, file_name = self.__download_file(file_id)
|
1075
|
-
parameter['path'] = file_path
|
1076
|
-
parameter['file_name'] = file_name
|
1077
|
-
|
1078
|
-
self.rwechat.send(
|
1079
|
-
send_type,
|
1080
|
-
receive_id,
|
1081
|
-
send_id,
|
1082
|
-
**parameter
|
1083
|
-
)
|
1084
|
-
|
1085
|
-
# Commit.
|
1086
|
-
conn.commit()
|
996
|
+
return cache_path, file_name
|
1087
997
|
|
1088
998
|
|
1089
999
|
@wrap_thread
|
1090
|
-
def
|
1000
|
+
def __start_from_message_send(self) -> None:
|
1091
1001
|
"""
|
1092
|
-
|
1002
|
+
Start loop read record from table `message_send`, put send queue.
|
1093
1003
|
"""
|
1094
1004
|
|
1095
1005
|
|
1096
1006
|
# Define.
|
1097
|
-
def
|
1007
|
+
def __from_message_send() -> None:
|
1098
1008
|
"""
|
1099
|
-
|
1100
|
-
|
1101
|
-
Parameters
|
1102
|
-
----------
|
1103
|
-
sendparam : `WeChatSendParameter` instance.
|
1009
|
+
Read record from table `message_send`, put send queue.
|
1104
1010
|
"""
|
1105
1011
|
|
1106
|
-
# Break.
|
1107
|
-
if sendparam.send_id is None:
|
1108
|
-
return
|
1109
|
-
|
1110
1012
|
# Get parameter.
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
'
|
1117
|
-
'
|
1118
|
-
'
|
1119
|
-
|
1013
|
+
conn = self.rdatabase_wechat.connect()
|
1014
|
+
|
1015
|
+
# Read.
|
1016
|
+
where = (
|
1017
|
+
'(\n'
|
1018
|
+
' `status` = 0\n'
|
1019
|
+
' AND (\n'
|
1020
|
+
' `plan_time` IS NULL\n'
|
1021
|
+
' OR `plan_time` < NOW()\n'
|
1022
|
+
' )\n'
|
1023
|
+
')'
|
1024
|
+
)
|
1025
|
+
result = conn.execute_select(
|
1026
|
+
('wechat', 'message_send'),
|
1027
|
+
['send_id', 'type', 'receive_id', 'parameter', 'file_id'],
|
1028
|
+
where,
|
1029
|
+
order='`plan_time` DESC, `send_id`'
|
1030
|
+
)
|
1031
|
+
|
1032
|
+
# Convert.
|
1033
|
+
if result.empty:
|
1034
|
+
return
|
1035
|
+
table = result.to_table()
|
1120
1036
|
|
1121
1037
|
# Update.
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1038
|
+
send_ids = [
|
1039
|
+
row['send_id']
|
1040
|
+
for row in table
|
1041
|
+
]
|
1042
|
+
sql = (
|
1043
|
+
'UPDATE `wechat`.`message_send`\n'
|
1044
|
+
'SET `status` = 1\n'
|
1045
|
+
'WHERE `send_id` IN :send_ids'
|
1046
|
+
)
|
1047
|
+
conn.execute(
|
1048
|
+
sql,
|
1049
|
+
send_ids=send_ids
|
1125
1050
|
)
|
1126
1051
|
|
1052
|
+
# Send.
|
1053
|
+
for row in table:
|
1054
|
+
send_id, type_, receive_id, parameter, file_id = row.values()
|
1055
|
+
send_type = WeChatSendEnum(type_)
|
1056
|
+
parameter: dict = json_loads(parameter)
|
1057
|
+
|
1058
|
+
## Save file.
|
1059
|
+
if file_id is not None:
|
1060
|
+
file_path, file_name = self.__download_file(file_id)
|
1061
|
+
parameter['file_path'] = file_path
|
1062
|
+
parameter['file_name'] = file_name
|
1063
|
+
|
1064
|
+
sendparam = WeChatSendParameter(
|
1065
|
+
self.wechat.sender,
|
1066
|
+
send_type,
|
1067
|
+
receive_id,
|
1068
|
+
send_id,
|
1069
|
+
**parameter
|
1070
|
+
)
|
1071
|
+
self.wechat.sender.__send(sendparam)
|
1072
|
+
|
1073
|
+
# Commit.
|
1074
|
+
conn.commit()
|
1127
1075
|
|
1128
|
-
# Add handler.
|
1129
|
-
self.rwechat.sender.add_handler(handler_update_send_status)
|
1130
1076
|
|
1131
1077
|
# Loop.
|
1132
1078
|
while True:
|
1133
1079
|
|
1134
1080
|
# Put.
|
1135
|
-
|
1081
|
+
__from_message_send()
|
1136
1082
|
|
1137
1083
|
# Wait.
|
1138
1084
|
sleep(1)
|
@@ -1160,7 +1106,7 @@ class WeChatDatabase(BaseWeChat):
|
|
1160
1106
|
|
1161
1107
|
## User.
|
1162
1108
|
if message.room is None:
|
1163
|
-
result = message.receiver.
|
1109
|
+
result = message.receiver.wechat.database.rdatabase_wechat.execute_select(
|
1164
1110
|
('wechat', 'contact_user'),
|
1165
1111
|
['valid'],
|
1166
1112
|
'`user_id` = :user_id',
|
@@ -1185,7 +1131,7 @@ class WeChatDatabase(BaseWeChat):
|
|
1185
1131
|
') AS `a`\n'
|
1186
1132
|
'WHERE `valid` = 1'
|
1187
1133
|
)
|
1188
|
-
result = message.receiver.
|
1134
|
+
result = message.receiver.wechat.database.rdatabase_wechat.execute(
|
1189
1135
|
sql,
|
1190
1136
|
room_id=message.room,
|
1191
1137
|
user_id=message.user
|
@@ -1195,3 +1141,119 @@ class WeChatDatabase(BaseWeChat):
|
|
1195
1141
|
judge = valid == 1
|
1196
1142
|
|
1197
1143
|
return judge
|
1144
|
+
|
1145
|
+
|
1146
|
+
@overload
|
1147
|
+
def send(
|
1148
|
+
self,
|
1149
|
+
send_type: Literal[WeChatSendEnum.SEND_TEXT],
|
1150
|
+
receive_id: str,
|
1151
|
+
*,
|
1152
|
+
text: str
|
1153
|
+
) -> None: ...
|
1154
|
+
|
1155
|
+
@overload
|
1156
|
+
def send(
|
1157
|
+
self,
|
1158
|
+
send_type: Literal[WeChatSendEnum.SEND_TEXT_AT],
|
1159
|
+
receive_id: str,
|
1160
|
+
*,
|
1161
|
+
user_id: str | list[str] | Literal['notify@all'],
|
1162
|
+
text: str
|
1163
|
+
) -> None: ...
|
1164
|
+
|
1165
|
+
@overload
|
1166
|
+
def send(
|
1167
|
+
self,
|
1168
|
+
send_type: Literal[WeChatSendEnum.SEND_FILE, WeChatSendEnum.SEND_IMAGE, WeChatSendEnum.SEND_EMOTION],
|
1169
|
+
receive_id: str,
|
1170
|
+
*,
|
1171
|
+
file_path: str,
|
1172
|
+
file_name: str | None = None
|
1173
|
+
) -> None: ...
|
1174
|
+
|
1175
|
+
@overload
|
1176
|
+
def send(
|
1177
|
+
self,
|
1178
|
+
send_type: Literal[WeChatSendEnum.SEND_PAT],
|
1179
|
+
receive_id: str,
|
1180
|
+
*,
|
1181
|
+
user_id: str
|
1182
|
+
) -> None: ...
|
1183
|
+
|
1184
|
+
@overload
|
1185
|
+
def send(
|
1186
|
+
self,
|
1187
|
+
send_type: Literal[WeChatSendEnum.SEND_PUBLIC],
|
1188
|
+
receive_id: str,
|
1189
|
+
*,
|
1190
|
+
page_url: str,
|
1191
|
+
title: str,
|
1192
|
+
text: str | None = None,
|
1193
|
+
image_url: str | None = None,
|
1194
|
+
public_name: str | None = None,
|
1195
|
+
public_id: str | None = None
|
1196
|
+
) -> None: ...
|
1197
|
+
|
1198
|
+
@overload
|
1199
|
+
def send(
|
1200
|
+
self,
|
1201
|
+
send_type: Literal[WeChatSendEnum.SEND_FORWARD],
|
1202
|
+
receive_id: str,
|
1203
|
+
*,
|
1204
|
+
message_id: str
|
1205
|
+
) -> None: ...
|
1206
|
+
|
1207
|
+
def send(
|
1208
|
+
self,
|
1209
|
+
send_type: WeChatSendEnum,
|
1210
|
+
receive_id: str | None = None,
|
1211
|
+
**params: Any
|
1212
|
+
) -> None:
|
1213
|
+
"""
|
1214
|
+
Insert into `wechat.message_send` table of database, wait send.
|
1215
|
+
|
1216
|
+
Parameters
|
1217
|
+
----------
|
1218
|
+
send_type : Send type.
|
1219
|
+
- `Literal[WeChatSendEnum.SEND_TEXT]`: Send text message, use `WeChatClient.send_text`: method.
|
1220
|
+
- `Literal[WeChatSendEnum.SEND_TEXT_AT]`: Send text message with `@`, use `WeChatClient.send_text_at`: method.
|
1221
|
+
- `Literal[WeChatSendEnum.SEND_FILE]`: Send file message, use `WeChatClient.send_file`: method.
|
1222
|
+
- `Literal[WeChatSendEnum.SEND_IMAGE]`: Send image message, use `WeChatClient.send_image`: method.
|
1223
|
+
- `Literal[WeChatSendEnum.SEND_EMOTION]`: Send emotion message, use `WeChatClient.send_emotion`: method.
|
1224
|
+
- `Literal[WeChatSendEnum.SEND_PAT]`: Send pat message, use `WeChatClient.send_pat`: method.
|
1225
|
+
- `Literal[WeChatSendEnum.SEND_PUBLIC]`: Send public account message, use `WeChatClient.send_public`: method.
|
1226
|
+
- `Literal[WeChatSendEnum.SEND_FORWARD]`: Forward message, use `WeChatClient.send_forward`: method.
|
1227
|
+
receive_id : User ID or chat room ID of receive message.
|
1228
|
+
params : Send parameters.
|
1229
|
+
"""
|
1230
|
+
|
1231
|
+
# Get parameter.
|
1232
|
+
data = {
|
1233
|
+
'status': 0,
|
1234
|
+
'type': send_type,
|
1235
|
+
'receive_id': receive_id,
|
1236
|
+
'parameter': params
|
1237
|
+
}
|
1238
|
+
|
1239
|
+
# Upload file.
|
1240
|
+
if 'file_path' in params:
|
1241
|
+
file_path: str = params.pop('file_path')
|
1242
|
+
if 'file_name' in params:
|
1243
|
+
file_name: str = params.pop('file_name')
|
1244
|
+
else:
|
1245
|
+
file_name = None
|
1246
|
+
file_id = self.rdatabase_file.file.upload(
|
1247
|
+
file_path,
|
1248
|
+
file_name,
|
1249
|
+
'WeChat'
|
1250
|
+
)
|
1251
|
+
else:
|
1252
|
+
file_id = None
|
1253
|
+
data['file_id'] = file_id
|
1254
|
+
|
1255
|
+
# Insert.
|
1256
|
+
self.rdatabase_wechat.execute_insert(
|
1257
|
+
('wechat', 'message_send'),
|
1258
|
+
data
|
1259
|
+
)
|