timoniq / telegrinder

Modern visionary telegram bot framework
MIT License
31 stars 5 forks source link

feat: compose polymorph implementations #76

Closed timoniq closed 3 months ago

timoniq commented 3 months ago

a node must allow adding multiple compose implementations

for different sets of child nodes. (this may have a lot of test cases to handle)

class Text(ScalarNode, str):
    @composer
    async def compose_message(cls, message: MessageNode) -> typing.Self:
        ...
        return cls(message.text.unwrap())

    @composer
    async def compose_caption(cls, attachment: Attachment) -> typing.Self:
        # works with attachments with caption
        ...
        return cls(attachment.caption.unwrap())