Skip to content

Commit 6d0ff09

Browse files
committed
fix: IndexError when an empty message is sent back
1 parent 51fdc50 commit 6d0ff09

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

sugaroid/brain/fun.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ def process(self, statement, additional_response_selection_parameters=None):
2626
emotion = Emotion.neutral
2727
confidence = 0.05
2828
parsed = str(statement)
29-
if "not" in parsed:
29+
if not parsed.strip():
30+
# it is an empty statement
31+
selected_statement = SugaroidStatement("😌😌😌", chatbot=True)
32+
selected_statement.confidence = 1
33+
selected_statement.emotion = emotion
34+
return selected_statement
35+
elif "not" in parsed:
3036
# if you are not, who then is?
3137
suffix = " either. "
3238
prefix = ""

sugaroid/brain/have.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class HaveAdapter(SugaroidLogicAdapter):
1717
"""
1818

1919
def can_process(self, statement: SugaroidStatement) -> bool:
20-
return statement.words[0] == "have" and not statement.words[-1].endswith("?")
20+
return len(statement.words) >= 1 and statement.words[0] == "have" and not statement.words[-1].endswith("?")
2121

2222
def process(
2323
self,

0 commit comments

Comments
 (0)