Run Python code right in your Telegram messages

Related tags

MiscellaneousTGPy
Overview

img.png

Run Python code right in your Telegram messages

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

img.png

Installation

  1. Get your Telegram API key on my.telegram.org
  2. Clone the repo
    > git clone https://github.com/tm-a-t/TGPy
  3. Create config.py
    api_id = ...
    api_hash = ...
    phone = ...
  4. Install the requirements and run TGPy
    > pip install -r requirements.txt
    > python -m app
  5. Log in with a confirmation code from Telegram

Usage

Basics

Just send Python code to any chat, and it will be executed.

img.png

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:

  • msg - current message
  • orig - original message if your message is a reply
  • client - Telethon client

img.png

Returning values

The evaluation result is the returned value. If there is no return, all evaluated statements are returned.

img.png

Saving variables

The locals are saved while TGPy is running. You can also use _ variable to get the previous result.

img_1.png

Asyncio

You can use async/await in your code. Also, the returned value is automatically awaited (if needed).

img.png

Credits

License

MIT

Comments
  • Editing not evaluated message does not cause evaluating

    Editing not evaluated message does not cause evaluating

    If I change my message from 'fyva prold je' (not Python code) to 'fyva-prold-je', it is not evaluated, although it is now Python code. Even editing 'my_var' -> 'return my_var' does not cause evaluating.

    opened by SashaVonSup 2
  • Two-factor authentication password is shown in the console

    Two-factor authentication password is shown in the console

    Steps to reproduce

    Run TGPy for the first time:

    > vim config.py
    > virtualenv venv
    > source venv/bin/activate.fish
    > pip install -r requirements.txt
    > python -m app
    
    < INFO:    Connecting to 149.154.167.51:443/TcpFull...
    < INFO:    Connection to 149.154.167.51:443/TcpFull complete!
    < Please enter the code you received: 12345
    < 2FA password: <!plain text password here>
    < Signed in successfully as ...
    

    Expected behaviour

    The password is not shown or at least shown in stars (for example, ********** for 10-symbol password)

    Behaviour seen

    The password is shown in plain text, which is insecure when running TGPy in a public place

    enhancement 
    opened by ntoneee 0
  • Customizability

    Customizability

    • сделать MessageModel вместо message_design.py, чтобы в нем были все функции и константы оттуда, которые можно было бы переопределять
    • сделать MessageParser вместо ast.parse
    • сделать возможным через апи менять MessageModel, MessageParser и variables (который сейчас в builtin_functions.py)
    • сделать builtin hooks, которые можно будет частично отключать в конфиге
    • переименовать hooks в modules
    enhancement 
    opened by vanutp 0
  • Improvements to cancel command

    Improvements to cancel command

    • [ ] ability to stop running commands
    • [ ] ability to stop sync commands such as while True loop
    • [ ] make cancel and // permanent (do not reevaluate message when editing, if it was cancelled before)
    enhancement 
    opened by vanutp 0
  • Do not show all fields in tl objects when they are returned

    Do not show all fields in tl objects when they are returned

    For example, when message is sent using await msg.reply('123'), Message object is returned and a lot of fields are shown, spamming in the chat.

    For instance:

    msg
    TGPy> Message(
     id=123,
     peer_id=PeerChannel(
      channel_id=1123456789
     ),
     date=datetime.datetime(2021, 11, 18, 18, 7, 4, tzinfo=datetime.timezone.utc),
     message='msg',
     out=True,
     mentioned=False,
     media_unread=False,
     silent=False,
     post=False,
     from_scheduled=False,
     legacy=False,
     edit_hide=False,
     pinned=False,
     from_id=PeerUser(
      user_id=123456
     ),
     fwd_from=None,
     via_bot_id=None,
     reply_to=None,
     media=None,
     reply_markup=None,
     entities=[
     ],
     views=None,
     forwards=None,
     replies=MessageReplies(
      replies=0,
      replies_pts=...,
      comments=False,
      recent_repliers=[
      ],
      channel_id=None,
      max_id=None,
      read_max_id=None
     ),
     edit_date=None,
     post_author=None,
     grouped_id=None,
     restriction_reason=[
     ],
     ttl_period=None
    )
    

    Proposal is to show only commonly used fields, such as id, text, date, fwd_from, etc. Also, this could be done for User, Channel, Chat too

    enhancement 
    opened by vanutp 0
  • False positive code detections

    False positive code detections

    • [x] 1. Multiple one-word lines
    word
    another_word
    ...
    
    • [x] 2. Tuple word, another_word, ...

    • [x] 3. Single hyphen confused with binary subtraction operator w-ord

    • [x] 4. URLs example.com or t.me/username or t.me/c/1234567890/1000

    • [x] 5. Email addresses [email protected]

    • [x] 6. not good

    • [x] 7. Unary operators to constant-1

    • [x] 8. 1 + 3

    a - b, c
    d - e, f
    
    enhancement 
    opened by vanutp 1
  • Function in first line of traceback is

    Function in first line of traceback is "tmp"

    It should be "<module>" instead

    Example:

    Traceback (most recent call last):
      File "tgpy://message/...", line 1, in tmp
        1/0
    ZeroDivisionError: division by zero
    
    bug meval 
    opened by vanutp 0
