99 lines
4.6 KiB
Python
99 lines
4.6 KiB
Python
from datetime import datetime
|
|
from app import app
|
|
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ForceReply, CallbackQuery
|
|
from pyrogram.client import Client
|
|
from pyrogram import filters
|
|
from classes.holo_user import HoloUser
|
|
from modules.utils import configGet, locale, logWrite, should_quote
|
|
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: Client, clb: CallbackQuery):
|
|
|
|
fullclb = clb.data.split("_")
|
|
holo_user = HoloUser(int(fullclb[2]))
|
|
|
|
if holo_user.application_state()[0] == "fill":
|
|
await clb.message.reply_text(locale("finish_application", "message"), quote=should_quote(clb.message))
|
|
return
|
|
|
|
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_applying", "message", locale=holo_user), reply_markup=InlineKeyboardMarkup(edited_markup))
|
|
await app.send_message(holo_user.id, locale(f"sponsor1", "message", locale=holo_user), reply_markup=ForceReply(placeholder=str(locale(f"sponsor1", "force_reply", locale=holo_user.locale))))
|
|
await clb.answer(text=locale("sponsor_started", "callback", locale=holo_user).format(holo_user.id), show_alert=False)
|
|
|
|
@app.on_callback_query(filters.regex("sponsor_yes_[\s\S]*"))
|
|
async def callback_query_sponsor_yes(app: Client, clb: CallbackQuery):
|
|
|
|
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},
|
|
{
|
|
"$set": {
|
|
"date": datetime.now(),
|
|
"admin": clb.from_user.id,
|
|
"sponsorship": col_tmp.find_one({"user": holo_user.id, "type": "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": holo_user.id, "type": "sponsorship"})["sponsorship"]
|
|
}
|
|
)
|
|
|
|
col_tmp.update_one({"user": holo_user.id, "type":"sponsorship"},
|
|
{
|
|
"$set": {
|
|
"state": "approved",
|
|
"sent": False
|
|
}
|
|
}
|
|
)
|
|
|
|
await holo_user.label_set(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=locale("sponsor_accepted", "callback").format(fullclb[2]), show_alert=False)
|
|
|
|
@app.on_callback_query(filters.regex("sponsor_no_[\s\S]*"))
|
|
async def callback_query_sponsor_no(app: Client, clb: CallbackQuery):
|
|
|
|
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": holo_user.id, "type": "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=locale("sponsor_rejected", "callback").format(fullclb[2]), show_alert=False) |