Changed code style to black

This commit is contained in:
2023-03-09 16:25:06 +01:00
parent 5b8951fe07
commit 3304339244
44 changed files with 3243 additions and 936 deletions

View File

@@ -3,7 +3,13 @@ from dateutil.relativedelta import relativedelta
from datetime import datetime
from app import app
from pyrogram import filters
from pyrogram.types import ReplyKeyboardRemove, InlineKeyboardMarkup, InlineKeyboardButton, ForceReply, Message
from pyrogram.types import (
ReplyKeyboardRemove,
InlineKeyboardMarkup,
InlineKeyboardButton,
ForceReply,
Message,
)
from pyrogram.client import Client
from pyrogram.enums.parse_mode import ParseMode
from classes.holo_user import HoloUser
@@ -16,16 +22,30 @@ from modules import custom_filters
confirmation_1 = []
for pattern in all_locales("confirm", "keyboard"):
confirmation_1.append(pattern[0][0])
@app.on_message((custom_filters.enabled_applications | custom_filters.enabled_sponsorships) & ~filters.scheduled & filters.private & filters.command(confirmation_1, prefixes=[""]) & ~custom_filters.banned)
async def confirm_yes(app: Client, msg: Message, kind: Literal["application", "sponsorship", "unknown"] = "unknown"):
@app.on_message(
(custom_filters.enabled_applications | custom_filters.enabled_sponsorships)
& ~filters.scheduled
& filters.private
& filters.command(confirmation_1, prefixes=[""])
& ~custom_filters.banned
)
async def confirm_yes(
app: Client,
msg: Message,
kind: Literal["application", "sponsorship", "unknown"] = "unknown",
):
holo_user = HoloUser(msg.from_user)
if configGet("enabled", "features", "applications") is True:
if (kind == "application") or ((holo_user.application_state()[0] == "fill") and (holo_user.application_state()[1] is True)):
tmp_application = col_tmp.find_one({"user": holo_user.id, "type": "application"})
if (kind == "application") or (
(holo_user.application_state()[0] == "fill")
and (holo_user.application_state()[1] is True)
):
tmp_application = col_tmp.find_one(
{"user": holo_user.id, "type": "application"}
)
if tmp_application is None:
logWrite(f"Application of {holo_user.id} is nowhere to be found.")
@@ -34,73 +54,120 @@ async def confirm_yes(app: Client, msg: Message, kind: Literal["application", "s
if tmp_application["sent"] is True:
return
await msg.reply_text(locale("application_sent", "message"), reply_markup=ReplyKeyboardRemove())
await msg.reply_text(
locale("application_sent", "message"),
reply_markup=ReplyKeyboardRemove(),
)
application_content = []
i = 1
for question in tmp_application['application']:
for question in tmp_application["application"]:
if i == 2:
age = relativedelta(datetime.now(), tmp_application['application']['2'])
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {tmp_application['application']['2'].strftime('%d.%m.%Y')} ({age.years} р.)")
age = relativedelta(
datetime.now(), tmp_application["application"]["2"]
)
application_content.append(
f"{locale(f'question{i}', 'message', 'question_titles')} {tmp_application['application']['2'].strftime('%d.%m.%Y')} ({age.years} р.)"
)
elif i == 3:
if tmp_application['application']['3']['countryCode'] == "UA":
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {tmp_application['application']['3']['name']}")
if tmp_application["application"]["3"]["countryCode"] == "UA":
application_content.append(
f"{locale(f'question{i}', 'message', 'question_titles')} {tmp_application['application']['3']['name']}"
)
else:
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {tmp_application['application']['3']['name']} ({tmp_application['application']['3']['adminName1']}, {tmp_application['application']['3']['countryName']})")
application_content.append(
f"{locale(f'question{i}', 'message', 'question_titles')} {tmp_application['application']['3']['name']} ({tmp_application['application']['3']['adminName1']}, {tmp_application['application']['3']['countryName']})"
)
else:
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {tmp_application['application'][question]}")
application_content.append(
f"{locale(f'question{i}', 'message', 'question_titles')} {tmp_application['application'][question]}"
)
i += 1
if tmp_application["reapply"] is True and col_applications.find_one({"user": holo_user.id}) is not None:
if (
tmp_application["reapply"] is True
and col_applications.find_one({"user": holo_user.id}) is not None
):
await app.send_message(
chat_id=configGet("admin", "groups"),
text=(locale("reapply_got", "message")).format(str(holo_user.id),msg.from_user.first_name, msg.from_user.username, "\n".join(application_content)),
text=(locale("reapply_got", "message")).format(
str(holo_user.id),
msg.from_user.first_name,
msg.from_user.username,
"\n".join(application_content),
),
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(text=str(locale("reapply_yes", "button")), callback_data=f"reapply_yes_{holo_user.id}")
InlineKeyboardButton(
text=str(locale("reapply_yes", "button")),
callback_data=f"reapply_yes_{holo_user.id}",
)
],
[
InlineKeyboardButton(text=str(locale("reapply_no", "button")), callback_data=f"reapply_no_{holo_user.id}")
]
InlineKeyboardButton(
text=str(locale("reapply_no", "button")),
callback_data=f"reapply_no_{holo_user.id}",
)
],
]
)
),
)
else:
await app.send_message(
chat_id=configGet("admin", "groups"),
text=(locale("application_got", "message")).format(str(holo_user.id), msg.from_user.first_name, msg.from_user.username, "\n".join(application_content)),
text=(locale("application_got", "message")).format(
str(holo_user.id),
msg.from_user.first_name,
msg.from_user.username,
"\n".join(application_content),
),
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(text=str(locale("sub_yes", "button")), callback_data=f"sub_yes_{holo_user.id}")
InlineKeyboardButton(
text=str(locale("sub_yes", "button")),
callback_data=f"sub_yes_{holo_user.id}",
)
],
[
InlineKeyboardButton(text=str(locale("sub_no", "button")), callback_data=f"sub_no_{holo_user.id}")
InlineKeyboardButton(
text=str(locale("sub_no", "button")),
callback_data=f"sub_no_{holo_user.id}",
)
],
[
InlineKeyboardButton(text=str(locale("sub_russian", "button")), callback_data=f"sub_russian_{holo_user.id}")
]
InlineKeyboardButton(
text=str(locale("sub_russian", "button")),
callback_data=f"sub_russian_{holo_user.id}",
)
],
]
)
),
)
logWrite(f"User {holo_user.id} sent his application and it will now be reviewed")
logWrite(
f"User {holo_user.id} sent his application and it will now be reviewed"
)
col_tmp.update_one({"user": holo_user.id, "type": "application"}, {"$set": {"sent": True}})
col_tmp.update_one(
{"user": holo_user.id, "type": "application"}, {"$set": {"sent": True}}
)
return
if configGet("enabled", "features", "sponsorships") is True:
if (kind == "sponsorship") or ((holo_user.sponsorship_state()[0] == "fill") and (holo_user.sponsorship_state()[1] is True)):
tmp_sponsorship = col_tmp.find_one({"user": holo_user.id, "type": "sponsorship"})
if (kind == "sponsorship") or (
(holo_user.sponsorship_state()[0] == "fill")
and (holo_user.sponsorship_state()[1] is True)
):
tmp_sponsorship = col_tmp.find_one(
{"user": holo_user.id, "type": "sponsorship"}
)
if tmp_sponsorship is None:
logWrite(f"Sponsorship of {holo_user.id} is nowhere to be found.")
@@ -109,58 +176,116 @@ async def confirm_yes(app: Client, msg: Message, kind: Literal["application", "s
if tmp_sponsorship["sent"] is True:
return
await msg.reply_text(locale("sponsorship_sent", "message"), reply_markup=ReplyKeyboardRemove())
await msg.reply_text(
locale("sponsorship_sent", "message"),
reply_markup=ReplyKeyboardRemove(),
)
sponsorship_content = []
for question in tmp_sponsorship['sponsorship']:
for question in tmp_sponsorship["sponsorship"]:
if question == "expires":
sponsorship_content.append(f"{locale(f'question_{question}', 'message', 'sponsor_titles')} {tmp_sponsorship['sponsorship'][question].strftime('%d.%m.%Y')}")
sponsorship_content.append(
f"{locale(f'question_{question}', 'message', 'sponsor_titles')} {tmp_sponsorship['sponsorship'][question].strftime('%d.%m.%Y')}"
)
elif question == "proof":
continue
else:
sponsorship_content.append(f"{locale(f'question_{question}', 'message', 'sponsor_titles')} {tmp_sponsorship['sponsorship'][question]}")
await app.send_cached_media(configGet("admin", "groups"), tmp_sponsorship["sponsorship"]["proof"], caption=(locale("sponsor_got", "message")).format(str(holo_user.id), msg.from_user.first_name, msg.from_user.username, "\n".join(sponsorship_content)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(
sponsorship_content.append(
f"{locale(f'question_{question}', 'message', 'sponsor_titles')} {tmp_sponsorship['sponsorship'][question]}"
)
await app.send_cached_media(
configGet("admin", "groups"),
tmp_sponsorship["sponsorship"]["proof"],
caption=(locale("sponsor_got", "message")).format(
str(holo_user.id),
msg.from_user.first_name,
msg.from_user.username,
"\n".join(sponsorship_content),
),
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(text=str(locale("sponsor_yes", "button")), callback_data=f"sponsor_yes_{holo_user.id}")
InlineKeyboardButton(
text=str(locale("sponsor_yes", "button")),
callback_data=f"sponsor_yes_{holo_user.id}",
)
],
[
InlineKeyboardButton(text=str(locale("sponsor_no", "button")), callback_data=f"sponsor_no_{holo_user.id}")
]
InlineKeyboardButton(
text=str(locale("sponsor_no", "button")),
callback_data=f"sponsor_no_{holo_user.id}",
)
],
]
)
),
)
# remove(f"tmp{sep}{filename}.jpg")
logWrite(f"User {holo_user.id} sent his sponsorship application and it will now be reviewed")
logWrite(
f"User {holo_user.id} sent his sponsorship application and it will now be reviewed"
)
col_tmp.update_one({"user": holo_user.id, "type": "sponsorship"}, {"$set": {"sent": True}})
col_tmp.update_one(
{"user": holo_user.id, "type": "sponsorship"}, {"$set": {"sent": True}}
)
return
confirmation_2 = []
for pattern in all_locales("confirm", "keyboard"):
confirmation_2.append(pattern[1][0])
@app.on_message((custom_filters.enabled_applications | custom_filters.enabled_sponsorships) & ~filters.scheduled & filters.private & filters.command(confirmation_2, prefixes=[""]) & ~custom_filters.banned)
async def confirm_no(app: Client, msg: Message, kind: Literal["application", "sponsorship", "unknown"] = "unknown"):
@app.on_message(
(custom_filters.enabled_applications | custom_filters.enabled_sponsorships)
& ~filters.scheduled
& filters.private
& filters.command(confirmation_2, prefixes=[""])
& ~custom_filters.banned
)
async def confirm_no(
app: Client,
msg: Message,
kind: Literal["application", "sponsorship", "unknown"] = "unknown",
):
holo_user = HoloUser(msg.from_user)
if configGet("enabled", "features", "applications") is True:
if (kind == "application") or ((holo_user.application_state()[0] == "fill") and (holo_user.application_state()[1] is True)):
if (kind == "application") or (
(holo_user.application_state()[0] == "fill")
and (holo_user.application_state()[1] is True)
):
holo_user.application_restart()
await welcome_pass(app, msg, once_again=True)
logWrite(f"User {msg.from_user.id} restarted the application due to typo in it")
logWrite(
f"User {msg.from_user.id} restarted the application due to typo in it"
)
return
if configGet("enabled", "features", "sponsorships") is True:
if (kind == "sponsorship") or ((holo_user.sponsorship_state()[0] == "fill") and (holo_user.sponsorship_state()[1] is True)):
if (kind == "sponsorship") or (
(holo_user.sponsorship_state()[0] == "fill")
and (holo_user.sponsorship_state()[1] is True)
):
holo_user.sponsorship_restart()
await app.send_message(holo_user.id, locale(f"sponsor1", "message", locale=holo_user.locale), reply_markup=ForceReply(placeholder=str(locale(f"sponsor1", "force_reply", locale=holo_user.locale))))
logWrite(f"User {msg.from_user.id} restarted the sponsorship application due to typo in it")
await app.send_message(
holo_user.id,
locale(f"sponsor1", "message", locale=holo_user.locale),
reply_markup=ForceReply(
placeholder=str(
locale(f"sponsor1", "force_reply", locale=holo_user.locale)
)
),
)
logWrite(
f"User {msg.from_user.id} restarted the sponsorship application due to typo in it"
)
return
# ==============================================================================================================================
# ==============================================================================================================================

