Dynamic data folder is now used
This commit is contained in:
parent
f54296290d
commit
83355785b8
80
main.py
80
main.py
@ -23,14 +23,14 @@ async def cmd_start(app, msg):
|
|||||||
if user_stage != 0:
|
if user_stage != 0:
|
||||||
return
|
return
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
jsonSave(jsonLoad(f"data{sep}user_default.json"), f"data{sep}users{sep}{msg.from_user.id}.json")
|
jsonSave(jsonLoad(f"{configGet('data', 'location')}{sep}user_default.json"), f"{configGet('data', 'location')}{sep}users{sep}{msg.from_user.id}.json")
|
||||||
user_stage = configGet("stage", file=str(msg.from_user.id))
|
user_stage = configGet("stage", file=str(msg.from_user.id))
|
||||||
configSet("telegram_id", str(msg.from_user.username), file=str(msg.from_user.id))
|
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_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_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))
|
configSet("telegram_locale", str(msg.from_user.language_code), file=str(msg.from_user.id))
|
||||||
|
|
||||||
await msg.reply_text(locale("start", "message"), reply_markup=ReplyKeyboardMarkup(locale("welcome", "keyboard"), resize_keyboard=True))
|
await msg.reply_text(locale("start", "message"), reply_markup=ReplyKeyboardMarkup(locale("welcome", "keyboard"), resize_keyboard=True)) # type: ignore
|
||||||
# ==============================================================================================================================
|
# ==============================================================================================================================
|
||||||
|
|
||||||
|
|
||||||
@ -52,13 +52,13 @@ async def welcome_pass(app, msg, once_again: bool = True):
|
|||||||
if not once_again:
|
if not once_again:
|
||||||
await msg.reply_text(locale("privacy_notice", "message"))
|
await msg.reply_text(locale("privacy_notice", "message"))
|
||||||
|
|
||||||
await msg.reply_text(locale("question1", "message"), reply_markup=ForceReply(placeholder=locale("question1", "force_reply")))
|
await msg.reply_text(locale("question1", "message"), reply_markup=ForceReply(placeholder=locale("question1", "force_reply"))) # type: ignore
|
||||||
configSet("stage", 1, file=str(msg.from_user.id))
|
configSet("stage", 1, file=str(msg.from_user.id))
|
||||||
|
|
||||||
@app.on_message(~ filters.scheduled & filters.private & (filters.regex(locale("welcome", "keyboard")[1][0])))
|
@app.on_message(~ filters.scheduled & filters.private & (filters.regex(locale("welcome", "keyboard")[1][0])))
|
||||||
async def welcome_reject(app, msg):
|
async def welcome_reject(app, msg):
|
||||||
|
|
||||||
await msg.reply_text(locale("goodbye", "message"), reply_markup=ReplyKeyboardMarkup(locale("return", "keyboard"), resize_keyboard=True))
|
await msg.reply_text(locale("goodbye", "message"), reply_markup=ReplyKeyboardMarkup(locale("return", "keyboard"), resize_keyboard=True)) # type: ignore
|
||||||
# ==============================================================================================================================
|
# ==============================================================================================================================
|
||||||
|
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ async def confirm_yes(app, msg):
|
|||||||
|
|
||||||
await msg.reply_text(locale("application_sent", "message"), reply_markup=ReplyKeyboardRemove())
|
await msg.reply_text(locale("application_sent", "message"), reply_markup=ReplyKeyboardRemove())
|
||||||
|
|
||||||
applications = jsonLoad(f"data{sep}applications.json")
|
applications = jsonLoad(f"{configGet('data', 'location')}{sep}applications.json")
|
||||||
|
|
||||||
applications[str(msg.from_user.id)] = {
|
applications[str(msg.from_user.id)] = {
|
||||||
"approved": False,
|
"approved": False,
|
||||||
@ -85,7 +85,7 @@ async def confirm_yes(app, msg):
|
|||||||
"application": configGet("application", file=str(msg.from_user.id))
|
"application": configGet("application", file=str(msg.from_user.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonSave(applications, f"data{sep}applications.json")
|
jsonSave(applications, f"{configGet('data', 'location')}{sep}applications.json")
|
||||||
|
|
||||||
application_content = []
|
application_content = []
|
||||||
i = 1
|
i = 1
|
||||||
@ -94,19 +94,19 @@ async def confirm_yes(app, msg):
|
|||||||
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('question'+str(i), 'message', 'question_titles')} {configGet('application', file=str(msg.from_user.id))[question]}")
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
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)), reply_markup=InlineKeyboardMarkup(
|
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)), reply_markup=InlineKeyboardMarkup( # type: ignore
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
InlineKeyboardButton(text=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_{msg.from_user.id}")
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
InlineKeyboardButton(text=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_{msg.from_user.id}")
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
InlineKeyboardButton(text=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_{msg.from_user.id}")
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
InlineKeyboardButton(text=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_{msg.from_user.id}")
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -121,7 +121,7 @@ async def confirm_no(app, msg):
|
|||||||
user_stage = configGet("stage", file=str(msg.from_user.id))
|
user_stage = configGet("stage", file=str(msg.from_user.id))
|
||||||
|
|
||||||
if user_stage == 10:
|
if user_stage == 10:
|
||||||
jsonSave(jsonLoad(f"data{sep}user_default.json"), f"data{sep}users{sep}{msg.from_user.id}.json")
|
jsonSave(jsonLoad(f"{configGet('data', 'location')}{sep}user_default.json"), f"{configGet('data', 'location')}{sep}users{sep}{msg.from_user.id}.json")
|
||||||
configSet("telegram_id", str(msg.from_user.username), file=str(msg.from_user.id))
|
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_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_phone", str(msg.from_user.phone_number), file=str(msg.from_user.id))
|
||||||
@ -131,68 +131,68 @@ async def confirm_no(app, msg):
|
|||||||
|
|
||||||
|
|
||||||
# Callbacks ====================================================================================================================
|
# Callbacks ====================================================================================================================
|
||||||
@app.on_callback_query(filters.regex("sub_yes_[\s\S]*"))
|
@app.on_callback_query(filters.regex("sub_yes_[\s\S]*")) # type: ignore
|
||||||
async def callback_query_accept(app, clb):
|
async def callback_query_accept(app, clb):
|
||||||
|
|
||||||
fullclb = clb.data.split("_")
|
fullclb = clb.data.split("_")
|
||||||
user_locale = clb.from_user.language_code
|
user_locale = clb.from_user.language_code
|
||||||
|
|
||||||
await app.send_message(configGet("admin_group"), f"Approved by {clb.from_user.id}")
|
await app.send_message(configGet("admin_group"), locale("approved_by", "message").format(clb.from_user.id, fullclb[2])) # type: ignore
|
||||||
|
|
||||||
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))
|
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]), "You got approved", reply_markup=InlineKeyboardMarkup(
|
await app.send_message(int(fullclb[2]), locale("approved", "message"), reply_markup=InlineKeyboardMarkup(
|
||||||
[[
|
[[
|
||||||
InlineKeyboardButton("Приєднатись", url=link.invite_link)
|
InlineKeyboardButton(str(locale("join", "button")), url=link.invite_link)
|
||||||
]]
|
]]
|
||||||
))
|
))
|
||||||
|
|
||||||
edited_markup = [[InlineKeyboardButton(text=locale("accepted", "button"), callback_data="nothing")]]
|
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.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||||
await clb.answer(text=locale("sub_accepted", "callback", locale=user_locale).format(fullclb[2]), show_alert=True)
|
await clb.answer(text=locale("sub_accepted", "callback").format(fullclb[2]), show_alert=True) # type: ignore
|
||||||
|
|
||||||
@app.on_callback_query(filters.regex("sub_no_[\s\S]*"))
|
@app.on_callback_query(filters.regex("sub_no_[\s\S]*")) # type: ignore
|
||||||
async def callback_query_refuse(app, clb):
|
async def callback_query_refuse(app, clb):
|
||||||
|
|
||||||
fullclb = clb.data.split("_")
|
fullclb = clb.data.split("_")
|
||||||
user_locale = clb.from_user.language_code
|
user_locale = clb.from_user.language_code
|
||||||
|
|
||||||
await app.send_message(configGet("admin_group"), f"Refused by {clb.from_user.id}")
|
await app.send_message(configGet("admin_group"), locale("refused_by", "message").format(clb.from_user.id, fullclb[2])) # type: ignore
|
||||||
await app.send_message(int(fullclb[2]), "You got refused")
|
await app.send_message(int(fullclb[2]), locale("refused", "message"))
|
||||||
|
|
||||||
edited_markup = [[InlineKeyboardButton(text=locale("declined", "button"), callback_data="nothing")]]
|
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.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||||
await clb.answer(text=locale("sub_refused", "callback", locale=user_locale).format(fullclb[2]), show_alert=True)
|
await clb.answer(text=locale("sub_refused", "callback").format(fullclb[2]), show_alert=True) # type: ignore
|
||||||
|
|
||||||
@app.on_callback_query(filters.regex("sub_no_aggressive_[\s\S]*"))
|
@app.on_callback_query(filters.regex("sub_no_aggressive_[\s\S]*")) # type: ignore
|
||||||
async def callback_query_refuse_aggressive(app, clb):
|
async def callback_query_refuse_aggressive(app, clb):
|
||||||
|
|
||||||
fullclb = clb.data.split("_")
|
fullclb = clb.data.split("_")
|
||||||
user_locale = clb.from_user.language_code
|
user_locale = clb.from_user.language_code
|
||||||
|
|
||||||
await app.send_message(configGet("admin_group"), f"Refused by {clb.from_user.id}")
|
await app.send_message(configGet("admin_group"), locale("refused_by_agr", "message").format(clb.from_user.id, fullclb[2])) # type: ignore
|
||||||
await app.send_message(int(fullclb[2]), "You got refused")
|
await app.send_message(int(fullclb[2]), locale("refused", "message"))
|
||||||
|
|
||||||
edited_markup = [[InlineKeyboardButton(text=locale("declined", "button"), callback_data="nothing")]]
|
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.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||||
await clb.answer(text=locale("sub_block", "callback", locale=user_locale).format(fullclb[2]), show_alert=True)
|
await clb.answer(text=locale("sub_no_aggressive", "callback").format(fullclb[2]), show_alert=True) # type: ignore
|
||||||
|
|
||||||
@app.on_callback_query(filters.regex("sub_no_russian_[\s\S]*"))
|
@app.on_callback_query(filters.regex("sub_no_russian_[\s\S]*")) # type: ignore
|
||||||
async def callback_query_refuse_russian(app, clb):
|
async def callback_query_refuse_russian(app, clb):
|
||||||
|
|
||||||
fullclb = clb.data.split("_")
|
fullclb = clb.data.split("_")
|
||||||
user_locale = clb.from_user.language_code
|
user_locale = clb.from_user.language_code
|
||||||
|
|
||||||
await app.send_message(configGet("admin_group"), f"Refused by {clb.from_user.id}")
|
await app.send_message(configGet("admin_group"), locale("refused_by_rus", "message").format(clb.from_user.id, fullclb[2])) # type: ignore
|
||||||
await app.send_message(int(fullclb[2]), "You got refused")
|
await app.send_message(int(fullclb[2]), locale("refused", "message"))
|
||||||
|
|
||||||
edited_markup = [[InlineKeyboardButton(text=locale("declined", "button"), callback_data="nothing")]]
|
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.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||||
await clb.answer(text=locale("sub_block", "callback", locale=user_locale).format(fullclb[2]), show_alert=True)
|
await clb.answer(text=locale("sub_no_russian", "callback").format(fullclb[2]), show_alert=True) # type: ignore
|
||||||
# ==============================================================================================================================
|
# ==============================================================================================================================
|
||||||
|
|
||||||
# Any other input ==============================================================================================================
|
# Any other input ==============================================================================================================
|
||||||
@ -202,24 +202,24 @@ async def any_stage(app, msg):
|
|||||||
user_stage = configGet("stage", file=str(msg.from_user.id))
|
user_stage = configGet("stage", file=str(msg.from_user.id))
|
||||||
|
|
||||||
if user_stage == 1:
|
if user_stage == 1:
|
||||||
await msg.reply_text(locale(f"question{user_stage+1}", "message"), reply_markup=ForceReply(placeholder=locale(f"question{user_stage+1}", "force_reply")))
|
await msg.reply_text(locale(f"question{user_stage+1}", "message"), reply_markup=ForceReply(placeholder=str(locale(f"question{user_stage+1}", "force_reply"))))
|
||||||
configSet(str(user_stage), str(msg.text), "application", file=str(msg.from_user.id))
|
configSet(str(user_stage), str(msg.text), "application", file=str(msg.from_user.id))
|
||||||
configSet("stage", user_stage+1, file=str(msg.from_user.id))
|
configSet("stage", user_stage+1, file=str(msg.from_user.id))
|
||||||
elif user_stage == 2:
|
elif user_stage == 2:
|
||||||
try:
|
try:
|
||||||
configSet(str(user_stage), int(msg.text), "application", file=str(msg.from_user.id))
|
configSet(str(user_stage), int(msg.text), "application", file=str(msg.from_user.id))
|
||||||
if (int(msg.text) in [-1, 0, 128, 256, 512, 1024, 2048]) or (int(msg.text) >= 100):
|
if (int(msg.text) in [-1, 0, 128, 256, 512, 1024, 2048]) or (int(msg.text) >= 100):
|
||||||
await msg.reply_text(locale("question2_joke", "message"), reply_markup=ForceReply(placeholder=locale("question2", "force_reply")))
|
await msg.reply_text(locale("question2_joke", "message"), reply_markup=ForceReply(placeholder=str(locale("question2", "force_reply"))))
|
||||||
elif int(msg.text) < configGet("age_allowed"):
|
elif int(msg.text) < configGet("age_allowed"):
|
||||||
await msg.reply_text(locale("question2_underage", "message"), reply_markup=ForceReply(placeholder=locale("question2", "force_reply")))
|
await msg.reply_text(locale("question2_underage", "message"), reply_markup=ForceReply(placeholder=str(locale("question2", "force_reply"))))
|
||||||
else:
|
else:
|
||||||
await msg.reply_text(locale(f"question{user_stage+1}", "message"), reply_markup=ForceReply(placeholder=locale(f"question{user_stage+1}", "force_reply")))
|
await msg.reply_text(locale(f"question{user_stage+1}", "message"), reply_markup=ForceReply(placeholder=str(locale(f"question{user_stage+1}", "force_reply"))))
|
||||||
configSet("stage", user_stage+1, file=str(msg.from_user.id))
|
configSet("stage", user_stage+1, file=str(msg.from_user.id))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
await msg.reply_text(locale(f"question2_invalid", "message"), reply_markup=ForceReply(placeholder=locale(f"question{user_stage}", "force_reply")))
|
await msg.reply_text(locale(f"question2_invalid", "message"), reply_markup=ForceReply(placeholder=str(locale(f"question{user_stage}", "force_reply"))))
|
||||||
else:
|
else:
|
||||||
if user_stage <= 9:
|
if user_stage <= 9:
|
||||||
await msg.reply_text(locale(f"question{user_stage+1}", "message"), reply_markup=ForceReply(placeholder=locale(f"question{user_stage+1}", "force_reply")))
|
await msg.reply_text(locale(f"question{user_stage+1}", "message"), reply_markup=ForceReply(placeholder=str(locale(f"question{user_stage+1}", "force_reply"))))
|
||||||
configSet(str(user_stage), str(msg.text), "application", file=str(msg.from_user.id))
|
configSet(str(user_stage), str(msg.text), "application", file=str(msg.from_user.id))
|
||||||
configSet("stage", user_stage+1, file=str(msg.from_user.id))
|
configSet("stage", user_stage+1, file=str(msg.from_user.id))
|
||||||
else:
|
else:
|
||||||
@ -230,7 +230,7 @@ async def any_stage(app, msg):
|
|||||||
for question in configGet("application", file=str(msg.from_user.id)):
|
for question in configGet("application", file=str(msg.from_user.id)):
|
||||||
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('question'+str(i), 'message', 'question_titles')} {configGet('application', file=str(msg.from_user.id))[question]}")
|
||||||
i += 1
|
i += 1
|
||||||
await msg.reply_text(locale("confirm", "message").format("\n".join(application_content)), reply_markup=ReplyKeyboardMarkup(locale("confirm", "keyboard"), resize_keyboard=True))
|
await msg.reply_text(locale("confirm", "message").format("\n".join(application_content)), reply_markup=ReplyKeyboardMarkup(locale("confirm", "keyboard"), resize_keyboard=True)) # type: ignore
|
||||||
configSet(str(user_stage), str(msg.text), "application", file=str(msg.from_user.id))
|
configSet(str(user_stage), str(msg.text), "application", file=str(msg.from_user.id))
|
||||||
#configSet("sent", True, file=str(msg.from_user.id))
|
#configSet("sent", True, file=str(msg.from_user.id))
|
||||||
#configSet("application_date", int(time()), file=str(msg.from_user.id))
|
#configSet("application_date", int(time()), file=str(msg.from_user.id))
|
||||||
|
Reference in New Issue
Block a user