From d5fa919f3d2f023c49fc6c3d866b34f32b6e9190 Mon Sep 17 00:00:00 2001 From: etienne-napoleone Date: Wed, 11 Aug 2021 01:23:28 +0200 Subject: [PATCH] feat: unmute on threshold change --- terra_ltv_bot/bot.py | 2 +- terra_ltv_bot/handlers.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/terra_ltv_bot/bot.py b/terra_ltv_bot/bot.py index 33b3d1c..22d11a8 100644 --- a/terra_ltv_bot/bot.py +++ b/terra_ltv_bot/bot.py @@ -34,7 +34,7 @@ async def on_startup(self, dp: Dispatcher): database=self.db, document_models=all_models, ) - Handlers(dp, self.terra) + Handlers(dp, self.terra, self.redis) Tasks(dp, self.bot, self.terra, self.redis) async def on_shutdown(self, _: Dispatcher): diff --git a/terra_ltv_bot/handlers.py b/terra_ltv_bot/handlers.py index 4531f9e..d190c4c 100644 --- a/terra_ltv_bot/handlers.py +++ b/terra_ltv_bot/handlers.py @@ -4,6 +4,7 @@ from aiogram import types from aiogram.dispatcher import Dispatcher from aiogram.utils.exceptions import Throttled +from aioredis import Redis from pymongo.errors import DuplicateKeyError from .models import Address, Subscription @@ -13,9 +14,10 @@ class Handlers: - def __init__(self, dp: Dispatcher, terra: Terra) -> None: + def __init__(self, dp: Dispatcher, terra: Terra, redis: Redis) -> None: self.dp = dp self.terra = terra + self.redis = redis dp.register_message_handler(self.start, commands=["start", "help"]) dp.register_message_handler(self.subscribe, commands=["subscribe"]) dp.register_message_handler(self.list_, commands=["list"]) @@ -90,6 +92,9 @@ async def subscribe(self, message: types.Message) -> None: if subscription: if alert_threshold != subscription.alert_threshold: subscription.alert_threshold = alert_threshold + await self.redis.delete( + f"{account_address}:anchor:{subscription.telegram_id}" + ) else: subscription = Subscription( address_id=address.id,