/remove command fixed

This commit is contained in:
2023-06-28 08:53:15 +02:00
parent 97b3aa1505
commit e06cb4b377
4 changed files with 78 additions and 4 deletions

View File

@@ -13,7 +13,12 @@ from convopyro import listen_message
from photosapi_client.errors import UnexpectedStatus
from pyrogram import filters
from pyrogram.client import Client
from pyrogram.types import Message
from pyrogram.types import (
KeyboardButton,
Message,
ReplyKeyboardMarkup,
ReplyKeyboardRemove,
)
from ujson import loads
from classes.pyroclient import PyroClient
@@ -23,6 +28,8 @@ from modules.api_client import (
client,
photo_delete,
photo_upload,
video_delete,
video_upload,
)
from modules.utils import USERS_WITH_CONTEXT, extract_and_save
@@ -155,6 +162,7 @@ async def cmd_import(app: PyroClient, msg: Message):
photo_bytes = BytesIO(fh.read())
try:
# VIDEO SUPPORT IS PLANNED HERE TOO
uploaded = await photo_upload(
app.config["posting"]["api"]["album"],
client=client,
@@ -273,7 +281,62 @@ async def cmd_remove(app: PyroClient, msg: Message):
)
return
response = await photo_delete(id=answer.text, client=client)
await msg.reply_text(
app._("remove_kind", "message", locale=msg.from_user.language_code),
reply_markup=ReplyKeyboardMarkup(
[
[
KeyboardButton(
app._("photo", "button", locale=msg.from_user.language_code)
),
KeyboardButton(
app._("video", "button", locale=msg.from_user.language_code)
),
]
],
resize_keyboard=True,
one_time_keyboard=True,
),
)
USERS_WITH_CONTEXT.append(msg.from_user.id)
answer = await listen_message(app, msg.chat.id, timeout=600)
USERS_WITH_CONTEXT.remove(msg.from_user.id)
if answer is None:
await msg.reply_text(
app._("remove_ignored", "message", locale=msg.from_user.language_code),
quote=True,
reply_markup=ReplyKeyboardRemove(),
)
return
if answer.text == "/cancel":
await answer.reply_text(
app._("remove_abort", "message", locale=msg.from_user.language_code),
reply_markup=ReplyKeyboardRemove(),
)
return
if answer.text in app.in_all_locales("photo", "button"):
func = photo_delete
elif answer.text in app.in_all_locales("video", "button"):
func = video_delete
else:
await answer.reply_text(
app._(
"remove_unknown", "message", locale=msg.from_user.language_code
).format(
app._("photo", "button", locale=msg.from_user.language_code),
app._("video", "button", locale=msg.from_user.language_code),
),
reply_markup=ReplyKeyboardRemove(),
)
return
response = await func(id=answer.text, client=client)
if response:
logger.info(