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/everything.py

129 lines
7.4 KiB
Python
Raw Normal View History

from app import app, isAnAdmin
2022-12-05 19:49:51 +02:00
import asyncio
from pyrogram import filters
2022-12-14 15:19:20 +02:00
from pyrogram.types import Message
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
2022-12-14 15:19:20 +02:00
from modules.utils import configGet, logWrite
2022-12-11 19:50:50 +02:00
from modules.database import col_messages
2022-12-11 19:50:50 +02:00
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})
if message is not None:
return True
return False
2022-12-11 19:50:50 +02:00
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})
if message is not None:
return message["origin"]["chat"], message["origin"]["id"]
return 0, 0
2022-12-05 19:49:51 +02:00
# Any other input ==============================================================================================================
2022-12-13 15:24:31 +02:00
@app.on_message(~ filters.scheduled & filters.private)
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)
await destination_user.message(
origin=context_message,
context=msg,
text=msg.text,
caption=msg.caption,
photo=msg.photo,
video=msg.video,
file=msg.document,
adm_origin=await isAnAdmin(context_message.from_user.id),
adm_context=await isAnAdmin(msg.from_user.id)
)
# await msg.reply_text(locale("message_sent", "message"), quote=should_quote(msg))
# col_messages.insert_one({"origin": {"chat": msg.chat.id, "id": msg.id}, "destination": {"chat": new_message.chat.id, "id": new_message.id}})
return
2022-12-12 15:35:11 +02:00
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:
await holo_user.application_next(msg.text, msg=msg)
if configGet("enabled", "features", "sponsorships") is True:
await holo_user.sponsorship_next(msg.text, msg=msg)
2022-12-14 14:58:06 +02:00
# user_stage = configGet("stage", file=str(msg.from_user.id))
2022-12-05 19:49:51 +02:00
2022-12-14 14:58:06 +02:00
# if user_stage == 1:
# await msg.reply_text(locale(f"question{user_stage+1}", "message"), reply_markup=ForceReply(placeholder=str(locale(f"question{user_stage+1}", "force_reply"))))
# logWrite(f"User {msg.from_user.id} completed stage {user_stage} of application")
# configSet(["application", str(user_stage)], str(msg.text), file=str(msg.from_user.id))
# configSet(["stage"], user_stage+1, file=str(msg.from_user.id))
# elif user_stage == 2:
# try:
# configSet(["application", str(user_stage)], str(msg.text), file=str(msg.from_user.id))
# input_dt = datetime.strptime(msg.text, "%d.%m.%Y")
# if datetime.now() <= input_dt:
# logWrite(f"User {msg.from_user.id} failed stage {user_stage} due to joking")
# await msg.reply_text(locale("question2_joke", "message"), reply_markup=ForceReply(placeholder=str(locale("question2", "force_reply"))))
# elif ((datetime.now() - input_dt).days) < ((datetime.now() - datetime.now().replace(year=datetime.now().year - configGet("age_allowed"))).days):
# logWrite(f"User {msg.from_user.id} failed stage {user_stage} due to being underage")
# await msg.reply_text(locale("question2_underage", "message").format(str(configGet("age_allowed"))), reply_markup=ForceReply(placeholder=str(locale("question2", "force_reply"))))
# else:
# logWrite(f"User {msg.from_user.id} completed stage {user_stage} of application")
# await msg.reply_text(locale(f"question{user_stage+1}", "message"), reply_markup=ForceReply(placeholder=str(locale(f"question{user_stage+1}", "force_reply"))))
# configSet(["stage"], user_stage+1, file=str(msg.from_user.id))
# except ValueError:
# logWrite(f"User {msg.from_user.id} failed stage {user_stage} due to sending invalid date format")
# await msg.reply_text(locale(f"question2_invalid", "message"), reply_markup=ForceReply(placeholder=str(locale(f"question{user_stage}", "force_reply"))))
# else:
# if user_stage <= 9:
# logWrite(f"User {msg.from_user.id} completed stage {user_stage} of application")
# await msg.reply_text(locale(f"question{user_stage+1}", "message"), reply_markup=ForceReply(placeholder=str(locale(f"question{user_stage+1}", "force_reply"))))
# configSet(["application", str(user_stage)], str(msg.text), file=str(msg.from_user.id))
# configSet(["stage"], user_stage+1, file=str(msg.from_user.id))
# else:
# if not configGet("sent", file=str(msg.from_user.id)):
# if not configGet("confirmed", file=str(msg.from_user.id)):
# configSet(["application", str(user_stage)], str(msg.text), file=str(msg.from_user.id))
# application_content = []
# i = 1
# for question in configGet("application", file=str(msg.from_user.id)):
# application_content.append(f"{locale('question'+str(i), 'message', 'question_titles')} {configGet('application', file=str(msg.from_user.id))[question]}")
# i += 1
# await msg.reply_text(locale("confirm", "message").format("\n".join(application_content)), reply_markup=ReplyKeyboardMarkup(locale("confirm", "keyboard"), resize_keyboard=True))
# #configSet("sent", True, file=str(msg.from_user.id))
# #configSet("application_date", int(time()), file=str(msg.from_user.id))
# else:
2022-12-15 14:50:11 +02:00
# if not configGet("approved", file=str(msg.from_user.id)) and not configGet("rejected", file=str(msg.from_user.id)):
2022-12-14 14:58:06 +02:00
# await msg.reply_text(locale("already_sent", "message"))
# else:
2022-12-15 14:50:11 +02:00
# if not configGet("approved", file=str(msg.from_user.id)) and not configGet("rejected", file=str(msg.from_user.id)):
2022-12-14 14:58:06 +02:00
# await msg.reply_text(locale("already_sent", "message"))
2022-12-05 19:49:51 +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):
if (msg.via_bot.id == configGet("bot_id")) and (msg.chat.id == configGet("destination_group")):
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)
await msg.delete()
logWrite(f"Removed application requested by {msg.from_user.id} in destination group")
# ==============================================================================================================================