View File

@@ -9,46 +9,79 @@ from modules.database import col_applications
from classes.holo_user import HoloUser
from modules import custom_filters
# Contact getting ==============================================================================================================
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.contact & filters.private & (custom_filters.allowed | custom_filters.admin) & ~custom_filters.banned)
async def get_contact(app: Client, msg: Message):
# Contact getting ==============================================================================================================
@app.on_message(
custom_filters.enabled_applications
& ~filters.scheduled
& filters.contact
& filters.private
& (custom_filters.allowed | custom_filters.admin)
& ~custom_filters.banned
)
async def get_contact(app: Client, msg: Message):
holo_user = HoloUser(msg.from_user)
if msg.contact.user_id != None:
application = col_applications.find_one({"user": msg.contact.user_id})
if application is None:
logWrite(f"User {holo_user.id} requested application of {msg.contact.user_id} but user does not exists")
await msg.reply_text(locale("contact_invalid", "message", locale=holo_user.locale))
logWrite(
f"User {holo_user.id} requested application of {msg.contact.user_id} but user does not exists"
)
await msg.reply_text(
locale("contact_invalid", "message", locale=holo_user.locale)
)
return
application_content = []
i = 1
for question in application['application']:
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', locale=holo_user.locale)} {application['application']['2'].strftime('%d.%m.%Y')} ({age.years} р.)")
age = relativedelta(datetime.now(), application["application"]["2"])
application_content.append(
f"{locale(f'question{i}', 'message', 'question_titles', locale=holo_user.locale)} {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', locale=holo_user.locale)} {application['application']['3']['name']}")
if application["application"]["3"]["countryCode"] == "UA":
application_content.append(
f"{locale(f'question{i}', 'message', 'question_titles', locale=holo_user.locale)} {application['application']['3']['name']}"
)
else:
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles', locale=holo_user.locale)} {application['application']['3']['name']} ({application['application']['3']['adminName1']}, {application['application']['3']['countryName']})")
application_content.append(
f"{locale(f'question{i}', 'message', 'question_titles', locale=holo_user.locale)} {application['application']['3']['name']} ({application['application']['3']['adminName1']}, {application['application']['3']['countryName']})"
)
else:
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles', locale=holo_user.locale)} {application['application'][question]}")
application_content.append(
f"{locale(f'question{i}', 'message', 'question_titles', locale=holo_user.locale)} {application['application'][question]}"
)
i += 1
application_status = locale("application_status_accepted", "message", locale=holo_user.locale).format((await app.get_users(application["admin"])).first_name, application["date"].strftime("%d.%m.%Y, %H:%M"))
application_status = locale(
"application_status_accepted", "message", locale=holo_user.locale
).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", locale=holo_user.locale).format(str(msg.contact.user_id), "\n".join(application_content), application_status))
await msg.reply_text(
locale("contact", "message", locale=holo_user.locale).format(
str(msg.contact.user_id),
"\n".join(application_content),
application_status,
)
)
else:
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", locale=holo_user.locale))
# ==============================================================================================================================
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", locale=holo_user.locale)
)
# ==============================================================================================================================

