Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#371 added takeorder command #429

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading