reywechat 1.0.39__py3-none-any.whl → 1.0.41__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/rdb.py +17 -93
- reywechat/rlog.py +7 -7
- reywechat/rreceive.py +18 -21
- reywechat/rschedule.py +2 -2
- reywechat/rsend.py +233 -99
- reywechat/rwechat.py +2 -2
- {reywechat-1.0.39.dist-info → reywechat-1.0.41.dist-info}/METADATA +1 -1
- reywechat-1.0.41.dist-info/RECORD +17 -0
- reywechat-1.0.39.dist-info/RECORD +0 -17
- {reywechat-1.0.39.dist-info → reywechat-1.0.41.dist-info}/WHEEL +0 -0
- {reywechat-1.0.39.dist-info → reywechat-1.0.41.dist-info}/licenses/LICENSE +0 -0
reywechat/rdb.py
CHANGED
@@ -19,7 +19,7 @@ from reykit.rwrap import wrap_thread
|
|
19
19
|
|
20
20
|
from .rbase import BaseWeChat
|
21
21
|
from .rreceive import WeChatMessage
|
22
|
-
from .rsend import
|
22
|
+
from .rsend import WeChatSendTypeEnum, WeChatSendParameter
|
23
23
|
from .rwechat import WeChat
|
24
24
|
|
25
25
|
|
@@ -280,13 +280,11 @@ class WeChatDatabase(BaseWeChat):
|
|
280
280
|
{
|
281
281
|
'name': 'room_id',
|
282
282
|
'type': 'varchar(31)',
|
283
|
-
'constraint': 'DEFAULT NULL',
|
284
283
|
'comment': 'Message chat room ID, null for private chat.'
|
285
284
|
},
|
286
285
|
{
|
287
286
|
'name': 'user_id',
|
288
287
|
'type': 'varchar(24)',
|
289
|
-
'constraint': 'DEFAULT NULL',
|
290
288
|
'comment': 'Message sender user ID, null for system message.'
|
291
289
|
},
|
292
290
|
{
|
@@ -317,7 +315,6 @@ class WeChatDatabase(BaseWeChat):
|
|
317
315
|
{
|
318
316
|
'name': 'file_id',
|
319
317
|
'type': 'mediumint unsigned',
|
320
|
-
'constraint': 'DEFAULT NULL',
|
321
318
|
'comment': 'Message file ID, from the file database.'
|
322
319
|
}
|
323
320
|
],
|
@@ -364,7 +361,6 @@ class WeChatDatabase(BaseWeChat):
|
|
364
361
|
{
|
365
362
|
'name': 'plan_time',
|
366
363
|
'type': 'datetime',
|
367
|
-
'constraint': 'DEFAULT NULL',
|
368
364
|
'comment': 'Send plan time.'
|
369
365
|
},
|
370
366
|
{
|
@@ -417,7 +413,6 @@ class WeChatDatabase(BaseWeChat):
|
|
417
413
|
{
|
418
414
|
'name': 'file_id',
|
419
415
|
'type': 'mediumint unsigned',
|
420
|
-
'constraint': 'DEFAULT NULL',
|
421
416
|
'comment': 'Send file ID, from the file database.'
|
422
417
|
}
|
423
418
|
],
|
@@ -936,22 +931,26 @@ class WeChatDatabase(BaseWeChat):
|
|
936
931
|
|
937
932
|
|
938
933
|
# Define.
|
939
|
-
def sender_handler_update_send_status(
|
934
|
+
def sender_handler_update_send_status(send_param: WeChatSendParameter) -> None:
|
940
935
|
"""
|
941
936
|
Update field `status` of table `message_send`.
|
942
937
|
|
943
938
|
Parameters
|
944
939
|
----------
|
945
|
-
|
940
|
+
send_param : `WeChatSendParameter` instance.
|
946
941
|
"""
|
947
942
|
|
943
|
+
# Check.
|
944
|
+
if send_param.status == send_param.StatusEnum.AFTER:
|
945
|
+
throw(TypeError, send_param.send_id)
|
946
|
+
|
948
947
|
# Handle parameter.
|
949
|
-
if
|
948
|
+
if send_param.exc_reports == []:
|
950
949
|
status = 2
|
951
950
|
else:
|
952
951
|
status = 3
|
953
952
|
data = {
|
954
|
-
'send_id':
|
953
|
+
'send_id': send_param.send_id,
|
955
954
|
'status': status,
|
956
955
|
'limit': 1
|
957
956
|
}
|
@@ -1055,7 +1054,7 @@ class WeChatDatabase(BaseWeChat):
|
|
1055
1054
|
# Send.
|
1056
1055
|
for row in table:
|
1057
1056
|
send_id, type_, receive_id, parameter, file_id = row.values()
|
1058
|
-
send_type =
|
1057
|
+
send_type = WeChatSendTypeEnum[type_]
|
1059
1058
|
parameter: dict = json_loads(parameter)
|
1060
1059
|
|
1061
1060
|
## File.
|
@@ -1064,14 +1063,14 @@ class WeChatDatabase(BaseWeChat):
|
|
1064
1063
|
parameter['file_path'] = file_path
|
1065
1064
|
parameter['file_name'] = file_name
|
1066
1065
|
|
1067
|
-
|
1066
|
+
send_param = WeChatSendParameter(
|
1068
1067
|
self.wechat.sender,
|
1069
1068
|
send_type,
|
1070
1069
|
receive_id,
|
1071
1070
|
send_id,
|
1072
1071
|
**parameter
|
1073
1072
|
)
|
1074
|
-
self.wechat.sender.queue.put(
|
1073
|
+
self.wechat.sender.queue.put(send_param)
|
1075
1074
|
|
1076
1075
|
# Commit.
|
1077
1076
|
conn.commit()
|
@@ -1146,96 +1145,21 @@ class WeChatDatabase(BaseWeChat):
|
|
1146
1145
|
return judge
|
1147
1146
|
|
1148
1147
|
|
1149
|
-
|
1150
|
-
def send(
|
1151
|
-
self,
|
1152
|
-
send_type: Literal[WeChatSendEnum.SEND_TEXT],
|
1153
|
-
receive_id: str,
|
1154
|
-
*,
|
1155
|
-
text: str
|
1156
|
-
) -> None: ...
|
1157
|
-
|
1158
|
-
@overload
|
1159
|
-
def send(
|
1160
|
-
self,
|
1161
|
-
send_type: Literal[WeChatSendEnum.SEND_TEXT_AT],
|
1162
|
-
receive_id: str,
|
1163
|
-
*,
|
1164
|
-
user_id: str | list[str] | Literal['notify@all'],
|
1165
|
-
text: str
|
1166
|
-
) -> None: ...
|
1167
|
-
|
1168
|
-
@overload
|
1169
|
-
def send(
|
1170
|
-
self,
|
1171
|
-
send_type: Literal[WeChatSendEnum.SEND_FILE, WeChatSendEnum.SEND_IMAGE, WeChatSendEnum.SEND_EMOTION],
|
1172
|
-
receive_id: str,
|
1173
|
-
*,
|
1174
|
-
file_path: str,
|
1175
|
-
file_name: str | None = None
|
1176
|
-
) -> None: ...
|
1177
|
-
|
1178
|
-
@overload
|
1179
|
-
def send(
|
1180
|
-
self,
|
1181
|
-
send_type: Literal[WeChatSendEnum.SEND_PAT],
|
1182
|
-
receive_id: str,
|
1183
|
-
*,
|
1184
|
-
user_id: str
|
1185
|
-
) -> None: ...
|
1186
|
-
|
1187
|
-
@overload
|
1188
|
-
def send(
|
1189
|
-
self,
|
1190
|
-
send_type: Literal[WeChatSendEnum.SEND_PUBLIC],
|
1191
|
-
receive_id: str,
|
1192
|
-
*,
|
1193
|
-
page_url: str,
|
1194
|
-
title: str,
|
1195
|
-
text: str | None = None,
|
1196
|
-
image_url: str | None = None,
|
1197
|
-
public_name: str | None = None,
|
1198
|
-
public_id: str | None = None
|
1199
|
-
) -> None: ...
|
1200
|
-
|
1201
|
-
@overload
|
1202
|
-
def send(
|
1203
|
-
self,
|
1204
|
-
send_type: Literal[WeChatSendEnum.SEND_FORWARD],
|
1205
|
-
receive_id: str,
|
1206
|
-
*,
|
1207
|
-
message_id: str
|
1208
|
-
) -> None: ...
|
1209
|
-
|
1210
|
-
def send(
|
1211
|
-
self,
|
1212
|
-
send_type: WeChatSendEnum,
|
1213
|
-
receive_id: str | None = None,
|
1214
|
-
**params: Any
|
1215
|
-
) -> None:
|
1148
|
+
def insert_send(self, send_param: WeChatSendParameter) -> None:
|
1216
1149
|
"""
|
1217
1150
|
Insert into `wechat.message_send` table of database, wait send.
|
1218
1151
|
|
1219
1152
|
Parameters
|
1220
1153
|
----------
|
1221
|
-
|
1222
|
-
- `Literal[WeChatSendEnum.SEND_TEXT]`: Send text message, use `WeChatClient.send_text`: method.
|
1223
|
-
- `Literal[WeChatSendEnum.SEND_TEXT_AT]`: Send text message with `@`, use `WeChatClient.send_text_at`: method.
|
1224
|
-
- `Literal[WeChatSendEnum.SEND_FILE]`: Send file message, use `WeChatClient.send_file`: method.
|
1225
|
-
- `Literal[WeChatSendEnum.SEND_IMAGE]`: Send image message, use `WeChatClient.send_image`: method.
|
1226
|
-
- `Literal[WeChatSendEnum.SEND_EMOTION]`: Send emotion message, use `WeChatClient.send_emotion`: method.
|
1227
|
-
- `Literal[WeChatSendEnum.SEND_PAT]`: Send pat message, use `WeChatClient.send_pat`: method.
|
1228
|
-
- `Literal[WeChatSendEnum.SEND_PUBLIC]`: Send public account message, use `WeChatClient.send_public`: method.
|
1229
|
-
- `Literal[WeChatSendEnum.SEND_FORWARD]`: Forward message, use `WeChatClient.send_forward`: method.
|
1230
|
-
receive_id : User ID or chat room ID of receive message.
|
1231
|
-
params : Send parameters.
|
1154
|
+
send_param : `WeChatSendParameter` instance.
|
1232
1155
|
"""
|
1233
1156
|
|
1234
1157
|
# Handle parameter.
|
1158
|
+
params = send_param.params.copy()
|
1235
1159
|
data = {
|
1236
1160
|
'status': 0,
|
1237
|
-
'type': send_type,
|
1238
|
-
'receive_id': receive_id,
|
1161
|
+
'type': send_param.send_type,
|
1162
|
+
'receive_id': send_param.receive_id,
|
1239
1163
|
'parameter': params
|
1240
1164
|
}
|
1241
1165
|
|
reywechat/rlog.py
CHANGED
@@ -185,27 +185,27 @@ class WeChatLog(BaseWeChat):
|
|
185
185
|
|
186
186
|
def log_send(
|
187
187
|
self,
|
188
|
-
|
188
|
+
send_param: WeChatSendParameter
|
189
189
|
) -> None:
|
190
190
|
"""
|
191
191
|
Log send message.
|
192
192
|
|
193
193
|
Parameters
|
194
194
|
----------
|
195
|
-
|
195
|
+
send_param : `WeChatSendParameter` instance.
|
196
196
|
"""
|
197
197
|
|
198
198
|
# Generate record.
|
199
|
-
content_print = 'SEND | %-20s' %
|
199
|
+
content_print = 'SEND | %-20s' % send_param.receive_id
|
200
200
|
content_file = 'SEND | %s' % {
|
201
|
-
'receive_id':
|
202
|
-
**
|
201
|
+
'receive_id': send_param.receive_id,
|
202
|
+
**send_param.params
|
203
203
|
}
|
204
|
-
if
|
204
|
+
if send_param.exc_reports == []:
|
205
205
|
level = self.rrlog.INFO
|
206
206
|
else:
|
207
207
|
level = self.rrlog.ERROR
|
208
|
-
exc_report = '\n'.join(
|
208
|
+
exc_report = '\n'.join(send_param.exc_reports)
|
209
209
|
content_print = '%s\n%s' % (content_print, exc_report)
|
210
210
|
content_file = '%s\n%s' % (content_file, exc_report)
|
211
211
|
|
reywechat/rreceive.py
CHANGED
@@ -26,7 +26,7 @@ from reykit.rtime import sleep, wait
|
|
26
26
|
from reykit.rwrap import wrap_thread, wrap_exc
|
27
27
|
|
28
28
|
from .rbase import BaseWeChat, WeChatTriggerError
|
29
|
-
from .rsend import
|
29
|
+
from .rsend import WeChatSendTypeEnum
|
30
30
|
from .rwechat import WeChat
|
31
31
|
|
32
32
|
|
@@ -66,7 +66,7 @@ class WeChatMessage(BaseWeChat):
|
|
66
66
|
WeChat message type.
|
67
67
|
"""
|
68
68
|
|
69
|
-
|
69
|
+
TypeEnum = WeChatSendTypeEnum
|
70
70
|
|
71
71
|
|
72
72
|
def __init__(
|
@@ -935,7 +935,7 @@ class WeChatMessage(BaseWeChat):
|
|
935
935
|
@overload
|
936
936
|
def reply(
|
937
937
|
self,
|
938
|
-
send_type: Literal[
|
938
|
+
send_type: Literal[WeChatSendTypeEnum.TEXT],
|
939
939
|
*,
|
940
940
|
text: str
|
941
941
|
) -> None: ...
|
@@ -943,7 +943,7 @@ class WeChatMessage(BaseWeChat):
|
|
943
943
|
@overload
|
944
944
|
def reply(
|
945
945
|
self,
|
946
|
-
send_type: Literal[
|
946
|
+
send_type: Literal[WeChatSendTypeEnum.TEXT_AT],
|
947
947
|
*,
|
948
948
|
user_id: str | list[str] | Literal['notify@all'],
|
949
949
|
text: str
|
@@ -952,7 +952,7 @@ class WeChatMessage(BaseWeChat):
|
|
952
952
|
@overload
|
953
953
|
def reply(
|
954
954
|
self,
|
955
|
-
send_type: Literal[
|
955
|
+
send_type: Literal[WeChatSendTypeEnum.FILE, WeChatSendTypeEnum.IMAGE, WeChatSendTypeEnum.EMOTION],
|
956
956
|
*,
|
957
957
|
path: str,
|
958
958
|
file_name: str | None = None
|
@@ -961,7 +961,7 @@ class WeChatMessage(BaseWeChat):
|
|
961
961
|
@overload
|
962
962
|
def reply(
|
963
963
|
self,
|
964
|
-
send_type: Literal[
|
964
|
+
send_type: Literal[WeChatSendTypeEnum.PAT],
|
965
965
|
*,
|
966
966
|
user_id: str
|
967
967
|
) -> None: ...
|
@@ -969,7 +969,7 @@ class WeChatMessage(BaseWeChat):
|
|
969
969
|
@overload
|
970
970
|
def reply(
|
971
971
|
self,
|
972
|
-
send_type: Literal[
|
972
|
+
send_type: Literal[WeChatSendTypeEnum.PUBLIC],
|
973
973
|
*,
|
974
974
|
page_url: str,
|
975
975
|
title: str,
|
@@ -982,14 +982,14 @@ class WeChatMessage(BaseWeChat):
|
|
982
982
|
@overload
|
983
983
|
def reply(
|
984
984
|
self,
|
985
|
-
send_type: Literal[
|
985
|
+
send_type: Literal[WeChatSendTypeEnum.FORWARD],
|
986
986
|
*,
|
987
987
|
message_id: str
|
988
988
|
) -> None: ...
|
989
989
|
|
990
990
|
def reply(
|
991
991
|
self,
|
992
|
-
send_type:
|
992
|
+
send_type: WeChatSendTypeEnum,
|
993
993
|
**params: Any
|
994
994
|
) -> None:
|
995
995
|
"""
|
@@ -998,18 +998,15 @@ class WeChatMessage(BaseWeChat):
|
|
998
998
|
Parameters
|
999
999
|
----------
|
1000
1000
|
send_type : Send type.
|
1001
|
-
- `Literal[
|
1002
|
-
- `Literal[
|
1003
|
-
- `Literal[
|
1004
|
-
- `Literal[
|
1005
|
-
- `Literal[
|
1006
|
-
- `Literal[
|
1007
|
-
- `Literal[
|
1008
|
-
- `Literal[
|
1001
|
+
- `Literal[WeChatSendTypeEnum.TEXT]`: Send text message, use `WeChatClient.send_text`: method.
|
1002
|
+
- `Literal[WeChatSendTypeEnum.TEXT_AT]`: Send text message with `@`, use `WeChatClient.send_text_at`: method.
|
1003
|
+
- `Literal[WeChatSendTypeEnum.FILE]`: Send file message, use `WeChatClient.send_file`: method.
|
1004
|
+
- `Literal[WeChatSendTypeEnum.IMAGE]`: Send image message, use `WeChatClient.send_image`: method.
|
1005
|
+
- `Literal[WeChatSendTypeEnum.EMOTION]`: Send emotion message, use `WeChatClient.send_emotion`: method.
|
1006
|
+
- `Literal[WeChatSendTypeEnum.PAT]`: Send pat message, use `WeChatClient.send_pat`: method.
|
1007
|
+
- `Literal[WeChatSendTypeEnum.PUBLIC]`: Send public account message, use `WeChatClient.send_public`: method.
|
1008
|
+
- `Literal[WeChatSendTypeEnum.FORWARD]`: Forward message, use `WeChatClient.send_forward`: method.
|
1009
1009
|
params : Send parameters.
|
1010
|
-
- `Callable`: Use execute return value.
|
1011
|
-
- `Any`: Use this value.
|
1012
|
-
`Key 'file_name'`: Given file name.
|
1013
1010
|
"""
|
1014
1011
|
|
1015
1012
|
# Check.
|
@@ -1036,7 +1033,7 @@ class WechatReceiver(BaseWeChat):
|
|
1036
1033
|
WeChat receiver type.
|
1037
1034
|
"""
|
1038
1035
|
|
1039
|
-
|
1036
|
+
TypeEnum = WeChatSendTypeEnum
|
1040
1037
|
|
1041
1038
|
|
1042
1039
|
def __init__(
|
reywechat/rschedule.py
CHANGED
@@ -15,7 +15,7 @@ from collections.abc import Callable
|
|
15
15
|
from reykit.rschedule import Schedule
|
16
16
|
|
17
17
|
from .rbase import BaseWeChat
|
18
|
-
from .rsend import
|
18
|
+
from .rsend import WeChatSendTypeEnum
|
19
19
|
from .rwechat import WeChat
|
20
20
|
|
21
21
|
|
@@ -24,7 +24,7 @@ class WeChatSchedule(BaseWeChat):
|
|
24
24
|
WeChat schedule type.
|
25
25
|
"""
|
26
26
|
|
27
|
-
|
27
|
+
TypeEnum = WeChatSendTypeEnum
|
28
28
|
|
29
29
|
|
30
30
|
def __init__(
|
reywechat/rsend.py
CHANGED
@@ -17,6 +17,7 @@ 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
|
20
21
|
from reykit.rre import sub
|
21
22
|
from reykit.rtime import sleep
|
22
23
|
from reykit.rwrap import wrap_thread, wrap_exc
|
@@ -26,36 +27,52 @@ from .rwechat import WeChat
|
|
26
27
|
|
27
28
|
|
28
29
|
__all__ = (
|
29
|
-
'
|
30
|
+
'WeChatSendTypeEnum',
|
30
31
|
'WeChatSendParameter',
|
31
32
|
'WeChatSender'
|
32
33
|
)
|
33
34
|
|
34
35
|
|
35
|
-
class
|
36
|
+
class WeChatSendTypeEnum(BaseWeChat, IntEnum):
|
36
37
|
"""
|
37
|
-
WeChat send enumeration type.
|
38
|
+
WeChat send type enumeration type.
|
38
39
|
|
39
40
|
Attributes
|
40
41
|
----------
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
42
|
+
TEXT : Send text message.
|
43
|
+
TEXT_AT : Send text message with @.
|
44
|
+
FILE : Send file message.
|
45
|
+
IMAGE : Send image message.
|
46
|
+
EMOTION : Send emotion message.
|
47
|
+
PAT : Send pat message.
|
48
|
+
PUBLIC : Send public account message.
|
49
|
+
FORWARD : Forward message.
|
49
50
|
"""
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
52
|
+
TEXT = 0
|
53
|
+
TEXT_AT = 1
|
54
|
+
FILE = 2
|
55
|
+
IMAGE = 3
|
56
|
+
EMOTION = 4
|
57
|
+
PAT = 5
|
58
|
+
PUBLIC = 6
|
59
|
+
FORWARD = 7
|
60
|
+
|
61
|
+
|
62
|
+
class WeChatSendStatusEnum(BaseWeChat, IntEnum):
|
63
|
+
"""
|
64
|
+
WeChat send status enumeration type.
|
65
|
+
|
66
|
+
Attributes
|
67
|
+
----------
|
68
|
+
INIT : The moment initializing before insert database queue.
|
69
|
+
BEFORE : The moment before send.
|
70
|
+
AFTER : The moment after send.
|
71
|
+
"""
|
72
|
+
|
73
|
+
INIT = 0
|
74
|
+
BEFORE = 1
|
75
|
+
AFTER = 2
|
59
76
|
|
60
77
|
|
61
78
|
class WeChatSendParameter(BaseWeChat):
|
@@ -63,16 +80,17 @@ class WeChatSendParameter(BaseWeChat):
|
|
63
80
|
WeChat send parameters type.
|
64
81
|
"""
|
65
82
|
|
66
|
-
|
83
|
+
TypeEnum = WeChatSendTypeEnum
|
84
|
+
StatusEnum = WeChatSendStatusEnum
|
67
85
|
|
68
86
|
|
69
87
|
@overload
|
70
88
|
def __init__(
|
71
89
|
self,
|
72
90
|
sender: WeChatSender,
|
73
|
-
send_type: Literal[
|
91
|
+
send_type: Literal[WeChatSendTypeEnum.TEXT],
|
74
92
|
receive_id: str,
|
75
|
-
send_id: int,
|
93
|
+
send_id: int | None = None,
|
76
94
|
*,
|
77
95
|
text: str
|
78
96
|
) -> None: ...
|
@@ -81,9 +99,9 @@ class WeChatSendParameter(BaseWeChat):
|
|
81
99
|
def __init__(
|
82
100
|
self,
|
83
101
|
sender: WeChatSender,
|
84
|
-
send_type: Literal[
|
102
|
+
send_type: Literal[WeChatSendTypeEnum.TEXT_AT],
|
85
103
|
receive_id: str,
|
86
|
-
send_id: int,
|
104
|
+
send_id: int | None = None,
|
87
105
|
*,
|
88
106
|
user_id: str | list[str] | Literal['notify@all'],
|
89
107
|
text: str
|
@@ -93,9 +111,9 @@ class WeChatSendParameter(BaseWeChat):
|
|
93
111
|
def __init__(
|
94
112
|
self,
|
95
113
|
sender: WeChatSender,
|
96
|
-
send_type: Literal[
|
114
|
+
send_type: Literal[WeChatSendTypeEnum.FILE, WeChatSendTypeEnum.IMAGE, WeChatSendTypeEnum.EMOTION],
|
97
115
|
receive_id: str,
|
98
|
-
send_id: int,
|
116
|
+
send_id: int | None = None,
|
99
117
|
*,
|
100
118
|
file_path: str,
|
101
119
|
file_name: str
|
@@ -105,9 +123,9 @@ class WeChatSendParameter(BaseWeChat):
|
|
105
123
|
def __init__(
|
106
124
|
self,
|
107
125
|
sender: WeChatSender,
|
108
|
-
send_type: Literal[
|
126
|
+
send_type: Literal[WeChatSendTypeEnum.PAT],
|
109
127
|
receive_id: str,
|
110
|
-
send_id: int,
|
128
|
+
send_id: int | None = None,
|
111
129
|
*,
|
112
130
|
user_id: str
|
113
131
|
) -> None: ...
|
@@ -116,9 +134,9 @@ class WeChatSendParameter(BaseWeChat):
|
|
116
134
|
def __init__(
|
117
135
|
self,
|
118
136
|
sender: WeChatSender,
|
119
|
-
send_type: Literal[
|
137
|
+
send_type: Literal[WeChatSendTypeEnum.PUBLIC],
|
120
138
|
receive_id: str,
|
121
|
-
send_id: int,
|
139
|
+
send_id: int | None = None,
|
122
140
|
*,
|
123
141
|
page_url: str,
|
124
142
|
title: str,
|
@@ -132,9 +150,9 @@ class WeChatSendParameter(BaseWeChat):
|
|
132
150
|
def __init__(
|
133
151
|
self,
|
134
152
|
sender: WeChatSender,
|
135
|
-
send_type: Literal[
|
153
|
+
send_type: Literal[WeChatSendTypeEnum.FORWARD],
|
136
154
|
receive_id: str,
|
137
|
-
send_id: int,
|
155
|
+
send_id: int | None = None,
|
138
156
|
*,
|
139
157
|
message_id: str
|
140
158
|
) -> None: ...
|
@@ -142,9 +160,9 @@ class WeChatSendParameter(BaseWeChat):
|
|
142
160
|
def __init__(
|
143
161
|
self,
|
144
162
|
sender: WeChatSender,
|
145
|
-
send_type:
|
163
|
+
send_type: WeChatSendTypeEnum,
|
146
164
|
receive_id: str,
|
147
|
-
send_id: int,
|
165
|
+
send_id: int | None = None,
|
148
166
|
**params: Any
|
149
167
|
) -> None:
|
150
168
|
"""
|
@@ -154,16 +172,17 @@ class WeChatSendParameter(BaseWeChat):
|
|
154
172
|
----------
|
155
173
|
sender : `WeChatSender` instance.
|
156
174
|
send_type : Send type.
|
157
|
-
- `Literal[
|
158
|
-
- `Literal[
|
159
|
-
- `Literal[
|
160
|
-
- `Literal[
|
161
|
-
- `Literal[
|
162
|
-
- `Literal[
|
163
|
-
- `Literal[
|
164
|
-
- `Literal[
|
175
|
+
- `Literal[WeChatSendTypeEnum.TEXT]`: Send text message, use `WeChatClient.send_text`: method.
|
176
|
+
- `Literal[WeChatSendTypeEnum.TEXT_AT]`: Send text message with `@`, use `WeChatClient.send_text_at`: method.
|
177
|
+
- `Literal[WeChatSendTypeEnum.FILE]`: Send file message, use `WeChatClient.send_file`: method.
|
178
|
+
- `Literal[WeChatSendTypeEnum.IMAGE]`: Send image message, use `WeChatClient.send_image`: method.
|
179
|
+
- `Literal[WeChatSendTypeEnum.EMOTION]`: Send emotion message, use `WeChatClient.send_emotion`: method.
|
180
|
+
- `Literal[WeChatSendTypeEnum.PAT]`: Send pat message, use `WeChatClient.send_pat`: method.
|
181
|
+
- `Literal[WeChatSendTypeEnum.PUBLIC]`: Send public account message, use `WeChatClient.send_public`: method.
|
182
|
+
- `Literal[WeChatSendTypeEnum.FORWARD]`: Forward message, use `WeChatClient.send_forward`: method.
|
165
183
|
receive_id : User ID or chat room ID of receive message.
|
166
184
|
send_id : Send ID of database.
|
185
|
+
- `None`: Not inserted into database.
|
167
186
|
params : Send parameters.
|
168
187
|
"""
|
169
188
|
|
@@ -177,16 +196,37 @@ class WeChatSendParameter(BaseWeChat):
|
|
177
196
|
self.sent: bool = False
|
178
197
|
|
179
198
|
|
199
|
+
@property
|
200
|
+
def status(self) -> WeChatSendStatusEnum:
|
201
|
+
"""
|
202
|
+
WeChat send status.
|
203
|
+
|
204
|
+
Returns
|
205
|
+
-------
|
206
|
+
WeChat send parameters status enumeration.
|
207
|
+
"""
|
208
|
+
|
209
|
+
# Get.
|
210
|
+
if self.send_id is None:
|
211
|
+
status = WeChatSendStatusEnum.INIT
|
212
|
+
elif self.sent:
|
213
|
+
status = WeChatSendStatusEnum.AFTER
|
214
|
+
else:
|
215
|
+
status = WeChatSendStatusEnum.BEFORE
|
216
|
+
|
217
|
+
return status
|
218
|
+
|
219
|
+
|
180
220
|
class WeChatSender(BaseWeChat):
|
181
221
|
"""
|
182
222
|
WeChat sender type.
|
183
223
|
|
184
224
|
Attribute
|
185
225
|
---------
|
186
|
-
|
226
|
+
WeChatSendTypeEnum : Send type enumeration.
|
187
227
|
"""
|
188
228
|
|
189
|
-
|
229
|
+
TypeEnum = WeChatSendTypeEnum
|
190
230
|
|
191
231
|
|
192
232
|
def __init__(self, wechat: WeChat) -> None:
|
@@ -215,20 +255,6 @@ class WeChatSender(BaseWeChat):
|
|
215
255
|
"""
|
216
256
|
|
217
257
|
|
218
|
-
# Define.
|
219
|
-
def handle_handler_exception(exc_report, *_) -> None:
|
220
|
-
"""
|
221
|
-
Handle Handler exception.
|
222
|
-
|
223
|
-
Parameters
|
224
|
-
----------
|
225
|
-
exc_report : Exception report text.
|
226
|
-
"""
|
227
|
-
|
228
|
-
# Save.
|
229
|
-
sendparam.exc_reports.append(exc_report)
|
230
|
-
|
231
|
-
|
232
258
|
# Loop.
|
233
259
|
while True:
|
234
260
|
match self.started:
|
@@ -242,16 +268,17 @@ class WeChatSender(BaseWeChat):
|
|
242
268
|
case None:
|
243
269
|
break
|
244
270
|
|
245
|
-
|
271
|
+
send_param = self.queue.get()
|
272
|
+
handle_handler_exception = lambda exc_report, *_: send_param.exc_reports.append(exc_report)
|
246
273
|
|
247
274
|
## Handler.
|
248
275
|
for handler in self.handlers:
|
249
276
|
handler = wrap_exc(handler, handler=handle_handler_exception)
|
250
|
-
handler(
|
277
|
+
handler(send_param)
|
251
278
|
|
252
279
|
## Send.
|
253
280
|
try:
|
254
|
-
self.__send(
|
281
|
+
self.__send(send_param)
|
255
282
|
|
256
283
|
## Exception.
|
257
284
|
except:
|
@@ -260,94 +287,94 @@ class WeChatSender(BaseWeChat):
|
|
260
287
|
exc_report, *_ = catch_exc()
|
261
288
|
|
262
289
|
# Save.
|
263
|
-
|
290
|
+
send_param.exc_reports.append(exc_report)
|
264
291
|
|
265
|
-
|
292
|
+
send_param.sent = True
|
266
293
|
|
267
294
|
## Handler.
|
268
295
|
for handler in self.handlers:
|
269
296
|
handler = wrap_exc(handler, handler=handle_handler_exception)
|
270
|
-
handler(
|
297
|
+
handler(send_param)
|
271
298
|
|
272
299
|
## Log.
|
273
|
-
self.wechat.log.log_send(
|
300
|
+
self.wechat.log.log_send(send_param)
|
274
301
|
|
275
302
|
|
276
303
|
def __send(
|
277
304
|
self,
|
278
|
-
|
305
|
+
send_param: WeChatSendParameter
|
279
306
|
) -> None:
|
280
307
|
"""
|
281
308
|
Send message.
|
282
309
|
|
283
310
|
Parameters
|
284
311
|
----------
|
285
|
-
|
312
|
+
send_param : `WeChatSendParameter` instance.
|
286
313
|
"""
|
287
314
|
|
288
315
|
# Send.
|
289
|
-
match
|
316
|
+
match send_param.send_type:
|
290
317
|
|
291
318
|
## Text.
|
292
|
-
case
|
319
|
+
case WeChatSendTypeEnum.TEXT:
|
293
320
|
self.wechat.client.send_text(
|
294
|
-
|
295
|
-
|
321
|
+
send_param.receive_id,
|
322
|
+
send_param.params['text']
|
296
323
|
)
|
297
324
|
|
298
325
|
## Text with '@'.
|
299
|
-
case
|
326
|
+
case WeChatSendTypeEnum.TEXT_AT:
|
300
327
|
self.wechat.client.send_text_at(
|
301
|
-
|
302
|
-
|
303
|
-
|
328
|
+
send_param.receive_id,
|
329
|
+
send_param.params['user_id'],
|
330
|
+
send_param.params['text']
|
304
331
|
)
|
305
332
|
|
306
333
|
## File.
|
307
|
-
case
|
334
|
+
case WeChatSendTypeEnum.FILE:
|
308
335
|
self.wechat.client.send_file(
|
309
|
-
|
310
|
-
|
336
|
+
send_param.receive_id,
|
337
|
+
send_param.params['file_path']
|
311
338
|
)
|
312
339
|
|
313
340
|
## Image.
|
314
|
-
case
|
341
|
+
case WeChatSendTypeEnum.IMAGE:
|
315
342
|
self.wechat.client.send_image(
|
316
|
-
|
317
|
-
|
343
|
+
send_param.receive_id,
|
344
|
+
send_param.params['file_path']
|
318
345
|
)
|
319
346
|
|
320
347
|
## Emotion.
|
321
|
-
case
|
348
|
+
case WeChatSendTypeEnum.EMOTION:
|
322
349
|
self.wechat.client.send_emotion(
|
323
|
-
|
324
|
-
|
350
|
+
send_param.receive_id,
|
351
|
+
send_param.params['file_path']
|
325
352
|
)
|
326
353
|
|
327
354
|
## Pat.
|
328
|
-
case
|
355
|
+
case WeChatSendTypeEnum.PAT:
|
329
356
|
self.wechat.client.send_pat(
|
330
|
-
|
331
|
-
|
357
|
+
send_param.receive_id,
|
358
|
+
send_param.params['user_id']
|
332
359
|
)
|
333
360
|
|
334
361
|
## Public account.
|
335
|
-
case
|
362
|
+
case WeChatSendTypeEnum.PUBLIC:
|
336
363
|
self.wechat.client.send_public(
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
364
|
+
send_param.receive_id,
|
365
|
+
send_param.params['page_url'],
|
366
|
+
send_param.params['title'],
|
367
|
+
send_param.params['text'],
|
368
|
+
send_param.params['image_url'],
|
369
|
+
send_param.params['public_name'],
|
370
|
+
send_param.params['public_id']
|
344
371
|
)
|
345
372
|
|
346
373
|
## Forward.
|
347
|
-
case
|
374
|
+
case WeChatSendTypeEnum.FORWARD:
|
348
375
|
self.wechat.client.send_forward(
|
349
|
-
|
350
|
-
|
376
|
+
send_param.receive_id,
|
377
|
+
send_param.params['message_id']
|
351
378
|
)
|
352
379
|
|
353
380
|
## Throw exception.
|
@@ -355,12 +382,119 @@ class WeChatSender(BaseWeChat):
|
|
355
382
|
throw(ValueError, send_type)
|
356
383
|
|
357
384
|
|
385
|
+
@overload
|
386
|
+
def send(
|
387
|
+
self,
|
388
|
+
send_type: Literal[WeChatSendTypeEnum.TEXT],
|
389
|
+
receive_id: str,
|
390
|
+
*,
|
391
|
+
text: str
|
392
|
+
) -> None: ...
|
393
|
+
|
394
|
+
@overload
|
395
|
+
def send(
|
396
|
+
self,
|
397
|
+
send_type: Literal[WeChatSendTypeEnum.TEXT_AT],
|
398
|
+
receive_id: str,
|
399
|
+
*,
|
400
|
+
user_id: str | list[str] | Literal['notify@all'],
|
401
|
+
text: str
|
402
|
+
) -> None: ...
|
403
|
+
|
404
|
+
@overload
|
405
|
+
def send(
|
406
|
+
self,
|
407
|
+
send_type: Literal[WeChatSendTypeEnum.FILE, WeChatSendTypeEnum.IMAGE, WeChatSendTypeEnum.EMOTION],
|
408
|
+
receive_id: str,
|
409
|
+
*,
|
410
|
+
file_path: str,
|
411
|
+
file_name: str | None = None
|
412
|
+
) -> None: ...
|
413
|
+
|
414
|
+
@overload
|
415
|
+
def send(
|
416
|
+
self,
|
417
|
+
send_type: Literal[WeChatSendTypeEnum.PAT],
|
418
|
+
receive_id: str,
|
419
|
+
*,
|
420
|
+
user_id: str
|
421
|
+
) -> None: ...
|
422
|
+
|
423
|
+
@overload
|
424
|
+
def send(
|
425
|
+
self,
|
426
|
+
send_type: Literal[WeChatSendTypeEnum.PUBLIC],
|
427
|
+
receive_id: str,
|
428
|
+
*,
|
429
|
+
page_url: str,
|
430
|
+
title: str,
|
431
|
+
text: str | None = None,
|
432
|
+
image_url: str | None = None,
|
433
|
+
public_name: str | None = None,
|
434
|
+
public_id: str | None = None
|
435
|
+
) -> None: ...
|
436
|
+
|
437
|
+
@overload
|
438
|
+
def send(
|
439
|
+
self,
|
440
|
+
send_type: Literal[WeChatSendTypeEnum.FORWARD],
|
441
|
+
receive_id: str,
|
442
|
+
*,
|
443
|
+
message_id: str
|
444
|
+
) -> None: ...
|
445
|
+
|
446
|
+
def send(
|
447
|
+
self,
|
448
|
+
send_type: WeChatSendTypeEnum,
|
449
|
+
receive_id: str | None = None,
|
450
|
+
**params: Any
|
451
|
+
) -> None:
|
452
|
+
"""
|
453
|
+
Insert into `wechat.message_send` table of database, wait send.
|
454
|
+
|
455
|
+
Parameters
|
456
|
+
----------
|
457
|
+
send_type : Send type.
|
458
|
+
- `Literal[WeChatSendTypeEnum.TEXT]`: Send text message, use `WeChatClient.send_text`: method.
|
459
|
+
- `Literal[WeChatSendTypeEnum.TEXT_AT]`: Send text message with `@`, use `WeChatClient.send_text_at`: method.
|
460
|
+
- `Literal[WeChatSendTypeEnum.FILE]`: Send file message, use `WeChatClient.send_file`: method.
|
461
|
+
- `Literal[WeChatSendTypeEnum.IMAGE]`: Send image message, use `WeChatClient.send_image`: method.
|
462
|
+
- `Literal[WeChatSendTypeEnum.EMOTION]`: Send emotion message, use `WeChatClient.send_emotion`: method.
|
463
|
+
- `Literal[WeChatSendTypeEnum.PAT]`: Send pat message, use `WeChatClient.send_pat`: method.
|
464
|
+
- `Literal[WeChatSendTypeEnum.PUBLIC]`: Send public account message, use `WeChatClient.send_public`: method.
|
465
|
+
- `Literal[WeChatSendTypeEnum.FORWARD]`: Forward message, use `WeChatClient.send_forward`: method.
|
466
|
+
receive_id : User ID or chat room ID of receive message.
|
467
|
+
params : Send parameters.
|
468
|
+
"""
|
469
|
+
|
470
|
+
# Handle parameter.
|
471
|
+
send_param = WeChatSendParameter(
|
472
|
+
self,
|
473
|
+
WeChatSendTypeEnum[send_type],
|
474
|
+
receive_id,
|
475
|
+
**params
|
476
|
+
)
|
477
|
+
handle_handler_exception = lambda exc_report, *_: send_param.exc_reports.append(exc_report)
|
478
|
+
|
479
|
+
# Handler.
|
480
|
+
for handler in self.handlers:
|
481
|
+
handler = wrap_exc(handler, handler=handle_handler_exception)
|
482
|
+
handler(send_param)
|
483
|
+
|
484
|
+
# Insert.
|
485
|
+
self.wechat.database.insert_send(send_param)
|
486
|
+
|
487
|
+
|
358
488
|
def add_handler(
|
359
489
|
self,
|
360
490
|
handler: Callable[[WeChatSendParameter], Any]
|
361
491
|
) -> None:
|
362
492
|
"""
|
363
493
|
Add send handler function.
|
494
|
+
Call at the moment initializing before insert database queue.
|
495
|
+
Call at the moment before sending.
|
496
|
+
Call at the moment after sending.
|
497
|
+
Can be use `WeChatSendParameter.status` judge status.
|
364
498
|
|
365
499
|
Parameters
|
366
500
|
----------
|
@@ -475,7 +609,7 @@ class WeChatSender(BaseWeChat):
|
|
475
609
|
)
|
476
610
|
for receive_id in receive_ids:
|
477
611
|
self.send(
|
478
|
-
|
612
|
+
WeChatSendTypeEnum.TEXT,
|
479
613
|
receive_id,
|
480
614
|
text=text
|
481
615
|
)
|
reywechat/rwechat.py
CHANGED
@@ -103,13 +103,13 @@ class WeChat(BaseWeChat):
|
|
103
103
|
|
104
104
|
## Send.
|
105
105
|
self.send_add_handler = self.sender.add_handler
|
106
|
-
self.send = self.database.
|
106
|
+
self.send = self.database.insert_send
|
107
107
|
self.send_start = self.sender.start
|
108
108
|
self.send_stop = self.sender.stop
|
109
109
|
self.wrap_try_send = self.sender.wrap_try_send
|
110
110
|
|
111
111
|
## Database.
|
112
|
-
self.send = self.sender.send = self.database.
|
112
|
+
self.send = self.sender.send = self.database.insert_send
|
113
113
|
self.database_build = self.database.build
|
114
114
|
|
115
115
|
## Schedule.
|
@@ -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=MEvQB3pHb5ORukKbKntalRtFcKIOP9BGtDsMt5ihQfM,22524
|
6
|
+
reywechat/rdb.py,sha256=7h6B9cWQ9dFDiFGEouAvcCAwXn1EBdGVlhxH-NLqhEI,39639
|
7
|
+
reywechat/rlog.py,sha256=IJL2WquiOYfB9iEai9xjojkuxPxiRHkdzZ5vCeaSA98,5261
|
8
|
+
reywechat/rreceive.py,sha256=40l3n_d1BcT2EhxIYOlOnzrSQkJ8WDI_qPvJcU7CSQU,35018
|
9
|
+
reywechat/rschedule.py,sha256=X9kreXdClTeItJHmNPJNqb_lct-BiLCyusMQxsj5hWU,1865
|
10
|
+
reywechat/rsend.py,sha256=lkI3FMrQd-yG2rvx4SgxuJiZgjJCVcrr6G375PjXixQ,17984
|
11
|
+
reywechat/rtrigger.py,sha256=n8kUNovh62r7crlXrp33uaKvbILT-wcfvUqeyGt7YhM,4956
|
12
|
+
reywechat/rwechat.py,sha256=kKQnvNTddzaYh9C9v_ujETuMP3-eMhra90jxI2RduRI,4949
|
13
|
+
reywechat/data/client_api.dll,sha256=H9uj-x9Ztg0jFZK0yY6NsnyH5_119dQRFfoVVMidxRs,592384
|
14
|
+
reywechat-1.0.41.dist-info/METADATA,sha256=LoO8NvZIe4Ep8LbRoajePi_uGhtz-dsX6u07sVpw7pw,1551
|
15
|
+
reywechat-1.0.41.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
16
|
+
reywechat-1.0.41.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
17
|
+
reywechat-1.0.41.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=1l7BGx-WC_DdDDAJrI-EsHUbdLApaQWGrxqAyggYXIA,42187
|
7
|
-
reywechat/rlog.py,sha256=x4WFLNoeKqGjPVoI81ZZNEd9ctdYToSg5hEFuESmCQY,5254
|
8
|
-
reywechat/rreceive.py,sha256=RkUwPsWz6k_Ua3ovrbXRMVajeNOJQqvpPXz_CvJyUPQ,35162
|
9
|
-
reywechat/rschedule.py,sha256=bZEEZV3K4zrJvupe1Eq6kGR7kunbVq5dfGnqFKYF3JI,1857
|
10
|
-
reywechat/rsend.py,sha256=UmdKCOb1cPKEmBPHt9htjxB8fPyi5jW5pGwpRQIZdKA,13720
|
11
|
-
reywechat/rtrigger.py,sha256=n8kUNovh62r7crlXrp33uaKvbILT-wcfvUqeyGt7YhM,4956
|
12
|
-
reywechat/rwechat.py,sha256=xkHQUUXDEqq4Q_DHF6vc3Dd33A8oOCkKyJN7v7p2leM,4935
|
13
|
-
reywechat/data/client_api.dll,sha256=H9uj-x9Ztg0jFZK0yY6NsnyH5_119dQRFfoVVMidxRs,592384
|
14
|
-
reywechat-1.0.39.dist-info/METADATA,sha256=YpRoJrcy0zs50O7BQKnVt9ukABoVK2APC2akitEv5AA,1551
|
15
|
-
reywechat-1.0.39.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
16
|
-
reywechat-1.0.39.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
17
|
-
reywechat-1.0.39.dist-info/RECORD,,
|
File without changes
|
File without changes
|