Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	tgpy/_core/eval_message.py
  • Loading branch information
tm-a-t committed Apr 20, 2024
2 parents 3fa538f + 80219a5 commit 9879d61
Show file tree
Hide file tree
Showing 55 changed files with 2,413 additions and 1,008 deletions.
8 changes: 7 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
**/__pycache__/
venv/
guide/site
.idea/
/.github/
/data/
/guide/site
/guide/.cache
flake.lock
flake.nix
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ data/
config.yaml

guide/site
guide/.cache
62 changes: 62 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,68 @@

<!--next-version-placeholder-->

## v0.14.0 (2024-03-09)

### Feature

* **docker:** Run specified commands on container creation. This feature can be used for example to persist installed packages between updates ([`456f503`](https://github.com/tm-a-t/TGPy/commit/456f5035ef8f0900750acee2a901cfdcea2e28b6))

### Fix

* Tgpy error when editing MessageService, e.g. when deleting all messages in pm or beating your high score in games ([`5d6fb5e`](https://github.com/tm-a-t/TGPy/commit/5d6fb5e9f0b6556163c90c327a4d2ac6afe62b96))

## v0.13.2 (2023-12-10)

### Fix

* Update telethon (fix draft constructor), update all dependencies ([`a2b6064`](https://github.com/tm-a-t/TGPy/commit/a2b60641af3a0cab9fef08e95e07447b6c61432a))

## v0.13.1 (2023-12-06)

### Fix

* Use official cryptg (prebuilt wheels for Python 3.12), bump telethon (fixes usage of Draft), set minimum python version to 3.10 ([`9e49739`](https://github.com/tm-a-t/TGPy/commit/9e497391f83dc6b333a6752f221d1221ea3d6cdb))

## v0.13.0 (2023-12-05)

### Feature

* Support proxy ([`cd6bc90`](https://github.com/tm-a-t/TGPy/commit/cd6bc9086a818c45ee129ace88a0662980ad6c92))

## v0.12.1 (2023-10-28)

### Fix

* **Telethon:** New layer fix ([`8145bd3`](https://github.com/tm-a-t/TGPy/commit/8145bd3c58371e047114e834e2fbdba2de7ec575))

## v0.12.0 (2023-10-28)

### Feature

* **Telethon:** Update to layer 166 ([`a18dc0d`](https://github.com/tm-a-t/TGPy/commit/a18dc0d663362b50dfe7827ebac6ea2971220248))

## v0.11.0 (2023-09-29)

### Feature

* **Telethon:** Fixes for the new layer and many more fixes from upstream ([`800fcd5`](https://github.com/tm-a-t/TGPy/commit/800fcd5f9799e82ed8a85155afd1c884b22355d3))

## v0.10.0 (2023-09-25)

### Feature

* **Telethon:** Layer 164 ([`2d0c186`](https://github.com/tm-a-t/TGPy/commit/2d0c1865fad08c8ee1f511f6749a22ede7374641))

### Documentation

* Revert narrowing container ([`bb0bff9`](https://github.com/tm-a-t/TGPy/commit/bb0bff98b058041a62f45fed260bf1f42ce32900))
* Recipes and new homepage ([`28e8eba`](https://github.com/tm-a-t/TGPy/commit/28e8ebae6f57642ce2dea7a70d4bd0bcfee94dc0))
* Fix transformer example ([`8007b25`](https://github.com/tm-a-t/TGPy/commit/8007b2587046550937cc63f7e5cd66f86e928f29))

## v0.9.7 (2023-07-23)
### Fix
* Consistent colors in setup across all terminals ([`faa625b`](https://github.com/tm-a-t/TGPy/commit/faa625bd2f4543b08ea7af361c8217cf006303d2))

## v0.9.6 (2023-06-01)
### Fix
* Strip device model ([`a775cc5`](https://github.com/tm-a-t/TGPy/commit/a775cc5a6415e92d023c421578f31bdd57a7a88d))
Expand Down
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1.3
FROM python:3.10-slim as base
FROM python:3.12-slim as base
WORKDIR /app

FROM base as builder
Expand All @@ -20,14 +20,15 @@ RUN --mount=type=cache,target=/root/.cache/pip \

COPY . .
RUN sed -i "s/\(COMMIT_HASH *= *\).*/\1'$(git rev-parse HEAD)'/" tgpy/version.py
RUN rm -rf .git guide poetry.lock pyproject.toml .dockerignore .gitignore README.md

FROM base as runner
COPY --from=builder /venv /venv
ENV PATH="/venv/bin:$PATH"

COPY --from=builder /app/tgpy tgpy
COPY --from=builder /app /app

ENV TGPY_DATA=/data
VOLUME /data

ENTRYPOINT ["/venv/bin/python", "-m", "tgpy"]
ENTRYPOINT ["/app/entrypoint.sh"]
89 changes: 47 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,84 +1,89 @@
<div align="center" style="width: 50%">

<h3>
<a href="https://tgpy.tmat.me">
<img alt="TGPy Logo" src="guide/docs/assets/TGPy.png" width=280>
</a>

Runs Python code snippets<br>within your Telegram messages
</h3>

<h6></h6>

# TGPy

**Runs Python code snippets within your Telegram messages**

[![PyPI - Downloads](https://img.shields.io/pypi/dm/tgpy?style=flat-square)](https://pypi.org/project/tgpy/)
[![PyPI](https://img.shields.io/pypi/v/tgpy?style=flat-square&color=9B59B6)](https://pypi.org/project/tgpy/)
[![Docker Image Version (latest semver)](https://img.shields.io/docker/v/tgpy/tgpy?style=flat-square&label=docker&sort=semver&color=9B59B6)](https://hub.docker.com/r/tgpy/tgpy)
[![Open issues](https://img.shields.io/github/issues-raw/tm-a-t/TGPy?style=flat-square)](https://github.com/tm-a-t/TGPy/issues)
[![Docs](https://img.shields.io/website?style=flat-square&label=docs&url=https%3A%2F%2Ftgpy.tmat.me)](https://tgpy.tmat.me/)

</div>

<br>

Here are a few examples of how people use TGPy:

🧮 Run Python as an in-chat calculator
Guide: https://tgpy.tmat.me/guide

🔍 Search for song lyrics within a chat
Recipes: https://tgpy.tmat.me/recipes

🧹 Delete multiple messages with a command
Discussion: https://t.me/tgpy_flood

📊 Find out the most active members in a chat
<br>

✏️ Instantly convert TeX to Unicode in messages:<br>For example, `x = \alpha^7` becomes `x = α⁷`
https://user-images.githubusercontent.com/38432588/181266550-c4640ff1-71f2-4868-ab83-6ea3690c01b6.mp4

## About
<br>

TGPy allows you to easily write and execute code snippets directly within your Telegram messages. Combine Telegram features with the full power of Python: Integrate with libraries and APIs. Create functions and TGPy modules to reuse code in the future. Set up code transformers and hooks to create custom commands and tweak Python syntax.

TGPy uses Telegram API through the [Telethon](https://github.com/LonamiWebs/Telethon) library.
<!-- --8<-- [start:body] -->
<!-- Starting from here, the content is shared between the readme file and the docs homepage -->

## Quick Start

Python 3.10+ required. Install TGPy and connect it to your Telegram account:
Python 3.10+ required. Install using pipx:

```shell
> pip install tgpy
> tgpy
pipx install tgpy
tgpy
```

You’re ready now. Send Python code to any chat, and it will run. Change your message to change the result. [Read more on installation](http://tgpy.tmat.me/installation/)
or Docker:

## Learn
```shell
docker pull tgpy/tgpy
docker run -it --rm -v /tgpy_data:/data tgpy/tgpy
```

[🙂 Basics Guide](https://tgpy.tmat.me/basics/code/)
Then follow instructions to connect your Telegram account.

[😎 Extensibility Guide](https://tgpy.tmat.me/extensibility/context/)
More on installation: [https://tgpy.tmat.me/installation](https://tgpy.tmat.me/installation)

[📗 Reference](https://tgpy.tmat.me/reference/builtins/)
Next, learn TGPy basics: [https://tgpy.tmat.me/basics](https://tgpy.tmat.me/basics)

[💬 Russian-Speaking Chat](https://t.me/tgpy_flood)
## Use Cases

Here are a few examples of how people use TGPy:

## Demo
🧮 Run Python as an in-chat calculator

https://user-images.githubusercontent.com/38432588/181266550-c4640ff1-71f2-4868-ab83-6ea3690c01b6.mp4
🔍 Search for song lyrics within a chat

<br>
🧹 Delete multiple messages with a command

![A message processed with TGPy](guide/docs/assets/example.png)
_Finding out the number of premium users in a chat_
📊 Find out the most active members in a chat

## Inspiration
✏️ Instantly convert TeX to Unicode in messages:<br>For example, `x = \alpha^7` becomes `x = α⁷`

## About

TGPy is inspired by [FTG](https://gitlab.com/friendly-telegram/friendly-telegram) and similar userbots. However, the key concept is different: TGPy is totally based on usage of code in Telegram rather than plugging extra modules. It was designed for running single-use scripts and reusing code flexibly. You can think of TGPy as a userbot for programmers.
TGPy allows you to easily write and execute code snippets directly within your Telegram messages. Combine Telegram
features with the full power of Python: Integrate with libraries and APIs. Create functions and TGPy modules to reuse
code in the future. Set up code transformers and hooks to create custom commands and tweak Python syntax.

## Credits
TGPy uses Telegram API through the [Telethon](https://github.com/LonamiWebs/Telethon) library.

TGPy is built on [Telethon](https://github.com/LonamiWebs/Telethon), a Python library to interact with Telegram API.
## Inspiration and Credits

TGPy is inspired by [FTG](https://gitlab.com/friendly-telegram/friendly-telegram) and similar userbots. However, the key
concept is different: TGPy is totally based on usage of code in Telegram rather than plugging extra modules. It was
designed for running single-use scripts and reusing code flexibly. You can think of TGPy as **a userbot for programmers
**.

We built TGPy with [Telethon](https://github.com/LonamiWebs/Telethon), a Python library to interact with Telegram API.
Basic code transformation (such as auto-return of values) is based on [meval](https://github.com/penn5/meval).

TGPy Docs use [Material for MKDocs](https://squidfunk.github.io/mkdocs-material/) with custom CSS.

## License

This project is licensed under the terms of the MIT license.

<!-- --8<-- [end:body] -->
31 changes: 31 additions & 0 deletions docker/install_mods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import logging
from subprocess import Popen

from tgpy.api.config import config

logging.basicConfig(
format='[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
level=logging.INFO,
)
logger = logging.getLogger('install_mods')


def main():
config.load()
command_groups: dict = config.get('docker.setup_commands', {})
command_groups['_core'] = 'apt-get update'
for name, commands in sorted(command_groups.items()):
if isinstance(commands, str):
commands = [commands]
logger.info(f"Running setup command group '{name}'")
for command in commands:
logger.info(f"Running setup command '{command}'")
p = Popen(command, shell=True)
p.wait()
if p.returncode != 0:
logger.info("Running setup command failed")


if __name__ == '__main__':
main()
8 changes: 8 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -e
if [ ! -f container_setup_completed ]; then
PYTHONPATH=. python /app/docker/install_mods.py
touch container_setup_completed
fi

exec python -m tgpy
Loading

0 comments on commit 9879d61

Please sign in to comment.