Submission without confirmation added
This commit is contained in:
parent
0d2e9fa6ec
commit
663a7b0db8
@ -88,6 +88,10 @@
|
||||
"timeout": 30,
|
||||
"file_size": 15728640,
|
||||
"tmp_size": 15728640,
|
||||
"require_confirmation": {
|
||||
"users": true,
|
||||
"admins": true
|
||||
},
|
||||
"mime_types": [
|
||||
"image/png",
|
||||
"image/gif",
|
||||
|
@ -1,70 +1,37 @@
|
||||
from os import path, remove, sep
|
||||
from pathlib import Path
|
||||
from shutil import rmtree
|
||||
|
||||
from pyrogram import filters
|
||||
from pyrogram.client import Client
|
||||
from pyrogram.types import CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton
|
||||
from classes.exceptions import SubmissionDuplicatesError, SubmissionUnavailableError
|
||||
from classes.poster_client import PosterClient
|
||||
|
||||
from modules.api_client import upload_pic
|
||||
from modules.app import app
|
||||
from modules.logger import logWrite
|
||||
from modules.submissions import subBlock, subUnblock
|
||||
from modules.utils import configGet, jsonLoad, jsonSave, locale
|
||||
from modules.utils import configGet, locale
|
||||
from modules.database import col_submitted
|
||||
from bson import ObjectId
|
||||
|
||||
|
||||
@app.on_callback_query(filters.regex("sub_yes_[\s\S]*"))
|
||||
async def callback_query_yes(app: Client, clb: CallbackQuery):
|
||||
async def callback_query_yes(app: PosterClient, clb: CallbackQuery):
|
||||
|
||||
fullclb = clb.data.split("_")
|
||||
fullclb = str(clb.data).split("_")
|
||||
user_locale = clb.from_user.language_code
|
||||
|
||||
db_entry = col_submitted.find_one({"_id": ObjectId(fullclb[2])})
|
||||
submission = None
|
||||
|
||||
if db_entry is None:
|
||||
await clb.answer(text=locale("sub_msg_unavail", "callback", locale=user_locale), show_alert=True)
|
||||
return
|
||||
else:
|
||||
if db_entry["temp"]["uuid"] is not None:
|
||||
if not path.exists(path.join(configGet("data", "locations"), "submissions", db_entry["temp"]["uuid"], db_entry["temp"]["file"])):
|
||||
await clb.answer(text=locale("sub_msg_unavail", "callback", locale=user_locale), show_alert=True)
|
||||
return
|
||||
else:
|
||||
filepath = path.join(configGet("data", "locations"), "submissions", db_entry["temp"]["uuid"], db_entry["temp"]["file"])
|
||||
else:
|
||||
try:
|
||||
submission = await app.get_messages(db_entry["user"], db_entry["telegram"]["msg_id"])
|
||||
filepath = await app.download_media(submission, file_name=configGet("tmp", "locations")+sep)
|
||||
except:
|
||||
await clb.answer(text=locale("sub_msg_unavail", "callback", locale=user_locale), show_alert=True)
|
||||
return
|
||||
|
||||
response = await upload_pic(str(filepath))
|
||||
|
||||
if response[0] is False and len(response[1]) == 0:
|
||||
await clb.answer(text=locale("sub_upload_failed", "callback", locale=user_locale), show_alert=True)
|
||||
return
|
||||
elif response[0] is False:
|
||||
await clb.answer(text=locale("sub_duplicates_found", "callback", locale=user_locale), show_alert=True)
|
||||
await clb.message.reply_text(locale("sub_media_duplicates_list", "message", locale=user_locale).format("\n • ".join(response[1])))
|
||||
return
|
||||
|
||||
col_submitted.find_one_and_update({"_id": ObjectId(fullclb[2])}, {"$set": {"done": True}})
|
||||
|
||||
try:
|
||||
if db_entry["temp"]["uuid"] is not None:
|
||||
rmtree(path.join(configGet("data", "locations"), "submissions", db_entry["temp"]["uuid"]), ignore_errors=True)
|
||||
else:
|
||||
remove(str(filepath))
|
||||
except (FileNotFoundError, NotADirectoryError):
|
||||
logWrite(f"Could not delete '{filepath}' on submission accepted", debug=True)
|
||||
submission = await app.submit_photo(fullclb[2])
|
||||
except SubmissionUnavailableError:
|
||||
await clb.answer(text=locale("sub_msg_unavail", "callback", locale=user_locale), show_alert=True)
|
||||
return
|
||||
except SubmissionDuplicatesError as exp:
|
||||
await clb.answer(text=locale("sub_duplicates_found", "callback", locale=user_locale), show_alert=True)
|
||||
await clb.message.reply_text(locale("sub_media_duplicates_list", "message", locale=user_locale).format("\n • ".join(exp.duplicates)))
|
||||
return
|
||||
|
||||
if submission is not None:
|
||||
await submission.reply_text(locale("sub_yes", "message", locale=submission.from_user.language_code), quote=True)
|
||||
else:
|
||||
elif db_entry is not None:
|
||||
await app.send_message(db_entry["user"], locale("sub_yes", "message"))
|
||||
|
||||
await clb.answer(text=locale("sub_yes", "callback", locale=user_locale).format(fullclb[2]), show_alert=True)
|
||||
@ -72,10 +39,6 @@ async def callback_query_yes(app: Client, clb: CallbackQuery):
|
||||
edited_markup = [[InlineKeyboardButton(text=str(locale("accepted", "button")), callback_data="nothing")], clb.message.reply_markup.inline_keyboard[1]] if len(clb.message.reply_markup.inline_keyboard) > 1 else [[InlineKeyboardButton(text=str(locale("accepted", "button")), callback_data="nothing")]]
|
||||
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||
|
||||
# Change keyboard to a completed variant
|
||||
|
||||
# Send replies to both user and admin about accepting the application
|
||||
|
||||
# try:
|
||||
# if configGet("api_based", "mode") is True:
|
||||
# media = await app.download_media(submission, file_name=configGet("tmp", "locations")+sep)
|
||||
@ -107,7 +70,7 @@ async def callback_query_yes(app: Client, clb: CallbackQuery):
|
||||
|
||||
|
||||
@app.on_callback_query(filters.regex("sub_no_[\s\S]*"))
|
||||
async def callback_query_no(app: Client, clb: CallbackQuery):
|
||||
async def callback_query_no(app: PosterClient, clb: CallbackQuery):
|
||||
fullclb = clb.data.split("_")
|
||||
user_locale = clb.from_user.language_code
|
||||
try:
|
||||
@ -123,7 +86,7 @@ async def callback_query_no(app: Client, clb: CallbackQuery):
|
||||
|
||||
|
||||
@app.on_callback_query(filters.regex("sub_block_[\s\S]*"))
|
||||
async def callback_query_block(app: Client, clb: CallbackQuery):
|
||||
async def callback_query_block(app: PosterClient, clb: CallbackQuery):
|
||||
fullclb = clb.data.split("_")
|
||||
user_locale = clb.from_user.language_code
|
||||
await app.send_message(int(fullclb[2]), locale("sub_msg_unavail", "message", locale=configGet("locale")))
|
||||
@ -135,7 +98,7 @@ async def callback_query_block(app: Client, clb: CallbackQuery):
|
||||
|
||||
|
||||
@app.on_callback_query(filters.regex("sub_unblock_[\s\S]*"))
|
||||
async def callback_query_unblock(app: Client, clb: CallbackQuery):
|
||||
async def callback_query_unblock(app: PosterClient, clb: CallbackQuery):
|
||||
fullclb = clb.data.split("_")
|
||||
user_locale = clb.from_user.language_code
|
||||
await app.send_message(int(fullclb[2]), locale("sub_msg_unavail", "message", locale=configGet("locale")))
|
||||
|
Reference in New Issue
Block a user