nexushub-commands 1.0.4 → 1.1.0

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.
@@ -1,4 +1,4 @@
1
1
  import { Command, CommandContext } from 'evogram/lib/migrated';
2
2
  export declare class CheckPaidOrderCommand extends Command {
3
- execute(context: CommandContext, orderId: string): Promise<any>;
3
+ execute(context: CommandContext, orderId: string): Promise<void>;
4
4
  }
@@ -5,60 +5,17 @@ const tslib_1 = require("tslib");
5
5
  const evogram_1 = require("evogram");
6
6
  const migrated_1 = require("evogram/lib/migrated");
7
7
  const Client_1 = require("../../Client");
8
- const axios_1 = tslib_1.__importDefault(require("axios"));
9
8
  const qs = require('qs');
10
9
  let CheckPaidOrderCommand = class CheckPaidOrderCommand extends migrated_1.Command {
11
10
  execute(context, orderId) {
12
11
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
13
- var _a;
14
12
  const config = Client_1.Client.config(context);
15
13
  yield config.API.get(`/orders/${orderId}/checkPaid`).catch(() => { });
16
14
  const order = yield config.API.get(`/orders/${orderId}`).then((x) => x.data);
17
- if (!order.cheque || ['card', 'qrcode'].includes(order.method))
18
- return context.sendFormattedQuestion({
19
- photo: config.images.depositCard,
20
- header: '<blockquote>🧾 Подтверждение оплаты счета</blockquote>',
21
- footer: '<i>Пожалуйста, отправьте чек, подтверждающий оплату счета в следующем сообщении</i>',
22
- }, undefined, (msg) => tslib_1.__awaiter(this, void 0, void 0, function* () {
23
- var _a, _b;
24
- let url = null;
25
- if ((_a = msg.attachments.photo) === null || _a === void 0 ? void 0 : _a.length) {
26
- url = `https://api.telegram.org/file/bot${this.client.params.token}/${(yield this.client.api.getFile({ file_id: msg.attachments.photo.at(-1).file_id })).file_path}`;
27
- }
28
- else if (msg.attachments.document) {
29
- if (!((_b = msg.attachments.document.mime_type) === null || _b === void 0 ? void 0 : _b.startsWith('image/')))
30
- throw new Error('Ваш файл не является изображением');
31
- url = `https://api.telegram.org/file/bot${this.client.params.token}/${(yield this.client.api.getFile({ file_id: msg.attachments.document.file_id })).file_path}`;
32
- }
33
- const photoURL = yield axios_1.default
34
- .request({
35
- method: 'POST',
36
- url: `https://catbox.moe/user/api.php`,
37
- maxBodyLength: Infinity,
38
- headers: {
39
- 'Content-Type': 'application/x-www-form-urlencoded',
40
- },
41
- data: qs.stringify({
42
- url,
43
- reqtype: 'urlupload',
44
- }),
45
- })
46
- .then((x) => x.data);
47
- yield config.API.put(`/orders/${orderId}`, {
48
- cheque: photoURL,
49
- });
50
- return context.sendFormatted({
51
- photo: photoURL,
52
- header: '<blockquote>🧾 Подтверждение оплаты счета</blockquote>',
53
- footer: '<i>Ваш чек был успешно отправлен, ожидайте подтверждения. Вы получите уведомление, как только оплата будет подтверждена</i>',
54
- }, {
55
- noBackButton: true,
56
- });
57
- }));
58
- if (order.data.status !== 'paid' && order.data.status !== 'fakepaid')
59
- throw new Error('Счет еще не оплачен');
15
+ if (['paid', 'fakepaid'].includes(order.status))
16
+ throw new Error('Счет уже оплачен');
60
17
  else
61
- (_a = context.callbackQuery) === null || _a === void 0 ? void 0 : _a.answer({ text: 'Счет оплачен', show_alert: true });
18
+ throw new Error('Счет ожидает оплаты');
62
19
  });
63
20
  }
64
21
  };
@@ -65,12 +65,14 @@ let DepositCommand = class DepositCommand extends evogram_1.Command {
65
65
  });
66
66
  }
67
67
  if (!order.isRepeat)
