from datetime import datetime from app import app from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ForceReply from pyrogram import filters from classes.holo_user import HoloUser from modules.utils import configGet, locale, logWrite from modules.database import col_tmp, col_sponsorships # Callbacks sponsorship ======================================================================================================== @app.on_callback_query(filters.regex("sponsor_apply_[\s\S]*")) async def callback_query_sponsor_apply(app, clb): fullclb = clb.data.split("_") holo_user = HoloUser(int(fullclb[2])) logWrite(f"User {holo_user.id} applied for sponsorship") holo_user.sponsorship_restart() edited_markup = [[InlineKeyboardButton(text=str(locale("sponsor_started", "button")), callback_data="nothing")]] await clb.message.edit(text=locale("sponsorship_apply", "message"), reply_markup=InlineKeyboardMarkup(edited_markup)) await app.send_message(holo_user.id, locale(f"sponsor1", "message", locale=holo_user.locale), reply_markup=ForceReply(placeholder=str(locale(f"sponsor1", "force_reply", locale=holo_user.locale)))) await clb.answer(text=locale("sponsor_started", "callback").format(holo_user.id), show_alert=False) @app.on_callback_query(filters.regex("sponsor_yes_[\s\S]*")) async def callback_query_sponsor_yes(app, clb): fullclb = clb.data.split("_") holo_user = HoloUser(int(fullclb[2])) await app.send_message(configGet("admin_group"), locale("sponsor_approved_by", "message").format(clb.from_user.first_name, holo_user.id), disable_notification=True) await app.send_message(holo_user.id, locale("sponsor_approved", "message", locale=holo_user)) logWrite(f"User {holo_user.id} got approved by {clb.from_user.id}") if col_sponsorships.find_one({"user": holo_user.id}) is not None: col_sponsorships.update_one({"user": holo_user.id}, {"date": {"$eq": datetime.now()}, "admin": {"$eq": clb.from_user.id}, "sponsorship": {"$eq": col_tmp.find_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "sponsorship"}})["sponsorship"]}}) else: col_sponsorships.insert_one({"user": holo_user.id, "date": datetime.now(), "admin": clb.from_user.id, "sponsorship": col_tmp.find_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "sponsorship"}})["sponsorship"]}) col_tmp.update_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "sponsorship"}}, {"$set": {"state": "approved", "sent": False}}) await holo_user.set_label(configGet("destination_group"), col_tmp.find_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "sponsorship"}})["sponsorship"]["label"]) edited_markup = [[InlineKeyboardButton(text=str(locale("accepted", "button")), callback_data="nothing")]] await app.edit_message_caption(clb.message.chat.id, clb.message.id, caption=clb.message.caption, reply_markup=InlineKeyboardMarkup(edited_markup)) await clb.answer(text=f"✅ Confirmed {fullclb[2]}", show_alert=False) @app.on_callback_query(filters.regex("sponsor_no_[\s\S]*")) async def callback_query_sponsor_no(app, clb): fullclb = clb.data.split("_") holo_user = HoloUser(int(fullclb[2])) await app.send_message(configGet("admin_group"), locale("sponsor_rejected_by", "message").format(clb.from_user.first_name, holo_user.id), disable_notification=True) await app.send_message(holo_user.id, locale("sponsor_rejected", "message", locale=holo_user)) logWrite(f"User {holo_user.id} got rejected by {clb.from_user.id}") col_tmp.update_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "sponsorship"}}, {"$set": {"state": "rejected", "sent": False}}) edited_markup = [[InlineKeyboardButton(text=str(locale("declined", "button")), callback_data="nothing")]] await app.edit_message_caption(clb.message.chat.id, clb.message.id, caption=clb.message.caption, reply_markup=InlineKeyboardMarkup(edited_markup)) await clb.answer(text=f"❌ Rejected {fullclb[2]}", show_alert=False)