2022-12-21 13:25:47 +02:00
|
|
|
from datetime import datetime
|
|
|
|
from app import app
|
2022-12-27 14:23:24 +02:00
|
|
|
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ForceReply, CallbackQuery
|
|
|
|
from pyrogram.client import Client
|
2022-12-21 13:25:47 +02:00
|
|
|
from pyrogram import filters
|
2023-01-05 21:46:47 +02:00
|
|
|
from classes.holo_user import HoloUser, LabelSettingError
|
2022-12-27 14:23:24 +02:00
|
|
|
from modules.utils import configGet, locale, logWrite, should_quote
|
2022-12-22 16:05:27 +02:00
|
|
|
from modules.database import col_tmp, col_sponsorships
|
2022-12-21 13:25:47 +02:00
|
|
|
|
|
|
|
# Callbacks sponsorship ========================================================================================================
|
|
|
|
@app.on_callback_query(filters.regex("sponsor_apply_[\s\S]*"))
|
2022-12-27 14:23:24 +02:00
|
|
|
async def callback_query_sponsor_apply(app: Client, clb: CallbackQuery):
|
2022-12-21 13:25:47 +02:00
|
|
|
|
|
|
|
fullclb = clb.data.split("_")
|
|
|
|
holo_user = HoloUser(int(fullclb[2]))
|
|
|
|
|
2022-12-27 14:23:24 +02:00
|
|
|
if holo_user.application_state()[0] == "fill":
|
|
|
|
await clb.message.reply_text(locale("finish_application", "message"), quote=should_quote(clb.message))
|
|
|
|
return
|
|
|
|
|
2022-12-21 13:25:47 +02:00
|
|
|
logWrite(f"User {holo_user.id} applied for sponsorship")
|
|
|
|
|
2022-12-22 16:05:27 +02:00
|
|
|
holo_user.sponsorship_restart()
|
2022-12-21 13:25:47 +02:00
|
|
|
|
|
|
|
edited_markup = [[InlineKeyboardButton(text=str(locale("sponsor_started", "button")), callback_data="nothing")]]
|
|
|
|
|
2022-12-28 20:01:21 +02:00
|
|
|
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)
|
2022-12-22 16:05:27 +02:00
|
|
|
|
|
|
|
@app.on_callback_query(filters.regex("sponsor_yes_[\s\S]*"))
|
2022-12-27 14:36:54 +02:00
|
|
|
async def callback_query_sponsor_yes(app: Client, clb: CallbackQuery):
|
2022-12-22 16:05:27 +02:00
|
|
|
|
|
|
|
fullclb = clb.data.split("_")
|
|
|
|
holo_user = HoloUser(int(fullclb[2]))
|
|
|
|
|
2023-01-04 20:14:02 +02:00
|
|
|
await app.send_message(configGet("admin", "groups"), locale("sponsor_approved_by", "message").format(clb.from_user.first_name, holo_user.id), disable_notification=True)
|
2022-12-22 16:05:27 +02:00
|
|
|
await app.send_message(holo_user.id, locale("sponsor_approved", "message", locale=holo_user))
|
2023-01-02 15:24:29 +02:00
|
|
|
logWrite(f"User {holo_user.id} got sponsorship approved by {clb.from_user.id}")
|
2022-12-22 16:05:27 +02:00
|
|
|
|
|
|
|
if col_sponsorships.find_one({"user": holo_user.id}) is not None:
|
2022-12-23 13:54:51 +02:00
|
|
|
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"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2022-12-22 16:05:27 +02:00
|
|
|
else:
|
2022-12-23 13:54:51 +02:00
|
|
|
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"]
|
|
|
|
}
|
|
|
|
)
|
2022-12-22 16:05:27 +02:00
|
|
|
|
2022-12-23 13:54:51 +02:00
|
|
|
col_tmp.update_one({"user": holo_user.id, "type":"sponsorship"},
|
|
|
|
{
|
|
|
|
"$set": {
|
|
|
|
"state": "approved",
|
|
|
|
"sent": False
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2022-12-22 16:05:27 +02:00
|
|
|
|
2023-01-05 21:46:47 +02:00
|
|
|
try:
|
|
|
|
await holo_user.label_set(configGet("users", "groups"), col_tmp.find_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "sponsorship"}})["sponsorship"]["label"])
|
|
|
|
except LabelSettingError as exp:
|
|
|
|
await app.send_message(configGet("admin", "groups"), exp.__str__(), disable_notification=True)
|
2022-12-22 16:05:27 +02:00
|
|
|
|
|
|
|
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))
|
2022-12-23 02:49:38 +02:00
|
|
|
await clb.answer(text=locale("sponsor_accepted", "callback").format(fullclb[2]), show_alert=False)
|
2022-12-22 16:05:27 +02:00
|
|
|
|
|
|
|
@app.on_callback_query(filters.regex("sponsor_no_[\s\S]*"))
|
2022-12-27 14:36:54 +02:00
|
|
|
async def callback_query_sponsor_no(app: Client, clb: CallbackQuery):
|
2022-12-22 16:05:27 +02:00
|
|
|
|
|
|
|
fullclb = clb.data.split("_")
|
|
|
|
holo_user = HoloUser(int(fullclb[2]))
|
|
|
|
|
2023-01-04 20:14:02 +02:00
|
|
|
await app.send_message(configGet("admin", "groups"), locale("sponsor_rejected_by", "message").format(clb.from_user.first_name, holo_user.id), disable_notification=True)
|
2022-12-22 16:05:27 +02:00
|
|
|
await app.send_message(holo_user.id, locale("sponsor_rejected", "message", locale=holo_user))
|
2023-01-02 15:24:29 +02:00
|
|
|
logWrite(f"User {holo_user.id} got sponsorship rejected by {clb.from_user.id}")
|
2022-12-22 16:05:27 +02:00
|
|
|
|
2022-12-23 13:54:51 +02:00
|
|
|
col_tmp.update_one({"user": holo_user.id, "type": "sponsorship"},
|
|
|
|
{
|
|
|
|
"$set": {
|
|
|
|
"state": "rejected",
|
|
|
|
"sent": False
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2022-12-22 16:05:27 +02:00
|
|
|
|
|
|
|
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))
|
2022-12-23 02:49:38 +02:00
|
|
|
await clb.answer(text=locale("sponsor_rejected", "callback").format(fullclb[2]), show_alert=False)
|