8000 [FEATURE] Convenience Method for `MessageEntity` Concatenation · Issue #4372 · python-telegram-bot/python-telegram-bot · GitHub
[go: up one dir, main page]

Skip to content
[FEATURE] Convenience Method for MessageEntity Concatenation #4372
@Bibo-Joshi

Description

@Bibo-Joshi

What kind of feature are you missing? Where do you notice a shortcoming of PTB?

The discussion with TG in tdlib/telegram-bot-api#515 has made it clear that we should encourage users to work more with MessageEntities rather than with our text_html/markdown helpers. Since this is sometimes cumbersome, convenience functionality for working with ME is surely advisable and we've made a step into that direction with #4323 .

What I'd like to see in addition is convenience functionality for catenating text with entities as initially touched in tdlib/telegram-bot-api#515 (comment)

Describe the solution you'd like

new class methods

  • ME.shift_entities(entities: Sequence[ME], by: str | int) -> Sequence[ME]: shifts the entities by the specified length or the utf-16 length of the string of by is a string. This would be useful for adding a prefix to a message with entities
  • ME.concatetane(first: tuple[str, Sequence[ME]], second: tuple[str, Sequence[ME]]) -> tuple[str, Sequence[ME]]: Concatenates text and entities. Uses ME.shift_entities internally

Describe alternatives you've considered

ME.concatenate could be skipped in a first step as it can be implemented using shift_entities

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0