Skip to content

Commit

Permalink
lnp2pBot#371 added takeorder command (lnp2pBot#429)
Browse files Browse the repository at this point in the history
* lnp2pBot#371 added takeorder command

* i18n
  • Loading branch information
dolchi21 authored Sep 14, 2023
1 parent 8a56efb commit 9404443
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 1 deletion.
35 changes: 34 additions & 1 deletion bot/modules/orders/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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 };
6 changes: 6 additions & 0 deletions bot/modules/orders/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions locales/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
<strong>User settings for @${user.username}</strong>
Expand Down
4 changes: 4 additions & 0 deletions locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
<strong>User settings for @${user.username}</strong>
Expand Down
4 changes: 4 additions & 0 deletions locales/es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
<strong>Configuraciones de @${user.username}</strong>
Expand Down
4 changes: 4 additions & 0 deletions locales/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
<strong>Paramètres de l'utilisateur pour @${user.username}</strong>
Expand Down
4 changes: 4 additions & 0 deletions locales/it.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
<strong>User settings for @${user.username}</strong>
Expand Down
4 changes: 4 additions & 0 deletions locales/pt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
<strong>User settings for @${user.username}</strong>
Expand Down
4 changes: 4 additions & 0 deletions locales/ru.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
<strong>User settings for @${user.username}</strong>
Expand Down
4 changes: 4 additions & 0 deletions locales/uk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
<strong>User settings for @${user.username}</strong>
Expand Down

0 comments on commit 9404443

Please sign in to comment.