Skip to content

Commit

Permalink
Merge pull request #55 from Mazawrath/beanTrivia_Fix
Browse files Browse the repository at this point in the history
Bean trivia fix
  • Loading branch information
Mazawrath authored Jan 19, 2020
2 parents 88fad0d + 52be53c commit d37e07a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void onCommand(ServerTextChannel serverTextChannel, User author, Server s
} else {
StringBuilder message = new StringBuilder();

message.append("You have already received free beanCoin today. You can receive beanCoin in ");
message.append("You have already received free beanCoin. You can receive beanCoin in ");

String dateStart = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
.format(new java.util.Date(System.currentTimeMillis()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public void onCommand(ServerTextChannel serverTextChannel, DiscordApi api, User
new Thread(() -> {
try {
Thread.sleep(10500);
Message checkMessage = serverTextChannel.sendMessage("Checking answers...").get();
serverTextChannel.type();

List<Reaction> reactions = triviaMessage.getReactions();

ArrayList<User> contestants = new ArrayList<>();
Expand All @@ -116,15 +119,14 @@ public void onCommand(ServerTextChannel serverTextChannel, DiscordApi api, User
}

// Check for cheaters
for (int i = 0; i < reactions.size(); i++) {
if (!reactions.get(i).getEmoji().equalsEmoji(EmojiParser.parseToUnicode(emojiCorrectAnswer)) && reactions.get(i).getUsers().get().contains(api.getYourself())) {
Reaction correctEmoji = reactions.get(i);
for (int j = 0; j < correctEmoji.getUsers().get().size(); j++) {
for (Reaction reaction : reactions) {
if (!reaction.getEmoji().equalsEmoji(EmojiParser.parseToUnicode(emojiCorrectAnswer)) && reaction.getUsers().get().contains(api.getYourself())) {
for (int j = 0; j < reaction.getUsers().get().size(); j++) {
for (int k = 0; k < winners.size(); k++) {
// Found a cheater!
if (correctEmoji.getUsers().get().get(j) == winners.get(k)) {
if (reaction.getUsers().get().get(j) == winners.get(k)) {
winners.remove(winners.get(k));
cheaters.add(correctEmoji.getUsers().get().get(j));
cheaters.add(reaction.getUsers().get().get(j));
}
}
}
Expand All @@ -143,25 +145,26 @@ public void onCommand(ServerTextChannel serverTextChannel, DiscordApi api, User
winnersMessage.append("No one got the answer correct!\n");
} else {
winnersMessage.append("The following users have won:\n");
for (int i = 0; i < winners.size(); i++) {
winnersMessage.append(winners.get(i).getDisplayName(server)).append(" got the correct answer!\n");
for (User winner : winners) {
winnersMessage.append(winner.getDisplayName(server)).append(" got the correct answer!\n");
points.depositCoins(new PointsUser(author, server), Points.TRIVIA_CORRECT_ANSWER);
}
}
winnersMessage.append("\n");
for (int i = 0; i < cheaters.size(); i++) {
winnersMessage.append(cheaters.get(i).getDisplayName(server)).append(" has cheated and has been fined ").append(Points.pointsToString(Points.TRIVIA_CHEAT_FINE)).append("!\n");
if (points.checkBalance(new PointsUser(cheaters.get(i), server)).compareTo(Points.TRIVIA_CHEAT_FINE) <= 0)
points.makePurchase(new PointsUser(cheaters.get(i), server), new PointsUser(api.getYourself(), server), points.checkBalance(new PointsUser(cheaters.get(i), server)));
for (User cheater : cheaters) {
winnersMessage.append(cheater.getDisplayName(server)).append(" has cheated and has been fined ").append(Points.pointsToString(Points.TRIVIA_CHEAT_FINE)).append("!\n");
if (points.checkBalance(new PointsUser(cheater, server)).compareTo(Points.TRIVIA_CHEAT_FINE) <= 0)
points.makePurchase(new PointsUser(cheater, server), new PointsUser(api.getYourself(), server), points.checkBalance(new PointsUser(cheater, server)));
else
points.makePurchase(new PointsUser(cheaters.get(i), server), new PointsUser(api.getYourself(), server), Points.TRIVIA_CHEAT_FINE);
points.makePurchase(new PointsUser(cheater, server), new PointsUser(api.getYourself(), server), Points.TRIVIA_CHEAT_FINE);
// Reset their trivia too.
points.useTriviaQuestion(new PointsUser(author, server), true);
}
if (cheaters.size() != 0)
winnersMessage.append("\n");
winnersMessage.append("The correct answer was: ").append(correctAnswer).append(".\nAnyone who answered correctly received ").append(Points.pointsToString(Points.TRIVIA_CORRECT_ANSWER)).append(".");

checkMessage.delete();
serverTextChannel.sendMessage(winnersMessage.toString());
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -177,7 +180,7 @@ public void onCommand(ServerTextChannel serverTextChannel, DiscordApi api, User
} else {
StringBuilder message = new StringBuilder();

message.append("You have already done your " + Points.MAX_TRIVIA_QUESTIONS_PER_DAY + " trivia questions today. You can use your trivia again in ");
message.append("You have already done your " + Points.MAX_TRIVIA_QUESTIONS_PER_DAY + " trivia questions. You can use your trivia again in ");

String dateStart = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
.format(new java.util.Date(System.currentTimeMillis()));
Expand Down Expand Up @@ -238,9 +241,7 @@ public boolean add(T e) {
return super.add(e);
}
};
for (T t : list) {
set.add(t);
}
set.addAll(list);
return duplicatedObjects;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void onCommand(String[] args, DiscordApi api, ServerTextChannel serverTex
} else
serverTextChannel.sendMessage("You do not have enough beanCoin to buy a ticket.");
} else
serverTextChannel.sendMessage("You must have 1 number with how many tickets you want to buy, " + Lottery.AMOUNT_DRAWN + " numbers >= " + Lottery.MIN_NUMBER + " and <= " + Lottery.MAX_NUMBER + ", or the word `draw` to have your own drawing.");
serverTextChannel.sendMessage("You must have 1 number with how many tickets you want to buy, " + Lottery.AMOUNT_DRAWN + " numbers >= " + Lottery.MIN_NUMBER + " and <= " + Lottery.MAX_NUMBER + ".");
} catch (NumberFormatException e) {
serverTextChannel.sendMessage("Invalid number(s).");
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/mazawrath/beanbot/utilities/Lottery.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ public void scheduleWeeklyDrawing(Points points, Server server, DiscordApi api,
@Override
public void run() {
try {
serverTextChannel.sendMessage("30 minutes until the weekly bean lottery drawing! Buy tickets using `.beanlottery` while you can!");
serverTextChannel.sendMessage("30 minutes until the automated bean lottery drawing! Buy tickets using `.beanlottery` while you can!");
Thread.sleep(1200000);
serverTextChannel.sendMessage("Only 10 minutes until the weekly bean lottery drawing! Last chance to buy tickets using `.beanlottery`!");
serverTextChannel.sendMessage("Only 10 minutes until the automated bean lottery drawing! Last chance to buy tickets using `.beanlottery`!");
Thread.sleep(595000);
serverTextChannel.sendMessage("Starting lottery drawing...");
Thread.sleep(5000);
Expand Down

0 comments on commit d37e07a

Please sign in to comment.