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
Calc.py - A powerful Python REPL calculator

Calc - A powerful Python REPL calculator This is a calculator with a complex sou

Alejandro 8 Oct 22, 2022
Xoroshiro-cairo - A xoroshiro128** pseudorandom number generator implementation in Cairo

xoroshiro-cairo A xoroshiro128** pseudorandom number generator implementation in

Milan Cermak 26 Oct 05, 2022
Python Example Project Structure

Python Example Project Structure Example of statuses that can be in readme: Visit my docs for the full documentation, examples and guides. With this p

1 Oct 31, 2021
Simple script with AminoLab to send ghost messages

Simple script with AminoLab to send ghost messages

Moleey 1 Nov 22, 2021
This is a Blender 2.9 script for importing mixamo Models to Godot-3

Mixamo-To-Godot This is a Blender 2.9 script for importing mixamo Models to Godot-3 The script does the following things Imports the mixamo models fro

8 Sep 02, 2022
A Trace Explorer for Reverse Engineers

Tenet - A Trace Explorer for Reverse Engineers Overview Tenet is an IDA Pro plugin for exploring execution traces. The goal of this plugin is to provi

1k Jan 02, 2023
Online HackerRank problem solving challenges

LinkedListHackerRank Online HackerRank problem solving challenges This challenge is part of a tutorial track by MyCodeSchool You are given the pointer

Sefineh Tesfa 1 Nov 21, 2021
DRF magic links

drf-magic-links Installation pip install drf-magic-links Add URL patterns # urls.py

Dmitry Kalinin 1 Nov 07, 2021
Anti VirusTotal written in Python.

How it works Most of the anti-viruses on VirusToal uses sandboxes or vms to scan and detect malicious activity. The code checks to see if the devices

cliphd 3 Dec 26, 2021
Life Dynamics for python

Daphny_counter run command must be like this: /usr/bin/python3 /home/nmakagonov/Daphny/daphny_counter/Daphny_counter.py -o /home/nmakagonov/Daphny/out

12 Sep 05, 2022
A Notifier Program that Notifies you to relax your eyes Every 15 Minutes👀

Every 15 Minutes is an application that is used to Notify you to Relax your eyes Every 15 Minutes, This is fully made with Python and also with the us

FSP Gang s' Admin 1 Nov 03, 2021
This simple script generates a backup of a given Python and R environment

Python Environment Backup It’s always good to maintain your Python and R Anaconda environment packages properly listed and well-kept in case you have

Andrew Laganaro 1 Jul 13, 2022
A simple bot that will help you in your learning and make it more fun.

hyperskill-SimpleChattyBot-python A simple bot that will help you in your learning and make it more fun. Syntax bot.py Stages Stage #1: Zuhura Bot we

1 Nov 09, 2021
We'll be using HTML, CSS and JavaScript for the frontend

We'll be using HTML, CSS and JavaScript for the frontend. Nothing to install in specific. Open your text-editor and start coding a beautiful front-end.

Mugada sai tilak 1 Dec 15, 2021
Fiber implements an proof-of-concept Python decorator that rewrites a function

Fiber implements an proof-of-concept Python decorator that rewrites a function so that it can be paused and resumed (by moving stack variables to a heap frame and adding if statements to simulate jum

Tyler Hou 225 Dec 13, 2022
Projeto-menu - This project is designed to learn more about control mechanisms in Python programming

Projeto-menu - This project is designed to learn more about control mechanisms in Python programming

Henrik Ricarte 2 Mar 01, 2022
The tool helps to find hidden parameters that can be vulnerable or can reveal interesting functionality that other hunters miss.

The tool helps to find hidden parameters that can be vulnerable or can reveal interesting functionality that other hunters miss. Greater accuracy is achieved thanks to the line-by-line comparison of

197 Nov 14, 2022
Get information about what a Python frame is currently doing, particularly the AST node being executed

executing This mini-package lets you get information about what a frame is currently doing, particularly the AST node being executed. Usage Getting th

Alex Hall 211 Jan 01, 2023
Basic repository showing how to use Hydra + Hydra launchers on SLURM cluster

Slurm-Hydra-Submitit This repository is a minimal working example on how to: setup Hydra setup batch of slurm jobs on top of Hydra via submitit-launch

Raphael Meudec 2 Jul 25, 2022
A Regex based linter tool that works for any language and works exclusively with custom linting rules.

renag Documentation Available Here Short for Regex (re) Nag (like "one who complains"). Now also PEGs (Parsing Expression Grammars) compatible with py

Ryan Peach 12 Oct 20, 2022