Skip to content

Commit

Permalink
lnp2pBot#371 added takeorder command
Browse files Browse the repository at this point in the history
  • Loading branch information
dolchi21 committed Sep 13, 2023
1 parent 8a56efb commit 91c6ea8
Show file tree
Hide file tree
Showing 4 changed files with 48 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/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

0 comments on commit 91c6ea8

Please sign in to comment.