testing reaction

master
BodgeMaster 2022-02-22 19:45:04 +01:00
parent 3f36573c19
commit 38803d519d
2 changed files with 30 additions and 6 deletions

View File

@ -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;
}

View File

@ -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(