from datetime import datetime from app import app from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery from pyrogram import filters from pyrogram.client import Client from classes.holo_user import HoloUser from modules.utils import configGet, locale, logWrite from modules.database import col_tmp, col_applications from modules.commands.rules import DefaultRulesMarkup # Callbacks application ======================================================================================================== @app.on_callback_query(filters.regex("sub_yes_[\s\S]*")) async def callback_query_accept(app: Client, clb: CallbackQuery): fullclb = clb.data.split("_") holo_user = HoloUser(int(fullclb[2])) 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 approved by {clb.from_user.id}") need_link = True async for member in app.get_chat_members(configGet("users", "groups")): if member.user.id == holo_user.id: need_link = False 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)) await app.send_message(holo_user.id, locale("rules_msg", locale=holo_user), disable_web_page_preview=True, reply_markup=DefaultRulesMarkup(holo_user).keyboard) await app.send_message(holo_user.id, locale("approved", "message", locale=holo_user), reply_markup=InlineKeyboardMarkup( [[ InlineKeyboardButton(str(locale("join", "button", locale=holo_user)), url=link.invite_link) ]] )) holo_user.set("link", link.invite_link) logWrite(f"User {holo_user.id} got an invite link {link.invite_link}") else: await app.send_message(holo_user.id, locale("approved_joined", "message", locale=holo_user)) 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}}) 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) @app.on_callback_query(filters.regex("sub_no_[\s\S]*")) async def callback_query_reject(app: Client, clb: CallbackQuery): fullclb = clb.data.split("_") holo_user = HoloUser(int(fullclb[2])) await app.send_message(configGet("admin", "groups"), locale("rejected_by", "message").format(clb.from_user.first_name, holo_user.id), disable_notification=True) await app.send_message(holo_user.id, locale("rejected", "message", locale=holo_user)) logWrite(f"User {holo_user.id} got 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")]] 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(holo_user.id), show_alert=True) @app.on_callback_query(filters.regex("sub_aggressive_[\s\S]*")) async def callback_query_reject_aggressive(app: Client, clb: CallbackQuery): fullclb = clb.data.split("_") holo_user = HoloUser(int(fullclb[2])) await app.send_message(configGet("admin", "groups"), locale("rejected_by_agr", "message").format(clb.from_user.first_name, holo_user.id), disable_notification=True) await app.send_message(holo_user.id, locale("rejected_aggressive", "message", locale=holo_user)) logWrite(f"User {holo_user.id} got rejected by {clb.from_user.id} due to being aggressive") 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")]] await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup)) await clb.answer(text=locale("sub_aggressive", "callback", locale=clb.from_user).format(holo_user.id), show_alert=True) @app.on_callback_query(filters.regex("sub_russian_[\s\S]*")) async def callback_query_reject_russian(app: Client, clb: CallbackQuery): fullclb = clb.data.split("_") holo_user = HoloUser(int(fullclb[2])) await app.send_message(configGet("admin", "groups"), locale("rejected_by_rus", "message").format(clb.from_user.first_name, holo_user.id), disable_notification=True) await app.send_message(holo_user.id, locale("rejected_russian", "message", locale=holo_user)) logWrite(f"User {holo_user.id} got rejected by {clb.from_user.id} due to being russian") 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")]] await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup)) await clb.answer(text=locale("sub_russian", "callback", locale=clb.from_user).format(holo_user.id), show_alert=True) # ==============================================================================================================================