From 399fc5050d479b8a756b674ed66f7fa3036bf8ea Mon Sep 17 00:00:00 2001 From: profitroll Date: Mon, 20 Mar 2023 14:50:57 +0100 Subject: [PATCH] Updated user messages --- locale/en.json | 17 ++++++++-- locale/uk.json | 17 ++++++++-- plugins/commands/photos.py | 65 ++++++++++++++++++++++++++++++-------- 3 files changed, 79 insertions(+), 20 deletions(-) diff --git a/locale/en.json b/locale/en.json index d673070..bb0762b 100644 --- a/locale/en.json +++ b/locale/en.json @@ -40,9 +40,21 @@ "post_low": "Low amount of content: `There are only {0} files left in the queue.`", "api_creds_invalid": "Could not authorize API access. Please check whether provided in config file are valid and update them if they're not.", "sub_wip": "Post submission is now WIP. It will be available again in a few days. Thank you for your patience.", - "sub_duplicates_found": "__TO_BE_ADDED__", "sub_error": "⚠️ Could not upload this image due to bot error. Admins are advised.", - "sub_error_admin": "User {0} could not submit photo without additional confirmation due to:\n```\n{1}\n```" + "sub_error_admin": "User {0} could not submit photo without additional confirmation due to:\n```\n{1}\n```", + "import_request": "Alright, please send me a zip archive with your media to be imported. Use /cancel if you want to abort this operation.", + "import_ignored": "No response, aborting import.", + "import_abort": "Import aborted.", + "import_invalid_media": "File to import must be a zip archive. Aborting.", + "import_invalid_mime": "Provided file is not supported. Please send `application/zip`. Aborting.", + "import_too_big": "You archive is `{0} GiB` big, but system has only `{1} GiB` free. Unpacking may take even more space. Aborting.", + "import_downloading": "Downloading archive...", + "import_unpacking": "Unpacking archive...", + "import_unpack_error": "Could not unpack the archive\n\nException: {0}\n\nTraceback:\n```python\n{1}\n```", + "import_uploading": "Uploading archive contents...", + "import_upload_error_duplicate": "Could not upload `{0}` because there're duplicates on server.", + "import_upload_error_other": "Could not upload `{0}`. Probably disallowed filetype.", + "import_finished": "Import finished." }, "button": { "sub_yes": "✅ Accept", @@ -62,7 +74,6 @@ "sub_msg_unavail": "Submission message no longer exist", "sub_media_unavail": "Could not download submission", "sub_done": "You've already decided what to do with submission", - "sub_upload_failed": "__TO_BE_ADDED__", "sub_duplicates_found": "There're duplicates in bot's database", "nothing": "🏁 This action is already finished" }, diff --git a/locale/uk.json b/locale/uk.json index 638d495..f41ba8e 100644 --- a/locale/uk.json +++ b/locale/uk.json @@ -40,9 +40,21 @@ "post_low": "Мала кількість контенту: `Залишилось всього {0} файлів в черзі.`", "api_creds_invalid": "Не вдалося авторизувати запит до API. Будь ласка, перевірте чи дані авторизації в конфігураційному файлі вірні та оновіть їх, якщо це не так.", "sub_wip": "Подання постів зараз знаходиться у розробці. Він буде знову доступний через кілька днів. Дякуємо за ваше терпіння.", - "sub_duplicates_found": "__TO_BE_ADDED__", "sub_error": "⚠️ Не вдалось завантажити фото через помилку бота. Адміністрацію повідомлено.", - "sub_error_admin": "Користувач {0} не зміг надіслати фото без додаткової перевірки через помилку:\n```\n{1}\n```" + "sub_error_admin": "Користувач {0} не зміг надіслати фото без додаткової перевірки через помилку:\n```\n{1}\n```", + "import_request": "Гаразд, будь ласка, надішліть zip-архів з медіа для імпортування. Використовуйте /cancel, якщо ви хочете перервати цю операцію.", + "import_ignored": "Немає відповіді, перериваємо імпорт.", + "import_abort": "Імпорт перервано.", + "import_invalid_media": "Файл для імпорту має бути zip-архівом. Перериваємо.", + "import_invalid_mime": "Наданий файл не підтримується. Будь ласка, надішліть `application/zip`. Перервано.", + "import_too_big": "Ваш архів має розмір `{0} GiB`, але система має лише `{1} GiB` вільних. Розпакування може зайняти значно більше місця. Перервано.", + "import_downloading": "Завантажуємо архів...", + "import_unpacking": "Розпаковуємо архів...", + "import_unpack_error": "Не вдалося розпакувати архів\n\nПомилка: {0}\n\nTraceback:\n```python\n{1}\n```", + "import_uploading": "Завантажуємо вміст архіву...", + "import_upload_error_duplicate": "Не вдалося завантажити `{0}`, оскільки на сервері є дублікати.", + "import_upload_error_other": "Не вдалося завантажити `{0}`. Ймовірно, заборонений тип файлу.", + "import_finished": "Імпорт завершено." }, "button": { "sub_yes": "✅ Прийняти", @@ -62,7 +74,6 @@ "sub_msg_unavail": "Повідомлення більше не існує", "sub_media_unavail": "Не вдалося завантажити подання", "sub_done": "Ви вже обрали що зробити з цим поданням", - "sub_upload_failed": "__TO_BE_ADDED__", "sub_duplicates_found": "Знайдено дублікати в базі даних бота", "nothing": "🏁 Цю дію вже було завершено" }, diff --git a/plugins/commands/photos.py b/plugins/commands/photos.py index 9c38d2a..0737093 100644 --- a/plugins/commands/photos.py +++ b/plugins/commands/photos.py @@ -14,7 +14,7 @@ from classes.poster_client import PosterClient from modules.api_client import upload_pic from modules.app import app, users_with_context from modules.logger import logWrite -from modules.utils import configGet, extract_and_save +from modules.utils import configGet, extract_and_save, locale @app.on_message(~filters.scheduled & filters.command(["import"], prefixes=["", "/"])) @@ -26,30 +26,47 @@ async def cmd_import(app: PosterClient, msg: Message): else: return await msg.reply_text( - f"Alright, please send me a zip archive with your media to be imported. Use /cancel if you want to abort this operation." + locale("import_request", "message", locale=msg.from_user.language_code) ) 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("No response, aborting import.", quote=True) + await msg.reply_text( + locale("import_ignored", "message", locale=msg.from_user.language_code), + quote=True, + ) return if answer.text == "/cancel": - await answer.reply_text("Okay, aborting.") + await answer.reply_text( + locale("import_abort", "message", locale=msg.from_user.language_code) + ) return if answer.document is None: await answer.reply_text( - "File to import must be a zip archive. Aborting.", quote=True + locale( + "import_invalid_media", + "message", + locale=msg.from_user.language_code, + ), + quote=True, ) return if answer.document.mime_type != "application/zip": await answer.reply_text( - "Provided file is not supported. Please send `application/zip`. Aborting.", + locale( + "import_invalid_mime", "message", locale=msg.from_user.language_code + ), quote=True, ) return if disk_usage(getcwd())[2] < (answer.document.file_size) * 3: await msg.reply_text( - f"You archive is `{answer.document.file_size//(2**30)} GiB` big, but system has only `{disk_usage(getcwd())[2]//(2**30)} GiB` free. Unpacking may take even more space. Aborting." + locale( + "import_too_big", "message", locale=msg.from_user.language_code + ).format( + answer.document.file_size // (2**30), + disk_usage(getcwd())[2] // (2**30), + ) ) return tmp_dir = str(uuid4()) @@ -58,9 +75,14 @@ async def cmd_import(app: PosterClient, msg: Message): ) makedirs(path.join(configGet("tmp", "locations"), tmp_dir), exist_ok=True) tmp_path = path.join(configGet("tmp", "locations"), answer.document.file_id) - downloading = await answer.reply_text("Okay, downloading...", quote=True) + downloading = await answer.reply_text( + locale("import_downloading", "message", locale=msg.from_user.language_code), + quote=True, + ) await app.download_media(answer, file_name=tmp_path) - await downloading.edit("Downloaded, unpacking...") + await downloading.edit( + locale("import_unpacking", "message", locale=msg.from_user.language_code) + ) try: with ZipFile(tmp_path, "r") as handle: tasks = [ @@ -75,11 +97,15 @@ async def cmd_import(app: PosterClient, msg: Message): f"Could not import '{answer.document.file_name}' due to {exp}: {format_exc}" ) await answer.reply_text( - f"Could not unpack the archive\n\nException: {exp}\n\nTraceback:\n```python\n{format_exc}\n```" + locale( + "import_unpack_error", "message", locale=msg.from_user.language_code + ).format(exp, format_exc()) ) return logWrite(f"Downloaded '{answer.document.file_name}' - awaiting upload") - await downloading.edit("Unpacked, uploading...") + await downloading.edit( + locale("import_uploading", "message", locale=msg.from_user.language_code) + ) remove(tmp_path) for filename in iglob( @@ -96,12 +122,20 @@ async def cmd_import(app: PosterClient, msg: Message): ) if len(uploaded[1]) > 0: await msg.reply_text( - f"Could not upload `{path.basename(filename)}` because there're duplicates on server.", + locale( + "import_upload_error_duplicate", + "message", + locale=msg.from_user.language_code, + ).format(path.basename(filename)), disable_notification=True, ) else: await msg.reply_text( - f"Could not upload `{path.basename(filename)}`. Probably disallowed filetype", + locale( + "import_upload_error_other", + "message", + locale=msg.from_user.language_code, + ).format(path.basename(filename)), disable_notification=True, ) else: @@ -116,7 +150,10 @@ async def cmd_import(app: PosterClient, msg: Message): debug=True, ) rmtree(path.join(configGet("tmp", "locations"), tmp_dir), ignore_errors=True) - await answer.reply_text("Done.", quote=True) + await answer.reply_text( + locale("import_finished", "message", locale=msg.from_user.language_code), + quote=True, + ) return