44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
|
import logging
|
||
|
|
||
|
from pyrogram import filters
|
||
|
from pyrogram.enums.chat_action import ChatAction
|
||
|
from pyrogram.types import Message
|
||
|
|
||
|
from classes.pyroclient import PyroClient
|
||
|
from modules.bwt_scrape import get_balance
|
||
|
|
||
|
logger = logging.getLogger(__name__)
|
||
|
|
||
|
|
||
|
@PyroClient.on_message(
|
||
|
~filters.scheduled & filters.private & filters.command(["balance"], prefixes=["/"]) # type: ignore
|
||
|
)
|
||
|
async def command_balance(app: PyroClient, message: Message):
|
||
|
user = await app.find_user(message.from_user)
|
||
|
|
||
|
if user.card is None:
|
||
|
logger.info("User %s tried to get balance without card set", user.id)
|
||
|
await message.reply_text(
|
||
|
app._("card_not_linked", "messages", locale=user.locale).format(
|
||
|
notice=app._("get_number", "messages", locale=user.locale)
|
||
|
)
|
||
|
)
|
||
|
return
|
||
|
|
||
|
await app.send_chat_action(chat_id=message.chat.id, action=ChatAction.TYPING)
|
||
|
balance = get_balance(user.card)
|
||
|
|
||
|
if balance is None or balance == "":
|
||
|
logger.warning("User %s could not get water balance of their card", user.id)
|
||
|
await message.reply_text(
|
||
|
app._("card_error", "messages", locale=user.locale).format(
|
||
|
link=f"https://bwtaqua.com.ua/card-topup/?id={user.card}"
|
||
|
)
|
||
|
)
|
||
|
return
|
||
|
|
||
|
logger.info("User %s has %s liters on balance", user.id, balance)
|
||
|
await message.reply_text(
|
||
|
app._("card_balance", "messages", locale=user.locale).format(balance=balance)
|
||
|
)
|