Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templating system #7

Open
e-dreyer opened this issue Jul 25, 2023 · 4 comments
Open

Templating system #7

e-dreyer opened this issue Jul 25, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@e-dreyer
Copy link
Owner

e-dreyer commented Jul 25, 2023

Problem

MastoBot is intended to simplify the process of creating bots for Mastodon. This involves allowing the user to perform actions on notifications and filtering them, but often, users would like to respond to a notification with a post.

This can easily be done in code, but Jinja2 templates are by far the most sustainable and future-proof method to do this.

It would allow for better customization and better implementations, and templates could also be easily shared between users but still allow for a personalized touch.

Such a templating system is generic enough to be part of MastoBot

@e-dreyer e-dreyer added the enhancement New feature or request label Jul 25, 2023
@e-dreyer e-dreyer self-assigned this Jul 25, 2023
@e-dreyer
Copy link
Owner Author

One bug I encountered recently in MastoBot-3D was due to some user with a hadh for their username. I implemented a Jinja2 templating system, but an API exception was thrown by Mastodon.py due to the rendered template being too long for the character limit.

If such a templating system were to be implemented. It should allow for a way to automatically split up long templates, sending them piece-by-piece and recursively reply with the following segment to the previous post, to allow for the creation of threads through templating.

@e-dreyer e-dreyer mentioned this issue Jul 25, 2023
@e-dreyer
Copy link
Owner Author

e-dreyer commented Jul 25, 2023

Possible example implementation I found.

@e-dreyer
Copy link
Owner Author

e-dreyer commented Jul 26, 2023

One bug I encountered recently in MastoBot-3D was due to some user with a hadh for their username. I implemented a Jinja2 templating system, but an API exception was thrown by Mastodon.py due to the rendered template being too long for the character limit.

If such a templating system were to be implemented. It should allow for a way to automatically split up long templates, sending them piece-by-piece and recursively reply with the following segment to the previous post, to allow for the creation of threads through templating.

The problem is, where should posts be split up? Should the responsibility of formatting be habded over to the user and posts are split up to the nearest new-line \n or character.

Example: A post is analyzed until a new-line is encountered. If the next new-line added to the length results in a character limit exceeded error, it should be split up. But what happens if the first paragraph exceeds the limit already? Should an exception be raised during initialization, requiring all templates to be scanned at initialization with some arbritary max length default value?

How do we judge and test this? Where is the line?

@e-dreyer
Copy link
Owner Author

Another problem here is, implementing the following function

def getTemplateText(filename: str, fields: Dict): -> str:
    ...

would result in errors if the user were to change the template to include variables not included in the fields dictionary. It should rather be:

def getTemplateText(filename: str, *args, **kwargs): -> str:
    fields = self.variables # Some dict with a bunch of variables

This way were self.variables is a Dict of predefined variables and *args and **kwargs include additional variables. Because any addition or changes to the template would break an existing code-base.

@e-dreyer e-dreyer removed their assignment Jul 26, 2023
@e-dreyer e-dreyer mentioned this issue Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

1 participant