Skip to content
This repository has been archived by the owner on Nov 4, 2019. It is now read-only.

Commit

Permalink
fix event
Browse files Browse the repository at this point in the history
  • Loading branch information
lamantin@tuta.io committed Feb 20, 2017
1 parent f7679c4 commit 3864c9c
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions or-bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,21 @@
def better_handler(text):
_text = text.strip()

if (re.match(r"что лучше, ", _text) or re.match(r"кто лучше, ", _text)) and re.search(r" или ", _text):
_text = _text[11:].strip()
_text = _text[11:].strip()

if _text[-1] == "?":
_text = _text[:-1]
if _text[-1] == "?":
_text = _text[:-1]

variation = _text.split(' или ')
r = random.randint(0, len(variation) - 1)
variation = _text.split(' или ')
r = random.randint(0, len(variation) - 1)

choice = variation[r].strip()
choice = variation[r].strip()

start_phrases_choice = start_better_phrases[random.randint(0, len(start_better_phrases) - 1)]
end_phrases_choice = end_better_phrases[random.randint(0, len(end_better_phrases) - 1)]

return start_phrases_choice + choice + end_phrases_choice
else:
return silence()
start_phrases_choice = start_better_phrases[random.randint(0, len(start_better_phrases) - 1)]
end_phrases_choice = end_better_phrases[random.randint(0, len(end_better_phrases) - 1)]

return start_phrases_choice + choice + end_phrases_choice


def event():
try:
Expand All @@ -83,11 +80,14 @@ def event():

message = data.get('text')

return Response(
response=json.dumps({'text': better_handler(message), 'bot': 'or-bot'}),
status=201,
mimetype="application/json"
)
if (re.match(r"что лучше, ", _text) or re.match(r"кто лучше, ", _text)) and re.search(r" или ", _text):
return Response(
response=json.dumps({'text': better_handler(message), 'bot': 'or-bot'}),
status=201,
mimetype="application/json"
)
else:
return silence()


def info():
Expand Down

0 comments on commit 3864c9c

Please sign in to comment.