use of net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent in project MantaroBot by Mantaro.
the class Poll method createPoll.
private void createPoll(Context ctx, Message message, I18nContext languageContext) {
runningPoll = ReactionOperations.create(message, TimeUnit.MILLISECONDS.toSeconds(timeout), new ReactionOperation() {
@Override
public int add(MessageReactionAddEvent e) {
// always return false anyway lul
return Operation.IGNORED;
}
@Override
public void onExpire() {
if (getChannel() == null)
return;
var user = ctx.getAuthor();
var embedBuilder = new EmbedBuilder().setTitle(languageContext.get("commands.poll.result_header")).setDescription(String.format(languageContext.get("commands.poll.result_screen"), user.getName(), name)).setFooter(languageContext.get("commands.poll.thank_note"), null);
var react = new AtomicInteger(0);
var counter = new AtomicInteger(0);
getChannel().retrieveMessageById(message.getIdLong()).queue(message -> {
var votes = message.getReactions().stream().filter(r -> react.getAndIncrement() <= options.length).map(r -> String.format(languageContext.get("commands.poll.vote_results"), r.getCount() - 1, options[counter.getAndIncrement()])).collect(Collectors.joining("\n"));
embedBuilder.addField(languageContext.get("commands.poll.results"), "```diff\n" + votes + "```", false);
getChannel().sendMessageEmbeds(embedBuilder.build()).queue();
});
getRunningPolls().remove(getChannel().getId());
}
@Override
public void onCancel() {
getChannel().sendMessageFormat(languageContext.get("commands.poll.cancelled"), EmoteReference.CORRECT).queue();
onExpire();
}
}, reactions(options.length));
}
Aggregations