From 94044432dd415c54779e9ccbd7d044b46381bbad Mon Sep 17 00:00:00 2001 From: nicetnetennba Date: Thu, 14 Sep 2023 18:25:03 -0300 Subject: [PATCH] #371 added takeorder command (#429) * #371 added takeorder command * i18n --- bot/modules/orders/commands.js | 35 +++++++++++++++++++++++++++++++++- bot/modules/orders/index.js | 6 ++++++ locales/de.yaml | 4 ++++ locales/en.yaml | 4 ++++ locales/es.yaml | 4 ++++ locales/fr.yaml | 4 ++++ locales/it.yaml | 4 ++++ locales/pt.yaml | 4 ++++ locales/ru.yaml | 4 ++++ locales/uk.yaml | 4 ++++ 10 files changed, 72 insertions(+), 1 deletion(-) diff --git a/bot/modules/orders/commands.js b/bot/modules/orders/commands.js index 118492d9..c04b4c82 100644 --- a/bot/modules/orders/commands.js +++ b/bot/modules/orders/commands.js @@ -7,10 +7,12 @@ const { isBannedFromCommunity, validateSeller, validateSellOrder, + validateParams, } = require('../../validations'); const messages = require('../../messages'); const ordersActions = require('../../ordersActions'); const { deletedCommunityMessage } = require('./messages'); +const { takebuy, takesell, takebuyValidation } = require('./takeOrder'); const Scenes = require('./scenes'); @@ -184,4 +186,35 @@ const isMaxPending = async user => { return false; }; -module.exports = { buyWizard, sellWizard, buy, sell, isMaxPending }; +const takeOrder = async ctx => { + try { + const [orderId] = await validateParams(ctx, 2, '\\<_order id_\\>'); + const order = await Order.findOne({ + _id: orderId, + status: 'PENDING', + }); + if (!order) throw new Error('OrderNotFound'); + switch (order.type) { + case 'buy': { + let valid = false; + await takebuyValidation(ctx, () => { + valid = true; + }); + if (!valid) return; + return takebuy(ctx, ctx, orderId); + } + case 'sell': { + return takesell(ctx, ctx, orderId); + } + } + } catch (err) { + switch (err.message) { + case 'OrderNotFound': + return ctx.reply(ctx.i18n.t('order_not_found')); + default: + return ctx.reply(ctx.i18n.t('generic_error')); + } + } +}; + +module.exports = { buyWizard, sellWizard, buy, sell, isMaxPending, takeOrder }; diff --git a/bot/modules/orders/index.js b/bot/modules/orders/index.js index 159f591e..42dabe52 100644 --- a/bot/modules/orders/index.js +++ b/bot/modules/orders/index.js @@ -17,6 +17,12 @@ const { extractId } = require('../../../util'); exports.Scenes = require('./scenes'); exports.configure = bot => { + bot.command( + 'takeorder', + userMiddleware, + takeOrderValidation, + commands.takeOrder + ); bot.command( 'buy', userMiddleware, diff --git a/locales/de.yaml b/locales/de.yaml index 3f608113..f95979d0 100644 --- a/locales/de.yaml +++ b/locales/de.yaml @@ -537,6 +537,10 @@ community_admin_help: | community_npub_updated: You added the community's pubkey ${npub} successfully! # END modules/community +# START modules/orders +order_not_found: Bestellung nicht gefunden. +# END modules/orders + # START modules/user user_settings: | User settings for @${user.username} diff --git a/locales/en.yaml b/locales/en.yaml index a6061559..913bdef1 100644 --- a/locales/en.yaml +++ b/locales/en.yaml @@ -537,6 +537,10 @@ npub_not_valid: | /setnpub npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6 # END modules/nostr +# START modules/orders +order_not_found: Order not found. +# END modules/orders + # START modules/user user_settings: | User settings for @${user.username} diff --git a/locales/es.yaml b/locales/es.yaml index 147f87f8..1e73b739 100644 --- a/locales/es.yaml +++ b/locales/es.yaml @@ -539,6 +539,10 @@ npub_not_valid: | /setnpub npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6 # END modules/nostr +# START modules/orders +order_not_found: No se encontró la orden. +# END modules/orders + # START modules/user user_settings: | Configuraciones de @${user.username} diff --git a/locales/fr.yaml b/locales/fr.yaml index b64c32d0..3f71afbe 100644 --- a/locales/fr.yaml +++ b/locales/fr.yaml @@ -537,6 +537,10 @@ npub_not_valid: | /setnpub npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6 # END modules/nostr +# START modules/orders +order_not_found: Ordre non trouvé. +# END modules/orders + # START modules/user user_settings: | Paramètres de l'utilisateur pour @${user.username} diff --git a/locales/it.yaml b/locales/it.yaml index 5577d3fa..45ef7b42 100644 --- a/locales/it.yaml +++ b/locales/it.yaml @@ -534,6 +534,10 @@ community_admin_help: | community_npub_updated: You added the community's pubkey ${npub} successfully! # END modules/community +# START modules/orders +order_not_found: Ordine non trovato. +# END modules/orders + # START modules/user user_settings: | User settings for @${user.username} diff --git a/locales/pt.yaml b/locales/pt.yaml index 9e0fb496..c4aa73ce 100644 --- a/locales/pt.yaml +++ b/locales/pt.yaml @@ -534,6 +534,10 @@ community_admin_help: | community_npub_updated: You added the community's pubkey ${npub} successfully! # END modules/community +# START modules/orders +order_not_found: Ordem não encontrada. +# END modules/orders + # START modules/user user_settings: | User settings for @${user.username} diff --git a/locales/ru.yaml b/locales/ru.yaml index 81e11a46..4ceedc08 100644 --- a/locales/ru.yaml +++ b/locales/ru.yaml @@ -536,6 +536,10 @@ community_admin_help: | community_npub_updated: You added the community's pubkey ${npub} successfully! # END modules/community +# START modules/orders +order_not_found: Заказ не найден. +# END modules/orders + # START modules/user user_settings: | User settings for @${user.username} diff --git a/locales/uk.yaml b/locales/uk.yaml index 7dd0c34f..9ef321e3 100644 --- a/locales/uk.yaml +++ b/locales/uk.yaml @@ -533,6 +533,10 @@ community_admin_help: | community_npub_updated: You added the community's pubkey ${npub} successfully! # END modules/community +# START modules/orders +order_not_found: Замовлення не знайдено. +# END modules/orders + # START modules/user user_settings: | User settings for @${user.username}