Big and tasty update to v2.0
This commit is contained in:
@@ -1,63 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
from traceback import format_exc
|
||||
|
||||
from libbot import config_get, json_read
|
||||
from pyrogram import filters
|
||||
from pyrogram.client import Client
|
||||
from pyrogram.enums.chat_action import ChatAction
|
||||
from pyrogram.types import Message
|
||||
|
||||
from modules.utils import string, userGet
|
||||
from modules.bwt import getWaterLeft
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@Client.on_message(
|
||||
~filters.scheduled & filters.command(["balance", "баланс"], prefixes=["/", ""]) # type: ignore
|
||||
)
|
||||
async def command_balance(app: Client, msg: Message):
|
||||
try:
|
||||
if "card" in (await json_read("data/database.json"))[str(msg.from_user.id)]:
|
||||
await app.send_chat_action(chat_id=msg.chat.id, action=ChatAction.TYPING)
|
||||
water_left = await getWaterLeft(
|
||||
userGet(msg.from_user.id, "card"), msg.from_user.id, app
|
||||
)
|
||||
if water_left == "":
|
||||
await msg.reply_text(
|
||||
(await string("error_new")).format(
|
||||
f'https://bwtaqua.com.ua/card-topup/?id={userGet(msg.from_user.id, "card")}'
|
||||
)
|
||||
)
|
||||
# raise EmptyCardException("Card information is empty")
|
||||
elif water_left == "Failure":
|
||||
await msg.reply_text(
|
||||
(await string("error_occured")).format(await string("get_number"))
|
||||
)
|
||||
logger.warning(
|
||||
f"User {str(msg.from_user.id)} could not get left water amount"
|
||||
)
|
||||
else:
|
||||
await msg.reply_text((await string("card_balance")).format(water_left))
|
||||
logger.info(
|
||||
f"User {str(msg.from_user.id)} has {water_left} liters remaining"
|
||||
)
|
||||
else:
|
||||
await msg.reply_text(
|
||||
(await string("card_not_linked")).format(await string("get_number"))
|
||||
)
|
||||
logger.info(
|
||||
f"User {str(msg.from_user.id)} tried to get balance without card set"
|
||||
)
|
||||
except Exception as exp:
|
||||
if msg.from_user.id != app.owner:
|
||||
await msg.reply_text(
|
||||
(await string("error_occured")).format(await string("get_number"))
|
||||
)
|
||||
await app.send_message(
|
||||
app.owner,
|
||||
f"Error occured by {str(msg.from_user.id)}:\nException: `{exp}`\nTraceback: `{format_exc()}`",
|
||||
)
|
||||
logger.warning(f"User {str(msg.from_user.id)} could not get left water amount")
|
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)
|
||||
)
|
@@ -1,24 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from libbot import json_read
|
||||
from pyrogram import filters
|
||||
from pyrogram.client import Client
|
||||
from pyrogram.types import Message
|
||||
|
||||
from modules.utils import string, userSet
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@Client.on_message(
|
||||
~filters.scheduled
|
||||
& filters.command(["start", "help", "допомога"], prefixes=["/", ""]) # type: ignore
|
||||
)
|
||||
async def command_help(app: Client, msg: Message):
|
||||
await msg.reply_text((await string("welcome")).format(await string("get_number")))
|
||||
if msg.from_user.language_code in await json_read("strings.json"):
|
||||
userSet(msg.from_user.id, "locale", msg.from_user.language_code)
|
||||
else:
|
||||
userSet(msg.from_user.id, "locale", "en")
|
45
plugins/language.py
Normal file
45
plugins/language.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from typing import List
|
||||
|
||||
from pykeyboard import InlineButton, InlineKeyboard
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import CallbackQuery, Message
|
||||
|
||||
from classes.callbacks import CallbackLanguage
|
||||
from classes.pyroclient import PyroClient
|
||||
|
||||
|
||||
@PyroClient.on_message(
|
||||
~filters.scheduled & filters.private & filters.command(["language"], prefixes=["/"]) # type: ignore
|
||||
)
|
||||
async def command_language(app: PyroClient, message: Message):
|
||||
user = await app.find_user(message.from_user)
|
||||
|
||||
keyboard = InlineKeyboard(row_width=2)
|
||||
buttons: List[InlineButton] = []
|
||||
|
||||
for locale, data in app.in_every_locale("metadata").items():
|
||||
buttons.append(
|
||||
InlineButton(f"{data['flag']} {data['name']}", f"language:{locale}")
|
||||
)
|
||||
|
||||
keyboard.add(*buttons)
|
||||
|
||||
await message.reply_text(
|
||||
app._("locale_choice", "messages", locale=user.locale),
|
||||
reply_markup=keyboard,
|
||||
)
|
||||
|
||||
|
||||
@PyroClient.on_callback_query(filters.regex(r"language:[\s\S]*")) # type: ignore
|
||||
async def callback_language(app: PyroClient, callback: CallbackQuery):
|
||||
user = await app.find_user(callback.from_user)
|
||||
parsed = CallbackLanguage.from_callback(callback)
|
||||
|
||||
await user.update_locale(parsed.language)
|
||||
|
||||
await callback.answer(
|
||||
app._("locale_set", "callbacks", locale=parsed.language).format(
|
||||
locale=app._("name", "metadata", locale=parsed.language)
|
||||
),
|
||||
show_alert=True,
|
||||
)
|
@@ -1,28 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from libbot import json_read
|
||||
from pyrogram import filters
|
||||
from pyrogram.client import Client
|
||||
from pyrogram.types import Message
|
||||
|
||||
from modules.utils import string, userReset
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@Client.on_message(
|
||||
~filters.scheduled
|
||||
& filters.command(["resetcard", "забути картку"], prefixes=["/", ""]) # type: ignore
|
||||
)
|
||||
async def command_resetcard(app: Client, msg: Message):
|
||||
if "card" in (await json_read("data/database.json"))[str(msg.from_user.id)]:
|
||||
userReset(msg.from_user.id, "card")
|
||||
await msg.reply_text(await string("card_unlinked"))
|
||||
logger.info(f"User {str(msg.from_user.id)} reseted his card")
|
||||
else:
|
||||
await msg.reply_text(
|
||||
(await string("card_not_linked")).format(await string("get_number"))
|
||||
)
|
||||
logger.info(f"User {str(msg.from_user.id)} tried to reset non-existent card")
|
@@ -1,35 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from convopyro import listen_message
|
||||
from pyrogram import filters
|
||||
from pyrogram.client import Client
|
||||
from pyrogram.types import ForceReply, Message, ReplyKeyboardRemove
|
||||
|
||||
from modules.utils import string, userSet
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@Client.on_message(
|
||||
~filters.scheduled
|
||||
& filters.command(["setcard", "задать карту"], prefixes=["/", ""]) # type: ignore
|
||||
)
|
||||
async def command_setcard(app: Client, msg: Message):
|
||||
await msg.reply_text(
|
||||
await string("send_number"),
|
||||
reply_markup=ForceReply(placeholder=await string("enter_number")),
|
||||
)
|
||||
answer = await listen_message(app, msg.chat.id, timeout=None)
|
||||
if answer is None:
|
||||
return
|
||||
elif answer.text.strip() in ["/cancel", "cancel", "/відміна", "відміна"]:
|
||||
await msg.reply_text(await string("cancel"), reply_markup=ReplyKeyboardRemove())
|
||||
return
|
||||
userSet(answer.from_user.id, "card", answer.text)
|
||||
logger.info(f"User {str(msg.from_user.id)} set card id to {answer.text}")
|
||||
await msg.reply_text(
|
||||
(await string("card_linked")).format(answer.text),
|
||||
reply_markup=ReplyKeyboardRemove(),
|
||||
)
|
@@ -1,21 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
from os import getpid
|
||||
|
||||
from libbot import config_get
|
||||
from pyrogram import filters
|
||||
from pyrogram.client import Client
|
||||
from pyrogram.types import Message
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@Client.on_message(
|
||||
~filters.scheduled & filters.command(["kill", "die", "shutdown"], prefixes="/") # type: ignore
|
||||
)
|
||||
async def command_shutdown(app: Client, msg: Message):
|
||||
if msg.from_user.id == app.owner:
|
||||
await msg.reply_text(f"Shutting down bot with pid **{getpid()}**")
|
||||
logger.info(f"Shutting down as requested by {msg.from_user.id}")
|
||||
exit()
|
@@ -1,36 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from libbot import json_read
|
||||
from pyrogram import filters
|
||||
from pyrogram.client import Client
|
||||
from pyrogram.enums.chat_action import ChatAction
|
||||
from pyrogram.types import Message
|
||||
|
||||
from modules.utils import string, userGet
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@Client.on_message(
|
||||
~filters.scheduled
|
||||
& filters.command(["topup", "refill", "поповнити"], prefixes=["/", ""]) # type: ignore
|
||||
)
|
||||
async def command_topup(app: Client, msg: Message):
|
||||
try:
|
||||
if "card" in (await json_read("data/database.json"))[str(msg.from_user.id)]:
|
||||
await app.send_chat_action(chat_id=msg.chat.id, action=ChatAction.TYPING)
|
||||
await msg.reply_text(
|
||||
(await string("top_up")).format(str(userGet(msg.from_user.id, "card")))
|
||||
)
|
||||
logger.info(f"User {str(msg.from_user.id)} requested top up")
|
||||
else:
|
||||
await msg.reply_text(
|
||||
(await string("card_not_linked")).format(await string("get_number"))
|
||||
)
|
||||
logger.info(
|
||||
f"User {str(msg.from_user.id)} tried to request top up without card set"
|
||||
)
|
||||
except Exception as exp:
|
||||
await msg.reply_text(str(exp))
|
Reference in New Issue
Block a user