2 Commits
0.0.1 ... 0.0.3

Author SHA1 Message Date
0528e44d07 Fixed regex.
All checks were successful
/ docker_build (push) Successful in 1m22s
/ deploy_helm (push) Successful in 54s
2025-09-12 17:57:36 +02:00
df1f6d0470 Added more triggers.
All checks were successful
/ docker_build (push) Successful in 8m15s
/ deploy_helm (push) Successful in 53s
2025-09-12 11:22:35 +02:00
4 changed files with 61 additions and 4 deletions

View File

@ -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

View File

@ -1,8 +1,26 @@
from typing import Union
import pytest
from lenochka.brain.brain_cell import BrainCell
def test_replies() -> None:
@pytest.mark.parametrize(
("sentence", "expected_reply"),
[
("Удав", "Пиздав."),
("Дакимакура", "Пиздакимакура."),
("Никак нет", None),
("нет", "Пидора ответ."),
("Уважаемая, Леночка", "Какая я тебе нахуй Леночка, хуесос?"),
("Леночка, принесите кофе", "Какая я тебе нахуй Леночка, хуесос?"),
("Да нет Леночка", "Какая я тебе нахуй Леночка, хуесос?"),
],
)
def test_replies(sentence: str, expected_reply: Union[str, None]) -> None:
"""Test reply generator."""
cell = BrainCell()
assert cell.create_reply("Удав") == "Пиздав."
assert cell.create_reply("Дакимакура") == "Пиздакимакура."
if expected_reply:
assert cell.create_reply(sentence) == expected_reply
else:
assert cell.create_reply(sentence) is None

View File

@ -18,6 +18,6 @@ def talk_to_the_wind() -> None:
ears = ConnectionToEars(brain_connection)
ears.register_message_handler(
brain.think,
regexp="да",
regexp="(да|нет|леночка)",
)
world.start_polling(ears)

View File

@ -3,6 +3,9 @@ nameOverride: "lenochka"
image:
tag: "latest"
updateStrategy:
type: Recreate
service:
enabled: false