2023-01-05 16:48:34 +02:00
|
|
|
from traceback import print_exc
|
2022-12-07 15:17:27 +02:00
|
|
|
from app import app, isAnAdmin
|
2022-12-05 19:49:51 +02:00
|
|
|
import asyncio
|
2023-01-10 14:41:08 +02:00
|
|
|
from ftfy import fix_text
|
2022-12-05 19:49:51 +02:00
|
|
|
from pyrogram import filters
|
2023-03-09 17:25:06 +02:00
|
|
|
from pyrogram.types import (
|
|
|
|
Message,
|
|
|
|
ForceReply,
|
|
|
|
InlineKeyboardMarkup,
|
|
|
|
InlineKeyboardButton,
|
|
|
|
ReplyKeyboardRemove,
|
|
|
|
)
|
2022-12-27 14:36:54 +02:00
|
|
|
from pyrogram.client import Client
|
2022-12-13 15:24:31 +02:00
|
|
|
from classes.holo_user import HoloUser
|
2023-01-04 21:13:29 +02:00
|
|
|
from modules.utils import configGet, logWrite, locale, all_locales
|
|
|
|
from modules.database import col_messages, col_spoilers
|
2023-01-30 12:28:23 +02:00
|
|
|
from modules import custom_filters
|
2022-12-07 15:17:27 +02:00
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
|
2022-12-11 19:50:50 +02:00
|
|
|
async def message_involved(msg: Message) -> bool:
|
2023-03-09 17:25:06 +02:00
|
|
|
message = col_messages.find_one(
|
|
|
|
{
|
|
|
|
"destination.id": msg.reply_to_message.id,
|
|
|
|
"destination.chat": msg.reply_to_message.chat.id,
|
|
|
|
}
|
|
|
|
)
|
2022-12-11 19:50:50 +02:00
|
|
|
if message is not None:
|
|
|
|
return True
|
2022-12-07 15:17:27 +02:00
|
|
|
return False
|
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
|
2022-12-11 19:50:50 +02:00
|
|
|
async def message_context(msg: Message) -> tuple:
|
2023-03-09 17:25:06 +02:00
|
|
|
message = col_messages.find_one(
|
|
|
|
{
|
|
|
|
"destination.id": msg.reply_to_message.id,
|
|
|
|
"destination.chat": msg.reply_to_message.chat.id,
|
|
|
|
}
|
|
|
|
)
|
2022-12-11 19:50:50 +02:00
|
|
|
if message is not None:
|
|
|
|
return message["origin"]["chat"], message["origin"]["id"]
|
|
|
|
return 0, 0
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
|
2022-12-05 19:49:51 +02:00
|
|
|
# Any other input ==============================================================================================================
|
2023-03-09 17:25:06 +02:00
|
|
|
@app.on_message(
|
|
|
|
~filters.scheduled
|
|
|
|
& (filters.private | filters.chat(configGet("admin", "groups")))
|
|
|
|
& ~custom_filters.banned
|
|
|
|
)
|
2022-12-27 14:36:54 +02:00
|
|
|
async def any_stage(app: Client, msg: Message):
|
2022-12-13 15:24:31 +02:00
|
|
|
if msg.via_bot is None:
|
2022-12-14 14:58:06 +02:00
|
|
|
holo_user = HoloUser(msg.from_user)
|
|
|
|
|
|
|
|
if (msg.reply_to_message is not None) and (await message_involved(msg)):
|
2022-12-13 15:24:31 +02:00
|
|
|
context = await message_context(msg)
|
|
|
|
context_message = await app.get_messages(context[0], context[1])
|
|
|
|
|
|
|
|
destination_user = HoloUser(context_message.from_user)
|
|
|
|
|
2023-01-30 11:54:43 +02:00
|
|
|
if destination_user is None:
|
|
|
|
return
|
|
|
|
|
2022-12-13 15:24:31 +02:00
|
|
|
await destination_user.message(
|
|
|
|
origin=context_message,
|
|
|
|
context=msg,
|
2023-01-30 11:54:43 +02:00
|
|
|
text=str(msg.text),
|
2022-12-13 15:24:31 +02:00
|
|
|
caption=msg.caption,
|
|
|
|
photo=msg.photo,
|
|
|
|
video=msg.video,
|
|
|
|
file=msg.document,
|
2023-01-06 14:21:16 +02:00
|
|
|
animation=msg.animation,
|
|
|
|
voice=msg.voice,
|
2022-12-13 15:24:31 +02:00
|
|
|
adm_origin=await isAnAdmin(context_message.from_user.id),
|
2023-03-09 17:25:06 +02:00
|
|
|
adm_context=await isAnAdmin(msg.from_user.id),
|
2022-12-13 15:24:31 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
return
|
2022-12-12 15:35:11 +02:00
|
|
|
|
2023-01-16 13:09:28 +02:00
|
|
|
if msg.chat.id == configGet("admin", "groups"):
|
|
|
|
return
|
|
|
|
|
2022-12-21 16:23:36 +02:00
|
|
|
if msg.text is not None:
|
2023-01-03 21:34:13 +02:00
|
|
|
if configGet("enabled", "features", "applications") is True:
|
2023-01-30 11:54:43 +02:00
|
|
|
await holo_user.application_next(str(msg.text), msg=msg)
|
2023-03-09 17:25:06 +02:00
|
|
|
|
2023-01-03 21:34:13 +02:00
|
|
|
if configGet("enabled", "features", "sponsorships") is True:
|
2023-01-30 11:54:43 +02:00
|
|
|
await holo_user.sponsorship_next(str(msg.text), msg)
|
2023-01-05 21:47:30 +02:00
|
|
|
|
|
|
|
if msg.photo is not None:
|
2023-01-30 11:54:43 +02:00
|
|
|
await holo_user.sponsorship_next(str(msg.text), msg=msg, photo=msg.photo)
|
2023-01-04 21:13:29 +02:00
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
if (
|
|
|
|
holo_user.application_state()[0] != "fill"
|
|
|
|
and holo_user.sponsorship_state()[0] != "fill"
|
|
|
|
):
|
2023-01-13 11:43:27 +02:00
|
|
|
if configGet("enabled", "features", "spoilers") is False:
|
|
|
|
return
|
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
spoiler = col_spoilers.find_one(
|
|
|
|
{"user": msg.from_user.id, "completed": False}
|
|
|
|
)
|
2023-01-04 21:13:29 +02:00
|
|
|
|
|
|
|
if spoiler is None:
|
|
|
|
return
|
|
|
|
|
2023-01-05 15:34:02 +02:00
|
|
|
if spoiler["category"] is None:
|
|
|
|
found = False
|
|
|
|
|
|
|
|
# Find category in all locales
|
|
|
|
for lc in all_locales("spoiler_categories", "message"):
|
|
|
|
for key in lc:
|
2023-01-30 11:54:43 +02:00
|
|
|
if lc[key] == str(msg.text):
|
2023-01-05 15:34:02 +02:00
|
|
|
found = True
|
|
|
|
category = key
|
|
|
|
|
|
|
|
if found is False:
|
2023-03-09 17:25:06 +02:00
|
|
|
await msg.reply_text(
|
|
|
|
locale(
|
|
|
|
"spoiler_incorrect_category",
|
|
|
|
"message",
|
|
|
|
locale=msg.from_user,
|
|
|
|
)
|
|
|
|
)
|
2023-01-05 15:34:02 +02:00
|
|
|
return
|
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
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
|
|
|
|
)
|
|
|
|
),
|
|
|
|
)
|
2023-01-05 15:34:02 +02:00
|
|
|
return
|
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
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
|
|
|
|
):
|
2023-01-05 15:34:02 +02:00
|
|
|
# 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
|
|
|
|
|
2023-01-30 11:54:43 +02:00
|
|
|
if str(msg.text) != "-":
|
|
|
|
msg.text = fix_text(str(msg.text))
|
|
|
|
if len(str(msg.text)) > 1024:
|
2023-03-09 17:25:06 +02:00
|
|
|
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,
|
|
|
|
)
|
|
|
|
),
|
|
|
|
)
|
2023-01-10 14:41:08 +02:00
|
|
|
return
|
2023-03-09 17:25:06 +02:00
|
|
|
col_spoilers.find_one_and_update(
|
|
|
|
{"user": msg.from_user.id, "completed": False},
|
|
|
|
{"$set": {"description": msg.text}},
|
|
|
|
)
|
2023-01-05 15:34:02 +02:00
|
|
|
else:
|
2023-03-09 17:25:06 +02:00
|
|
|
col_spoilers.find_one_and_update(
|
|
|
|
{"user": msg.from_user.id, "completed": False},
|
|
|
|
{"$set": {"description": ""}},
|
|
|
|
)
|
2023-01-05 15:34:02 +02:00
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
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
|
|
|
|
)
|
|
|
|
),
|
|
|
|
)
|
2023-01-05 15:34:02 +02:00
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
ready = False
|
|
|
|
|
2023-01-04 21:13:29 +02:00
|
|
|
if msg.photo is not None:
|
2023-03-09 17:25:06 +02:00
|
|
|
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"
|
|
|
|
)
|
2023-01-05 15:34:02 +02:00
|
|
|
ready = True
|
2023-01-04 22:55:50 +02:00
|
|
|
|
|
|
|
if msg.video is not None:
|
2023-03-09 17:25:06 +02:00
|
|
|
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"
|
|
|
|
)
|
2023-01-10 13:11:29 +02:00
|
|
|
ready = True
|
|
|
|
|
|
|
|
if msg.audio is not None:
|
2023-03-09 17:25:06 +02:00
|
|
|
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"
|
|
|
|
)
|
2023-01-05 15:34:02 +02:00
|
|
|
ready = True
|
2023-01-04 22:55:50 +02:00
|
|
|
|
|
|
|
if msg.animation is not None:
|
2023-03-09 17:25:06 +02:00
|
|
|
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"
|
|
|
|
)
|
2023-01-05 15:34:02 +02:00
|
|
|
ready = True
|
2023-01-04 21:13:29 +02:00
|
|
|
|
2023-01-05 22:15:34 +02:00
|
|
|
if msg.document is not None:
|
2023-03-09 17:25:06 +02:00
|
|
|
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"
|
|
|
|
)
|
2023-01-05 22:15:34 +02:00
|
|
|
ready = True
|
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
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
|
|
|
|
):
|
2023-01-05 15:52:57 +02:00
|
|
|
if msg.text is not None:
|
2023-03-09 17:25:06 +02:00
|
|
|
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"
|
|
|
|
)
|
2023-01-05 15:52:57 +02:00
|
|
|
ready = True
|
2023-01-05 15:34:02 +02:00
|
|
|
|
|
|
|
if ready is True:
|
2023-03-09 17:25:06 +02:00
|
|
|
await msg.reply_text(
|
|
|
|
locale("spoiler_ready", "message", locale=msg.from_user),
|
|
|
|
reply_markup=ReplyKeyboardRemove(),
|
|
|
|
)
|
2023-01-12 12:04:52 +02:00
|
|
|
if configGet("allow_external", "features", "spoilers") is True:
|
|
|
|
await msg.reply_text(
|
2023-01-30 11:58:47 +02:00
|
|
|
locale("spoiler_send", "message", locale=msg.from_user),
|
2023-01-12 12:04:52 +02:00
|
|
|
reply_markup=InlineKeyboardMarkup(
|
|
|
|
[
|
|
|
|
[
|
2023-03-09 17:25:06 +02:00
|
|
|
InlineKeyboardButton(
|
|
|
|
locale(
|
|
|
|
"spoiler_preview",
|
|
|
|
"button",
|
|
|
|
locale=msg.from_user,
|
|
|
|
),
|
|
|
|
callback_data=f"sid_{spoiler['_id'].__str__()}",
|
|
|
|
)
|
2023-01-12 12:04:52 +02:00
|
|
|
],
|
|
|
|
[
|
2023-03-09 17:25:06 +02:00
|
|
|
InlineKeyboardButton(
|
|
|
|
locale(
|
|
|
|
"spoiler_send_chat",
|
|
|
|
"button",
|
|
|
|
locale=msg.from_user,
|
|
|
|
),
|
|
|
|
callback_data=f"shc_{spoiler['_id'].__str__()}",
|
|
|
|
)
|
2023-01-12 12:04:52 +02:00
|
|
|
],
|
|
|
|
[
|
2023-03-09 17:25:06 +02:00
|
|
|
InlineKeyboardButton(
|
|
|
|
locale(
|
|
|
|
"spoiler_send_other",
|
|
|
|
"button",
|
|
|
|
locale=msg.from_user,
|
|
|
|
),
|
|
|
|
switch_inline_query=f"spoiler:{spoiler['_id'].__str__()}",
|
|
|
|
)
|
|
|
|
],
|
2023-01-12 12:04:52 +02:00
|
|
|
]
|
2023-03-09 17:25:06 +02:00
|
|
|
),
|
2023-01-12 12:04:52 +02:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
await msg.reply_text(
|
2023-01-30 11:58:47 +02:00
|
|
|
locale("spoiler_send", "message", locale=msg.from_user),
|
2023-01-12 12:04:52 +02:00
|
|
|
reply_markup=InlineKeyboardMarkup(
|
|
|
|
[
|
|
|
|
[
|
2023-03-09 17:25:06 +02:00
|
|
|
InlineKeyboardButton(
|
|
|
|
locale(
|
|
|
|
"spoiler_preview",
|
|
|
|
"button",
|
|
|
|
locale=msg.from_user,
|
|
|
|
),
|
|
|
|
callback_data=f"sid_{spoiler['_id'].__str__()}",
|
|
|
|
)
|
2023-01-12 12:04:52 +02:00
|
|
|
],
|
|
|
|
[
|
2023-03-09 17:25:06 +02:00
|
|
|
InlineKeyboardButton(
|
|
|
|
locale(
|
|
|
|
"spoiler_send_chat",
|
|
|
|
"button",
|
|
|
|
locale=msg.from_user,
|
|
|
|
),
|
|
|
|
callback_data=f"shc_{spoiler['_id'].__str__()}",
|
|
|
|
)
|
|
|
|
],
|
2023-01-12 12:04:52 +02:00
|
|
|
]
|
2023-03-09 17:25:06 +02:00
|
|
|
),
|
2023-01-12 12:04:52 +02:00
|
|
|
)
|
2023-01-04 21:13:29 +02:00
|
|
|
else:
|
2023-03-09 17:25:06 +02:00
|
|
|
await msg.reply_text(
|
|
|
|
locale("spoiler_incorrect_content", "message", locale=msg.from_user)
|
|
|
|
)
|
2022-12-14 14:58:06 +02:00
|
|
|
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
@app.on_message(~filters.scheduled & filters.group)
|
2022-12-27 14:36:54 +02:00
|
|
|
async def message_in_group(app: Client, msg: Message):
|
2022-12-05 19:49:51 +02:00
|
|
|
if (msg.chat is not None) and (msg.via_bot is not None):
|
2023-03-09 17:25:06 +02:00
|
|
|
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]
|
|
|
|
):
|
2023-01-05 16:48:34 +02:00
|
|
|
logWrite(f"User {msg.from_user.id} sent spoiler to user's group")
|
2023-01-04 22:55:50 +02:00
|
|
|
try:
|
2023-01-05 16:48:34 +02:00
|
|
|
logWrite("Forwarding spoiler to admin's group")
|
2023-03-09 17:25:06 +02:00
|
|
|
await msg.copy(
|
|
|
|
configGet("admin", "groups"), disable_notification=True
|
|
|
|
)
|
2023-01-05 16:48:34 +02:00
|
|
|
except Exception as exp:
|
2023-03-09 17:25:06 +02:00
|
|
|
logWrite(
|
|
|
|
f"Could not forward spoiler to admin's group due to '{exp}': {print_exc()}"
|
|
|
|
)
|
2023-01-04 22:55:50 +02:00
|
|
|
return
|
2022-12-05 19:49:51 +02:00
|
|
|
if configGet("remove_application_time") > 0:
|
2023-03-09 17:25:06 +02:00
|
|
|
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)
|
2022-12-05 19:49:51 +02:00
|
|
|
await msg.delete()
|
2023-03-09 17:25:06 +02:00
|
|
|
logWrite(
|
|
|
|
f"Removed application requested by {msg.from_user.id} in destination group"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# ==============================================================================================================================
|