Search in sources :

Example 1 with EmbedDTO

use of com.github.kaktushose.jda.commands.embeds.EmbedDTO in project Levelbot by Kaktushose.

the class Levelbot method generateRankInfo.

public EmbedBuilder generateRankInfo(User target, boolean dm) {
    BotUser botUser = userService.getUserById(target.getIdLong());
    Rank currentRank = levelService.getCurrentRank(botUser.getUserId());
    Rank nextRank = levelService.getNextRank(botUser.getUserId());
    long nextRankXp = nextRank.getBound() - botUser.getXp();
    long xpGain = botUser.getXp() - botUser.getStartXp();
    long coinsGain = botUser.getCoins() - botUser.getStartCoins();
    long diamondsGain = botUser.getDiamonds() - botUser.getStartDiamonds();
    // if event is active, load another template
    String embed = eventService.isCollectEventActive(guildId) ? "eventRankInfo" : "rankInfo";
    String currentRankInfo = dm ? currentRank.getName() : String.format("<@&%d>", currentRank.getRoleId());
    String nextRankInfo = dm ? String.format("%s (noch %d XP)", nextRank.getName(), nextRankXp) : String.format("<@&%d> (noch %d XP)", nextRank.getRoleId(), nextRankXp);
    nextRankInfo = currentRank.equals(nextRank) ? "N/A" : nextRankInfo;
    String url = target.getAvatarUrl() == null ? "https://cdn.discordapp.com/embed/avatars/0.png" : target.getAvatarUrl();
    EmbedDTO embedDTO = embedCache.getEmbed(embed).injectValue("user", target.getAsMention()).injectValue("color", currentRank.getColor()).injectValue("currentRank", currentRankInfo).injectValue("nextRank", nextRankInfo).injectValue("avatarUrl", url).injectValue("xpGain", xpGain).injectValue("coinsGain", coinsGain).injectValue("diamondsGain", diamondsGain).injectFields(botUser);
    if (eventService.isCollectEventActive(guildId)) {
        CollectEvent collectEvent = eventService.getActiveCollectEvent(guildId);
        Role collectEventRole = guild.getRoleById(collectEvent.getRoleId());
        long eventPoints = botUser.getEventPoints();
        embedDTO.injectValue("eventName", collectEvent.getName()).injectValue("currencyName", collectEvent.getCurrencyName()).injectValue("currencyEmote", collectEvent.getCurrencyEmote()).injectValue("currencyPoints", eventPoints);
        if (eventPoints >= collectEvent.getItemBound()) {
            embedDTO.injectValue("eventRewards", collectEvent.getItem().getName() + "\n:blue_circle: Eventrolle " + collectEventRole.getName());
        } else if (eventPoints >= collectEvent.getRoleBound()) {
            embedDTO.injectValue("eventRewards", ":blue_circle: Eventrolle " + collectEventRole.getName());
        } else {
            embedDTO.injectValue("eventRewards", ":x: noch keine");
        }
    }
    EmbedBuilder embedBuilder = embedDTO.toEmbedBuilder();
    if (botUser.getTransactions().isEmpty()) {
        embedBuilder.addField("Keine Items in Besitz", "", false);
    }
    botUser.getTransactions().forEach(transaction -> {
        Item item = transaction.getItem();
        embedBuilder.addField(item.getName(), "noch " + item.getRemainingTimeAsDate(transaction.getBuyTime()), false);
    });
    return embedBuilder;
}
Also used : Item(de.kaktushose.levelbot.shop.data.items.Item) BotUser(de.kaktushose.levelbot.database.model.BotUser) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) EmbedDTO(com.github.kaktushose.jda.commands.embeds.EmbedDTO) CollectEvent(de.kaktushose.levelbot.database.model.CollectEvent) Rank(de.kaktushose.levelbot.database.model.Rank)

Aggregations

EmbedDTO (com.github.kaktushose.jda.commands.embeds.EmbedDTO)1 BotUser (de.kaktushose.levelbot.database.model.BotUser)1 CollectEvent (de.kaktushose.levelbot.database.model.CollectEvent)1 Rank (de.kaktushose.levelbot.database.model.Rank)1 Item (de.kaktushose.levelbot.shop.data.items.Item)1 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)1