Coder Social home page Coder Social logo

arshiaafr / sticker-thief Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zeroone2numeral2/sticker-thief

0.0 0.0 0.0 678 KB

Telegram bot to build custom sticker packs

Home Page: https://t.me/stickersthiefbot

License: MIT License

Python 99.44% Mako 0.42% Dockerfile 0.14%

sticker-thief's Introduction

Stickers thief bot

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

Running the bot

Native

  1. install requirements with pip3 install -r requirements.txt
  2. rename config.example.toml to config.toml and change relevant values (that is, telegram.token and telegram.admins)
  3. run the bot with python3 main.py

Docker

  1. rename config.example.toml to config.toml and change relevant values (that is, telegram.token and telegram.admins)
  2. with docker installed run sudo docker build -t sticker-thief . in the project root
  3. 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 integration

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

Notes for those who are going to run this

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

sticker-thief's People

Contributors

zeroone2numeral2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.