Run Python code right in your Telegram messages
Made with Telethon library, TGPy is a tool for evaluating expressions and Telegram API scripts.
Installation
- Get your Telegram API key on my.telegram.org
- Clone the repo
> git clone https://github.com/tm-a-t/TGPy
- Create
config.py
api_id = ... api_hash = ... phone = ...
- Install the requirements and run TGPy
> pip install -r requirements.txt > python -m app
- Log in with a confirmation code from Telegram
Usage
Basics
Just send Python code to any chat, and it will be executed.
Change your message to change the result.
Code detection
TGPy automatically detects and evaluates Python code in your messages.
Single constants/names are not evaluated. Instead, use return something
.
Cancel evaluation. Reply cancel
to your TGPy message to keep the original message.
Prevent evaluation. Write //
in the beginning of your message to prevent evaluation.
Interacting with chats, users, messages
TGPy uses Telethon library for Telegram API. Refer to Telethon documentation.
In TGPy expressions you can use some context variables:
Returning values
The evaluation result is the returned value. If there is no return
, all evaluated statements are returned.
Saving variables
The locals are saved while TGPy is running. You can also use _
variable to get the previous result.
Asyncio
You can use async
/await
in your code. Also, the returned value is automatically awaited (if needed).
Credits
License
MIT