Skip to main content

Run Python code right in your Telegram messages

Project description

TGPy

Run Python code right in your Telegram messages

Made with Telethon library, TGPy is a tool for evaluating expressions and Telegram API scripts.

  • Do Python calculations in dialogs
  • Interact with your messages and chats
  • Automate sending messages and more

Example

Just send Python code to any chat, and it will be executed. Change your message to change the result.

Examples

Send any of these examples to any chat to evaluate:

🐍 Do Python calculations

for i in range(5):
    print(i)

⏳ Delete the current message in 5 seconds

import asyncio

await asyncio.sleep(5)
await msg.delete()

↪️ Forward the message you replied to to another chat

orig.forward_to('Chat title')

🖼 Send all chat profile photos to the same chat

photos = await client.get_profile_photos(msg.chat)
msg.reply(file=photos)

🔖 Define a function which forwards messages to Saved Messages with reply

def save():
    message = ctx.msg
    original = await message.get_reply_message()
    await original.forward_to('me')
    return 'Saved!'

🗑 Define a function which deletes messages with reply

async def delete():
    message = ctx.msg
    original = await message.get_reply_message()
    await original.delete()
    await message.delete()

Guide

Installation

  1. You'll need Telegram API key. Register your "app" at my.telegram.org to get api_id and api_hash. App title and other data don't matter.

  2. Clone the repo:

    > git clone https://github.com/tm-a-t/TGPy
    > cd TGPy
    
  3. Create config.py. Enter your API data and your phone to log in:

    api_id = ...
    api_hash = ...
    phone = ...
    
  4. Install the requirements and run TGPy:

    > pip install -r requirements.txt
    > python -m tgpy
    
  5. For the first time, you'll need to log in with a confirmation code from Telegram.

Send ping() to any chat to check if TGPy is running.

Credits

License

This project is licensed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tgpy-0.2.0.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

tgpy-0.2.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file tgpy-0.2.0.tar.gz.

File metadata

  • Download URL: tgpy-0.2.0.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for tgpy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 82c9a633935d2e1e24ebf466ae21e110a8af07d2f15b2851e7be55247690865b
MD5 32321961263f626bbf41b9ea29c67971
BLAKE2b-256 df321e2a510871fdba3bbccd0a4d253dd8e88929430c5d9e166dc005c65ba6c0

See more details on using hashes here.

File details

Details for the file tgpy-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: tgpy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for tgpy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 86fba37bc13fe3ec3fdb35051099eeb046433c5dc4c49a09883040fb5590830a
MD5 c92c3619fdd138b4ce1cb74875f44276
BLAKE2b-256 7156c3581e4a95a92aea9d41db9ede64d60700461d4cb088a8751bca3aea86e6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page