From 7b323595f3cfe743f70fe2f108b6a3d3a237dd8c Mon Sep 17 00:00:00 2001 From: Linus E <75929322+Rripped@users.noreply.github.com> Date: Tue, 10 May 2022 17:44:45 +0200 Subject: [PATCH] added helper funcs --- telegram_bot/helper_functions.py | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 telegram_bot/helper_functions.py diff --git a/telegram_bot/helper_functions.py b/telegram_bot/helper_functions.py new file mode 100644 index 0000000..b69b200 --- /dev/null +++ b/telegram_bot/helper_functions.py @@ -0,0 +1,47 @@ +""" +script for helper functions for bot related stuff +""" +__author__ = "Florian Kellermann, Linus Eickhoff" +__date__ = "10.05.2022" +__version__ = "1.0.0" +__license__ = "None" + +def contains_markdown_symbols(text): + """ checks if text contains markdown symbols + :type text: string + + :param text: text to check + + :return: true if text contains markdown symbols + + :rtype: bool + """ + if text.find("_") != -1 or text.find("*") != -1 or text.find("~") != -1 or text.find("`") != -1: # check if text contains markdown symbols + return True + + return False + + +def make_markdown_proof(text): + """ makes text markdown proof + :type text: string + + :param text: text to make markdown proof + + :return: markdown proof text + + :rtype: string + """ + if not contains_markdown_symbols(text): + return text + + text = text.replace("_", "\\_") + text = text.replace("*", "\\*") + text = text.replace("~", "\\~") + text = text.replace("`", "\\`") + + return text + + +if __name__ == '__main__': + print("this is a module for helper functions for the bot and should not be run directly") \ No newline at end of file