68
- yield context.user.log(0, `Запросил пополнение на ${Number(order.amount).toLocaleString('ru')} ${order.currency} (${yield order.amount.convert({
69
- from: order.currency,
70
- to: 'RUB',
71
- ceiled: true,
72
- })})`, {
73
- keyboard: [[{ text: '🚀 Оплатить счет', callback_data: `paidOrder?orderId=${order.id}` }]],
68
+ yield context.user.log(0, `Запросил пополнение на ${Number(order.amount).toLocaleString('ru')} ${order.currency} ${order.currency !== 'RUB'
69
+ ? `(${yield order.amount.convert({
70
+ from: order.currency,
71
+ to: 'RUB',
72
+ ceiled: true,
73
+ })})`
74
+ : ''}`, {
75
+ keyboard: [[{ text: '🚀 Оплатить счет', callback_data: `PaidOrderCommand?orderId=${order.id}` }]],
74
76
  });
75
77
  return context.redirect(GetDepositOrder_command_1.GetDepositOrderCommand, { orderId: order.id });
76
78
  }
@@ -6,6 +6,7 @@ const evogram_1 = require("evogram");
6
6
  const migrated_1 = require("evogram/lib/migrated");
7
7
  const Client_1 = require("../../Client");
8
8
  const CheckPaidOrder_command_1 = require("./CheckPaidOrder.command");
9
+ const SendCheque_command_1 = require("./SendCheque.command");
9
10
  let GetDepositOrderCommand = class GetDepositOrderCommand extends evogram_1.Command {
10
11
  execute(context, orderId) {
11
12
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
@@ -60,7 +61,12 @@ let GetDepositOrderCommand = class GetDepositOrderCommand extends evogram_1.Comm
60
61
  footer: '<i>Реквизиты действительны 10 минут.</i>',
61
62
  }, {
62
63
  reply_markup: {
63
- inline_keyboard: [[{ text: '🔄 Проверить оплату', command: CheckPaidOrder_command_1.CheckPaidOrderCommand, payload: { orderId: order.id } }]],
64
+ inline_keyboard: [
65
+ [
66
+ { text: '🔄 Проверить оплату', command: CheckPaidOrder_command_1.CheckPaidOrderCommand, payload: { orderId: order.id } },
67
+ { text: '✅ Я оплатил', command: SendCheque_command_1.SendChequeCommand, payload: { orderId: order.id } },
68
+ ],
69
+ ],
64
70
  },
65
71
  });
66
72
  case 'qrcode':
@@ -72,7 +78,10 @@ let GetDepositOrderCommand = class GetDepositOrderCommand extends evogram_1.Comm
72
78
  reply_markup: {
73
79
  inline_keyboard: [
74
80
  [{ text: '🔗 Перейти к оплате', url: order.qrcode.link }],
75
- [{ text: '🔄 Проверить оплату', command: CheckPaidOrder_command_1.CheckPaidOrderCommand, payload: { orderId: order.id } }],
81
+ [
82
+ { text: '🔄 Проверить оплату', command: CheckPaidOrder_command_1.CheckPaidOrderCommand, payload: { orderId: order.id } },
83
+ { text: '✅ Я оплатил', command: SendCheque_command_1.SendChequeCommand, payload: { orderId: order.id } },
84
+ ],
76
85
  ],
77
86
  },
78
87
  });
