bemyak
1 supporter
Devlog №002

Devlog №002

Apr 25, 2021

Parser bugfix

Since /roll can now accept any user input as a roll annotation, I am now facing the sanitization problem. At the moment, roll_bot uses Telegram Markdown syntax, but it turns out to be really tricky to handle properly. The main issues here are with message splitting.

The maximum length of the message that can be sent is 4096 symbols. If the message is longer, the bot tries its best to split it, looking backward from the "hard limit" to find a "soft limit", i.e. some place where it is okay to make a split. This is usually a new line or, if it is too far, just whitespace.

The problem as you may guess is that this split can still occur in the middle of a markdown tag, e.g. *(bold font). In this case, the bot needs to close all unclosed tags in the previous part and open them in a new one. What makes things worse is that this asterisk could have been escaped, so we don't need to do anything with it.

So far I just implemented a rather hacky solution, which should cover 99% of cases. The only way that I see to solve this problem completely is to replace all internal Markdown usage with HTML, but this will require a lot of work (see Pareto Principle).

Anyway, those fixes allowed to pass comments as they are, with a very minimum stripping of whitespace and punctuation.

Extended roll help

Since the /roll command becomes really complicated extensive, users might become lost with its syntax. I ended up implementing /help roll command to explain all the nuances and cover most of the use cases with nice examples.

Do not send error messages in groups

From the logs, I see that the bot is often used in groups, sometimes along with other bots. Users also may start their messages with a / to indicate out-of-role text. This leads to the bot sometimes receives commands and messages that were not addressed to it. In this case, it started to spam with "I don't know this command" or was just sending the help message.

This is not the case anymore. If the message arrived from a group and is not recognized, the bot just remains silent.

Enjoy this post?

Buy bemyak a coffee

More from bemyak