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)