Mastodon.py icon indicating copy to clipboard operation
Mastodon.py copied to clipboard

How to check total status length before posting when using `status_reply`

Open yuletide opened this issue 2 years ago • 1 comments

I'm working on a bot that replies to existing statuses, filters and then reposts. I'm using status_reply to easily tag the original post author, but recently got an error mastodon.errors.MastodonAPIError: ('Mastodon API returned error', 422, 'Unprocessable Entity', 'Validation failed: Text character limit of 500 exceeded')

It would be great if there was a way to do this validation, or enforce a limit before sending to Mastodon.

Especially when using status_reply a lot of logic is encapsulated in that funciton before it posts, incluing untag and mentions, which are what cause the status to be over length (the original post was 493 characters so adding in the @mention pushes it over 500).

If anyone has a clever way to handle this that I'm missing please share!

yuletide avatar Jan 05 '23 16:01 yuletide

There currently isn’t a way and you‘re absolutely right - there should be. Would be good to implement a function to compute and check effective status length in terms of what counts into the limit to what extent, and maybe with an option to compare against instance reported max length.

Sent from my iPhone

On 5. Jan 2023, at 18:57, Alex Yule @.***> wrote:

 I'm working on a bot that replies to existing statuses, filters and then reposts. I'm using status_reply to easily tag the original post author, but recently got an error mastodon.errors.MastodonAPIError: ('Mastodon API returned error', 422, 'Unprocessable Entity', 'Validation failed: Text character limit of 500 exceeded')

It would be great if there was a way to do this validation, or enforce a limit before sending to Mastodon.

Especially when using status_reply a lot of logic is encapsulated in that funciton before it posts, incluing untag and mentions, which are what cause the status to be over length (the original post was 493 characters so adding in the @mention pushes it over 500).

If anyone has a clever way to handle this that I'm missing please share!

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.

halcy avatar Jan 05 '23 18:01 halcy