I made this bot because I was tired of wasting my time looking for that perfect sticker to use, among all my installed packs.
Features:
- create static and animated stickerpacks
- add stickers to an existing pack just by sending other stickers (png files are accepted too)
- automatically resize png files so they can fit Telegram's rateo size requirements
- remove stickers from a pack
- convert stickers to png files (and resize them if they're too big)
- export a sticker pack as a zip of png files
- set the sticker's emojis before sending the sticker
- bonus: stickers added to a pack inherits all the emojis bind to the original sticker, by hacking around with the Telegram API
- install requirements with
pip3 install -r requirements.txt
- rename
config.example.toml
toconfig.toml
and change relevant values (that is,telegram.token
andtelegram.admins
) - run the bot with
python3 main.py
- rename
config.example.toml
toconfig.toml
and change relevant values (that is,telegram.token
andtelegram.admins
) - with docker installed run
sudo docker build -t sticker-thief .
in the project root - then run
sudo docker run --rm sticker-thief
(add a-d
flag after--rm
if you want to run the bot in the background)
Pyrogram is an MTProto client, that is, a software (a Python library, in this case) that allows to talk with the Telegram API (not to be confused with the bot API).
The Telegram API is mainly designed to let human user accounts interact with Telegram, but it also allows to login as a bot (fun fact: the bot API is just an http interface that exposes some methods to simply let your bot login and interact with the Telegram API). By skipping the bot API middleware and connecting directly to the Telegram API, we are allowed to use a set of methods which are not exposed by the standard bot API, and that we wouldn't be able to use otherwise.
So, what we need Pyrogram for? This bot makes use of Pyrogram to overcome a bot API limitation: when a bot (or, well, any user) receives a sticker, Telegram will tell the receiver only the main emoji associated with that sticker object. This behavior is designed into the Telegram API, so it is obviously inherited by the bot API. This is not ideal in our context, because when we add a sticker to a pack, we are able to tell Telegram only one emoji to bind to it (the sticker's main one). To get a sticker's full list of emojis, we have to request to the API the whole pack, which is the only way to obtain this information. This request can be executed only by authenticating as a bot account through the Telegram API.
Does this mean the bot is not using the bot API, but directly uses the Telegram API instead? No, all networking with Telegram is still done through the bot API. But, when we need to fetch a stciker's emojis, we briefly authenticate to the Telegram API (by starting a Pyrogram client) and execute an API request to fecth the sticker's pack, which contains the emojis list.
By default, the bot doesn't make use of Pyrogram.
You can enable it from the pyrogram
config section, by switching enabled
to true
. Important: you also need to fill api_id
and api_hash
with your tokens, which can be obtained by following this guide from the Pyrogram documentation (pay attention to #2).
This bot is not made to be used by a large amount of users and I cannot guarantee its performances.
By default, everyone can use this bot (with the exception of some special commands, listed below). If you want to restrict its use to only the users listed in telegram.admins
(condfig.toml
file), open config.toml
and change telegram.admins_only
to true
.
When you pull from git, make sure to run alembic to upgrade your database schema: alembic upgrade head