Fix non enabled telegram order taken

This commit is contained in:
Reckless_Satoshi 2022-02-21 16:55:31 -08:00
parent d146f522f3
commit 3906ed73aa
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
2 changed files with 8 additions and 5 deletions

View File

@ -7,8 +7,6 @@ from api.models import Order, LNPayment, MarketTick, User, Currency
from api.messages import Telegram from api.messages import Telegram
from decouple import config from decouple import config
from api.tasks import follow_send_payment
import math import math
import ast import ast

View File

@ -1,11 +1,13 @@
from decouple import config from decouple import config
from secrets import token_urlsafe from secrets import token_urlsafe
from api.models import Order from api.models import Order
import requests from api.utils import get_tor_session
class Telegram(): class Telegram():
''' Simple telegram messages by requesting to API''' ''' Simple telegram messages by requesting to API'''
session = get_tor_session()
def get_context(user): def get_context(user):
"""returns context needed to enable TG notifications""" """returns context needed to enable TG notifications"""
context = {} context = {}
@ -23,7 +25,7 @@ class Telegram():
return context return context
def send_message(user, text): def send_message(self, user, text):
""" sends a message to a user with telegram notifications enabled""" """ sends a message to a user with telegram notifications enabled"""
bot_token=config('TELEGRAM_TOKEN') bot_token=config('TELEGRAM_TOKEN')
@ -31,7 +33,7 @@ class Telegram():
chat_id = user.profile.telegram_chat_id chat_id = user.profile.telegram_chat_id
message_url = f'https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text={text}' message_url = f'https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text={text}'
response = requests.get(message_url).json() response = self.session.get(message_url).json()
print(response) print(response)
return return
@ -51,6 +53,9 @@ class Telegram():
@classmethod @classmethod
def order_taken(cls, order): def order_taken(cls, order):
user = order.maker user = order.maker
if not user.profile.telegram_enabled:
return
lang = user.profile.telegram_lang_code lang = user.profile.telegram_lang_code
taker_nick = order.taker.username taker_nick = order.taker.username
site = config('HOST_NAME') site = config('HOST_NAME')