diff --git a/api/logics.py b/api/logics.py index c9b32bb6..4e9e6e4c 100644 --- a/api/logics.py +++ b/api/logics.py @@ -619,6 +619,7 @@ class Logics: order.expires_at = order.created_at + timedelta( seconds=Order.t_to_expire[Order.Status.PUB]) order.save() + send_message.delay(order.id,'order_published') return @classmethod diff --git a/api/messages.py b/api/messages.py index 164b43a0..0d5156cd 100644 --- a/api/messages.py +++ b/api/messages.py @@ -2,6 +2,7 @@ from decouple import config from secrets import token_urlsafe from api.models import Order from api.utils import get_tor_session +import time class Telegram(): ''' Simple telegram messages by requesting to API''' @@ -126,9 +127,9 @@ class Telegram(): lang = user.profile.telegram_lang_code if lang == 'es': - text = f'El tomador ha cancelado antes de bloquear su fianza. Tu orden con ID {order.id} vuelve a ser pública.' + text = f'El tomador ha cancelado antes de bloquear su fianza.' else: - text = f'The taker has canceled before locking the bond. Your order with ID {order.id} is once again public in the order book.' + text = f'The taker has canceled before locking the bond.' self.send_message(user, text) return @@ -140,9 +141,31 @@ class Telegram(): lang = user.profile.telegram_lang_code if lang == 'es': - text = f'El tomador no ha bloqueado la fianza a tiempo. Tu orden con ID {order.id} vuelve a ser pública.' + text = f'El tomador no ha bloqueado la fianza a tiempo.' else: - text = f'The taker has not locked the bond in time. Your order with ID {order.id} is once again public in the order book.' + text = f'The taker has not locked the bond in time.' self.send_message(user, text) + return + + def order_published(self, order): + + time.sleep(1) # Just so this message always arrives after the previous two + + user = order.maker + 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() + + print(str(order.id)) + if lang == 'es': + text = f'Tu orden con ID {str(order.id)} es pública en el libro de ordenes.' + else: + text = f"Your order with ID {str(order.id)} is public in the order book." + self.send_message(user, text) + user.profile.telegram_welcomed = True + user.profile.save() return \ No newline at end of file diff --git a/api/tasks.py b/api/tasks.py index 9c402fdd..dc981f01 100644 --- a/api/tasks.py +++ b/api/tasks.py @@ -181,5 +181,8 @@ def send_message(order_id, message): elif message == 'taker_canceled_b4bond': telegram.taker_canceled_b4bond(order) + + elif message == 'order_published': + telegram.order_published(order) return \ No newline at end of file