This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Telegram/modules/commands/reapply.py

170 lines
6.7 KiB
Python
Raw Normal View History

2022-12-05 19:49:51 +02:00
from app import app
from pyrogram import filters
2022-12-27 14:36:54 +02:00
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, Message
from pyrogram.client import Client
2022-12-14 14:58:06 +02:00
from classes.holo_user import HoloUser
2023-01-09 14:19:17 +02:00
from modules.logging import logWrite
2022-12-27 14:23:24 +02:00
from modules.utils import configGet, locale, should_quote
2022-12-05 19:49:51 +02:00
from modules.handlers.welcome import welcome_pass
2023-01-16 13:10:07 +02:00
from modules.database import col_tmp, col_applications
2023-01-03 21:34:13 +02:00
from modules import custom_filters
2022-12-05 19:49:51 +02:00
2023-03-09 17:25:06 +02:00
@app.on_message(
custom_filters.enabled_applications
& ~filters.scheduled
& filters.private
& filters.command(["reapply"], prefixes=["/"])
& ~custom_filters.banned
)
2022-12-27 14:36:54 +02:00
async def cmd_reapply(app: Client, msg: Message):
2022-12-14 14:58:06 +02:00
holo_user = HoloUser(msg.from_user)
# Check if user has approved/rejected tmp application
2023-03-09 17:25:06 +02:00
if (
(holo_user.application_state()[0] in ["approved", "rejected"])
or (holo_user.application_state()[0] == "none")
) and holo_user.spoiler_state() is False:
# Check if user's tmp application is already completed or even sent
2023-03-09 17:25:06 +02:00
if (
(holo_user.application_state()[1] is True)
and (
not col_tmp.find_one({"user": holo_user.id, "type": "application"})[
"sent"
]
)
) or (holo_user.application_state()[0] == "none"):
2022-12-05 19:49:51 +02:00
left_chat = True
2023-01-04 20:59:09 +02:00
async for member in app.get_chat_members(configGet("users", "groups")):
2022-12-05 19:49:51 +02:00
if member.user.id == msg.from_user.id:
left_chat = False
2023-01-16 13:10:07 +02:00
if left_chat is True:
2023-03-09 17:25:06 +02:00
if holo_user.application_state()[
1
] is True and holo_user.application_state()[0] not in [
"fill",
"rejected",
]:
await msg.reply_text(
locale("reapply_left_chat", "message", locale=holo_user),
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
locale(
"reapply_old_one",
"button",
locale=holo_user,
),
f"reapply_old_{msg.id}",
)
],
[
InlineKeyboardButton(
locale(
"reapply_new_one",
"button",
locale=holo_user,
),
f"reapply_new_{msg.id}",
)
],
]
),
)
elif (
col_tmp.find_one({"user": holo_user.id, "type": "application"})
is None
and col_applications.find_one({"user": holo_user.id}) is not None
):
await msg.reply_text(
locale("reapply_left_chat", "message", locale=holo_user),
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
locale(
"reapply_old_one",
"button",
locale=holo_user,
),
f"reapply_old_{msg.id}",
)
],
[
InlineKeyboardButton(
locale(
"reapply_new_one",
"button",
locale=holo_user,
),
f"reapply_new_{msg.id}",
)
],
]
),
)
2023-01-09 13:39:39 +02:00
else:
holo_user.application_restart(reapply=True)
await welcome_pass(app, msg, once_again=True)
2023-01-16 13:10:07 +02:00
else:
if holo_user.sponsorship_state()[0] == "fill":
2023-03-09 17:25:06 +02:00
await msg.reply_text(
locale("finish_sponsorship", "message"), quote=should_quote(msg)
)
2023-01-16 13:10:07 +02:00
return
2023-03-09 17:25:06 +02:00
2023-01-16 13:10:07 +02:00
holo_user.application_restart(reapply=True)
await welcome_pass(app, msg, once_again=True)
2022-12-05 19:49:51 +02:00
else:
2023-03-09 17:25:06 +02:00
await msg.reply_text(
locale("reapply_in_progress", "message", locale=holo_user).format(
locale("confirm", "keyboard", locale=holo_user)[1][0]
),
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
locale("applying_stop", "button", locale=holo_user),
f"reapply_stop_{msg.id}",
)
]
]
),
)
elif holo_user.spoiler_state() is True:
await msg.reply_text(locale("spoiler_in_progress", "message", locale=holo_user))
2022-12-05 19:49:51 +02:00
else:
2023-03-09 17:25:06 +02:00
if (holo_user.application_state()[0] == "fill") and (
col_tmp.find_one({"user": holo_user.id, "type": "application"})["sent"]
is True
):
await msg.reply_text(
locale("reapply_forbidden", "message", locale=holo_user)
)
2022-12-05 19:49:51 +02:00
else:
2023-03-09 17:25:06 +02:00
await msg.reply_text(
locale("reapply_in_progress", "message", locale=holo_user).format(
locale("confirm", "keyboard", locale=holo_user)[1][0]
),
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
locale("applying_stop", "button", locale=holo_user),
f"reapply_stop_{msg.id}",
)
]
]
),
)