2022-12-05 19:49:51 +02:00
from os import sep
from time import time
from app import app
from pyrogram . types import InlineKeyboardMarkup , InlineKeyboardButton
2022-12-05 19:53:09 +02:00
from pyrogram import filters
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
# Callbacks reapply ============================================================================================================
2022-12-06 11:26:22 +02:00
@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-06 11:26:22 +02:00
await app . send_message ( configGet ( " admin_group " ) , locale ( " approved_by " , " message " ) . format ( clb . from_user . first_name , fullclb [ 2 ] ) , disable_notification = True )
2022-12-05 19:49:51 +02:00
logWrite ( f " User { fullclb [ 2 ] } got their reapplication approved by { clb . from_user . id } " )
await app . send_message ( int ( fullclb [ 2 ] ) , locale ( " approved_joined " , " message " ) )
configSet ( [ " approved " ] , True , file = fullclb [ 2 ] )
configSet ( [ " sent " ] , False , file = fullclb [ 2 ] )
application = jsonLoad ( f " { configGet ( ' data ' , ' locations ' ) } { sep } applications.json " )
application [ fullclb [ 2 ] ] [ " approved " ] = True
application [ fullclb [ 2 ] ] [ " approved_by " ] = clb . from_user . id
application [ fullclb [ 2 ] ] [ " approval_date " ] = int ( time ( ) )
jsonSave ( application , f " { configGet ( ' data ' , ' locations ' ) } { sep } applications.json " )
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-06 11:26:22 +02:00
await clb . answer ( text = locale ( " sub_accepted " , " callback " ) . format ( fullclb [ 2 ] ) , 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 " ) ) :
if member . user . id == int ( fullclb [ 2 ] ) :
need_link = False
if need_link :
link = await app . create_chat_invite_link ( configGet ( " destination_group " ) , name = f " Invite for { fullclb [ 2 ] } " , member_limit = 1 ) #, expire_date=datetime.now()+timedelta(days=1))
await app . send_message ( int ( fullclb [ 2 ] ) , locale ( " read_rules " , " message " ) )
for rule_msg in locale ( " rules " ) :
await app . send_message ( int ( fullclb [ 2 ] ) , rule_msg )
await app . send_message ( int ( fullclb [ 2 ] ) , locale ( " approved " , " message " ) , reply_markup = InlineKeyboardMarkup (
[ [
InlineKeyboardButton ( str ( locale ( " join " , " button " ) ) , url = link . invite_link )
] ]
) )
configSet ( [ " link " ] , link . invite_link , file = fullclb [ 2 ] )
logWrite ( f " User { fullclb [ 2 ] } got an invite link { link . invite_link } " )
else :
await app . send_message ( int ( fullclb [ 2 ] ) , locale ( " approved_joined " , " message " ) )
2022-12-06 11:26:22 +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-06 11:26:22 +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-05 19:49:51 +02:00
await app . send_message ( int ( fullclb [ 2 ] ) , locale ( " refused " , " message " ) )
logWrite ( f " User { fullclb [ 2 ] } got their reapplication refused by { clb . from_user . id } " )
configSet ( [ " refused " ] , True , file = fullclb [ 2 ] )
configSet ( [ " sent " ] , False , file = fullclb [ 2 ] )
application = jsonLoad ( f " { configGet ( ' data ' , ' locations ' ) } { sep } applications.json " )
application [ fullclb [ 2 ] ] [ " refused " ] = True
application [ fullclb [ 2 ] ] [ " refused_by " ] = clb . from_user . id
application [ fullclb [ 2 ] ] [ " refusal_date " ] = int ( time ( ) )
jsonSave ( application , f " { configGet ( ' data ' , ' locations ' ) } { sep } applications.json " )
edited_markup = [ [ InlineKeyboardButton ( text = str ( locale ( " declined " , " button " ) ) , callback_data = " nothing " ) ] ]
await clb . message . edit ( text = clb . message . text , reply_markup = InlineKeyboardMarkup ( edited_markup ) )
2022-12-06 11:26:22 +02:00
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
2022-12-06 11:26:22 +02:00
@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 ] ) )
configSet ( [ " approved " ] , False , file = str ( clb . from_user . id ) )
configSet ( [ " refused " ] , False , file = str ( clb . from_user . id ) )
await confirm_yes ( app , message )
2022-12-06 11:26:22 +02:00
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
2022-12-06 11:26:22 +02:00
@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 ( " _ " )
jsonSave ( jsonLoad ( f " { configGet ( ' data ' , ' locations ' ) } { sep } user_default.json " ) , f " { configGet ( ' data ' , ' locations ' ) } { sep } users { sep } { clb . from_user . id } .json " )
configSet ( [ " telegram_id " ] , str ( clb . from_user . username ) , file = str ( clb . from_user . id ) )
configSet ( [ " telegram_name " ] , f " { clb . from_user . first_name } { clb . from_user . last_name } " , file = str ( clb . from_user . id ) )
configSet ( [ " telegram_phone " ] , str ( clb . from_user . phone_number ) , file = str ( clb . from_user . id ) )
configSet ( [ " telegram_locale " ] , str ( clb . from_user . language_code ) , file = str ( clb . from_user . id ) )
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 " )
2022-12-06 11:26:22 +02:00
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
2022-12-06 11:26:22 +02:00
@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 ( " _ " )
jsonSave ( jsonLoad ( f " { configGet ( ' data ' , ' locations ' ) } { sep } user_default.json " ) , f " { configGet ( ' data ' , ' locations ' ) } { sep } users { sep } { clb . from_user . id } .json " )
configSet ( [ " telegram_id " ] , str ( clb . from_user . username ) , file = str ( clb . from_user . id ) )
configSet ( [ " telegram_name " ] , f " { clb . from_user . first_name } { clb . from_user . last_name } " , file = str ( clb . from_user . id ) )
configSet ( [ " telegram_phone " ] , str ( clb . from_user . phone_number ) , file = str ( clb . from_user . id ) )
configSet ( [ " telegram_locale " ] , str ( clb . from_user . language_code ) , file = str ( clb . from_user . id ) )
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 " )
await clb . message . edit ( clb . message . text , reply_markup = None )
# ==============================================================================================================================