diff --git a/python/bot.py b/python/bot.py index c22d6424..411be68b 100644 --- a/python/bot.py +++ b/python/bot.py @@ -93,6 +93,9 @@ def message_new(self, event): self.delete_message(event) elif regex.findall(patterns.ADD_PROGRAMMING_LANGUAGE, message): language = regex.match(patterns.ADD_PROGRAMMING_LANGUAGE, message).group('language') + language = self.get_default_programming_language(language) + if not language: + return if "programming_languages" not in user.obj: user.programming_languages = [] base.save(user) @@ -173,6 +176,13 @@ def get_programming_languages_string(self, user): else: return "" + def get_default_programming_language(self, language): + for default_programming_language in default_programming_languages: + default_programming_language = default_programming_language.replace('\\', '') + if default_programming_language.lower() == language.lower(): + return default_programming_language + return None + def contains_string(self, strings, matchedString, ignoreCase): if ignoreCase: for string in strings: diff --git a/python/patterns.py b/python/patterns.py index 5a0a8d6c..7ec440ee 100644 --- a/python/patterns.py +++ b/python/patterns.py @@ -7,4 +7,4 @@ APPLY_RATING = compile(r"\A\s*(?P\+|\-)(?P[0-9]*)\s*\Z") TOP = compile(r"\A\s*(топ|top)\s*\Z", IGNORECASE) TOP_LANGUAGES = compile(r"\A\s*(топ|top)\s*(?P(" + default_languages + r")(\s+(" + default_languages + r"))*)\s*\Z", IGNORECASE) -ADD_PROGRAMMING_LANGUAGE = compile(r"\A\s*\+=\s*(?P" + default_languages + r")\s*\Z") +ADD_PROGRAMMING_LANGUAGE = compile(r"\A\s*\+=\s*(?P" + default_languages + r")\s*\Z", IGNORECASE)