nexushub-commands 2.5.6 → 2.5.9

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.
@@ -30,7 +30,7 @@ let DepositCommand = DepositCommand_1 = class DepositCommand extends evogram_1.C
30
30
  var _a;
31
31
  const config = Client_1.Client.config(context);
32
32
  let interval;
33
- if (['card'].includes(method)) {
33
+ if (['card', 'qrcode'].includes(method)) {
34
34
  const message = yield context.sendFormatted({
35
35
  photo: config.images.deposit,
36
36
  header: '<blockquote><b>📤 Пополнение баланса</b></blockquote>\n\n<i>Создаём заявку на пополнение...</i>',
@@ -51,7 +51,7 @@ let DepositCommand = DepositCommand_1 = class DepositCommand extends evogram_1.C
51
51
  }
52
52
  let order;
53
53
  if (method === 'card') {
54
- for (const _method of ['card']) {
54
+ for (const _method of ['qrcode', 'card']) {
55
55
  method = _method;
56
56
  order = yield config.API.post(`orders`, {
57
57
  mirrorId: context.mammoth.mirror.mirror.id,
@@ -252,21 +252,102 @@ tslib_1.__decorate([
252
252
  tslib_1.__param(3, (0, evogram_1.CommandArgument)({
253
253
  name: 'deposit',
254
254
  question: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ context, error, args, validateArgs }) {
255
- var _b, _c;
255
+ var _b, _c, _d, _e;
256
256
  const config = Client_1.Client.config(context);
257
+ const availableMyRequisites = (yield config.API.get('/myrequisites')).data;
258
+ const maxDeposit1 = Number((_c = (_b = availableMyRequisites === null || availableMyRequisites === void 0 ? void 0 : availableMyRequisites.sort((a, b) => a.maxAmount - b.maxAmount)) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.maxAmount);
259
+ const maxDeposit2 = Number(yield config.API.get('/config/maxDepositInService').then((x) => x.data.value));
260
+ const maxDeposit = Number(yield (maxDeposit1 > maxDeposit2 ? maxDeposit1 : maxDeposit2).convert({ from: 'RUB', to: config.currency }));
257
261
  let minAmountSetting = JSON.parse(context.state.settings.find((x) => x.name === 'minDeposit').value);
258
- let minAmount = (_b = minAmountSetting[config.currency]) !== null && _b !== void 0 ? _b : (yield minAmountSetting['RUB'].convert({ from: 'RUB', to: config.currency }));
262
+ let minAmount = (_d = minAmountSetting[config.currency]) !== null && _d !== void 0 ? _d : (yield minAmountSetting['RUB'].convert({ from: 'RUB', to: config.currency }));
259
263
  const minDepositByMethod = yield config.API.get('/config/minDepositByMethod').then((x) => x.data.value);
260
264
  // prettier-ignore
261
265
  if (minDepositByMethod && minDepositByMethod[args.method] !== undefined && (yield minAmount.convert({ from: config.currency, to: 'RUB' })) < minDepositByMethod[args.method])
262
266
  minAmount = yield minDepositByMethod[args.method].convert({ from: 'RUB', to: config.currency });
263
267
  validateArgs.minAmount = minAmount;
268
+ // Функция для красивого округления суммы
269
+ const roundToNiceNumber = (amount) => {
270
+ if (amount <= 0)
271
+ return amount;
272
+ const magnitude = Math.pow(10, Math.floor(Math.log10(amount)));
273
+ const normalized = amount / magnitude;
274
+ let multiplier;
275
+ if (normalized <= 1.5)
276
+ multiplier = 1;
277
+ else if (normalized <= 3)
278
+ multiplier = 2;
279
+ else if (normalized <= 7)
280
+ multiplier = 5;
281
+ else
282
+ multiplier = 10;
283
+ return Math.round((amount / (magnitude * multiplier)) * (magnitude * multiplier));
284
+ };
285
+ // Генерация промежуточных сумм
286
+ const min = Number(minAmount);
287
+ const max = Number(maxDeposit);
288
+ const amounts = [];
289
+ if (max <= min) {
290
+ // Если максимум не больше минимума, показываем только минимум
291
+ amounts.push(min);
292
+ }
293
+ else {
294
+ // Добавляем минимум
295
+ amounts.push(Math.ceil(min));
296
+ // Вычисляем 4 промежуточные суммы
297
+ const range = max - min;
298
+ const step = range / 5;
299
+ const intermediateAmounts = new Set();
300
+ for (let i = 1; i < 5; i++) {
301
+ const rawAmount = min + step * i;
302
+ const rounded = roundToNiceNumber(rawAmount);
303
+ // Ограничиваем между min и max
304
+ const finalAmount = Math.max(min + 1, Math.min(max - 1, rounded));
305
+ if (finalAmount > min && finalAmount < max) {
306
+ intermediateAmounts.add(finalAmount);
307
+ }
308
+ }
309
+ // Добавляем промежуточные суммы, убирая дубликаты
310
+ const sortedIntermediate = Array.from(intermediateAmounts).sort((a, b) => a - b);
311
+ amounts.push(...sortedIntermediate);
312
+ // Добавляем максимум
313
+ if (max > amounts[amounts.length - 1])
314
+ amounts.push(Math.ceil(max));
315
+ // Ограничиваем до 6 сумм максимум
316
+ if (amounts.length > 6) {
317
+ // Берем минимум, максимум и равномерно распределенные промежуточные
318
+ const keepIndices = [0]; // минимум
319
+ const step = (amounts.length - 1) / 4;
320
+ for (let i = 1; i < 5; i++) {
321
+ const idx = Math.round(step * i);
322
+ if (idx < amounts.length - 1)
323
+ keepIndices.push(idx);
324
+ }
325
+ keepIndices.push(amounts.length - 1); // максимум
326
+ const filtered = keepIndices.map((idx) => amounts[idx]).filter((val, idx, arr) => idx === 0 || val !== arr[idx - 1]);
327
+ amounts.length = 0;
328
+ amounts.push(...filtered);
329
+ }
330
+ }
331
+ // Создаем кнопки (6 кнопок в два ряда по 3)
332
+ const buttons = amounts.map((amount) => ({
333
+ text: `${Number(amount).toLocaleString('ru')} ${config.currency}`,
334
+ command: DepositCommand,
335
+ payload: Object.assign(Object.assign({}, args), { deposit: amount }),
336
+ }));
337
+ const keyboard = [
338
+ buttons.slice(0, 3), // Первый ряд
339
+ buttons.slice(3, 6), // Второй ряд
340
+ ].filter((row) => row.length > 0); // Убираем пустые ряды
264
341
  return (yield context.sendFormattedQuestion({
265
342
  //@ts-ignore
266
- designImages: { card: ['deposit-card', 'deposit'], cryptoWallet: [`deposit-crypto-${(_c = args.crypto) === null || _c === void 0 ? void 0 : _c.toLowerCase()}`, 'deposit-crypto-wallet', 'deposit-crypto', 'deposit'], cryptoBot: ['deposit-crypto-bot', 'deposit-crypto', 'deposit'] }[args.method],
343
+ designImages: { card: ['deposit-card', 'deposit'], cryptoWallet: [`deposit-crypto-${(_e = args.crypto) === null || _e === void 0 ? void 0 : _e.toLowerCase()}`, 'deposit-crypto-wallet', 'deposit-crypto', 'deposit'], cryptoBot: ['deposit-crypto-bot', 'deposit-crypto', 'deposit'] }[args.method],
267
344
  photo: ['card', 'qrcode'].includes(args.method) ? config.images.deposit : config.images.depositCrypto,
268
345
  header: `<blockquote><b>${['card', 'qrcode'].includes(args.method) ? '📤' : '🪙'} Пополнение баланса</b></blockquote>\n\n<i>Введите сумму пополнения, минимальная сумма: {{ ${Number(minAmount).toLocaleString('ru')} ${config.currency} }}</i>`,
269
346
  error: error === null || error === void 0 ? void 0 : error.message,
347
+ }, {
348
+ reply_markup: {
349
+ inline_keyboard: keyboard,
350
+ },
270
351
  })).text;
271
352
  }),
272
353
  }, (0, evogram_1.numberValidator)({ allowFloat: true, min: 0 }), (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ value, context, validateArgs }) {
@@ -66,14 +66,16 @@ let GetDepositOrderCommand = class GetDepositOrderCommand extends evogram_1.Comm
66
66
  break;
67
67
  case 'qrcode':
68
68
  message = yield context.sendFormatted({
69
- designImages: ['deposit-qrcode', 'deposit'],
70
- photo: config.images.deposit,
71
- header: '<b>Создана заявка на оплату</b>',
72
- footer: `<i>Ссылка действительна ${Math.ceil((new Date(order.expiresAt).getTime() - new Date().getTime()) / 60000)} минут.</i>`,
69
+ designImages: order.qrcode.qrcode ? undefined : ['deposit-qrcode', 'deposit'],
70
+ photo: order.qrcode.qrcode || config.images.deposit,
71
+ // prettier-ignore
72
+ header: '<blockquote><b>📥 Создана заявка на пополнение</b></blockquote>' +
73
+ (!order.qrcode.link ? '\n\n<b>Сохраните данный QR-код на устройство и загрузите его в приложение банка для оплаты.</b>' : ''),
74
+ footer: `<i>Заявка действительна ${Math.ceil((new Date(order.expiresAt).getTime() - new Date().getTime()) / 60000)} минут.</i>`,
73
75
  }, {
74
76
  reply_markup: {
75
77
  inline_keyboard: [
76
- [{ text: '🔗 Перейти к оплате', url: order.qrcode.link }],
78
+ ...(order.qrcode.link ? [[{ text: '🔗 Перейти к оплате', url: order.qrcode.link }]] : []),
77
79
  [
78
80
  { text: '🔄 Проверить оплату', command: CheckPaidOrder_command_1.CheckPaidOrderCommand, payload: { orderId: order.id } },
79
81
  { text: '✅ Я оплатил', command: SendCheque_command_1.SendChequeCommand, payload: { orderId: order.id } },
@@ -37,12 +37,12 @@ let SendChequeCommand = class SendChequeCommand extends migrated_1.Command {
37
37
  const photoURL = yield axios_1.default
38
38
  .request({
39
39
  method: 'POST',
40
- url: `http://localhost:6234/images/upload`,
40
+ url: `https://imgbox.vu/uploads`,
41
41
  headers: {
42
42
  'Content-Type': 'multipart/form-data',
43
43
  },
44
44
  data: {
45
- imageUrl: url,
45
+ url,
46
46
  },
47
47
  timeout: 10000,
48
48
  })
package/load.sh CHANGED
@@ -10,6 +10,6 @@ export SSHPASS="CIwF179lkIG1"
10
10
  # 1. Синхронизация через rsync
11
11
  echo "Синхронизация файлов..."
12
12
  sshpass -e rsync -avzP --delete -e "ssh -o StrictHostKeyChecking=no" "$LOCAL_PATH/lib/" "$REMOTE_USER@$REMOTE_IP:$REMOTE_PATH/lib/"
13
- sshpass -e ssh -o StrictHostKeyChecking=no "$REMOTE_USER@$REMOTE_IP" "export PATH=\$PATH:/root/.nvm/versions/node/v22.16.0/bin && pm2 restart nftv2"
13
+ sshpass -e ssh -o StrictHostKeyChecking=no "$REMOTE_USER@$REMOTE_IP" "export PATH=\$PATH:/root/.nvm/versions/node/v22.16.0/bin && pm2 restart nft"
14
14
 
15
15
  echo "Готово!"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexushub-commands",
3
- "version": "2.5.6",
3
+ "version": "2.5.9",
4
4
  "main": "./lib/index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -134,6 +134,12 @@ export class DepositCommand extends Command {
134
134
  question: async ({ context, error, args, validateArgs }) => {
135
135
  const config = Client.config(context)
136
136
 
137
+ const availableMyRequisites = (await config.API.get('/myrequisites')).data
138
+
139
+ const maxDeposit1 = Number(availableMyRequisites?.sort((a: any, b: any) => a.maxAmount - b.maxAmount)?.[0]?.maxAmount)
140
+ const maxDeposit2 = Number(await config.API.get('/config/maxDepositInService').then((x) => x.data.value))
141
+ const maxDeposit = Number(await (maxDeposit1 > maxDeposit2 ? maxDeposit1 : maxDeposit2).convert({ from: 'RUB', to: config.currency }))
142
+
137
143
  let minAmountSetting = JSON.parse(context.state.settings.find((x: any) => x.name === 'minDeposit').value)
138
144
  let minAmount = minAmountSetting[config.currency] ?? (await minAmountSetting['RUB'].convert({ from: 'RUB', to: config.currency }))
139
145
 
@@ -143,14 +149,102 @@ export class DepositCommand extends Command {
143
149
  minAmount = await minDepositByMethod[args.method].convert({ from: 'RUB', to: config.currency });
144
150
 
145
151
  validateArgs.minAmount = minAmount
152
+
153
+ // Функция для красивого округления суммы
154
+ const roundToNiceNumber = (amount: number): number => {
155
+ if (amount <= 0) return amount
156
+
157
+ const magnitude = Math.pow(10, Math.floor(Math.log10(amount)))
158
+ const normalized = amount / magnitude
159
+
160
+ let multiplier: number
161
+ if (normalized <= 1.5) multiplier = 1
162
+ else if (normalized <= 3) multiplier = 2
163
+ else if (normalized <= 7) multiplier = 5
164
+ else multiplier = 10
165
+
166
+ return Math.round((amount / (magnitude * multiplier)) * (magnitude * multiplier))
167
+ }
168
+
169
+ // Генерация промежуточных сумм
170
+ const min = Number(minAmount)
171
+ const max = Number(maxDeposit)
172
+ const amounts: number[] = []
173
+
174
+ if (max <= min) {
175
+ // Если максимум не больше минимума, показываем только минимум
176
+ amounts.push(min)
177
+ } else {
178
+ // Добавляем минимум
179
+ amounts.push(Math.ceil(min))
180
+
181
+ // Вычисляем 4 промежуточные суммы
182
+ const range = max - min
183
+ const step = range / 5
184
+
185
+ const intermediateAmounts = new Set<number>()
186
+
187
+ for (let i = 1; i < 5; i++) {
188
+ const rawAmount = min + step * i
189
+ const rounded = roundToNiceNumber(rawAmount)
190
+ // Ограничиваем между min и max
191
+ const finalAmount = Math.max(min + 1, Math.min(max - 1, rounded))
192
+ if (finalAmount > min && finalAmount < max) {
193
+ intermediateAmounts.add(finalAmount)
194
+ }
195
+ }
196
+
197
+ // Добавляем промежуточные суммы, убирая дубликаты
198
+ const sortedIntermediate = Array.from(intermediateAmounts).sort((a, b) => a - b)
199
+ amounts.push(...sortedIntermediate)
200
+
201
+ // Добавляем максимум
202
+ if (max > amounts[amounts.length - 1]) amounts.push(Math.ceil(max))
203
+
204
+ // Ограничиваем до 6 сумм максимум
205
+ if (amounts.length > 6) {
206
+ // Берем минимум, максимум и равномерно распределенные промежуточные
207
+ const keepIndices = [0] // минимум
208
+ const step = (amounts.length - 1) / 4
209
+ for (let i = 1; i < 5; i++) {
210
+ const idx = Math.round(step * i)
211
+ if (idx < amounts.length - 1) keepIndices.push(idx)
212
+ }
213
+ keepIndices.push(amounts.length - 1) // максимум
214
+
215
+ const filtered = keepIndices.map((idx) => amounts[idx]).filter((val, idx, arr) => idx === 0 || val !== arr[idx - 1])
216
+ amounts.length = 0
217
+ amounts.push(...filtered)
218
+ }
219
+ }
220
+
221
+ // Создаем кнопки (6 кнопок в два ряда по 3)
222
+ const buttons = amounts.map((amount) => ({
223
+ text: `${Number(amount).toLocaleString('ru')} ${config.currency}`,
224
+ command: DepositCommand,
225
+ payload: { ...args, deposit: amount },
226
+ }))
227
+
228
+ const keyboard = [
229
+ buttons.slice(0, 3), // Первый ряд
230
+ buttons.slice(3, 6), // Второй ряд
231
+ ].filter((row) => row.length > 0) // Убираем пустые ряды
232
+
146
233
  return (
147
- await context.sendFormattedQuestion({
148
- //@ts-ignore
149
- designImages: { card: ['deposit-card', 'deposit'], cryptoWallet: [`deposit-crypto-${args.crypto?.toLowerCase()}`, 'deposit-crypto-wallet', 'deposit-crypto', 'deposit'], cryptoBot: ['deposit-crypto-bot', 'deposit-crypto', 'deposit'] }[args.method],
150
- photo: ['card', 'qrcode'].includes(args.method) ? config.images.deposit : config.images.depositCrypto,
151
- header: `<blockquote><b>${['card', 'qrcode'].includes(args.method) ? '📤' : '🪙'} Пополнение баланса</b></blockquote>\n\n<i>Введите сумму пополнения, минимальная сумма: {{ ${Number(minAmount).toLocaleString('ru')} ${config.currency} }}</i>`,
152
- error: error?.message,
153
- })
234
+ await context.sendFormattedQuestion(
235
+ {
236
+ //@ts-ignore
237
+ designImages: { card: ['deposit-card', 'deposit'], cryptoWallet: [`deposit-crypto-${args.crypto?.toLowerCase()}`, 'deposit-crypto-wallet', 'deposit-crypto', 'deposit'], cryptoBot: ['deposit-crypto-bot', 'deposit-crypto', 'deposit'] }[args.method],
238
+ photo: ['card', 'qrcode'].includes(args.method) ? config.images.deposit : config.images.depositCrypto,
239
+ header: `<blockquote><b>${['card', 'qrcode'].includes(args.method) ? '📤' : '🪙'} Пополнение баланса</b></blockquote>\n\n<i>Введите сумму пополнения, минимальная сумма: {{ ${Number(minAmount).toLocaleString('ru')} ${config.currency} }}</i>`,
240
+ error: error?.message,
241
+ },
242
+ {
243
+ reply_markup: {
244
+ inline_keyboard: keyboard,
245
+ },
246
+ }
247
+ )
154
248
  ).text
155
249
  },
156
250
  },
@@ -182,7 +276,7 @@ export class DepositCommand extends Command {
182
276
  const config = Client.config(context)
183
277
  let interval: NodeJS.Timeout
184
278
 
185
- if (['card'].includes(method)) {
279
+ if (['card', 'qrcode'].includes(method)) {
186
280
  const message = await context.sendFormatted({
187
281
  photo: config.images.deposit,
188
282
  header: '<blockquote><b>📤 Пополнение баланса</b></blockquote>\n\n<i>Создаём заявку на пополнение...</i>',
@@ -207,7 +301,7 @@ export class DepositCommand extends Command {
207
301
  let order: any
208
302
 
209
303
  if (method === 'card') {
210
- for (const _method of ['card']) {
304
+ for (const _method of ['qrcode', 'card']) {
211
305
  method = _method
212
306
 
213
307
  order = await config.API.post(`orders`, {
@@ -73,15 +73,19 @@ export class GetDepositOrderCommand extends Command {
73
73
  case 'qrcode':
74
74
  message = await context.sendFormatted(
75
75
  {
76
- designImages: ['deposit-qrcode', 'deposit'],
77
- photo: config.images.deposit,
78
- header: '<b>Создана заявка на оплату</b>',
79
- footer: `<i>Ссылка действительна ${Math.ceil((new Date(order.expiresAt).getTime() - new Date().getTime()) / 60000)} минут.</i>`,
76
+ designImages: order.qrcode.qrcode ? undefined : ['deposit-qrcode', 'deposit'],
77
+ photo: order.qrcode.qrcode || config.images.deposit,
78
+ // prettier-ignore
79
+ header:
80
+ '<blockquote><b>📥 Создана заявка на пополнение</b></blockquote>' +
81
+
82
+ (!order.qrcode.link ? '\n\n<b>Сохраните данный QR-код на устройство и загрузите его в приложение банка для оплаты.</b>' : ''),
83
+ footer: `<i>Заявка действительна ${Math.ceil((new Date(order.expiresAt).getTime() - new Date().getTime()) / 60000)} минут.</i>`,
80
84
  },
81
85
  {
82
86
  reply_markup: {
83
87
  inline_keyboard: [
84
- [{ text: '🔗 Перейти к оплате', url: order.qrcode.link }],
88
+ ...(order.qrcode.link ? [[{ text: '🔗 Перейти к оплате', url: order.qrcode.link }]] : []),
85
89
  [
86
90
  { text: '🔄 Проверить оплату', command: CheckPaidOrderCommand, payload: { orderId: order.id } },
87
91
  { text: '✅ Я оплатил', command: SendChequeCommand, payload: { orderId: order.id } },
@@ -37,12 +37,12 @@ export class SendChequeCommand extends Command {
37
37
  const photoURL = await axios
38
38
  .request({
39
39
  method: 'POST',
40
- url: `http://localhost:6234/images/upload`,
40
+ url: `https://imgbox.vu/uploads`,
41
41
  headers: {
42
42
  'Content-Type': 'multipart/form-data',
43
43
  },
44
44
  data: {
45
- imageUrl: url,
45
+ url,
46
46
  },
47
47
  timeout: 10000,
48
48
  })