diff --git a/api/logics.py b/api/logics.py index 803ce98a..10231487 100644 --- a/api/logics.py +++ b/api/logics.py @@ -130,7 +130,7 @@ class Logics: order.expires_at = timezone.now() + timedelta( seconds=Order.t_to_expire[Order.Status.TAK]) order.save() - send_message.delay(order.id,'order_taken') + # send_message.delay(order.id,'order_taken') # Too spammy return True, None def is_buyer(order, user): @@ -215,7 +215,7 @@ class Logics: elif order.status == Order.Status.TAK: cls.cancel_bond(order.taker_bond) cls.kick_taker(order) - send_message.delay(order.id,'taker_expired_b4bond') + # send_message.delay(order.id,'taker_expired_b4bond') # Too spammy return True elif order.status == Order.Status.WF2: @@ -578,7 +578,7 @@ class Logics: # adds a timeout penalty cls.cancel_bond(order.taker_bond) cls.kick_taker(order) - send_message.delay(order.id,'taker_canceled_b4bond') + # send_message.delay(order.id,'taker_canceled_b4bond') # too spammy return True, None # 4) When taker or maker cancel after bond (before escrow) @@ -769,6 +769,7 @@ class Logics: MarketTick.log_a_tick(order) except: pass + send_message.delay(order.id,'order_taken_confirmed') return True @classmethod diff --git a/api/messages.py b/api/messages.py index 43ac1fd8..cbdc0a58 100644 --- a/api/messages.py +++ b/api/messages.py @@ -34,7 +34,6 @@ class Telegram(): chat_id = user.profile.telegram_chat_id message_url = f'https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text={text}' - # telegram messaging is atm inserted dangerously in the logics module # if it fails, it should keep trying while True: try: @@ -47,7 +46,6 @@ class Telegram(): lang = user.profile.telegram_lang_code # In weird cases the order cannot be found (e.g. it is cancelled) - queryset = Order.objects.filter(maker=user) order = queryset.last() @@ -77,6 +75,22 @@ class Telegram(): self.send_message(user, text) return + def order_taken_confirmed(self, order): + user = order.maker + if not user.profile.telegram_enabled: + return + + lang = user.profile.telegram_lang_code + taker_nick = order.taker.username + site = config('HOST_NAME') + if lang == 'es': + text = f'¡Tu orden con ID {order.id} ha sido tomada por {taker_nick}!🥳 El tomador ya ha bloqueado su fianza. Visita http://{site}/order/{order.id} para continuar.' + else: + text = f'Your order with ID {order.id} was taken by {taker_nick}!🥳 The taker bond has been already locked. Visit http://{site}/order/{order.id} to proceed with the trade.' + + self.send_message(user, text) + return + def order_expired_untaken(self, order): user = order.maker if not user.profile.telegram_enabled: diff --git a/api/tasks.py b/api/tasks.py index 08604cbf..596fb71b 100644 --- a/api/tasks.py +++ b/api/tasks.py @@ -211,5 +211,7 @@ def send_message(order_id, message): elif message == 'order_published': telegram.order_published(order) - + + elif message == 'order_taken_confirmed': + telegram.order_taken_confirmed(order) return \ No newline at end of file