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/callbacks/reapply.py

110 lines
5.6 KiB
Python
Raw Normal View History

2022-12-14 15:16:14 +02:00
from datetime import datetime
2022-12-05 19:49:51 +02:00
from os import sep
from time import time
from app import app
2022-12-06 11:42:45 +02:00
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ReplyKeyboardRemove
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
2022-12-05 19:49:51 +02:00
from modules.utils import configGet, configSet, jsonLoad, jsonSave, locale, logWrite
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
# Callbacks reapply ============================================================================================================
@app.on_callback_query(filters.regex("reapply_yes_[\s\S]*"))
2022-12-05 19:49:51 +02:00
async def callback_reapply_query_accept(app, clb):
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
2022-12-14 15:16:14 +02:00
await app.send_message(configGet("admin_group"), 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
2022-12-14 15:16:14 +02:00
await app.send_message(holo_user.id, locale("approved_joined", "message"))
2022-12-05 19:49:51 +02:00
2022-12-14 15:16:14 +02:00
col_applications.delete_one({"user": {"$eq": holo_user.id}})
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": {"$eq": holo_user.id}, "type": {"$eq": "application"}}, {"$set": {"state": "approved", "sent": False}})
2022-12-05 19:49:51 +02:00
edited_markup = [[InlineKeyboardButton(text=str(locale("accepted", "button")), callback_data="nothing")]]
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
2022-12-14 15:16:14 +02:00
await clb.answer(text=locale("sub_accepted", "callback").format(holo_user.id), show_alert=True)
2022-12-05 19:49:51 +02:00
need_link = True
async for member in app.get_chat_members(configGet("destination_group")):
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
if need_link:
2022-12-14 15:16:14 +02:00
link = await app.create_chat_invite_link(configGet("destination_group"), name=f"Invite for {holo_user.id}", member_limit=1) #, expire_date=datetime.now()+timedelta(days=1))
2022-12-05 19:49:51 +02:00
2022-12-14 15:16:14 +02:00
await app.send_message(holo_user.id, locale("read_rules", "message"))
2022-12-05 19:49:51 +02:00
for rule_msg in locale("rules"):
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
2022-12-14 15:16:14 +02:00
await app.send_message(holo_user.id, locale("approved", "message"), reply_markup=InlineKeyboardMarkup(
2022-12-05 19:49:51 +02:00
[[
InlineKeyboardButton(str(locale("join", "button")), url=link.invite_link)
]]
))
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:
2022-12-14 15:16:14 +02:00
await app.send_message(holo_user.id, locale("approved_joined", "message"))
2022-12-05 19:49:51 +02:00
@app.on_callback_query(filters.regex("reapply_no_[\s\S]*"))
2022-12-05 19:49:51 +02:00
async def callback_query_reapply_refuse(app, clb):
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
await app.send_message(configGet("admin_group"), locale("refused_by", "message").format(clb.from_user.first_name, fullclb[2]), disable_notification=True)
2022-12-14 15:16:14 +02:00
await app.send_message(holo_user.id, locale("refused", "message"))
2022-12-05 19:49:51 +02:00
logWrite(f"User {fullclb[2]} got their reapplication refused by {clb.from_user.id}")
2022-12-14 15:16:14 +02:00
col_tmp.update_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "application"}}, {"$set": {"state": "rejected", "sent": False}})
2022-12-05 19:49:51 +02:00
edited_markup = [[InlineKeyboardButton(text=str(locale("declined", "button")), callback_data="nothing")]]
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
await clb.answer(text=locale("sub_refused", "callback").format(fullclb[2]), show_alert=True)
2022-12-05 19:49:51 +02:00
# Use old application when user reapplies after leaving the chat
@app.on_callback_query(filters.regex("reapply_old_[\s\S]*"))
2022-12-05 19:49:51 +02:00
async def callback_query_reapply_old(app, clb):
fullclb = clb.data.split("_")
message = await app.get_messages(clb.from_user.id, int(fullclb[2]))
await confirm_yes(app, message)
await clb.message.edit(clb.message.text, reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton(locale("done", "button"), "nothing")]]))
2022-12-05 19:49:51 +02:00
# Start a new application when user reapplies after leaving the chat
@app.on_callback_query(filters.regex("reapply_new_[\s\S]*"))
2022-12-05 19:49:51 +02:00
async def callback_query_reapply_new(app, clb):
fullclb = clb.data.split("_")
await clb.answer(locale("reapply_stopped", "callback"))
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 after leaving the chat earlier")
await clb.message.edit(clb.message.text, reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton(locale("done", "button"), "nothing")]]))
2022-12-05 19:49:51 +02:00
# Abort application fill in progress and restart it
@app.on_callback_query(filters.regex("reapply_stop_[\s\S]*"))
2022-12-05 19:49:51 +02:00
async def callback_query_reapply_stop(app, clb):
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-05 19:49:51 +02:00
await clb.answer(locale("reapply_stopped", "callback"))
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")
2022-12-06 11:42:45 +02:00
await clb.message.edit(locale("reapply_restarted", "message"), reply_markup=ReplyKeyboardRemove())
2022-12-05 19:49:51 +02:00
# ==============================================================================================================================