Releases(v0.6.1)
Owner
Too lazy to write bio but too bored to write nothing
a package that provides a marketstrategy for whitelisting on golem

filterms a package that provides a marketstrategy for whitelisting on golem watching requestor logs distribute 10 tasks asynchronously is fun. but you

KJM 3 Aug 03, 2022
A basic DIY-project made using Python and MySQL

Banking-Using-Python-MySQL This is a basic DIY-project made using Python and MySQL. Pre-Requisite needed:-- MySQL command Line:- creating a database

ABHISHEK 0 Jul 03, 2022
An After Effects render queue for ShotGrid Toolkit.

AEQueue An After Effects render queue for ShotGrid Toolkit. Features Render multiple comps to locations defined by templates in your Toolkit config. C

Brand New School 5 Nov 20, 2022
The refactoring tutorial I wrote for PyConDE 2022. You can also work through the exercises on your own.

Refactoring 101 planet images by Justin Nichol on opengameart.org CC-BY 3.0 Goal of this Tutorial In this tutorial, you will refactor a space travel t

Kristian Rother 9 Jun 10, 2022
Terrible python code from the "bubble that breaks maths" video.

Terrible python code from the "bubble that breaks maths" video.

Stand-up Maths 12 Oct 25, 2022
Awesome & interesting talks about programming

Programming Talks I watch a lot of talks that I love to share with my friends, fellows and coworkers. As I consider all GitHubbers my friends (oh yeah

Veit Heller 7k Dec 26, 2022
Sabe is a python framework written for easy web server setup.

Sabe is a python framework written for easy web server setup. Sabe, kolay web sunucusu kurulumu için yazılmış bir python çerçevesidir. Öğrenmesi kola

2 Jan 01, 2022
That is a example of a Book app on Python, made with support of all JS libraries on React framework

React+Python Books App You can use this repository whenever you want Used for a video Create the database: python -m dbutils Start the web server: pyt

Koma Human 1 Apr 20, 2022
A simple python project that can find Tangkeke in a given image.

A simple python project that can find Tangkeke in a given image. Make the real Tangkeke image as a kernel to convolute the target image. The area wher

张志衡 1 Dec 08, 2021
The most widely used Python to C compiler

Welcome to Cython! Cython is a language that makes writing C extensions for Python as easy as Python itself. Cython is based on Pyrex, but supports mo

7.6k Jan 03, 2023
This project intends to take the user's CEP (brazilian adress code) and return the local in which the CEP is placed.

This project aims to simply return the CEP's (the brazilian resident adress code) User of the application. The project uses a request and passes on to

Daniel Soares Saldanha 4 Nov 17, 2021
Driving lessons made simpler. Custom scheduling API built with Python.

NOTE This is a mirror of a GitLab repository. Dryvo Dryvo is a unique solution for the driving lessons industry. Our aim is to save the teacher’s time

Adam Goldschmidt 595 Dec 05, 2022
Small exercises to get you used to reading and writing Python code!

Pythonlings Welcome to Pythonlings, an automated Python tutorial program (inspired by Rustlings and Haskellings). WIP This program is still working in

鹤翔万里 5 Sep 23, 2022
Small pip update helpers.

pipdate pipdate is a collection of small pip update helpers. The command pipdate # or python3.9 -m pipdate updates all your pip-installed packages. (O

Nico Schlömer 69 Dec 18, 2022
3x+1 recreated in Python

3x-1 3x+1 recreated in Python If a number is odd it is multiplied by 3 and 1 is added to the product. If a number is even it is divided by 2. These ru

4 Aug 19, 2022
Hexa is an advanced browser.It can carry out all the functions present in a browser.

Hexa is an advanced browser.It can carry out all the functions present in a browser.It is coded in the language Python using the modules PyQt5 and sys mainly.It is gonna get developed more in the fut

1 Dec 10, 2021
Superset custom path for python

It is a common requirement to have superset running under a base url, (https://mydomain.at/analytics/ instead of https://mydomain.at/). I created the

9 Dec 14, 2022
combs is a package used to generate all possible combinations of a given length k on a given set.

The package combs is a package used to generate all possible combinations of a given length k on a given set. The set is given as a list, and k must b

1 Dec 24, 2021
Modelling and Implementation of Cable Driven Parallel Manipulator System with Tension Control

Cable Driven Parallel Robots (CDPR) is also known as Cable-Suspended Robots are the emerging and flexible end effector manipulation system. Cable-driven parallel robots (CDPRs) are categorized as a t

Siddharth U 0 Jul 19, 2022
Retrying library for Python

Tenacity Tenacity is an Apache 2.0 licensed general-purpose retrying library, written in Python, to simplify the task of adding retry behavior to just

Julien Danjou 4.3k Jan 02, 2023