From 78f62b5f8d1de952bed0c187a1af3a6fad6608c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Wed, 21 Dec 2022 03:40:13 +0100 Subject: [PATCH] Make trivia functional for a single question --- .../commands/message/TriviaCommand.java | 45 ++++++++++++++++--- .../runnables/ExpiredMessageTask.java | 10 ++--- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/TriviaCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/TriviaCommand.java index 11b8211..a5dfceb 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/TriviaCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/TriviaCommand.java @@ -4,6 +4,7 @@ import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import net.dv8tion.jda.api.interactions.components.buttons.Button; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.json.JSONObject; @@ -14,6 +15,7 @@ import wtf.beatrice.hidekobot.objects.commands.MessageCommand; import wtf.beatrice.hidekobot.util.TriviaUtil; import java.nio.channels.ScatteringByteChannel; +import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -63,25 +65,56 @@ public class TriviaCommand implements MessageCommand if(TriviaUtil.channelsRunningTrivia.contains(event.getChannel().getId())) { // todo nicer looking + // todo: also what if the bot stops (database...?) + // todo: also what if the message is already deleted Message err = event.getMessage().reply("Trivia is already running here!").complete(); - Cache.getTaskScheduler().schedule(() -> err.delete().queue(), 15, TimeUnit.SECONDS); + Cache.getTaskScheduler().schedule(() -> err.delete().queue(), 10, TimeUnit.SECONDS); return; + } else { + // todo nicer looking + event.getMessage().reply("Starting new Trivia session!").queue(); } + + JSONObject triviaJson = TriviaUtil.fetchTrivia(); + List questions = TriviaUtil.getQuestions(triviaJson); //todo null check, rate limiting... + TriviaQuestion first = questions.get(0); + + List