From 38803d519d66287d2e570af870ec9d54d735d638 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Tue, 22 Feb 2022 19:45:04 +0100 Subject: [PATCH] testing reaction --- .../general/hackyquizbot/QuizBackend.java | 7 +++++ .../general/hackyquizbot/QuizHandler.java | 29 +++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/main/java/linux/general/hackyquizbot/QuizBackend.java b/src/main/java/linux/general/hackyquizbot/QuizBackend.java index c4e887f..9da9660 100644 --- a/src/main/java/linux/general/hackyquizbot/QuizBackend.java +++ b/src/main/java/linux/general/hackyquizbot/QuizBackend.java @@ -14,6 +14,9 @@ public class QuizBackend { private static final String dbName = "jdbc:mariadb://localhost/quizbot"; //we can make this configurable later private static Connection dbConnection; private static Statement statement; + + // temporary hack to get something working + private static boolean once = true; // CREATE TABLE questions(id INT(32) AUTO_INCREMENT PRIMARY KEY, question TEXT, max_score INT(8)); // CREATE TABLE answer_choices(id INT(32), answer VARCHAR(2048), correctness BOOLEAN); @@ -62,6 +65,10 @@ public class QuizBackend { //TODO: function to determine whether a user should get more questions public static boolean shouldGetMoreQuestions(String discordUserID) { + if (once) { + once=false; + return true; + } return false; } diff --git a/src/main/java/linux/general/hackyquizbot/QuizHandler.java b/src/main/java/linux/general/hackyquizbot/QuizHandler.java index e366e75..bb05395 100644 --- a/src/main/java/linux/general/hackyquizbot/QuizHandler.java +++ b/src/main/java/linux/general/hackyquizbot/QuizHandler.java @@ -1,5 +1,9 @@ package linux.general.hackyquizbot; +import java.util.concurrent.ExecutionException; + +import org.javacord.api.entity.emoji.Emoji; +import org.javacord.api.entity.message.Message; import org.javacord.api.entity.user.User; import linux.general.hackyquizbot.QuizBackend.Question; @@ -11,13 +15,26 @@ public class QuizHandler { public QuizHandler(User user) { this.user = user; if (QuizBackend.shouldGetMoreQuestions(user.getIdAsString())) { - user.sendMessage("Hi! I'm Hacky.\n" - + "I will be sending you a bunch of multiple-choice questions. " - + "You can answer by selecting one or more of the reactions on the message and confirm your selection by selecting the :white_check_mark: reaction." - + " Please contact @BodgeMaster#0344 if there are any issues.\n" - + "\n" - + "Select the :white_check_mark: reaction to continue."); + try { + Message message = user.sendMessage("Hi! I'm Hacky.\n" + + "I will be sending you a bunch of multiple-choice questions. " + + "You can answer by selecting one or more of the reactions on the message and confirm your selection by selecting the :white_check_mark: reaction." + + " Please contact @BodgeMaster#0344 if there are any issues.\n" + + "\n" + + "Select the :white_check_mark: reaction to continue.").get(); + message.addReaction("✅"); + message.addReactionAddListener(event -> { + if (event.getReaction().get().getEmoji().equalsEmoji("✅")) { + event.getMessage().get().getChannel().sendMessage("test"); + } + }); + } catch (InterruptedException | ExecutionException e) { + // TODO Auto-generated catch block + System.err.println("Something went wrong while trying to get the sent message object."); + e.printStackTrace(); + } //TODO: add white question mark reaction + //TODO: add reaction handler (preferably to channel?) } else { user.sendMessage(