View File

@@ -3,35 +3,55 @@ from app import app, isAnAdmin
import asyncio
from ftfy import fix_text
from pyrogram import filters
from pyrogram.types import Message, ForceReply, InlineKeyboardMarkup, InlineKeyboardButton, ReplyKeyboardRemove
from pyrogram.types import (
Message,
ForceReply,
InlineKeyboardMarkup,
InlineKeyboardButton,
ReplyKeyboardRemove,
)
from pyrogram.client import Client
from classes.holo_user import HoloUser
from modules.utils import configGet, logWrite, locale, all_locales
from modules.database import col_messages, col_spoilers
from modules import custom_filters
async def message_involved(msg: Message) -> bool:
message = col_messages.find_one({"destination.id": msg.reply_to_message.id, "destination.chat": msg.reply_to_message.chat.id})
message = col_messages.find_one(
{
"destination.id": msg.reply_to_message.id,
"destination.chat": msg.reply_to_message.chat.id,
}
)
if message is not None:
return True
return False
async def message_context(msg: Message) -> tuple:
message = col_messages.find_one({"destination.id": msg.reply_to_message.id, "destination.chat": msg.reply_to_message.chat.id})
message = col_messages.find_one(
{
"destination.id": msg.reply_to_message.id,
"destination.chat": msg.reply_to_message.chat.id,
}
)
if message is not None:
return message["origin"]["chat"], message["origin"]["id"]
return 0, 0
# Any other input ==============================================================================================================
@app.on_message(~ filters.scheduled & (filters.private | filters.chat(configGet("admin", "groups"))) & ~custom_filters.banned)
@app.on_message(
~filters.scheduled
& (filters.private | filters.chat(configGet("admin", "groups")))
& ~custom_filters.banned
)
async def any_stage(app: Client, msg: Message):
if msg.via_bot is None:
holo_user = HoloUser(msg.from_user)
if (msg.reply_to_message is not None) and (await message_involved(msg)):
context = await message_context(msg)
context_message = await app.get_messages(context[0], context[1])
@@ -51,7 +71,7 @@ async def any_stage(app: Client, msg: Message):
animation=msg.animation,
voice=msg.voice,
adm_origin=await isAnAdmin(context_message.from_user.id),
adm_context=await isAnAdmin(msg.from_user.id)
adm_context=await isAnAdmin(msg.from_user.id),
)
return
@@ -60,29 +80,30 @@ async def any_stage(app: Client, msg: Message):
return
if msg.text is not None:
if configGet("enabled", "features", "applications") is True:
await holo_user.application_next(str(msg.text), msg=msg)
if configGet("enabled", "features", "sponsorships") is True:
await holo_user.sponsorship_next(str(msg.text), msg)
if msg.photo is not None:
await holo_user.sponsorship_next(str(msg.text), msg=msg, photo=msg.photo)
if holo_user.application_state()[0] != "fill" and holo_user.sponsorship_state()[0] != "fill":
if (
holo_user.application_state()[0] != "fill"
and holo_user.sponsorship_state()[0] != "fill"
):
if configGet("enabled", "features", "spoilers") is False:
return
spoiler = col_spoilers.find_one( {"user": msg.from_user.id, "completed": False} )
spoiler = col_spoilers.find_one(
{"user": msg.from_user.id, "completed": False}
)
if spoiler is None:
return
if spoiler["category"] is None:
found = False
# Find category in all locales
@@ -93,86 +114,226 @@ async def any_stage(app: Client, msg: Message):
category = key
if found is False:
await msg.reply_text(locale("spoiler_incorrect_category", "message", locale=msg.from_user))
await msg.reply_text(
locale(
"spoiler_incorrect_category",
"message",
locale=msg.from_user,
)
)
return
col_spoilers.find_one_and_update( {"_id": spoiler["_id"]}, {"$set": {"category": category}} )
await msg.reply_text(locale("spoiler_send_description", "message", locale=msg.from_user), reply_markup=ForceReply(placeholder=locale("spoiler_description", "force_reply", locale=msg.from_user)))
col_spoilers.find_one_and_update(
{"_id": spoiler["_id"]}, {"$set": {"category": category}}
)
await msg.reply_text(
locale("spoiler_send_description", "message", locale=msg.from_user),
reply_markup=ForceReply(
placeholder=locale(
"spoiler_description", "force_reply", locale=msg.from_user
)
),
)
return
if spoiler["description"] is None and (spoiler["photo"] is None and spoiler["video"] is None and spoiler["audio"] is None and spoiler["animation"] is None and spoiler["text"] is None):
if spoiler["description"] is None and (
spoiler["photo"] is None
and spoiler["video"] is None
and spoiler["audio"] is None
and spoiler["animation"] is None
and spoiler["text"] is None
):
# for lc in all_locales("spoiler_description", "keyboard"):
# if msg.text == lc[-1][0]:
# await msg.reply_text(locale("spoiler_description_enter", "message", locale=msg.from_user), reply_markup=ForceReply(placeholder=locale("spoiler_description", "force_reply", locale=msg.from_user)))
# return
if str(msg.text) != "-":
msg.text = fix_text(str(msg.text))
if len(str(msg.text)) > 1024:
await msg.reply_text(locale("spoiler_description_too_long", "message", locale=msg.from_user), reply_markup=ForceReply(placeholder=locale("spoiler_description", "force_reply", locale=msg.from_user)))
await msg.reply_text(
locale(
"spoiler_description_too_long",
"message",
locale=msg.from_user,
),
reply_markup=ForceReply(
placeholder=locale(
"spoiler_description",
"force_reply",
locale=msg.from_user,
)
),
)
return
col_spoilers.find_one_and_update( {"user": msg.from_user.id, "completed": False}, {"$set": {"description": msg.text}} )
col_spoilers.find_one_and_update(
{"user": msg.from_user.id, "completed": False},
{"$set": {"description": msg.text}},
)
else:
col_spoilers.find_one_and_update( {"user": msg.from_user.id, "completed": False}, {"$set": {"description": ""}} )
col_spoilers.find_one_and_update(
{"user": msg.from_user.id, "completed": False},
{"$set": {"description": ""}},
)
logWrite(f"Adding description '{str(msg.text)}' to {msg.from_user.id}'s spoiler")
await msg.reply_text(locale("spoiler_using_description", "message", locale=msg.from_user).format(msg.text), reply_markup=ForceReply(placeholder=locale("spoiler_content", "force_reply", locale=msg.from_user)))
logWrite(
f"Adding description '{str(msg.text)}' to {msg.from_user.id}'s spoiler"
)
await msg.reply_text(
locale(
"spoiler_using_description", "message", locale=msg.from_user
).format(msg.text),
reply_markup=ForceReply(
placeholder=locale(
"spoiler_content", "force_reply", locale=msg.from_user
)
),
)
return
ready = False
if msg.photo is not None:
col_spoilers.find_one_and_update( {"user": msg.from_user.id, "completed": False}, {"$set": {"photo": msg.photo.file_id, "caption": msg.caption, "completed": True}} )
logWrite(f"Adding photo with id {msg.photo.file_id} to {msg.from_user.id}'s spoiler")
col_spoilers.find_one_and_update(
{"user": msg.from_user.id, "completed": False},
{
"$set": {
"photo": msg.photo.file_id,
"caption": msg.caption,
"completed": True,
}
},
)
logWrite(
f"Adding photo with id {msg.photo.file_id} to {msg.from_user.id}'s spoiler"
)
ready = True
if msg.video is not None:
col_spoilers.find_one_and_update( {"user": msg.from_user.id, "completed": False}, {"$set": {"video": msg.video.file_id, "caption": msg.caption, "completed": True}} )
logWrite(f"Adding audio with id {msg.video.file_id} to {msg.from_user.id}'s spoiler")
col_spoilers.find_one_and_update(
{"user": msg.from_user.id, "completed": False},
{
"$set": {
"video": msg.video.file_id,
"caption": msg.caption,
"completed": True,
}
},
)
logWrite(
f"Adding audio with id {msg.video.file_id} to {msg.from_user.id}'s spoiler"
)
ready = True
if msg.audio is not None:
col_spoilers.find_one_and_update( {"user": msg.from_user.id, "completed": False}, {"$set": {"audio": msg.audio.file_id, "caption": msg.caption, "completed": True}} )
logWrite(f"Adding video with id {msg.audio.file_id} to {msg.from_user.id}'s spoiler")
col_spoilers.find_one_and_update(
{"user": msg.from_user.id, "completed": False},
{
"$set": {
"audio": msg.audio.file_id,
"caption": msg.caption,
"completed": True,
}
},
)
logWrite(
f"Adding video with id {msg.audio.file_id} to {msg.from_user.id}'s spoiler"
)
ready = True
if msg.animation is not None:
col_spoilers.find_one_and_update( {"user": msg.from_user.id, "completed": False}, {"$set": {"animation": msg.animation.file_id, "caption": msg.caption, "completed": True}} )
logWrite(f"Adding animation with id {msg.animation.file_id} to {msg.from_user.id}'s spoiler")
col_spoilers.find_one_and_update(
{"user": msg.from_user.id, "completed": False},
{
"$set": {
"animation": msg.animation.file_id,
"caption": msg.caption,
"completed": True,
}
},
)
logWrite(
f"Adding animation with id {msg.animation.file_id} to {msg.from_user.id}'s spoiler"
)
ready = True
if msg.document is not None:
col_spoilers.find_one_and_update( {"user": msg.from_user.id, "completed": False}, {"$set": {"document": msg.document.file_id, "caption": msg.caption, "completed": True}} )
logWrite(f"Adding document with id {msg.document.file_id} to {msg.from_user.id}'s spoiler")
col_spoilers.find_one_and_update(
{"user": msg.from_user.id, "completed": False},
{
"$set": {
"document": msg.document.file_id,
"caption": msg.caption,
"completed": True,
}
},
)
logWrite(
f"Adding document with id {msg.document.file_id} to {msg.from_user.id}'s spoiler"
)
ready = True
if spoiler["photo"] is None and spoiler["video"] is None and spoiler["audio"] is None and spoiler["animation"] is None and spoiler["document"] is None and spoiler["text"] is None:
if (
spoiler["photo"] is None
and spoiler["video"] is None
and spoiler["audio"] is None
and spoiler["animation"] is None
and spoiler["document"] is None
and spoiler["text"] is None
):
if msg.text is not None:
col_spoilers.find_one_and_update( {"user": msg.from_user.id, "completed": False}, {"$set": {"text": str(msg.text), "completed": True}} )
logWrite(f"Adding text '{str(msg.text)}' to {msg.from_user.id}'s spoiler")
col_spoilers.find_one_and_update(
{"user": msg.from_user.id, "completed": False},
{"$set": {"text": str(msg.text), "completed": True}},
)
logWrite(
f"Adding text '{str(msg.text)}' to {msg.from_user.id}'s spoiler"
)
ready = True
if ready is True:
await msg.reply_text(locale("spoiler_ready", "message", locale=msg.from_user), reply_markup=ReplyKeyboardRemove())
await msg.reply_text(
locale("spoiler_ready", "message", locale=msg.from_user),
reply_markup=ReplyKeyboardRemove(),
)
if configGet("allow_external", "features", "spoilers") is True:
await msg.reply_text(
locale("spoiler_send", "message", locale=msg.from_user),
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(locale("spoiler_preview", "button", locale=msg.from_user), callback_data=f"sid_{spoiler['_id'].__str__()}")
InlineKeyboardButton(
locale(
"spoiler_preview",
"button",
locale=msg.from_user,
),
callback_data=f"sid_{spoiler['_id'].__str__()}",
)
],
[
InlineKeyboardButton(locale("spoiler_send_chat", "button", locale=msg.from_user), callback_data=f"shc_{spoiler['_id'].__str__()}")
InlineKeyboardButton(
locale(
"spoiler_send_chat",
"button",
locale=msg.from_user,
),
callback_data=f"shc_{spoiler['_id'].__str__()}",
)
],
[
InlineKeyboardButton(locale("spoiler_send_other", "button", locale=msg.from_user), switch_inline_query=f"spoiler:{spoiler['_id'].__str__()}")
]
InlineKeyboardButton(
locale(
"spoiler_send_other",
"button",
locale=msg.from_user,
),
switch_inline_query=f"spoiler:{spoiler['_id'].__str__()}",
)
],
]
)
),
)
else:
await msg.reply_text(
@@ -180,33 +341,65 @@ async def any_stage(app: Client, msg: Message):
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(locale("spoiler_preview", "button", locale=msg.from_user), callback_data=f"sid_{spoiler['_id'].__str__()}")
InlineKeyboardButton(
locale(
"spoiler_preview",
"button",
locale=msg.from_user,
),
callback_data=f"sid_{spoiler['_id'].__str__()}",
)
],
[
InlineKeyboardButton(locale("spoiler_send_chat", "button", locale=msg.from_user), callback_data=f"shc_{spoiler['_id'].__str__()}")
]
InlineKeyboardButton(
locale(
"spoiler_send_chat",
"button",
locale=msg.from_user,
),
callback_data=f"shc_{spoiler['_id'].__str__()}",
)
],
]
)
),
)
else:
await msg.reply_text(locale("spoiler_incorrect_content", "message", locale=msg.from_user))
await msg.reply_text(
locale("spoiler_incorrect_content", "message", locale=msg.from_user)
)
@app.on_message(~ filters.scheduled & filters.group)
@app.on_message(~filters.scheduled & filters.group)
async def message_in_group(app: Client, msg: Message):
if (msg.chat is not None) and (msg.via_bot is not None):
if (msg.via_bot.id == (await app.get_me()).id) and (msg.chat.id == configGet("users", "groups")):
if str(msg.text).startswith(locale("spoiler_described", "message").split()[0]) or str(msg.text).startswith(locale("spoiler_empty", "message").split()[0]):
if (msg.via_bot.id == (await app.get_me()).id) and (
msg.chat.id == configGet("users", "groups")
):
if str(msg.text).startswith(
locale("spoiler_described", "message").split()[0]
) or str(msg.text).startswith(
locale("spoiler_empty", "message").split()[0]
):
logWrite(f"User {msg.from_user.id} sent spoiler to user's group")
try:
logWrite("Forwarding spoiler to admin's group")
await msg.copy(configGet("admin", "groups"), disable_notification=True)
await msg.copy(
configGet("admin", "groups"), disable_notification=True
)
except Exception as exp:
logWrite(f"Could not forward spoiler to admin's group due to '{exp}': {print_exc()}")
logWrite(
f"Could not forward spoiler to admin's group due to '{exp}': {print_exc()}"
)
return
if configGet("remove_application_time") > 0:
logWrite(f"User {msg.from_user.id} requested application in destination group, removing in {configGet('remove_application_time')} minutes")
await asyncio.sleep(configGet("remove_application_time")*60)
logWrite(
f"User {msg.from_user.id} requested application in destination group, removing in {configGet('remove_application_time')} minutes"
)
await asyncio.sleep(configGet("remove_application_time") * 60)
await msg.delete()
logWrite(f"Removed application requested by {msg.from_user.id} in destination group")
# ==============================================================================================================================
logWrite(
f"Removed application requested by {msg.from_user.id} in destination group"
)
# ==============================================================================================================================

