Compare commits
3 Commits
8cc7808afb
...
v0.1
Author | SHA1 | Date | |
---|---|---|---|
853c3c7cea | |||
e5f80d9702 | |||
6f03d5c18f |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -169,3 +169,4 @@ cython_debug/
|
||||
cache
|
||||
data
|
||||
logs
|
||||
config.json
|
20
.renovaterc
Normal file
20
.renovaterc
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"config:base"
|
||||
],
|
||||
"baseBranches": [
|
||||
"dev"
|
||||
],
|
||||
"packageRules": [
|
||||
{
|
||||
"matchUpdateTypes": [
|
||||
"minor",
|
||||
"patch",
|
||||
"pin",
|
||||
"digest"
|
||||
],
|
||||
"automerge": true
|
||||
}
|
||||
]
|
||||
}
|
73
README.md
73
README.md
@@ -11,7 +11,11 @@ This bot is used for one and only task - post pictures from my personal archive.
|
||||
|
||||
## Dependencies
|
||||
|
||||
For now bot requires [MongoDB](https://www.mongodb.com) and [PhotosAPI](https://git.end-play.xyz/profitroll/PhotosAPI) in order to function properly. Use [MongoDB's installation manual](https://www.mongodb.com/docs/manual/installation) and [Photos API's README](https://git.end-play.xyz/profitroll/PhotosAPI/src/branch/master/README.md) to install install them.
|
||||
* [Python 3.7+](https://www.python.org) (3.9+ recommended)
|
||||
* [MongoDB](https://www.mongodb.com)
|
||||
* [PhotosAPI](https://git.end-play.xyz/profitroll/PhotosAPI)
|
||||
|
||||
Use [MongoDB's installation manual](https://www.mongodb.com/docs/manual/installation) and [Photos API's README](https://git.end-play.xyz/profitroll/PhotosAPI/src/branch/master/README.md).
|
||||
|
||||
Please note that Photos API also requires MongoDB so it makes sense to install and configure Mongo first.
|
||||
|
||||
@@ -26,51 +30,58 @@ To make this bot run at first you need to have a Python interpreter, Photos API,
|
||||
> it in scripts you will use (`loop.sh`, `loop.bat`, `start.sh` and `start.bat`).
|
||||
|
||||
1. Install Mongo and Photos API:
|
||||
|
||||
1. Install MongoDB by following [official installation manual](https://www.mongodb.com/docs/manual/installation)
|
||||
2. Install Photos API by following [Photos API's README](https://git.end-play.xyz/profitroll/PhotosAPI/src/branch/master/README.md)
|
||||
|
||||
2. Download the bot:
|
||||
1. `git clone -b dev https://git.end-play.xyz/profitroll/TelegramSender.git` (if you want to use git)
|
||||
2. `cd ./TelegramSender`
|
||||
|
||||
3. Install project's dependencies:
|
||||
1. `git clone -b dev https://git.end-play.xyz/profitroll/TelegramPoster.git` (if you're using git)
|
||||
2. `cd TelegramPoster`
|
||||
|
||||
3. Create virtual environment [Optional]:
|
||||
|
||||
1. Install virtualenv module: `pip install virtualenv`
|
||||
2. Create venv: `python -m venv env`
|
||||
3. Activate it using `source venv/bin/activate` on Linux, `venv\Scripts\activate.bat` in CMD or `venv\Scripts\Activate.ps1` in PowerShell.
|
||||
|
||||
4. Install project's dependencies:
|
||||
|
||||
`python -m pip install -r requirements.txt`
|
||||
Without installing those - bot cannot work at all
|
||||
Without installing those - bot cannot work at all.
|
||||
|
||||
4. Install optional dependencies [Not required]:
|
||||
`python -m pip install -r requirements-optional.txt`
|
||||
These are not required but can make the bot run a bit faster
|
||||
5. Configure "bot" and "owner" with your favorite text editor:
|
||||
|
||||
1. Copy file `config_example.json` to `config.json`
|
||||
2. Open `config.json` using your favorite text editor. For example `nano config.json`, but you can edit with vim, nano, on Windows it's Notepad or Notepad++. Whatever
|
||||
3. Change `"owner"`, `"bot.api_id"`, `"bot.api_hash"` and `"bot.bot_token"` keys' values.
|
||||
|
||||
5. Configure your bot with a favorite text editor:
|
||||
`nano config.json`
|
||||
You can edit with vim, nano, on Windows it's Notepad or Notepad++. Whatever.
|
||||
If you don't know where to find bot_token and your id - here you can find some hints: [get bot token](https://www.siteguarding.com/en/how-to-get-telegram-bot-api-token), [get your id](https://www.alphr.com/telegram-find-user-id), [get api_hash and api_id](https://core.telegram.org/api/obtaining_api_id).
|
||||
|
||||
6. Configure database and API:
|
||||
|
||||
1. Configure database:
|
||||
1. Change database host and port in keys `"database.host"` and `"database.port"`;
|
||||
2. Change database name to the one you like in `"database.name"`;
|
||||
3. If you've changed user and password to access the db you should also change `"database.user"` and `"database.password"` keys, otherwise leave them `null` (default).
|
||||
1. Change database host and port in keys `"database.host"` and `"database.port"`. For default local installation those will be `127.0.0.1` and `27017` respectively
|
||||
2. Change database name to the one you like in `"database.name"`. It will be automatically created on start
|
||||
3. If you've changed user and password to access the db, you should also change `"database.user"` and `"database.password"` keys, otherwise leave them `null` (default).
|
||||
|
||||
2. Configure Photos API:
|
||||
1. Create new user and album
|
||||
1. Register new user using API's `POST /users` request (`/docs#/default/user_create_users_post`). Please make sure you're using a valid email address if you've configured you API to use email confirmation;
|
||||
2. If you have email confirmation - activate your new user by using `PATCH /users/{user}/confirm` (`/docs#/default/user_confirm_users__user__confirm_patch`) or by using the link from the email;
|
||||
3. Now create a new album for your bot using your user. Click "Authorize" on the docs page of your API, enter your login and password, select "select all" in scopes section and click "Authorize". Now you can execute requests as your user;
|
||||
4. Go to `POST /albums` (`docs#/default/album_create_albums_post`) and create a friendly name for your album. No worries, only bot can see it so it doesn't matter what name you use;
|
||||
2. Configure bot to use that album
|
||||
1. Now you can configure your bot to use all of that. Change key `"posting.api.address"` to the http/https address accessible by the bot. Avoid using external address without a reason if API and the bot are on the same machine. If you want to see duplicates from the outside you can also change `"posting.api.address_external"` to the one accessible from the internet;
|
||||
2. Configure API user/password and your album name using `"posting.api.username"`, `"posting.api.password"` and `"posting.api.album"` keys.
|
||||
1. Change `"posting.api.address"` to the one your API servers uses
|
||||
2. Run your bot using `python poster.py --create-user --create-album` to configure its new user and album. You can also use manual user and album creation described [in the wiki](https://git.end-play.xyz/profitroll/TelegramPoster/wiki/Configuring-API). You can also change username, password and album in`"posting.api"` to the user and album you have if you already have Photos API album and user set up. In that case you don't need to create a new one.
|
||||
|
||||
7. Add bot to the channel:
|
||||
|
||||
To use your bot of course you need to have a channel or group otherwise makes no sense to have such a bot. [Here](https://stackoverflow.com/a/33497769) you can find a quick guide how to add your bot to a channel. After that simply set `"posting.channel"` to your channel's ID.
|
||||
|
||||
8. Configure posting time:
|
||||
|
||||
To make your bot post random content you need to configure `"posting.time"` with a list of "DD:MM" formatted strings or use `"posting.interval"` formatted as "XdXhXmXs". To use interval instead of selected time set `"posting.use_interval"` to `true`.
|
||||
|
||||
9. Good to go, run it!
|
||||
Make sure MongoDB and Photos API are running and use `python ./main.py` to start it.
|
||||
|
||||
Make sure MongoDB and Photos API are running and use `python poster.py` to start it.
|
||||
Or you can also use `.\start.bat` on Windows and `bash ./start.sh` on Linux.
|
||||
Additionally there are `loop.sh` and `loop.bat` available if you want your bot to start again after being stopped or after using `/reboot` command.
|
||||
Additionally there are `loop.sh` and `loop.bat` available if you want your bot to start again after being stopped or after using `/shutdown` command.
|
||||
|
||||
If you need any further instructions on how to configure your bot or you had any difficulties doing so - please use [wiki in this repository](https://git.end-play.xyz/profitroll/TelegramPoster/wiki) to get more detailed instructions.
|
||||
|
||||
@@ -78,15 +89,17 @@ If you need any further instructions on how to configure your bot or you had any
|
||||
|
||||
Of course bot also has them. You can perform some actions with them.
|
||||
|
||||
* `--move-sent` - allows you to move all sent files from queue to sent directories
|
||||
* `--cleanup` - purge files in both `queue` and `sent` folders if they're sent. Requires `--confirm` argument
|
||||
* `--cleanup-index` - purge all sent entries from index. Requires `--confirm` argument
|
||||
* `--norun` - allows you to execute above arguments without triggering the bot start itself
|
||||
* `--create-user` - create new API user. Requires config key `"posting.api.address"` to be set;
|
||||
* `--create-album` - create new API album. Requires API address and user config (`"posting.api"`) to be complete.
|
||||
|
||||
Examples:
|
||||
|
||||
* `python3 ./main.py --move-sent --norun`
|
||||
* `python3 ./main.py --cleanup --confirm`
|
||||
* `python poster.py --create-user`
|
||||
* `python poster.py --create-user --create-album`
|
||||
|
||||
## Tips and improvements
|
||||
|
||||
* You may want to configure your bot to work as a systemd service instead. There's [a tutorial for that](https://git.end-play.xyz/profitroll/TelegramPoster/wiki/Configuring-Service) in the wiki.
|
||||
|
||||
## Localization
|
||||
|
||||
|
@@ -5,6 +5,8 @@
|
||||
<a href="https://git.end-play.xyz/profitroll/TelegramPoster"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
|
||||
</p>
|
||||
|
||||
## ⚠️ Українська версія README dev гілки ще не готова! Користуйтесь англійською! ⚠️
|
||||
|
||||
Цей бот використовується для однієї-єдиної задачі - розміщувати фотографії з мого особистого архіву. Ось його код, тож Ви також можете захостити бота самостійно та розважитися з ним. Тільки не очікуйте, що він ідеальним. Не буде. Але гей, Ви завжди можете його доробити під себе ;)
|
||||
|
||||
## Установка
|
||||
|
@@ -1,6 +1,6 @@
|
||||
from os import path, remove, sep
|
||||
from shutil import rmtree
|
||||
from typing import Union
|
||||
from typing import Tuple, Union
|
||||
from pyrogram.client import Client
|
||||
from pyrogram.types import Message
|
||||
from classes.exceptions import SubmissionDuplicatesError, SubmissionUnavailableError
|
||||
@@ -18,7 +18,9 @@ class PosterClient(Client):
|
||||
self.owner = configGet("owner")
|
||||
self.admins = configGet("admins") + [configGet("owner")]
|
||||
|
||||
async def submit_photo(self, id: str) -> Union[Message, None]:
|
||||
async def submit_photo(
|
||||
self, id: str
|
||||
) -> Tuple[Union[Message, None], Union[str, None]]:
|
||||
db_entry = col_submitted.find_one({"_id": ObjectId(id)})
|
||||
submission = None
|
||||
|
||||
@@ -87,7 +89,7 @@ class PosterClient(Client):
|
||||
f"Could not delete '{filepath}' on submission accepted", debug=True
|
||||
)
|
||||
|
||||
return submission
|
||||
return submission, response[2]
|
||||
|
||||
async def ban_user(self, id: int) -> None:
|
||||
pass
|
||||
|
@@ -23,6 +23,7 @@
|
||||
"reports": {
|
||||
"sent": false,
|
||||
"error": true,
|
||||
"update": true,
|
||||
"startup": true,
|
||||
"shutdown": true
|
||||
},
|
||||
@@ -86,14 +87,17 @@
|
||||
},
|
||||
"caption": {
|
||||
"enabled": false,
|
||||
"text": "sample text",
|
||||
"link": null
|
||||
"link": null,
|
||||
"text": [
|
||||
"sample text"
|
||||
]
|
||||
},
|
||||
"submission": {
|
||||
"timeout": 30,
|
||||
"file_size": 15728640,
|
||||
"tmp_size": 15728640,
|
||||
"allow_duplicates": false,
|
||||
"send_uploaded_id": false,
|
||||
"require_confirmation": {
|
||||
"users": true,
|
||||
"admins": true
|
||||
@@ -113,6 +117,7 @@
|
||||
"commands_admin": [
|
||||
"import",
|
||||
"export",
|
||||
"reboot"
|
||||
"remove",
|
||||
"shutdown"
|
||||
]
|
||||
}
|
@@ -1 +0,0 @@
|
||||
# Configuring virtual environment
|
1
docs/updating.md
Normal file
1
docs/updating.md
Normal file
@@ -0,0 +1 @@
|
||||
# Updating your bot
|
@@ -9,13 +9,16 @@
|
||||
"export": "Get .zip archive with all photos",
|
||||
"remove": "Delete photo by its ID",
|
||||
"purge": "Completely purge bot's queue",
|
||||
"reboot": "Restart the bot"
|
||||
"shutdown": "Turn off the bot"
|
||||
},
|
||||
"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!",
|
||||
"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}`",
|
||||
"startup": "Starting with pid `{0}`",
|
||||
"startup_downtime_minutes": "Starting with pid `{0}` (was down for {1} m.)",
|
||||
"startup_downtime_hours": "Starting with pid `{0}` (was down for {1} h.)",
|
||||
"startup_downtime_days": "Starting with pid `{0}` (was down for {1} d.)",
|
||||
"sub_yes": "✅ Submission approved and accepted",
|
||||
"sub_yes_auto": "✅ Submission automatically accepted",
|
||||
"sub_no": "❌ Submission reviewed and declined",
|
||||
@@ -37,9 +40,27 @@
|
||||
"post_low": "Low amount of content: `There are only {0} files left in the queue.`",
|
||||
"api_creds_invalid": "Could not authorize API access. Please check whether provided in config file are valid and update them if they're not.",
|
||||
"sub_wip": "Post submission is now WIP. It will be available again in a few days. Thank you for your patience.",
|
||||
"sub_duplicates_found": "__TO_BE_ADDED__",
|
||||
"sub_error": "⚠️ Could not upload this image due to bot error. Admins are advised.",
|
||||
"sub_error_admin": "User {0} could not submit photo without additional confirmation due to:\n```\n{1}\n```"
|
||||
"sub_error_admin": "User {0} could not submit photo without additional confirmation due to:\n```\n{1}\n```",
|
||||
"import_request": "Please send me a zip archive with your media to be imported. Use /cancel if you want to abort this operation.",
|
||||
"import_ignored": "No response, aborting import.",
|
||||
"import_abort": "Import aborted.",
|
||||
"import_invalid_media": "File to import must be a zip archive. Aborting.",
|
||||
"import_invalid_mime": "Provided file is not supported. Please send `application/zip`. Aborting.",
|
||||
"import_too_big": "You archive is `{0} GiB` big, but system has only `{1} GiB` free. Unpacking may take even more space. Aborting.",
|
||||
"import_downloading": "Downloading archive...",
|
||||
"import_unpacking": "Unpacking archive...",
|
||||
"import_unpack_error": "Could not unpack the archive\n\nException: {0}\n\nTraceback:\n```python\n{1}\n```",
|
||||
"import_uploading": "Uploading archive contents...",
|
||||
"import_upload_error_duplicate": "Could not upload `{0}` because there're duplicates on server.",
|
||||
"import_upload_error_other": "Could not upload `{0}`. Probably disallowed filetype.",
|
||||
"import_finished": "Import finished.",
|
||||
"remove_request": "Please send me an ID to delete. You might have it from upload dialog. Use /cancel if you want to abort this operation.",
|
||||
"remove_ignored": "No response, aborting removal.",
|
||||
"remove_abort": "Removal aborted.",
|
||||
"remove_success": "Removed media with ID `{0}`.",
|
||||
"remove_failure": "Could not remove media with ID `{0}`. Check if provided ID is correct and if it is - you can also check bot's log for details.",
|
||||
"update_available": "**New version found**\nThere's a newer version of a bot found. You can update your bot to [{0}]({1}) using command line of your host.\n\n**Release notes**\n{2}\n\nRead more about updating you bot on the [wiki page](https://git.end-play.xyz/profitroll/TelegramPoster/wiki/Updating-Instance).\n\nPlease not that you can also disable this notification by editing `reports.update` key of the config."
|
||||
},
|
||||
"button": {
|
||||
"sub_yes": "✅ Accept",
|
||||
@@ -59,13 +80,12 @@
|
||||
"sub_msg_unavail": "Submission message no longer exist",
|
||||
"sub_media_unavail": "Could not download submission",
|
||||
"sub_done": "You've already decided what to do with submission",
|
||||
"sub_upload_failed": "__TO_BE_ADDED__",
|
||||
"sub_duplicates_found": "There're duplicates in bot's database",
|
||||
"nothing": "🏁 This action is already finished"
|
||||
},
|
||||
"console": {
|
||||
"shutdown": "Shutting down bot with pid {0}",
|
||||
"startup":"Starting with pid {0}",
|
||||
"startup": "Starting with pid {0}",
|
||||
"keyboard_interrupt": "\nShutting down...",
|
||||
"exception_occured": "Exception {0} happened on task execution",
|
||||
"post_sent": "Sent {0} to {1} with caption {2} and silently {3}",
|
||||
@@ -94,6 +114,17 @@
|
||||
"cleanup_completed": "Performed cleanup of the sent files",
|
||||
"cleanup_unathorized": "Requested cleanup of sent files but not authorized. Please pass '--confirm' to perform that",
|
||||
"cleanup_index_completed": "Performed cleanup of sent files index",
|
||||
"cleanup_index_unathorized": "Requested cleanup of sent files index but not authorized. Please pass '--confirm' to perform that"
|
||||
"cleanup_index_unathorized": "Requested cleanup of sent files index but not authorized. Please pass '--confirm' to perform that",
|
||||
"random_pic_response": "Random pic response: {0}",
|
||||
"random_pic_error_code": "Could not get photos from album {0}: HTTP {1}",
|
||||
"random_pic_error_debug": "Could not get photos from '{0}/albums/{1}/photos?q=&page_size={2}&caption=queue' using token '{3}': HTTP {4}",
|
||||
"find_pic_error": "Could not find image with name '{0}' and caption '{1}' due to: {2}",
|
||||
"pic_upload_error": "Could not upload '{0}' to API: HTTP {1} with message '{2}'",
|
||||
"api_creds_invalid": "Incorrect API credentials! Could not login into '{0}' using login '{1}': HTTP {2}",
|
||||
"user_blocked": "User {0} has been blocked",
|
||||
"user_unblocked": "User {0} has been unblocked",
|
||||
"submission_accepted": "Submission with ID '{0}' accepted and uploaded with ID '{1}'",
|
||||
"submission_rejected": "Submission with ID '{0}' rejected",
|
||||
"submission_duplicate": "Submission with ID '{0}' could not be accepted because of the duplicates: {1}"
|
||||
}
|
||||
}
|
@@ -9,13 +9,16 @@
|
||||
"export": "Отримати .zip архів з усіма фотографіями",
|
||||
"remove": "Видалити фото за його ID",
|
||||
"purge": "Повністю видалити всю чергу бота",
|
||||
"reboot": "Перезапустити бота"
|
||||
"shutdown": "Вимкнути бота"
|
||||
},
|
||||
"message": {
|
||||
"start": "Привіт і ласкаво просимо!\n\nТут можна пропонувати свої фотографії та відео. Ми переглянемо та додамо їх, якщо вони нам сподобаються. Переконайтеся, що ви надсилаєте свої матеріали по одному та вибираєте медіа, які відповідають нашим правилам.\n\nВи також можете написати нам щось у полі опису. За потреби ми надішлемо це разом із самим фото.\n\nКрім того, переконайтеся, що ви дотримуєтеся /rules (правил) подання, інакше вашу пропозицію буде відхилено. У разі спаму/зловживань вас можуть навіть заблокувати.\n\nГарного дня та щасливого надсилання!",
|
||||
"rules": "Правила пропонування фото:\n1. Ніякого порно, тільки еротика та естетика\n2. Соски можна, але або завуальовані, або зовсім ледь помітні\n3. Геніталії суворо ні, а ось відбитки статевих губ на одязі або гарні лобочки/трусики/попки - без проблем\n4. Пропонувати русню заборонено",
|
||||
"shutdown": "Вимкнення бота з підом `{0}`",
|
||||
"startup": "Запуск бота з підом `{0}`",
|
||||
"startup_downtime_minutes": "Запуск бота з підом `{0}` (лежав {1} хв.)",
|
||||
"startup_downtime_hours": "Запуск бота з підом `{0}` (лежав {1} год.)",
|
||||
"startup_downtime_days": "Запуск бота з підом `{0}` (лежав {1} дн.)",
|
||||
"sub_yes": "✅ Подання схвалено та прийнято",
|
||||
"sub_yes_auto": "✅ Подання автоматично прийнято",
|
||||
"sub_no": "❌ Подання розглянуто та відхилено",
|
||||
@@ -37,9 +40,27 @@
|
||||
"post_low": "Мала кількість контенту: `Залишилось всього {0} файлів в черзі.`",
|
||||
"api_creds_invalid": "Не вдалося авторизувати запит до API. Будь ласка, перевірте чи дані авторизації в конфігураційному файлі вірні та оновіть їх, якщо це не так.",
|
||||
"sub_wip": "Подання постів зараз знаходиться у розробці. Він буде знову доступний через кілька днів. Дякуємо за ваше терпіння.",
|
||||
"sub_duplicates_found": "__TO_BE_ADDED__",
|
||||
"sub_error": "⚠️ Не вдалось завантажити фото через помилку бота. Адміністрацію повідомлено.",
|
||||
"sub_error_admin": "Користувач {0} не зміг надіслати фото без додаткової перевірки через помилку:\n```\n{1}\n```"
|
||||
"sub_error_admin": "Користувач {0} не зміг надіслати фото без додаткової перевірки через помилку:\n```\n{1}\n```",
|
||||
"import_request": "Будь ласка, надішліть zip-архів з медіа для імпортування. Використовуйте /cancel, якщо ви хочете перервати цю операцію.",
|
||||
"import_ignored": "Немає відповіді, перериваємо імпорт.",
|
||||
"import_abort": "Імпорт перервано.",
|
||||
"import_invalid_media": "Файл для імпорту має бути zip-архівом. Перериваємо.",
|
||||
"import_invalid_mime": "Наданий файл не підтримується. Будь ласка, надішліть `application/zip`. Перервано.",
|
||||
"import_too_big": "Ваш архів має розмір `{0} GiB`, але система має лише `{1} GiB` вільних. Розпакування може зайняти значно більше місця. Перервано.",
|
||||
"import_downloading": "Завантажуємо архів...",
|
||||
"import_unpacking": "Розпаковуємо архів...",
|
||||
"import_unpack_error": "Не вдалося розпакувати архів\n\nПомилка: {0}\n\nTraceback:\n```python\n{1}\n```",
|
||||
"import_uploading": "Завантажуємо вміст архіву...",
|
||||
"import_upload_error_duplicate": "Не вдалося завантажити `{0}`, оскільки на сервері є дублікати.",
|
||||
"import_upload_error_other": "Не вдалося завантажити `{0}`. Ймовірно, заборонений тип файлу.",
|
||||
"import_finished": "Імпорт завершено.",
|
||||
"remove_request": "Будь ласка, надішліть мені ID для видалення. Ви могли отримати його з діалогу завантаження. Використовуйте /cancel, якщо ви хочете перервати цю операцію.",
|
||||
"remove_ignored": "Немає відповіді, перериваємо видалення.",
|
||||
"remove_abort": "Видалення перервано.",
|
||||
"remove_success": "Видалено медіа з ID `{0}`.",
|
||||
"remove_failure": "Не вдалося видалити медіа з ID `{0}`. Перевірте, чи вказано правильний ID, і якщо він правильний, ви також можете переглянути логи бота для отримання більш детальної інформації.",
|
||||
"update_available": "**Знайдено нову версію**\nЗнайдено нову версію бота. Ви можете оновити бота до [{0}]({1}) за допомогою командного рядка вашого хосту.\n\n**Примітки до релізу**\n{2}\n\nДетальніше про оновлення бота можна знайти на [вікі-сторінці](https://git.end-play.xyz/profitroll/TelegramPoster/wiki/Updating-Instance).\n\nЗверніть увагу, що ви також можете вимкнути це сповіщення, відредагувавши ключ `reports.update` у конфігурації."
|
||||
},
|
||||
"button": {
|
||||
"sub_yes": "✅ Прийняти",
|
||||
@@ -59,7 +80,6 @@
|
||||
"sub_msg_unavail": "Повідомлення більше не існує",
|
||||
"sub_media_unavail": "Не вдалося завантажити подання",
|
||||
"sub_done": "Ви вже обрали що зробити з цим поданням",
|
||||
"sub_upload_failed": "__TO_BE_ADDED__",
|
||||
"sub_duplicates_found": "Знайдено дублікати в базі даних бота",
|
||||
"nothing": "🏁 Цю дію вже було завершено"
|
||||
},
|
||||
@@ -94,6 +114,17 @@
|
||||
"cleanup_completed": "Виконано очищення надісланих файлів",
|
||||
"cleanup_unathorized": "Надіслано запит на очищення надісланих файлів, але не авторизовано. Для цього надайте аргумент '--confirm'",
|
||||
"cleanup_index_completed": "Виконано очищення індексу надісланих файлів",
|
||||
"cleanup_index_unathorized": "Надіслано запит на очищення індексу надісланих файлів, але не авторизовано. Для цього надайте аргумент '--confirm'"
|
||||
"cleanup_index_unathorized": "Надіслано запит на очищення індексу надісланих файлів, але не авторизовано. Для цього надайте аргумент '--confirm'",
|
||||
"random_pic_response": "Відповідь на пошук випадкової картинки: {0}",
|
||||
"random_pic_error_code": "Не вдалося отримати фото з альбому {0}: HTTP {1}",
|
||||
"random_pic_error_debug": "Не вдалося отримати фотографії з '{0}/albums/{1}/photos?q=&page_size={2}&caption=queue', використовуючи токен '{3}': HTTP {4}",
|
||||
"find_pic_error": "Не вдалося знайти зображення з назвою '{0}' та підписом '{1}' через: {2}",
|
||||
"pic_upload_error": "Не вдалося завантажити '{0}' до API: HTTP {1} з повідомленням '{2}'",
|
||||
"api_creds_invalid": "Невірні облікові дані API! Не вдалося увійти в '{0}' за допомогою логіна '{1}': HTTP {2}",
|
||||
"user_blocked": "Користувача {0} було заблоковано",
|
||||
"user_unblocked": "Користувача {0} було розблоковано",
|
||||
"submission_accepted": "Подання з ID '{0}' прийнято та завантажено з ID '{1}'",
|
||||
"submission_rejected": "Подання з ID '{0}' відхилено",
|
||||
"submission_duplicate": "Подання з ID '{0}' не може бути прийнято через наявність дублікатів: {1}"
|
||||
}
|
||||
}
|
@@ -8,8 +8,7 @@ from traceback import print_exc
|
||||
from typing import Tuple, Union
|
||||
|
||||
import aiofiles
|
||||
from aiohttp import ClientSession, FormData
|
||||
from ujson import dumps
|
||||
from aiohttp import FormData
|
||||
|
||||
from classes.exceptions import (
|
||||
AlbumCreationDuplicateError,
|
||||
@@ -20,11 +19,8 @@ from classes.exceptions import (
|
||||
UserCreationError,
|
||||
)
|
||||
from modules.logger import logWrite
|
||||
from modules.utils import configGet
|
||||
|
||||
http_session = ClientSession(
|
||||
json_serialize=dumps,
|
||||
)
|
||||
from modules.utils import configGet, locale
|
||||
from modules.http_client import http_session
|
||||
|
||||
|
||||
async def authorize() -> str:
|
||||
@@ -52,7 +48,15 @@ async def authorize() -> str:
|
||||
)
|
||||
if not response.ok:
|
||||
logWrite(
|
||||
f'Incorrect API credentials! Could not login into "{configGet("address", "posting", "api")}" using login "{configGet("username", "posting", "api")}": HTTP {response.status}'
|
||||
locale(
|
||||
"api_creds_invalid",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(
|
||||
configGet("address", "posting", "api"),
|
||||
configGet("username", "posting", "api"),
|
||||
response.status,
|
||||
),
|
||||
)
|
||||
)
|
||||
raise ValueError
|
||||
async with aiofiles.open(
|
||||
@@ -78,13 +82,34 @@ async def random_pic(token: Union[str, None] = None) -> Tuple[str, str]:
|
||||
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}"},
|
||||
)
|
||||
print(await resp.json(), flush=True)
|
||||
logWrite(
|
||||
locale("random_pic_response", "console", locale=configGet("locale_log")).format(
|
||||
await resp.json()
|
||||
),
|
||||
debug=True,
|
||||
)
|
||||
if resp.status != 200:
|
||||
logWrite(
|
||||
f'Could not get photos from album {configGet("album", "posting", "api")}: HTTP {resp.status}'
|
||||
locale(
|
||||
"random_pic_error_code",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(
|
||||
configGet("album", "posting", "api"), resp.status
|
||||
),
|
||||
),
|
||||
)
|
||||
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}',
|
||||
locale(
|
||||
"random_pic_error_debug",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(
|
||||
configGet("address", "posting", "api"),
|
||||
configGet("album", "posting", "api"),
|
||||
configGet("page_size", "posting"),
|
||||
token,
|
||||
resp.status,
|
||||
),
|
||||
),
|
||||
debug=True,
|
||||
)
|
||||
raise ValueError
|
||||
@@ -96,7 +121,7 @@ async def random_pic(token: Union[str, None] = None) -> Tuple[str, str]:
|
||||
|
||||
async def upload_pic(
|
||||
filepath: str, allow_duplicates: bool = False, token: Union[str, None] = None
|
||||
) -> Tuple[bool, list]:
|
||||
) -> Tuple[bool, list, Union[str, None]]:
|
||||
token = await authorize() if token is None else token
|
||||
try:
|
||||
pic_name = path.basename(filepath)
|
||||
@@ -117,28 +142,36 @@ async def upload_pic(
|
||||
headers={"Authorization": f"Bearer {token}"},
|
||||
data=formdata,
|
||||
)
|
||||
response_json = await response.json()
|
||||
if response.status != 200 and response.status != 409:
|
||||
logWrite(
|
||||
f"Could not upload '{filepath}' to API: HTTP {response.status} with message '{response.content}'"
|
||||
locale(
|
||||
"pic_upload_error",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(
|
||||
filepath, response.status, response.content
|
||||
),
|
||||
),
|
||||
)
|
||||
raise SubmissionUploadError(
|
||||
str(filepath), response.status, response.content
|
||||
)
|
||||
id = response_json["id"] if "id" in await response.json() else None
|
||||
duplicates = []
|
||||
if "duplicates" in (await response.json()):
|
||||
for index, duplicate in enumerate((await response.json())["duplicates"]):
|
||||
if (await response.json())["access_token"] is None:
|
||||
if "duplicates" in response_json:
|
||||
for index, duplicate in enumerate(response_json["duplicates"]): # type: ignore
|
||||
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/{(await response.json())["access_token"]}?id={index}'
|
||||
f'`{duplicate["id"]}`:\n{configGet("address_external", "posting", "api")}/token/photo/{response_json["access_token"]}?id={index}'
|
||||
)
|
||||
return True, duplicates
|
||||
return True, duplicates, id
|
||||
except Exception as exp:
|
||||
print_exc()
|
||||
return False, []
|
||||
return False, [], None
|
||||
|
||||
|
||||
async def find_pic(
|
||||
@@ -159,7 +192,11 @@ async def find_pic(
|
||||
return (await response.json())["results"]
|
||||
except Exception as exp:
|
||||
logWrite(
|
||||
f"Could not find image with name '{name}' and caption '{caption}' due to: {exp}"
|
||||
locale(
|
||||
"find_pic_error",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(name, caption, exp),
|
||||
),
|
||||
)
|
||||
return None
|
||||
|
||||
@@ -167,10 +204,28 @@ async def find_pic(
|
||||
async def move_pic(id: str, token: Union[str, None] = None) -> bool:
|
||||
token = await authorize() if token is None else token
|
||||
try:
|
||||
await http_session.patch(
|
||||
response = await http_session.patch(
|
||||
f'{configGet("address", "posting", "api")}/photos/{id}?caption=sent',
|
||||
headers={"Authorization": f"Bearer {token}"},
|
||||
)
|
||||
if response.status != 200:
|
||||
logWrite(f"Media moving failed with HTTP {response.status}", debug=True)
|
||||
return False
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
|
||||
async def remove_pic(id: str, token: Union[str, None] = None) -> bool:
|
||||
token = await authorize() if token is None else token
|
||||
try:
|
||||
response = await http_session.delete(
|
||||
f'{configGet("address", "posting", "api")}/photos/{id}',
|
||||
headers={"Authorization": f"Bearer {token}"},
|
||||
)
|
||||
if response.status != 204:
|
||||
logWrite(f"Media removal failed with HTTP {response.status}", debug=True)
|
||||
return False
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
@@ -1,5 +1,6 @@
|
||||
from modules.utils import configGet
|
||||
from classes.poster_client import PosterClient
|
||||
from convopyro import Conversation
|
||||
|
||||
app = PosterClient(
|
||||
"duptsiaposter",
|
||||
@@ -7,3 +8,7 @@ app = PosterClient(
|
||||
api_id=configGet("api_id", "bot"),
|
||||
api_hash=configGet("api_hash", "bot"),
|
||||
)
|
||||
|
||||
Conversation(app)
|
||||
|
||||
users_with_context = []
|
||||
|
@@ -26,7 +26,7 @@ async def cli_create_user() -> None:
|
||||
email = input(f"Choose email for user '{username}': ").strip()
|
||||
password = input(f"Choose password for user '{username}': ").strip()
|
||||
try:
|
||||
result = await create_user(username, email, password)
|
||||
result_1 = await create_user(username, email, password)
|
||||
# asyncio.run(create_user(username, email, password))
|
||||
configSet("username", username, "posting", "api")
|
||||
configSet("password", password, "posting", "api")
|
||||
@@ -41,6 +41,7 @@ async def cli_create_user() -> None:
|
||||
print("You're done!", flush=True)
|
||||
await http_session.close()
|
||||
exit()
|
||||
return None
|
||||
|
||||
|
||||
async def cli_create_album() -> None:
|
||||
@@ -51,7 +52,7 @@ async def cli_create_album() -> None:
|
||||
name = input("Choose a name for your album: ").strip()
|
||||
title = input(f"Choose a title for album '{name}': ").strip()
|
||||
try:
|
||||
result = await create_album(name, title)
|
||||
result_2 = await create_album(name, title)
|
||||
# asyncio.run(create_album(name, title))
|
||||
configSet("album", name, "posting", "api")
|
||||
except Exception as exp:
|
||||
@@ -61,6 +62,7 @@ async def cli_create_album() -> None:
|
||||
print("You're done!", flush=True)
|
||||
await http_session.close()
|
||||
exit()
|
||||
return None
|
||||
|
||||
|
||||
if args.create_user or args.create_album:
|
||||
@@ -68,10 +70,9 @@ if args.create_user or args.create_album:
|
||||
tasks = []
|
||||
|
||||
if args.create_user:
|
||||
tasks.append(loop.create_task(cli_create_user()))
|
||||
loop.run_until_complete(asyncio.wait([loop.create_task(cli_create_user())]))
|
||||
|
||||
if args.create_album:
|
||||
tasks.append(loop.create_task(cli_create_album()))
|
||||
loop.run_until_complete(asyncio.wait([loop.create_task(cli_create_album())]))
|
||||
|
||||
loop.run_until_complete(asyncio.wait(tasks))
|
||||
loop.close()
|
||||
|
6
modules/http_client.py
Normal file
6
modules/http_client.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from aiohttp import ClientSession
|
||||
from ujson import dumps
|
||||
|
||||
http_session = ClientSession(
|
||||
json_serialize=dumps,
|
||||
)
|
@@ -1,5 +1,6 @@
|
||||
from datetime import datetime
|
||||
from os import makedirs, path
|
||||
from random import choice
|
||||
from shutil import rmtree
|
||||
from traceback import format_exc
|
||||
from uuid import uuid4
|
||||
@@ -129,9 +130,9 @@ async def send_content(app: PosterClient) -> None:
|
||||
|
||||
if configGet("enabled", "caption"):
|
||||
if configGet("link", "caption") != None:
|
||||
caption = f"{caption}[{configGet('text', 'caption')}]({configGet('link', 'caption')})"
|
||||
caption = f"{caption}[{choice(configGet('text', 'caption'))}]({configGet('link', 'caption')})"
|
||||
else:
|
||||
caption = f"{caption}{configGet('text', 'caption')}"
|
||||
caption = f"{caption}{choice(configGet('text', 'caption'))}"
|
||||
else:
|
||||
caption = caption
|
||||
|
||||
|
119
modules/utils.py
119
modules/utils.py
@@ -1,14 +1,96 @@
|
||||
from os import kill
|
||||
from os import kill, makedirs
|
||||
from os import name as osname
|
||||
from os import sep
|
||||
from os import path, sep
|
||||
from sys import exit
|
||||
from traceback import print_exc
|
||||
from typing import Any
|
||||
from zipfile import ZipFile
|
||||
|
||||
import aiofiles
|
||||
from ujson import JSONDecodeError, dumps, loads
|
||||
|
||||
from modules.logger import logWrite
|
||||
|
||||
default_config = {
|
||||
"locale": "en",
|
||||
"locale_log": "en",
|
||||
"locale_fallback": "en",
|
||||
"owner": 0,
|
||||
"admins": [],
|
||||
"bot": {"api_id": 0, "api_hash": "", "bot_token": ""},
|
||||
"database": {
|
||||
"user": None,
|
||||
"password": None,
|
||||
"host": "127.0.0.1",
|
||||
"port": 27017,
|
||||
"name": "tgposter",
|
||||
},
|
||||
"mode": {"post": True, "submit": True},
|
||||
"reports": {"sent": False, "error": True, "startup": True, "shutdown": True},
|
||||
"logging": {"size": 512, "location": "logs"},
|
||||
"locations": {
|
||||
"tmp": "tmp",
|
||||
"data": "data",
|
||||
"cache": "cache",
|
||||
"sent": "data/sent",
|
||||
"queue": "data/queue",
|
||||
"index": "data/index.json",
|
||||
"locale": "locale",
|
||||
},
|
||||
"posting": {
|
||||
"channel": 0,
|
||||
"silent": False,
|
||||
"move_sent": False,
|
||||
"use_interval": False,
|
||||
"interval": "1h30m",
|
||||
"page_size": 300,
|
||||
"submitted_caption": {
|
||||
"enabled": True,
|
||||
"ignore_admins": True,
|
||||
"text": "#submitted",
|
||||
},
|
||||
"extensions": {
|
||||
"photo": ["jpg", "png", "gif", "jpeg"],
|
||||
"video": ["mp4", "avi", "mkv", "webm", "mov"],
|
||||
},
|
||||
"time": [
|
||||
"08:00",
|
||||
"10:00",
|
||||
"12:00",
|
||||
"14:00",
|
||||
"16:00",
|
||||
"18:00",
|
||||
"20:00",
|
||||
"22:00",
|
||||
],
|
||||
"api": {
|
||||
"address": "http://localhost:8054",
|
||||
"address_external": "https://photos.domain.com",
|
||||
"username": "",
|
||||
"password": "",
|
||||
"album": "",
|
||||
},
|
||||
},
|
||||
"caption": {"enabled": False, "link": None, "text": ["sample text"]},
|
||||
"submission": {
|
||||
"timeout": 30,
|
||||
"file_size": 15728640,
|
||||
"tmp_size": 15728640,
|
||||
"allow_duplicates": False,
|
||||
"send_uploaded_id": False,
|
||||
"require_confirmation": {"users": True, "admins": True},
|
||||
"mime_types": [
|
||||
"image/png",
|
||||
"image/gif",
|
||||
"image/jpeg",
|
||||
"video/mp4",
|
||||
"video/quicktime",
|
||||
],
|
||||
},
|
||||
"commands": ["start", "rules"],
|
||||
"commands_admin": ["import", "export", "shutdown"],
|
||||
}
|
||||
|
||||
|
||||
def jsonLoad(filename: str) -> Any:
|
||||
"""Loads arg1 as json and returns its contents"""
|
||||
@@ -73,9 +155,20 @@ def configGet(key: str, *args: str):
|
||||
* any: Value of provided key
|
||||
"""
|
||||
this_dict = jsonLoad("config.json")
|
||||
try:
|
||||
this_key = this_dict
|
||||
for dict_key in args:
|
||||
this_key = this_key[dict_key]
|
||||
this_key[key]
|
||||
except KeyError:
|
||||
print(
|
||||
f"Could not find config key '{key}' under path {args}: falling back to default config",
|
||||
flush=True,
|
||||
)
|
||||
this_key = default_config
|
||||
for dict_key in args:
|
||||
this_key = this_key[dict_key]
|
||||
configSet(key, this_key[key], *args)
|
||||
return this_key[key]
|
||||
|
||||
|
||||
@@ -116,6 +209,28 @@ def locale(key: str, *args: str, locale=configGet("locale")):
|
||||
return f'⚠️ Locale in config is invalid: could not get "{key}" in {str(args)} from locale "{locale}"'
|
||||
|
||||
|
||||
async def extract_and_save(handle: ZipFile, filename: str, destpath: str):
|
||||
"""Extract and save file from archive
|
||||
|
||||
Args:
|
||||
* handle (ZipFile): ZipFile handler
|
||||
* filename (str): File base name
|
||||
* path (str): Path where to store
|
||||
"""
|
||||
data = handle.read(filename)
|
||||
filepath = path.join(destpath, filename)
|
||||
try:
|
||||
makedirs(path.dirname(filepath), exist_ok=True)
|
||||
async with aiofiles.open(filepath, "wb") as fd:
|
||||
await fd.write(data)
|
||||
logWrite(f"Unzipped {filename}", debug=True)
|
||||
except IsADirectoryError:
|
||||
makedirs(filepath, exist_ok=True)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
return
|
||||
|
||||
|
||||
try:
|
||||
from psutil import Process
|
||||
except ModuleNotFoundError:
|
||||
|
29
plugins/callbacks/shutdown.py
Normal file
29
plugins/callbacks/shutdown.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from os import getpid, makedirs, path
|
||||
from time import time
|
||||
from modules.app import app
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import CallbackQuery
|
||||
from classes.poster_client import PosterClient
|
||||
from modules.scheduler import scheduler
|
||||
from modules.logger import logWrite
|
||||
from modules.utils import configGet, jsonSave, locale
|
||||
|
||||
|
||||
@app.on_callback_query(filters.regex("shutdown"))
|
||||
async def callback_query_nothing(app: PosterClient, clb: CallbackQuery):
|
||||
if clb.from_user.id in app.admins:
|
||||
pid = getpid()
|
||||
logWrite(f"Shutting down bot with pid {pid}")
|
||||
await clb.answer()
|
||||
await clb.message.reply_text(
|
||||
locale("shutdown", "message", locale=clb.from_user.language_code).format(
|
||||
pid
|
||||
),
|
||||
)
|
||||
scheduler.shutdown()
|
||||
makedirs(configGet("cache", "locations"), exist_ok=True)
|
||||
jsonSave(
|
||||
{"timestamp": time()},
|
||||
path.join(configGet("cache", "locations"), "shutdown_time"),
|
||||
)
|
||||
exit()
|
@@ -7,6 +7,7 @@ from classes.poster_client import PosterClient
|
||||
from classes.user import PosterUser
|
||||
|
||||
from modules.app import app
|
||||
from modules.logger import logWrite
|
||||
from modules.utils import configGet, locale
|
||||
from modules.database import col_submitted
|
||||
from bson import ObjectId
|
||||
@@ -38,11 +39,22 @@ async def callback_query_yes(app: PosterClient, clb: CallbackQuery):
|
||||
),
|
||||
quote=True,
|
||||
)
|
||||
logWrite(
|
||||
locale(
|
||||
"submission_duplicate",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(
|
||||
fullclb[2],
|
||||
str(exp.duplicates),
|
||||
),
|
||||
),
|
||||
debug=True,
|
||||
)
|
||||
return
|
||||
|
||||
if submission is not None:
|
||||
await submission.reply_text(
|
||||
locale("sub_yes", "message", locale=submission.from_user.language_code),
|
||||
if submission[0] is not None:
|
||||
await submission[0].reply_text(
|
||||
locale("sub_yes", "message", locale=submission[0].from_user.language_code),
|
||||
quote=True,
|
||||
)
|
||||
elif db_entry is not None:
|
||||
@@ -73,10 +85,25 @@ async def callback_query_yes(app: PosterClient, clb: CallbackQuery):
|
||||
]
|
||||
]
|
||||
)
|
||||
|
||||
if configGet("send_uploaded_id", "submission"):
|
||||
await clb.message.edit_caption(
|
||||
clb.message.caption + f"\n\nID: `{submission[1]}`"
|
||||
)
|
||||
|
||||
await clb.message.edit_reply_markup(
|
||||
reply_markup=InlineKeyboardMarkup(edited_markup)
|
||||
)
|
||||
|
||||
logWrite(
|
||||
locale(
|
||||
"submission_accepted",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(fullclb[2], submission[1]),
|
||||
),
|
||||
debug=True,
|
||||
)
|
||||
|
||||
# try:
|
||||
# if configGet("api_based", "mode") is True:
|
||||
# media = await app.download_media(submission, file_name=configGet("tmp", "locations")+sep)
|
||||
@@ -167,6 +194,14 @@ async def callback_query_no(app: PosterClient, clb: CallbackQuery):
|
||||
await clb.message.edit_reply_markup(
|
||||
reply_markup=InlineKeyboardMarkup(edited_markup)
|
||||
)
|
||||
logWrite(
|
||||
locale(
|
||||
"submission_rejected",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(fullclb[2]),
|
||||
),
|
||||
debug=True,
|
||||
)
|
||||
|
||||
|
||||
@app.on_callback_query(filters.regex("sub_block_[\s\S]*"))
|
||||
@@ -194,6 +229,14 @@ async def callback_query_block(app: PosterClient, clb: CallbackQuery):
|
||||
await clb.message.edit_reply_markup(
|
||||
reply_markup=InlineKeyboardMarkup(edited_markup)
|
||||
)
|
||||
logWrite(
|
||||
locale(
|
||||
"user_blocked",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(fullclb[2]),
|
||||
),
|
||||
debug=True,
|
||||
)
|
||||
|
||||
|
||||
@app.on_callback_query(filters.regex("sub_unblock_[\s\S]*"))
|
||||
@@ -221,3 +264,11 @@ async def callback_query_unblock(app: PosterClient, clb: CallbackQuery):
|
||||
await clb.message.edit_reply_markup(
|
||||
reply_markup=InlineKeyboardMarkup(edited_markup)
|
||||
)
|
||||
logWrite(
|
||||
locale(
|
||||
"user_unblocked",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(fullclb[2]),
|
||||
),
|
||||
debug=True,
|
||||
)
|
||||
|
@@ -1,24 +1,45 @@
|
||||
from os import getpid
|
||||
from os import getpid, makedirs, path
|
||||
from time import time
|
||||
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
||||
|
||||
from classes.poster_client import PosterClient
|
||||
from pyrogram.types import Message
|
||||
|
||||
from modules.app import app
|
||||
from modules.app import app, users_with_context
|
||||
from modules.logger import logWrite
|
||||
from modules.utils import configGet, killProc, locale
|
||||
from modules.scheduler import scheduler
|
||||
from modules.utils import configGet, jsonSave, locale
|
||||
|
||||
|
||||
@app.on_message(
|
||||
~filters.scheduled & filters.command(["kill", "die", "reboot"], prefixes=["", "/"])
|
||||
)
|
||||
@app.on_message(~filters.scheduled & filters.command(["shutdown"], prefixes=["", "/"]))
|
||||
async def cmd_kill(app: PosterClient, msg: Message):
|
||||
if msg.from_user.id in app.admins:
|
||||
pid = getpid()
|
||||
logWrite(
|
||||
locale("shutdown", "console", locale=configGet("locale")).format(str(pid))
|
||||
)
|
||||
global users_with_context
|
||||
if len(users_with_context) > 0:
|
||||
await msg.reply_text(
|
||||
locale("shutdown", "message", locale=configGet("locale")).format(str(pid))
|
||||
f"There're {len(users_with_context)} unfinished users' contexts. If you turn off the bot, those will be lost. Please confirm shutdown using a button below.",
|
||||
reply_markup=InlineKeyboardMarkup(
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
"Confirm shutdown", callback_data="shutdown"
|
||||
)
|
||||
killProc(pid)
|
||||
]
|
||||
]
|
||||
),
|
||||
)
|
||||
return
|
||||
pid = getpid()
|
||||
logWrite(f"Shutting down bot with pid {pid}")
|
||||
await msg.reply_text(
|
||||
locale("shutdown", "message", locale=msg.from_user.language_code).format(
|
||||
pid
|
||||
),
|
||||
)
|
||||
scheduler.shutdown()
|
||||
makedirs(configGet("cache", "locations"), exist_ok=True)
|
||||
jsonSave(
|
||||
{"timestamp": time()},
|
||||
path.join(configGet("cache", "locations"), "shutdown_time"),
|
||||
)
|
||||
exit()
|
||||
|
@@ -1,14 +1,160 @@
|
||||
import asyncio
|
||||
from glob import iglob
|
||||
from os import getcwd, makedirs, path, remove
|
||||
from shutil import disk_usage, rmtree
|
||||
from traceback import format_exc
|
||||
from uuid import uuid4
|
||||
from zipfile import ZipFile
|
||||
|
||||
from convopyro import listen_message
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
from classes.poster_client import PosterClient
|
||||
from modules.app import app
|
||||
from modules.api_client import remove_pic, upload_pic
|
||||
from modules.app import app, users_with_context
|
||||
from modules.logger import logWrite
|
||||
from modules.utils import configGet, extract_and_save, locale
|
||||
|
||||
|
||||
@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
|
||||
global users_with_context
|
||||
if msg.from_user.id not in users_with_context:
|
||||
users_with_context.append(msg.from_user.id)
|
||||
else:
|
||||
return
|
||||
await msg.reply_text(
|
||||
locale("import_request", "message", locale=msg.from_user.language_code)
|
||||
)
|
||||
answer = await listen_message(app, msg.chat.id, timeout=600)
|
||||
users_with_context.remove(msg.from_user.id)
|
||||
if answer is None:
|
||||
await msg.reply_text(
|
||||
locale("import_ignored", "message", locale=msg.from_user.language_code),
|
||||
quote=True,
|
||||
)
|
||||
return
|
||||
if answer.text == "/cancel":
|
||||
await answer.reply_text(
|
||||
locale("import_abort", "message", locale=msg.from_user.language_code)
|
||||
)
|
||||
return
|
||||
if answer.document is None:
|
||||
await answer.reply_text(
|
||||
locale(
|
||||
"import_invalid_media",
|
||||
"message",
|
||||
locale=msg.from_user.language_code,
|
||||
),
|
||||
quote=True,
|
||||
)
|
||||
return
|
||||
if answer.document.mime_type != "application/zip":
|
||||
await answer.reply_text(
|
||||
locale(
|
||||
"import_invalid_mime", "message", locale=msg.from_user.language_code
|
||||
),
|
||||
quote=True,
|
||||
)
|
||||
return
|
||||
if disk_usage(getcwd())[2] < (answer.document.file_size) * 3:
|
||||
await msg.reply_text(
|
||||
locale(
|
||||
"import_too_big", "message", locale=msg.from_user.language_code
|
||||
).format(
|
||||
answer.document.file_size // (2**30),
|
||||
disk_usage(getcwd())[2] // (2**30),
|
||||
)
|
||||
)
|
||||
return
|
||||
tmp_dir = str(uuid4())
|
||||
logWrite(
|
||||
f"Importing '{answer.document.file_name}' file {answer.document.file_size} bytes big (TMP ID {tmp_dir})"
|
||||
)
|
||||
makedirs(path.join(configGet("tmp", "locations"), tmp_dir), exist_ok=True)
|
||||
tmp_path = path.join(configGet("tmp", "locations"), answer.document.file_id)
|
||||
downloading = await answer.reply_text(
|
||||
locale("import_downloading", "message", locale=msg.from_user.language_code),
|
||||
quote=True,
|
||||
)
|
||||
await app.download_media(answer, file_name=tmp_path)
|
||||
await downloading.edit(
|
||||
locale("import_unpacking", "message", locale=msg.from_user.language_code)
|
||||
)
|
||||
try:
|
||||
with ZipFile(tmp_path, "r") as handle:
|
||||
tasks = [
|
||||
extract_and_save(
|
||||
handle, name, path.join(configGet("tmp", "locations"), tmp_dir)
|
||||
)
|
||||
for name in handle.namelist()
|
||||
]
|
||||
_ = await asyncio.gather(*tasks)
|
||||
except Exception as exp:
|
||||
logWrite(
|
||||
f"Could not import '{answer.document.file_name}' due to {exp}: {format_exc}"
|
||||
)
|
||||
await answer.reply_text(
|
||||
locale(
|
||||
"import_unpack_error", "message", locale=msg.from_user.language_code
|
||||
).format(exp, format_exc())
|
||||
)
|
||||
return
|
||||
logWrite(f"Downloaded '{answer.document.file_name}' - awaiting upload")
|
||||
await downloading.edit(
|
||||
locale("import_uploading", "message", locale=msg.from_user.language_code)
|
||||
)
|
||||
remove(tmp_path)
|
||||
|
||||
for filename in iglob(
|
||||
path.join(configGet("tmp", "locations"), tmp_dir) + "**/**", recursive=True
|
||||
):
|
||||
if not path.isfile(filename):
|
||||
continue
|
||||
# upload filename
|
||||
uploaded = await upload_pic(filename)
|
||||
if uploaded[0] is False:
|
||||
logWrite(
|
||||
f"Could not upload '{filename}' from '{path.join(configGet('tmp', 'locations'), tmp_dir)}'. Duplicates: {str(uploaded[1])}",
|
||||
debug=True,
|
||||
)
|
||||
if len(uploaded[1]) > 0:
|
||||
await msg.reply_text(
|
||||
locale(
|
||||
"import_upload_error_duplicate",
|
||||
"message",
|
||||
locale=msg.from_user.language_code,
|
||||
).format(path.basename(filename)),
|
||||
disable_notification=True,
|
||||
)
|
||||
else:
|
||||
await msg.reply_text(
|
||||
locale(
|
||||
"import_upload_error_other",
|
||||
"message",
|
||||
locale=msg.from_user.language_code,
|
||||
).format(path.basename(filename)),
|
||||
disable_notification=True,
|
||||
)
|
||||
else:
|
||||
logWrite(
|
||||
f"Uploaded '{filename}' from '{path.join(configGet('tmp', 'locations'), tmp_dir)}' and got ID {uploaded[2]}",
|
||||
debug=True,
|
||||
)
|
||||
|
||||
await downloading.delete()
|
||||
logWrite(
|
||||
f"Removing '{path.join(configGet('tmp', 'locations'), tmp_dir)}' after uploading",
|
||||
debug=True,
|
||||
)
|
||||
rmtree(path.join(configGet("tmp", "locations"), tmp_dir), ignore_errors=True)
|
||||
await answer.reply_text(
|
||||
locale("import_finished", "message", locale=msg.from_user.language_code),
|
||||
quote=True,
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
@app.on_message(~filters.scheduled & filters.command(["export"], prefixes=["", "/"]))
|
||||
@@ -20,7 +166,46 @@ async def cmd_export(app: PosterClient, msg: Message):
|
||||
@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
|
||||
global users_with_context
|
||||
if msg.from_user.id not in users_with_context:
|
||||
users_with_context.append(msg.from_user.id)
|
||||
else:
|
||||
return
|
||||
await msg.reply_text(
|
||||
locale("remove_request", "message", locale=msg.from_user.language_code)
|
||||
)
|
||||
answer = await listen_message(app, msg.chat.id, timeout=600)
|
||||
users_with_context.remove(msg.from_user.id)
|
||||
if answer is None:
|
||||
await msg.reply_text(
|
||||
locale("remove_ignored", "message", locale=msg.from_user.language_code),
|
||||
quote=True,
|
||||
)
|
||||
return
|
||||
if answer.text == "/cancel":
|
||||
await answer.reply_text(
|
||||
locale("remove_abort", "message", locale=msg.from_user.language_code)
|
||||
)
|
||||
return
|
||||
response = await remove_pic(answer.text)
|
||||
if response:
|
||||
logWrite(
|
||||
f"Removed '{answer.text}' by request of user {answer.from_user.id}"
|
||||
)
|
||||
await answer.reply_text(
|
||||
locale(
|
||||
"remove_success", "message", locale=msg.from_user.language_code
|
||||
).format(answer.text)
|
||||
)
|
||||
else:
|
||||
logWrite(
|
||||
f"Could not remove '{answer.text}' by request of user {answer.from_user.id}"
|
||||
)
|
||||
await answer.reply_text(
|
||||
locale(
|
||||
"remove_failure", "message", locale=msg.from_user.language_code
|
||||
).format(answer.text)
|
||||
)
|
||||
|
||||
|
||||
@app.on_message(~filters.scheduled & filters.command(["purge"], prefixes=["", "/"]))
|
||||
|
@@ -4,17 +4,17 @@ from traceback import format_exc
|
||||
from uuid import uuid4
|
||||
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
|
||||
from pyrogram.enums.chat_action import ChatAction
|
||||
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
|
||||
|
||||
from classes.enums.submission_types import SubmissionType
|
||||
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, users_with_context
|
||||
from modules.database import col_banned, col_submitted
|
||||
from modules.logger import logWrite
|
||||
from modules.utils import configGet, locale
|
||||
from classes.enums.submission_types import SubmissionType
|
||||
|
||||
|
||||
@app.on_message(
|
||||
@@ -24,6 +24,9 @@ from classes.enums.submission_types import SubmissionType
|
||||
| filters.document
|
||||
)
|
||||
async def get_submission(app: PosterClient, msg: Message):
|
||||
global users_with_context
|
||||
if msg.from_user.id in users_with_context:
|
||||
return
|
||||
try:
|
||||
if col_banned.find_one({"user": msg.from_user.id}) is not None:
|
||||
return
|
||||
@@ -43,9 +46,15 @@ async def get_submission(app: PosterClient, msg: Message):
|
||||
return
|
||||
|
||||
if msg.document is not None:
|
||||
logWrite(
|
||||
f"User {msg.from_user.id} is trying to submit a file of type '{msg.document.mime_type}' with name '{msg.document.file_name}' and size of {msg.document.file_size / 1024 / 1024} MB",
|
||||
debug=True,
|
||||
)
|
||||
if msg.document.mime_type not in configGet("mime_types", "submission"):
|
||||
await msg.reply_text(
|
||||
locale("mime_not_allowed", "message", locale=user_locale),
|
||||
locale("mime_not_allowed", "message", locale=user_locale).format(
|
||||
", ".join(configGet("mime_types", "submission"))
|
||||
),
|
||||
quote=True,
|
||||
)
|
||||
return
|
||||
@@ -65,6 +74,10 @@ async def get_submission(app: PosterClient, msg: Message):
|
||||
) # , msg.document.file_name
|
||||
|
||||
if msg.video is not None:
|
||||
logWrite(
|
||||
f"User {msg.from_user.id} is trying to submit a video with name '{msg.video.file_name}' and size of {msg.video.file_size / 1024 / 1024} MB",
|
||||
debug=True,
|
||||
)
|
||||
if msg.video.file_size > configGet("file_size", "submission"):
|
||||
await msg.reply_text(
|
||||
locale("document_too_large", "message", locale=user_locale).format(
|
||||
@@ -78,6 +91,10 @@ async def get_submission(app: PosterClient, msg: Message):
|
||||
contents = msg.video.file_id, SubmissionType.VIDEO # , msg.video.file_name
|
||||
|
||||
if msg.animation is not None:
|
||||
logWrite(
|
||||
f"User {msg.from_user.id} is trying to submit an animation with name '{msg.animation.file_name}' and size of {msg.animation.file_size / 1024 / 1024} MB",
|
||||
debug=True,
|
||||
)
|
||||
if msg.animation.file_size > configGet("file_size", "submission"):
|
||||
await msg.reply_text(
|
||||
locale("document_too_large", "message", locale=user_locale).format(
|
||||
@@ -94,6 +111,10 @@ async def get_submission(app: PosterClient, msg: Message):
|
||||
) # , msg.animation.file_name
|
||||
|
||||
if msg.photo is not None:
|
||||
logWrite(
|
||||
f"User {msg.from_user.id} is trying to submit a photo with ID '{msg.photo.file_id}' and size of {msg.photo.file_size / 1024 / 1024} MB",
|
||||
debug=True,
|
||||
)
|
||||
contents = msg.photo.file_id, SubmissionType.PHOTO # , "please_generate"
|
||||
|
||||
if save_tmp is not None:
|
||||
@@ -188,12 +209,14 @@ async def get_submission(app: PosterClient, msg: Message):
|
||||
and configGet("admins", "submission", "require_confirmation") is False
|
||||
):
|
||||
try:
|
||||
await app.submit_photo(str(inserted.inserted_id))
|
||||
submitted = 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,
|
||||
)
|
||||
if configGet("send_uploaded_id", "submission"):
|
||||
caption += f"\n\nID: `{submitted[1]}`"
|
||||
await msg.copy(app.owner, caption=caption, disable_notification=True)
|
||||
return
|
||||
except SubmissionDuplicatesError as exp:
|
||||
@@ -212,12 +235,14 @@ async def get_submission(app: PosterClient, msg: Message):
|
||||
and configGet("users", "submission", "require_confirmation") is False
|
||||
):
|
||||
try:
|
||||
await app.submit_photo(str(inserted.inserted_id))
|
||||
submitted = 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,
|
||||
)
|
||||
if configGet("send_uploaded_id", "submission"):
|
||||
caption += f"\n\nID: `{submitted[1]}`"
|
||||
await msg.copy(app.owner, caption=caption)
|
||||
return
|
||||
except SubmissionDuplicatesError as exp:
|
||||
|
166
poster.py
166
poster.py
@@ -1,13 +1,20 @@
|
||||
from os import getpid
|
||||
from datetime import datetime
|
||||
from os import getpid, path
|
||||
from sys import exit
|
||||
from time import time
|
||||
from traceback import format_exc
|
||||
from modules.api_client import authorize
|
||||
|
||||
from modules.cli import *
|
||||
from modules.http_client import http_session
|
||||
from modules.logger import logWrite
|
||||
from modules.scheduler import scheduler
|
||||
from modules.utils import configGet, killProc, locale
|
||||
from modules.utils import configGet, jsonLoad, jsonSave, locale
|
||||
|
||||
# Import ===================================================================================================================================
|
||||
try:
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from pyrogram.errors import bad_request_400
|
||||
from pyrogram.sync import idle
|
||||
|
||||
from modules.app import app
|
||||
@@ -18,6 +25,7 @@ except ModuleNotFoundError:
|
||||
|
||||
|
||||
pid = getpid()
|
||||
version = 0.1
|
||||
|
||||
# Work in progress
|
||||
# def check_forwards(app):
|
||||
@@ -55,6 +63,8 @@ pid = getpid()
|
||||
# check_forwards(app)
|
||||
|
||||
|
||||
from plugins.callbacks.shutdown import *
|
||||
|
||||
# Imports ==================================================================================================================================
|
||||
from plugins.commands.general import *
|
||||
|
||||
@@ -64,6 +74,9 @@ if configGet("submit", "mode"):
|
||||
from plugins.commands.mode_submit import *
|
||||
from plugins.handlers.submission import *
|
||||
|
||||
if configGet("post", "mode"):
|
||||
from plugins.commands.photos import *
|
||||
|
||||
# if configGet("api_based", "mode"):
|
||||
# from modules.api_client import authorize
|
||||
# ===========================================================================================================================================
|
||||
@@ -108,31 +121,146 @@ if configGet("submit", "mode"):
|
||||
# uvloop.install()
|
||||
# asyncio.run(main())
|
||||
|
||||
if __name__ == "__main__":
|
||||
logWrite(locale("startup", "console", locale=configGet("locale")).format(str(pid)))
|
||||
|
||||
app.start()
|
||||
async def main():
|
||||
logWrite(locale("startup", "console").format(str(pid)))
|
||||
|
||||
await app.start()
|
||||
|
||||
if configGet("startup", "reports"):
|
||||
app.send_message(
|
||||
app.owner,
|
||||
locale("startup", "message", locale=configGet("locale")).format(str(pid)),
|
||||
try:
|
||||
if path.exists(path.join(configGet("cache", "locations"), "shutdown_time")):
|
||||
downtime = relativedelta(
|
||||
datetime.now(),
|
||||
datetime.fromtimestamp(
|
||||
jsonLoad(
|
||||
path.join(configGet("cache", "locations"), "shutdown_time")
|
||||
)["timestamp"]
|
||||
),
|
||||
)
|
||||
if downtime.days >= 1:
|
||||
await app.send_message(
|
||||
configGet("owner"),
|
||||
locale(
|
||||
"startup_downtime_days",
|
||||
"message",
|
||||
).format(pid, downtime.days),
|
||||
)
|
||||
elif downtime.hours >= 1:
|
||||
await app.send_message(
|
||||
configGet("owner"),
|
||||
locale(
|
||||
"startup_downtime_hours",
|
||||
"message",
|
||||
).format(pid, downtime.hours),
|
||||
)
|
||||
else:
|
||||
await app.send_message(
|
||||
configGet("owner"),
|
||||
locale(
|
||||
"startup_downtime_minutes",
|
||||
"message",
|
||||
locale=configGet("locale"),
|
||||
).format(pid, downtime.minutes),
|
||||
)
|
||||
else:
|
||||
await app.send_message(
|
||||
configGet("owner"),
|
||||
locale("startup", "message").format(pid),
|
||||
)
|
||||
except bad_request_400.PeerIdInvalid:
|
||||
logWrite(
|
||||
f"Could not send startup message to bot owner. Perhaps user has not started the bot yet."
|
||||
)
|
||||
|
||||
if configGet("update", "reports"):
|
||||
try:
|
||||
check_update = await http_session.get(
|
||||
"https://git.end-play.xyz/api/v1/repos/profitroll/TelegramPoster/releases?page=1&limit=1"
|
||||
)
|
||||
response = await check_update.json()
|
||||
if len(response) == 0:
|
||||
raise ValueError("No bot releases on git found.")
|
||||
if float(response[0]["tag_name"].replace("v.", "")) > version:
|
||||
logWrite(
|
||||
f'New version {response[0]["tag_name"].replace("v.", "")} found (current {version})'
|
||||
)
|
||||
await app.send_message(
|
||||
configGet("owner"),
|
||||
locale(
|
||||
"update_available",
|
||||
"message",
|
||||
).format(
|
||||
response[0]["tag_name"],
|
||||
response[0]["html_url"],
|
||||
response[0]["body"],
|
||||
),
|
||||
)
|
||||
else:
|
||||
logWrite(f"No updates found, bot is up to date.")
|
||||
except bad_request_400.PeerIdInvalid:
|
||||
logWrite(
|
||||
f"Could not send startup message to bot owner. Perhaps user has not started the bot yet."
|
||||
)
|
||||
except Exception as exp:
|
||||
logWrite(f"Update check failed due to {exp}: {format_exc()}")
|
||||
|
||||
if configGet("post", "mode"):
|
||||
scheduler.start()
|
||||
|
||||
# if configGet("api_based", "mode"):
|
||||
# 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:
|
||||
# post(f'{configGet("address", "posting", "api")}/albums?name={configGet("queue", "posting", "api", "albums")}&title={configGet("queue", "posting", "api", "albums")}', headers={"Authorization": f"Bearer {token}"})
|
||||
try:
|
||||
token = await authorize()
|
||||
|
||||
idle()
|
||||
|
||||
app.send_message(
|
||||
app.owner,
|
||||
locale("shutdown", "message", locale=configGet("locale")).format(str(pid)),
|
||||
if (
|
||||
len(
|
||||
(
|
||||
await (
|
||||
await http_session.get(
|
||||
f'{configGet("address", "posting", "api")}/albums?q={configGet("album", "posting", "api")}',
|
||||
headers={"Authorization": f"Bearer {token}"},
|
||||
)
|
||||
logWrite(locale("shutdown", "console", locale=configGet("locale")).format(str(pid)))
|
||||
).json()
|
||||
)["results"]
|
||||
)
|
||||
== 0
|
||||
):
|
||||
logWrite("Media album does not exist on API server. Trying to create it...")
|
||||
try:
|
||||
await http_session.post(
|
||||
f'{configGet("address", "posting", "api")}/albums?name={configGet("album", "posting", "api")}&title={configGet("album", "posting", "api")}',
|
||||
headers={"Authorization": f"Bearer {token}"},
|
||||
)
|
||||
logWrite("Created media album on API server.")
|
||||
except Exception as exp:
|
||||
logWrite(
|
||||
f"Could not create media album on API server due to {exp}: {format_exc()}"
|
||||
)
|
||||
except Exception as exp:
|
||||
logWrite(f"Could not check if API album exists due to {exp}: {format_exc()}")
|
||||
|
||||
killProc(pid)
|
||||
await idle()
|
||||
|
||||
try:
|
||||
await app.send_message(
|
||||
configGet("owner"),
|
||||
locale("shutdown", "message").format(pid),
|
||||
)
|
||||
except bad_request_400.PeerIdInvalid:
|
||||
logWrite(
|
||||
f"Could not send shutdown message to bot owner. Perhaps user has not started the bot yet."
|
||||
)
|
||||
|
||||
makedirs(configGet("cache", "locations"), exist_ok=True)
|
||||
jsonSave(
|
||||
{"timestamp": time()},
|
||||
path.join(configGet("cache", "locations"), "shutdown_time"),
|
||||
)
|
||||
|
||||
logWrite(locale("shutdown", "console").format(str(pid)))
|
||||
|
||||
scheduler.shutdown()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(main())
|
||||
|
@@ -1 +0,0 @@
|
||||
tgcrypto~=1.2.5
|
@@ -1,9 +1,12 @@
|
||||
apscheduler~=3.10.1
|
||||
pyrogram~=2.0.102
|
||||
pytimeparse~=1.1.8
|
||||
python_dateutil==2.8.2
|
||||
apscheduler==3.10.1
|
||||
pytimeparse==1.1.8
|
||||
convopyro==0.5
|
||||
pyrogram==2.0.104
|
||||
aiofiles~=23.1.0
|
||||
tgcrypto==1.2.5
|
||||
aiohttp~=3.8.4
|
||||
psutil~=5.9.4
|
||||
pymongo~=4.3.3
|
||||
pillow~=9.4.0
|
||||
ujson~=5.7.0
|
||||
psutil==5.9.5
|
||||
pymongo==4.3.3
|
||||
pillow~=9.5.0
|
||||
ujson==5.7.0
|
Reference in New Issue
Block a user