@ -1,99 +1,93 @@
from os import sep
from time import time
from dateutil . relativedelta import relativedelta
from datetime import datetime
from app import app
from pyrogram import filters
from pyrogram . types import ReplyKeyboardRemove , InlineKeyboardMarkup , InlineKeyboardButton
from pyrogram . enums . parse_mode import ParseMode
from modules . utils import configGet , configSet , jsonLoad , jsonSave , locale , logWrite
from classes . holo_user import HoloUser
from modules . utils import configGet , locale , logWrite
from modules . handlers . welcome import welcome_pass
from modules . database import col_tmp
# Confirmation =================================================================================================================
@app.on_message ( ~ filters . scheduled & filters . private & ( filters . regex ( locale ( " confirm " , " keyboard " ) [ 0 ] [ 0 ] ) ) )
async def confirm_yes ( app , msg ) :
user_stage = configGet ( " stage " , file = str ( msg . from_user . id ) )
holo_user = HoloUser ( msg . from_user )
if user_stage == 10 :
if not configGet ( " sent " , file = str ( msg . from_user . id ) ) :
if ( holo_user . application_state ( ) [ 0 ] == " fill " ) and ( holo_user . application_state ( ) [ 1 ] is True ) :
await msg . reply_text ( locale ( " application_sent " , " message " ) , reply_markup = ReplyKeyboardRemove ( ) )
applications = jsonLoad ( f " { configGet ( ' data ' , ' locations ' ) } { sep } applications.json " )
tmp_application = col_tmp . find_one ( { " user " : holo_user . id , " type " : " application " } )
applications [ str ( msg . from_user . id ) ] = {
" approved " : False ,
" approved_by " : None ,
" approval_date " : None ,
" refused " : False ,
" refused_by " : False ,
" refusal_date " : False ,
" application_date " : int ( time ( ) ) ,
" application " : configGet ( " application " , file = str ( msg . from_user . id ) )
}
jsonSave ( applications , f " { configGet ( ' data ' , ' locations ' ) } { sep } applications.json " )
if tmp_application is None :
logWrite ( f " Application of { holo_user . id } is nowhere to be found. " )
return
application_content = [ ]
i = 1
for question in configGet ( " application " , file = str ( msg . from_user . id ) ) :
for question in tmp_application [ ' application ' ] :
if i == 2 :
age = relativedelta ( datetime . now ( ) , datetime . strptime ( configGet ( ' application ' , file = str ( msg . from_user . id ) ) [ ' 2 ' ] , ' %d . % m. % Y ' ) )
application_content . append ( f " { locale ( ' question ' + str ( i ) , ' message ' , ' question_titles ' ) } { configGet ( ' application ' , file = str ( msg . from_user . id ) ) [ ' 2 ' ] } ( { age . years } р .) " )
age = relativedelta ( datetime . now ( ) , tmp_application [ ' application ' ] [ ' 2 ' ] )
application_content . append ( f " { locale ( f ' question { i } ' , ' message ' , ' question_titles ' ) } { tmp_application [ ' application ' ] [ ' 2 ' ] . strftime ( ' %d . % m. % Y ' ) } ( { age . years } р .) " )
elif i == 3 :
if tmp_application [ ' application ' ] [ ' 3 ' ] [ ' countryCode ' ] == " UA " :
application_content . append ( f " { locale ( f ' question { i } ' , ' message ' , ' question_titles ' ) } { tmp_application [ ' application ' ] [ ' 3 ' ] [ ' name ' ] } " )
else :
application_content . append ( f " { locale ( ' question ' + str ( i ) , ' message ' , ' question_titles ' ) } { configGet ( ' application ' , file = str ( msg . from_user . id ) ) [ question ] } " )
application_content . append ( f " { locale ( f ' question { i } ' , ' message ' , ' question_titles ' ) } { tmp_application [ ' application ' ] [ ' 3 ' ] [ ' name ' ] } ( { tmp_application [ ' application ' ] [ ' 3 ' ] [ ' adminName1 ' ] } , { tmp_application [ ' application ' ] [ ' 3 ' ] [ ' countryName ' ] } ) " )
else :
application_content . append ( f " { locale ( f ' question { i } ' , ' message ' , ' question_titles ' ) } { tmp_application [ ' application ' ] [ question ] } " )
i + = 1
if configGet ( " reapply " , file = str ( msg . from_user . id ) ) :
await app . send_message ( chat_id = configGet ( " admin_group " ) , text = ( locale ( " reapply_got " , " message " ) ) . format ( str ( msg. from _user. id ) , msg . from_user . first_name , msg . from_user . last_name , msg . from_user . username , " \n " . join ( application_content ) ) , parse_mode = ParseMode . MARKDOWN , reply_markup = InlineKeyboardMarkup (
if tmp_application [ " reapply " ] :
await app . send_message ( chat_id = configGet ( " admin_group " ) , text = ( locale ( " reapply_got " , " message " ) ) . format ( str ( holo _user. id ) , msg . from_user . first_name , msg . from_user . last_name , msg . from_user . username , " \n " . join ( application_content ) ) , parse_mode = ParseMode . MARKDOWN , reply_markup = InlineKeyboardMarkup (
[
[
InlineKeyboardButton ( text = str ( locale ( " reapply_yes " , " button " ) ) , callback_data = f " reapply_yes_ { msg. from _user. id } " )
InlineKeyboardButton ( text = str ( locale ( " reapply_yes " , " button " ) ) , callback_data = f " reapply_yes_ { holo _user. id } " )
] ,
[
InlineKeyboardButton ( text = str ( locale ( " reapply_no " , " button " ) ) , callback_data = f " reapply_no_ { msg. from _user. id } " )
InlineKeyboardButton ( text = str ( locale ( " reapply_no " , " button " ) ) , callback_data = f " reapply_no_ { holo _user. id } " )
]
]
)
)
else :
await app . send_message ( chat_id = configGet ( " admin_group " ) , text = ( locale ( " application_got " , " message " ) ) . format ( str ( msg. from _user. id ) , msg . from_user . first_name , msg . from_user . last_name , msg . from_user . username , " \n " . join ( application_content ) ) , parse_mode = ParseMode . MARKDOWN , reply_markup = InlineKeyboardMarkup (
await app . send_message ( chat_id = configGet ( " admin_group " ) , text = ( locale ( " application_got " , " message " ) ) . format ( str ( holo _user. id ) , msg . from_user . first_name , msg . from_user . last_name , msg . from_user . username , " \n " . join ( application_content ) ) , parse_mode = ParseMode . MARKDOWN , reply_markup = InlineKeyboardMarkup (
[
[
InlineKeyboardButton ( text = str ( locale ( " sub_yes " , " button " ) ) , callback_data = f " sub_yes_ { msg. from _user. id } " )
InlineKeyboardButton ( text = str ( locale ( " sub_yes " , " button " ) ) , callback_data = f " sub_yes_ { holo _user. id } " )
] ,
[
InlineKeyboardButton ( text = str ( locale ( " sub_no " , " button " ) ) , callback_data = f " sub_no_ { msg. from _user. id } " )
InlineKeyboardButton ( text = str ( locale ( " sub_no " , " button " ) ) , callback_data = f " sub_no_ { holo _user. id } " )
] ,
[
InlineKeyboardButton ( text = str ( locale ( " sub_no_aggressive " , " button " ) ) , callback_data = f " sub_no_aggresive_ { msg. from _user. id } " )
InlineKeyboardButton ( text = str ( locale ( " sub_no_aggressive " , " button " ) ) , callback_data = f " sub_no_aggresive_ { holo _user. id } " )
] ,
[
InlineKeyboardButton ( text = str ( locale ( " sub_no_russian " , " button " ) ) , callback_data = f " sub_no_russian_ { msg. from _user. id } " )
InlineKeyboardButton ( text = str ( locale ( " sub_no_russian " , " button " ) ) , callback_data = f " sub_no_russian_ { holo _user. id } " )
]
]
)
)
logWrite ( f " User { msg. from _user. id } sent his application and it will now be reviewed " )
logWrite ( f " User { holo _user. id } sent his application and it will now be reviewed " )
configSet ( [ " sent " ] , True , file = str ( msg . from_user . id ) )
configSet ( [ " confirmed " ] , True , file = str ( msg . from_user . id ) )
col_tmp . update_one ( { " user " : holo_user . id , " type " : " application " } , { " $set " : { " sent " : True } } )
# configSet(["sent"], True, file=str(holo_user.id))
# configSet(["confirmed"], True, file=str(holo_user.id))
@app.on_message ( ~ filters . scheduled & filters . private & ( filters . regex ( locale ( " confirm " , " keyboard " ) [ 1 ] [ 0 ] ) ) )
async def confirm_no ( app , msg ) :
user_stage = configGet ( " stage " , file = str ( msg . from_user . id ) )
holo_user = HoloUser ( msg . from_user )
if user_stage == 10 :
jsonSave ( jsonLoad ( f " { configGet ( ' data ' , ' locations ' ) } { sep } user_default.json " ) , f " { configGet ( ' data ' , ' locations ' ) } { sep } users { sep } { msg . from_user . id } .json " )
configSet ( [ " telegram_id " ] , str ( msg . from_user . username ) , file = str ( msg . from_user . id ) )
configSet ( [ " telegram_name " ] , f " { msg . from_user . first_name } { msg . from_user . last_name } " , file = str ( msg . from_user . id ) )
configSet ( [ " telegram_phone " ] , str ( msg . from_user . phone_number ) , file = str ( msg . from_user . id ) )
configSet ( [ " telegram_locale " ] , str ( msg . from_user . language_code ) , file = str ( msg . from_user . id ) )
if ( holo_user . application_state ( ) [ 0 ] == " fill " ) and ( holo_user . application_state ( ) [ 1 ] is True ) :
holo_user . application_restart ( )
await welcome_pass ( app , msg , once_again = True )
logWrite ( f " User { msg . from_user . id } restarted the application due to typo in it " )
# ==============================================================================================================================