Fixed invite link check

This commit is contained in:
Profitroll 2022-10-23 23:40:43 +02:00
parent edadff30d4
commit ae13d5df96

90
main.py
View File

@ -139,7 +139,7 @@ async def confirm_no(app, msg):
# ============================================================================================================================== # ==============================================================================================================================
# Callbacks ==================================================================================================================== # Callbacks application ========================================================================================================
@app.on_callback_query(filters.regex("sub_yes_[\s\S]*")) # type: ignore @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):
@ -148,7 +148,7 @@ async def callback_query_accept(app, clb):
await app.send_message(configGet("admin_group"), locale("approved_by", "message").format(clb.from_user.first_name, fullclb[2]), disable_notification=True) # type: ignore await app.send_message(configGet("admin_group"), locale("approved_by", "message").format(clb.from_user.first_name, fullclb[2]), disable_notification=True) # type: ignore
logWrite(f"User {fullclb[2]} got approved by {clb.from_user.id}") logWrite(f"User {fullclb[2]} got approved by {clb.from_user.id}")
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]), locale("approved", "message"), reply_markup=InlineKeyboardMarkup( await app.send_message(int(fullclb[2]), locale("approved", "message"), reply_markup=InlineKeyboardMarkup(
[[ [[
@ -241,6 +241,57 @@ async def callback_query_refuse(app, clb):
# ============================================================================================================================== # ==============================================================================================================================
# Callbacks sus users ==========================================================================================================
@app.on_callback_query(filters.regex("sus_allow_[\s\S]*")) # type: ignore
async def callback_query_sus_allow(app, clb):
fullclb = clb.data.split("_")
await app.send_message(configGet("admin_group"), locale("sus_allowed_by", "message").format(clb.from_user.first_name, fullclb[2]), disable_notification=True) # type: ignore
logWrite(f"User {fullclb[2]} was allowed to join with another link by {clb.from_user.id}")
edited_markup = [[InlineKeyboardButton(text=str(locale("sus_allowed", "button")), callback_data="nothing")]]
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
await clb.answer(text=locale("sus_allowed", "callback").format(fullclb[2]), show_alert=True) # type: ignore
await app.restrict_chat_member(configGet("destination_group"), int(fullclb[2]), permissions=ChatPermissions(
can_send_messages=True,
can_send_media_messages=True,
can_send_other_messages=True,
can_send_polls=True
)
)
@app.on_callback_query(filters.regex("sus_refuse_[\s\S]*")) # type: ignore
async def callback_query_sus_refuse(app, clb):
fullclb = clb.data.split("_")
await app.send_message(configGet("admin_group"), locale("sus_refused_by", "message").format(clb.from_user.first_name, fullclb[2]), disable_notification=True) # type: ignore
logWrite(f"User {fullclb[2]} was refused to join with another link by {clb.from_user.id}")
edited_markup = [[InlineKeyboardButton(text=str(locale("sus_refused", "button")), callback_data="nothing")]]
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
await clb.answer(text=locale("sus_refused", "callback").format(fullclb[2]), show_alert=True) # type: ignore
await app.ban_chat_member(configGet("destination_group"), int(fullclb[2]))
jsonSave(jsonLoad(f"{configGet('data', 'locations')}{sep}user_default.json"), f"{configGet('data', 'locations')}{sep}users{sep}{fullclb[2]}.json")
configSet("stage", 10, file=fullclb[2])
configSet("refused", True, file=fullclb[2])
configSet("refused_by", clb.from_user.id, file=fullclb[2])
# ==============================================================================================================================
# Callback empty ===============================================================================================================
@app.on_callback_query(filters.regex("nothing")) # type: ignore
async def callback_query_nothing(app, clb):
await clb.answer(text=locale("nothing", "callback"))
# ==============================================================================================================================
# 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):
@ -328,25 +379,30 @@ async def any_stage(app, msg):
# Filter users on join ========================================================================================================= # Filter users on join =========================================================================================================
@app.on_chat_member_updated(filters.new_chat_members, group=configGet("destination_group")) @app.on_chat_member_updated(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 (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 (member.from_user.id in configGet("admins")) or (member.from_user.id == configGet("owner")): if member.invite_link != None:
if configGet("link", file=str(member.from_user.id)) == member.invite_link.invite_link: 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 (member.from_user.id in configGet("admins")) or (member.from_user.id == configGet("owner")):
return if configGet("link", file=str(member.from_user.id)) == member.invite_link.invite_link:
await app.send_message(configGet("admin_group"), f"User **{member.from_user.first_name}** (`{member.from_user.id}`) the chat not with his personal link", reply_markup=InlineKeyboardMarkup( 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(
[ [
InlineKeyboardButton(text="Allow usage", callback_data=f"sus_allow_{member.from_user.id}") [
InlineKeyboardButton(text=str(locale("sus_allow", "button")), callback_data=f"sus_allow_{member.from_user.id}")
],
[
InlineKeyboardButton(text=str(locale("sus_refuse", "button")), callback_data=f"sus_refuse_{member.from_user.id}")
]
] ]
] ))
)) await app.restrict_chat_member(member.chat.id, member.from_user.id, permissions=ChatPermissions(
await app.restrict_chat_member(member.chat.id, member.from_user.id, permissions=ChatPermissions( can_send_messages=False,
can_send_messages=False, can_send_media_messages=False,
can_send_media_messages=False, can_send_other_messages=False,
can_send_other_messages=False, can_send_polls=False
can_send_polls=False )
) )
)
# ============================================================================================================================== # ==============================================================================================================================