This bot is used for one and only task - post pictures from my personal archive.
This repository has been archived on 2024-08-21. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Renovate a45f6b620f Update dependency black to ~=23.7.0 (#34)
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [black](https://github.com/psf/black) ([changelog](https://github.com/psf/black/blob/main/CHANGES.md)) | minor | `~=23.3.0` -> `~=23.7.0` |

---

### Release Notes

<details>
<summary>psf/black</summary>

### [`v23.7.0`](https://github.com/psf/black/blob/HEAD/CHANGES.md#&#8203;2370)

[Compare Source](https://github.com/psf/black/compare/23.3.0...23.7.0)

##### Highlights

-   Runtime support for Python 3.7 has been removed. Formatting 3.7 code will still be
    supported until further notice ([#&#8203;3765](https://github.com/psf/black/issues/3765))

##### Stable style

-   Fix a bug where an illegal trailing comma was added to return type annotations using
    PEP 604 unions ([#&#8203;3735](https://github.com/psf/black/issues/3735))
-   Fix several bugs and crashes where comments in stub files were removed or mishandled
    under some circumstances ([#&#8203;3745](https://github.com/psf/black/issues/3745))
-   Fix a crash with multi-line magic comments like `type: ignore` within parentheses
    ([#&#8203;3740](https://github.com/psf/black/issues/3740))
-   Fix error in AST validation when *Black* removes trailing whitespace in a type comment
    ([#&#8203;3773](https://github.com/psf/black/issues/3773))

##### Preview style

-   Implicitly concatenated strings used as function args are no longer wrapped inside
    parentheses ([#&#8203;3640](https://github.com/psf/black/issues/3640))
-   Remove blank lines between a class definition and its docstring ([#&#8203;3692](https://github.com/psf/black/issues/3692))

##### Configuration

-   The `--workers` argument to *Black* can now be specified via the `BLACK_NUM_WORKERS`
    environment variable ([#&#8203;3743](https://github.com/psf/black/issues/3743))
-   `.pytest_cache`, `.ruff_cache` and `.vscode` are now excluded by default ([#&#8203;3691](https://github.com/psf/black/issues/3691))
-   Fix *Black* not honouring `pyproject.toml` settings when running `--stdin-filename`
    and the `pyproject.toml` found isn't in the current working directory ([#&#8203;3719](https://github.com/psf/black/issues/3719))
-   *Black* will now error if `exclude` and `extend-exclude` have invalid data types in
    `pyproject.toml`, instead of silently doing the wrong thing ([#&#8203;3764](https://github.com/psf/black/issues/3764))

##### Packaging

-   Upgrade mypyc from 0.991 to 1.3 ([#&#8203;3697](https://github.com/psf/black/issues/3697))
-   Remove patching of Click that mitigated errors on Python 3.6 with `LANG=C` ([#&#8203;3768](https://github.com/psf/black/issues/3768))

##### Parser

-   Add support for the new PEP 695 syntax in Python 3.12 ([#&#8203;3703](https://github.com/psf/black/issues/3703))

##### Performance

-   Speed up *Black* significantly when the cache is full ([#&#8203;3751](https://github.com/psf/black/issues/3751))
-   Avoid importing `IPython` in a case where we wouldn't need it ([#&#8203;3748](https://github.com/psf/black/issues/3748))

##### Output

-   Use aware UTC datetimes internally, avoids deprecation warning on Python 3.12 ([#&#8203;3728](https://github.com/psf/black/issues/3728))
-   Change verbose logging to exactly mirror *Black*'s logic for source discovery ([#&#8203;3749](https://github.com/psf/black/issues/3749))

##### *Blackd*

-   The `blackd` argument parser now shows the default values for options in their help
    text ([#&#8203;3712](https://github.com/psf/black/issues/3712))

##### Integrations

-   Black is now tested with
    [`PYTHONWARNDEFAULTENCODING = 1`](https://docs.python.org/3/library/io.html#io-encoding-warning)
    ([#&#8203;3763](https://github.com/psf/black/issues/3763))
-   Update GitHub Action to display black output in the job summary ([#&#8203;3688](https://github.com/psf/black/issues/3688))

##### Documentation

-   Add a CITATION.cff file to the root of the repository, containing metadata on how to
    cite this software ([#&#8203;3723](https://github.com/psf/black/issues/3723))
-   Update the *classes* and *exceptions* documentation in Developer reference to match
    the latest code base ([#&#8203;3755](https://github.com/psf/black/issues/3755))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS41NC4wIiwidXBkYXRlZEluVmVyIjoiMzUuNTQuMCJ9-->

Co-authored-by: Renovate <renovate@git.end-play.xyz>
Reviewed-on: #34
Co-authored-by: Renovate <renovate@noreply.localhost>
Co-committed-by: Renovate <renovate@noreply.localhost>
2023-07-11 11:20:23 +03:00
classes master (#33) 2023-07-06 17:35:12 +03:00
docs Updates wiki init 2023-03-22 11:02:13 +01:00
locale Locale for console is gone for good 2023-07-03 11:42:28 +02:00
modules unauthorized_client will be created when needed 2023-07-03 14:42:55 +02:00
plugins Locale for console is gone for good 2023-07-03 11:42:28 +02:00
.gitignore API usage overhaul (#27) 2023-06-28 00:57:30 +03:00
.renovaterc Fixed branch name in Renovate config 2023-04-20 13:35:52 +02:00
config_example.json max_concurrent_transmissions reduced to 1 2023-07-06 14:19:56 +02:00
LICENSE Initial commit 2022-08-08 14:53:26 +02:00
loop.bat Starting scripts and README were updated 2023-06-28 08:22:18 +02:00
loop.sh Starting scripts and README were updated 2023-06-28 08:22:18 +02:00
main.py CLI is back and updated 2023-07-03 11:27:15 +02:00
README_uk.md Updated README 2023-07-03 12:34:55 +02:00
README.md Updated README 2023-07-03 12:34:55 +02:00
requirements.txt Update dependency black to ~=23.7.0 (#34) 2023-07-11 11:20:23 +03:00
start.bat Starting scripts and README were updated 2023-06-28 08:22:18 +02:00
start.sh Starting scripts and README were updated 2023-06-28 08:22:18 +02:00

TelegramPoster

License: GPL Code style: black

Шукаєш інструкцію українською? А вона ось тут знаходиться)

This bot is used for one and only task - post pictures from my personal archive. Here's its source code so you can also host a bot and have fun with it. Just don't exepect it to be brilliant. It is not. But hey, you can always fork it ;)

Dependencies

Use MongoDB's installation manual and Photos API's README.

Please note that Photos API also requires MongoDB so it makes sense to install and configure Mongo first.

Installation

To make this bot run at first you need to have a Python interpreter, Photos API, MongoDB and optionally git (if you want to update using git pull). You can also ignore git and simply download source code, should also work fine. After that you're ready to go.

In this README I assume that you're using default python in your system and your system's PATH contains it. If your default python is python3 or for example /home/user/.local/bin/python3.9 - use it instead. If it's non-standard executable path - you should also change it in scripts you will use (loop.sh, loop.bat, start.sh and start.bat).

  1. Install MongoDB and Photos API:

    1. Install MongoDB by following official installation manual
    2. Install Photos API by following Photos API's README
  2. Download the bot:

    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 .venv
    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.

  5. Configure required keys with your favorite text editor:

    1. Copy config file: cp config_example.json config.json
    2. Open config.json using your favorite text editor. For example nano config.json, but you can also edit it with vim, mcedit, or Notepad/Notepad++ on Windows
    3. Change "bot.owner", "bot.api_id", "bot.api_hash" and "bot.bot_token" keys' values.

    If you don't know where to find bot_token and your id - here you can find some hints: get bot token, get your id, get api_hash and api_id.

  6. Configure database and API:

    1. Configure database:

      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. Change "posting.api.address" and "posting.api.address_external" to the ones your API server uses
      2. Run your bot using python main.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. 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 it makes no sense to have such a bot. Here 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 and "posting.comments" to comments group'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 the bot.
    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 /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 to get more detailed instructions.

CLI arguments

Of course bot also has them. You can perform some actions with them.

  • --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:

  • python main.py --create-user
  • python main.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 in the wiki.

Localization

Bot is capable of using custom locales. There are some that are pre-installed (English and Ukrainian), however you can add your own locales too.

All localization files are located in the locale. Just copy locale file of your choice, name it in accordance to IETF language tags (if you want your locale to be compatible with Telegram's locales) or define your own name. Save it as json and you're good to go. If you want to change default locale for messages - edit "locale" parameter in the config.json.

We recommend to only make changes to your custom locale. Or at least always have your backup of for example en.json as your fallback.