Search in sources :

Example 1 with CollectEvent

use of de.kaktushose.levelbot.database.model.CollectEvent 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)

Example 2 with CollectEvent

use of de.kaktushose.levelbot.database.model.CollectEvent in project Levelbot by Kaktushose.

the class LevelListener method onGuildMessageReceived.

@Override
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
    Guild guild = event.getGuild();
    long guildId = event.getGuild().getIdLong();
    User author = event.getAuthor();
    long userId = author.getIdLong();
    if (author.isBot()) {
        return;
    }
    if (!levelService.isValidMessage(userId, guildId, event.getChannel().getIdLong())) {
        return;
    }
    if (event.getMessage().getContentStripped().length() < 10) {
        return;
    }
    TextChannel channel = levelbot.getBotChannel();
    if (eventService.isCollectEventActive(guildId)) {
        CollectEvent collectEvent = eventService.getActiveCollectEvent(guildId);
        long eventPoints = userService.increaseEventPoints(userId);
        if (eventPoints == collectEvent.getItemBound()) {
            shopService.addItem(userId, collectEvent.getItem().getItemId());
            channel.sendMessage(author.getAsMention()).and(channel.sendMessageEmbeds(embedCache.getEmbed("collectEventItemReward").injectValue("user", author.getName()).toMessageEmbed())).queue();
        } else if (eventPoints == collectEvent.getRoleBound()) {
            levelbot.addCollectEventRole(userId);
            channel.sendMessage(author.getAsMention()).and(channel.sendMessageEmbeds(embedCache.getEmbed("collectEventRoleReward").injectValue("user", author.getName()).toMessageEmbed())).queue();
        }
    }
    Optional<Rank> optional = levelService.onValidMessage(userId);
    if (optional.isEmpty()) {
        return;
    }
    Rank currentRank = optional.get();
    Rank nextRank = levelService.getNextRank(userId);
    String rewards = levelService.applyRewards(userId, currentRank.getRankId());
    levelbot.addRankRole(userId, currentRank.getRankId());
    levelbot.removeRankRole(userId, levelService.getPreviousRank(userId).getRankId());
    String nextRankInfo = currentRank.equals(nextRank) ? "N/A" : String.format("<@&%d>", nextRank.getRoleId());
    String xp = currentRank.equals(nextRank) ? "0" : String.valueOf(nextRank.getBound());
    channel.sendMessage(author.getAsMention()).and(channel.sendMessageEmbeds(embedCache.getEmbed("levelUp").injectValue("user", author.getAsMention()).injectValue("color", currentRank.getColor()).injectValue("currentRank", guild.getRoleById(currentRank.getRoleId()).getAsMention()).injectValue("nextRank", nextRankInfo).injectValue("reward", rewards).injectValue("xp", xp).toMessageEmbed())).queue();
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) User(net.dv8tion.jda.api.entities.User) CollectEvent(de.kaktushose.levelbot.database.model.CollectEvent) Rank(de.kaktushose.levelbot.database.model.Rank) Guild(net.dv8tion.jda.api.entities.Guild)

Example 3 with CollectEvent

use of de.kaktushose.levelbot.database.model.CollectEvent in project Levelbot by Kaktushose.

the class Levelbot method addCollectEventRole.

public void addCollectEventRole(long userId) {
    CollectEvent event = eventService.getActiveCollectEvent(guildId);
    guild.addRoleToMember(userId, guild.getRoleById(event.getRoleId())).queue();
}
Also used : CollectEvent(de.kaktushose.levelbot.database.model.CollectEvent)

Aggregations

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