Fix BtcOffersBot (notify without amount)

This commit is contained in:
AlberLC
2025-04-16 20:41:36 +02:00
parent bdf658ee9a
commit abc4462723

View File

@@ -206,21 +206,16 @@ class BtcOffersBot(MultiBot, ABC):
@preprocess_btc_offers @preprocess_btc_offers
async def _on_notify_btc_offers(self, message: Message, query: dict[str, float]): async def _on_notify_btc_offers(self, message: Message, query: dict[str, float]):
if message.chat.is_group and not self.is_bot_mentioned(message): if not query:
await self.send_error('❌ Especifica una cantidad para poder avisarte.', message)
return return
if max_price_eur := query.get('max_price_eur'): match query:
response_text = f'✅ ¡Perfecto! Te avisaré cuando existan ofertas por {max_price_eur:.2f} € o menos.' case {'max_price_eur': max_price_eur}:
else: response_text = f'✅ ¡Perfecto! Te avisaré cuando existan ofertas por {max_price_eur:.2f} € o menos.'
async with aiohttp.ClientSession() as session: case {'max_price_usd': max_price_usd}:
async with session.get(constants.YADIO_API_ENDPOINT) as response:
yadio_data = await response.json()
if max_price_usd := query.get('max_price_usd'):
max_price_eur = max_price_usd / yadio_data['EUR']['USD']
response_text = f'✅ ¡Perfecto! Te avisaré cuando existan ofertas por {max_price_usd:.2f} $ o menos.' response_text = f'✅ ¡Perfecto! Te avisaré cuando existan ofertas por {max_price_usd:.2f} $ o menos.'
else: case _:
max_price_eur = yadio_data['BTC'] + query['max_premium'] / 100 * yadio_data['BTC']
response_text = f"✅ ¡Perfecto! Te avisaré cuando existan ofertas con una prima del {query['max_premium']:.2f} % o menor." response_text = f"✅ ¡Perfecto! Te avisaré cuando existan ofertas con una prima del {query['max_premium']:.2f} % o menor."
await self.send(response_text, message) await self.send(response_text, message)