Skip to content

Commit

Permalink
docs: readme & guide updates
Browse files Browse the repository at this point in the history
- add guide link to readme
- 'hooks' are replaced with 'modules'
- API page
  • Loading branch information
tm-a-t authored and vanutp committed Jan 1, 2022
1 parent 7d0e283 commit 59a4036
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 65 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -78,6 +78,8 @@ async def delete():
await message.delete()
```

## [TGPy Guide](https://tgpy.tmat.me/)

## Credits

- Thanks to [penn5](https://github.com/penn5) for [meval](https://github.com/penn5/meval)
Expand Down
14 changes: 14 additions & 0 deletions guide/docs/api.md
@@ -0,0 +1,14 @@
# API

## Code transformers

`tgpy.add_code_transformer`

`code_transformers`

TODO

## Available variables

- `tgpy.variables` - dictionary of variables
- `tgpy.constants` - dictionary of [TGPy constants](builtins.md#tgpy-objects)
6 changes: 5 additions & 1 deletion guide/docs/builtins.md
Expand Up @@ -70,5 +70,9 @@ to Telegram API).

## TGPy objects

- [`hooks`](hooks.md)
- [`modules`](modules.md)
- [`ctx`](context.md)

## TGPy API object

- [`tgpy`](api.md)
63 changes: 0 additions & 63 deletions guide/docs/hooks.md

This file was deleted.

57 changes: 57 additions & 0 deletions guide/docs/modules.md
@@ -0,0 +1,57 @@
# Modules

Modules are executed when TGPy starts. For example, with modules you can define shortcut functions for future using.

## Add modules

Add one of previous TGPy messages to modules by replying with `modules.add` function.

```python
modules.add(module_name)
```

You can also use `#!python modules.add(module_name, code)` to add any other code.

If the module with this name already exists, its code will be replaced.

!!! example

1. Define a square function:

```python
def square(x):
return x * x
TGPy> None
```

2. Save the definition to modules:

```python
# in reply to the previous message
modules.add('square')
TGPy> Added module 'square'.
The module will be executed every time TGPy starts.
```

## Remove modules

Remove a module by name:
```python
modules.remove(module_name)
```

## Manage your modules

Use the string value of `modules` to list all of your modules:

```python
modules
```

Modules are executed when TGPy starts. By default, modules are executed in order of addition.

Modules are stored as separate Python files in `data/modules` directory. You can safely edit them manually.

TODO: metadata explanation
3 changes: 2 additions & 1 deletion guide/mkdocs.yml
Expand Up @@ -43,5 +43,6 @@ nav:
- builtins.md
- code_detection.md
- Advanced:
- hooks.md
- modules.md
- context.md
- api.md

0 comments on commit 59a4036

Please sign in to comment.