Run Python code right in your Telegram messages

Related tags

Miscellaneous TGPy
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
null
Osu statistics right on your desktop, made with pyqt

Osu!Stat Osu statistics right on your desktop, made with Qt5 Credits Would like to thank these creators for their projects and contributions. ppy, osu

Aditya Gupta 21 Jul 13, 2022
run-js Goal: The Easiest Way to Run JavaScript in Python

run-js Goal: The Easiest Way to Run JavaScript in Python features Stateless Async JS Functions No Intermediary Files Functional Programming CommonJS a

Daniel J. Dufour 9 Aug 16, 2022
A python script to turn tabs into spaces the right way.

detab A python script to turn tabs into spaces the right way. detab turns all tabs into spaces, not just leading tabs. Not all tabs have the same leng

null 1 Jan 26, 2022
Hoopoe - Get notified of important stuff, right away.

Hoopoe - Get notified of important stuff, right away. Report a Bug · Request a Feature . Ask a Question Table of Contents About Getting Started Prereq

Vahid Al 8 Nov 12, 2022
Reverse the infix string. Note that while reversing the string you must interchange left and right parentheses

Reverse the infix string. Note that while reversing the string you must interchange left and right parentheses. Obtain the postfix expression of the infix expression Step 1.Reverse the postfix expression to get the prefix expression

Sazzad Hossen 1 Jan 4, 2022
Cylinder volume calculator features the calculations of the volume of a Right /oblique full cylinder

Cylinder-Volume-Calculator Cylinder volume calculator features the calculations of the volume of a Right /oblique full cylinder. Size : 10.5 mb compat

Abhijeet 4 Nov 7, 2022
Telegram bot to remove the forwarded tag from messages.

Anonymous Sender Bot @AnonySendBot Telegram bot to remove the forwarded tag from messages. Table of Contents Usage Deploy To Heroku Local Deploying En

Stark Bots 26 Nov 24, 2022
Telop - Encode and decode messages using an interpretation of the telegraphic code devised by José María Mathé

telop Telop (TELégrafoÓPtico) - Utilidad para codificar y descodificar mensajes de texto empleando una interpretación del código telegráfico ideado po

Ricardo F. 4 Nov 1, 2022
Run-Your-Own Firefox Sync Server

Run-Your-Own Firefox Sync Server This is an all-in-one package for running a self-hosted Firefox Sync server. It bundles the "tokenserver" project for

Mozilla Services 1.7k Dec 30, 2022
Run CodeServer on Google Colab using Inlets in less than 60 secs using your own domain.

Inlets Colab Run CodeServer on Colab using Inlets in less than 60 secs using your own domain. Features Optimized for Inlets/InletsPro Use your own Cus

null 2 Dec 30, 2021
A python tool for synchronizing the messages from different threads, processes, or hosts.

Sync-stream This project is designed for providing the synchoronization of the stdout / stderr among different threads, processes, devices or hosts.

Yuchen Jin 0 Aug 11, 2021
Python tools for working with Orbit Ephemeris Messages (OEMs).

Python Orbit Ephemeris Message tools Python tools for working with Orbit Ephemeris Messages (OEMs). Development Status Installation The oem package is

Brad Sease 4 Apr 6, 2022
Provide error messages for Python exceptions, even if the original message is empty

errortext is a Python package to provide error messages for Python exceptions, even if the original message is empty.

Thomas Aglassinger 0 Dec 7, 2021
Automatically remove user join messages when the user leaves the server.

CleanLeave Automatically remove user join messages when the user leaves the server. Installation You will need to install poetry to run this bot local

null 11 Sep 19, 2022
Simple script with AminoLab to send ghost messages

Simple script with AminoLab to send ghost messages

Moleey 1 Nov 22, 2021
A Github Action for sending messages to a Matrix Room.

matrix-commit A Github Action for sending messages to a Matrix Room. Screenshot: Example Usage: # .github/workflows/matrix-commit.yml on: push:

null 3 Sep 11, 2022
ViberExport - Export messages from Viber messenger using viber.db file

?? ViberExport Export messages from Viber messenger using viber.db file ⚡ Usage:

null 7 Nov 23, 2022
Automatically unpin old messages so you can always pin more!

PinRotate Automatically unpin old messages so you can always pin more! Installation You will need to install poetry to run this bot locally for develo

null 3 Sep 18, 2022
Run python scripts and pass data between multiple python and node processes using this npm module

Run python scripts and pass data between multiple python and node processes using this npm module. process-communication has a event based architecture for interacting with python data and errors inside nodejs.

Tyler Laceby 2 Aug 6, 2021