reywechat 1.0.80__py3-none-any.whl → 1.0.81__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 +252 -522
- reywechat/rreceive.py +1 -1
- reywechat/rsend.py +1 -1
- reywechat/rwechat.py +4 -4
- {reywechat-1.0.80.dist-info → reywechat-1.0.81.dist-info}/METADATA +1 -1
- {reywechat-1.0.80.dist-info → reywechat-1.0.81.dist-info}/RECORD +8 -8
- {reywechat-1.0.80.dist-info → reywechat-1.0.81.dist-info}/WHEEL +0 -0
- {reywechat-1.0.80.dist-info → reywechat-1.0.81.dist-info}/licenses/LICENSE +0 -0
reywechat/rdb.py
CHANGED
@@ -12,6 +12,7 @@
|
|
12
12
|
from typing import Literal
|
13
13
|
from json import loads as json_loads
|
14
14
|
from reydb.rdb import Database
|
15
|
+
from reydb import rorm
|
15
16
|
from reykit.rbase import throw
|
16
17
|
from reykit.ros import File
|
17
18
|
from reykit.rtime import to_time, time_to, sleep
|
@@ -24,21 +25,179 @@ from .rwechat import WeChat
|
|
24
25
|
|
25
26
|
|
26
27
|
__all__ = (
|
27
|
-
'
|
28
|
+
'DatabaseTableContactUser',
|
29
|
+
'DatabaseTableContactRoom',
|
30
|
+
'DatabaseTableContactRoomUser',
|
31
|
+
'DatabaseTableMessageReceive',
|
32
|
+
'DatabaseTableMessageSend',
|
33
|
+
'WeChatDatabase'
|
28
34
|
)
|
29
35
|
|
30
36
|
|
37
|
+
class DatabaseTableContactUser(rorm.Model, table=True):
|
38
|
+
"""
|
39
|
+
Database `contact_user` table model.
|
40
|
+
"""
|
41
|
+
|
42
|
+
__comment__ = 'User contact table.'
|
43
|
+
create_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', not_null=True, index_n=True, comment='Record create time.')
|
44
|
+
update_time: rorm.Datetime = rorm.Field(field_default='ON UPDATE CURRENT_TIMESTAMP', index_n=True, comment='Record update time.')
|
45
|
+
user_id: str = rorm.Field(field_type=rorm.types.VARCHAR(24), key=True, comment='User ID.')
|
46
|
+
name: str = rorm.Field(field_type=rorm.types.VARCHAR(32), comment='User name.')
|
47
|
+
contact: int = rorm.Field(field_type=rorm.types_mysql.TINYINT(unsigned=True), field_default='1', not_null=True, comment='Is the contact, 0 is no contact, 1 is contact.')
|
48
|
+
valid: int = rorm.Field(field_type=rorm.types_mysql.TINYINT(unsigned=True), field_default='1', not_null=True, comment='Is the valid, 0 is invalid, 1 is valid.')
|
49
|
+
|
50
|
+
|
51
|
+
class DatabaseTableContactRoom(rorm.Model, table=True):
|
52
|
+
"""
|
53
|
+
Database `contact_room` table model.
|
54
|
+
"""
|
55
|
+
|
56
|
+
__comment__ = 'Chat room contact table.'
|
57
|
+
create_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', not_null=True, index_n=True, comment='Record create time.')
|
58
|
+
update_time: rorm.Datetime = rorm.Field(field_default='ON UPDATE CURRENT_TIMESTAMP', index_n=True, comment='Record update time.')
|
59
|
+
room_id: str = rorm.Field(field_type=rorm.types.VARCHAR(31), key=True, comment='Chat room ID.')
|
60
|
+
name: str = rorm.Field(field_type=rorm.types.VARCHAR(32), comment='Chat room name.')
|
61
|
+
contact: int = rorm.Field(field_type=rorm.types_mysql.TINYINT(unsigned=True), field_default='1', not_null=True, comment='Is the contact, 0 is no contact, 1 is contact.')
|
62
|
+
valid: int = rorm.Field(field_type=rorm.types_mysql.TINYINT(unsigned=True), field_default='1', not_null=True, comment='Is the valid, 0 is invalid, 1 is valid.')
|
63
|
+
|
64
|
+
|
65
|
+
class DatabaseTableContactRoomUser(rorm.Model, table=True):
|
66
|
+
"""
|
67
|
+
Database `contact_room_user` table model.
|
68
|
+
"""
|
69
|
+
|
70
|
+
__comment__ = 'Chat room user contact table.'
|
71
|
+
create_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', not_null=True, index_n=True, comment='Record create time.')
|
72
|
+
update_time: rorm.Datetime = rorm.Field(field_default='ON UPDATE CURRENT_TIMESTAMP', index_n=True, comment='Record update time.')
|
73
|
+
room_id: str = rorm.Field(field_type=rorm.types.VARCHAR(31), key=True, comment='Chat room ID.')
|
74
|
+
user_id: str = rorm.Field(field_type=rorm.types.VARCHAR(24), key=True, comment='Chat room user ID.')
|
75
|
+
name: str = rorm.Field(field_type=rorm.types.VARCHAR(32), comment='Chat room user name.')
|
76
|
+
contact: int = rorm.Field(field_type=rorm.types_mysql.TINYINT(unsigned=True), field_default='1', not_null=True, comment='Is the contact, 0 is no contact, 1 is contact.')
|
77
|
+
valid: int = rorm.Field(field_type=rorm.types_mysql.TINYINT(unsigned=True), field_default='1', not_null=True, comment='Is the valid, 0 is invalid, 1 is valid.')
|
78
|
+
|
79
|
+
|
80
|
+
class DatabaseTableMessageReceive(rorm.Model, table=True):
|
81
|
+
"""
|
82
|
+
Database `message_receive` table model.
|
83
|
+
"""
|
84
|
+
|
85
|
+
__comment__ = 'Message receive table.'
|
86
|
+
create_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', not_null=True, index_n=True, comment='Record create time.')
|
87
|
+
message_time: rorm.Datetime = rorm.Field(not_null=True, index_n=True, comment='Message time.')
|
88
|
+
message_id: int = rorm.Field(field_type=rorm.types_mysql.BIGINT(unsigned=True), key=True, comment='Message UUID.')
|
89
|
+
room_id: str = rorm.Field(field_type=rorm.types.VARCHAR(31), index_n=True, comment='Message chat room ID, null for private chat.')
|
90
|
+
user_id: str = rorm.Field(field_type=rorm.types.VARCHAR(24), index_n=True, comment='Message sender user ID, null for system message.')
|
91
|
+
type: int = rorm.Field(
|
92
|
+
field_type=rorm.types_mysql.INTEGER(unsigned=True),
|
93
|
+
not_null=True,
|
94
|
+
comment=(
|
95
|
+
'Message type, '
|
96
|
+
'1 is text message, '
|
97
|
+
'3 is image message, '
|
98
|
+
'34 is voice message, '
|
99
|
+
'37 is new friend invitation message, '
|
100
|
+
'42 is business card message, '
|
101
|
+
'43 is video message, '
|
102
|
+
'47 is emoticon message, '
|
103
|
+
'48 is position message, '
|
104
|
+
'49 is share message ('
|
105
|
+
'data type, '
|
106
|
+
'1 is pure link text, '
|
107
|
+
'6 is other side upload file completed, '
|
108
|
+
'17 is initiate real time location, '
|
109
|
+
'19 or 40 is forward, '
|
110
|
+
'33 is mini program, '
|
111
|
+
'51 is video channel, '
|
112
|
+
'57 is quote, '
|
113
|
+
'74 is other side start uploading file, '
|
114
|
+
'2000 is transfer money, '
|
115
|
+
'include "<appname>[^<>]+</appname>" is app, '
|
116
|
+
'other omit'
|
117
|
+
'), '
|
118
|
+
'50 is voice call or video call invitation message, '
|
119
|
+
'51 is system synchronize data message, '
|
120
|
+
'56 is real time position data message, '
|
121
|
+
'10000 is text system message, '
|
122
|
+
'10002 is system message ('
|
123
|
+
'date type, '
|
124
|
+
'"pat" is pat, '
|
125
|
+
'"revokemsg" is recall, '
|
126
|
+
'"paymsg" is transfer money tip, '
|
127
|
+
'other omit'
|
128
|
+
'), '
|
129
|
+
'other omit.'
|
130
|
+
)
|
131
|
+
)
|
132
|
+
data: str = rorm.Field(field_type=rorm.types.TEXT, not_null=True, comment='Message data.')
|
133
|
+
file_id: int = rorm.Field(field_type=rorm.types_mysql.MEDIUMINT(unsigned=True), comment='Message file ID, from the file database.')
|
134
|
+
|
135
|
+
|
136
|
+
class DatabaseTableMessageSend(rorm.Model, table=True):
|
137
|
+
"""
|
138
|
+
Database `message_send` table model.
|
139
|
+
"""
|
140
|
+
|
141
|
+
__comment__ = 'Message send table.'
|
142
|
+
create_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', not_null=True, index_n=True, comment='Record create time.')
|
143
|
+
update_time: rorm.Datetime = rorm.Field(field_default='ON UPDATE CURRENT_TIMESTAMP', index_n=True, comment='Record update time.')
|
144
|
+
send_id: int = rorm.Field(field_type=rorm.types_mysql.INTEGER(unsigned=True), key_auto=True, comment='Send ID.')
|
145
|
+
status: int = rorm.Field(
|
146
|
+
field_type=rorm.types_mysql.TINYINT(unsigned=True),
|
147
|
+
not_null=True,
|
148
|
+
comment=(
|
149
|
+
'Send status, '
|
150
|
+
'0 is not sent, '
|
151
|
+
'1 is handling, '
|
152
|
+
'2 is send success, '
|
153
|
+
'3 is send fail, '
|
154
|
+
'4 is send cancel.'
|
155
|
+
)
|
156
|
+
)
|
157
|
+
type: int = rorm.Field(
|
158
|
+
field_type=rorm.types_mysql.TINYINT(unsigned=True),
|
159
|
+
not_null=True,
|
160
|
+
comment=(
|
161
|
+
'Send type, '
|
162
|
+
'0 is text message, '
|
163
|
+
"1 is text message with \\'@\\', "
|
164
|
+
'2 is file message, '
|
165
|
+
'3 is image message, '
|
166
|
+
'4 is emoticon message, '
|
167
|
+
'5 is pat message, '
|
168
|
+
'6 is public account message, '
|
169
|
+
'7 is forward message.'
|
170
|
+
)
|
171
|
+
)
|
172
|
+
receive_id: str = rorm.Field(field_type=rorm.types.VARCHAR(31), not_null=True, index_n=True, comment='Receive to user ID or chat room ID.')
|
173
|
+
parameter: str = rorm.Field(field_type=rorm.types.JSON, not_null=True, comment='Send parameters.')
|
174
|
+
file_id: int = rorm.Field(field_type=rorm.types_mysql.MEDIUMINT(unsigned=True), comment='Message file ID, from the file database.')
|
175
|
+
|
176
|
+
|
31
177
|
class WeChatDatabase(WeChatBase):
|
32
178
|
"""
|
33
179
|
WeChat database type.
|
34
180
|
Can create database used `self.build_db` method.
|
181
|
+
|
182
|
+
Attributes
|
183
|
+
----------
|
184
|
+
db_names : Database table name mapping dictionary.
|
35
185
|
"""
|
36
186
|
|
187
|
+
db_names = {
|
188
|
+
'contact_user': 'contact_user',
|
189
|
+
'contact_room': 'contact_room',
|
190
|
+
'contact_room_user': 'contact_room_user',
|
191
|
+
'message_receive': 'message_receive',
|
192
|
+
'message_send': 'message_send',
|
193
|
+
'stats': 'stats'
|
194
|
+
}
|
195
|
+
|
37
196
|
|
38
197
|
def __init__(
|
39
198
|
self,
|
40
199
|
wechat: WeChat,
|
41
|
-
|
200
|
+
db: Database | dict[Literal['wechat', 'file'], Database]
|
42
201
|
) -> None:
|
43
202
|
"""
|
44
203
|
Build instance attributes.
|
@@ -46,7 +205,7 @@ class WeChatDatabase(WeChatBase):
|
|
46
205
|
Parameters
|
47
206
|
----------
|
48
207
|
wechat : `WeChatClient` instance.
|
49
|
-
|
208
|
+
db : `Database` instance of `reykit` package.
|
50
209
|
- `Database`, Set all `Database`: instances.
|
51
210
|
- `dict`, Set each `Database`: instance, all item is required.
|
52
211
|
`Key 'wechat'`: `Database` instance used in WeChat methods.
|
@@ -55,30 +214,14 @@ class WeChatDatabase(WeChatBase):
|
|
55
214
|
|
56
215
|
# Set attribute.
|
57
216
|
self.wechat = wechat
|
58
|
-
match
|
217
|
+
match db:
|
59
218
|
case Database():
|
60
|
-
self.
|
219
|
+
self.db_wechat = self.db_file = db
|
61
220
|
case dict():
|
62
|
-
self.
|
63
|
-
self.
|
64
|
-
if (
|
65
|
-
self.database_wechat is None
|
66
|
-
or self.database_file is None
|
67
|
-
):
|
68
|
-
throw(ValueError, database)
|
221
|
+
self.db_wechat: Database = db.get('wechat')
|
222
|
+
self.db_file: Database = db.get('file')
|
69
223
|
case _:
|
70
|
-
throw(TypeError,
|
71
|
-
|
72
|
-
## Database path name.
|
73
|
-
self.db_names = {
|
74
|
-
'wechat': 'wechat',
|
75
|
-
'wechat.contact_user': 'contact_user',
|
76
|
-
'wechat.contact_room': 'contact_room',
|
77
|
-
'wechat.contact_room_user': 'contact_room_user',
|
78
|
-
'wechat.message_receive': 'message_receive',
|
79
|
-
'wechat.message_send': 'message_send',
|
80
|
-
'wechat.stats': 'stats'
|
81
|
-
}
|
224
|
+
throw(TypeError, db)
|
82
225
|
|
83
226
|
# Add handler.
|
84
227
|
self.__add_receiver_handler_to_contact_user()
|
@@ -97,433 +240,35 @@ class WeChatDatabase(WeChatBase):
|
|
97
240
|
"""
|
98
241
|
|
99
242
|
# Check.
|
100
|
-
if self.
|
101
|
-
throw(ValueError, self.
|
243
|
+
if self.db_wechat is None:
|
244
|
+
throw(ValueError, self.db_wechat)
|
102
245
|
|
103
246
|
# Set parameter.
|
104
247
|
|
105
|
-
## Database.
|
106
|
-
databases = [
|
107
|
-
{
|
108
|
-
'name': self.db_names['wechat']
|
109
|
-
}
|
110
|
-
]
|
111
|
-
|
112
248
|
## Table.
|
249
|
+
DatabaseTableContactUser._set_name(self.db_names['contact_user'])
|
250
|
+
DatabaseTableContactRoom._set_name(self.db_names['contact_room'])
|
251
|
+
DatabaseTableContactRoomUser._set_name(self.db_names['contact_room_user'])
|
252
|
+
DatabaseTableMessageReceive._set_name(self.db_names['message_receive'])
|
253
|
+
DatabaseTableMessageSend._set_name(self.db_names['message_send'])
|
113
254
|
tables = [
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
{
|
120
|
-
'name': 'create_time',
|
121
|
-
'type': 'datetime',
|
122
|
-
'constraint': 'NOT NULL DEFAULT CURRENT_TIMESTAMP',
|
123
|
-
'comment': 'Record create time.'
|
124
|
-
},
|
125
|
-
{
|
126
|
-
'name': 'update_time',
|
127
|
-
'type': 'datetime',
|
128
|
-
'constraint': 'DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP',
|
129
|
-
'comment': 'Record update time.'
|
130
|
-
},
|
131
|
-
{
|
132
|
-
'name': 'user_id',
|
133
|
-
'type': 'varchar(24)',
|
134
|
-
'constraint': 'NOT NULL',
|
135
|
-
'comment': 'User ID.'
|
136
|
-
},
|
137
|
-
{
|
138
|
-
'name': 'name',
|
139
|
-
'type': 'varchar(32)',
|
140
|
-
'constraint': 'CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL',
|
141
|
-
'comment': 'User name.'
|
142
|
-
},
|
143
|
-
{
|
144
|
-
'name': 'contact',
|
145
|
-
'type': 'tinyint unsigned',
|
146
|
-
'constraint': 'NOT NULL',
|
147
|
-
'comment': 'Is the contact, 0 is contact, 1 is no contact.'
|
148
|
-
},
|
149
|
-
{
|
150
|
-
'name': 'valid',
|
151
|
-
'type': 'tinyint unsigned',
|
152
|
-
'constraint': 'DEFAULT 1',
|
153
|
-
'comment': 'Is the valid, 0 is invalid, 1 is valid.'
|
154
|
-
}
|
155
|
-
],
|
156
|
-
'primary': 'user_id',
|
157
|
-
'indexes': [
|
158
|
-
{
|
159
|
-
'name': 'n_create_time',
|
160
|
-
'fields': 'create_time',
|
161
|
-
'type': 'noraml',
|
162
|
-
'comment': 'Record create time normal index.'
|
163
|
-
},
|
164
|
-
{
|
165
|
-
'name': 'n_update_time',
|
166
|
-
'fields': 'update_time',
|
167
|
-
'type': 'noraml',
|
168
|
-
'comment': 'Record update time normal index.'
|
169
|
-
}
|
170
|
-
],
|
171
|
-
'comment': 'User contact table.'
|
172
|
-
},
|
173
|
-
|
174
|
-
### 'contact_room'.
|
175
|
-
{
|
176
|
-
'path': (self.db_names['wechat'], self.db_names['wechat.contact_room']),
|
177
|
-
'fields': [
|
178
|
-
{
|
179
|
-
'name': 'create_time',
|
180
|
-
'type': 'datetime',
|
181
|
-
'constraint': 'NOT NULL DEFAULT CURRENT_TIMESTAMP',
|
182
|
-
'comment': 'Record create time.'
|
183
|
-
},
|
184
|
-
{
|
185
|
-
'name': 'update_time',
|
186
|
-
'type': 'datetime',
|
187
|
-
'constraint': 'DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP',
|
188
|
-
'comment': 'Record update time.'
|
189
|
-
},
|
190
|
-
{
|
191
|
-
'name': 'room_id',
|
192
|
-
'type': 'varchar(31)',
|
193
|
-
'constraint': 'NOT NULL',
|
194
|
-
'comment': 'Chat room ID.'
|
195
|
-
},
|
196
|
-
{
|
197
|
-
'name': 'name',
|
198
|
-
'type': 'varchar(32)',
|
199
|
-
'constraint': 'CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL',
|
200
|
-
'comment': 'Chat room name.'
|
201
|
-
},
|
202
|
-
{
|
203
|
-
'name': 'contact',
|
204
|
-
'type': 'tinyint unsigned',
|
205
|
-
'constraint': 'NOT NULL',
|
206
|
-
'comment': 'Is the contact, 0 is contact, 1 is no contact.'
|
207
|
-
},
|
208
|
-
{
|
209
|
-
'name': 'valid',
|
210
|
-
'type': 'tinyint unsigned',
|
211
|
-
'constraint': 'DEFAULT 1',
|
212
|
-
'comment': 'Is the valid, 0 is invalid, 1 is valid.'
|
213
|
-
}
|
214
|
-
],
|
215
|
-
'primary': 'room_id',
|
216
|
-
'indexes': [
|
217
|
-
{
|
218
|
-
'name': 'n_create_time',
|
219
|
-
'fields': 'create_time',
|
220
|
-
'type': 'noraml',
|
221
|
-
'comment': 'Record create time normal index.'
|
222
|
-
},
|
223
|
-
{
|
224
|
-
'name': 'n_update_time',
|
225
|
-
'fields': 'update_time',
|
226
|
-
'type': 'noraml',
|
227
|
-
'comment': 'Record update time normal index.'
|
228
|
-
}
|
229
|
-
],
|
230
|
-
'comment': 'Chat room contact table.'
|
231
|
-
},
|
232
|
-
|
233
|
-
### 'contact_room_user'.
|
234
|
-
{
|
235
|
-
'path': (self.db_names['wechat'], self.db_names['wechat.contact_room_user']),
|
236
|
-
'fields': [
|
237
|
-
{
|
238
|
-
'name': 'create_time',
|
239
|
-
'type': 'datetime',
|
240
|
-
'constraint': 'NOT NULL DEFAULT CURRENT_TIMESTAMP',
|
241
|
-
'comment': 'Record create time.'
|
242
|
-
},
|
243
|
-
{
|
244
|
-
'name': 'update_time',
|
245
|
-
'type': 'datetime',
|
246
|
-
'constraint': 'DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP',
|
247
|
-
'comment': 'Record update time.'
|
248
|
-
},
|
249
|
-
{
|
250
|
-
'name': 'room_id',
|
251
|
-
'type': 'varchar(31)',
|
252
|
-
'constraint': 'NOT NULL',
|
253
|
-
'comment': 'Chat room ID.'
|
254
|
-
},
|
255
|
-
{
|
256
|
-
'name': 'user_id',
|
257
|
-
'type': 'varchar(24)',
|
258
|
-
'constraint': 'NOT NULL',
|
259
|
-
'comment': 'Chat room user ID.'
|
260
|
-
},
|
261
|
-
{
|
262
|
-
'name': 'name',
|
263
|
-
'type': 'varchar(32)',
|
264
|
-
'constraint': 'CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL',
|
265
|
-
'comment': 'Chat room user name.'
|
266
|
-
},
|
267
|
-
{
|
268
|
-
'name': 'contact',
|
269
|
-
'type': 'tinyint unsigned',
|
270
|
-
'constraint': 'NOT NULL',
|
271
|
-
'comment': 'Is the contact, 0 is contact, 1 is no contact.'
|
272
|
-
},
|
273
|
-
{
|
274
|
-
'name': 'valid',
|
275
|
-
'type': 'tinyint unsigned',
|
276
|
-
'constraint': 'DEFAULT 1',
|
277
|
-
'comment': 'Is the valid, 0 is invalid, 1 is valid.'
|
278
|
-
}
|
279
|
-
],
|
280
|
-
'primary': ['room_id', 'user_id'],
|
281
|
-
'indexes': [
|
282
|
-
{
|
283
|
-
'name': 'n_create_time',
|
284
|
-
'fields': 'create_time',
|
285
|
-
'type': 'noraml',
|
286
|
-
'comment': 'Record create time normal index.'
|
287
|
-
},
|
288
|
-
{
|
289
|
-
'name': 'n_update_time',
|
290
|
-
'fields': 'update_time',
|
291
|
-
'type': 'noraml',
|
292
|
-
'comment': 'Record update time normal index.'
|
293
|
-
}
|
294
|
-
],
|
295
|
-
'comment': 'Chat room user contact table.'
|
296
|
-
},
|
297
|
-
|
298
|
-
|
299
|
-
### 'message_receive'.
|
300
|
-
{
|
301
|
-
'path': (self.db_names['wechat'], self.db_names['wechat.message_receive']),
|
302
|
-
'fields': [
|
303
|
-
{
|
304
|
-
'name': 'create_time',
|
305
|
-
'type': 'datetime',
|
306
|
-
'constraint': 'NOT NULL DEFAULT CURRENT_TIMESTAMP',
|
307
|
-
'comment': 'Record create time.'
|
308
|
-
},
|
309
|
-
{
|
310
|
-
'name': 'message_time',
|
311
|
-
'type': 'datetime',
|
312
|
-
'constraint': 'NOT NULL',
|
313
|
-
'comment': 'Message time.'
|
314
|
-
},
|
315
|
-
{
|
316
|
-
'name': 'message_id',
|
317
|
-
'type': 'bigint unsigned',
|
318
|
-
'constraint': 'NOT NULL',
|
319
|
-
'comment': 'Message UUID.'
|
320
|
-
},
|
321
|
-
{
|
322
|
-
'name': 'room_id',
|
323
|
-
'type': 'varchar(31)',
|
324
|
-
'comment': 'Message chat room ID, null for private chat.'
|
325
|
-
},
|
326
|
-
{
|
327
|
-
'name': 'user_id',
|
328
|
-
'type': 'varchar(24)',
|
329
|
-
'comment': 'Message sender user ID, null for system message.'
|
330
|
-
},
|
331
|
-
{
|
332
|
-
'name': 'type',
|
333
|
-
'type': 'int unsigned',
|
334
|
-
'constraint': 'NOT NULL',
|
335
|
-
'comment': (
|
336
|
-
'Message type, '
|
337
|
-
'1 is text message, '
|
338
|
-
'3 is image message, '
|
339
|
-
'34 is voice message, '
|
340
|
-
'37 is new friend invitation message, '
|
341
|
-
'42 is business card message, '
|
342
|
-
'43 is video message, '
|
343
|
-
'47 is emoticon message, '
|
344
|
-
'48 is position message, '
|
345
|
-
'49 is share message ('
|
346
|
-
'data type, '
|
347
|
-
'1 is pure link text, '
|
348
|
-
'6 is other side upload file completed, '
|
349
|
-
'17 is initiate real time location, '
|
350
|
-
'19 or 40 is forward, '
|
351
|
-
'33 is mini program, '
|
352
|
-
'51 is video channel, '
|
353
|
-
'57 is quote, '
|
354
|
-
'74 is other side start uploading file, '
|
355
|
-
'2000 is transfer money, '
|
356
|
-
'include "<appname>[^<>]+</appname>" is app, '
|
357
|
-
'other omit'
|
358
|
-
'), '
|
359
|
-
'50 is voice call or video call invitation message, '
|
360
|
-
'51 is system synchronize data message, '
|
361
|
-
'56 is real time position data message, '
|
362
|
-
'10000 is text system message, '
|
363
|
-
'10002 is system message ('
|
364
|
-
'date type, '
|
365
|
-
'"pat" is pat, '
|
366
|
-
'"revokemsg" is recall, '
|
367
|
-
'"paymsg" is transfer money tip, '
|
368
|
-
'other omit'
|
369
|
-
'), '
|
370
|
-
'other omit.'
|
371
|
-
)
|
372
|
-
},
|
373
|
-
{
|
374
|
-
'name': 'data',
|
375
|
-
'type': 'text',
|
376
|
-
'constraint': 'CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL',
|
377
|
-
'comment': 'Message data.'
|
378
|
-
},
|
379
|
-
{
|
380
|
-
'name': 'file_id',
|
381
|
-
'type': 'mediumint unsigned',
|
382
|
-
'comment': 'Message file ID, from the file database.'
|
383
|
-
}
|
384
|
-
],
|
385
|
-
'primary': 'message_id',
|
386
|
-
'indexes': [
|
387
|
-
{
|
388
|
-
'name': 'n_create_time',
|
389
|
-
'fields': 'create_time',
|
390
|
-
'type': 'noraml',
|
391
|
-
'comment': 'Record create time normal index.'
|
392
|
-
},
|
393
|
-
{
|
394
|
-
'name': 'n_message_time',
|
395
|
-
'fields': 'message_time',
|
396
|
-
'type': 'noraml',
|
397
|
-
'comment': 'Message time normal index.'
|
398
|
-
},
|
399
|
-
{
|
400
|
-
'name': 'n_room_id',
|
401
|
-
'fields': 'room_id',
|
402
|
-
'type': 'noraml',
|
403
|
-
'comment': 'Message chat room ID normal index.'
|
404
|
-
},
|
405
|
-
{
|
406
|
-
'name': 'n_user_id',
|
407
|
-
'fields': 'user_id',
|
408
|
-
'type': 'noraml',
|
409
|
-
'comment': 'Message sender user ID normal index.'
|
410
|
-
}
|
411
|
-
],
|
412
|
-
'comment': 'Message receive table.'
|
413
|
-
},
|
414
|
-
|
415
|
-
### 'message_send'.
|
416
|
-
{
|
417
|
-
'path': (self.db_names['wechat'], self.db_names['wechat.message_send']),
|
418
|
-
'fields': [
|
419
|
-
{
|
420
|
-
'name': 'create_time',
|
421
|
-
'type': 'datetime',
|
422
|
-
'constraint': 'NOT NULL DEFAULT CURRENT_TIMESTAMP',
|
423
|
-
'comment': 'Record create time.'
|
424
|
-
},
|
425
|
-
{
|
426
|
-
'name': 'update_time',
|
427
|
-
'type': 'datetime',
|
428
|
-
'constraint': 'DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP',
|
429
|
-
'comment': 'Record update time.'
|
430
|
-
},
|
431
|
-
{
|
432
|
-
'name': 'plan_time',
|
433
|
-
'type': 'datetime',
|
434
|
-
'comment': 'Send plan time.'
|
435
|
-
},
|
436
|
-
{
|
437
|
-
'name': 'send_id',
|
438
|
-
'type': 'int unsigned',
|
439
|
-
'constraint': 'NOT NULL AUTO_INCREMENT',
|
440
|
-
'comment': 'Send ID.'
|
441
|
-
},
|
442
|
-
{
|
443
|
-
'name': 'status',
|
444
|
-
'type': 'tinyint unsigned',
|
445
|
-
'constraint': 'NOT NULL',
|
446
|
-
'comment': (
|
447
|
-
'Send status, '
|
448
|
-
'0 is not sent, '
|
449
|
-
'1 is handling, '
|
450
|
-
'2 is send success, '
|
451
|
-
'3 is send fail, '
|
452
|
-
'4 is send cancel.'
|
453
|
-
)
|
454
|
-
},
|
455
|
-
{
|
456
|
-
'name': 'type',
|
457
|
-
'type': 'tinyint unsigned',
|
458
|
-
'constraint': 'NOT NULL',
|
459
|
-
'comment': (
|
460
|
-
'Send type, '
|
461
|
-
'0 is text message, '
|
462
|
-
"1 is text message with \\'@\\', "
|
463
|
-
'2 is file message, '
|
464
|
-
'3 is image message, '
|
465
|
-
'4 is emoticon message, '
|
466
|
-
'5 is pat message, '
|
467
|
-
'6 is public account message, '
|
468
|
-
'7 is forward message.'
|
469
|
-
)
|
470
|
-
},
|
471
|
-
{
|
472
|
-
'name': 'receive_id',
|
473
|
-
'type': 'varchar(31)',
|
474
|
-
'constraint': 'NOT NULL',
|
475
|
-
'comment': 'Receive to user ID or chat room ID.'
|
476
|
-
},
|
477
|
-
{
|
478
|
-
'name': 'parameter',
|
479
|
-
'type': 'json',
|
480
|
-
'constraint': 'NOT NULL',
|
481
|
-
'comment': 'Send parameters.'
|
482
|
-
},
|
483
|
-
{
|
484
|
-
'name': 'file_id',
|
485
|
-
'type': 'mediumint unsigned',
|
486
|
-
'comment': 'Send file ID, from the file database.'
|
487
|
-
}
|
488
|
-
],
|
489
|
-
'primary': 'send_id',
|
490
|
-
'indexes': [
|
491
|
-
{
|
492
|
-
'name': 'n_create_time',
|
493
|
-
'fields': 'create_time',
|
494
|
-
'type': 'noraml',
|
495
|
-
'comment': 'Record create time normal index.'
|
496
|
-
},
|
497
|
-
{
|
498
|
-
'name': 'n_update_time',
|
499
|
-
'fields': 'update_time',
|
500
|
-
'type': 'noraml',
|
501
|
-
'comment': 'Record update time normal index.'
|
502
|
-
},
|
503
|
-
{
|
504
|
-
'name': 'n_receive_id',
|
505
|
-
'fields': 'receive_id',
|
506
|
-
'type': 'noraml',
|
507
|
-
'comment': 'Receive to user ID or chat room ID normal index.'
|
508
|
-
}
|
509
|
-
],
|
510
|
-
'comment': 'Message send table.'
|
511
|
-
}
|
512
|
-
|
255
|
+
DatabaseTableContactUser,
|
256
|
+
DatabaseTableContactRoom,
|
257
|
+
DatabaseTableContactRoomUser,
|
258
|
+
DatabaseTableMessageReceive,
|
259
|
+
DatabaseTableMessageSend
|
513
260
|
]
|
514
261
|
|
515
262
|
## View stats.
|
516
263
|
views_stats = [
|
517
|
-
|
518
|
-
### 'stats'.
|
519
264
|
{
|
520
|
-
'path':
|
265
|
+
'path': self.db_names['stats'],
|
521
266
|
'items': [
|
522
267
|
{
|
523
268
|
'name': 'receive_count',
|
524
269
|
'select': (
|
525
270
|
'SELECT COUNT(1)\n'
|
526
|
-
f'FROM `{self.
|
271
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['message_receive']}`'
|
527
272
|
),
|
528
273
|
'comment': 'Message receive count.'
|
529
274
|
},
|
@@ -531,7 +276,7 @@ class WeChatDatabase(WeChatBase):
|
|
531
276
|
'name': 'send_count',
|
532
277
|
'select': (
|
533
278
|
'SELECT COUNT(1)\n'
|
534
|
-
f'FROM `{self.
|
279
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['message_send']}`\n'
|
535
280
|
'WHERE `status` = 2'
|
536
281
|
),
|
537
282
|
'comment': 'Message send count.'
|
@@ -540,7 +285,7 @@ class WeChatDatabase(WeChatBase):
|
|
540
285
|
'name': 'user_count',
|
541
286
|
'select': (
|
542
287
|
'SELECT COUNT(1)\n'
|
543
|
-
f'FROM `{self.
|
288
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['contact_user']}`'
|
544
289
|
),
|
545
290
|
'comment': 'Contact user count.'
|
546
291
|
},
|
@@ -548,7 +293,7 @@ class WeChatDatabase(WeChatBase):
|
|
548
293
|
'name': 'room_count',
|
549
294
|
'select': (
|
550
295
|
'SELECT COUNT(1)\n'
|
551
|
-
f'FROM `{self.
|
296
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['contact_room']}`'
|
552
297
|
),
|
553
298
|
'comment': 'Contact room count.'
|
554
299
|
},
|
@@ -556,7 +301,7 @@ class WeChatDatabase(WeChatBase):
|
|
556
301
|
'name': 'room_user_count',
|
557
302
|
'select': (
|
558
303
|
'SELECT COUNT(1)\n'
|
559
|
-
f'FROM `{self.
|
304
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['contact_room_user']}`'
|
560
305
|
),
|
561
306
|
'comment': 'Contact room user count.'
|
562
307
|
},
|
@@ -564,7 +309,7 @@ class WeChatDatabase(WeChatBase):
|
|
564
309
|
'name': 'past_day_receive_count',
|
565
310
|
'select': (
|
566
311
|
'SELECT COUNT(1)\n'
|
567
|
-
f'FROM `{self.
|
312
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['message_receive']}`'
|
568
313
|
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) = 0'
|
569
314
|
),
|
570
315
|
'comment': 'Message receive count in the past day.'
|
@@ -573,7 +318,7 @@ class WeChatDatabase(WeChatBase):
|
|
573
318
|
'name': 'past_day_send_count',
|
574
319
|
'select': (
|
575
320
|
'SELECT COUNT(1)\n'
|
576
|
-
f'FROM `{self.
|
321
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['message_send']}`'
|
577
322
|
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) = 0'
|
578
323
|
),
|
579
324
|
'comment': 'Message send count in the past day.'
|
@@ -582,7 +327,7 @@ class WeChatDatabase(WeChatBase):
|
|
582
327
|
'name': 'past_day_user_count',
|
583
328
|
'select': (
|
584
329
|
'SELECT COUNT(1)\n'
|
585
|
-
f'FROM `{self.
|
330
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['contact_user']}`'
|
586
331
|
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) = 0'
|
587
332
|
),
|
588
333
|
'comment': 'Contact user count in the past day.'
|
@@ -591,7 +336,7 @@ class WeChatDatabase(WeChatBase):
|
|
591
336
|
'name': 'past_day_room_count',
|
592
337
|
'select': (
|
593
338
|
'SELECT COUNT(1)\n'
|
594
|
-
f'FROM `{self.
|
339
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['contact_room']}`'
|
595
340
|
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) = 0'
|
596
341
|
),
|
597
342
|
'comment': 'Contact room count in the past day.'
|
@@ -600,7 +345,7 @@ class WeChatDatabase(WeChatBase):
|
|
600
345
|
'name': 'past_day_room_user_count',
|
601
346
|
'select': (
|
602
347
|
'SELECT COUNT(1)\n'
|
603
|
-
f'FROM `{self.
|
348
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['contact_room_user']}`'
|
604
349
|
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) = 0'
|
605
350
|
),
|
606
351
|
'comment': 'Contact room user count in the past day.'
|
@@ -609,7 +354,7 @@ class WeChatDatabase(WeChatBase):
|
|
609
354
|
'name': 'past_week_receive_count',
|
610
355
|
'select': (
|
611
356
|
'SELECT COUNT(1)\n'
|
612
|
-
f'FROM `{self.
|
357
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['message_receive']}`'
|
613
358
|
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 6'
|
614
359
|
),
|
615
360
|
'comment': 'Message receive count in the past week.'
|
@@ -618,7 +363,7 @@ class WeChatDatabase(WeChatBase):
|
|
618
363
|
'name': 'past_week_send_count',
|
619
364
|
'select': (
|
620
365
|
'SELECT COUNT(1)\n'
|
621
|
-
f'FROM `{self.
|
366
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['message_send']}`'
|
622
367
|
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 6'
|
623
368
|
),
|
624
369
|
'comment': 'Message send count in the past week.'
|
@@ -627,7 +372,7 @@ class WeChatDatabase(WeChatBase):
|
|
627
372
|
'name': 'past_week_user_count',
|
628
373
|
'select': (
|
629
374
|
'SELECT COUNT(1)\n'
|
630
|
-
f'FROM `{self.
|
375
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['contact_user']}`'
|
631
376
|
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 6'
|
632
377
|
),
|
633
378
|
'comment': 'Contact user count in the past week.'
|
@@ -636,7 +381,7 @@ class WeChatDatabase(WeChatBase):
|
|
636
381
|
'name': 'past_week_room_count',
|
637
382
|
'select': (
|
638
383
|
'SELECT COUNT(1)\n'
|
639
|
-
f'FROM `{self.
|
384
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['contact_room']}`'
|
640
385
|
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 6'
|
641
386
|
),
|
642
387
|
'comment': 'Contact room count in the past week.'
|
@@ -645,7 +390,7 @@ class WeChatDatabase(WeChatBase):
|
|
645
390
|
'name': 'past_week_room_user_count',
|
646
391
|
'select': (
|
647
392
|
'SELECT COUNT(1)\n'
|
648
|
-
f'FROM `{self.
|
393
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['contact_room_user']}`'
|
649
394
|
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 6'
|
650
395
|
),
|
651
396
|
'comment': 'Contact room user count in the past week.'
|
@@ -654,7 +399,7 @@ class WeChatDatabase(WeChatBase):
|
|
654
399
|
'name': 'past_month_receive_count',
|
655
400
|
'select': (
|
656
401
|
'SELECT COUNT(1)\n'
|
657
|
-
f'FROM `{self.
|
402
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['message_receive']}`'
|
658
403
|
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 29'
|
659
404
|
),
|
660
405
|
'comment': 'Message receive count in the past month.'
|
@@ -663,7 +408,7 @@ class WeChatDatabase(WeChatBase):
|
|
663
408
|
'name': 'past_month_send_count',
|
664
409
|
'select': (
|
665
410
|
'SELECT COUNT(1)\n'
|
666
|
-
f'FROM `{self.
|
411
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['message_send']}`'
|
667
412
|
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 29'
|
668
413
|
),
|
669
414
|
'comment': 'Message send count in the past month.'
|
@@ -672,7 +417,7 @@ class WeChatDatabase(WeChatBase):
|
|
672
417
|
'name': 'past_month_user_count',
|
673
418
|
'select': (
|
674
419
|
'SELECT COUNT(1)\n'
|
675
|
-
f'FROM `{self.
|
420
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['contact_user']}`'
|
676
421
|
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 29'
|
677
422
|
),
|
678
423
|
'comment': 'Contact user count in the past month.'
|
@@ -681,7 +426,7 @@ class WeChatDatabase(WeChatBase):
|
|
681
426
|
'name': 'past_month_room_count',
|
682
427
|
'select': (
|
683
428
|
'SELECT COUNT(1)\n'
|
684
|
-
f'FROM `{self.
|
429
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['contact_room']}`'
|
685
430
|
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 29'
|
686
431
|
),
|
687
432
|
'comment': 'Contact room count in the past month.'
|
@@ -690,7 +435,7 @@ class WeChatDatabase(WeChatBase):
|
|
690
435
|
'name': 'past_month_room_user_count',
|
691
436
|
'select': (
|
692
437
|
'SELECT COUNT(1)\n'
|
693
|
-
f'FROM `{self.
|
438
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['contact_room_user']}`'
|
694
439
|
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 29'
|
695
440
|
),
|
696
441
|
'comment': 'Contact room user count in the past month.'
|
@@ -699,7 +444,7 @@ class WeChatDatabase(WeChatBase):
|
|
699
444
|
'name': 'receive_last_time',
|
700
445
|
'select': (
|
701
446
|
'SELECT MAX(`message_time`)\n'
|
702
|
-
f'FROM `{self.
|
447
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['message_receive']}`'
|
703
448
|
),
|
704
449
|
'comment': 'Message last receive time.'
|
705
450
|
},
|
@@ -707,24 +452,22 @@ class WeChatDatabase(WeChatBase):
|
|
707
452
|
'name': 'send_last_time',
|
708
453
|
'select': (
|
709
454
|
'SELECT MAX(`update_time`)\n'
|
710
|
-
f'FROM `{self.
|
455
|
+
f'FROM `{self.db_wechat.database}`.`{self.db_names['message_send']}`\n'
|
711
456
|
'WHERE `status` = 2'
|
712
457
|
),
|
713
458
|
'comment': 'Message last send time.'
|
714
459
|
}
|
715
460
|
]
|
716
|
-
|
717
461
|
}
|
718
|
-
|
719
462
|
]
|
720
463
|
|
721
464
|
# Build.
|
722
465
|
|
723
466
|
## WeChat.
|
724
|
-
self.
|
467
|
+
self.db_wechat.build.build(tables=tables, views_stats=views_stats, skip=True)
|
725
468
|
|
726
469
|
## File.
|
727
|
-
self.
|
470
|
+
self.db_file.file.build_db()
|
728
471
|
|
729
472
|
# Update.
|
730
473
|
self.update_contact_user()
|
@@ -743,8 +486,7 @@ class WeChatDatabase(WeChatBase):
|
|
743
486
|
user_data = [
|
744
487
|
{
|
745
488
|
'user_id': row['id'],
|
746
|
-
'name': row['name']
|
747
|
-
'contact': 1
|
489
|
+
'name': row['name']
|
748
490
|
}
|
749
491
|
for row in contact_table
|
750
492
|
]
|
@@ -754,12 +496,12 @@ class WeChatDatabase(WeChatBase):
|
|
754
496
|
]
|
755
497
|
|
756
498
|
# Insert and update.
|
757
|
-
conn = self.
|
499
|
+
conn = self.db_wechat.connect()
|
758
500
|
|
759
501
|
## Insert.
|
760
502
|
if contact_table != []:
|
761
503
|
conn.execute.insert(
|
762
|
-
self.db_names['
|
504
|
+
self.db_names['contact_user'],
|
763
505
|
user_data,
|
764
506
|
'update'
|
765
507
|
)
|
@@ -767,12 +509,12 @@ class WeChatDatabase(WeChatBase):
|
|
767
509
|
## Update.
|
768
510
|
if user_ids == []:
|
769
511
|
sql = (
|
770
|
-
f'UPDATE `{self.
|
512
|
+
f'UPDATE `{self.db_wechat.database}`.`{self.db_names['contact_user']}`\n'
|
771
513
|
'SET `contact` = 0'
|
772
514
|
)
|
773
515
|
else:
|
774
516
|
sql = (
|
775
|
-
f'UPDATE `{self.
|
517
|
+
f'UPDATE `{self.db_wechat.database}`.`{self.db_names['contact_user']}`\n'
|
776
518
|
'SET `contact` = 0\n'
|
777
519
|
'WHERE `user_id` NOT IN :user_ids'
|
778
520
|
)
|
@@ -799,8 +541,7 @@ class WeChatDatabase(WeChatBase):
|
|
799
541
|
room_data = [
|
800
542
|
{
|
801
543
|
'room_id': row['id'],
|
802
|
-
'name': row['name']
|
803
|
-
'contact': 1
|
544
|
+
'name': row['name']
|
804
545
|
}
|
805
546
|
for row in contact_table
|
806
547
|
]
|
@@ -810,12 +551,12 @@ class WeChatDatabase(WeChatBase):
|
|
810
551
|
]
|
811
552
|
|
812
553
|
# Insert and update.
|
813
|
-
conn = self.
|
554
|
+
conn = self.db_wechat.connect()
|
814
555
|
|
815
556
|
## Insert.
|
816
557
|
if contact_table != []:
|
817
558
|
conn.execute.insert(
|
818
|
-
self.db_names['
|
559
|
+
self.db_names['contact_room'],
|
819
560
|
room_data,
|
820
561
|
'update'
|
821
562
|
)
|
@@ -823,12 +564,12 @@ class WeChatDatabase(WeChatBase):
|
|
823
564
|
## Update.
|
824
565
|
if room_ids == []:
|
825
566
|
sql = (
|
826
|
-
f'UPDATE `{self.
|
567
|
+
f'UPDATE `{self.db_wechat.database}`.`{self.db_names['contact_room']}`\n'
|
827
568
|
'SET `contact` = 0'
|
828
569
|
)
|
829
570
|
else:
|
830
571
|
sql = (
|
831
|
-
f'UPDATE `{self.
|
572
|
+
f'UPDATE `{self.db_wechat.database}`.`{self.db_names['contact_room']}`\n'
|
832
573
|
'SET `contact` = 0\n'
|
833
574
|
'WHERE `room_id` NOT IN :room_ids'
|
834
575
|
)
|
@@ -872,8 +613,7 @@ class WeChatDatabase(WeChatBase):
|
|
872
613
|
{
|
873
614
|
'room_id': row['id'],
|
874
615
|
'user_id': user_id,
|
875
|
-
'name': name
|
876
|
-
'contact': 1
|
616
|
+
'name': name
|
877
617
|
}
|
878
618
|
for row in contact_table
|
879
619
|
for user_id, name
|
@@ -888,12 +628,12 @@ class WeChatDatabase(WeChatBase):
|
|
888
628
|
]
|
889
629
|
|
890
630
|
# Insert and update.
|
891
|
-
conn = self.
|
631
|
+
conn = self.db_wechat.connect()
|
892
632
|
|
893
633
|
## Insert.
|
894
634
|
if room_user_data != []:
|
895
635
|
conn.execute.insert(
|
896
|
-
self.db_names['
|
636
|
+
self.db_names['contact_room_user'],
|
897
637
|
room_user_data,
|
898
638
|
'update'
|
899
639
|
)
|
@@ -901,18 +641,18 @@ class WeChatDatabase(WeChatBase):
|
|
901
641
|
## Update.
|
902
642
|
if room_user_ids == []:
|
903
643
|
sql = (
|
904
|
-
f'UPDATE `{self.
|
644
|
+
f'UPDATE `{self.db_wechat.database}`.`{self.db_names['contact_room_user']}`\n'
|
905
645
|
'SET `contact` = 0'
|
906
646
|
)
|
907
647
|
elif room_id is None:
|
908
648
|
sql = (
|
909
|
-
f'UPDATE `{self.
|
649
|
+
f'UPDATE `{self.db_wechat.database}`.`{self.db_names['contact_room_user']}`\n'
|
910
650
|
'SET `contact` = 0\n'
|
911
651
|
"WHERE CONCAT(`room_id`, ',', `user_id`) NOT IN :room_user_ids"
|
912
652
|
)
|
913
653
|
else:
|
914
654
|
sql = (
|
915
|
-
f'UPDATE `{self.
|
655
|
+
f'UPDATE `{self.db_wechat.database}`.`{self.db_names['contact_room_user']}`\n'
|
916
656
|
'SET `contact` = 0\n'
|
917
657
|
'WHERE (\n'
|
918
658
|
' `room_id` = :room_id\n'
|
@@ -955,13 +695,12 @@ class WeChatDatabase(WeChatBase):
|
|
955
695
|
name = self.wechat.client.get_contact_name(message.user)
|
956
696
|
data = {
|
957
697
|
'user_id': message.user,
|
958
|
-
'name': name
|
959
|
-
'contact': 1
|
698
|
+
'name': name
|
960
699
|
}
|
961
700
|
|
962
701
|
## Insert.
|
963
|
-
self.
|
964
|
-
self.db_names['
|
702
|
+
self.db_wechat.execute.insert(
|
703
|
+
self.db_names['contact_user'],
|
965
704
|
data,
|
966
705
|
'update'
|
967
706
|
)
|
@@ -994,15 +733,14 @@ class WeChatDatabase(WeChatBase):
|
|
994
733
|
name = self.wechat.client.get_contact_name(message.room)
|
995
734
|
data = {
|
996
735
|
'room_id': message.room,
|
997
|
-
'name': name
|
998
|
-
'contact': 1
|
736
|
+
'name': name
|
999
737
|
}
|
1000
738
|
|
1001
739
|
## Insert.
|
1002
740
|
|
1003
741
|
### 'contact_room'.
|
1004
|
-
self.
|
1005
|
-
self.db_names['
|
742
|
+
self.db_wechat.execute.insert(
|
743
|
+
self.db_names['contact_room'],
|
1006
744
|
data,
|
1007
745
|
'update'
|
1008
746
|
)
|
@@ -1023,8 +761,8 @@ class WeChatDatabase(WeChatBase):
|
|
1023
761
|
}
|
1024
762
|
|
1025
763
|
## Update.
|
1026
|
-
self.
|
1027
|
-
self.db_names['
|
764
|
+
self.db_wechat.execute.update(
|
765
|
+
self.db_names['contact_room'],
|
1028
766
|
data
|
1029
767
|
)
|
1030
768
|
|
@@ -1045,8 +783,8 @@ class WeChatDatabase(WeChatBase):
|
|
1045
783
|
}
|
1046
784
|
|
1047
785
|
## Update.
|
1048
|
-
self.
|
1049
|
-
self.db_names['
|
786
|
+
self.db_wechat.execute.update(
|
787
|
+
self.db_names['contact_room'],
|
1050
788
|
data
|
1051
789
|
)
|
1052
790
|
|
@@ -1105,7 +843,7 @@ class WeChatDatabase(WeChatBase):
|
|
1105
843
|
if message.file is None:
|
1106
844
|
file_id = None
|
1107
845
|
else:
|
1108
|
-
file_id = self.
|
846
|
+
file_id = self.db_file.file.upload(
|
1109
847
|
message.file['path'],
|
1110
848
|
message.file['name'],
|
1111
849
|
'WeChat'
|
@@ -1125,8 +863,8 @@ class WeChatDatabase(WeChatBase):
|
|
1125
863
|
}
|
1126
864
|
|
1127
865
|
# Insert.
|
1128
|
-
self.
|
1129
|
-
self.db_names['
|
866
|
+
self.db_wechat.execute.insert(
|
867
|
+
self.db_names['message_receive'],
|
1130
868
|
data,
|
1131
869
|
'ignore'
|
1132
870
|
)
|
@@ -1168,8 +906,8 @@ class WeChatDatabase(WeChatBase):
|
|
1168
906
|
}
|
1169
907
|
|
1170
908
|
# Update.
|
1171
|
-
self.
|
1172
|
-
self.db_names['
|
909
|
+
self.db_wechat.execute.update(
|
910
|
+
self.db_names['message_send'],
|
1173
911
|
data
|
1174
912
|
)
|
1175
913
|
|
@@ -1195,7 +933,7 @@ class WeChatDatabase(WeChatBase):
|
|
1195
933
|
"""
|
1196
934
|
|
1197
935
|
# Information.
|
1198
|
-
file_info = self.
|
936
|
+
file_info = self.db_file.file.query(file_id)
|
1199
937
|
file_md5 = file_info['md5']
|
1200
938
|
file_name = file_info['name']
|
1201
939
|
|
@@ -1204,7 +942,7 @@ class WeChatDatabase(WeChatBase):
|
|
1204
942
|
|
1205
943
|
## Download.
|
1206
944
|
if cache_path is None:
|
1207
|
-
file_bytes = self.
|
945
|
+
file_bytes = self.db_file.file.download(file_id)
|
1208
946
|
cache_path = self.wechat.cache.store(file_bytes, file_name)
|
1209
947
|
|
1210
948
|
return cache_path, file_name
|
@@ -1224,23 +962,15 @@ class WeChatDatabase(WeChatBase):
|
|
1224
962
|
"""
|
1225
963
|
|
1226
964
|
# Set parameter.
|
1227
|
-
conn = self.
|
965
|
+
conn = self.db_wechat.connect()
|
1228
966
|
|
1229
967
|
# Read.
|
1230
|
-
where =
|
1231
|
-
'(\n'
|
1232
|
-
' `status` = 0\n'
|
1233
|
-
' AND (\n'
|
1234
|
-
' `plan_time` IS NULL\n'
|
1235
|
-
' OR `plan_time` < NOW()\n'
|
1236
|
-
' )\n'
|
1237
|
-
')'
|
1238
|
-
)
|
968
|
+
where = '`status` = 0'
|
1239
969
|
result = conn.execute.select(
|
1240
|
-
self.db_names['
|
970
|
+
self.db_names['message_send'],
|
1241
971
|
['send_id', 'type', 'receive_id', 'parameter', 'file_id'],
|
1242
972
|
where,
|
1243
|
-
order='`
|
973
|
+
order='`send_id`'
|
1244
974
|
)
|
1245
975
|
|
1246
976
|
# Convert.
|
@@ -1254,7 +984,7 @@ class WeChatDatabase(WeChatBase):
|
|
1254
984
|
for row in table
|
1255
985
|
]
|
1256
986
|
sql = (
|
1257
|
-
f'UPDATE `{self.
|
987
|
+
f'UPDATE `{self.db_wechat.database}`.`{self.db_names['message_send']}`\n'
|
1258
988
|
'SET `status` = 1\n'
|
1259
989
|
'WHERE `send_id` IN :send_ids'
|
1260
990
|
)
|
@@ -1321,8 +1051,8 @@ class WeChatDatabase(WeChatBase):
|
|
1321
1051
|
|
1322
1052
|
## User.
|
1323
1053
|
if message.room is None:
|
1324
|
-
result = message.receiver.wechat.
|
1325
|
-
self.db_names['
|
1054
|
+
result = message.receiver.wechat.db.db_wechat.execute.select(
|
1055
|
+
self.db_names['message_send'],
|
1326
1056
|
['valid'],
|
1327
1057
|
'`user_id` = :user_id',
|
1328
1058
|
limit=1,
|
@@ -1331,8 +1061,8 @@ class WeChatDatabase(WeChatBase):
|
|
1331
1061
|
|
1332
1062
|
## Room.
|
1333
1063
|
elif message.user is None:
|
1334
|
-
result = message.receiver.wechat.
|
1335
|
-
self.db_names['
|
1064
|
+
result = message.receiver.wechat.db.db_wechat.execute.select(
|
1065
|
+
self.db_names['message_send'],
|
1336
1066
|
['valid'],
|
1337
1067
|
'`room_id` = :room_id',
|
1338
1068
|
limit=1,
|
@@ -1344,19 +1074,19 @@ class WeChatDatabase(WeChatBase):
|
|
1344
1074
|
sql = (
|
1345
1075
|
'SELECT (\n'
|
1346
1076
|
' SELECT `valid`\n'
|
1347
|
-
f' FROM `{self.
|
1077
|
+
f' FROM `{self.db_wechat.database}`.`{self.db_names['contact_room_user']}`\n'
|
1348
1078
|
' WHERE `room_id` = :room_id AND `user_id` = :user_id\n'
|
1349
1079
|
' LIMIT 1\n'
|
1350
1080
|
') AS `valid`\n'
|
1351
1081
|
'FROM (\n'
|
1352
1082
|
' SELECT `valid`\n'
|
1353
|
-
f' FROM `{self.
|
1083
|
+
f' FROM `{self.db_wechat.database}`.`{self.db_names['contact_room']}`\n'
|
1354
1084
|
' WHERE `room_id` = :room_id\n'
|
1355
1085
|
' LIMIT 1\n'
|
1356
1086
|
') AS `a`\n'
|
1357
1087
|
'WHERE `valid` = 1'
|
1358
1088
|
)
|
1359
|
-
result = message.receiver.wechat.
|
1089
|
+
result = message.receiver.wechat.db.db_wechat.execute(
|
1360
1090
|
sql,
|
1361
1091
|
room_id=message.room,
|
1362
1092
|
user_id=message.user
|
@@ -1398,7 +1128,7 @@ class WeChatDatabase(WeChatBase):
|
|
1398
1128
|
## Cache.
|
1399
1129
|
cache_path = self.wechat.cache.store(file_path, file_name)
|
1400
1130
|
|
1401
|
-
file_id = self.
|
1131
|
+
file_id = self.db_file.file.upload(
|
1402
1132
|
cache_path,
|
1403
1133
|
file_name,
|
1404
1134
|
'WeChat'
|
@@ -1408,7 +1138,7 @@ class WeChatDatabase(WeChatBase):
|
|
1408
1138
|
data['file_id'] = file_id
|
1409
1139
|
|
1410
1140
|
# Insert.
|
1411
|
-
self.
|
1412
|
-
self.db_names['
|
1141
|
+
self.db_wechat.execute.insert(
|
1142
|
+
self.db_names['message_send'],
|
1413
1143
|
data
|
1414
1144
|
)
|
reywechat/rreceive.py
CHANGED
@@ -1461,7 +1461,7 @@ class WeChatMessage(WeChatBase):
|
|
1461
1461
|
return self._cache['valid']
|
1462
1462
|
|
1463
1463
|
# Judge.
|
1464
|
-
self._cache['valid'] = self.receiver.wechat.
|
1464
|
+
self._cache['valid'] = self.receiver.wechat.db.is_valid(self)
|
1465
1465
|
|
1466
1466
|
return self._cache['valid']
|
1467
1467
|
|
reywechat/rsend.py
CHANGED
reywechat/rwechat.py
CHANGED
@@ -40,7 +40,7 @@ class WeChat(WeChatBase):
|
|
40
40
|
|
41
41
|
def __init__(
|
42
42
|
self,
|
43
|
-
|
43
|
+
db: Database | dict[Literal['wechat', 'file'], Database] | None,
|
44
44
|
max_receiver: int = 2,
|
45
45
|
call_name: str | None = None,
|
46
46
|
project_dir: str | None = None
|
@@ -50,7 +50,7 @@ class WeChat(WeChatBase):
|
|
50
50
|
|
51
51
|
Parameters
|
52
52
|
----------
|
53
|
-
|
53
|
+
db : `Database` instance of `reykit` package.
|
54
54
|
- `Database`, Set all `Database`: instances.
|
55
55
|
- `dict`, Set each `Database`: instance, all item is required.
|
56
56
|
`Key 'wechat'`: `Database` instance used in WeChat methods.
|
@@ -81,7 +81,7 @@ class WeChat(WeChatBase):
|
|
81
81
|
self.receiver = WechatReceiver(self, max_receiver, call_name)
|
82
82
|
self.trigger = self.receiver.trigger
|
83
83
|
self.sender = WeChatSender(self)
|
84
|
-
self.
|
84
|
+
self.db = WeChatDatabase(self, db)
|
85
85
|
|
86
86
|
## Client.
|
87
87
|
self.client_version = self.client.client_version
|
@@ -109,7 +109,7 @@ class WeChat(WeChatBase):
|
|
109
109
|
self.wrap_try_send = self.sender.wrap_try_send
|
110
110
|
|
111
111
|
## Database.
|
112
|
-
self.database_build = self.
|
112
|
+
self.database_build = self.db.build_db
|
113
113
|
|
114
114
|
|
115
115
|
def start(self) -> None:
|
@@ -3,14 +3,14 @@ reywechat/rall.py,sha256=5J_X-XMOyb1Vp1jyS9-oRFXGOtp2vRPX1g3tJot_Eck,371
|
|
3
3
|
reywechat/rbase.py,sha256=hbxn5spvcl_C_Bw8A9teulOXT9GMlxUw145_YbXIOzc,1124
|
4
4
|
reywechat/rcache.py,sha256=5FIa8UB3VsLHT_EXHHmFP62a5AeS22anJCJXC8t4tWw,908
|
5
5
|
reywechat/rclient.py,sha256=j4ktgD2l1W9ktrTtfQfyIXCxc7KnT-gvqgy8-zRq8IU,22655
|
6
|
-
reywechat/rdb.py,sha256
|
6
|
+
reywechat/rdb.py,sha256=-tZ1xzWKgDnt_sYLNQqmqMigrv8vdWpafJoismO33AA,39942
|
7
7
|
reywechat/rlog.py,sha256=JnzuSfQCKnvASPjZw9KrLTX9TjT79KLbciu8XeIA_88,5256
|
8
|
-
reywechat/rreceive.py,sha256=
|
9
|
-
reywechat/rsend.py,sha256=
|
8
|
+
reywechat/rreceive.py,sha256=PjDdbF5tJh-bj2p_DxwYKXfk6dDkmv4s8W77Z1ODE1M,50960
|
9
|
+
reywechat/rsend.py,sha256=m3TvKlmBKK8KTsM85DeWIHbhVTRWbLMetBAU-zBYkAc,20064
|
10
10
|
reywechat/rtrigger.py,sha256=gDnokfFjw29Kz9qazxtb2clT2pBsuOJqIEErvg7L3hE,4986
|
11
|
-
reywechat/rwechat.py,sha256=
|
11
|
+
reywechat/rwechat.py,sha256=xOxki5zFq145V-Ii3q8cFnJkCm8joCftgbbekGoCel0,4718
|
12
12
|
reywechat/data/client_api.dll,sha256=H9uj-x9Ztg0jFZK0yY6NsnyH5_119dQRFfoVVMidxRs,592384
|
13
|
-
reywechat-1.0.
|
14
|
-
reywechat-1.0.
|
15
|
-
reywechat-1.0.
|
16
|
-
reywechat-1.0.
|
13
|
+
reywechat-1.0.81.dist-info/METADATA,sha256=rlyCxhuW3cUbQaXedNeU_phFAohqkXBfZr0amsicEgw,1551
|
14
|
+
reywechat-1.0.81.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
15
|
+
reywechat-1.0.81.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
16
|
+
reywechat-1.0.81.dist-info/RECORD,,
|
File without changes
|
File without changes
|