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;
}
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));
});
}
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);
});
});
}
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();
}
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();
}
Aggregations