oira666_tg 1.0.2 → 1.0.4
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.
- package/middleware/message_info.js +1 -1
- package/middleware/session.js +1 -1
- package/package.json +1 -1
- package/source/classes/MessageInfo.js +1 -1
- package/source/classes/TelegramSession.js +29 -28
- package/source/classes/TextButtons.js +2 -1
- package/source/classes/User.js +2 -1
- package/source/handlers/id.js +1 -1
- package/source/handlers/test.js +1 -1
- package/utils/regexps.js +1 -1
- package/utils/send_empty_message.js +1 -3
- package/.eslintignore:Zone.Identifier +0 -0
- package/.eslintrc.js:Zone.Identifier +0 -0
- package/apply_middlewares_cron +0 -0
- package/source/classes/WaitMessage.js:Zone.Identifier +0 -0
package/middleware/session.js
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const _ = require('lodash');
|
|
2
2
|
const moment = require('moment');
|
|
3
|
-
const { options } = require('
|
|
4
|
-
|
|
3
|
+
const { options } = require('../../options');
|
|
4
|
+
|
|
5
|
+
const { db } = options;
|
|
5
6
|
|
|
6
7
|
class TelegramSession {
|
|
7
|
-
constructor
|
|
8
|
+
constructor(from_id, chat_id) {
|
|
8
9
|
this.session_key = `${from_id}:${chat_id}`;
|
|
9
10
|
this.user_id = +from_id || 0;
|
|
10
11
|
this._data = null;
|
|
@@ -13,33 +14,33 @@ class TelegramSession {
|
|
|
13
14
|
this._keyboard = null;
|
|
14
15
|
}
|
|
15
16
|
|
|
17
|
+
set data(value) {
|
|
18
|
+
this._data = !_.isEmpty(value) ? value : null;
|
|
19
|
+
}
|
|
20
|
+
|
|
16
21
|
get data() {
|
|
17
22
|
return !_.isEmpty(this._data) ? this._data : {};
|
|
18
23
|
}
|
|
19
24
|
|
|
25
|
+
set keyboard(value) {
|
|
26
|
+
this._keyboard = Array.isArray(value) && !_.isEmpty(value) ? value : null;
|
|
27
|
+
}
|
|
28
|
+
|
|
20
29
|
get keyboard() {
|
|
21
30
|
return !_.isEmpty(this._keyboard) ? this._keyboard : [];
|
|
22
31
|
}
|
|
23
32
|
|
|
33
|
+
set handler_history(value) {
|
|
34
|
+
this._handler_history = !_.isEmpty(value) ? value : null;
|
|
35
|
+
}
|
|
36
|
+
|
|
24
37
|
get handler_history() {
|
|
25
38
|
return !_.isEmpty(this._handler_history) ? this._handler_history : [];
|
|
26
39
|
}
|
|
27
40
|
|
|
28
41
|
get expected_input() {
|
|
29
|
-
return +moment() - +moment(this._expected_input?.dt_create) <= options.expected_input_lifetime
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
set data(value) {
|
|
34
|
-
this._data = !_.isEmpty(value) ? value : null;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
set keyboard(value) {
|
|
38
|
-
this._keyboard = Array.isArray(value) && !_.isEmpty(value) ? value : null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
set handler_history(value) {
|
|
42
|
-
this._handler_history = !_.isEmpty(value) ? value : null;
|
|
42
|
+
return +moment() - +moment(this._expected_input?.dt_create) <= options.expected_input_lifetime
|
|
43
|
+
? this._expected_input?.action || null : null;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
set expected_input(value) {
|
|
@@ -47,17 +48,18 @@ class TelegramSession {
|
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
async save() {
|
|
50
|
-
if (!
|
|
51
|
+
if (!this.session_key) return;
|
|
51
52
|
|
|
52
53
|
if (_.isEmpty(this._data) && _.isEmpty(this._handler_history) && _.isEmpty(this._expected_input)) {
|
|
53
54
|
await this._deleteSession();
|
|
54
|
-
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
55
57
|
await this._saveSession();
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
async _saveSession() {
|
|
60
|
-
if (!
|
|
62
|
+
if (!this.session_key) return;
|
|
61
63
|
|
|
62
64
|
const query = `
|
|
63
65
|
INSERT INTO session (session_key, user_id, data, keyboard, handler_history, expected_input, dt_access)
|
|
@@ -76,27 +78,27 @@ class TelegramSession {
|
|
|
76
78
|
keyboard: _.isEmpty(this._keyboard) ? null : JSON.stringify(this._keyboard),
|
|
77
79
|
handler_history: _.isEmpty(this._handler_history) ? null : JSON.stringify(this._handler_history),
|
|
78
80
|
expected_input: _.isEmpty(this._expected_input) ? null : JSON.stringify(this._expected_input),
|
|
79
|
-
dt_access: new Date()
|
|
80
|
-
}
|
|
81
|
+
dt_access: new Date(),
|
|
82
|
+
};
|
|
81
83
|
await db.query(query, params);
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
async _deleteSession() {
|
|
85
|
-
if (!
|
|
87
|
+
if (!this.session_key) return;
|
|
86
88
|
|
|
87
|
-
const query =
|
|
88
|
-
await db.query(query, {session_key: this.session_key});
|
|
89
|
+
const query = 'DELETE FROM telegram_session WHERE session_key = :session_key';
|
|
90
|
+
await db.query(query, { session_key: this.session_key });
|
|
89
91
|
}
|
|
90
92
|
|
|
91
93
|
async load() {
|
|
92
|
-
if (!
|
|
94
|
+
if (!this.session_key) return;
|
|
93
95
|
|
|
94
96
|
const query = `
|
|
95
97
|
SELECT *
|
|
96
98
|
FROM session
|
|
97
99
|
WHERE session_key = :session_key
|
|
98
100
|
`;
|
|
99
|
-
const data = await db.query(query, {session_key: this.session_key});
|
|
101
|
+
const data = await db.query(query, { session_key: this.session_key });
|
|
100
102
|
|
|
101
103
|
if (!_.isEmpty(data)) {
|
|
102
104
|
this._data = data[0].data ? JSON.parse(data[0].data) : null;
|
|
@@ -105,7 +107,6 @@ class TelegramSession {
|
|
|
105
107
|
this._expected_input = data[0].expected_input ? JSON.parse(data[0].expected_input) : null;
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
|
-
|
|
109
110
|
}
|
|
110
111
|
|
|
111
112
|
module.exports.TelegramSession = TelegramSession;
|
package/source/classes/User.js
CHANGED
package/source/handlers/id.js
CHANGED
package/source/handlers/test.js
CHANGED
package/utils/regexps.js
CHANGED
|
File without changes
|
|
File without changes
|
package/apply_middlewares_cron
DELETED
|
File without changes
|
|
File without changes
|