fincubator / tellerbot

Telegram Bot for over-the-counter trading
https://t.me/TellerBot
GNU Affero General Public License v3.0
23 stars 10 forks source link

Change MARKDOWN to MARKDOWN_V2 #91

Open r4rdsn opened 4 years ago

r4rdsn commented 4 years ago

Markdown is now legacy parse mode and was superseded by MarkdownV2 (as per Telegram bot API: https://core.telegram.org/bots/api#markdownv2-style). This change is reflected in aiogram's quote function, so in order to not add reduntant escape characters, it had to be updated. It also allows nested, underline and strikethrough entities, which may be nice in some future.

Unfortunately, it means that a whole lot more characters now must be escaped. These characters: >#+-=|{}.! are not used in markup as of now but are still reserved and require escaping in any place of the message for some reason. For instance, .! reservation means that even translation strings themselves that have punctuation now have to be escaped when used in markdown, because formatter's field values are often should not be escaped (e. g. user links). Meanwhile, _{} reservation means that formatter's placeholders will be escaped with aiogram's markdown.escape_md function. So as a solution I've added an optional argument escape_md to i18n which escaped translation string but rolls back placeholders as they were afterwards.

All in all, the style update is a mixed bag. There are some new features which can be useful, but it complicates string construction as reserved characters should be watched much more closely, and some choices for markup characters (in particular, punctuation marks . and !) are questionable to say the least.

Signed-off-by: alfred richardsn rchrdsn@protonmail.ch

Proposed Changes

Should be tested on unstable bot more for merging.

By sending this contribution I hereby agree to the terms of Contributor License Agreement.