Compare commits
39 Commits
v0.1
...
2387823151
Author | SHA1 | Date | |
---|---|---|---|
2387823151 | |||
88f8bb4a52 | |||
cf6c1f03d7 | |||
0a309a9f59 | |||
7810f3b7b9 | |||
7b2534012d | |||
6e8b47cf4b | |||
c27b1c5a5b | |||
c7228a006b | |||
64ae3fb047 | |||
|
056fc52353 | ||
|
8bafd0cb35 | ||
|
fd47217bad | ||
|
6b7b5c22f2 | ||
|
b3698cfa70 | ||
|
7607003f55 | ||
|
7918049f49 | ||
|
fcd59b7aca | ||
|
8c478072c6 | ||
|
b766d0c52c | ||
|
807e629ae7 | ||
|
87af9fd333 | ||
|
a54081a2ae | ||
|
664284a6f8 | ||
|
bd9917fb17 | ||
|
68ea087963 | ||
|
d1813856d9 | ||
|
cf204577e4 | ||
|
68c887999e | ||
|
642e17ee55 | ||
|
25af9b31f8 | ||
|
28fc359593 | ||
|
07203a9db9 | ||
|
663a7b0db8 | ||
|
0d2e9fa6ec | ||
|
c90e5eb697 | ||
|
f4359aa6cd | ||
4cd37be5dc | |||
05042f01c6 |
16
classes/exceptions.py
Normal file
16
classes/exceptions.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
class SubmissionUnavailableError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class SubmissionUploadError(Exception):
|
||||||
|
def __init__(self, file_path: str, status_code: int, content: Any) -> None:
|
||||||
|
self.status_code = status_code
|
||||||
|
self.content = content
|
||||||
|
super().__init__(f"Could not upload photo '{file_path}' due to HTTP {self.status_code}: {self.content}")
|
||||||
|
|
||||||
|
class SubmissionDuplicatesError(Exception):
|
||||||
|
def __init__(self, file_path: str, duplicates: list) -> None:
|
||||||
|
self.duplicates = duplicates
|
||||||
|
super().__init__(f"Found duplicates of a photo '{file_path}': {self.duplicates}")
|
66
classes/poster_client.py
Normal file
66
classes/poster_client.py
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
from os import path, remove, sep
|
||||||
|
from shutil import rmtree
|
||||||
|
from typing import Union
|
||||||
|
from pyrogram.client import Client
|
||||||
|
from pyrogram.types import Message
|
||||||
|
from classes.exceptions import SubmissionDuplicatesError, SubmissionUnavailableError
|
||||||
|
from modules.api_client import upload_pic
|
||||||
|
from modules.database import col_submitted
|
||||||
|
from bson import ObjectId
|
||||||
|
from modules.logger import logWrite
|
||||||
|
|
||||||
|
from modules.utils import configGet
|
||||||
|
|
||||||
|
class PosterClient(Client):
|
||||||
|
|
||||||
|
def __init__(self, name: str, **kwargs): # type: ignore
|
||||||
|
super().__init__(name, **kwargs)
|
||||||
|
self.owner = configGet("owner")
|
||||||
|
self.admins = configGet("admins")+[configGet("owner")]
|
||||||
|
|
||||||
|
async def submit_photo(self, id: str) -> Union[Message, None]:
|
||||||
|
|
||||||
|
db_entry = col_submitted.find_one({"_id": ObjectId(id)})
|
||||||
|
submission = None
|
||||||
|
|
||||||
|
if db_entry is None:
|
||||||
|
raise SubmissionUnavailableError()
|
||||||
|
else:
|
||||||
|
if db_entry["temp"]["uuid"] is not None:
|
||||||
|
if not path.exists(path.join(configGet("data", "locations"), "submissions", db_entry["temp"]["uuid"], db_entry["temp"]["file"])):
|
||||||
|
raise SubmissionUnavailableError()
|
||||||
|
else:
|
||||||
|
filepath = path.join(configGet("data", "locations"), "submissions", db_entry["temp"]["uuid"], db_entry["temp"]["file"])
|
||||||
|
try:
|
||||||
|
submission = await self.get_messages(db_entry["user"], db_entry["telegram"]["msg_id"])
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
submission = await self.get_messages(db_entry["user"], db_entry["telegram"]["msg_id"])
|
||||||
|
filepath = await self.download_media(submission, file_name=configGet("tmp", "locations")+sep)
|
||||||
|
except:
|
||||||
|
raise SubmissionUnavailableError()
|
||||||
|
|
||||||
|
response = await upload_pic(str(filepath), allow_duplicates=configGet("allow_duplicates", "submission"))
|
||||||
|
|
||||||
|
if len(response[1]) > 0:
|
||||||
|
raise SubmissionDuplicatesError(str(filepath), response[1])
|
||||||
|
|
||||||
|
col_submitted.find_one_and_update({"_id": ObjectId(id)}, {"$set": {"done": True}})
|
||||||
|
|
||||||
|
try:
|
||||||
|
if db_entry["temp"]["uuid"] is not None:
|
||||||
|
rmtree(path.join(configGet("data", "locations"), "submissions", db_entry["temp"]["uuid"]), ignore_errors=True)
|
||||||
|
else:
|
||||||
|
remove(str(filepath))
|
||||||
|
except (FileNotFoundError, NotADirectoryError):
|
||||||
|
logWrite(f"Could not delete '{filepath}' on submission accepted", debug=True)
|
||||||
|
|
||||||
|
return submission
|
||||||
|
|
||||||
|
async def ban_user(self, id: int) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
async def unban_user(self, id: int) -> None:
|
||||||
|
pass
|
45
classes/user.py
Normal file
45
classes/user.py
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
from modules.app import app
|
||||||
|
from datetime import datetime
|
||||||
|
from modules.database import col_banned, col_users
|
||||||
|
from modules.utils import configGet
|
||||||
|
|
||||||
|
class PosterUser():
|
||||||
|
|
||||||
|
def __init__(self, id: int):
|
||||||
|
self.id = id
|
||||||
|
|
||||||
|
def is_blocked(self) -> bool:
|
||||||
|
"""Check if user is banned from submitting content.
|
||||||
|
|
||||||
|
### Returns:
|
||||||
|
`bool`: Must be `True` if banned and `False` if not
|
||||||
|
"""
|
||||||
|
return False if col_banned.find_one({"user": self.id}) is None else True
|
||||||
|
|
||||||
|
def block(self) -> None:
|
||||||
|
"""Ban user from using command and submitting content."""
|
||||||
|
if col_banned.find_one({"user": self.id}) is None:
|
||||||
|
col_banned.insert_one({"user": self.id, "date": datetime.now()})
|
||||||
|
|
||||||
|
def unblock(self) -> None:
|
||||||
|
"""Allow user to use command and submit posts again."""
|
||||||
|
col_banned.find_one_and_delete({"user": self.id})
|
||||||
|
|
||||||
|
def is_limited(self) -> bool:
|
||||||
|
"""Check if user is on a cooldown after submitting something.
|
||||||
|
|
||||||
|
### Returns:
|
||||||
|
`bool`: Must be `True` if on the cooldown and `False` if not
|
||||||
|
"""
|
||||||
|
if self.id in app.admins:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
db_record = col_users.find_one({"user": self.id})
|
||||||
|
if db_record is None:
|
||||||
|
return False
|
||||||
|
return True if (datetime.now() - db_record["cooldown"]).total_seconds() < configGet("timeout", "submission") else False
|
||||||
|
|
||||||
|
def limit(self) -> None:
|
||||||
|
"""Restart user's cooldown. Used after post has been submitted."""
|
||||||
|
if col_users.find_one_and_update({"user": self.id}, {"$set": {"cooldown": datetime.now()}}) is None:
|
||||||
|
col_users.insert_one({"user": self.id, "cooldown": datetime.now()})
|
20
config.json
20
config.json
@@ -3,7 +3,8 @@
|
|||||||
"locale": "en",
|
"locale": "en",
|
||||||
"locale_log": "en",
|
"locale_log": "en",
|
||||||
"locale_fallback": "en",
|
"locale_fallback": "en",
|
||||||
"admin": 0,
|
"owner": 0,
|
||||||
|
"admins": [],
|
||||||
"bot": {
|
"bot": {
|
||||||
"api_id": 0,
|
"api_id": 0,
|
||||||
"api_hash": "",
|
"api_hash": "",
|
||||||
@@ -46,7 +47,14 @@
|
|||||||
"channel": 0,
|
"channel": 0,
|
||||||
"silent": false,
|
"silent": false,
|
||||||
"move_sent": false,
|
"move_sent": false,
|
||||||
"interval": 1,
|
"use_interval": false,
|
||||||
|
"interval": "1h30m",
|
||||||
|
"page_size": 300,
|
||||||
|
"submitted_caption": {
|
||||||
|
"enabled": true,
|
||||||
|
"ignore_admins": true,
|
||||||
|
"text": "#submitted"
|
||||||
|
},
|
||||||
"extensions": {
|
"extensions": {
|
||||||
"photo": [
|
"photo": [
|
||||||
"jpg",
|
"jpg",
|
||||||
@@ -74,6 +82,7 @@
|
|||||||
],
|
],
|
||||||
"api": {
|
"api": {
|
||||||
"address": "http://localhost:8054",
|
"address": "http://localhost:8054",
|
||||||
|
"address_external": "https://photos.domain.com",
|
||||||
"username": "",
|
"username": "",
|
||||||
"password": "",
|
"password": "",
|
||||||
"album": ""
|
"album": ""
|
||||||
@@ -88,6 +97,11 @@
|
|||||||
"timeout": 30,
|
"timeout": 30,
|
||||||
"file_size": 15728640,
|
"file_size": 15728640,
|
||||||
"tmp_size": 15728640,
|
"tmp_size": 15728640,
|
||||||
|
"allow_duplicates": false,
|
||||||
|
"require_confirmation": {
|
||||||
|
"users": true,
|
||||||
|
"admins": true
|
||||||
|
},
|
||||||
"mime_types": [
|
"mime_types": [
|
||||||
"image/png",
|
"image/png",
|
||||||
"image/gif",
|
"image/gif",
|
||||||
@@ -101,6 +115,8 @@
|
|||||||
"rules"
|
"rules"
|
||||||
],
|
],
|
||||||
"commands_admin": [
|
"commands_admin": [
|
||||||
|
"import",
|
||||||
|
"export",
|
||||||
"reboot"
|
"reboot"
|
||||||
]
|
]
|
||||||
}
|
}
|
@@ -5,15 +5,21 @@
|
|||||||
},
|
},
|
||||||
"commands_admin": {
|
"commands_admin": {
|
||||||
"forwards": "Check post forwards",
|
"forwards": "Check post forwards",
|
||||||
|
"import": "Submit .zip archive with photos",
|
||||||
|
"export": "Get .zip archive with all photos",
|
||||||
|
"remove": "Delete photo by its ID",
|
||||||
|
"purge": "Completely purge bot's queue",
|
||||||
"reboot": "Restart the bot"
|
"reboot": "Restart the bot"
|
||||||
},
|
},
|
||||||
"message": {
|
"message": {
|
||||||
"start": "Hi and welcome!\n\nYou can submit your pictures and videos here. We'll review and add them, if we like them. Make sure you send your stuff one at a time and have chosen media that corresponds to our rules.\n\nYou can also write something to us in the description field. We'll send it with the submission itself, if needed.\n\nAlso, make sure you follow the /rules of submission, otherwise your submission will be declined. In case of spam/abuse you may even be blocked.\n\nHave fun and happy submitting!",
|
"start": "Hi and welcome!\n\nYou can submit your pictures and videos here. We'll review and add them, if we like them. Make sure you send your stuff one at a time and have chosen media that corresponds to our rules.\n\nYou can also write something to us in the description field. We'll send it with the submission itself, if needed.\n\nAlso, make sure you follow the /rules of submission, otherwise your submission will be declined. In case of spam/abuse you may even be blocked.\n\nHave fun and happy submitting!",
|
||||||
"rules": "Photos submission rules:\n1. No porn, only erotics and aesthetics\n2. Nipples are semi-allowed, should be either veiled or barely visible\n3. Genitalia strictly prohibited, but labia prints on clothes or nice pubes/panties/butts - are fine",
|
"rules": "Photos submission rules:\n1. No porn, only erotics and aesthetics\n2. Nipples are semi-allowed, should be either veiled or barely visible\n3. Genitalia strictly prohibited, but labia prints on clothes or nice pubes/panties/butts - are fine\n4. Submitting russians is forbidden",
|
||||||
"shutdown": "Shutting down bot with pid `{0}`",
|
"shutdown": "Shutting down bot with pid `{0}`",
|
||||||
"startup": "Starting with pid `{0}`",
|
"startup": "Starting with pid `{0}`",
|
||||||
"sub_yes": "✅ Submission approved and accepted",
|
"sub_yes": "✅ Submission approved and accepted",
|
||||||
|
"sub_yes_auto": "✅ Submission automatically accepted",
|
||||||
"sub_no": "❌ Submission reviewed and declined",
|
"sub_no": "❌ Submission reviewed and declined",
|
||||||
|
"sub_dup": "⚠️ Submission automatically declined because database already contains this photo",
|
||||||
"sub_blocked": "You were blocked and you can't submit media anymore.",
|
"sub_blocked": "You were blocked and you can't submit media anymore.",
|
||||||
"sub_unblocked": "You were unblocked and you can now submit media.",
|
"sub_unblocked": "You were unblocked and you can now submit media.",
|
||||||
"sub_by": "\n\nSubmitted by:",
|
"sub_by": "\n\nSubmitted by:",
|
||||||
@@ -25,12 +31,15 @@
|
|||||||
"document_too_large": "File you've sent is too large. Please submit files not bigger than {0} MB",
|
"document_too_large": "File you've sent is too large. Please submit files not bigger than {0} MB",
|
||||||
"mime_not_allowed": "File type not allowed. Please, consider using one of these: {0}",
|
"mime_not_allowed": "File type not allowed. Please, consider using one of these: {0}",
|
||||||
"post_exception": "Could not send content due to `{0}`\n\nTraceback:\n```{1}```",
|
"post_exception": "Could not send content due to `{0}`\n\nTraceback:\n```{1}```",
|
||||||
"post_invalid_pic": "__TO_BE_ADDED__",
|
"post_invalid_pic": "⚠️ Error {0} while sending photo\n```python\n{1}\n```",
|
||||||
"api_queue_empty": "Could not send content: `Queue is empty or contains only unsupported files.`",
|
"api_queue_empty": "Could not send content: `Queue is empty or contains only unsupported files.`",
|
||||||
"api_queue_error": "__TO_BE_ADDED__",
|
"api_queue_error": "Could not get photo from API's queue. Check the log above or API's errors to get more info.",
|
||||||
"post_low": "Low amount of content: `There are only {0} files left in the queue.`",
|
"post_low": "Low amount of content: `There are only {0} files left in the queue.`",
|
||||||
"api_creds_invalid": "__TO_BE_ADDED__",
|
"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_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```"
|
||||||
},
|
},
|
||||||
"button": {
|
"button": {
|
||||||
"sub_yes": "✅ Accept",
|
"sub_yes": "✅ Accept",
|
||||||
@@ -49,7 +58,10 @@
|
|||||||
"sub_unblock": "User {0} has been unblocked",
|
"sub_unblock": "User {0} has been unblocked",
|
||||||
"sub_msg_unavail": "Submission message no longer exist",
|
"sub_msg_unavail": "Submission message no longer exist",
|
||||||
"sub_media_unavail": "Could not download submission",
|
"sub_media_unavail": "Could not download submission",
|
||||||
"sub_done": "You've already decided what to do with 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"
|
||||||
},
|
},
|
||||||
"console": {
|
"console": {
|
||||||
"shutdown": "Shutting down bot with pid {0}",
|
"shutdown": "Shutting down bot with pid {0}",
|
||||||
@@ -58,7 +70,7 @@
|
|||||||
"exception_occured": "Exception {0} happened on task execution",
|
"exception_occured": "Exception {0} happened on task execution",
|
||||||
"post_sent": "Sent {0} to {1} with caption {2} and silently {3}",
|
"post_sent": "Sent {0} to {1} with caption {2} and silently {3}",
|
||||||
"post_exception": "Could not send content due to {0}. Traceback: {1}",
|
"post_exception": "Could not send content due to {0}. Traceback: {1}",
|
||||||
"post_invalid_pic": "__TO_BE_ADDED__",
|
"post_invalid_pic": "Error while sending photo HTTP {0}: {1}",
|
||||||
"post_empty": "Could not send content due to queue empty or contains only forbidden extensions",
|
"post_empty": "Could not send content due to queue empty or contains only forbidden extensions",
|
||||||
"sub_mime_not_allowed": "Got submission from {0} but type of {1} which is not allowed",
|
"sub_mime_not_allowed": "Got submission from {0} but type of {1} which is not allowed",
|
||||||
"sub_document_too_large": "Got submission from {0} but but file is too large ({1} > {2})",
|
"sub_document_too_large": "Got submission from {0} but but file is too large ({1} > {2})",
|
||||||
|
@@ -5,15 +5,21 @@
|
|||||||
},
|
},
|
||||||
"commands_admin": {
|
"commands_admin": {
|
||||||
"forwards": "Переглянути репости",
|
"forwards": "Переглянути репости",
|
||||||
|
"import": "Надати боту .zip архів з фотографіями",
|
||||||
|
"export": "Отримати .zip архів з усіма фотографіями",
|
||||||
|
"remove": "Видалити фото за його ID",
|
||||||
|
"purge": "Повністю видалити всю чергу бота",
|
||||||
"reboot": "Перезапустити бота"
|
"reboot": "Перезапустити бота"
|
||||||
},
|
},
|
||||||
"message": {
|
"message": {
|
||||||
"start": "Привіт і ласкаво просимо!\n\nТут можна пропонувати свої фотографії та відео. Ми переглянемо та додамо їх, якщо вони нам сподобаються. Переконайтеся, що ви надсилаєте свої матеріали по одному та вибираєте медіа, які відповідають нашим правилам.\n\nВи також можете написати нам щось у полі опису. За потреби ми надішлемо це разом із самим фото.\n\nКрім того, переконайтеся, що ви дотримуєтеся /rules (правил) подання, інакше вашу пропозицію буде відхилено. У разі спаму/зловживань вас можуть навіть заблокувати.\n\nГарного дня та щасливого надсилання!",
|
"start": "Привіт і ласкаво просимо!\n\nТут можна пропонувати свої фотографії та відео. Ми переглянемо та додамо їх, якщо вони нам сподобаються. Переконайтеся, що ви надсилаєте свої матеріали по одному та вибираєте медіа, які відповідають нашим правилам.\n\nВи також можете написати нам щось у полі опису. За потреби ми надішлемо це разом із самим фото.\n\nКрім того, переконайтеся, що ви дотримуєтеся /rules (правил) подання, інакше вашу пропозицію буде відхилено. У разі спаму/зловживань вас можуть навіть заблокувати.\n\nГарного дня та щасливого надсилання!",
|
||||||
"rules": "Правила пропонування фото:\n1. Ніякого порно, тільки еротика та естетика\n2. Соски можна, але або завуальовані, або зовсім ледь помітні\n3. Геніталії суворо ні, а ось відбитки статевих губ на одязі або гарні лобочки/трусики/попки - без проблем",
|
"rules": "Правила пропонування фото:\n1. Ніякого порно, тільки еротика та естетика\n2. Соски можна, але або завуальовані, або зовсім ледь помітні\n3. Геніталії суворо ні, а ось відбитки статевих губ на одязі або гарні лобочки/трусики/попки - без проблем\n4. Пропонувати русню заборонено",
|
||||||
"shutdown": "Вимкнення бота з підом `{0}`",
|
"shutdown": "Вимкнення бота з підом `{0}`",
|
||||||
"startup": "Запуск бота з підом `{0}`",
|
"startup": "Запуск бота з підом `{0}`",
|
||||||
"sub_yes": "✅ Подання схвалено та прийнято",
|
"sub_yes": "✅ Подання схвалено та прийнято",
|
||||||
|
"sub_yes_auto": "✅ Подання автоматично прийнято",
|
||||||
"sub_no": "❌ Подання розглянуто та відхилено",
|
"sub_no": "❌ Подання розглянуто та відхилено",
|
||||||
|
"sub_dup": "⚠️ Подання автоматично відхилено через наявність цього фото в базі даних",
|
||||||
"sub_blocked": "Вас заблокували, ви більше не можете надсилати медіафайли.",
|
"sub_blocked": "Вас заблокували, ви більше не можете надсилати медіафайли.",
|
||||||
"sub_unblocked": "Вас розблокували, тепер ви можете надсилати медіафайли.",
|
"sub_unblocked": "Вас розблокували, тепер ви можете надсилати медіафайли.",
|
||||||
"sub_by": "\n\nПредставлено:",
|
"sub_by": "\n\nПредставлено:",
|
||||||
@@ -25,12 +31,15 @@
|
|||||||
"document_too_large": "Надісланий файл завеликий. Будь ласка, надсилайте файли не більше {0} Мб",
|
"document_too_large": "Надісланий файл завеликий. Будь ласка, надсилайте файли не більше {0} Мб",
|
||||||
"mime_not_allowed": "Тип файлу не дозволений. Розгляньте можливість використання одного з цих: {0}",
|
"mime_not_allowed": "Тип файлу не дозволений. Розгляньте можливість використання одного з цих: {0}",
|
||||||
"post_exception": "Не вдалося надіслати контент через `{0}`\n\nTraceback:\n```{1}```",
|
"post_exception": "Не вдалося надіслати контент через `{0}`\n\nTraceback:\n```{1}```",
|
||||||
"post_invalid_pic": "__TO_BE_ADDED__",
|
"post_invalid_pic": "⚠️ Помилка надсилання фото {0}\n```python\n{1}\n```",
|
||||||
"api_queue_empty": "Не вдалося надіслати контент: `Черга порожня або містить лише непідтримувані файли`.",
|
"api_queue_empty": "Не вдалося надіслати контент: `Черга порожня або містить лише непідтримувані файли`.",
|
||||||
"api_queue_error": "__TO_BE_ADDED__",
|
"api_queue_error": "Не вдалось отримати фото з черги API. Погляньте на логи вище а також на лог помилок API щоб дізнатись подробиці.",
|
||||||
"post_low": "Мала кількість контенту: `Залишилось всього {0} файлів в черзі.`",
|
"post_low": "Мала кількість контенту: `Залишилось всього {0} файлів в черзі.`",
|
||||||
"api_creds_invalid": "__TO_BE_ADDED__",
|
"api_creds_invalid": "Не вдалося авторизувати запит до API. Будь ласка, перевірте чи дані авторизації в конфігураційному файлі вірні та оновіть їх, якщо це не так.",
|
||||||
"sub_wip": "Подання постів зараз знаходиться у розробці. Він буде знову доступний через кілька днів. Дякуємо за ваше терпіння."
|
"sub_wip": "Подання постів зараз знаходиться у розробці. Він буде знову доступний через кілька днів. Дякуємо за ваше терпіння.",
|
||||||
|
"sub_duplicates_found": "__TO_BE_ADDED__",
|
||||||
|
"sub_error": "⚠️ Не вдалось завантажити фото через помилку бота. Адміністрацію повідомлено.",
|
||||||
|
"sub_error_admin": "Користувач {0} не зміг надіслати фото без додаткової перевірки через помилку:\n```\n{1}\n```"
|
||||||
},
|
},
|
||||||
"button": {
|
"button": {
|
||||||
"sub_yes": "✅ Прийняти",
|
"sub_yes": "✅ Прийняти",
|
||||||
@@ -49,7 +58,10 @@
|
|||||||
"sub_unblock": "Користувача {0} розблоковано",
|
"sub_unblock": "Користувача {0} розблоковано",
|
||||||
"sub_msg_unavail": "Повідомлення більше не існує",
|
"sub_msg_unavail": "Повідомлення більше не існує",
|
||||||
"sub_media_unavail": "Не вдалося завантажити подання",
|
"sub_media_unavail": "Не вдалося завантажити подання",
|
||||||
"sub_done": "Ви вже обрали що зробити з цим поданням"
|
"sub_done": "Ви вже обрали що зробити з цим поданням",
|
||||||
|
"sub_upload_failed": "__TO_BE_ADDED__",
|
||||||
|
"sub_duplicates_found": "Знайдено дублікати в базі даних бота",
|
||||||
|
"nothing": "🏁 Цю дію вже було завершено"
|
||||||
},
|
},
|
||||||
"console": {
|
"console": {
|
||||||
"shutdown": "Вимкнення бота з підом {0}",
|
"shutdown": "Вимкнення бота з підом {0}",
|
||||||
@@ -58,7 +70,7 @@
|
|||||||
"exception_occured": "Помилка {0} сталась під час виконання",
|
"exception_occured": "Помилка {0} сталась під час виконання",
|
||||||
"post_sent": "Надіслано {0} у {1} з підписом {2} та без звуку {3}",
|
"post_sent": "Надіслано {0} у {1} з підписом {2} та без звуку {3}",
|
||||||
"post_exception": "Не вдалося надіслати контент через {0}. Traceback: {1}",
|
"post_exception": "Не вдалося надіслати контент через {0}. Traceback: {1}",
|
||||||
"post_invalid_pic": "__TO_BE_ADDED__",
|
"post_invalid_pic": "Помилка надсилання фото HTTP {0}: {1}",
|
||||||
"post_empty": "Не вдалося надіслати контент адже черга з дозволеними розширеннями порожня",
|
"post_empty": "Не вдалося надіслати контент адже черга з дозволеними розширеннями порожня",
|
||||||
"sub_mime_not_allowed": "Отримано подання від {0} але типу {1} який не є дозволеним",
|
"sub_mime_not_allowed": "Отримано подання від {0} але типу {1} який не є дозволеним",
|
||||||
"sub_document_too_large": "Отримано подання від {0} але файл завеликий({1} > {2})",
|
"sub_document_too_large": "Отримано подання від {0} але файл завеликий({1} > {2})",
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
"""This is only a temporary solution. Complete Photos API client is yet to be developed."""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from base64 import b64decode, b64encode
|
from base64 import b64decode, b64encode
|
||||||
from os import makedirs, path, sep
|
from os import makedirs, path, sep
|
||||||
@@ -5,6 +7,7 @@ from random import choice
|
|||||||
from typing import Tuple, Union
|
from typing import Tuple, Union
|
||||||
|
|
||||||
from requests import get, patch, post
|
from requests import get, patch, post
|
||||||
|
from classes.exceptions import SubmissionUploadError
|
||||||
|
|
||||||
from modules.logger import logWrite
|
from modules.logger import logWrite
|
||||||
from modules.utils import configGet
|
from modules.utils import configGet
|
||||||
@@ -37,36 +40,54 @@ async def random_pic(token: Union[str, None] = None) -> Tuple[str, str]:
|
|||||||
### Returns:
|
### Returns:
|
||||||
* `Tuple[str, str]`: First value is an ID and the filename in the filesystem to be indexed.
|
* `Tuple[str, str]`: First value is an ID and the filename in the filesystem to be indexed.
|
||||||
"""
|
"""
|
||||||
if token is None:
|
token = await authorize() if token is None else token
|
||||||
token = await authorize()
|
logWrite(f'{configGet("address", "posting", "api")}/albums/{configGet("album", "posting", "api")}/photos?q=&page_size={configGet("page_size", "posting")}&caption=queue')
|
||||||
logWrite(f'{configGet("address", "posting", "api")}/albums/{configGet("album", "posting", "api")}/photos?q=&page_size=100&caption=queue')
|
resp = get(f'{configGet("address", "posting", "api")}/albums/{configGet("album", "posting", "api")}/photos?q=&page_size={configGet("page_size", "posting")}&caption=queue', headers={"Authorization": f"Bearer {token}"})
|
||||||
resp = get(f'{configGet("address", "posting", "api")}/albums/{configGet("album", "posting", "api")}/photos?q=&page_size=100&caption=queue', headers={"Authorization": f"Bearer {token}"})
|
|
||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
logWrite(f'Could not get photos from album {configGet("album", "posting", "api")}: HTTP {resp.status_code}')
|
logWrite(f'Could not get photos from album {configGet("album", "posting", "api")}: HTTP {resp.status_code}')
|
||||||
logWrite(f'Could not get photos from "{configGet("address", "posting", "api")}/albums/{configGet("album", "posting", "api")}/photos?q=&page_size=100&caption=queue" using token "{token}": HTTP {resp.status_code}', debug=True)
|
logWrite(f'Could not get photos from "{configGet("address", "posting", "api")}/albums/{configGet("album", "posting", "api")}/photos?q=&page_size={configGet("page_size", "posting")}&caption=queue" using token "{token}": HTTP {resp.status_code}', debug=True)
|
||||||
raise ValueError
|
raise ValueError
|
||||||
if len(resp.json()["results"]) == 0:
|
if len(resp.json()["results"]) == 0:
|
||||||
raise KeyError
|
raise KeyError
|
||||||
pic = choice(resp.json()["results"])
|
pic = choice(resp.json()["results"])
|
||||||
return pic["id"], pic["filename"]
|
return pic["id"], pic["filename"]
|
||||||
|
|
||||||
async def upload_pic(filepath: str) -> Tuple[bool, list]:
|
async def upload_pic(filepath: str, allow_duplicates: bool = False, token: Union[str, None] = None) -> Tuple[bool, list]:
|
||||||
token = await authorize()
|
token = await authorize() if token is None else token
|
||||||
try:
|
try:
|
||||||
pic_name = path.basename(filepath)
|
pic_name = path.basename(filepath)
|
||||||
files = {'file': (pic_name, open(filepath, 'rb'), 'image/jpeg')}
|
files = {'file': (pic_name, open(filepath, 'rb'), 'image/jpeg')}
|
||||||
response = post(f'{configGet("address", "posting", "api")}/albums/{configGet("album", "posting", "api")}/photos&caption=queue', headers={"Authorization": f"Bearer {token}"}, files=files).json()
|
response = post(f'{configGet("address", "posting", "api")}/albums/{configGet("album", "posting", "api")}/photos', params={"caption": "queue", "compress": False, "ignore_duplicates": allow_duplicates}, headers={"Authorization": f"Bearer {token}"}, files=files)
|
||||||
print(response, flush=True)
|
if response.status_code != 200 and response.status_code != 409:
|
||||||
|
logWrite(f"Could not upload '{filepath}' to API: HTTP {response.status_code} with message '{response.content}'")
|
||||||
|
raise SubmissionUploadError(str(filepath), response.status_code, response.content)
|
||||||
duplicates = []
|
duplicates = []
|
||||||
if "duplicates" in response:
|
if "duplicates" in response.json():
|
||||||
for duplicate in response["duplicates"]:
|
for index, duplicate in enumerate(response.json()["duplicates"]):
|
||||||
duplicates.append(f'{configGet("address", "posting", "api")}/photos/{duplicate["id"]}')
|
if response.json()["access_token"] is None:
|
||||||
|
duplicates.append(f'`{duplicate["id"]}`:\n{configGet("address_external", "posting", "api")}/photos/{duplicate["id"]}')
|
||||||
|
else:
|
||||||
|
duplicates.append(f'`{duplicate["id"]}`:\n{configGet("address_external", "posting", "api")}/token/photo/{response.json()["access_token"]}?id={index}')
|
||||||
return True, duplicates
|
return True, duplicates
|
||||||
except:
|
except:
|
||||||
return False, []
|
return False, []
|
||||||
|
|
||||||
async def move_pic(id: str) -> bool:
|
async def find_pic(name: str, caption: Union[str, None] = None, token: Union[str, None] = None) -> Union[dict, None]:
|
||||||
token = await authorize()
|
token = await authorize() if token is None else token
|
||||||
|
try:
|
||||||
|
response = get(f'{configGet("address", "posting", "api")}/albums/{configGet("album", "posting", "api")}/photos', params={"q": name, "caption": caption}, headers={"Authorization": f"Bearer {token}"})
|
||||||
|
# logWrite(response.json())
|
||||||
|
if response.status_code != 200:
|
||||||
|
return None
|
||||||
|
if len(response.json()["results"]) == 0:
|
||||||
|
return None
|
||||||
|
return response.json()["results"]
|
||||||
|
except Exception as exp:
|
||||||
|
logWrite(f"Could not find image with name '{name}' and caption '{caption}' due to: {exp}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
async def move_pic(id: str, token: Union[str, None] = None) -> bool:
|
||||||
|
token = await authorize() if token is None else token
|
||||||
try:
|
try:
|
||||||
patch(f'{configGet("address", "posting", "api")}/photos/{id}?caption=sent', headers={"Authorization": f"Bearer {token}"})
|
patch(f'{configGet("address", "posting", "api")}/photos/{id}?caption=sent', headers={"Authorization": f"Bearer {token}"})
|
||||||
return True
|
return True
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
from pyrogram.client import Client
|
|
||||||
from modules.utils import configGet
|
from modules.utils import configGet
|
||||||
|
from classes.poster_client import PosterClient
|
||||||
|
|
||||||
app = Client("duptsiaposter", bot_token=configGet("bot_token", "bot"), api_id=configGet("api_id", "bot"), api_hash=configGet("api_hash", "bot"))
|
app = PosterClient("duptsiaposter", bot_token=configGet("bot_token", "bot"), api_id=configGet("api_id", "bot"), api_hash=configGet("api_hash", "bot"))
|
@@ -1,9 +1,9 @@
|
|||||||
from os import listdir
|
from os import listdir
|
||||||
from pyrogram.client import Client
|
from classes.poster_client import PosterClient
|
||||||
from pyrogram.types import BotCommand, BotCommandScopeChat
|
from pyrogram.types import BotCommand, BotCommandScopeChat
|
||||||
from modules.utils import configGet, locale
|
from modules.utils import configGet, locale
|
||||||
|
|
||||||
async def register_commands(app: Client):
|
async def register_commands(app: PosterClient) -> None:
|
||||||
|
|
||||||
if configGet("submit", "mode"):
|
if configGet("submit", "mode"):
|
||||||
# Registering user commands
|
# Registering user commands
|
||||||
@@ -30,4 +30,5 @@ async def register_commands(app: Client):
|
|||||||
for command in configGet("commands_admin"):
|
for command in configGet("commands_admin"):
|
||||||
commands_admin_list.append(BotCommand(command, locale(command, "commands_admin", locale=configGet("locale"))))
|
commands_admin_list.append(BotCommand(command, locale(command, "commands_admin", locale=configGet("locale"))))
|
||||||
|
|
||||||
await app.set_bot_commands(commands_admin_list, scope=BotCommandScopeChat(chat_id=configGet("admin")))
|
for admin in app.admins:
|
||||||
|
await app.set_bot_commands(commands_admin_list, scope=BotCommandScopeChat(chat_id=admin))
|
@@ -16,7 +16,7 @@ with open(getcwd()+path.sep+"config.json", "r", encoding='utf8') as file:
|
|||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
# Check latest log size
|
# Check latest log size
|
||||||
def checkSize(debug=False):
|
def checkSize(debug=False) -> None:
|
||||||
|
|
||||||
global log_folder
|
global log_folder
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ def checkSize(debug=False):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# Append string to log
|
# Append string to log
|
||||||
def logAppend(message, debug=False):
|
def logAppend(message, debug=False) -> None:
|
||||||
|
|
||||||
global log_folder
|
global log_folder
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ def logAppend(message, debug=False):
|
|||||||
log.close()
|
log.close()
|
||||||
|
|
||||||
# Print to stdout and then to log
|
# Print to stdout and then to log
|
||||||
def logWrite(message, debug=False):
|
def logWrite(message, debug=False) -> None:
|
||||||
# save to log file and rotation is to be done
|
# save to log file and rotation is to be done
|
||||||
logAppend(f'{message}', debug=debug)
|
logAppend(f'{message}', debug=debug)
|
||||||
print(f"{message}", flush=True)
|
print(f"{message}", flush=True)
|
@@ -1,5 +1,6 @@
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||||
|
from pytimeparse.timeparse import timeparse
|
||||||
from modules.utils import configGet
|
from modules.utils import configGet
|
||||||
from modules.sender import send_content
|
from modules.sender import send_content
|
||||||
from modules.commands_register import register_commands
|
from modules.commands_register import register_commands
|
||||||
@@ -8,10 +9,11 @@ from modules.app import app
|
|||||||
scheduler = AsyncIOScheduler()
|
scheduler = AsyncIOScheduler()
|
||||||
|
|
||||||
if configGet("post", "mode"):
|
if configGet("post", "mode"):
|
||||||
# for entry in configGet("time", "posting"):
|
if configGet("use_interval", "posting"):
|
||||||
# dt_obj = datetime.strptime(entry, "%H:%M")
|
scheduler.add_job(send_content, "interval", seconds=timeparse(configGet("interval", "posting")), args=[app])
|
||||||
# Is only used for debug now!
|
else:
|
||||||
scheduler.add_job(send_content, "interval", seconds=30, args=[app])
|
for entry in configGet("time", "posting"):
|
||||||
# scheduler.add_job(send_content, "cron", hour=dt_obj.hour, minute=dt_obj.minute, args=[app])
|
dt_obj = datetime.strptime(entry, "%H:%M")
|
||||||
|
scheduler.add_job(send_content, "cron", hour=dt_obj.hour, minute=dt_obj.minute, args=[app])
|
||||||
|
|
||||||
scheduler.add_job(register_commands, "date", run_date=datetime.now()+timedelta(seconds=10), args=[app])
|
scheduler.add_job(register_commands, "date", run_date=datetime.now()+timedelta(seconds=10), args=[app])
|
@@ -1,11 +1,11 @@
|
|||||||
from datetime import datetime, timezone
|
from datetime import datetime
|
||||||
from os import makedirs, path
|
from os import makedirs, path
|
||||||
from shutil import copyfileobj, rmtree
|
from shutil import copyfileobj, rmtree
|
||||||
from traceback import format_exc
|
from traceback import format_exc
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
from bson import ObjectId
|
from classes.poster_client import PosterClient
|
||||||
from pyrogram.client import Client
|
|
||||||
from requests import get
|
from requests import get
|
||||||
|
|
||||||
from modules.api_client import authorize, move_pic, random_pic
|
from modules.api_client import authorize, move_pic, random_pic
|
||||||
@@ -14,14 +14,14 @@ from modules.logger import logWrite
|
|||||||
from modules.utils import configGet, locale
|
from modules.utils import configGet, locale
|
||||||
|
|
||||||
|
|
||||||
async def send_content(app: Client):
|
async def send_content(app: PosterClient) -> None:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
token = await authorize()
|
token = await authorize()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
await app.send_message(configGet("admin"), locale("api_creds_invalid", "message", locale=configGet("locale")))
|
await app.send_message(app.owner, locale("api_creds_invalid", "message", locale=configGet("locale")))
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -29,19 +29,19 @@ async def send_content(app: Client):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
logWrite(locale("post_empty", "console", locale=configGet("locale")))
|
logWrite(locale("post_empty", "console", locale=configGet("locale")))
|
||||||
if configGet("error", "reports"):
|
if configGet("error", "reports"):
|
||||||
await app.send_message(configGet("admin"), locale("api_queue_empty", "message", locale=configGet("locale")))
|
await app.send_message(app.owner, locale("api_queue_empty", "message", locale=configGet("locale")))
|
||||||
return
|
return
|
||||||
except ValueError:
|
except ValueError:
|
||||||
if configGet("error", "reports"):
|
if configGet("error", "reports"):
|
||||||
await app.send_message(configGet("admin"), locale("api_queue_error", "message", locale=configGet("locale")))
|
await app.send_message(app.owner, locale("api_queue_error", "message", locale=configGet("locale")))
|
||||||
return
|
return
|
||||||
|
|
||||||
response = get(f'{configGet("address", "posting", "api")}/photos/{pic[0]}', headers={"Authorization": f"Bearer {token}"}, stream=True)
|
response = get(f'{configGet("address", "posting", "api")}/photos/{pic[0]}', headers={"Authorization": f"Bearer {token}"}, stream=True)
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
logWrite(locale("post_invalid_pic", "console", locale=configGet("locale")).format(str(response.json())))
|
logWrite(locale("post_invalid_pic", "console", locale=configGet("locale")).format(response.status_code, str(response.json())))
|
||||||
if configGet("error", "reports"):
|
if configGet("error", "reports"):
|
||||||
await app.send_message(configGet("admin"), locale("post_invalid_pic", "message", locale=configGet("locale")).format(response.json()))
|
await app.send_message(app.owner, locale("post_invalid_pic", "message", locale=configGet("locale")).format(response.status_code, response.json()))
|
||||||
|
|
||||||
tmp_dir = str(uuid4())
|
tmp_dir = str(uuid4())
|
||||||
|
|
||||||
@@ -52,20 +52,43 @@ async def send_content(app: Client):
|
|||||||
with open(path.join(configGet("tmp", "locations"), tmp_path), 'wb') as out_file:
|
with open(path.join(configGet("tmp", "locations"), tmp_path), 'wb') as out_file:
|
||||||
copyfileobj(response.raw, out_file)
|
copyfileobj(response.raw, out_file)
|
||||||
|
|
||||||
|
logWrite(f'Candidate {pic[1]} ({pic[0]}) is {path.getsize(path.join(configGet("tmp", "locations"), tmp_path))} bytes big', debug=True)
|
||||||
|
|
||||||
|
if path.getsize(path.join(configGet("tmp", "locations"), tmp_path)) > 5242880:
|
||||||
|
image = Image.open(path.join(configGet("tmp", "locations"), tmp_path))
|
||||||
|
width, height = image.size
|
||||||
|
image = image.resize((int(width/2), int(height/2)), Image.ANTIALIAS)
|
||||||
|
if tmp_path.lower().endswith(".jpeg") or tmp_path.lower().endswith(".jpg"):
|
||||||
|
image.save(path.join(configGet("tmp", "locations"), tmp_path), "JPEG", optimize=True, quality=50)
|
||||||
|
elif tmp_path.lower().endswith(".png"):
|
||||||
|
image.save(path.join(configGet("tmp", "locations"), tmp_path), "PNG", optimize=True, compress_level=8)
|
||||||
|
image.close()
|
||||||
|
|
||||||
|
if path.getsize(path.join(configGet("tmp", "locations"), tmp_path)) > 5242880:
|
||||||
|
rmtree(path.join(configGet("tmp", "locations"), tmp_dir), ignore_errors=True)
|
||||||
|
raise BytesWarning
|
||||||
|
|
||||||
del response
|
del response
|
||||||
|
|
||||||
submitted_caption = col_submitted.find_one( {"image": ObjectId(pic[0])} )
|
submitted = col_submitted.find_one({"temp.file": pic[1]})
|
||||||
|
|
||||||
if submitted_caption is not None:
|
if submitted is not None and submitted["caption"] is not None:
|
||||||
caption = submitted_caption["caption"].strip()
|
caption = submitted["caption"].strip()
|
||||||
else:
|
else:
|
||||||
caption = ""
|
caption = ""
|
||||||
|
|
||||||
|
if submitted is not None and configGet("enabled", "posting", "submitted_caption") and (
|
||||||
|
(submitted["user"] not in app.admins) or (configGet("ignore_admins", "posting", "submitted_caption") is False)
|
||||||
|
):
|
||||||
|
caption = f"{caption}\n\n{configGet('text', 'posting', 'submitted_caption')}\n"
|
||||||
|
else:
|
||||||
|
caption = f"{caption}\n\n"
|
||||||
|
|
||||||
if configGet("enabled", "caption"):
|
if configGet("enabled", "caption"):
|
||||||
if configGet("link", "caption") != None:
|
if configGet("link", "caption") != None:
|
||||||
caption = f"{caption}\n\n[{configGet('text', 'caption')}]({configGet('link', 'caption')})"
|
caption = f"{caption}[{configGet('text', 'caption')}]({configGet('link', 'caption')})"
|
||||||
else:
|
else:
|
||||||
caption = f"{caption}\n\n{configGet('text', 'caption')}"
|
caption = f"{caption}{configGet('text', 'caption')}"
|
||||||
else:
|
else:
|
||||||
caption = caption
|
caption = caption
|
||||||
|
|
||||||
@@ -74,17 +97,17 @@ async def send_content(app: Client):
|
|||||||
except Exception as exp:
|
except Exception as exp:
|
||||||
logWrite(f"Could not send image {pic[1]} ({pic[0]}) due to {exp}")
|
logWrite(f"Could not send image {pic[1]} ({pic[0]}) due to {exp}")
|
||||||
if configGet("error", "reports"):
|
if configGet("error", "reports"):
|
||||||
await app.send_message(configGet("admin"), locale("post_exception", "message", locale=configGet("locale")).format(exp, format_exc()))
|
await app.send_message(app.owner, locale("post_exception", "message", locale=configGet("locale")).format(exp, format_exc()))
|
||||||
# rmtree(path.join(configGet("tmp", "locations"), tmp_dir), ignore_errors=True)
|
# rmtree(path.join(configGet("tmp", "locations"), tmp_dir), ignore_errors=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
col_sent.insert_one(
|
col_sent.insert_one(
|
||||||
{
|
{
|
||||||
"date": datetime.now(tz=timezone.utc),
|
"date": datetime.now(),
|
||||||
"image": pic[0],
|
"image": pic[0],
|
||||||
"filename": pic[1],
|
"filename": pic[1],
|
||||||
"channel": configGet("channel", "posting"),
|
"channel": configGet("channel", "posting"),
|
||||||
"caption": None if submitted_caption is None else submitted_caption["caption"].strip()
|
"caption": None if (submitted is None or submitted["caption"] is None) else submitted["caption"].strip()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -97,138 +120,8 @@ async def send_content(app: Client):
|
|||||||
except Exception as exp:
|
except Exception as exp:
|
||||||
logWrite(locale("post_exception", "console", locale=configGet("locale")).format(str(exp), format_exc()))
|
logWrite(locale("post_exception", "console", locale=configGet("locale")).format(str(exp), format_exc()))
|
||||||
if configGet("error", "reports"):
|
if configGet("error", "reports"):
|
||||||
await app.send_message(configGet("admin"), locale("post_exception", "message", locale=configGet("locale")).format(exp, format_exc()))
|
await app.send_message(app.owner, locale("post_exception", "message", locale=configGet("locale")).format(exp, format_exc()))
|
||||||
|
try:
|
||||||
|
rmtree(path.join(configGet("tmp", "locations"), tmp_dir), ignore_errors=True)
|
||||||
# async def send_content_old(app: Client):
|
except:
|
||||||
|
pass
|
||||||
# # Send post to channel
|
|
||||||
# try:
|
|
||||||
|
|
||||||
# index = jsonLoad(configGet("index", "locations"))
|
|
||||||
|
|
||||||
# if configGet("api_based", "mode"):
|
|
||||||
|
|
||||||
# try:
|
|
||||||
# pic = random_pic()
|
|
||||||
# except:
|
|
||||||
# logWrite(locale("post_empty", "console", locale=configGet("locale")))
|
|
||||||
# if configGet("error", "reports"):
|
|
||||||
# await app.send_message(configGet("admin"), locale("post_empty", "message", locale=configGet("locale")))
|
|
||||||
# return
|
|
||||||
|
|
||||||
# token = authorize()
|
|
||||||
|
|
||||||
# response = get(f'{configGet("address", "posting", "api")}/photos/{pic[0]}', headers={"Authorization": f"Bearer {token}"}, stream=True)
|
|
||||||
|
|
||||||
# with open(configGet("tmp", "locations")+sep+pic[0]+".jpg", 'wb') as out_file:
|
|
||||||
# copyfileobj(response.raw, out_file)
|
|
||||||
|
|
||||||
# del response
|
|
||||||
|
|
||||||
# candidate = configGet("tmp", "locations")+sep+pic[0]+".jpg"
|
|
||||||
# candidate_file = pic[1]
|
|
||||||
# ext_type = "photo"
|
|
||||||
|
|
||||||
# if not configGet("api_based", "mode"):
|
|
||||||
|
|
||||||
# list_queue = listdir(configGet("queue", "locations"))
|
|
||||||
|
|
||||||
# for file in list_queue:
|
|
||||||
|
|
||||||
# if not file in index["sent"]:
|
|
||||||
|
|
||||||
# ext_match = False
|
|
||||||
|
|
||||||
# for ext in configGet("photo", "posting", "extensions"):
|
|
||||||
# if file.endswith(ext):
|
|
||||||
# ext_match = True
|
|
||||||
# ext_type = "photo"
|
|
||||||
# break
|
|
||||||
|
|
||||||
# for ext in configGet("video", "posting", "extensions"):
|
|
||||||
# if file.endswith(ext):
|
|
||||||
# ext_match = True
|
|
||||||
# ext_type = "video"
|
|
||||||
# break
|
|
||||||
|
|
||||||
# if not ext_match:
|
|
||||||
# list_queue.remove(file)
|
|
||||||
|
|
||||||
# else:
|
|
||||||
# list_queue.remove(file)
|
|
||||||
|
|
||||||
# if len(list_queue) > 0:
|
|
||||||
# candidate_file = choice(list_queue)
|
|
||||||
# candidate = configGet("queue", "locations")+sep+candidate_file
|
|
||||||
# else:
|
|
||||||
# logWrite(locale("post_empty", "console", locale=configGet("locale")))
|
|
||||||
# if configGet("error", "reports"):
|
|
||||||
# await app.send_message(configGet("admin"), locale("post_empty", "message", locale=configGet("locale")))
|
|
||||||
# return
|
|
||||||
|
|
||||||
# if candidate_file in index["captions"]:
|
|
||||||
# caption = index["captions"][candidate_file]
|
|
||||||
# else:
|
|
||||||
# caption = ""
|
|
||||||
|
|
||||||
# if configGet("enabled", "caption"):
|
|
||||||
# if configGet("link", "caption") != None:
|
|
||||||
# caption = f"{caption}\n\n[{configGet('text', 'caption')}]({configGet('link', 'caption')})"
|
|
||||||
# else:
|
|
||||||
# caption = f"{caption}\n\n{configGet('text', 'caption')}"
|
|
||||||
# else:
|
|
||||||
# caption = caption
|
|
||||||
|
|
||||||
# if ext_type == "photo":
|
|
||||||
|
|
||||||
# if configGet("enabled", "caption"):
|
|
||||||
# if configGet("link", "caption") != None:
|
|
||||||
# sent = await app.send_photo(configGet("channel", "posting"), candidate, caption=caption, disable_notification=configGet("silent", "posting"))
|
|
||||||
# else:
|
|
||||||
# sent = await app.send_photo(configGet("channel", "posting"), candidate, caption=caption, disable_notification=configGet("silent", "posting"))
|
|
||||||
# else:
|
|
||||||
# sent = await app.send_photo(configGet("channel", "posting"), candidate, caption=caption, disable_notification=configGet("silent", "posting"))
|
|
||||||
|
|
||||||
# elif ext_type == "video":
|
|
||||||
|
|
||||||
# if configGet("enabled", "caption"):
|
|
||||||
# if configGet("link", "caption") != None:
|
|
||||||
# sent = await app.send_video(configGet("channel", "posting"), candidate, caption=caption, disable_notification=configGet("silent", "posting"))
|
|
||||||
# else:
|
|
||||||
# sent = await app.send_video(configGet("channel", "posting"), candidate, caption=caption, disable_notification=configGet("silent", "posting"))
|
|
||||||
# else:
|
|
||||||
# sent = await app.send_video(configGet("channel", "posting"), candidate, caption=caption, disable_notification=configGet("silent", "posting"))
|
|
||||||
|
|
||||||
# else:
|
|
||||||
# return
|
|
||||||
|
|
||||||
# if configGet("api_based", "mode"):
|
|
||||||
# remove(configGet("tmp", "locations")+sep+pic[0]+".jpg")
|
|
||||||
# move_pic(pic[0])
|
|
||||||
|
|
||||||
# index["sent"].append(candidate_file)
|
|
||||||
# index["last_id"] = sent.id
|
|
||||||
|
|
||||||
# jsonSave(index, configGet("index", "locations"))
|
|
||||||
|
|
||||||
# if configGet("move_sent", "posting"):
|
|
||||||
# move(candidate, configGet("sent", "locations")+sep+candidate_file)
|
|
||||||
|
|
||||||
# logWrite(locale("post_sent", "console", locale=configGet("locale")).format(candidate, ext_type, str(configGet("channel", "posting")), caption.replace("\n", "%n"), str(configGet("silent", "posting"))))
|
|
||||||
|
|
||||||
# if configGet("sent", "reports"):
|
|
||||||
# await app.send_message(configGet("admin"), f"Posted `{candidate_file}`", disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup([
|
|
||||||
# [InlineKeyboardButton(locale("post_view", "button", locale=configGet("locale")), url=sent.link)]
|
|
||||||
# ]))
|
|
||||||
|
|
||||||
# except Exception as exp:
|
|
||||||
# logWrite(locale("post_exception", "console", locale=configGet("locale")).format(str(exp), format_exc()))
|
|
||||||
# if configGet("error", "reports"):
|
|
||||||
# await app.send_message(configGet("admin"), locale("post_exception", "message", locale=configGet("locale")).format(exp, format_exc()))
|
|
||||||
# pass
|
|
||||||
|
|
||||||
|
|
||||||
# Work in progress
|
|
||||||
# Check last posts forwards
|
|
||||||
# check_forwards(app)
|
|
@@ -1,27 +0,0 @@
|
|||||||
from datetime import datetime, timezone
|
|
||||||
from modules.utils import configGet
|
|
||||||
from modules.database import col_users, col_banned
|
|
||||||
from pyrogram.types.user_and_chats import User
|
|
||||||
|
|
||||||
def subLimit(user: User) -> None:
|
|
||||||
if col_users.find_one_and_update({"user": user.id}, {"$set": {"cooldown": datetime.now(tz=timezone.utc)}}) is None:
|
|
||||||
col_users.insert_one({"user": user.id, "cooldown": datetime.now(tz=timezone.utc)})
|
|
||||||
|
|
||||||
def subLimited(user: User) -> bool:
|
|
||||||
if user.id == configGet("admin"):
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
db_record = col_users.find_one({"user": user.id})
|
|
||||||
if db_record is None:
|
|
||||||
return False
|
|
||||||
return True if (datetime.now(tz=timezone.utc) - db_record["cooldown"]).total_seconds() < configGet("timeout", "submission") else False
|
|
||||||
|
|
||||||
def subBlocked(user: User) -> bool:
|
|
||||||
return False if col_banned.find_one({"user": user.id}) is None else True
|
|
||||||
|
|
||||||
def subBlock(user: User) -> None:
|
|
||||||
if col_banned.find_one({"user": user.id}) is None:
|
|
||||||
col_banned.insert_one({"user": user.id, "date": datetime.now(tz=timezone.utc)})
|
|
||||||
|
|
||||||
def subUnblock(user: User) -> None:
|
|
||||||
col_banned.find_one_and_delete({"user": user.id})
|
|
@@ -9,10 +9,11 @@ from sys import exit
|
|||||||
from os import sep, kill
|
from os import sep, kill
|
||||||
from os import name as osname
|
from os import name as osname
|
||||||
from traceback import print_exc
|
from traceback import print_exc
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from modules.logger import logWrite
|
from modules.logger import logWrite
|
||||||
|
|
||||||
def jsonLoad(filename):
|
def jsonLoad(filename: str) -> Any:
|
||||||
"""Loads arg1 as json and returns its contents"""
|
"""Loads arg1 as json and returns its contents"""
|
||||||
with open(filename, "r", encoding='utf8') as file:
|
with open(filename, "r", encoding='utf8') as file:
|
||||||
try:
|
try:
|
||||||
@@ -26,7 +27,7 @@ def jsonLoad(filename):
|
|||||||
file.close()
|
file.close()
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def jsonSave(contents, filename):
|
def jsonSave(contents: Any, filename: str) -> None:
|
||||||
"""Dumps dict/list arg1 to file arg2"""
|
"""Dumps dict/list arg1 to file arg2"""
|
||||||
try:
|
try:
|
||||||
with open(filename, "w", encoding='utf8') as file:
|
with open(filename, "w", encoding='utf8') as file:
|
||||||
@@ -108,10 +109,14 @@ except ModuleNotFoundError:
|
|||||||
print(locale("deps_missing", "console", locale=configGet("locale")), flush=True)
|
print(locale("deps_missing", "console", locale=configGet("locale")), flush=True)
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
def killProc(pid):
|
def killProc(pid: int) -> None:
|
||||||
|
"""Kill process by its PID. Meant to be used to kill the main process of bot itself.
|
||||||
|
|
||||||
|
### Args:
|
||||||
|
* pid (`int`): PID of the target
|
||||||
|
"""
|
||||||
if osname == "posix":
|
if osname == "posix":
|
||||||
from signal import SIGKILL
|
from signal import SIGKILL
|
||||||
kill(pid, SIGKILL)
|
kill(pid, SIGKILL)
|
||||||
else:
|
else:
|
||||||
p = Process(pid)
|
Process(pid).kill()
|
||||||
p.kill()
|
|
@@ -1,11 +1,11 @@
|
|||||||
from modules.app import app
|
from modules.app import app
|
||||||
from pyrogram import filters
|
from pyrogram import filters
|
||||||
from pyrogram.types import CallbackQuery
|
from pyrogram.types import CallbackQuery
|
||||||
from pyrogram.client import Client
|
from classes.poster_client import PosterClient
|
||||||
from modules.utils import locale
|
from modules.utils import locale
|
||||||
|
|
||||||
# Callback empty ===============================================================================================================
|
# Callback empty ===============================================================================================================
|
||||||
@app.on_callback_query(filters.regex("nothing"))
|
@app.on_callback_query(filters.regex("nothing"))
|
||||||
async def callback_query_nothing(app: Client, clb: CallbackQuery):
|
async def callback_query_nothing(app: PosterClient, clb: CallbackQuery):
|
||||||
await clb.answer(text=locale("nothing", "callback", locale=clb.from_user))
|
await clb.answer(text=locale("nothing", "callback", locale=clb.from_user.language_code))
|
||||||
# ==============================================================================================================================
|
# ==============================================================================================================================
|
@@ -1,116 +1,115 @@
|
|||||||
from os import path, sep
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
|
from os import path
|
||||||
|
from shutil import rmtree
|
||||||
from pyrogram import filters
|
from pyrogram import filters
|
||||||
from pyrogram.client import Client
|
from pyrogram.types import CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton
|
||||||
from pyrogram.types import CallbackQuery
|
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.app import app
|
||||||
from modules.submissions import subBlock, subUnblock
|
from modules.utils import configGet, locale
|
||||||
from modules.utils import configGet, jsonLoad, jsonSave, locale
|
|
||||||
from modules.database import col_submitted
|
from modules.database import col_submitted
|
||||||
from bson import ObjectId
|
from bson import ObjectId
|
||||||
|
|
||||||
|
|
||||||
@app.on_callback_query(filters.regex("sub_yes_[\s\S]*"))
|
@app.on_callback_query(filters.regex("sub_yes_[\s\S]*"))
|
||||||
async def callback_query_yes(app: Client, clb: CallbackQuery):
|
async def callback_query_yes(app: PosterClient, clb: CallbackQuery):
|
||||||
|
|
||||||
fullclb = clb.data.split("_")
|
fullclb = str(clb.data).split("_")
|
||||||
user_locale = clb.from_user.language_code
|
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])})
|
db_entry = col_submitted.find_one({"_id": ObjectId(fullclb[2])})
|
||||||
|
|
||||||
if db_entry is None:
|
try:
|
||||||
await clb.answer(text=locale("sub_msg_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
|
return
|
||||||
else:
|
except SubmissionDuplicatesError as exp:
|
||||||
if db_entry["tmp"]["uuid"] is not None:
|
await clb.answer(text=locale("sub_duplicates_found", "callback", locale=user_locale), show_alert=True)
|
||||||
if not path.exists(path.join(configGet("data", "locations"), "submissions", db_entry["tmp"]["uuid"], db_entry["tmp"]["file"])):
|
await clb.message.reply_text(locale("sub_media_duplicates_list", "message", locale=user_locale).format("\n • ".join(exp.duplicates)), quote=True)
|
||||||
await clb.answer(text=locale("sub_msg_unavail", "message", locale=user_locale), show_alert=True)
|
|
||||||
return
|
return
|
||||||
else:
|
|
||||||
|
if submission is not None:
|
||||||
|
await submission.reply_text(locale("sub_yes", "message", locale=submission.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")]]
|
||||||
|
await clb.message.edit_reply_markup(reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||||
|
|
||||||
|
# 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: PosterClient, clb: CallbackQuery):
|
||||||
|
|
||||||
|
fullclb = str(clb.data).split("_")
|
||||||
|
user_locale = clb.from_user.language_code
|
||||||
|
|
||||||
|
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:
|
try:
|
||||||
submission = await app.get_messages(db_entry["user"], db_entry["telegram"]["msg_id"])
|
submission = await app.get_messages(db_entry["user"], db_entry["telegram"]["msg_id"])
|
||||||
except:
|
except:
|
||||||
await clb.answer(text=locale("sub_msg_unavail", "message", locale=user_locale), show_alert=True)
|
await clb.answer(text=locale("sub_msg_unavail", "message", locale=user_locale), show_alert=True)
|
||||||
return
|
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)
|
|
||||||
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))
|
|
||||||
|
|
||||||
|
|
||||||
@app.on_callback_query(filters.regex("sub_no_[\s\S]*"))
|
|
||||||
async def callback_query_no(app: Client, clb: CallbackQuery):
|
|
||||||
fullclb = 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 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)
|
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")]]
|
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(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
await clb.message.edit_reply_markup(reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||||
|
|
||||||
|
|
||||||
@app.on_callback_query(filters.regex("sub_block_[\s\S]*"))
|
@app.on_callback_query(filters.regex("sub_block_[\s\S]*"))
|
||||||
async def callback_query_block(app: Client, clb: CallbackQuery):
|
async def callback_query_block(app: PosterClient, clb: CallbackQuery):
|
||||||
fullclb = clb.data.split("_")
|
fullclb = str(clb.data).split("_")
|
||||||
user_locale = clb.from_user.language_code
|
user_locale = clb.from_user.language_code
|
||||||
await app.send_message(int(fullclb[2]), locale("sub_msg_unavail", "message", locale=configGet("locale")))
|
await app.send_message(int(fullclb[2]), locale("sub_blocked", "message", locale=configGet("locale")))
|
||||||
subBlock(int(fullclb[2]))
|
PosterUser(int(fullclb[2])).block()
|
||||||
await clb.answer(text=locale("sub_block", "callback", locale=user_locale).format(fullclb[2]), show_alert=True)
|
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")]]
|
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(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
await clb.message.edit_reply_markup(reply_markup=InlineKeyboardMarkup(edited_markup))
|
||||||
|
|
||||||
|
|
||||||
@app.on_callback_query(filters.regex("sub_unblock_[\s\S]*"))
|
@app.on_callback_query(filters.regex("sub_unblock_[\s\S]*"))
|
||||||
async def callback_query_unblock(app: Client, clb: CallbackQuery):
|
async def callback_query_unblock(app: PosterClient, clb: CallbackQuery):
|
||||||
fullclb = clb.data.split("_")
|
fullclb = str(clb.data).split("_")
|
||||||
user_locale = clb.from_user.language_code
|
user_locale = clb.from_user.language_code
|
||||||
await app.send_message(int(fullclb[2]), locale("sub_msg_unavail", "message", locale=configGet("locale")))
|
await app.send_message(int(fullclb[2]), locale("sub_unblocked", "message", locale=configGet("locale")))
|
||||||
subUnblock(int(fullclb[2]))
|
PosterUser(int(fullclb[2])).unblock()
|
||||||
await clb.answer(text=locale("sub_unblock", "callback", locale=user_locale).format(fullclb[2]), show_alert=True)
|
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")]]
|
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(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
|
await clb.message.edit_reply_markup(reply_markup=InlineKeyboardMarkup(edited_markup))
|
@@ -1,7 +1,7 @@
|
|||||||
from os import getpid
|
from os import getpid
|
||||||
|
|
||||||
from pyrogram import filters
|
from pyrogram import filters
|
||||||
from pyrogram.client import Client
|
from classes.poster_client import PosterClient
|
||||||
from pyrogram.types import Message
|
from pyrogram.types import Message
|
||||||
|
|
||||||
from modules.app import app
|
from modules.app import app
|
||||||
@@ -10,9 +10,9 @@ from modules.utils import configGet, killProc, locale
|
|||||||
|
|
||||||
|
|
||||||
@app.on_message(~ filters.scheduled & filters.command(["kill", "die", "reboot"], prefixes=["", "/"]))
|
@app.on_message(~ filters.scheduled & filters.command(["kill", "die", "reboot"], prefixes=["", "/"]))
|
||||||
async def cmd_kill(app: Client, msg: Message):
|
async def cmd_kill(app: PosterClient, msg: Message):
|
||||||
|
|
||||||
if msg.from_user.id == configGet("admin"):
|
if msg.from_user.id in app.admins:
|
||||||
pid = getpid()
|
pid = getpid()
|
||||||
logWrite(locale("shutdown", "console", locale=configGet("locale")).format(str(pid)))
|
logWrite(locale("shutdown", "console", locale=configGet("locale")).format(str(pid)))
|
||||||
await msg.reply_text(locale("shutdown", "message", locale=configGet("locale")).format(str(pid)))
|
await msg.reply_text(locale("shutdown", "message", locale=configGet("locale")).format(str(pid)))
|
||||||
|
@@ -1,18 +1,18 @@
|
|||||||
from pyrogram import filters
|
from pyrogram import filters
|
||||||
from pyrogram.client import Client
|
|
||||||
from pyrogram.types import Message
|
from pyrogram.types import Message
|
||||||
|
|
||||||
from modules.app import app
|
from modules.app import app
|
||||||
from modules.submissions import subBlocked
|
from modules.utils import locale
|
||||||
from modules.utils import configGet, jsonLoad, locale
|
from classes.user import PosterUser
|
||||||
|
from classes.poster_client import PosterClient
|
||||||
|
|
||||||
|
|
||||||
@app.on_message(~ filters.scheduled & filters.command(["start"], prefixes="/"))
|
@app.on_message(~ filters.scheduled & filters.command(["start"], prefixes="/"))
|
||||||
async def cmd_start(app: Client, msg: Message):
|
async def cmd_start(app: PosterClient, msg: Message):
|
||||||
if subBlocked(msg.from_user) is False:
|
if PosterUser(msg.from_user.id).is_blocked() is False:
|
||||||
await msg.reply_text(locale("start", "message", locale=msg.from_user.language_code))
|
await msg.reply_text(locale("start", "message", locale=msg.from_user.language_code))
|
||||||
|
|
||||||
@app.on_message(~ filters.scheduled & filters.command(["rules", "help"], prefixes="/"))
|
@app.on_message(~ filters.scheduled & filters.command(["rules", "help"], prefixes="/"))
|
||||||
async def cmd_rules(app: Client, msg: Message):
|
async def cmd_rules(app: PosterClient, msg: Message):
|
||||||
if subBlocked(msg.from_user) is False:
|
if PosterUser(msg.from_user.id).is_blocked() is False:
|
||||||
await msg.reply_text(locale("rules", "message", locale=msg.from_user.language_code))
|
await msg.reply_text(locale("rules", "message", locale=msg.from_user.language_code))
|
33
plugins/commands/photos.py
Normal file
33
plugins/commands/photos.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
from pyrogram import filters
|
||||||
|
from pyrogram.types import Message
|
||||||
|
|
||||||
|
from classes.poster_client import PosterClient
|
||||||
|
from modules.app import app
|
||||||
|
|
||||||
|
|
||||||
|
@app.on_message(~ filters.scheduled & filters.command(["import"], prefixes=["", "/"]))
|
||||||
|
async def cmd_import(app: PosterClient, msg: Message):
|
||||||
|
|
||||||
|
if msg.from_user.id in app.admins:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@app.on_message(~ filters.scheduled & filters.command(["export"], prefixes=["", "/"]))
|
||||||
|
async def cmd_export(app: PosterClient, msg: Message):
|
||||||
|
|
||||||
|
if msg.from_user.id in app.admins:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@app.on_message(~ filters.scheduled & filters.command(["remove"], prefixes=["", "/"]))
|
||||||
|
async def cmd_remove(app: PosterClient, msg: Message):
|
||||||
|
|
||||||
|
if msg.from_user.id in app.admins:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@app.on_message(~ filters.scheduled & filters.command(["purge"], prefixes=["", "/"]))
|
||||||
|
async def cmd_purge(app: PosterClient, msg: Message):
|
||||||
|
|
||||||
|
if msg.from_user.id in app.admins:
|
||||||
|
pass
|
@@ -1,162 +1,190 @@
|
|||||||
from datetime import datetime, timezone
|
from datetime import datetime
|
||||||
from os import makedirs, path, sep
|
from os import makedirs, path, sep
|
||||||
|
from traceback import format_exc
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from pyrogram import filters
|
from pyrogram import filters
|
||||||
from pyrogram.client import Client
|
|
||||||
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
|
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
|
||||||
|
from pyrogram.enums.chat_action import ChatAction
|
||||||
|
from classes.exceptions import SubmissionDuplicatesError
|
||||||
|
from classes.poster_client import PosterClient
|
||||||
|
from classes.user import PosterUser
|
||||||
|
|
||||||
from modules.app import app
|
from modules.app import app
|
||||||
from modules.database import col_banned, col_submitted
|
from modules.database import col_banned, col_submitted
|
||||||
from modules.logger import logWrite
|
from modules.logger import logWrite
|
||||||
from modules.submissions import subLimit, subLimited
|
|
||||||
from modules.utils import configGet, locale
|
from modules.utils import configGet, locale
|
||||||
from classes.enums.submission_types import SubmissionType
|
from classes.enums.submission_types import SubmissionType
|
||||||
|
|
||||||
|
|
||||||
@app.on_message(~ filters.scheduled & filters.photo | filters.video | filters.animation | filters.document)
|
@app.on_message(~filters.scheduled & filters.private & filters.photo | filters.video | filters.animation | filters.document)
|
||||||
async def get_submission(_: Client, msg: Message):
|
async def get_submission(app: PosterClient, msg: Message):
|
||||||
|
|
||||||
locale("sub_wip", "message", locale=msg.from_user.language_code)
|
try:
|
||||||
|
|
||||||
# try:
|
if col_banned.find_one( {"user": msg.from_user.id} ) is not None:
|
||||||
|
return
|
||||||
|
|
||||||
# if col_banned.find_one( {"user": msg.from_user.id} ) is not None:
|
await app.send_chat_action(msg.chat.id, ChatAction.TYPING)
|
||||||
# return
|
|
||||||
|
|
||||||
# user_locale = msg.from_user.language_code
|
user_locale = msg.from_user.language_code
|
||||||
# save_tmp = True
|
save_tmp = True
|
||||||
# contents = None
|
contents = None
|
||||||
|
|
||||||
# if subLimited(msg.from_user):
|
if PosterUser(msg.from_user.id).is_limited():
|
||||||
# await msg.reply_text(locale("sub_cooldown", "message", locale=user_locale).format(str(configGet("timeout", "submission"))))
|
await msg.reply_text(locale("sub_cooldown", "message", locale=user_locale).format(str(configGet("timeout", "submission"))))
|
||||||
# return
|
return
|
||||||
|
|
||||||
# if msg.document is not None:
|
if msg.document is not None:
|
||||||
# if msg.document.mime_type not in configGet("mime_types", "submission"):
|
if msg.document.mime_type not in configGet("mime_types", "submission"):
|
||||||
# await msg.reply_text(locale("mime_not_allowed", "message", locale=user_locale), quote=True)
|
await msg.reply_text(locale("mime_not_allowed", "message", locale=user_locale), quote=True)
|
||||||
# return
|
return
|
||||||
# if msg.document.file_size > configGet("file_size", "submission"):
|
if msg.document.file_size > configGet("file_size", "submission"):
|
||||||
# await msg.reply_text(locale("document_too_large", "message", locale=user_locale).format(str(configGet("file_size", "submission")/1024/1024)), quote=True)
|
await msg.reply_text(locale("document_too_large", "message", locale=user_locale).format(str(configGet("file_size", "submission")/1024/1024)), quote=True)
|
||||||
# return
|
return
|
||||||
# if msg.document.file_size > configGet("tmp_size", "submission"):
|
if msg.document.file_size > configGet("tmp_size", "submission"):
|
||||||
# save_tmp = False
|
save_tmp = False
|
||||||
# contents = msg.document.file_id, SubmissionType.DOCUMENT #, msg.document.file_name
|
contents = msg.document.file_id, SubmissionType.DOCUMENT #, msg.document.file_name
|
||||||
|
|
||||||
# if msg.video is not None:
|
if msg.video is not None:
|
||||||
# if msg.video.file_size > configGet("file_size", "submission"):
|
if msg.video.file_size > configGet("file_size", "submission"):
|
||||||
# await msg.reply_text(locale("document_too_large", "message", locale=user_locale).format(str(configGet("file_size", "submission")/1024/1024)), quote=True)
|
await msg.reply_text(locale("document_too_large", "message", locale=user_locale).format(str(configGet("file_size", "submission")/1024/1024)), quote=True)
|
||||||
# return
|
return
|
||||||
# if msg.video.file_size > configGet("tmp_size", "submission"):
|
if msg.video.file_size > configGet("tmp_size", "submission"):
|
||||||
# save_tmp = False
|
save_tmp = False
|
||||||
# contents = msg.video.file_id, SubmissionType.VIDEO #, msg.video.file_name
|
contents = msg.video.file_id, SubmissionType.VIDEO #, msg.video.file_name
|
||||||
|
|
||||||
# if msg.animation is not None:
|
if msg.animation is not None:
|
||||||
# if msg.animation.file_size > configGet("file_size", "submission"):
|
if msg.animation.file_size > configGet("file_size", "submission"):
|
||||||
# await msg.reply_text(locale("document_too_large", "message", locale=user_locale).format(str(configGet("file_size", "submission")/1024/1024)), quote=True)
|
await msg.reply_text(locale("document_too_large", "message", locale=user_locale).format(str(configGet("file_size", "submission")/1024/1024)), quote=True)
|
||||||
# return
|
return
|
||||||
# if msg.animation.file_size > configGet("tmp_size", "submission"):
|
if msg.animation.file_size > configGet("tmp_size", "submission"):
|
||||||
# save_tmp = False
|
save_tmp = False
|
||||||
# contents = msg.animation.file_id, SubmissionType.ANIMATION #, msg.animation.file_name
|
contents = msg.animation.file_id, SubmissionType.ANIMATION #, msg.animation.file_name
|
||||||
|
|
||||||
# if msg.photo is not None:
|
if msg.photo is not None:
|
||||||
# contents = msg.photo.file_id, SubmissionType.PHOTO #, "please_generate"
|
contents = msg.photo.file_id, SubmissionType.PHOTO #, "please_generate"
|
||||||
|
|
||||||
# if save_tmp is not None:
|
if save_tmp is not None:
|
||||||
|
|
||||||
# if contents is None:
|
if contents is None:
|
||||||
# return
|
return
|
||||||
|
|
||||||
# tmp_id = str(uuid4())
|
tmp_id = str(uuid4())
|
||||||
# # filename = tmp_id if contents[1] == "please_generate" else contents[1]
|
# filename = tmp_id if contents[1] == "please_generate" else contents[1]
|
||||||
# makedirs(path.join(configGet("data", "locations"), "submissions", tmp_id), exist_ok=True)
|
makedirs(path.join(configGet("data", "locations"), "submissions", tmp_id), exist_ok=True)
|
||||||
# downloaded = await app.download_media(msg, path.join(configGet("data", "locations"), "submissions", tmp_id)+sep)
|
downloaded = await app.download_media(msg, path.join(configGet("data", "locations"), "submissions", tmp_id)+sep)
|
||||||
# inserted = col_submitted.insert_one(
|
inserted = col_submitted.insert_one(
|
||||||
# {
|
{
|
||||||
# "user": msg.from_user.id,
|
"user": msg.from_user.id,
|
||||||
# "date": datetime.now(tz=timezone.utc),
|
"date": datetime.now(),
|
||||||
# "done": False,
|
"done": False,
|
||||||
# "type": contents[1].value,
|
"type": contents[1].value,
|
||||||
# "temp": {
|
"temp": {
|
||||||
# "uuid": tmp_id,
|
"uuid": tmp_id,
|
||||||
# "file": path.basename(str(downloaded))
|
"file": path.basename(str(downloaded))
|
||||||
# },
|
},
|
||||||
# "telegram": {
|
"telegram": {
|
||||||
# "msg_id": msg.id,
|
"msg_id": msg.id,
|
||||||
# "file_id": contents[0]
|
"file_id": contents[0]
|
||||||
# },
|
},
|
||||||
# "caption": str(msg.caption) if msg.caption is not None else None
|
"caption": str(msg.caption) if msg.caption is not None else None
|
||||||
# }
|
}
|
||||||
# )
|
)
|
||||||
|
|
||||||
# else:
|
else:
|
||||||
|
|
||||||
# if contents is None:
|
if contents is None:
|
||||||
# return
|
return
|
||||||
|
|
||||||
# inserted = col_submitted.insert_one(
|
inserted = col_submitted.insert_one(
|
||||||
# {
|
{
|
||||||
# "user": msg.from_user.id,
|
"user": msg.from_user.id,
|
||||||
# "date": datetime.now(tz=timezone.utc),
|
"date": datetime.now(),
|
||||||
# "done": False,
|
"done": False,
|
||||||
# "type": contents[1].value,
|
"type": contents[1].value,
|
||||||
# "temp": {
|
"temp": {
|
||||||
# "uuid": None,
|
"uuid": None,
|
||||||
# "file": None
|
"file": None
|
||||||
# },
|
},
|
||||||
# "telegram": {
|
"telegram": {
|
||||||
# "msg_id": msg.id,
|
"msg_id": msg.id,
|
||||||
# "file_id": contents[0]
|
"file_id": contents[0]
|
||||||
# },
|
},
|
||||||
# "caption": str(msg.caption) if msg.caption is not None else None
|
"caption": str(msg.caption) if msg.caption is not None else None
|
||||||
# }
|
}
|
||||||
# )
|
)
|
||||||
|
|
||||||
# buttons = [
|
buttons = [
|
||||||
# [
|
[
|
||||||
# InlineKeyboardButton(text=locale("sub_yes", "button", locale=configGet("locale")), callback_data=f"sub_yes_{str(inserted.inserted_id)}")
|
InlineKeyboardButton(text=locale("sub_yes", "button", locale=configGet("locale")), callback_data=f"sub_yes_{str(inserted.inserted_id)}")
|
||||||
# ]
|
]
|
||||||
# ]
|
]
|
||||||
|
|
||||||
# if msg.caption is not None:
|
if msg.caption is not None:
|
||||||
# caption = str(msg.caption)
|
caption = str(msg.caption)
|
||||||
# buttons[0].append(
|
buttons[0].append(
|
||||||
# InlineKeyboardButton(text=locale("sub_yes_caption", "button", locale=configGet("locale")), callback_data=f"sub_yes_{str(inserted.inserted_id)}_caption")
|
InlineKeyboardButton(text=locale("sub_yes_caption", "button", locale=configGet("locale")), callback_data=f"sub_yes_{str(inserted.inserted_id)}_caption")
|
||||||
# )
|
)
|
||||||
# buttons[0].append(
|
buttons[0].append(
|
||||||
# InlineKeyboardButton(text=locale("sub_no", "button", locale=configGet("locale")), callback_data=f"sub_no_{str(inserted.inserted_id)}")
|
InlineKeyboardButton(text=locale("sub_no", "button", locale=configGet("locale")), callback_data=f"sub_no_{str(inserted.inserted_id)}")
|
||||||
# )
|
)
|
||||||
# else:
|
else:
|
||||||
# caption = ""
|
caption = ""
|
||||||
# buttons[0].append(
|
buttons[0].append(
|
||||||
# InlineKeyboardButton(text=locale("sub_no", "button", locale=configGet("locale")), callback_data=f"sub_no_{str(inserted.inserted_id)}")
|
InlineKeyboardButton(text=locale("sub_no", "button", locale=configGet("locale")), callback_data=f"sub_no_{str(inserted.inserted_id)}")
|
||||||
# )
|
)
|
||||||
|
|
||||||
# caption += locale("sub_by", "message", locale=locale(configGet("locale")))
|
caption += locale("sub_by", "message", locale=locale(configGet("locale")))
|
||||||
|
|
||||||
# if msg.from_user.first_name is not None:
|
if msg.from_user.first_name is not None:
|
||||||
# caption += f" {msg.from_user.first_name}"
|
caption += f" {msg.from_user.first_name}"
|
||||||
# if msg.from_user.last_name is not None:
|
if msg.from_user.last_name is not None:
|
||||||
# caption += f" {msg.from_user.last_name}"
|
caption += f" {msg.from_user.last_name}"
|
||||||
# if msg.from_user.username is not None:
|
if msg.from_user.username is not None:
|
||||||
# caption += f" (@{msg.from_user.username})"
|
caption += f" (@{msg.from_user.username})"
|
||||||
# if msg.from_user.phone_number is not None:
|
if msg.from_user.phone_number is not None:
|
||||||
# caption += f" ({msg.from_user.phone_number})"
|
caption += f" ({msg.from_user.phone_number})"
|
||||||
|
|
||||||
# if msg.from_user.id != configGet("admin"):
|
if msg.from_user.id in app.admins and configGet("admins", "submission", "require_confirmation") is False:
|
||||||
# buttons += [
|
try:
|
||||||
# [
|
await app.submit_photo(str(inserted.inserted_id))
|
||||||
# InlineKeyboardButton(text=locale("sub_block", "button", locale=configGet("locale")), callback_data=f"sub_block_{msg.from_user.id}")
|
await msg.reply_text(locale("sub_yes_auto", "message", locale=user_locale), disable_notification=True, quote=True)
|
||||||
# ]
|
await msg.copy(app.owner, caption=caption, disable_notification=True)
|
||||||
# # [
|
return
|
||||||
# # InlineKeyboardButton(text=locale("sub_unblock", "button", locale=configGet("locale")), callback_data=f"sub_unblock_{msg.from_user.id}")
|
except SubmissionDuplicatesError as exp:
|
||||||
# # ]
|
await msg.reply_text(locale("sub_media_duplicates_list", "message", locale=user_locale).format("\n • ".join(exp.duplicates)), quote=True)
|
||||||
# ]
|
return
|
||||||
|
except Exception as exp:
|
||||||
|
await msg.reply_text(format_exc(), quote=True)
|
||||||
|
return
|
||||||
|
elif msg.from_user.id not in app.admins and configGet("users", "submission", "require_confirmation") is False:
|
||||||
|
try:
|
||||||
|
await app.submit_photo(str(inserted.inserted_id))
|
||||||
|
await msg.reply_text(locale("sub_yes_auto", "message", locale=user_locale), disable_notification=True, quote=True)
|
||||||
|
await msg.copy(app.owner, caption=caption)
|
||||||
|
return
|
||||||
|
except SubmissionDuplicatesError as exp:
|
||||||
|
await msg.reply_text(locale("sub_dup", "message", locale=user_locale), quote=True)
|
||||||
|
return
|
||||||
|
except Exception as exp:
|
||||||
|
await app.send_message(app.owner, locale("sub_error_admin", "message").format(msg.from_user.id, format_exc()))
|
||||||
|
await msg.reply_text("sub_error", quote=True)
|
||||||
|
return
|
||||||
|
|
||||||
# await msg.reply_text(locale("sub_sent", "message", locale=user_locale), quote=True)
|
if msg.from_user.id not in app.admins:
|
||||||
# subLimit(msg.from_user)
|
buttons += [
|
||||||
|
[
|
||||||
|
InlineKeyboardButton(text=locale("sub_block", "button", locale=configGet("locale")), callback_data=f"sub_block_{msg.from_user.id}")
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
# await msg.copy(configGet("admin"), caption=caption, reply_markup=InlineKeyboardMarkup(buttons))
|
PosterUser(msg.from_user.id).limit()
|
||||||
|
|
||||||
# except AttributeError:
|
if msg.from_user.id != app.owner:
|
||||||
# logWrite(f"from_user in function get_submission does not seem to contain id")
|
await msg.reply_text(locale("sub_sent", "message", locale=user_locale), disable_notification=True, quote=True)
|
||||||
|
|
||||||
|
await msg.copy(app.owner, caption=caption, reply_markup=InlineKeyboardMarkup(buttons))
|
||||||
|
|
||||||
|
except AttributeError:
|
||||||
|
logWrite(f"from_user in function get_submission does not seem to contain id")
|
13
poster.py
13
poster.py
@@ -119,6 +119,7 @@ pid = getpid()
|
|||||||
from plugins.commands.general import *
|
from plugins.commands.general import *
|
||||||
|
|
||||||
if configGet("submit", "mode"):
|
if configGet("submit", "mode"):
|
||||||
|
from plugins.callbacks.nothing import *
|
||||||
from plugins.callbacks.submission import *
|
from plugins.callbacks.submission import *
|
||||||
from plugins.commands.mode_submit import *
|
from plugins.commands.mode_submit import *
|
||||||
from plugins.handlers.submission import *
|
from plugins.handlers.submission import *
|
||||||
@@ -174,19 +175,19 @@ if __name__ == "__main__":
|
|||||||
app.start()
|
app.start()
|
||||||
|
|
||||||
if configGet("startup", "reports"):
|
if configGet("startup", "reports"):
|
||||||
app.send_message(configGet("admin"), locale("startup", "message", locale=configGet("locale")).format(str(pid)))
|
app.send_message(app.owner, locale("startup", "message", locale=configGet("locale")).format(str(pid)))
|
||||||
|
|
||||||
if configGet("post", "mode"):
|
if configGet("post", "mode"):
|
||||||
scheduler.start()
|
scheduler.start()
|
||||||
|
|
||||||
if configGet("api_based", "mode"):
|
#if configGet("api_based", "mode"):
|
||||||
token = authorize()
|
# token = await authorize()
|
||||||
if len(get(f'{configGet("address", "posting", "api")}/albums?q={configGet("queue", "posting", "api", "albums")}', headers={"Authorization": f"Bearer {token}"}).json()["results"]) == 0:
|
# if len(get(f'{configGet("address", "posting", "api")}/albums?q={configGet("queue", "posting", "api", "albums")}', headers={"Authorization": f"Bearer {token}"}).json()["results"]) == 0:
|
||||||
post(f'{configGet("address", "posting", "api")}/albums?name={configGet("queue", "posting", "api", "albums")}&title={configGet("queue", "posting", "api", "albums")}', headers={"Authorization": f"Bearer {token}"})
|
# post(f'{configGet("address", "posting", "api")}/albums?name={configGet("queue", "posting", "api", "albums")}&title={configGet("queue", "posting", "api", "albums")}', headers={"Authorization": f"Bearer {token}"})
|
||||||
|
|
||||||
idle()
|
idle()
|
||||||
|
|
||||||
app.send_message(configGet("admin"), locale("shutdown", "message", locale=configGet("locale")).format(str(pid)))
|
app.send_message(app.owner, locale("shutdown", "message", locale=configGet("locale")).format(str(pid)))
|
||||||
logWrite(locale("shutdown", "console", locale=configGet("locale")).format(str(pid)))
|
logWrite(locale("shutdown", "console", locale=configGet("locale")).format(str(pid)))
|
||||||
|
|
||||||
killProc(pid)
|
killProc(pid)
|
@@ -3,3 +3,5 @@ pyrogram~=2.0.99
|
|||||||
requests~=2.28.2
|
requests~=2.28.2
|
||||||
psutil~=5.9.4
|
psutil~=5.9.4
|
||||||
pymongo~=4.3.3
|
pymongo~=4.3.3
|
||||||
|
pillow~=9.4.0
|
||||||
|
pytimeparse~=1.1.8
|
Reference in New Issue
Block a user