This repository has been archived on 2024-08-21. You can view files and clone it, but cannot push or open issues or pull requests.
TelegramPoster/plugins/handlers/submission.py

87 lines
4.0 KiB
Python
Raw Normal View History

2023-01-10 13:52:44 +02:00
from pyrogram import filters
from pyrogram.client import Client
2023-02-14 12:38:54 +02:00
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
2023-01-10 13:52:44 +02:00
from modules.app import app
2023-02-14 12:38:54 +02:00
from modules.logger import logWrite
from modules.submissions import subLimit, subLimited
from modules.utils import configGet, jsonLoad, locale
2023-02-14 17:25:56 +02:00
from modules.database import col_banned
2023-02-14 12:38:54 +02:00
2023-01-10 13:52:44 +02:00
2023-02-14 17:25:56 +02:00
@app.on_message(~ filters.scheduled & filters.photo) # | filters.video | filters.animation | filters.document)
2023-01-10 14:06:24 +02:00
async def get_submission(_: Client, msg: Message):
2023-01-10 13:52:44 +02:00
try:
2023-01-10 14:06:24 +02:00
2023-02-14 17:25:56 +02:00
if col_banned.find_one( {"user": msg.from_user.id} ) is not None:
return
2023-01-10 14:06:24 +02:00
2023-02-14 17:25:56 +02:00
user_locale = msg.from_user.language_code
2023-01-10 13:52:44 +02:00
2023-02-14 17:25:56 +02:00
if not subLimited(msg.from_user):
2023-01-10 13:52:44 +02:00
2023-02-14 17:25:56 +02:00
if msg.document != None:
if msg.document.mime_type not in configGet("mime_types", "submission"):
await msg.reply_text(locale("mime_not_allowed", "message", locale=user_locale), quote=True)
return
if msg.document.file_size > configGet("file_size", "submission"):
await msg.reply_text(locale("document_too_large", "message", locale=user_locale).format(str(configGet("file_size", "submission")/1024/1024)), quote=True)
return
2023-01-10 13:52:44 +02:00
2023-02-14 17:25:56 +02:00
if msg.video != None:
if msg.video.file_size > configGet("file_size", "submission"):
await msg.reply_text(locale("document_too_large", "message", locale=user_locale).format(str(configGet("file_size", "submission")/1024/1024)), quote=True)
return
buttons = [
[
InlineKeyboardButton(text=locale("sub_yes", "button", locale=configGet("locale")), callback_data=f"sub_yes_{msg.from_user.id}_{msg.id}")
]
]
if msg.caption != None:
caption = str(msg.caption)
buttons[0].append(
InlineKeyboardButton(text=locale("sub_yes_caption", "button", locale=configGet("locale")), callback_data=f"sub_yes_{msg.from_user.id}_{msg.id}_caption")
)
buttons[0].append(
InlineKeyboardButton(text=locale("sub_no", "button", locale=configGet("locale")), callback_data=f"sub_no_{msg.from_user.id}_{msg.id}")
)
else:
caption = ""
buttons[0].append(
InlineKeyboardButton(text=locale("sub_no", "button", locale=configGet("locale")), callback_data=f"sub_no_{msg.from_user.id}_{msg.id}")
)
caption += locale("sub_by", "message", locale=locale(configGet("locale")))
if msg.from_user.first_name != None:
caption += f" {msg.from_user.first_name}"
if msg.from_user.last_name != None:
caption += f" {msg.from_user.last_name}"
if msg.from_user.username != None:
caption += f" (@{msg.from_user.username})"
if msg.from_user.phone_number != None:
caption += f" ({msg.from_user.phone_number})"
if msg.from_user.id != configGet("admin"):
buttons += [
[
InlineKeyboardButton(text=locale("sub_block", "button", locale=configGet("locale")), callback_data=f"sub_block_{msg.from_user.id}")
],
2023-01-10 13:52:44 +02:00
[
2023-02-14 17:25:56 +02:00
InlineKeyboardButton(text=locale("sub_unblock", "button", locale=configGet("locale")), callback_data=f"sub_unblock_{msg.from_user.id}")
2023-01-10 13:52:44 +02:00
]
]
2023-02-14 17:25:56 +02:00
await msg.reply_text(locale("sub_sent", "message", locale=user_locale), quote=True)
subLimit(msg.from_user)
2023-01-10 13:52:44 +02:00
2023-02-14 17:25:56 +02:00
await msg.copy(configGet("admin"), caption=caption, reply_markup=InlineKeyboardMarkup(buttons))
2023-01-17 15:38:31 +02:00
2023-02-14 17:25:56 +02:00
else:
await msg.reply_text(locale("sub_cooldown", "message", locale=user_locale).format(str(configGet("timeout", "submission"))))
2023-01-10 14:06:24 +02:00
2023-01-10 13:52:44 +02:00
except AttributeError:
logWrite(f"from_user in function get_submission does not seem to contain id")