Skip to content

Releases: tm-a-t/TGPy

v0.9.1

25 Feb 09:43
Compare
Choose a tag to compare

Fix

  • Update from older versions (df11e8b)

v0.9.0

25 Feb 09:14
Compare
Choose a tag to compare

Major update

  • restructured the code
  • cancel, // now remember cancellation permanently
  • reactions fix now remembers message content hashes after a restart. This means no more 'Edit message again to evaluate' messages
  • implemented simple key-value store for storing various data
    • tgpy.api.config.get(key: str, default: JSON = None) -> JSON
    • tgpy.api.config.set(key: str, value: JSON)
    • tgpy.api.config.unset(key: str)
    • tgpy.api.config.save() useful when modifying objects acquired using the .get method in place
  • if the __all__ variable is set in a module, only objects with names in that list are exported (added to variables list)
  • ctx.is_module is True if the code is executed as a module (on startup)
  • ctx.is_manual_output can be set to True to prevent the last message edit by TGPy so that you can edit it yourself
  • cancel, //, restart, ping, update, modules object and .await syntax are now implemented as regular modules in the std directory
    • builtin modules can be disabled with core.disable_modules config option (for example, tgpy.api.config.set('core.disable_modules', ['postfix_await']))
  • extra keys are now allowed in module metadata. They are parsed into Module.extra dict
  • tgpy.api module is now used for public API instead of the tgpy object
  • moved get_installed_version, get_running_version, installed_as_package, get_user, get_hostname, running_in_docker, try_await, outgoing_messages_filter
    functions to tgpy.api (tgpy.api.utils)
  • new public API functions:
    • async parse_code(text: str) -> ParseResult(is_code: bool, original: str, transformed: str, tree: AST | None)
    • parse_tgpy_message(message: Message) -> MessageParseResult(is_tgpy_message: bool, code: str | None, result: str | None)
    • async tgpy_eval(code: str, message: Message = None, *, filename: str = None) -> EvalResult(result: Any, output: str)
  • AST transformers. AST transformers are applied after code transformers
  • exec hooks. Exec hooks are executed before the message is parsed and handled. Exec hooks must have the following signature: async hook(message: Message, is_edit: bool) -> Message | bool | None. An exec hook may edit the message using Telegram API methods and/or alter the message in place. If a hook returns Message object or alters it in place, it's used instead of the original Message object during the rest of handling (including calling other hook functions). If a hook returns True or None, execution completes normally. If a hook returns False, the rest of hooks are executed and then the handling stops without further message parsing or evaluating
    • Apply hooks with tgpy.api.exec_hooks.apply(message: Message, *, is_edit: bool) -> Message | False. This method returns False if any of the hooks returned False, Message object that should be used instead of the original one otherwise
  • new dict/list compatible transformers/hooks interface (store_obj is one of tgpy.api.code_transformers, tgpy.api.ast_transformers or tgpy.api.exec_hooks)
    • add a function with store_obj.add(name, function)
    • add/replace a function with store_obj[name] = function
    • get a function with store_obj[name or index]
    • iter functions with for name, function in store_obj
    • apply transformers/hooks with tgpy.api.code_transformers.apply(code: str) -> str, tgpy.api.ast_transformers.apply(tree: AST) -> AST or tgpy.api.exec_hooks.apply (documented above)
  • podman is now correctly detected so that tgpy doesn't try to update itself in the container
  • Change in-message url to tgpy.tmat.me (8737ca9)
  • Move tokenize_string and untokenize_to_string to tgpy.api (7d8c3b2)

v0.8.0

15 Feb 17:52
Compare
Choose a tag to compare

Feature

  • Wrap sys.stdout instead of print to capture output + properly use contextvars (7aa2015)

Fix

  • Don't stop on unhandled errors. They may happen when, for example, a module uses asyncio.create_task (3584f22)

v0.7.0

05 Feb 14:47
Compare
Choose a tag to compare

Feature

  • Update telethon (new markdown parser, html parser fixes) (43dd76f)
  • Update dependencies (layer 152) (234dc86)

Fix

  • Handle entities properly when editing "//" message (6d989dc)
  • Specify parse_mode in error handler to support markdown global parse mode (60cd81b)
  • Use message.raw_text instead of message.text to detect // (a85b1c8)

v0.6.2

22 Jan 18:15
Compare
Choose a tag to compare

Fix

  • Fix IndentationError appearing for some non-code messages (599c84f)
  • docker: Add /venv/bin to path (00be149)

Documentation

v0.6.1

06 Jan 18:11
Compare
Choose a tag to compare

Fix

  • Update command saying "Already up to date" while in fact updating correctly (9b25fe6)

v0.6.0

26 Nov 22:58
Compare
Choose a tag to compare

Feature

  • Use MessageEntityPre with language set to 'python' to enable syntax highlighting on supported clients (e.g. WebZ). Closes #24 (5de6ded)

Fix

  • Keep 'cancel' message when replying to other user (fixes #21) (057231d)
  • Ignore error when running code deletes the message itself (d022450)

Documentation

v0.5.1

09 Aug 14:50
Compare
Choose a tag to compare

Fix

  • Restart() now edits message properly (60afa44)
  • Compatibility with python 3.9 (f3c0468)

v0.5.0

08 Aug 18:25
Compare
Choose a tag to compare

Feature

  • Use custom telethon fork with updated layer (91894fc) (9c7738e)
  • Transform x.await into await x (6117421) (fde6291)
  • Better version detection, ping() builtin improvements (265b83f)
  • Allow to specify data directory via environment variable TGPY_DATA (4d769da)

Fix

  • Setting/removing reaction no longer triggers reevaluation (#25) (cf6e64e)
  • Emojis no longer break messages markup (#10) (20f48bc)
  • Parsing of modules with triple quotes in code (485166d)

Documentation

  • Guide rewrite

v0.4.1

10 Jan 14:36
Compare
Choose a tag to compare

Fix

  • code detection: Ignore messages like "fix: fix" (1b73815)