2022-12-14 15:16:14 +02:00
|
|
|
from datetime import datetime
|
2022-12-05 19:49:51 +02:00
|
|
|
from app import app
|
2023-03-09 17:25:06 +02:00
|
|
|
from pyrogram.types import (
|
|
|
|
InlineKeyboardMarkup,
|
|
|
|
InlineKeyboardButton,
|
|
|
|
ReplyKeyboardRemove,
|
|
|
|
CallbackQuery,
|
|
|
|
)
|
2022-12-27 14:36:54 +02:00
|
|
|
from pyrogram.client import Client
|
2022-12-05 19:53:09 +02:00
|
|
|
from pyrogram import filters
|
2022-12-14 15:16:14 +02:00
|
|
|
from classes.holo_user import HoloUser
|
2023-01-03 16:15:15 +02:00
|
|
|
from modules.utils import configGet, locale, logWrite
|
2022-12-05 19:49:51 +02:00
|
|
|
from modules.handlers.confirmation import confirm_yes
|
|
|
|
from modules.handlers.welcome import welcome_pass
|
2022-12-14 15:16:14 +02:00
|
|
|
from modules.database import col_tmp, col_applications
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
|
2022-12-05 19:49:51 +02:00
|
|
|
# Callbacks reapply ============================================================================================================
|
2022-12-06 11:26:22 +02:00
|
|
|
@app.on_callback_query(filters.regex("reapply_yes_[\s\S]*"))
|
2022-12-27 14:36:54 +02:00
|
|
|
async def callback_reapply_query_accept(app: Client, clb: CallbackQuery):
|
2022-12-05 19:49:51 +02:00
|
|
|
fullclb = clb.data.split("_")
|
2022-12-14 15:16:14 +02:00
|
|
|
holo_user = HoloUser(int(fullclb[2]))
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
await app.send_message(
|
|
|
|
configGet("admin", "groups"),
|
|
|
|
locale("approved_by", "message").format(clb.from_user.first_name, holo_user.id),
|
|
|
|
disable_notification=True,
|
|
|
|
)
|
|
|
|
logWrite(
|
|
|
|
f"User {holo_user.id} got their reapplication approved by {clb.from_user.id}"
|
|
|
|
)
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
await app.send_message(
|
|
|
|
holo_user.id, locale("approved_joined", "message", locale=holo_user)
|
|
|
|
)
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2023-01-11 13:28:58 +02:00
|
|
|
applications = col_applications.find({"user": holo_user.id})
|
|
|
|
|
|
|
|
if len(list(applications)) > 1:
|
|
|
|
col_applications.delete_many({"user": holo_user.id})
|
2023-03-09 17:25:06 +02:00
|
|
|
col_applications.insert_one(
|
|
|
|
{
|
|
|
|
"user": holo_user.id,
|
|
|
|
"date": datetime.now(),
|
|
|
|
"admin": clb.from_user.id,
|
|
|
|
"application": col_tmp.find_one(
|
|
|
|
{"user": {"$eq": holo_user.id}, "type": {"$eq": "application"}}
|
|
|
|
)["application"],
|
|
|
|
}
|
|
|
|
)
|
2023-01-11 13:28:58 +02:00
|
|
|
elif applications == 1:
|
2023-03-09 17:25:06 +02:00
|
|
|
col_applications.find_one_and_replace(
|
|
|
|
{"user": holo_user.id},
|
|
|
|
{
|
|
|
|
"user": holo_user.id,
|
|
|
|
"date": datetime.now(),
|
|
|
|
"admin": clb.from_user.id,
|
|
|
|
"application": col_tmp.find_one(
|
|
|
|
{"user": {"$eq": holo_user.id}, "type": {"$eq": "application"}}
|
|
|
|
)["application"],
|
|
|
|
},
|
|
|
|
)
|
2023-01-11 13:28:58 +02:00
|
|
|
else:
|
2023-03-09 17:25:06 +02:00
|
|
|
col_applications.insert_one(
|
|
|
|
{
|
|
|
|
"user": holo_user.id,
|
|
|
|
"date": datetime.now(),
|
|
|
|
"admin": clb.from_user.id,
|
|
|
|
"application": col_tmp.find_one(
|
|
|
|
{"user": {"$eq": holo_user.id}, "type": {"$eq": "application"}}
|
|
|
|
)["application"],
|
|
|
|
}
|
|
|
|
)
|
|
|
|
col_tmp.update_one(
|
|
|
|
{"user": holo_user.id, "type": "application"},
|
|
|
|
{"$set": {"state": "approved", "sent": False}},
|
|
|
|
)
|
|
|
|
|
|
|
|
edited_markup = [
|
|
|
|
[
|
|
|
|
InlineKeyboardButton(
|
|
|
|
text=str(locale("accepted", "button")), callback_data="nothing"
|
|
|
|
)
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
await clb.message.edit(
|
|
|
|
text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup)
|
|
|
|
)
|
|
|
|
await clb.answer(
|
|
|
|
text=locale("sub_accepted", "callback", locale=clb.from_user).format(
|
|
|
|
holo_user.id
|
|
|
|
),
|
|
|
|
show_alert=True,
|
|
|
|
)
|
2022-12-05 19:49:51 +02:00
|
|
|
|
|
|
|
need_link = True
|
|
|
|
|
2023-01-04 20:59:09 +02:00
|
|
|
async for member in app.get_chat_members(configGet("users", "groups")):
|
2022-12-14 15:16:14 +02:00
|
|
|
if member.user.id == holo_user.id:
|
2022-12-05 19:49:51 +02:00
|
|
|
need_link = False
|
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
if need_link:
|
|
|
|
link = await app.create_chat_invite_link(
|
|
|
|
configGet("users", "groups"),
|
|
|
|
name=f"Invite for {holo_user.id}",
|
|
|
|
member_limit=1,
|
|
|
|
) # , expire_date=datetime.now()+timedelta(days=1))
|
|
|
|
|
|
|
|
await app.send_message(
|
|
|
|
holo_user.id, locale("read_rules", "message", locale=holo_user)
|
|
|
|
)
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2022-12-17 01:58:33 +02:00
|
|
|
for rule_msg in locale("rules", locale=holo_user):
|
2022-12-14 15:16:14 +02:00
|
|
|
await app.send_message(holo_user.id, rule_msg)
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
await app.send_message(
|
|
|
|
holo_user.id,
|
|
|
|
locale("approved", "message"),
|
|
|
|
reply_markup=InlineKeyboardMarkup(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
InlineKeyboardButton(
|
|
|
|
str(locale("join", "button", locale=holo_user)),
|
|
|
|
url=link.invite_link,
|
|
|
|
)
|
|
|
|
]
|
|
|
|
]
|
|
|
|
),
|
|
|
|
)
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2022-12-14 15:16:14 +02:00
|
|
|
holo_user.set("link", link.invite_link)
|
|
|
|
logWrite(f"User {holo_user.id} got an invite link {link.invite_link}")
|
2022-12-05 19:49:51 +02:00
|
|
|
|
|
|
|
else:
|
2023-03-09 17:25:06 +02:00
|
|
|
await app.send_message(
|
|
|
|
holo_user.id, locale("approved_joined", "message", locale=holo_user)
|
|
|
|
)
|
|
|
|
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2022-12-06 11:26:22 +02:00
|
|
|
@app.on_callback_query(filters.regex("reapply_no_[\s\S]*"))
|
2022-12-27 14:36:54 +02:00
|
|
|
async def callback_query_reapply_reject(app: Client, clb: CallbackQuery):
|
2022-12-05 19:49:51 +02:00
|
|
|
fullclb = clb.data.split("_")
|
2022-12-14 15:16:14 +02:00
|
|
|
holo_user = HoloUser(int(fullclb[2]))
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
await app.send_message(
|
|
|
|
configGet("admin", "groups"),
|
|
|
|
locale("rejected_by", "message").format(clb.from_user.first_name, fullclb[2]),
|
|
|
|
disable_notification=True,
|
|
|
|
)
|
|
|
|
await app.send_message(
|
|
|
|
holo_user.id, locale("rejected", "message", locale=holo_user)
|
|
|
|
)
|
|
|
|
logWrite(
|
|
|
|
f"User {fullclb[2]} got their reapplication rejected by {clb.from_user.id}"
|
|
|
|
)
|
|
|
|
|
|
|
|
col_tmp.update_one(
|
|
|
|
{"user": {"$eq": holo_user.id}, "type": {"$eq": "application"}},
|
|
|
|
{"$set": {"state": "rejected", "sent": False}},
|
|
|
|
)
|
|
|
|
|
|
|
|
edited_markup = [
|
|
|
|
[
|
|
|
|
InlineKeyboardButton(
|
|
|
|
text=str(locale("declined", "button")), callback_data="nothing"
|
|
|
|
)
|
|
|
|
],
|
|
|
|
[
|
|
|
|
InlineKeyboardButton(
|
|
|
|
text=str(locale("ban", "button")), callback_data=f"ban_{fullclb[2]}"
|
|
|
|
)
|
|
|
|
],
|
|
|
|
]
|
|
|
|
|
|
|
|
await clb.message.edit(
|
|
|
|
text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup)
|
|
|
|
)
|
|
|
|
await clb.answer(
|
|
|
|
text=locale("sub_rejected", "callback", locale=clb.from_user).format(
|
|
|
|
fullclb[2]
|
|
|
|
),
|
|
|
|
show_alert=True,
|
|
|
|
)
|
2022-12-05 19:49:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Use old application when user reapplies after leaving the chat
|
2022-12-06 11:26:22 +02:00
|
|
|
@app.on_callback_query(filters.regex("reapply_old_[\s\S]*"))
|
2022-12-27 14:36:54 +02:00
|
|
|
async def callback_query_reapply_old(app: Client, clb: CallbackQuery):
|
2022-12-05 19:49:51 +02:00
|
|
|
fullclb = clb.data.split("_")
|
2023-01-16 13:10:07 +02:00
|
|
|
holo_user = HoloUser(clb.from_user)
|
2022-12-27 14:23:24 +02:00
|
|
|
|
2023-01-16 13:10:07 +02:00
|
|
|
if holo_user.sponsorship_state()[0] == "fill":
|
2023-03-09 17:25:06 +02:00
|
|
|
await clb.message.reply_text(
|
|
|
|
locale("finish_sponsorship", "message"), quote=False
|
|
|
|
)
|
2022-12-27 14:23:24 +02:00
|
|
|
return
|
2022-12-27 14:36:54 +02:00
|
|
|
|
2022-12-05 19:49:51 +02:00
|
|
|
message = await app.get_messages(clb.from_user.id, int(fullclb[2]))
|
2023-01-16 13:10:07 +02:00
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
if (
|
|
|
|
col_tmp.find_one({"user": holo_user.id, "type": "application"}) is None
|
|
|
|
and col_applications.find_one({"user": holo_user.id}) is not None
|
|
|
|
):
|
2023-01-16 13:10:07 +02:00
|
|
|
col_tmp.insert_one(
|
|
|
|
{
|
|
|
|
"user": holo_user.id,
|
|
|
|
"type": "application",
|
|
|
|
"complete": True,
|
|
|
|
"sent": False,
|
|
|
|
"state": "fill",
|
|
|
|
"reapply": True,
|
|
|
|
"stage": 10,
|
2023-03-09 17:25:06 +02:00
|
|
|
"application": col_applications.find_one({"user": holo_user.id})[
|
|
|
|
"application"
|
|
|
|
],
|
2023-01-16 13:10:07 +02:00
|
|
|
}
|
|
|
|
)
|
2023-03-09 17:25:06 +02:00
|
|
|
|
2022-12-22 16:05:27 +02:00
|
|
|
await confirm_yes(app, message, kind="application")
|
2023-03-09 17:25:06 +02:00
|
|
|
await clb.message.edit(
|
|
|
|
clb.message.text,
|
|
|
|
reply_markup=InlineKeyboardMarkup(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
InlineKeyboardButton(
|
|
|
|
locale("done", "button", locale=clb.from_user), "nothing"
|
|
|
|
)
|
|
|
|
]
|
|
|
|
]
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2022-12-05 19:49:51 +02:00
|
|
|
|
|
|
|
# Start a new application when user reapplies after leaving the chat
|
2022-12-06 11:26:22 +02:00
|
|
|
@app.on_callback_query(filters.regex("reapply_new_[\s\S]*"))
|
2022-12-27 14:36:54 +02:00
|
|
|
async def callback_query_reapply_new(app: Client, clb: CallbackQuery):
|
2022-12-05 19:49:51 +02:00
|
|
|
fullclb = clb.data.split("_")
|
|
|
|
|
2023-02-20 16:04:24 +02:00
|
|
|
holo_user = HoloUser(clb.from_user)
|
|
|
|
|
|
|
|
if holo_user.sponsorship_state()[0] == "fill":
|
2023-03-09 17:25:06 +02:00
|
|
|
await clb.message.reply_text(
|
|
|
|
locale("finish_sponsorship", "message"), quote=False
|
|
|
|
)
|
2022-12-27 14:23:24 +02:00
|
|
|
return
|
|
|
|
|
2022-12-17 01:58:33 +02:00
|
|
|
await clb.answer(locale("reapply_stopped", "callback", locale=clb.from_user))
|
2022-12-05 19:49:51 +02:00
|
|
|
message = await app.get_messages(clb.from_user.id, int(fullclb[2]))
|
2023-03-09 17:25:06 +02:00
|
|
|
col_tmp.update_one(
|
|
|
|
{"user": clb.from_user.id, "type": "application"},
|
|
|
|
{"$set": {"state": "fill", "completed": False, "stage": 1}},
|
|
|
|
)
|
2023-02-20 16:04:24 +02:00
|
|
|
holo_user.application_restart(reapply=True)
|
2022-12-05 19:49:51 +02:00
|
|
|
await welcome_pass(app, message, once_again=True)
|
2023-03-09 17:25:06 +02:00
|
|
|
logWrite(
|
|
|
|
f"User {clb.from_user.id} restarted the application after leaving the chat earlier"
|
|
|
|
)
|
|
|
|
await clb.message.edit(
|
|
|
|
clb.message.text,
|
|
|
|
reply_markup=InlineKeyboardMarkup(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
InlineKeyboardButton(
|
|
|
|
locale("done", "button", locale=clb.from_user), "nothing"
|
|
|
|
)
|
|
|
|
]
|
|
|
|
]
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2022-12-05 19:49:51 +02:00
|
|
|
|
|
|
|
# Abort application fill in progress and restart it
|
2022-12-06 11:26:22 +02:00
|
|
|
@app.on_callback_query(filters.regex("reapply_stop_[\s\S]*"))
|
2022-12-27 14:36:54 +02:00
|
|
|
async def callback_query_reapply_stop(app: Client, clb: CallbackQuery):
|
2022-12-05 19:49:51 +02:00
|
|
|
fullclb = clb.data.split("_")
|
2022-12-14 15:16:14 +02:00
|
|
|
holo_user = HoloUser(clb.from_user)
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2022-12-14 15:16:14 +02:00
|
|
|
holo_user.application_restart()
|
2022-12-17 01:58:33 +02:00
|
|
|
await clb.answer(locale("reapply_stopped", "callback", locale=holo_user))
|
2022-12-05 19:49:51 +02:00
|
|
|
message = await app.get_messages(clb.from_user.id, int(fullclb[2]))
|
|
|
|
await welcome_pass(app, message, once_again=True)
|
|
|
|
logWrite(f"User {clb.from_user.id} restarted the application due to typo in it")
|
2023-03-09 17:25:06 +02:00
|
|
|
await clb.message.edit(
|
|
|
|
locale("reapply_restarted", "message", locale=holo_user),
|
|
|
|
reply_markup=ReplyKeyboardRemove(),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# ==============================================================================================================================
|