Add order_expired and trade_successful telegram messages

This commit is contained in:
Reckless_Satoshi 2022-02-22 09:50:01 -08:00
parent d051312e84
commit a9575c2338
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
2 changed files with 42 additions and 13 deletions

View File

@ -207,6 +207,7 @@ class Logics:
elif order.status == Order.Status.PUB:
cls.return_bond(order.maker_bond)
order.status = Order.Status.EXP
cls.telegram.order_expired_untaken(order)
order.save()
return True
@ -999,14 +1000,9 @@ class Logics:
order.payout.status = LNPayment.Status.FLIGHT
order.payout.save()
order.save()
cls.telegram.trade_successful(order)
return True, None
# is_payed, context = follow_send_payment(order.payout) ##### !!! KEY LINE - PAYS THE BUYER INVOICE !!!
# if is_payed:
# order.save()
# return True, context
# else:
# # error handling here
# return False, context
else:
return False, {
"bad_request":

View File

@ -33,8 +33,12 @@ 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}'
response = self.session.get(message_url).json()
print(response)
# telegram messaging is atm inserted dangerously in the logics module
# if it fails, it should just keep going
try:
self.session.get(message_url).json()
except:
pass
return
@ -43,13 +47,12 @@ class Telegram():
order = Order.objects.get(maker=user)
print(str(order.id))
if lang == 'es':
text = f'Hola {user.username}⚡, Te enviaré un mensaje cuando tu orden con ID {str(order.id)} haya sido tomada.'
text = f'Hola {user.username}, te enviaré un mensaje cuando tu orden con ID {str(order.id)} haya sido tomada.'
else:
text = f"Hey {user.username}, I will send you a message when someone takes your order with ID {str(order.id)}."
text = f"Hey {user.username}, I will send you a message when someone takes your order with ID {str(order.id)}."
self.send_message(user, text)
return
def order_taken(self, order):
user = order.maker
if not user.profile.telegram_enabled:
@ -59,9 +62,39 @@ class Telegram():
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}!🥳 Visita http://{site}/order/{order.id} para continuar.'
text = f'¡Tu orden con ID {order.id} ha sido tomada por {taker_nick}!🥳 Visita http://{site}/order/{order.id} para continuar.'
else:
text = f'Your order with ID {order.id} was taken by {taker_nick}!🥳 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:
return
lang = user.profile.telegram_lang_code
site = config('HOST_NAME')
if lang == 'es':
text = f'Tu orden con ID {order.id} ha expirado sin ser tomada por ningún robot. Visita http://{site} para crear una nueva.'
else:
text = f'Your order with ID {order.id} has expired untaken. Visit http://{site} to create a new one.'
self.send_message(user, text)
return
def trade_successful(self, order):
user = order.maker
if not user.profile.telegram_enabled:
return
lang = user.profile.telegram_lang_code
site = config('HOST_NAME')
if lang == 'es':
text = f'¡Tu orden con ID ha finalizado exitosamente!⚡ Unase a @robosats_es y ayudanos a mejorar.'
else:
text = f'Your order with ID has finished successfully!⚡ Join us @robosats and help us improve.'
self.send_message(user, text)
return