Other API features
TGPy API allows you to use TGPy internal features in your messages and modules.
python
import tgpy.apiConfig
tgpy.api.config provides you simple key-value store for any data. The data, as well as some TGPy settings, is saved to tgpy/config.yml.
python
tgpy.api.config.get(key: str, default: JSON = None) -> JSONpython
tgpy.api.config.set(key: str, value: JSON)python
tgpy.api.config.unset(key: str)python
tgpy.api.config.save()Useful when modifying objects acquired via the get method
Code processing
You can use the following functions to parse and run code.
Parse code
python
async parse_code(text: str) -> ParseResult(is_code: bool, original: str, transformed: str, tree: AST | None)Checks if the given text is code and gives AST and other info
Parse a message
python
parse_tgpy_message(message: Message) -> MessageParseResult(is_tgpy_message: bool, code: str | None, result: str | None)Splits Telethon message object into TGPy code and result (if present)
Run code
python
async tgpy_eval(code: str, message: Message = None, *, filename: str = None) -> EvalResult(result: Any, output: str)Runs code and gets the result and the output