@@ -0,0 +1,4 @@
1
+ import { Command, CommandContext } from 'evogram/lib/migrated';
2
+ export declare class SendChequeCommand extends Command {
3
+ execute(context: CommandContext, orderId: string): Promise<any>;
4
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SendChequeCommand = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const evogram_1 = require("evogram");
6
+ const migrated_1 = require("evogram/lib/migrated");
7
+ const Client_1 = require("../../Client");
8
+ const axios_1 = tslib_1.__importDefault(require("axios"));
9
+ const qs = require('qs');
10
+ let SendChequeCommand = class SendChequeCommand extends migrated_1.Command {
11
+ execute(context, orderId) {
12
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
13
+ const config = Client_1.Client.config(context);
14
+ yield config.API.get(`/orders/${orderId}/checkPaid`).catch(() => { });
15
+ const order = yield config.API.get(`/orders/${orderId}`).then((x) => x.data);
16
+ if (['paid', 'fakepaid'].includes(order.status))
17
+ throw new Error('Счет уже оплачен');
18
+ if (!order.cheque && ['card', 'qrcode'].includes(order.method))
19
+ return context.sendFormattedQuestion({
20
+ photo: config.images.depositCard,
21
+ header: '<blockquote><b>🧾 Подтверждение оплаты счета</b></blockquote>',
22
+ footer: '<i>Пожалуйста, отправьте квитанцию, подтверждающую оплату счета в следующем сообщении</i>',
23
+ }, undefined, (msg) => tslib_1.__awaiter(this, void 0, void 0, function* () {
24
+ var _a, _b;
25
+ let url = null;
26
+ if ((_a = msg.attachments.photo) === null || _a === void 0 ? void 0 : _a.length) {
27
+ url = `https://api.telegram.org/file/bot${this.client.params.token}/${(yield this.client.api.getFile({ file_id: msg.attachments.photo.at(-1).file_id })).file_path}`;
28
+ }
29
+ else if (msg.attachments.document) {
30
+ if (!((_b = msg.attachments.document.mime_type) === null || _b === void 0 ? void 0 : _b.startsWith('image/')))
31
+ throw new Error('Ваш файл не является изображением');
32
+ url = `https://api.telegram.org/file/bot${this.client.params.token}/${(yield this.client.api.getFile({ file_id: msg.attachments.document.file_id })).file_path}`;
33
+ }
34
+ if (!url)
35
+ throw new Error('Пожалуйста, отправьте изображение с квитанцией в следующем сообщении');
36
+ const photoURL = yield axios_1.default
37
+ .request({
38
+ method: 'POST',
39
+ url: `https://catbox.moe/user/api.php`,
40
+ maxBodyLength: Infinity,
41
+ headers: {
42
+ 'Content-Type': 'application/x-www-form-urlencoded',
43
+ },
44
+ data: qs.stringify({
45
+ url,
46
+ reqtype: 'urlupload',
47
+ }),
48
+ })
49
+ .then((x) => x.data);
50
+ yield config.API.put(`/orders/${orderId}`, {
51
+ cheque: photoURL,
52
+ });
53
+ return context.sendFormatted({
54
+ photo: photoURL,
55
+ header: '<blockquote><b>🧾 Подтверждение оплаты счета</b></blockquote>',
56
+ footer: '<i>Ваш чек был успешно отправлен, ожидайте подтверждения. Вы получите уведомление, как только оплата будет подтверждена</i>',
57
+ }, {
58
+ noBackButton: true,
59
+ });
60
+ }));
61
+ });
62
+ }
63
+ };
64
+ exports.SendChequeCommand = SendChequeCommand;
65
+ tslib_1.__decorate([
66
+ tslib_1.__param(1, (0, evogram_1.CommandArgument)('orderId')),
67
+ tslib_1.__metadata("design:type", Function),
68
+ tslib_1.__metadata("design:paramtypes", [migrated_1.CommandContext, String]),
69
+ tslib_1.__metadata("design:returntype", Promise)
70
+ ], SendChequeCommand.prototype, "execute", null);
71
+ exports.SendChequeCommand = SendChequeCommand = tslib_1.__decorate([
72
+ (0, evogram_1.CommandD)({ name: 'sendCheque' })
73
+ ], SendChequeCommand);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexushub-commands",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "main": "./lib/index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -12,61 +12,7 @@ export class CheckPaidOrderCommand extends Command {
12
12
  await config.API.get(`/orders/${orderId}/checkPaid`).catch(() => {});
13
13
  const order = await config.API.get(`/orders/${orderId}`).then((x) => x.data);
14
14
 
15
- if (!order.cheque || ['card', 'qrcode'].includes(order.method))
16
- return context.sendFormattedQuestion(
17
- {
18
- photo: config.images.depositCard,
19
- header: '<blockquote>🧾 Подтверждение оплаты счета</blockquote>',
20
- footer: '<i>Пожалуйста, отправьте чек, подтверждающий оплату счета в следующем сообщении</i>',
21
- },
22
- undefined,
23
- async (msg) => {
24
- let url: any = null;
25
- if (msg.attachments.photo?.length) {
26
- url = `https://api.telegram.org/file/bot${this.client.params.token}/${
27
- (await this.client.api.getFile({ file_id: msg.attachments.photo.at(-1)!.file_id })).file_path
28
- }`;
29
- } else if (msg.attachments.document) {
30
- if (!msg.attachments.document.mime_type?.startsWith('image/')) throw new Error('Ваш файл не является изображением');
31
-
32
- url = `https://api.telegram.org/file/bot${this.client.params.token}/${
33
- (await this.client.api.getFile({ file_id: msg.attachments.document.file_id })).file_path
34
- }`;
35
- }
36
-
37
- const photoURL = await axios
38
- .request({
39
- method: 'POST',
40
- url: `https://catbox.moe/user/api.php`,
41
- maxBodyLength: Infinity,
42
- headers: {
43
- 'Content-Type': 'application/x-www-form-urlencoded',
44
- },
45
- data: qs.stringify({
46
- url,
47
- reqtype: 'urlupload',
48
- }),
49
- })
50
- .then((x) => x.data);
51
-
52
- await config.API.put(`/orders/${orderId}`, {
53
- cheque: photoURL,
54
- });
55
-
56
- return context.sendFormatted(
57
- {
58
- photo: photoURL,
59
- header: '<blockquote>🧾 Подтверждение оплаты счета</blockquote>',
60
- footer: '<i>Ваш чек был успешно отправлен, ожидайте подтверждения. Вы получите уведомление, как только оплата будет подтверждена</i>',
61
- },
62
- {
63
- noBackButton: true,
64
- }
65
- );
66
- }
67
- );
68
-
69
- if (order.data.status !== 'paid' && order.data.status !== 'fakepaid') throw new Error('Счет еще не оплачен');
70
- else context.callbackQuery?.answer({ text: 'Счет оплачен', show_alert: true });
15
+ if (['paid', 'fakepaid'].includes(order.status)) throw new Error('Счет уже оплачен');
16
+ else throw new Error('Счет ожидает оплаты');
71
17
  }
