Big and tasty update to v2.0
This commit is contained in:
43
plugins/commands/balance.py
Normal file
43
plugins/commands/balance.py
Normal file
@@ -0,0 +1,43 @@
|
||||
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)
|
||||
)
|
12
plugins/commands/remove_commands.py
Normal file
12
plugins/commands/remove_commands.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
from classes.pyroclient import PyroClient
|
||||
|
||||
|
||||
@PyroClient.on_message(
|
||||
~filters.scheduled & filters.private & filters.command(["remove_commands"], prefixes=["/"]) # type: ignore
|
||||
)
|
||||
async def command_remove_commands(app: PyroClient, message: Message):
|
||||
await message.reply_text("Okay.")
|
||||
await app.remove_commands(command_sets=await app.collect_commands())
|
30
plugins/commands/resetcard.py
Normal file
30
plugins/commands/resetcard.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import logging
|
||||
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
from classes.pyroclient import PyroClient
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@PyroClient.on_message(
|
||||
~filters.scheduled
|
||||
& filters.command(["resetcard", "забути картку"], prefixes=["/", ""]) # type: ignore
|
||||
)
|
||||
async def command_resetcard(app: PyroClient, message: Message):
|
||||
user = await app.find_user(message.from_user)
|
||||
|
||||
if user.card is None:
|
||||
logger.info("User %s tried to reset their card, but it's null", 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 user.update_card(None)
|
||||
|
||||
logger.info("User %s has reset their card", user.id)
|
||||
await message.reply_text(app._("card_unlinked", "messages", locale=user.locale))
|
53
plugins/commands/setcard.py
Normal file
53
plugins/commands/setcard.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import logging
|
||||
|
||||
from convopyro import listen_message
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import ForceReply, Message, ReplyKeyboardRemove
|
||||
|
||||
from classes.pyroclient import PyroClient
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@PyroClient.on_message(
|
||||
~filters.scheduled
|
||||
& filters.command(["setcard", "задати картку"], prefixes=["/", ""]) # type: ignore
|
||||
)
|
||||
async def command_setcard(app: PyroClient, message: Message):
|
||||
user = await app.find_user(message.from_user)
|
||||
|
||||
await message.reply_text(
|
||||
app._("send_number", "messages", locale=user.locale),
|
||||
reply_markup=ForceReply(
|
||||
placeholder=app._("enter_number", "force_replies", locale=user.locale)
|
||||
),
|
||||
)
|
||||
|
||||
answer = await listen_message(app, message.chat.id, timeout=500)
|
||||
|
||||
if (
|
||||
answer is None
|
||||
or answer.text is None
|
||||
or answer.text.strip()
|
||||
in [
|
||||
"/cancel",
|
||||
"cancel",
|
||||
"/відміна",
|
||||
"відміна",
|
||||
]
|
||||
):
|
||||
await message.reply_text(
|
||||
app._("cancel", "messages", locale=user.locale),
|
||||
reply_markup=ReplyKeyboardRemove(),
|
||||
)
|
||||
return
|
||||
|
||||
await user.update_card(answer.text)
|
||||
|
||||
logger.info("User %s set their card id to %s", user.id, answer.text)
|
||||
await message.reply_text(
|
||||
app._("card_linked", "messages", locale=user.locale).format(
|
||||
card_id=answer.text
|
||||
),
|
||||
reply_markup=ReplyKeyboardRemove(),
|
||||
)
|
15
plugins/commands/shutdown.py
Normal file
15
plugins/commands/shutdown.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import asyncio
|
||||
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
from classes.pyroclient import PyroClient
|
||||
|
||||
|
||||
@PyroClient.on_message(
|
||||
~filters.scheduled
|
||||
& filters.command(["shutdown", "reboot", "restart"], prefixes=["/", ""]) # type: ignore
|
||||
)
|
||||
async def command_shutdown(app: PyroClient, message: Message):
|
||||
if message.from_user.id == app.owner:
|
||||
asyncio.get_event_loop().create_task(app.stop())
|
17
plugins/commands/start.py
Normal file
17
plugins/commands/start.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
from classes.pyroclient import PyroClient
|
||||
|
||||
|
||||
@PyroClient.on_message(
|
||||
~filters.scheduled & filters.private & filters.command(["start", "welcome", "help"], prefixes=["/", ""]) # type: ignore
|
||||
)
|
||||
async def command_start(app: PyroClient, message: Message):
|
||||
user = await app.find_user(message.from_user)
|
||||
|
||||
await message.reply_text(
|
||||
app._("welcome", "messages", locale=user.locale).format(
|
||||
notice=app._("get_number", "messages", locale=user.locale)
|
||||
)
|
||||
)
|
30
plugins/commands/topup.py
Normal file
30
plugins/commands/topup.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import logging
|
||||
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
from classes.pyroclient import PyroClient
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@PyroClient.on_message(
|
||||
~filters.scheduled
|
||||
& filters.command(["topup", "refill", "поповнити"], prefixes=["/", ""]) # type: ignore
|
||||
)
|
||||
async def command_topup(app: PyroClient, message: Message):
|
||||
user = await app.find_user(message.from_user)
|
||||
|
||||
if user.card is None:
|
||||
logger.info("User %s tried to get card's top-up link, but it's null", user.id)
|
||||
await message.reply_text(
|
||||
app._("card_not_linked", "messages", locale=user.locale).format(
|
||||
notice=app._("get_number", "messages", locale=user.locale)
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
logger.info("User %s requested top-up link", user.id)
|
||||
await message.reply_text(
|
||||
app._("top_up", "messages", locale=user.locale).format(card_id=user.card)
|
||||
)
|
Reference in New Issue
Block a user