Compare commits
4 Commits
b3ec78d54e
...
9fb095b7c6
Author | SHA1 | Date | |
---|---|---|---|
9fb095b7c6 | |||
b0a3830c4f | |||
32ec34435d | |||
57428e530a |
@ -274,6 +274,14 @@ class HoloUser():
|
|||||||
else:
|
else:
|
||||||
return tmp_application["state"], tmp_application["complete"]
|
return tmp_application["state"], tmp_application["complete"]
|
||||||
|
|
||||||
|
def application_approved(self) -> bool:
|
||||||
|
"""Check whether user has a completed application and it got approved
|
||||||
|
|
||||||
|
### Returns:
|
||||||
|
* `bool`: `True` if yes and `False` if no
|
||||||
|
"""
|
||||||
|
return True if col_applications.find_one({"user": self.id}) is not None else False
|
||||||
|
|
||||||
def application_restart(self) -> None:
|
def application_restart(self) -> None:
|
||||||
"""Reset application of a user in tmp collection and replace it with an empty one
|
"""Reset application of a user in tmp collection and replace it with an empty one
|
||||||
"""
|
"""
|
||||||
|
@ -26,14 +26,15 @@ async def cmd_application(app, msg):
|
|||||||
return
|
return
|
||||||
|
|
||||||
application = col_applications.find_one({"user": holo_user.id})
|
application = col_applications.find_one({"user": holo_user.id})
|
||||||
application_content = []
|
|
||||||
i = 1
|
|
||||||
|
|
||||||
if application is None:
|
if application is None:
|
||||||
logWrite(f"User {msg.from_user.id} requested application of {holo_user.id} but user does not exists")
|
logWrite(f"User {msg.from_user.id} requested application of {holo_user.id} but user does not exists")
|
||||||
await msg.reply_text(locale("user_invalid", "message"), quote=should_quote(msg))
|
await msg.reply_text(locale("user_invalid", "message"), quote=should_quote(msg))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
application_content = []
|
||||||
|
i = 1
|
||||||
|
|
||||||
for question in application['application']:
|
for question in application['application']:
|
||||||
|
|
||||||
if i == 2:
|
if i == 2:
|
||||||
@ -51,6 +52,7 @@ async def cmd_application(app, msg):
|
|||||||
|
|
||||||
application_status = locale("application_status_accepted", "message").format((await app.get_users(application["admin"])).first_name, application["date"].strftime("%d.%m.%Y, %H:%M"))
|
application_status = locale("application_status_accepted", "message").format((await app.get_users(application["admin"])).first_name, application["date"].strftime("%d.%m.%Y, %H:%M"))
|
||||||
|
|
||||||
|
logWrite(f"User {msg.from_user.id} requested application of {holo_user.id}")
|
||||||
await msg.reply_text(locale("contact", "message").format(holo_user.id, "\n".join(application_content), application_status), parse_mode=ParseMode.MARKDOWN, quote=should_quote(msg))
|
await msg.reply_text(locale("contact", "message").format(holo_user.id, "\n".join(application_content), application_status), parse_mode=ParseMode.MARKDOWN, quote=should_quote(msg))
|
||||||
|
|
||||||
# if (path.exists(f"{configGet('data', 'locations')}{sep}users{sep}{msg.command[1]}.json") and jsonLoad(f"{configGet('data', 'locations')}{sep}users{sep}{msg.command[1]}.json")["approved"]):
|
# if (path.exists(f"{configGet('data', 'locations')}{sep}users{sep}{msg.command[1]}.json") and jsonLoad(f"{configGet('data', 'locations')}{sep}users{sep}{msg.command[1]}.json")["approved"]):
|
||||||
|
@ -4,44 +4,51 @@ from datetime import datetime
|
|||||||
from app import app, isAnAdmin
|
from app import app, isAnAdmin
|
||||||
from pyrogram import filters
|
from pyrogram import filters
|
||||||
from modules.utils import configGet, jsonLoad, locale, logWrite
|
from modules.utils import configGet, jsonLoad, locale, logWrite
|
||||||
|
from modules.database import col_applications
|
||||||
|
from classes.holo_user import HoloUser
|
||||||
|
|
||||||
# Contact getting ==============================================================================================================
|
# Contact getting ==============================================================================================================
|
||||||
@app.on_message(~ filters.scheduled & filters.contact & filters.private)
|
@app.on_message(~ filters.scheduled & filters.contact & filters.private)
|
||||||
async def get_contact(app, msg):
|
async def get_contact(app, msg):
|
||||||
if (path.exists(f"{configGet('data', 'locations')}{sep}users{sep}{msg.from_user.id}.json") and jsonLoad(f"{configGet('data', 'locations')}{sep}users{sep}{msg.from_user.id}.json")["approved"]) or (await isAnAdmin(msg.from_user.id) is True):
|
|
||||||
|
holo_user = HoloUser(msg.from_user)
|
||||||
|
|
||||||
|
if holo_user.application_approved() or (await isAnAdmin(holo_user.id) is True):
|
||||||
|
|
||||||
if msg.contact.user_id != None:
|
if msg.contact.user_id != None:
|
||||||
try:
|
|
||||||
user_data = jsonLoad(f"{configGet('data', 'locations')}{sep}users{sep}{msg.contact.user_id}.json")
|
application = col_applications.find_one({"user": msg.contact.user_id})
|
||||||
application = jsonLoad(f"{configGet('data', 'locations')}{sep}applications.json")[str(msg.contact.user_id)]
|
|
||||||
application_content = []
|
if application is None:
|
||||||
i = 1
|
logWrite(f"User {holo_user.id} requested application of {msg.contact.user_id} but user does not exists")
|
||||||
for question in application["application"]:
|
|
||||||
if i == 2:
|
|
||||||
age = relativedelta(datetime.now(), datetime.strptime(application['application']['2'], '%d.%m.%Y'))
|
|
||||||
application_content.append(f"{locale('question'+str(i), 'message', 'question_titles')} {application['application']['2']} ({age.years} р.)")
|
|
||||||
else:
|
|
||||||
application_content.append(f"{locale('question'+str(i), 'message', 'question_titles')} {application['application'][question]}")
|
|
||||||
i += 1
|
|
||||||
if user_data["sent"]:
|
|
||||||
if user_data["approved"]:
|
|
||||||
application_status = locale("application_status_accepted", "message").format((await app.get_users(application["approved_by"])).first_name, datetime.fromtimestamp(application["approval_date"]).strftime("%d.%m.%Y, %H:%M"))
|
|
||||||
elif application["rejected"]:
|
|
||||||
application_status = locale("application_status_rejected", "message").format((await app.get_users(application["rejected_by"])).first_name, datetime.fromtimestamp(application["refusal_date"]).strftime("%d.%m.%Y, %H:%M"))
|
|
||||||
else:
|
|
||||||
application_status = locale("application_status_on_hold", "message")
|
|
||||||
else:
|
|
||||||
if user_data["approved"]:
|
|
||||||
application_status = locale("application_status_accepted", "message").format((await app.get_users(application["approved_by"])).first_name, datetime.fromtimestamp(application["approval_date"]).strftime("%d.%m.%Y, %H:%M"))
|
|
||||||
elif application["rejected"]:
|
|
||||||
application_status = locale("application_status_rejected", "message").format((await app.get_users(application["rejected_by"])).first_name, datetime.fromtimestamp(application["refusal_date"]).strftime("%d.%m.%Y, %H:%M"))
|
|
||||||
else:
|
|
||||||
application_status = locale("application_status_not_send", "message")
|
|
||||||
logWrite(f"User {msg.from_user.id} requested application of {msg.contact.user_id}")
|
|
||||||
await msg.reply_text(locale("contact", "message").format(str(msg.contact.user_id), "\n".join(application_content), application_status))
|
|
||||||
except FileNotFoundError:
|
|
||||||
logWrite(f"User {msg.from_user.id} requested application of {msg.contact.user_id} but user does not exists")
|
|
||||||
await msg.reply_text(locale("contact_invalid", "message"))
|
await msg.reply_text(locale("contact_invalid", "message"))
|
||||||
|
return
|
||||||
|
|
||||||
|
application_content = []
|
||||||
|
i = 1
|
||||||
|
|
||||||
|
for question in application['application']:
|
||||||
|
|
||||||
|
if i == 2:
|
||||||
|
age = relativedelta(datetime.now(), application['application']['2'])
|
||||||
|
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {application['application']['2'].strftime('%d.%m.%Y')} ({age.years} р.)")
|
||||||
|
elif i == 3:
|
||||||
|
if application['application']['3']['countryCode'] == "UA":
|
||||||
|
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {application['application']['3']['name']}")
|
||||||
|
else:
|
||||||
|
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {application['application']['3']['name']} ({application['application']['3']['adminName1']}, {application['application']['3']['countryName']})")
|
||||||
|
else:
|
||||||
|
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {application['application'][question]}")
|
||||||
|
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
application_status = locale("application_status_accepted", "message").format((await app.get_users(application["admin"])).first_name, application["date"].strftime("%d.%m.%Y, %H:%M"))
|
||||||
|
|
||||||
|
logWrite(f"User {holo_user.id} requested application of {msg.contact.user_id}")
|
||||||
|
await msg.reply_text(locale("contact", "message").format(str(msg.contact.user_id), "\n".join(application_content), application_status))
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logWrite(f"User {msg.from_user.id} requested application of someone but user is not telegram user")
|
logWrite(f"User {holo_user.id} requested application of someone but user is not telegram user")
|
||||||
await msg.reply_text(locale("contact_not_member", "message"))
|
await msg.reply_text(locale("contact_not_member", "message"))
|
||||||
# ==============================================================================================================================
|
# ==============================================================================================================================
|
@ -2,17 +2,24 @@ from os import sep, path
|
|||||||
from app import app, isAnAdmin
|
from app import app, isAnAdmin
|
||||||
from pyrogram.types import ChatPermissions, InlineKeyboardMarkup, InlineKeyboardButton
|
from pyrogram.types import ChatPermissions, InlineKeyboardMarkup, InlineKeyboardButton
|
||||||
from modules.utils import configGet, jsonLoad, locale
|
from modules.utils import configGet, jsonLoad, locale
|
||||||
|
from modules.database import col_users
|
||||||
|
from classes.holo_user import HoloUser
|
||||||
|
|
||||||
# Filter users on join =========================================================================================================
|
# Filter users on join =========================================================================================================
|
||||||
@app.on_chat_member_updated(group=configGet("destination_group"))
|
@app.on_chat_member_updated(group=configGet("destination_group"))
|
||||||
#@app.on_message(filters.new_chat_members, group=configGet("destination_group"))
|
#@app.on_message(filters.new_chat_members, group=configGet("destination_group"))
|
||||||
async def filter_join(app, member):
|
async def filter_join(app, member):
|
||||||
|
|
||||||
if member.invite_link != None:
|
if member.invite_link != None:
|
||||||
if (path.exists(f"{configGet('data', 'locations')}{sep}users{sep}{member.from_user.id}.json") and jsonLoad(f"{configGet('data', 'locations')}{sep}users{sep}{member.from_user.id}.json")["approved"]) or (await isAnAdmin(member.from_user.id) is True):
|
|
||||||
if configGet("link", file=str(member.from_user.id)) == member.invite_link.invite_link:
|
holo_user = HoloUser(member.from_user)
|
||||||
return
|
|
||||||
|
if (holo_user.link is not None) and (holo_user.link == member.invite_link):
|
||||||
|
return
|
||||||
|
|
||||||
if await isAnAdmin(member.invite_link.creator.id):
|
if await isAnAdmin(member.invite_link.creator.id):
|
||||||
return
|
return
|
||||||
|
|
||||||
await app.send_message(configGet("admin_group"), f"User **{member.from_user.first_name}** (`{member.from_user.id}`) joined the chat not with his personal link", reply_markup=InlineKeyboardMarkup(
|
await app.send_message(configGet("admin_group"), f"User **{member.from_user.first_name}** (`{member.from_user.id}`) joined the chat not with his personal link", reply_markup=InlineKeyboardMarkup(
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
|
Reference in New Issue
Block a user