Search in sources :

Example 1 with FreeGameUtility

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);
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) MessageBuilder(net.dv8tion.jda.api.MessageBuilder) Document(org.bson.Document) EpicFreeGame(com.sx4.bot.entities.info.EpicFreeGame) FreeGame(com.sx4.bot.entities.info.FreeGame) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command)

Aggregations

Command (com.jockie.bot.core.command.Command)1 Sx4Command (com.sx4.bot.core.Sx4Command)1 EpicFreeGame (com.sx4.bot.entities.info.EpicFreeGame)1 FreeGame (com.sx4.bot.entities.info.FreeGame)1 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)1 MessageBuilder (net.dv8tion.jda.api.MessageBuilder)1 Document (org.bson.Document)1