Now using black for formatting

This commit is contained in:
2023-03-09 11:33:02 +01:00
parent 4331af415e
commit 88692ebc85
19 changed files with 701 additions and 250 deletions

View File

@@ -4,8 +4,9 @@ from pyrogram.types import CallbackQuery
from classes.poster_client import PosterClient
from modules.utils import locale
# Callback empty ===============================================================================================================
@app.on_callback_query(filters.regex("nothing"))
async def callback_query_nothing(app: PosterClient, clb: CallbackQuery):
await clb.answer(text=locale("nothing", "callback", locale=clb.from_user.language_code))
# ==============================================================================================================================
await clb.answer(
text=locale("nothing", "callback", locale=clb.from_user.language_code)
)

View File

@@ -1,4 +1,3 @@
from os import path
from shutil import rmtree
from pyrogram import filters
@@ -15,7 +14,6 @@ from bson import ObjectId
@app.on_callback_query(filters.regex("sub_yes_[\s\S]*"))
async def callback_query_yes(app: PosterClient, clb: CallbackQuery):
fullclb = str(clb.data).split("_")
user_locale = clb.from_user.language_code
@@ -24,22 +22,60 @@ async def callback_query_yes(app: PosterClient, clb: CallbackQuery):
try:
submission = await app.submit_photo(fullclb[2])
except SubmissionUnavailableError:
await clb.answer(text=locale("sub_msg_unavail", "callback", locale=user_locale), show_alert=True)
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)), quote=True)
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)
),
quote=True,
)
return
if submission is not None:
await submission.reply_text(locale("sub_yes", "message", locale=submission.from_user.language_code), quote=True)
await submission.reply_text(
locale("sub_yes", "message", locale=submission.from_user.language_code),
quote=True,
)
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)
await clb.answer(
text=locale("sub_yes", "callback", locale=user_locale).format(fullclb[2]),
show_alert=True,
)
edited_markup = [[InlineKeyboardButton(text=str(locale("accepted", "button", locale=user_locale)), 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", locale=user_locale)), callback_data="nothing")]]
await clb.message.edit_reply_markup(reply_markup=InlineKeyboardMarkup(edited_markup))
edited_markup = (
[
[
InlineKeyboardButton(
text=str(locale("accepted", "button", locale=user_locale)),
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", locale=user_locale)),
callback_data="nothing",
)
]
]
)
await clb.message.edit_reply_markup(
reply_markup=InlineKeyboardMarkup(edited_markup)
)
# try:
# if configGet("api_based", "mode") is True:
@@ -68,48 +104,120 @@ async def callback_query_yes(app: PosterClient, clb: CallbackQuery):
@app.on_callback_query(filters.regex("sub_no_[\s\S]*"))
async def callback_query_no(app: PosterClient, clb: CallbackQuery):
fullclb = str(clb.data).split("_")
user_locale = clb.from_user.language_code
db_entry = col_submitted.find_one_and_delete({"_id": ObjectId(fullclb[2])})
if db_entry["temp"]["uuid"] is not None:
if path.exists(path.join(configGet("data", "locations"), "submissions", db_entry["temp"]["uuid"])):
rmtree(path.join(configGet("data", "locations"), "submissions", db_entry["temp"]["uuid"]), ignore_errors=True)
if path.exists(
path.join(
configGet("data", "locations"), "submissions", db_entry["temp"]["uuid"]
)
):
rmtree(
path.join(
configGet("data", "locations"),
"submissions",
db_entry["temp"]["uuid"],
),
ignore_errors=True,
)
try:
submission = await app.get_messages(db_entry["user"], db_entry["telegram"]["msg_id"])
submission = await app.get_messages(
db_entry["user"], db_entry["telegram"]["msg_id"]
)
except:
await clb.answer(text=locale("sub_msg_unavail", "message", locale=user_locale), show_alert=True)
await clb.answer(
text=locale("sub_msg_unavail", "message", locale=user_locale),
show_alert=True,
)
return
await submission.reply_text(locale("sub_no", "message", locale=submission.from_user.language_code), quote=True)
await clb.answer(text=locale("sub_no", "callback", locale=user_locale).format(fullclb[2]), show_alert=True)
edited_markup = [[InlineKeyboardButton(text=str(locale("declined", "button", locale=user_locale)), callback_data="nothing")], clb.message.reply_markup.inline_keyboard[1]] if len(clb.message.reply_markup.inline_keyboard) > 1 else [[InlineKeyboardButton(text=str(locale("declined", "button", locale=user_locale)), callback_data="nothing")]]
await clb.message.edit_reply_markup(reply_markup=InlineKeyboardMarkup(edited_markup))
await submission.reply_text(
locale("sub_no", "message", locale=submission.from_user.language_code),
quote=True,
)
await clb.answer(
text=locale("sub_no", "callback", locale=user_locale).format(fullclb[2]),
show_alert=True,
)
edited_markup = (
[
[
InlineKeyboardButton(
text=str(locale("declined", "button", locale=user_locale)),
callback_data="nothing",
)
],
clb.message.reply_markup.inline_keyboard[1],
]
if len(clb.message.reply_markup.inline_keyboard) > 1
else [
[
InlineKeyboardButton(
text=str(locale("declined", "button", locale=user_locale)),
callback_data="nothing",
)
]
]
)
await clb.message.edit_reply_markup(
reply_markup=InlineKeyboardMarkup(edited_markup)
)
@app.on_callback_query(filters.regex("sub_block_[\s\S]*"))
async def callback_query_block(app: PosterClient, clb: CallbackQuery):
fullclb = str(clb.data).split("_")
user_locale = clb.from_user.language_code
await app.send_message(int(fullclb[2]), locale("sub_blocked", "message", locale=configGet("locale")))
await app.send_message(
int(fullclb[2]), locale("sub_blocked", "message", locale=configGet("locale"))
)
PosterUser(int(fullclb[2])).block()
await clb.answer(text=locale("sub_block", "callback", locale=user_locale).format(fullclb[2]), show_alert=True)
await clb.answer(
text=locale("sub_block", "callback", locale=user_locale).format(fullclb[2]),
show_alert=True,
)
edited_markup = [clb.message.reply_markup.inline_keyboard[0], [InlineKeyboardButton(text=str(locale("sub_unblock", "button", locale=user_locale)), callback_data=f"sub_unblock_{fullclb[2]}")]]
await clb.message.edit_reply_markup(reply_markup=InlineKeyboardMarkup(edited_markup))
edited_markup = [
clb.message.reply_markup.inline_keyboard[0],
[
InlineKeyboardButton(
text=str(locale("sub_unblock", "button", locale=user_locale)),
callback_data=f"sub_unblock_{fullclb[2]}",
)
],
]
await clb.message.edit_reply_markup(
reply_markup=InlineKeyboardMarkup(edited_markup)
)
@app.on_callback_query(filters.regex("sub_unblock_[\s\S]*"))
@app.on_callback_query(filters.regex("sub_unblock_[\s\S]*"))
async def callback_query_unblock(app: PosterClient, clb: CallbackQuery):
fullclb = str(clb.data).split("_")
user_locale = clb.from_user.language_code
await app.send_message(int(fullclb[2]), locale("sub_unblocked", "message", locale=configGet("locale")))
await app.send_message(
int(fullclb[2]), locale("sub_unblocked", "message", locale=configGet("locale"))
)
PosterUser(int(fullclb[2])).unblock()
await clb.answer(text=locale("sub_unblock", "callback", locale=user_locale).format(fullclb[2]), show_alert=True)
await clb.answer(
text=locale("sub_unblock", "callback", locale=user_locale).format(fullclb[2]),
show_alert=True,
)
edited_markup = [clb.message.reply_markup.inline_keyboard[0], [InlineKeyboardButton(text=str(locale("sub_block", "button", locale=user_locale)), callback_data=f"sub_block_{fullclb[2]}")]]
await clb.message.edit_reply_markup(reply_markup=InlineKeyboardMarkup(edited_markup))
edited_markup = [
clb.message.reply_markup.inline_keyboard[0],
[
InlineKeyboardButton(
text=str(locale("sub_block", "button", locale=user_locale)),
callback_data=f"sub_block_{fullclb[2]}",
)
],
]
await clb.message.edit_reply_markup(
reply_markup=InlineKeyboardMarkup(edited_markup)
)