Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
fix: handle blocked account
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-napoleone committed Jul 27, 2021
1 parent eeecb04 commit 97336ae
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions terra_ltv_bot/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from aiogram import Bot
from aiogram.dispatcher import Dispatcher
from aiogram.utils.exceptions import TelegramAPIError
from aioredis import Redis

from .models import Address, Subscription
Expand Down Expand Up @@ -66,15 +67,23 @@ async def check_ltv_ratio(self) -> None:
threshold = subscription.alert_threshold or 45
cache_key = f"{account_address}:anchor:{subscription.telegram_id}"
if threshold <= ltv and not await self.redis.get(cache_key):
await self.bot.send_message(
subscription.telegram_id,
(
f"🚨 Anchor LTV ratio is over {threshold}% ({ltv}%):\n"
f"<pre>{account_address}</pre>"
),
)
log.info(f"{account_address} {subscription.telegram_id} {ltv} alerted")
await self.redis.set(cache_key, 1, ex=timedelta(hours=1))
try:
await self.bot.send_message(
subscription.telegram_id,
(
f"🚨 Anchor LTV ratio is over {threshold}% ({ltv}%):\n"
f"<pre>{account_address}</pre>"
),
)
log.info(
f"{account_address} {subscription.telegram_id} {ltv} alerted"
)
await self.redis.set(cache_key, 1, ex=timedelta(hours=1))
except TelegramAPIError as e:
log.warning(
f"Couldn't send alert to {subscription.telegram_id} "
f"for {account_address}: {e}"
)
elif threshold <= ltv:
log.debug(f"{account_address} {subscription.telegram_id} {ltv} muted")
else:
Expand Down

0 comments on commit 97336ae

Please sign in to comment.