classes | ||
docs | ||
locale | ||
modules | ||
plugins | ||
.gitignore | ||
config_example.json | ||
LICENSE | ||
loop.bat | ||
loop.sh | ||
poster.py | ||
README_uk.md | ||
README.md | ||
requirements-optional.txt | ||
requirements.txt | ||
start.bat | ||
start.sh |
TelegramPoster
Шукаєш інструкцію українською? А вона ось тут знаходиться)
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
- Python 3.7+ (3.9+ recommended)
- MongoDB
- PhotosAPI
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. 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
andstart.bat
).
-
Install Mongo and Photos API:
- Install MongoDB by following official installation manual
- Install Photos API by following Photos API's README
-
Download the bot:
git clone -b dev https://git.end-play.xyz/profitroll/TelegramPoster.git
(if you're using git)cd TelegramPoster
-
Create virtual environment [Optional]:
- Install virtualenv module:
pip install virtualenv
- Create venv:
python -m venv env
- Activate it using
source venv/bin/activate
on Linux,venv\Scripts\activate.bat
in CMD orvenv\Scripts\Activate.ps1
in PowerShell.
- Install virtualenv module:
-
Install project's dependencies:
python -m pip install -r requirements.txt
Without installing those - bot cannot work at all. -
Install optional dependencies [Optional]:
python -m pip install -r requirements-optional.txt
These are not required but can make the bot run a bit faster. -
Configure "bot" and "owner" with your favorite text editor:
- Copy file
config_example.json
toconfig.json
- Open
config.json
using your favorite text editor. For examplenano config.json
, but you can edit with vim, nano, on Windows it's Notepad or Notepad++. Whatever - Change
"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.
- Copy file
-
Configure database and API:
-
Configure database:
- Change database host and port in keys
"database.host"
and"database.port"
. For default local installation those will be127.0.0.1
and27017
respectively - Change database name to the one you like in
"database.name"
. It will be automatically created on start - If you've changed user and password to access the db, you should also change
"database.user"
and"database.password"
keys, otherwise leave themnull
(default).
- Change database host and port in keys
-
Configure Photos API:
- Change
"posting.api.address"
to the one your API servers uses - 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. 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.
- Change
-
-
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 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. -
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"
totrue
. -
Good to go, run 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 andbash ./start.sh
on Linux.
Additionally there areloop.sh
andloop.bat
available if you want your bot to start again after being stopped or after using/reboot
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.
Command line 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 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 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
folder, otherwise in folder specified in config file. 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, that cannot determine admin's locale - edit "locale"
parameter in the config.json
. If this locale is not available - "locale_fallback"
will be used instead. If both are not available - error will be shown. For console output and logging locale you should edit "locale_log"
.
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.