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/modules/callbacks/submission.py

61 lines
2.9 KiB
Python
Raw Normal View History

2023-01-10 13:52:44 +02:00
from os import sep
from pathlib import Path
from pyrogram import filters
from pyrogram.client import Client
from pyrogram.types import CallbackQuery
from modules.utils import jsonLoad, jsonSave, configGet, locale
from modules.submissions import subBlock, subUnblock
from modules.app import app
2023-01-10 14:06:24 +02:00
2023-01-10 13:52:44 +02:00
@app.on_callback_query(filters.regex("sub_yes_[\s\S]*_[\s\S]*"))
2023-01-10 14:06:24 +02:00
async def callback_query_yes(app: Client, clb: CallbackQuery):
2023-01-10 13:52:44 +02:00
fullclb = clb.data.split("_")
user_locale = clb.from_user.language_code
try:
2023-01-10 14:06:24 +02:00
submission = await app.get_messages(int(fullclb[2]), int(fullclb[3]))
2023-01-10 13:52:44 +02:00
except:
2023-01-10 14:06:24 +02:00
await clb.answer(text=locale("sub_msg_unavail", "message", locale=user_locale), show_alert=True)
2023-01-10 13:52:44 +02:00
return
try:
2023-01-10 14:06:24 +02:00
media = await app.download_media(submission, file_name=configGet("queue", "locations")+sep)
2023-01-10 13:52:44 +02:00
if clb.data.endswith("_caption"):
index = jsonLoad(configGet("index", "locations"))
index["captions"][Path(media).name] = submission.caption
jsonSave(index, configGet("index", "locations"))
except:
2023-01-10 14:06:24 +02:00
await clb.answer(text=locale("sub_media_unavail", "message", locale=user_locale), show_alert=True)
2023-01-10 13:52:44 +02:00
return
2023-01-10 14:06:24 +02:00
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)
2023-01-10 13:52:44 +02:00
@app.on_callback_query(filters.regex("sub_no_[\s\S]*_[\s\S]*"))
2023-01-10 14:06:24 +02:00
async def callback_query_no(app: Client, clb: CallbackQuery):
2023-01-10 13:52:44 +02:00
fullclb = clb.data.split("_")
user_locale = clb.from_user.language_code
try:
2023-01-10 14:06:24 +02:00
submission = await app.get_messages(int(fullclb[2]), int(fullclb[3]))
2023-01-10 13:52:44 +02:00
except:
2023-01-10 14:06:24 +02:00
await clb.answer(text=locale("sub_msg_unavail", "message", locale=user_locale), show_alert=True)
2023-01-10 13:52:44 +02:00
return
2023-01-10 14:06:24 +02:00
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)
2023-01-10 13:52:44 +02:00
@app.on_callback_query(filters.regex("sub_block_[\s\S]*"))
2023-01-10 14:06:24 +02:00
async def callback_query_block(app: Client, clb: CallbackQuery):
2023-01-10 13:52:44 +02:00
fullclb = clb.data.split("_")
user_locale = clb.from_user.language_code
2023-01-10 14:06:24 +02:00
await app.send_message(int(fullclb[2]), locale("sub_msg_unavail", "message", locale=configGet("locale")))
2023-01-10 13:52:44 +02:00
subBlock(int(fullclb[2]))
2023-01-10 14:06:24 +02:00
await clb.answer(text=locale("sub_block", "callback", locale=user_locale).format(fullclb[2]), show_alert=True)
2023-01-10 13:52:44 +02:00
@app.on_callback_query(filters.regex("sub_unblock_[\s\S]*"))
2023-01-10 14:06:24 +02:00
async def callback_query_unblock(app: Client, clb: CallbackQuery):
2023-01-10 13:52:44 +02:00
fullclb = clb.data.split("_")
user_locale = clb.from_user.language_code
2023-01-10 14:06:24 +02:00
await app.send_message(int(fullclb[2]), locale("sub_msg_unavail", "message", locale=configGet("locale")))
2023-01-10 13:52:44 +02:00
subUnblock(int(fullclb[2]))
2023-01-10 14:06:24 +02:00
await clb.answer(text=locale("sub_unblock", "callback", locale=user_locale).format(fullclb[2]), show_alert=True)