Skip to content

Commit

Permalink
feat: send initial notification after subscription (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackstar12 authored Feb 13, 2025
1 parent 1d92d59 commit 95f20f8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 1 addition & 5 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@
)
from settings import Settings
from commands.subscribe import subscribe_handler
from utils import encode_url_params
from utils import encode_url_params, get_fee

logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(message)s")
logging.getLogger("apscheduler").setLevel(logging.WARN)
logging.getLogger("httpx").setLevel(logging.WARN)


def get_fee(fees: Fees, subscription: Subscription) -> float | None:
return fees.get(subscription.from_asset, {}).get(subscription.to_asset, None)


async def notify_subscription(
bot: Bot,
subscription: Subscription,
Expand Down
7 changes: 6 additions & 1 deletion commands/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
get_subscriptions,
get_previous,
)
from utils import encode_url_params, get_fee

FROM_ASSET, TO_ASSET, THRESHOLD, CUSTOM_THRESHOLD = range(4)

Expand Down Expand Up @@ -116,8 +117,12 @@ async def save_threshold(
return

if await add_subscription(session, subscription):
latest = await get_previous(session, ALL_FEES)
current_value = get_fee(latest, subscription)
url = encode_url_params(subscription.from_asset, subscription.to_asset)
await chat.send_message(
f"You have subscribed to fee alerts for {subscription.pretty_string()}!",
f"You have subscribed to fee alerts for *{subscription.pretty_string()}*!\nCurrent fees: [{current_value}%]({url})",
parse_mode="markdown",
)
logging.info(f"Added: {subscription}")
else:
Expand Down
7 changes: 6 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from urllib.parse import urlencode

from consts import PRO_URL, SwapType
from consts import PRO_URL, SwapType, Fees
from db import Subscription


def get_fee(fees: Fees, subscription: Subscription) -> float | None:
return fees.get(subscription.from_asset, {}).get(subscription.to_asset, None)


def currency_to_asset(swap_type: SwapType, currency: str, is_send: bool):
Expand Down

0 comments on commit 95f20f8

Please sign in to comment.