diff --git a/lenochka/brain/brain_cell.py b/lenochka/brain/brain_cell.py index aff4d2b..fa756b4 100644 --- a/lenochka/brain/brain_cell.py +++ b/lenochka/brain/brain_cell.py @@ -3,6 +3,7 @@ from typing import Optional MAX_TRIGGER_WORDS = 3 WORD_PATTERN = re.compile(r"(\w+)") +NAME_PATTERN = re.compile(r"^[Лл]еночк.*$", re.IGNORECASE) class BrainCell: @@ -26,8 +27,43 @@ class BrainCell: tokens = WORD_PATTERN.findall(sentence) if not tokens or len(tokens) > MAX_TRIGGER_WORDS: return None + return self.be_polite(tokens) or self.say_yes(tokens) or self.say_no(tokens) + + @staticmethod + def say_yes(tokens: list[str]) -> Optional[str]: + """ + Always say yes. + + :param tokens: Sentence that needs a reply. + :return: actual reply. + """ *_, last_token = tokens last_token_parts = last_token.lower().split("да") if len(last_token_parts) > 1: return f"Пизда{last_token_parts[-1]}." return None + + @staticmethod + def say_no(tokens: list[str]) -> Optional[str]: + """ + Don't you dare refuse me! + + :param tokens: Sentence that needs a reply. + :return: actual reply. + """ + if len(tokens) == 1 and tokens[0].lower() == "нет": + return "Пидора ответ." + return None + + @staticmethod + def be_polite(tokens: list[str]) -> Optional[str]: + """ + Be polite when talking to a woman. + + :param tokens: Sentence that needs a reply. + :return: actual reply. + """ + for token in tokens: + if NAME_PATTERN.match(token): + return "Какая я тебе нахуй Леночка, хуесос?" + return None diff --git a/lenochka/brain/tests/test_brain_cell.py b/lenochka/brain/tests/test_brain_cell.py index ff95d96..d079756 100644 --- a/lenochka/brain/tests/test_brain_cell.py +++ b/lenochka/brain/tests/test_brain_cell.py @@ -6,3 +6,11 @@ def test_replies() -> None: cell = BrainCell() assert cell.create_reply("Удав") == "Пиздав." assert cell.create_reply("Дакимакура") == "Пиздакимакура." + + assert cell.create_reply("Никак нет") is None + assert cell.create_reply("нет") == "Пидора ответ." + + assert cell.create_reply("Уважаемая, Леночка") == "Какая я тебе нахуй Леночка, хуесос?" + assert cell.create_reply("Леночка, принесите кофе") == "Какая я тебе нахуй Леночка, хуесос?" + + assert cell.create_reply("Да нет Леночка") == "Какая я тебе нахуй Леночка, хуесос?"