use of net.dv8tion.jda.api.entities.MessageReaction in project Emolga by TecToast.
the class Giveaway method end.
public void end() {
isEnded = true;
DBManagers.GIVEAWAY.removeGiveaway(this);
MessageBuilder mb = new MessageBuilder();
mb.append("\uD83C\uDF89").append(" **GIVEAWAY ZU ENDE** ").append("\uD83C\uDF89");
EmbedBuilder eb = new EmbedBuilder();
// dark theme background
eb.setColor(Color.CYAN);
eb.setFooter((winners == 1 ? "" : winners + " Gewinner | ") + "Endete", null);
eb.setTimestamp(end);
if (prize != null)
eb.setAuthor(prize, null, null);
try {
Optional<MessageReaction> opt;
if (messageId == 775761399737352222L) {
opt = emolgajda.getTextChannelById(channelId).retrieveMessageById(messageId).complete().getReactions().stream().filter(mr -> mr.getReactionEmote().isEmoji() && mr.getReactionEmote().getEmoji().equals("\uD83C\uDF89")).findFirst();
} else {
opt = emolgajda.getTextChannelById(channelId).retrieveMessageById(messageId).complete().getReactions().stream().filter(mr -> mr.getReactionEmote().isEmote() && (mr.getReactionEmote().getEmote().getId().equals("772191611487780934") || mr.getReactionEmote().getEmote().getId().equals("774817002636181535"))).findFirst();
}
ArrayList<Member> members = new ArrayList<>();
opt.ifPresent(mr -> mr.retrieveUsers().complete().stream().filter(u -> !u.isBot() && u.getIdLong() != userId).forEach(u -> members.add(emolgajda.getTextChannelById(channelId).getGuild().retrieveMember(u).complete())));
ArrayList<Member> wins = new ArrayList<>();
if (members.size() > 0)
for (int i = 0; i < winners; i++) {
if (members.size() == 0)
break;
wins.add(members.remove(new Random().nextInt(members.size())));
}
// restJDA.getReactionUsers(channelId, messageId, EncodingUtil.encodeUTF8(Constants.TADA))..submit().thenAcceptAsync(ids -> {
// List<Long> wins = GiveawayUtil.selectWinners(ids, winners);
String toSend;
if (wins.isEmpty()) {
eb.setDescription("Es konnte kein Gewinner ermittelt werden!");
toSend = "Es konnte kein Gewinner ermittelt werden!";
} else if (wins.size() == 1) {
eb.setDescription("Gewinner: " + wins.get(0).getAsMention());
toSend = "Herzlichen Glückwunsch " + wins.get(0).getAsMention() + "! Du hast" + (prize == null ? "" : " **" + prize + "**") + " gewonnen!";
} else {
eb.setDescription("Gewinner:");
wins.forEach(w -> eb.appendDescription("\n").appendDescription(w.getAsMention()));
toSend = "Herzlichen Glückwunsch " + wins.stream().map(Member::getAsMention).collect(Collectors.joining(", "));
toSend += "! Ihr habt" + (prize == null ? "" : " **" + prize + "**") + " gewonnen!";
}
mb.setEmbeds(eb.appendDescription("\nGehostet von: <@" + userId + ">").build());
EmolgaMain.todel.add(this);
emolgajda.getTextChannelById(channelId).editMessageById(messageId, mb.build()).queue();
emolgajda.getTextChannelById(channelId).sendMessage(toSend).queue();
} catch (Exception e) {
e.printStackTrace();
mb.setEmbeds(eb.setDescription("Es konnte kein Gewinner festgestellt werden!\nGehostet von: <@" + userId + ">").build());
emolgajda.getTextChannelById(channelId).editMessageById(messageId, mb.build()).queue();
emolgajda.getTextChannelById(channelId).sendMessage("Es konnte kein Gewinner festgestellt werden!").queue();
}
}
Aggregations