98 lines
5.3 KiB
Python
98 lines
5.3 KiB
Python
from datetime import datetime
|
||
from app import app, isAnAdmin
|
||
from pyrogram.types import ChatPermissions, InlineKeyboardMarkup, InlineKeyboardButton, ChatMemberUpdated
|
||
from pyrogram.client import Client
|
||
from modules.utils import configGet, locale
|
||
from modules import custom_filters
|
||
from modules.logging import logWrite
|
||
from modules.database import col_applications
|
||
from classes.holo_user import HoloUser
|
||
from dateutil.relativedelta import relativedelta
|
||
|
||
# Filter users on join =========================================================================================================
|
||
@app.on_chat_member_updated(custom_filters.enabled_invites_check, group=configGet("users", "groups"))
|
||
#@app.on_message(filters.new_chat_members, group=configGet("users", "groups"))
|
||
async def filter_join(app: Client, member: ChatMemberUpdated):
|
||
|
||
if member.invite_link != None:
|
||
|
||
holo_user = HoloUser(member.from_user)
|
||
|
||
if (holo_user.link is not None) and (holo_user.link == member.invite_link.invite_link):
|
||
|
||
logWrite(f"User {holo_user.id} joined destination group with correct link {holo_user.link}")
|
||
|
||
application = col_applications.find_one({"user": holo_user.id})
|
||
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
|
||
|
||
await app.send_message(configGet("users", "groups"), locale("joined_application", "message").format(member.from_user.first_name, member.from_user.username, "\n".join(application_content)))
|
||
|
||
return
|
||
|
||
if await isAnAdmin(member.invite_link.creator.id):
|
||
|
||
logWrite(f"User {holo_user.id} joined destination group with link {holo_user.link} of an admin {member.invite_link.creator.id}")
|
||
|
||
application = col_applications.find_one({"user": holo_user.id})
|
||
|
||
if application is None:
|
||
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
|
||
|
||
await app.send_message(configGet("users", "groups"), locale("joined_application", "message").format(member.from_user.first_name, member.from_user.username, "\n".join(application_content)))
|
||
|
||
return
|
||
|
||
logWrite(f"User {holo_user.id} joined destination group with stolen/unapproved link {holo_user.link}")
|
||
|
||
await app.send_message(configGet("admin", "groups"), locale("joined_false_link", "message").format(member.from_user.first_name, member.from_user.id), reply_markup=InlineKeyboardMarkup(
|
||
[
|
||
[
|
||
InlineKeyboardButton(text=str(locale("sus_allow", "button")), callback_data=f"sus_allow_{member.from_user.id}")
|
||
],
|
||
[
|
||
InlineKeyboardButton(text=str(locale("sus_reject", "button")), callback_data=f"sus_reject_{member.from_user.id}")
|
||
]
|
||
]
|
||
))
|
||
await app.restrict_chat_member(member.chat.id, member.from_user.id, permissions=ChatPermissions(
|
||
can_send_messages=False,
|
||
can_send_media_messages=False,
|
||
can_send_other_messages=False,
|
||
can_send_polls=False
|
||
)
|
||
)
|
||
# ============================================================================================================================== |