This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Telegram/modules/handlers/group_join.py

156 lines
6.3 KiB
Python
Raw Normal View History

2023-01-23 12:57:32 +02:00
from datetime import datetime
2022-12-05 19:49:51 +02:00
from app import app, isAnAdmin
2023-03-09 17:25:06 +02:00
from pyrogram.types import (
ChatPermissions,
InlineKeyboardMarkup,
InlineKeyboardButton,
ChatMemberUpdated,
)
2022-12-27 14:36:54 +02:00
from pyrogram.client import Client
2022-12-16 12:29:10 +02:00
from modules.utils import configGet, locale
2023-01-23 12:57:32 +02:00
from modules import custom_filters
2022-12-16 13:04:57 +02:00
from modules.logging import logWrite
2023-01-23 12:57:32 +02:00
from modules.database import col_applications
2022-12-16 12:15:56 +02:00
from classes.holo_user import HoloUser
2023-01-23 12:57:32 +02:00
from dateutil.relativedelta import relativedelta
2022-12-05 19:49:51 +02:00
2023-03-09 17:25:06 +02:00
2022-12-05 19:49:51 +02:00
# Filter users on join =========================================================================================================
2023-03-09 17:25:06 +02:00
@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"))
2022-12-27 14:36:54 +02:00
async def filter_join(app: Client, member: ChatMemberUpdated):
2022-12-05 19:49:51 +02:00
if member.invite_link != None:
2022-12-16 12:15:56 +02:00
holo_user = HoloUser(member.from_user)
2023-03-09 17:25:06 +02:00
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}"
)
2023-01-23 12:57:32 +02:00
application = col_applications.find_one({"user": holo_user.id})
application_content = []
i = 1
2023-03-09 17:25:06 +02:00
for question in application["application"]:
2023-01-23 12:57:32 +02:00
if i == 2:
2023-03-09 17:25:06 +02:00
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} р.)"
)
2023-01-23 12:57:32 +02:00
elif i == 3:
2023-03-09 17:25:06 +02:00
if application["application"]["3"]["countryCode"] == "UA":
application_content.append(
f"{locale(f'question{i}', 'message', 'question_titles')} {application['application']['3']['name']}"
)
2023-01-23 12:57:32 +02:00
else:
2023-03-09 17:25:06 +02:00
application_content.append(
f"{locale(f'question{i}', 'message', 'question_titles')} {application['application']['3']['name']} ({application['application']['3']['adminName1']}, {application['application']['3']['countryName']})"
)
2023-01-23 12:57:32 +02:00
else:
2023-03-09 17:25:06 +02:00
application_content.append(
f"{locale(f'question{i}', 'message', 'question_titles')} {application['application'][question]}"
)
2023-01-23 12:57:32 +02:00
i += 1
2023-01-23 13:01:35 +02:00
2023-03-09 17:25:06 +02:00
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),
),
)
2023-01-23 13:01:35 +02:00
2022-12-16 12:15:56 +02:00
return
2023-03-09 17:25:06 +02:00
2022-12-05 19:49:51 +02:00
if await isAnAdmin(member.invite_link.creator.id):
2023-03-09 17:25:06 +02:00
logWrite(
f"User {holo_user.id} joined destination group with link {holo_user.link} of an admin {member.invite_link.creator.id}"
)
2023-01-23 13:01:35 +02:00
application = col_applications.find_one({"user": holo_user.id})
2023-01-23 13:01:58 +02:00
2023-01-23 13:01:35 +02:00
if application is None:
return
application_content = []
i = 1
2023-03-09 17:25:06 +02:00
for question in application["application"]:
2023-01-23 13:01:35 +02:00
if i == 2:
2023-03-09 17:25:06 +02:00
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} р.)"
)
2023-01-23 13:01:35 +02:00
elif i == 3:
2023-03-09 17:25:06 +02:00
if application["application"]["3"]["countryCode"] == "UA":
application_content.append(
f"{locale(f'question{i}', 'message', 'question_titles')} {application['application']['3']['name']}"
)
2023-01-23 13:01:35 +02:00
else:
2023-03-09 17:25:06 +02:00
application_content.append(
f"{locale(f'question{i}', 'message', 'question_titles')} {application['application']['3']['name']} ({application['application']['3']['adminName1']}, {application['application']['3']['countryName']})"
)
2023-01-23 13:01:35 +02:00
else:
2023-03-09 17:25:06 +02:00
application_content.append(
f"{locale(f'question{i}', 'message', 'question_titles')} {application['application'][question]}"
)
2023-01-23 13:01:35 +02:00
i += 1
2023-03-09 17:25:06 +02:00
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),
),
)
2023-01-23 13:01:35 +02:00
2022-12-05 19:49:51 +02:00
return
2022-12-16 13:04:57 +02:00
2023-03-09 17:25:06 +02:00
logWrite(
f"User {holo_user.id} joined destination group with stolen/unapproved link {holo_user.link}"
)
2022-12-16 13:04:57 +02:00
2023-03-09 17:25:06 +02:00
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(
2022-12-05 19:49:51 +02:00
[
2023-03-09 17:25:06 +02:00
[
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}",
)
],
2022-12-05 19:49:51 +02:00
]
2023-03-09 17:25:06 +02:00
),
)
await app.restrict_chat_member(
member.chat.id,
member.from_user.id,
permissions=ChatPermissions(
2022-12-05 19:49:51 +02:00
can_send_messages=False,
can_send_media_messages=False,
can_send_other_messages=False,
2023-03-09 17:25:06 +02:00
can_send_polls=False,
),
2022-12-05 19:49:51 +02:00
)
2023-03-09 17:25:06 +02:00
# ==============================================================================================================================