finish akinator

This commit is contained in:
Tyler Murphy 2022-10-05 18:56:44 -04:00
parent 50af52f2e4
commit b4495281f1
2 changed files with 25 additions and 13 deletions

View file

@ -296,11 +296,14 @@ public class Responder extends ListenerAdapter {
} else {
hook.editOriginal(response.getMessage()).queue();
}
if(response.hasSelectMenu() || response.hasButtons()) {
if((response.hasSelectMenu() || response.hasButtons() && !response.hasNoComponents())) {
List<LayoutComponent> components = new ArrayList<>();
if(response.hasButtons()) components.add(ActionRow.of(response.getButtons()));
if(response.hasSelectMenu()) components.add(ActionRow.of(response.getSelectMenu()));
hook.editOriginalComponents(components).queue();
} else if(response.hasNoComponents()) {
List<LayoutComponent> components = new ArrayList<>();
hook.editOriginalComponents(components).queue();
}
}
}

View file

@ -16,6 +16,7 @@ import net.tylermurphy.ken.command.Response;
import net.tylermurphy.ken.command.annotation.ButtonCallback;
import net.tylermurphy.ken.command.annotation.Command;
import net.tylermurphy.ken.util.Checks;
import org.json.JSONException;
import java.awt.*;
import java.util.*;
@ -162,6 +163,7 @@ class AkinatorGame {
}
private Response respondQuestion(String label) {
try {
switch (label) {
case "yes":
wrapper.answer(Akiwrapper.Answer.YES);
@ -175,6 +177,12 @@ class AkinatorGame {
case "back":
return back();
}
} catch (JSONException e) {
// JSONEXception when aki cant make more questions
container.games.remove(gameId);
container.gameMappings.remove(userId);
return sendWin();
}
return next();
}
@ -184,6 +192,7 @@ class AkinatorGame {
if(guess.isPresent()) {
status = AkiStatus.GUESS;
sequence.add(guess.get());
guesses.add(guess.get().getId());
attemptedGuesses++;
return sendGuess(guess.get());
} else {