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
Manually Install Python 2.7 pip without any problem !

Python2.7_install_pip Manually Install Python 2.7 pip without any problem ! Download installPip.py to your system and Run the code using this Command

Ali Jafari 1 Dec 09, 2021
Cobalt Strike Sleep Python Bridge

This project is 'bridge' between the sleep and python language. It allows the control of a Cobalt Strike teamserver through python without the need for for the standard GUI client. NOTE: This project

Cobalt Strike 140 Jan 04, 2023
Solutions for the Advent of Code 2021 event.

About 📋 This repository holds all of the solution code for the Advent of Code 2021 event. All solutions are done in Python 3.9.9 and done in non-real

robert yin 0 Mar 21, 2022
The program calculates the BMI of people

Programmieren Einleitung: Das Programm berechnet den BMI von Menschen. Es ist sehr einfach zu handhaben, so können alle Menschen ihren BMI berechnen.

2 Dec 16, 2021
Free Data Engineering course!

Data Engineering Zoomcamp Register in DataTalks.Club's Slack Join the #course-data-engineering channel The videos are published to DataTalks.Club's Yo

DataTalksClub 7.3k Dec 30, 2022
A small script I made that takes any standard Decklist of magic the gathering cards and pulls all card images from scryfall at once!

A small script I made that takes any standard Decklist of magic the gathering cards and pulls all card images from scryfall at once!

15 Aug 26, 2022
This code can help you with auto update for-TV-advertisements in the store.

Auto-update-files-for-TV-advertisements-in-the-store This code can help you with auto update for-TV-advertisements in the store. It was write for Rasp

Max 2 Feb 20, 2022
Scripts to integrate DFIR-IRIS, MISP and TimeSketch

Scripts to integrate DFIR-IRIS, MISP and TimeSketch

Koen Van Impe 20 Dec 16, 2022
API Rate Limit Decorator

ratelimit APIs are a very common way to interact with web services. As the need to consume data grows, so does the number of API calls necessary to re

Tomas Basham 574 Dec 26, 2022
A patch and keygen tools for typora.

A patch and keygen tools for typora.

Mason Shi 1.4k Apr 12, 2022
OTP-Bomber - An otp from MPL ID app, which can be spammed

OTP-Bomber An otp from MPL ID app, which can be spammed Note: Only available on

5 Oct 29, 2022
Junos PyEZ is a Python library to remotely manage/automate Junos devices.

The repo is under active development. If you take a clone, you are getting the latest, and perhaps not entirely stable code. DOCUMENTATION Official Do

Juniper Networks 623 Dec 10, 2022
A python package for bitclout.

BitClout.py A python package for bitclout. Developed by ItsAditya Run pip install bitclout to install the module! Examples of How To Use BitClout.py G

ItsAditya 9 Dec 31, 2021
Senior Comprehensive Project For Python

Senior Comprehensive Project Author: Grey Hutchinson My project, which I nicknamed “Murmur”, was to create a research tool that would use neural netwo

1 May 29, 2022
Multifunctional Analysis of Regions through Input-Output

MARIO Multifunctional Analysis of Regions through Input-Output. (Documents) What is it MARIO is a python package for handling input-output tables and

14 Dec 25, 2022
A carrot-based color palette you didn't know you needed.

A package to produce a carrot-inspired color palette for python/matplotlib. Install: pip install carrotColors Update: pip install --upgrade carrotColo

10 Sep 28, 2021
Safe temperature monitor for baby's room. Made for Raspberry Pi Pico.

Baby Safe Temperature Monitor This project is meant to build a temperature safety monitor for a baby or small child's room. Studies have shown the ris

Jeff Geerling 72 Oct 09, 2022
36 key ergo split keyboard, designed around the Seeeduino Xiao platform

Slice36 Minimalist Split Keyboard 36 key ergo split keyboard, designed around the Seeeduino Xiao platform. Inspired by the Corne, Ferris, Ben Vallack'

54 Dec 21, 2022
A collection of repositories used to realise various end-to-end high-level synthesis (HLS) flows centering around the CIRCT project.

circt-hls What is this?: A collection of repositories used to realise various end-to-end high-level synthesis (HLS) flows centering around the CIRCT p

29 Dec 14, 2022
Yet another Python Implementation of the Elo rating system.

Python Implementation - Elo Rating System Yet another Python Implementation of the Elo rating system (how innovative am I right?). Only supports 1vs1

Kraktoos 5 Dec 22, 2022