Skip to content

Commit d6103ae

Browse files
committed
feat: do not crash if akinator server is down
1 parent a39d5b9 commit d6103ae

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

sugaroid/brain/aki.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ def __init__(self, chatbot: SugaroidBot):
7070
try:
7171
self.game_instance = self.aki.start_game("en")
7272
except (AkiServerDown, AkiTechnicalError):
73-
self.game_instance = self.aki.start_game("en3")
73+
try:
74+
self.game_instance = self.aki.start_game("en3")
75+
except (AkiServerDown, AkiTechnicalError):
76+
self.game_instance = None
7477

7578
def start_game(self):
7679
# We are about to start the game. Lets send a fascinating entry
@@ -170,9 +173,13 @@ def process(
170173
random_response(HOPE_GAME_WAS_GOOD)
171174
)
172175
elif not self.chatbot.globals["akinator"]["enabled"]:
173-
self.chatbot.globals["akinator"]["class"] = SugaroidAkinator(self.chatbot)
174-
response = self.chatbot.globals["akinator"]["class"].start_game()
175-
response += "<sugaroid:yesno>"
176+
sugaroid_akinator_instance = SugaroidAkinator(self.chatbot)
177+
if sugaroid_akinator_instance.game_instance is None:
178+
response = "Sorry dude. Better luck next time. I am feeling sleepy for a game. 🥱"
179+
else:
180+
self.chatbot.globals["akinator"]["class"] = sugaroid_akinator_instance
181+
response = self.chatbot.globals["akinator"]["class"].start_game()
182+
response += "<sugaroid:yesno>"
176183
else:
177184
if not self.chatbot.globals["akinator"]["class"].game_over():
178185
response = self.chatbot.globals["akinator"]["class"].progression(

0 commit comments

Comments
 (0)