View File

@@ -1,6 +1,11 @@
from datetime import datetime
from app import app, isAnAdmin
from pyrogram.types import ChatPermissions, InlineKeyboardMarkup, InlineKeyboardButton, ChatMemberUpdated
from pyrogram.types import (
ChatPermissions,
InlineKeyboardMarkup,
InlineKeyboardButton,
ChatMemberUpdated,
)
from pyrogram.client import Client
from modules.utils import configGet, locale
from modules import custom_filters
@@ -9,45 +14,64 @@ 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"))
@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}")
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']:
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} р.)")
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']}")
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']})")
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]}")
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)))
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}")
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})
@@ -57,42 +81,75 @@ async def filter_join(app: Client, member: ChatMemberUpdated):
application_content = []
i = 1
for question in application['application']:
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} р.)")
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']}")
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']})")
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]}")
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)))
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}")
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(
[
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}")
[
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(
),
)
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
)
can_send_polls=False,
),
)
# ==============================================================================================================================
# ==============================================================================================================================

View File

@@ -7,7 +7,13 @@ from modules.logging import logWrite
from modules.utils import configGet, locale
from modules import custom_filters
@app.on_message(custom_filters.enabled_dinovoice & ~filters.scheduled & filters.voice & filters.chat(configGet("users", "groups")))
@app.on_message(
custom_filters.enabled_dinovoice
& ~filters.scheduled
& filters.voice
& filters.chat(configGet("users", "groups"))
)
async def voice_message(app: Client, msg: Message):
logWrite(f"User {msg.from_user.id} sent voice message in destination group")
await msg.reply_text(choice(locale("voice_message", "message")))
await msg.reply_text(choice(locale("voice_message", "message")))

