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.
@@ -7,7 +7,7 @@ const { MessageInfoManager } = require('../source/classes/MessageInfoManager');
7
7
  // messageInfo.clean(); // delete data
8
8
 
9
9
 
10
- export default async (ctx, next) => {
10
+ module.exports = async (ctx, next) => {
11
11
  if (!ctx.from) {
12
12
  await next();
13
13
  return;
@@ -1,7 +1,7 @@
1
1
  const _ = require('lodash');
2
2
  const { TelegramSession } = require('../source/classes/TelegramSession');
3
3
 
4
- export default async (ctx, next) => {
4
+ module.exports = async (ctx, next) => {
5
5
  if (!ctx.from) {
6
6
  await next();
7
7
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oira666_tg",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "tg framework for oira666",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,5 +1,5 @@
1
1
  const _ = require('lodash');
2
- const { options } = require('../options');
2
+ const { options } = require('../../options');
3
3
  const db = options.db;
4
4
 
5
5
 
@@ -1,10 +1,11 @@
1
1
  const _ = require('lodash');
2
2
  const moment = require('moment');
3
- const { options } = require('../options');
4
- const db = options.db;
3
+ const { options } = require('../../options');
4
+
5
+ const { db } = options;
5
6
 
6
7
  class TelegramSession {
7
- constructor (from_id, chat_id) {
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
- this._expected_input?.action || null : null;
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 (! this.session_key) return;
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
- } else {
55
+ }
56
+ else {
55
57
  await this._saveSession();
56
58
  }
57
59
  }
58
60
 
59
61
  async _saveSession() {
60
- if (! this.session_key) return;
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 (! this.session_key) return;
87
+ if (!this.session_key) return;
86
88
 
87
- const query = `DELETE FROM telegram_session WHERE session_key = :session_key`;
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 (! this.session_key) return;
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;
@@ -1,4 +1,5 @@
1
- const { options } = require('../options');
1
+ const { options } = require('../../options');
2
+
2
3
  const Markup = options.Markup;
3
4
 
4
5
 
@@ -1,5 +1,6 @@
1
1
  import _ from 'lodash';
2
- const { options } = require('../options');
2
+ const { options } = require('../../options');
3
+
3
4
  const db = options.db;
4
5
 
5
6
  class User {
@@ -1,4 +1,4 @@
1
- export default async (ctx) => {
1
+ module.exports = async (ctx) => {
2
2
  await ctx.telegram.sendMessage(
3
3
  ctx.chat.id,
4
4
  ctx.t`ID Твоего пользователя в телеграме: ${ctx.from.id}\nID этого чата в телеграме: ${ctx.chat.id}`,
@@ -1,4 +1,4 @@
1
- export default async (ctx) => {
1
+ module.exports = async (ctx) => {
2
2
  try {
3
3
  await ctx.telegram.sendMessage(
4
4
  ctx.chat.id,
package/utils/regexps.js CHANGED
@@ -3,6 +3,6 @@ const regexps = {
3
3
  handlername: /^[a-zA-Z\/\d_]+$/,
4
4
  url: /^https?:\/\/.+\.[A-Za-zА-Яа-я]{2,5}((\/|\?).*)?$/,
5
5
  handlername_args: /^[a-zA-Z_\/]+(\s.+)?$/,
6
- }
6
+ };
7
7
 
8
8
  module.exports.regexps = regexps;
@@ -2,9 +2,7 @@ const send_empty_message = async (ctx, message_text) => {
2
2
  const message = await ctx.telegram.sendMessage(
3
3
  ctx.chat.id,
4
4
  message_text,
5
- {
6
- parse_mode: 'HTML',
7
- }
5
+ { parse_mode: 'HTML' }
8
6
  );
9
7
  return message.message_id;
10
8
  };
File without changes
File without changes
File without changes
File without changes