trying to work around an arbitrary API limitation with a hack

master
BodgeMaster 2022-02-22 21:17:16 +01:00
parent 95b38a39dd
commit 8c0abb092a
1 changed files with 15 additions and 11 deletions

View File

@ -20,21 +20,25 @@ public class QuizHandler {
Message message = user.sendMessage("Hi! I'm Hacky.\n" Message message = user.sendMessage("Hi! I'm Hacky.\n"
+ "I will be sending you a bunch of multiple-choice questions. " + "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." + "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" + " Please contact @BodgeMaster#0344 if there are any issues.\n\n"
+ "\n"
+ "Select the :white_check_mark: reaction to continue.").get(); + "Select the :white_check_mark: reaction to continue.").get();
message.addReaction(EmojiParser.parseToUnicode(":white_check_mark:")); message.addReaction(EmojiParser.parseToUnicode(":white_check_mark:"));
message.addReactionAddListener(event -> { message.addReactionAddListener(event -> {
System.err.println("We get to here. #1"); // HACK: Testing for an exception to find out whether the event was caused by a
User test = event.getUser().get(); //test to see if this throws an exception // user or by the bot itself because reactions added by the bot allow to check
System.err.println("We get to here. #2"); // for user where reactions added by actual users dont.
System.err.println("Got an event from "+Long.toString(event.getUser().get().getId())); //this throws an exception - why? try {
System.err.println("We get to here. #3"); if (!event.getUser().get().isYourself() && event.getReaction().get().getEmoji()
if (event.getUser().get().getId()!=Main.getUserID() && event.getReaction().get().getEmoji().equalsEmoji(EmojiParser.parseToUnicode(":white_check_mark:"))) { .equalsEmoji(EmojiParser.parseToUnicode(":white_check_mark:"))) {
event.getMessage().get().getChannel().sendMessage("test"); event.getMessage().get().getChannel().sendMessage(
"This should not work. If you ever see this message, please inform @BodgeMaster#0344 that there is more to this arbitrary limitation in the Discord API than expected.");
}
} catch (Exception e) {
System.err.println("Assuming the reaction event was caused by the user...");
System.err.println("User ID: "+this.user.getIdAsString()); //test if we can get the user ID that way
}
// TODO: trigger question dispatch // TODO: trigger question dispatch
// TODO: remove ReactionAddListener // TODO: remove ReactionAddListener
}
}); });
} catch (InterruptedException | ExecutionException e) { } catch (InterruptedException | ExecutionException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block