From 11b119b08eb3721a55ca47779302d00b0601ec6a Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 9 Feb 2019 19:57:49 +0100 Subject: [PATCH] Fix diario text bug --- strings.py | 11 +++++++---- telegrambot.py | 3 +-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/strings.py b/strings.py index 216f4274..14a899d2 100644 --- a/strings.py +++ b/strings.py @@ -7,10 +7,13 @@ class SafeDict(dict): return key -def safely_format_string(string: str, words: typing.Dict[str, str]) -> str: - escaped = {} - for key in words: - escaped[key] = words[key].replace("<", "<").replace(">", ">") +def safely_format_string(string: str, words: typing.Dict[str, str], ignore_escaping=False) -> str: + if ignore_escaping: + escaped = words + else: + escaped = {} + for key in words: + escaped[key] = words[key].replace("<", "<").replace(">", ">") return string.format_map(SafeDict(**escaped)) diff --git a/telegrambot.py b/telegrambot.py index 8d21e848..11a60399 100644 --- a/telegrambot.py +++ b/telegrambot.py @@ -53,8 +53,7 @@ sentry = raven.Client(config["Sentry"]["token"], def reply_msg(bot: telegram.Bot, chat_id: int, string: str, ignore_escaping=False, **kwargs) -> telegram.Message: - if not ignore_escaping: - string = strings.safely_format_string(string, words=kwargs) + string = strings.safely_format_string(string, ignore_escaping=ignore_escaping, words=kwargs) return bot.send_message(chat_id, string, parse_mode="HTML", disable_web_page_preview=True)