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
Persistent/Immutable/Functional data structures for Python

Pyrsistent Pyrsistent is a number of persistent collections (by some referred to as functional data structures). Persistent in the sense that they are

Tobias Gustafsson 1.8k Dec 31, 2022
A Gura parser implementation for Python

Gura parser This repository contains the implementation of a Gura format parser in Python. Installation pip install gura-parser Usage import gura gur

JWare Solutions 19 Jan 25, 2022
A lightweight Python module to interact with the Mitre Att&ck Enterprise dataset.

enterpriseattack - Mitre's Enterprise Att&ck A lightweight Python module to interact with the Mitre Att&ck Enterprise dataset. Built to be used in pro

xakepnz 7 Jan 01, 2023
Python library for creating and parsing HSReplay XML files

python-hsreplay A python module for HSReplay support. https://hearthsim.info/hsreplay/ Installation The library is available on PyPI. pip install hsre

HearthSim 45 Mar 28, 2022
Powering up Apache JMeter with Streamlit and opening the door for machine learning.

Powering up Apache JMeter with Streamlit Overview Apache JMeter is an open source load testing tool written in 100% pure Java. JMeter supports umpteen

NaveenKumar Namachivayam ⚡ 16 Aug 24, 2022
IPO Checker for NEPSE

IPO Checker Checks more than one account for an IPO. Usage: ipo_checker.py [-h] --file FILE IPO Checker for a list. optional arguments: -h, --help

Sagar Tamang 4 Sep 20, 2022
LinuxHelper - A collection of utilities for non-technical Linux users accessible via a GUI

Linux Helper A collection of utilities for non-technical Linux users accessible via a GUI This app is still in very early development, expect bugs and

Seth 7 Oct 03, 2022
万能通用对象池,可以池化任意自定义类型的对象。

pip install universal_object_pool 此包能够将一切任意类型的python对象池化,是万能池,适用范围远大于单一用途的mysql连接池 http连接池等。 框架使用对象池包,自带实现了4个对象池。可以直接开箱用这四个对象池,也可以作为例子学习对象池用法。

12 Dec 15, 2022
A software dedicated to automaticaly select the agent of your desire in Valorant

AUTOPICKER A software dedicated to automaticaly select the agent of your desire in Valorant GUIDE Before stariting to use this program check if you ha

p1n00 0 Sep 24, 2022
Protocol Buffers for the Rest of Us

Protocol Buffers for the Rest of Us Motivation protoletariat has one goal: fixing the broken imports for the Python code generated by protoc. Usage He

Phillip Cloud 76 Jan 04, 2023
This is a Python 3.10 port of mock, a library for manipulating human-readable message strings.

This is a Python 3.10 port of mock, a library for manipulating human-readable message strings.

Alexander Bartolomey 1 Dec 31, 2021
Minimalist BERT implementation assignment for CS11-747

minbert Assignment by Zhengbao Jiang, Shuyan Zhou, and Ritam Dutt This is an exercise in developing a minimalist version of BERT, part of Carnegie Mel

Graham Neubig 51 Jan 03, 2023
OpenSea NFT API App using Python and Streamlit

opensea-nft-api-tutorial OpenSea NFT API App using Python and Streamlit Tutorial Video Walkthrough https://www.youtube.com/watch?v=49SupvcFC1M Instruc

64 Oct 28, 2022
Meaningful and minimalist release notes for developers

Managing manual release notes is hard. Therefore, everyone tends to generate release notes from commit messages. But, you won't get a meaningful release note at the end.

codezri 31 Dec 30, 2022
The Python Fuzzer that the world deserves 🐍

pip3 install frelatage Current release : 0.0.2 The Python Fuzzer that the world deserves Installation | How it works | Features | Use Frelatage | Conf

Rog3r 219 Dec 21, 2022
A Way to Use Python, Easier.

PyTools A Way to Use Python, Easier. How to Install Just copy this code, then make a new file in your project directory called PyTools.py, then paste

Kamran 2 Aug 15, 2022
End-to-End text sumarization, QAs generation using flask.

Help-Me-Read A web application created with Flask + BootStrap + HuggingFace 🤗 to generate summary and question-answer from given input text. It uses

Ankush Kuwar 12 Nov 13, 2022
Run PD patches in NRT using Python

The files in this repository demonstrate how to use Pure Data (Pd) patches designed to run in Non-Real-Time mode to batch-process (synthesize, analyze, etc) sounds in series using Python.

Jose Henrique Padovani 3 Feb 08, 2022
An AI-powered device to stop people from stealing my packages.

Package Theft Prevention Device An AI-powered device to stop people from stealing my packages. Installation To install on a raspberry pi, clone the re

rydercalmdown 157 Nov 24, 2022
India's own RPA Platform Python Powered

Welcome to My-AutoPylot , Made in India with ❤️ What is My-AutoPylot? PyBots is an Indian firm based in Vadodara, Gujarat. My-AutoPylot is a product d

PyBots Pvt Ltd 28 Sep 12, 2022