Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • telegram-bots/lenochka
  • aisus/volodya
2 results
Show changes
File deleted
......@@ -24,7 +24,5 @@ class Brain:
:param state_of_mind: lenochka's current state of mind.
It's always clear in order to make the most thoughtful answer.
"""
if not self.cell.do_i_need_to_say_something():
return
thoughtful_answer = self.cell.create_reply(message.text)
await message.reply(thoughtful_answer)
if thoughtful_answer := self.cell.create_reply(message.text):
await message.reply(thoughtful_answer)
import re
import secrets
from typing import Optional
MAX_TRIGGER_WORDS = 3
WORD_PATTERN = re.compile(r"(\w+)")
......@@ -11,20 +12,7 @@ class BrainCell:
It decides when and what to say.
"""
def do_i_need_to_say_something(self) -> bool:
"""
One of the most important decisions.
This brain cell's function looks
deep inside the palaces of the mind,
searching through the secrets of the universe
and decides if she want to say something.
:return: The decision.
"""
return secrets.randbelow(11) < 1 # noqa: WPS432
def create_reply(self, sentence: str) -> str:
def create_reply(self, sentence: str) -> Optional[str]:
"""
The hardest action to accomplish.
......@@ -36,10 +24,10 @@ class BrainCell:
:return: actual reply.
"""
tokens = WORD_PATTERN.findall(sentence)
for token in reversed(tokens):
token_parts = token.lower().split("да")
if len(token_parts) > 1:
postfix = token_parts[-1]
break
return f"Пизда{postfix}."
if not tokens or len(tokens) > MAX_TRIGGER_WORDS:
return None
*_, last_token = tokens
last_token_parts = last_token.lower().split("да")
if len(last_token_parts) > 1:
return f"Пизда{last_token_parts[-1]}."
return None
......@@ -8,7 +8,10 @@ class Memory(BaseSettings):
It holds the most important things for lenochka's life.
"""
token: str = Field(env="LENOCHKA_INSTAGRAM_ID", required=True)
token: str = Field(..., env="LENOCHKA_INSTAGRAM_ID")
class Config:
env_file = ".env"
memory = Memory()
memory = Memory() # type: ignore
This diff is collapsed.
......@@ -9,21 +9,21 @@ python = "^3.9"
aiogram = "^2.13"
pydantic = "^1.8.2"
[tool.poetry.dev-dependencies]
pytest = "^5.2"
black = "^21.5b2"
isort = "^5.8.0"
wemake-python-styleguide = "^0.15.2"
flake8 = "^3.9.2"
mypy = "^0.812"
yesqa = "^1.2.3"
autoflake = "^1.4"
pytest-env = "^0.6.2"
pytest-cov = "^2.12.1"
[tool.poetry.scripts]
lenochka_wake_up = "lenochka.mouth:talk_to_the_wind"
[tool.poetry.group.dev.dependencies]
pytest = "^7.4.2"
black = "^23.9.1"
isort = "^5.12.0"
flake8 = "^6.1.0"
mypy = "^1.5.1"
yesqa = "^1.5.0"
pytest-env = "^1.0.1"
pytest-cov = "^4.1.0"
autoflake = "^2.2.1"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"