nexushub-commands 1.5.8 → 1.6.1
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/lib/commands/deposit/Deposit.command.js +2 -0
- package/lib/commands/deposit/DepositByPromocode.command.d.ts +5 -0
- package/lib/commands/deposit/DepositByPromocode.command.js +47 -0
- package/package.json +1 -1
- package/src/commands/deposit/Deposit.command.ts +2 -0
- package/src/commands/deposit/DepositByPromocode.command.ts +50 -0
|
@@ -7,6 +7,7 @@ const migrated_1 = require("evogram/lib/migrated");
|
|
|
7
7
|
const Client_1 = require("../../Client");
|
|
8
8
|
const formatMessage_1 = require("../../utils/formatMessage");
|
|
9
9
|
const CheckPaidOrder_command_1 = require("./CheckPaidOrder.command");
|
|
10
|
+
const DepositByPromocode_command_1 = require("./DepositByPromocode.command");
|
|
10
11
|
const GetDepositOrder_command_1 = require("./GetDepositOrder.command");
|
|
11
12
|
// Функция для маскировки реквизитов: оставляет только последние 4 не пробельных символа
|
|
12
13
|
function maskExceptLast4(str) {
|
|
@@ -170,6 +171,7 @@ tslib_1.__decorate([
|
|
|
170
171
|
inline_keyboard: [
|
|
171
172
|
...(allowedMethods.includes('card') ? [[{ text: '💳 Банковская карта', command: DepositCommand, payload: { method: 'card' } }]] : []),
|
|
172
173
|
[{ text: '🪙 Криптовалюта', command: DepositCommand, payload: { method: 'cryptowallet' } }],
|
|
174
|
+
[{ text: '🎫 Промокод', command: DepositByPromocode_command_1.DepositByPromocodeCommand, payload: { method: 'promocode' } }],
|
|
173
175
|
],
|
|
174
176
|
},
|
|
175
177
|
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DepositByPromocodeCommand = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const evogram_1 = require("evogram");
|
|
6
|
+
const contexts_1 = require("evogram/lib/contexts");
|
|
7
|
+
const Client_1 = require("../../Client");
|
|
8
|
+
class DepositByPromocodeCommand extends evogram_1.Command {
|
|
9
|
+
execute(context, promocode) {
|
|
10
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
11
|
+
const config = Client_1.Client.config(context);
|
|
12
|
+
yield config.API.post(`promocodes/${promocode.id}/use`, {
|
|
13
|
+
mammothByProjectId: context.mammoth.id,
|
|
14
|
+
});
|
|
15
|
+
context.user.db.balance = Number(context.user.db.balance) + Number(promocode.amount);
|
|
16
|
+
yield context.user.db.save();
|
|
17
|
+
// prettier-ignore
|
|
18
|
+
yield context.sendFormatted({
|
|
19
|
+
header: `<blockquote><b>🎫 Пополнение через промокод</b></blockquote>\n\n` +
|
|
20
|
+
`<i>— Код промокода: <code>{{ ${promocode.code} }}</code></i>\n` +
|
|
21
|
+
`<i>— Сумма: {{ ${yield promocode.amount.convert({ from: 'RUB', to: config.currency })} }}</i>\n\n` +
|
|
22
|
+
`<i>— Ваш баланс: {{ ${yield context.user.db.balance.convert({ from: 'RUB', to: config.currency })} }}</i>`,
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.DepositByPromocodeCommand = DepositByPromocodeCommand;
|
|
28
|
+
tslib_1.__decorate([
|
|
29
|
+
tslib_1.__param(1, (0, evogram_1.CommandArgument)({
|
|
30
|
+
name: 'promocode',
|
|
31
|
+
question: ({ context, error }) => context
|
|
32
|
+
.sendFormattedQuestion({
|
|
33
|
+
header: '<blockquote><b>🎫 Пополнение через промокод</b></blockquote>\n\n' + '<i>Отправьте код промокода в следующем сообщении</i>',
|
|
34
|
+
error: error === null || error === void 0 ? void 0 : error.message,
|
|
35
|
+
})
|
|
36
|
+
.then((x) => x.text),
|
|
37
|
+
}, (0, evogram_1.stringValidator)({ minLength: 16, maxLength: 16 }), (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ value, context }) {
|
|
38
|
+
const config = Client_1.Client.config(context);
|
|
39
|
+
const promocode = yield config.API.get(`/promocodes/${value}`).then((x) => x.data);
|
|
40
|
+
if (!promocode)
|
|
41
|
+
throw new Error('Промокод не найден');
|
|
42
|
+
return promocode;
|
|
43
|
+
}))),
|
|
44
|
+
tslib_1.__metadata("design:type", Function),
|
|
45
|
+
tslib_1.__metadata("design:paramtypes", [contexts_1.CommandContext, Object]),
|
|
46
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
47
|
+
], DepositByPromocodeCommand.prototype, "execute", null);
|
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import { CommandContext } from 'evogram/lib/migrated';
|
|
|
3
3
|
import { Client } from '../../Client';
|
|
4
4
|
import { formatMessage } from '../../utils/formatMessage';
|
|
5
5
|
import { CheckPaidOrderCommand } from './CheckPaidOrder.command';
|
|
6
|
+
import { DepositByPromocodeCommand } from './DepositByPromocode.command';
|
|
6
7
|
import { GetDepositOrderCommand } from './GetDepositOrder.command';
|
|
7
8
|
|
|
8
9
|
// Функция для маскировки реквизитов: оставляет только последние 4 не пробельных символа
|
|
@@ -49,6 +50,7 @@ export class DepositCommand extends Command {
|
|
|
49
50
|
inline_keyboard: [
|
|
50
51
|
...(allowedMethods.includes('card') ? [[{ text: '💳 Банковская карта', command: DepositCommand, payload: { method: 'card' } }]] : []),
|
|
51
52
|
[{ text: '🪙 Криптовалюта', command: DepositCommand, payload: { method: 'cryptowallet' } }],
|
|
53
|
+
[{ text: '🎫 Промокод', command: DepositByPromocodeCommand, payload: { method: 'promocode' } }],
|
|
52
54
|
],
|
|
53
55
|
},
|
|
54
56
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Command, CommandArgument, stringValidator } from 'evogram';
|
|
2
|
+
import { CommandContext } from 'evogram/lib/contexts';
|
|
3
|
+
import { Client } from '../../Client';
|
|
4
|
+
|
|
5
|
+
export class DepositByPromocodeCommand extends Command {
|
|
6
|
+
public async execute(
|
|
7
|
+
context: CommandContext,
|
|
8
|
+
@CommandArgument(
|
|
9
|
+
{
|
|
10
|
+
name: 'promocode',
|
|
11
|
+
question: ({ context, error }) =>
|
|
12
|
+
context
|
|
13
|
+
.sendFormattedQuestion({
|
|
14
|
+
header: '<blockquote><b>🎫 Пополнение через промокод</b></blockquote>\n\n' + '<i>Отправьте код промокода в следующем сообщении</i>',
|
|
15
|
+
error: error?.message,
|
|
16
|
+
})
|
|
17
|
+
.then((x) => x.text),
|
|
18
|
+
},
|
|
19
|
+
stringValidator({ minLength: 16, maxLength: 16 }),
|
|
20
|
+
async ({ value, context }) => {
|
|
21
|
+
const config = Client.config(context);
|
|
22
|
+
|
|
23
|
+
const promocode = await config.API.get(`/promocodes/${value}`).then((x) => x.data);
|
|
24
|
+
if (!promocode) throw new Error('Промокод не найден');
|
|
25
|
+
|
|
26
|
+
return promocode;
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
promocode: any
|
|
30
|
+
) {
|
|
31
|
+
const config = Client.config(context);
|
|
32
|
+
await config.API.post(`promocodes/${promocode.id}/use`, {
|
|
33
|
+
mammothByProjectId: context.mammoth.id,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
context.user.db.balance = Number(context.user.db.balance) + Number(promocode.amount);
|
|
37
|
+
await context.user.db.save();
|
|
38
|
+
|
|
39
|
+
// prettier-ignore
|
|
40
|
+
await context.sendFormatted({
|
|
41
|
+
header:
|
|
42
|
+
`<blockquote><b>🎫 Пополнение через промокод</b></blockquote>\n\n` +
|
|
43
|
+
|
|
44
|
+
`<i>— Код промокода: <code>{{ ${promocode.code} }}</code></i>\n` +
|
|
45
|
+
`<i>— Сумма: {{ ${await promocode.amount.convert({ from: 'RUB', to: config.currency })} }}</i>\n\n` +
|
|
46
|
+
|
|
47
|
+
`<i>— Ваш баланс: {{ ${await context.user.db.balance.convert({ from: 'RUB', to: config.currency })} }}</i>`,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|