WIP: API usage as main
This commit is contained in:
@@ -6,80 +6,82 @@ from modules.app import app
|
||||
from modules.logger import logWrite
|
||||
from modules.submissions import subLimit, subLimited
|
||||
from modules.utils import configGet, jsonLoad, locale
|
||||
from modules.database import col_banned
|
||||
|
||||
|
||||
@app.on_message(~ filters.scheduled & filters.photo | filters.video | filters.animation | filters.document)
|
||||
@app.on_message(~ filters.scheduled & filters.photo) # | filters.video | filters.animation | filters.document)
|
||||
async def get_submission(_: Client, msg: Message):
|
||||
|
||||
try:
|
||||
|
||||
if msg.from_user.id not in jsonLoad(configGet("blocked", "locations")):
|
||||
|
||||
user_locale = msg.from_user.language_code
|
||||
if col_banned.find_one( {"user": msg.from_user.id} ) is not None:
|
||||
return
|
||||
|
||||
if not subLimited(msg.from_user):
|
||||
user_locale = msg.from_user.language_code
|
||||
|
||||
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
|
||||
if not subLimited(msg.from_user):
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
buttons = [
|
||||
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_yes", "button", locale=configGet("locale")), callback_data=f"sub_yes_{msg.from_user.id}_{msg.id}")
|
||||
InlineKeyboardButton(text=locale("sub_block", "button", locale=configGet("locale")), callback_data=f"sub_block_{msg.from_user.id}")
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton(text=locale("sub_unblock", "button", locale=configGet("locale")), callback_data=f"sub_unblock_{msg.from_user.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}")
|
||||
)
|
||||
await msg.reply_text(locale("sub_sent", "message", locale=user_locale), quote=True)
|
||||
subLimit(msg.from_user)
|
||||
|
||||
caption += locale("sub_by", "message", locale=locale(configGet("locale")))
|
||||
await msg.copy(configGet("admin"), caption=caption, reply_markup=InlineKeyboardMarkup(buttons))
|
||||
|
||||
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}")
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton(text=locale("sub_unblock", "button", locale=configGet("locale")), callback_data=f"sub_unblock_{msg.from_user.id}")
|
||||
]
|
||||
]
|
||||
|
||||
await msg.reply_text(locale("sub_sent", "message", locale=user_locale), quote=True)
|
||||
subLimit(msg.from_user)
|
||||
|
||||
await msg.copy(configGet("admin"), caption=caption, reply_markup=InlineKeyboardMarkup(buttons))
|
||||
|
||||
else:
|
||||
await msg.reply_text(locale("sub_cooldown", "message", locale=user_locale).format(str(configGet("timeout", "submission"))))
|
||||
else:
|
||||
await msg.reply_text(locale("sub_cooldown", "message", locale=user_locale).format(str(configGet("timeout", "submission"))))
|
||||
|
||||
except AttributeError:
|
||||
logWrite(f"from_user in function get_submission does not seem to contain id")
|
Reference in New Issue
Block a user