Telegram notification only when taker bond is locked

This commit is contained in:
Reckless_Satoshi 2022-03-11 07:24:39 -08:00
parent b4001653f2
commit 6373957774
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
3 changed files with 23 additions and 6 deletions

View File

@ -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

View File

@ -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:

View File

@ -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