More smart answer
This commit is contained in:
@ -24,7 +24,5 @@ class Brain:
|
|||||||
:param state_of_mind: lenochka's current state of mind.
|
:param state_of_mind: lenochka's current state of mind.
|
||||||
It's always clear in order to make the most thoughtful answer.
|
It's always clear in order to make the most thoughtful answer.
|
||||||
"""
|
"""
|
||||||
if not self.cell.do_i_need_to_say_something():
|
if thoughtful_answer := self.cell.create_reply(message.text):
|
||||||
return
|
await message.reply(thoughtful_answer)
|
||||||
thoughtful_answer = self.cell.create_reply(message.text)
|
|
||||||
await message.reply(thoughtful_answer)
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import re
|
import re
|
||||||
import secrets
|
import secrets
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
|
MAX_TRIGGER_WORDS = 3
|
||||||
WORD_PATTERN = re.compile(r"(\w+)")
|
WORD_PATTERN = re.compile(r"(\w+)")
|
||||||
|
|
||||||
|
|
||||||
@ -11,20 +14,7 @@ class BrainCell:
|
|||||||
It decides when and what to say.
|
It decides when and what to say.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def do_i_need_to_say_something(self) -> bool:
|
def create_reply(self, sentence: str) -> Optional[str]:
|
||||||
"""
|
|
||||||
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:
|
|
||||||
"""
|
"""
|
||||||
The hardest action to accomplish.
|
The hardest action to accomplish.
|
||||||
|
|
||||||
@ -36,10 +26,10 @@ class BrainCell:
|
|||||||
:return: actual reply.
|
:return: actual reply.
|
||||||
"""
|
"""
|
||||||
tokens = WORD_PATTERN.findall(sentence)
|
tokens = WORD_PATTERN.findall(sentence)
|
||||||
for token in reversed(tokens):
|
if not tokens or len(tokens) > MAX_TRIGGER_WORDS:
|
||||||
token_parts = token.lower().split("да")
|
return None
|
||||||
if len(token_parts) > 1:
|
*_, last_token = tokens
|
||||||
postfix = token_parts[-1]
|
last_token_parts = last_token.lower().split("да")
|
||||||
break
|
if len(last_token_parts) > 1:
|
||||||
|
return f"Пизда{last_token_parts[-1]}."
|
||||||
return f"Пизда{postfix}."
|
return None
|
||||||
|
Reference in New Issue
Block a user