tm-a-t / tgpy Goto Github PK
View Code? Open in Web Editor NEWRuns Python code snippets within your Telegram messages
Home Page: https://tgpy.tmat.me
License: MIT License
Runs Python code snippets within your Telegram messages
Home Page: https://tgpy.tmat.me
License: MIT License
Now you have to login to the server and open the logs for TGPy each time something breaks.
We’re starting recipes, short TGPy tutorials: https://tgpy.tmat.me/recipes
Here are some ideas for inspiration:
Please include code and at least some explanation. There are no strict rules for the format, but remember your recipe should be interesting for other users.
If we find your recipe helpful, we will publish it on the site.
Write a Dockerfile and publish to Docker Hub
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.
word
another_word
...
2. Tuple word, another_word, ...
3. Single hyphen confused with binary subtraction operator w-ord
4. URLs example.com
or t.me/username
or t.me/c/1234567890/1000
5. Email addresses [email protected]
6. not good
7. Unary operators to constant-1
8. 1 + 3
a - b, c
d - e, f
First line in traceback isn't shown when function is not awaited in message, thus awaited by meval instead. In this case, this line is skipped, because it's not message's code
Example:
Original traceback:
async def delete():
ctx_orig = await ctx.msg.get_reply_message()
await ctx_orig.delete()
await ctx.msg.delete()
delete()
TGPy> Error occurred
Traceback (most recent call last):
File ".../app/run_code/meval.py", line 177, in <listcomp>
ret = [await el if inspect.isawaitable(el) else el for el in ret]
File "tgpy://message/...", line 3, in delete
await ctx_orig.delete()
AttributeError: 'NoneType' object has no attribute 'delete'
Stripped traceback:
Traceback (most recent call last):
File "tgpy://message/...", line 3, in delete
await ctx_orig.delete()
AttributeError: 'NoneType' object has no attribute 'delete'
It should be "<module>" instead
Example:
Traceback (most recent call last):
File "tgpy://message/...", line 1, in tmp
1/0
ZeroDivisionError: division by zero
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
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 ...
The password is not shown or at least shown in stars (for example, **********
for 10-symbol password)
The password is shown in plain text, which is insecure when running TGPy in a public place
Rust is a memory-safe and secure language and is more efficient than Python. It is type safe and has better telegram support. Also, the industry trend is shifting towards Rust so we should rewrite this in Rust.
Once a code snippet message gets a first reaction, TGPy treats the message as edited and reruns the code. Telegram bug?
TGPy messages with errors look quite like random spam, and full error tracebacks are rarely useful.
I am proposing to show only the last line of the error and save the full error to a variable and/or logs.
Current behavior:
msg.something
TGPy> Error occurred
Traceback (most recent call last):
File "/home/tmat/.local/pipx/venvs/tgpy/lib/python3.11/site-packages/tgpy/_core/meval.py", line 175, in _meval
new_locs, ret = await getattr(py_module, 'tmp')(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "tgpy://message/-1001611149679/38326", line 1, in tmp
msg.something
AttributeError: 'Message' object has no attribute 'something'
Suggested behavior:
msg.something
TGPy> AttributeError: 'Message' object has no attribute 'something'
WebZ now supports syntax highlighting which might be useful for TGPy
Think how commands can be implemented and if it should be done at all
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.