Search in sources :

Example 1 with BotUser

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

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

the class Levelbot method dmRankInfo.

public void dmRankInfo() {
    userService.getUsersByDailyEnabled().forEach(botUser -> {
        User user = jda.getUserById(botUser.getUserId());
        user.openPrivateChannel().flatMap(privateChannel -> privateChannel.sendMessageEmbeds(generateRankInfo(user, true).build())).queue(null, new ErrorHandler().ignore(ErrorResponse.CANNOT_SEND_TO_USER));
    });
}
Also used : LoginException(javax.security.auth.login.LoginException) net.dv8tion.jda.api.entities(net.dv8tion.jda.api.entities) BotUser(de.kaktushose.levelbot.database.model.BotUser) JDA(net.dv8tion.jda.api.JDA) Date(java.util.Date) ReactionListener(de.kaktushose.discord.reactionwaiter.ReactionListener) LoggerFactory(org.slf4j.LoggerFactory) Statistics(de.kaktushose.levelbot.util.Statistics) SimpleDateFormat(java.text.SimpleDateFormat) ErrorResponse(net.dv8tion.jda.api.requests.ErrorResponse) de.kaktushose.levelbot.listener(de.kaktushose.levelbot.listener) GatewayIntent(net.dv8tion.jda.api.requests.GatewayIntent) ShopService(de.kaktushose.levelbot.shop.data.ShopService) Calendar(java.util.Calendar) CollectEvent(de.kaktushose.levelbot.database.model.CollectEvent) JDABuilder(net.dv8tion.jda.api.JDABuilder) Bootstrapper(de.kaktushose.levelbot.Bootstrapper) CacheFlag(net.dv8tion.jda.api.utils.cache.CacheFlag) ErrorHandler(net.dv8tion.jda.api.exceptions.ErrorHandler) OnlineStatus(net.dv8tion.jda.api.OnlineStatus) MemberCachePolicy(net.dv8tion.jda.api.utils.MemberCachePolicy) ShopListener(de.kaktushose.levelbot.shop.ShopListener) Logger(org.slf4j.Logger) JsonErrorMessageFactory(com.github.kaktushose.jda.commands.embeds.error.JsonErrorMessageFactory) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) de.kaktushose.levelbot.database.services(de.kaktushose.levelbot.database.services) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) EmbedDTO(com.github.kaktushose.jda.commands.embeds.EmbedDTO) List(java.util.List) EmbedCache(com.github.kaktushose.jda.commands.embeds.EmbedCache) Rank(de.kaktushose.levelbot.database.model.Rank) JDACommands(com.github.kaktushose.jda.commands.JDACommands) JsonHelpMessageFactory(com.github.kaktushose.jda.commands.embeds.help.JsonHelpMessageFactory) WelcomeEmbedsCommand(de.kaktushose.levelbot.commands.moderation.WelcomeEmbedsCommand) Item(de.kaktushose.levelbot.shop.data.items.Item) ChunkingFilter(net.dv8tion.jda.api.utils.ChunkingFilter) ErrorHandler(net.dv8tion.jda.api.exceptions.ErrorHandler) BotUser(de.kaktushose.levelbot.database.model.BotUser)

Example 3 with BotUser

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

the class ChangeDiamondsCommand method onChangeDiamonds.

@Command(name = "Diamanten tauschen", usage = "{prefix}tauschen <anzahl>", desc = "Tauscht Diamanten gegen Münzen ein. Ein Diamant ist 20 Münzen wert")
public void onChangeDiamonds(CommandEvent event, @Optional("1") long amount) {
    BotUser botUser = userService.getUserById(event.getAuthor().getIdLong());
    long diamonds = botUser.getDiamonds();
    long coins = amount * 20;
    if (diamonds == 0 || amount > diamonds) {
        event.reply(embedCache.getEmbed("missingCurrency").injectValue("currency", "Diamanten"));
        return;
    }
    event.reply(embedCache.getEmbed("confirmAction").injectValue("action", String.format("du %d Diamanten gegen %d Münzen tauschen möchtest?", amount, coins)), confirmMessage -> {
        confirmMessage.addReaction(EmoteType.THUMBSUP.unicode).and(confirmMessage.addReaction(EmoteType.THUMBSDOWN.unicode)).queue();
        ReactionWaiter reactionWaiter = new ReactionWaiter(confirmMessage, event.getMember(), EmoteType.THUMBSUP.unicode, EmoteType.THUMBSDOWN.unicode);
        reactionWaiter.onEvent(reactionEvent -> {
            if (reactionEvent.getEmote().equals(EmoteType.THUMBSUP.unicode)) {
                userService.exchangeDiamonds(botUser.getUserId(), amount);
                confirmMessage.editMessageEmbeds(embedCache.getEmbed("diamondChangeSuccess").injectValue("diamonds", amount).injectValue("coins", coins).toMessageEmbed()).queue();
            }
            reactionWaiter.stopWaiting(true);
        });
    });
}
Also used : BotUser(de.kaktushose.levelbot.database.model.BotUser) ReactionWaiter(de.kaktushose.discord.reactionwaiter.ReactionWaiter) Command(com.github.kaktushose.jda.commands.annotations.Command)

Example 4 with BotUser

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

the class UserService method addXp.

public long addXp(long userId, long amount) {
    BotUser botUser = getUserById(userId);
    botUser.setXp(botUser.getXp() + amount);
    userRepository.save(botUser);
    return botUser.getXp();
}
Also used : BotUser(de.kaktushose.levelbot.database.model.BotUser)

Example 5 with BotUser

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

the class UserService method addCoins.

public long addCoins(long userId, long amount) {
    BotUser botUser = getUserById(userId);
    botUser.setCoins(botUser.getCoins() + amount);
    userRepository.save(botUser);
    return botUser.getCoins();
}
Also used : BotUser(de.kaktushose.levelbot.database.model.BotUser)

Aggregations

BotUser (de.kaktushose.levelbot.database.model.BotUser)33 Command (com.github.kaktushose.jda.commands.annotations.Command)4 Item (de.kaktushose.levelbot.shop.data.items.Item)3 TimeUnit (java.util.concurrent.TimeUnit)3 EmbedCache (com.github.kaktushose.jda.commands.embeds.EmbedCache)2 EmbedDTO (com.github.kaktushose.jda.commands.embeds.EmbedDTO)2 ReactionWaiter (de.kaktushose.discord.reactionwaiter.ReactionWaiter)2 Levelbot (de.kaktushose.levelbot.bot.Levelbot)2 CollectEvent (de.kaktushose.levelbot.database.model.CollectEvent)2 Rank (de.kaktushose.levelbot.database.model.Rank)2 UserService (de.kaktushose.levelbot.database.services.UserService)2 ShopService (de.kaktushose.levelbot.shop.data.ShopService)2 Transaction (de.kaktushose.levelbot.shop.data.transactions.Transaction)2 List (java.util.List)2 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 JDACommands (com.github.kaktushose.jda.commands.JDACommands)1 JsonErrorMessageFactory (com.github.kaktushose.jda.commands.embeds.error.JsonErrorMessageFactory)1 JsonHelpMessageFactory (com.github.kaktushose.jda.commands.embeds.help.JsonHelpMessageFactory)1