View File

@@ -12,15 +12,23 @@ for pattern in all_locales("welcome", "keyboard"):
welcome_1.append(pattern[0][0])
for pattern in all_locales("return", "keyboard"):
welcome_1.append(pattern[0][0])
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.private & filters.command(welcome_1, prefixes=[""]) & ~custom_filters.banned)
@app.on_message(
custom_filters.enabled_applications
& ~filters.scheduled
& filters.private
& filters.command(welcome_1, prefixes=[""])
& ~custom_filters.banned
)
async def welcome_pass(app: Client, msg: Message, once_again: bool = False) -> None:
"""Set user's stage to 1 and start a fresh application
### Args:
* app (app): Pyrogram Client to use
* app (app): Pyrogram Client to use
* msg (Message): Message with .from_user.id attribute equal to the end-user ID whose application will be started
* once_again (bool, optional): Set to False if it's the first time as user applies. Defaults to True.
"""
"""
if not once_again:
await msg.reply_text(locale("privacy_notice", "message"))
@@ -29,19 +37,41 @@ async def welcome_pass(app: Client, msg: Message, once_again: bool = False) -> N
if once_again is False:
holo_user.application_restart()
if once_again is True:
logWrite(f"User {msg.from_user.id} confirmed starting the application")
else:
logWrite(f"User {msg.from_user.id} confirmed starting the application once again")
await msg.reply_text(locale("question1", "message", locale=msg.from_user), reply_markup=ForceReply(placeholder=locale("question1", "force_reply", locale=msg.from_user)))
logWrite(
f"User {msg.from_user.id} confirmed starting the application once again"
)
await msg.reply_text(
locale("question1", "message", locale=msg.from_user),
reply_markup=ForceReply(
placeholder=locale("question1", "force_reply", locale=msg.from_user)
),
)
welcome_2 = []
for pattern in all_locales("welcome", "keyboard"):
welcome_2.append(pattern[1][0])
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.private & filters.command(welcome_2, prefixes=[""]) & ~custom_filters.banned)
async def welcome_reject(app: Client, msg: Message):
@app.on_message(
custom_filters.enabled_applications
& ~filters.scheduled
& filters.private
& filters.command(welcome_2, prefixes=[""])
& ~custom_filters.banned
)
async def welcome_reject(app: Client, msg: Message):
logWrite(f"User {msg.from_user.id} rejected to start the application")
await msg.reply_text(locale("goodbye", "message", locale=msg.from_user), reply_markup=ReplyKeyboardMarkup(locale("return", "keyboard", locale=msg.from_user), resize_keyboard=True))
# ==============================================================================================================================
await msg.reply_text(
locale("goodbye", "message", locale=msg.from_user),
reply_markup=ReplyKeyboardMarkup(
locale("return", "keyboard", locale=msg.from_user), resize_keyboard=True
),
)
# ==============================================================================================================================