diff --git a/config.json b/config.json index 66d148d..c866569 100644 --- a/config.json +++ b/config.json @@ -21,6 +21,7 @@ "index": "data/index.json", "submit": "data/submit.json", "blocked": "data/blocked.json", + "captions": "data/captions.json", "locale": "locale" }, "posting": { @@ -38,7 +39,8 @@ "mp4", "avi", "mkv", - "webm" + "webm", + "mov" ] }, "time": [ @@ -58,7 +60,15 @@ "link": null }, "submission": { - "timeout": 30 + "timeout": 30, + "file_size": 5242880, + "mime_types": [ + "image/png", + "image/gif", + "image/jpeg", + "video/mp4", + "video/quicktime" + ] }, "commands": [ "start", diff --git a/data/captions.json b/data/captions.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/data/captions.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/locale/en.json b/locale/en.json index b2c423f..102464f 100644 --- a/locale/en.json +++ b/locale/en.json @@ -18,11 +18,13 @@ "sub_by": "\n\nSubmitted by:", "sub_sent": "Media has been submitted.\nWe'll notify you whether it will be accepted or not soon.", "sub_cooldown": "You can only submit 1 media per {0} seconds", + "mime_not_allowed": "File type not allowed. Please, consider using one of these: {0}", "post_exception": "Could not send content due to `{exp}`\n\nTraceback:\n```{0}```", "post_empty": "Could not send content: `Queue folder is empty or contains only unsupported or already sent files.`" }, "button": { "sub_yes": "✅ Accept", + "sub_yes_caption": "✅ Accept + 📝", "sub_no": "❌ Deny", "sub_block": "☠️ Block sender", "sub_unblock": "🏳️ Unblock sender", diff --git a/locale/uk.json b/locale/uk.json index 5f8a8b1..4e931d7 100644 --- a/locale/uk.json +++ b/locale/uk.json @@ -18,11 +18,13 @@ "sub_by": "\n\nПредставлено:", "sub_sent": "Медіа-файл надіслано.\nСкоро ми повідомимо вас, чи буде його прийнято.", "sub_cooldown": "Ви можете надсилати лише 1 медіафайл на {0} секунд", + "mime_not_allowed": "Тип файлу не дозволений. Розгляньте можливість використання одного з цих: {0}", "post_exception": "Не вдалося надіслати контент через `{exp}`\n\nTraceback:\n```{0}```", "post_empty": "Не вдалося надіслати контент: «Папка черги порожня або містить лише непідтримувані або вже надіслані файли»." }, "button": { "sub_yes": "✅ Прийняти", + "sub_yes_caption": "✅ Прийняти + 📝", "sub_no": "❌ Відхилити", "sub_block": "☠️ Заблокувати відправника", "sub_unblock": "🏳️ Розблокувати відправника", diff --git a/main.py b/main.py index 39d2f71..d03479f 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,7 @@ import sys from threading import Thread import time import traceback +from pathlib import Path from modules.logging import logWrite from modules.utils import configGet, jsonLoad, jsonSave, killProc, locale @@ -197,16 +198,40 @@ def subUnblock(user): blocked.remove(user) jsonSave(blocked, configGet("blocked", "locations")) -@app.on_message(~ filters.scheduled & filters.photo | filters.video | filters.animation) +@app.on_message(~ filters.scheduled & filters.photo | filters.video | filters.animation | filters.document) def get_submission(_, msg): if msg.from_user.id not in jsonLoad(configGet("blocked", "locations")): user_locale = msg.from_user.language_code if not subLimited(msg.from_user): + if msg.document != None: + if msg.document.mime_type not in configGet("mime_types", "submission"): + msg.reply_text(locale("mime_not_allowed", "message", locale=user_locale), quote=True) + return + + buttons = [ + [ + InlineKeyboardButton(text=locale("sub_yes", "button", locale=configGet("locale")), callback_data=f"sub_yes_{msg.from_user.id}_{msg.id}") + ], + [ + InlineKeyboardButton(text=locale("sub_block", "button", locale=configGet("locale")), callback_data=f"sub_block_{msg.from_user.id}") + ], + [ + InlineKeyboardButton(text=locale("sub_unblock", "button", locale=configGet("locale")), callback_data=f"sub_unblock_{msg.from_user.id}") + ] + ] + if msg.caption != None: caption = str(msg.caption) + buttons[0].append( + InlineKeyboardButton(text=locale("sub_yes_caption", "button", locale=configGet("locale")), callback_data=f"sub_yes_{msg.from_user.id}_{msg.id}_caption"), + InlineKeyboardButton(text=locale("sub_no", "button", locale=configGet("locale")), callback_data=f"sub_no_{msg.from_user.id}_{msg.id}") + ) else: caption = "" + buttons[0].append( + InlineKeyboardButton(text=locale("sub_no", "button", locale=configGet("locale")), callback_data=f"sub_no_{msg.from_user.id}_{msg.id}") + ) caption += locale("sub_by", "message", locale=locale(configGet("locale"))) @@ -219,19 +244,7 @@ def get_submission(_, msg): if msg.from_user.phone_number != None: caption += f" ({msg.from_user.phone_number})" - msg.copy(configGet("admin", "reports"), caption=caption, reply_markup=InlineKeyboardMarkup([ - [ - InlineKeyboardButton(text=locale("sub_yes", "button", locale=configGet("locale")), callback_data=f"sub_yes_{msg.from_user.id}_{msg.id}"), - InlineKeyboardButton(text=locale("sub_no", "button", locale=configGet("locale")), callback_data=f"sub_no_{msg.from_user.id}_{msg.id}") - ], - [ - InlineKeyboardButton(text=locale("sub_block", "button", locale=configGet("locale")), callback_data=f"sub_block_{msg.from_user.id}") - ], - [ - InlineKeyboardButton(text=locale("sub_unblock", "button", locale=configGet("locale")), callback_data=f"sub_unblock_{msg.from_user.id}") - ] - ] - )) + msg.copy(configGet("admin", "reports"), caption=caption, reply_markup=InlineKeyboardMarkup(buttons)) msg.reply_text(locale("sub_sent", "message", locale=user_locale), quote=True) subLimit(msg.from_user) else: @@ -247,7 +260,10 @@ def callback_query_yes(app, clb): # type: ignore clb.answer(text=locale("sub_msg_unavail", "message", locale=user_locale), show_alert=True) return try: - app.download_media(submission, file_name=configGet("queue", "locations")+os.sep) + media = app.download_media(submission, file_name=configGet("queue", "locations")+os.sep) + if clb.data.endswith("_caption"): + captions = jsonLoad(configGet("captions", "locations")) + captions[Path(media).name] = submission.caption except: clb.answer(text=locale("sub_media_unavail", "message", locale=user_locale), show_alert=True) return