use of com.sx4.bot.utility.FreeGameUtility in project Sx4 by sx4-discord-bot.
the class FreeGamesCommand method list.
@Command(value = "list", description = "Lists the current free games")
@CommandId(473)
@Examples({ "free games list" })
public void list(Sx4CommandEvent event) {
List<Document> games = event.getMongo().getAnnouncedGames(Filters.gte("promotion.end", Instant.now().getEpochSecond()), new Document()).into(new ArrayList<>());
if (games.isEmpty()) {
event.replyFailure("There are currently no free games").queue();
return;
}
List<FreeGame<?>> freeGames = games.stream().map(FreeGameUtility::getFreeGame).collect(Collectors.toList());
PagedResult<FreeGame<?>> paged = new PagedResult<>(event.getBot(), freeGames).setSelect().setPerPage(1).setCustomFunction(page -> {
EmbedBuilder embed = new EmbedBuilder();
embed.setFooter("Game " + page.getPage() + "/" + page.getMaxPage());
page.forEach((game, index) -> this.setGameEmbed(embed, game));
return new MessageBuilder().setEmbeds(embed.build());
});
paged.execute(event);
}
Aggregations