dev (#19)
* Config file changes * Commands `/remove`, `/import` and `/export` Co-authored-by: profitroll <vozhd.kk@gmail.com> Co-authored-by: Profitroll <47523801+profitrollgame@users.noreply.github.com> Co-authored-by: Renovate <renovate@git.end-play.xyz> Reviewed-on: #19
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
from modules.app import app
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import CallbackQuery
|
||||
from pyrogram.client import Client
|
||||
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: Client, clb: CallbackQuery):
|
||||
await clb.answer(text=locale("nothing", "callback", locale=clb.from_user))
|
||||
# ==============================================================================================================================
|
||||
async def callback_query_nothing(app: PosterClient, clb: CallbackQuery):
|
||||
await clb.answer(
|
||||
text=locale("nothing", "callback", locale=clb.from_user.language_code)
|
||||
)
|
||||
|
29
plugins/callbacks/shutdown.py
Normal file
29
plugins/callbacks/shutdown.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from os import getpid, makedirs, path
|
||||
from time import time
|
||||
from modules.app import app
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import CallbackQuery
|
||||
from classes.poster_client import PosterClient
|
||||
from modules.scheduler import scheduler
|
||||
from modules.logger import logWrite
|
||||
from modules.utils import configGet, jsonSave, locale
|
||||
|
||||
|
||||
@app.on_callback_query(filters.regex("shutdown"))
|
||||
async def callback_query_nothing(app: PosterClient, clb: CallbackQuery):
|
||||
if clb.from_user.id in app.admins:
|
||||
pid = getpid()
|
||||
logWrite(f"Shutting down bot with pid {pid}")
|
||||
await clb.answer()
|
||||
await clb.message.reply_text(
|
||||
locale("shutdown", "message", locale=clb.from_user.language_code).format(
|
||||
pid
|
||||
),
|
||||
)
|
||||
scheduler.shutdown()
|
||||
makedirs(configGet("cache", "locations"), exist_ok=True)
|
||||
jsonSave(
|
||||
{"timestamp": time()},
|
||||
path.join(configGet("cache", "locations"), "shutdown_time"),
|
||||
)
|
||||
exit()
|
@@ -1,116 +1,274 @@
|
||||
from os import path, sep
|
||||
from pathlib import Path
|
||||
|
||||
from os import path
|
||||
from shutil import rmtree
|
||||
from pyrogram import filters
|
||||
from pyrogram.client import Client
|
||||
from pyrogram.types import CallbackQuery
|
||||
from pyrogram.types import CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton
|
||||
from classes.exceptions import SubmissionDuplicatesError, SubmissionUnavailableError
|
||||
from classes.poster_client import PosterClient
|
||||
from classes.user import PosterUser
|
||||
|
||||
from modules.api_client import upload_pic
|
||||
from modules.app import app
|
||||
from modules.submissions import subBlock, subUnblock
|
||||
from modules.utils import configGet, jsonLoad, jsonSave, locale
|
||||
from modules.logger import logWrite
|
||||
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):
|
||||
|
||||
fullclb = clb.data.split("_")
|
||||
async def callback_query_yes(app: PosterClient, clb: CallbackQuery):
|
||||
fullclb = str(clb.data).split("_")
|
||||
user_locale = clb.from_user.language_code
|
||||
|
||||
# Check if submission is in DB and really exists
|
||||
|
||||
# Upload the file to the API server
|
||||
|
||||
# Modify submission in DB to state that it's accepted (or so called "done")
|
||||
|
||||
# Change keyboard to a completed variant
|
||||
|
||||
# Send replies to both user and admin about accepting the application
|
||||
|
||||
db_entry = col_submitted.find_one({"_id": ObjectId(fullclb[2])})
|
||||
|
||||
if db_entry is None:
|
||||
await clb.answer(text=locale("sub_msg_unavail", "message", locale=user_locale), show_alert=True)
|
||||
return
|
||||
else:
|
||||
if db_entry["tmp"]["uuid"] is not None:
|
||||
if not path.exists(path.join(configGet("data", "locations"), "submissions", db_entry["tmp"]["uuid"], db_entry["tmp"]["file"])):
|
||||
await clb.answer(text=locale("sub_msg_unavail", "message", locale=user_locale), show_alert=True)
|
||||
return
|
||||
else:
|
||||
try:
|
||||
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)
|
||||
return
|
||||
|
||||
try:
|
||||
if configGet("api_based", "mode") is True:
|
||||
media = await app.download_media(submission, file_name=configGet("tmp", "locations")+sep)
|
||||
upload = upload_pic(media)
|
||||
if upload[0] is False:
|
||||
await clb.answer(text=locale("sub_media_failed", "message", locale=user_locale), show_alert=True)
|
||||
elif len(upload[1]) > 0:
|
||||
await clb.answer(text=locale("sub_media_duplicates", "message", locale=user_locale))
|
||||
await clb.message.reply_text(locale("sub_media_duplicates_list", "message", locale=user_locale).format("\n • ".join(upload[1])))
|
||||
else:
|
||||
if clb.data.endswith("_caption"):
|
||||
index = jsonLoad(configGet("index", "locations"))
|
||||
index["captions"][Path(media).name] = submission.caption
|
||||
jsonSave(index, configGet("index", "locations"))
|
||||
else:
|
||||
media = await app.download_media(submission, file_name=configGet("queue", "locations")+sep)
|
||||
if clb.data.endswith("_caption"):
|
||||
index = jsonLoad(configGet("index", "locations"))
|
||||
index["captions"][Path(media).name] = submission.caption
|
||||
jsonSave(index, configGet("index", "locations"))
|
||||
except:
|
||||
await clb.answer(text=locale("sub_media_unavail", "message", locale=user_locale), show_alert=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)
|
||||
),
|
||||
quote=True,
|
||||
)
|
||||
logWrite(
|
||||
locale(
|
||||
"submission_duplicate",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(
|
||||
fullclb[2],
|
||||
str(exp.duplicates),
|
||||
),
|
||||
),
|
||||
debug=True,
|
||||
)
|
||||
return
|
||||
await submission.reply_text(locale("sub_yes", "message", locale=submission.from_user.language_code), quote=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")), callback_data="nothing")]]
|
||||
# await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||
if submission[0] is not None:
|
||||
await submission[0].reply_text(
|
||||
locale("sub_yes", "message", locale=submission[0].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,
|
||||
)
|
||||
|
||||
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",
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
|
||||
if configGet("send_uploaded_id", "submission"):
|
||||
await clb.message.edit_caption(
|
||||
clb.message.caption + f"\n\nID: `{submission[1]}`"
|
||||
)
|
||||
|
||||
await clb.message.edit_reply_markup(
|
||||
reply_markup=InlineKeyboardMarkup(edited_markup)
|
||||
)
|
||||
|
||||
logWrite(
|
||||
locale(
|
||||
"submission_accepted",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(fullclb[2], submission[1]),
|
||||
),
|
||||
debug=True,
|
||||
)
|
||||
|
||||
# try:
|
||||
# if configGet("api_based", "mode") is True:
|
||||
# media = await app.download_media(submission, file_name=configGet("tmp", "locations")+sep)
|
||||
# upload = upload_pic(media)
|
||||
# if upload[0] is False:
|
||||
# await clb.answer(text=locale("sub_media_failed", "message", locale=user_locale), show_alert=True)
|
||||
# elif len(upload[1]) > 0:
|
||||
# await clb.answer(text=locale("sub_media_duplicates", "message", locale=user_locale))
|
||||
# await clb.message.reply_text(locale("sub_media_duplicates_list", "message", locale=user_locale).format("\n • ".join(upload[1])))
|
||||
# else:
|
||||
# if clb.data.endswith("_caption"):
|
||||
# index = jsonLoad(configGet("index", "locations"))
|
||||
# index["captions"][Path(media).name] = submission.caption
|
||||
# jsonSave(index, configGet("index", "locations"))
|
||||
# else:
|
||||
# media = await app.download_media(submission, file_name=configGet("queue", "locations")+sep)
|
||||
# if clb.data.endswith("_caption"):
|
||||
# index = jsonLoad(configGet("index", "locations"))
|
||||
# index["captions"][Path(media).name] = submission.caption
|
||||
# jsonSave(index, configGet("index", "locations"))
|
||||
# except:
|
||||
# await clb.answer(text=locale("sub_media_unavail", "message", locale=user_locale), show_alert=True)
|
||||
# return
|
||||
|
||||
|
||||
@app.on_callback_query(filters.regex("sub_no_[\s\S]*"))
|
||||
async def callback_query_no(app: Client, clb: CallbackQuery):
|
||||
fullclb = clb.data.split("_")
|
||||
async def callback_query_no(app: PosterClient, clb: CallbackQuery):
|
||||
fullclb = str(clb.data).split("_")
|
||||
user_locale = clb.from_user.language_code
|
||||
try:
|
||||
submission = await app.get_messages(int(fullclb[2]), int(fullclb[3]))
|
||||
except:
|
||||
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("accepted", "button")), callback_data="nothing")]]
|
||||
# await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||
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,
|
||||
)
|
||||
|
||||
try:
|
||||
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,
|
||||
)
|
||||
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)
|
||||
)
|
||||
logWrite(
|
||||
locale(
|
||||
"submission_rejected",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(fullclb[2]),
|
||||
),
|
||||
debug=True,
|
||||
)
|
||||
|
||||
|
||||
@app.on_callback_query(filters.regex("sub_block_[\s\S]*"))
|
||||
async def callback_query_block(app: Client, clb: CallbackQuery):
|
||||
fullclb = clb.data.split("_")
|
||||
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_msg_unavail", "message", locale=configGet("locale")))
|
||||
subBlock(int(fullclb[2]))
|
||||
await clb.answer(text=locale("sub_block", "callback", locale=user_locale).format(fullclb[2]), show_alert=True)
|
||||
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,
|
||||
)
|
||||
|
||||
# edited_markup = [[InlineKeyboardButton(text=str(locale("accepted", "button")), callback_data="nothing")]]
|
||||
# await clb.message.edit(text=clb.message.text, 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)
|
||||
)
|
||||
logWrite(
|
||||
locale(
|
||||
"user_blocked",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(fullclb[2]),
|
||||
),
|
||||
debug=True,
|
||||
)
|
||||
|
||||
|
||||
@app.on_callback_query(filters.regex("sub_unblock_[\s\S]*"))
|
||||
async def callback_query_unblock(app: Client, clb: CallbackQuery):
|
||||
fullclb = clb.data.split("_")
|
||||
@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_msg_unavail", "message", locale=configGet("locale")))
|
||||
subUnblock(int(fullclb[2]))
|
||||
await clb.answer(text=locale("sub_unblock", "callback", locale=user_locale).format(fullclb[2]), show_alert=True)
|
||||
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,
|
||||
)
|
||||
|
||||
# edited_markup = [[InlineKeyboardButton(text=str(locale("accepted", "button")), callback_data="nothing")]]
|
||||
# await clb.message.edit(text=clb.message.text, 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)
|
||||
)
|
||||
logWrite(
|
||||
locale(
|
||||
"user_unblocked",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(fullclb[2]),
|
||||
),
|
||||
debug=True,
|
||||
)
|
||||
|
Reference in New Issue
Block a user