72
18
  }
@@ -210,13 +210,17 @@ export class DepositCommand extends Command {
210
210
  if (!order.isRepeat)
211
211
  await context.user.log(
212
212
  0,
213
- `Запросил пополнение на ${Number(order.amount).toLocaleString('ru')} ${order.currency} (${await order.amount.convert({
214
- from: order.currency,
215
- to: 'RUB',
216
- ceiled: true,
217
- })})`,
213
+ `Запросил пополнение на ${Number(order.amount).toLocaleString('ru')} ${order.currency} ${
214
+ order.currency !== 'RUB'
215
+ ? `(${await order.amount.convert({
216
+ from: order.currency,
217
+ to: 'RUB',
218
+ ceiled: true,
219
+ })})`
220
+ : ''
221
+ }`,
218
222
  {
219
- keyboard: [[{ text: '🚀 Оплатить счет', callback_data: `paidOrder?orderId=${order.id}` }]],
223
+ keyboard: [[{ text: '🚀 Оплатить счет', callback_data: `PaidOrderCommand?orderId=${order.id}` }]],
220
224
  }
221
225
  );
222
226
 
@@ -2,6 +2,7 @@ import { Command, CommandArgument, CommandD } from 'evogram';
2
2
  import { CommandContext } from 'evogram/lib/migrated';
3
3
  import { Client } from '../../Client';
4
4
  import { CheckPaidOrderCommand } from './CheckPaidOrder.command';
5
+ import { SendChequeCommand } from './SendCheque.command';
5
6
 
6
7
  @CommandD({ name: 'getDepositOrder', backButton: 'К пополнению' })
7
8
  export class GetDepositOrderCommand extends Command {
@@ -63,7 +64,12 @@ export class GetDepositOrderCommand extends Command {
63
64
  },
64
65
  {
65
66
  reply_markup: {
66
- inline_keyboard: [[{ text: '🔄 Проверить оплату', command: CheckPaidOrderCommand, payload: { orderId: order.id } }]],
67
+ inline_keyboard: [
68
+ [
69
+ { text: '🔄 Проверить оплату', command: CheckPaidOrderCommand, payload: { orderId: order.id } },
70
+ { text: '✅ Я оплатил', command: SendChequeCommand, payload: { orderId: order.id } },
71
+ ],
72
+ ],
67
73
  },
68
74
  }
69
75
  );
@@ -78,7 +84,10 @@ export class GetDepositOrderCommand extends Command {
78
84
  reply_markup: {
79
85
  inline_keyboard: [
80
86
  [{ text: '🔗 Перейти к оплате', url: order.qrcode.link }],
81
- [{ text: '🔄 Проверить оплату', command: CheckPaidOrderCommand, payload: { orderId: order.id } }],
87
+ [
88
+ { text: '🔄 Проверить оплату', command: CheckPaidOrderCommand, payload: { orderId: order.id } },
89
+ { text: '✅ Я оплатил', command: SendChequeCommand, payload: { orderId: order.id } },
90
+ ],
82
91
  ],
83
92
  },
84
93
  }
@@ -0,0 +1,72 @@
1
+ import { CommandArgument, CommandD } from 'evogram';
2
+ import { Command, CommandContext } from 'evogram/lib/migrated';
3
+ import { Client } from '../../Client';
4
+ import axios from 'axios';
5
+ const qs = require('qs');
6
+
7
+ @CommandD({ name: 'sendCheque' })
8
+ export class SendChequeCommand extends Command {
9
+ public async execute(context: CommandContext, @CommandArgument('orderId') orderId: string) {
10
+ const config = Client.config(context);
11
+
12
+ await config.API.get(`/orders/${orderId}/checkPaid`).catch(() => {});
13
+ const order = await config.API.get(`/orders/${orderId}`).then((x) => x.data);
14
+
15
+ if (['paid', 'fakepaid'].includes(order.status)) throw new Error('Счет уже оплачен');
16
+
17
+ if (!order.cheque && ['card', 'qrcode'].includes(order.method))
18
+ return context.sendFormattedQuestion(
19
+ {
20
+ photo: config.images.depositCard,
21
+ header: '<blockquote><b>🧾 Подтверждение оплаты счета</b></blockquote>',
22
+ footer: '<i>Пожалуйста, отправьте квитанцию, подтверждающую оплату счета в следующем сообщении</i>',
23
+ },
24
+ undefined,
25
+ async (msg) => {
26
+ let url: any = null;
27
+ if (msg.attachments.photo?.length) {
28
+ url = `https://api.telegram.org/file/bot${this.client.params.token}/${
29
+ (await this.client.api.getFile({ file_id: msg.attachments.photo.at(-1)!.file_id })).file_path
30
+ }`;
31
+ } else if (msg.attachments.document) {
32
+ if (!msg.attachments.document.mime_type?.startsWith('image/')) throw new Error('Ваш файл не является изображением');
33
+
34
+ url = `https://api.telegram.org/file/bot${this.client.params.token}/${
35
+ (await this.client.api.getFile({ file_id: msg.attachments.document.file_id })).file_path
36
+ }`;
37
+ }
38
+
39
+ if (!url) throw new Error('Пожалуйста, отправьте изображение с квитанцией в следующем сообщении');
40
+ const photoURL = await axios
41
+ .request({
42
+ method: 'POST',
43
+ url: `https://catbox.moe/user/api.php`,
44
+ maxBodyLength: Infinity,
45
+ headers: {
46
+ 'Content-Type': 'application/x-www-form-urlencoded',
47
+ },
48
+ data: qs.stringify({
49
+ url,
50
+ reqtype: 'urlupload',
51
+ }),
52
+ })
53
+ .then((x) => x.data);
54
+
55
+ await config.API.put(`/orders/${orderId}`, {
56
+ cheque: photoURL,
57
+ });
58
+
59
+ return context.sendFormatted(
60
+ {
61
+ photo: photoURL,
62
+ header: '<blockquote><b>🧾 Подтверждение оплаты счета</b></blockquote>',
63
+ footer: '<i>Ваш чек был успешно отправлен, ожидайте подтверждения. Вы получите уведомление, как только оплата будет подтверждена</i>',
64
+ },
65
+ {
66
+ noBackButton: true,
67
+ }
68
+ );
69
+ }
70
+ );
71
+ }
72
+ }