use of me.shadorc.shadbot.utils.object.Pair in project Shadbot by Shadorc.
the class RouletteManager method show.
public void show() {
EmbedBuilder embed = EmbedUtils.getDefaultEmbed().setLenient(true).withAuthorName("Roulette Game").withThumbnail("http://icongal.com/gallery/image/278586/roulette_baccarat_casino.png").withDescription(String.format("**Use `%s%s <bet> <place>` to join the game.**" + "%n%n**Place** is a `number between 1 and 36`, %s", this.getPrefix(), this.getCmdName(), FormatUtils.format(Place.values(), value -> String.format("`%s`", value.toString().toLowerCase()), ", "))).appendField("Player (Bet)", FormatUtils.format(playersPlace.keySet().stream(), user -> String.format("**%s** (%s)", user.getName(), FormatUtils.formatCoins(playersPlace.get(user).getFirst())), "\n"), true).appendField("Place", playersPlace.values().stream().map(Pair::getSecond).collect(Collectors.joining("\n")), true).appendField("Results", results, false).withFooterText(String.format("You have %d seconds to make your bets.", GAME_DURATION));
RequestFuture<IMessage> msgRequest = message.send(embed.build());
if (msgRequest != null) {
msgRequest.get();
}
}
use of me.shadorc.shadbot.utils.object.Pair in project Shadbot by Shadorc.
the class MoneyStatsManager method getAverageEmbed.
public static EmbedBuilder getAverageEmbed() {
Map<String, AtomicLong> moneyGained = MONEY_STATS_MAP.getOrDefault(MoneyEnum.MONEY_GAINED, Collections.emptyMap());
Map<String, AtomicLong> moneyLost = MONEY_STATS_MAP.getOrDefault(MoneyEnum.MONEY_LOST, Collections.emptyMap());
EmbedBuilder embed = EmbedUtils.getDefaultEmbed().withAuthorName("Stats: average");
List<String> gamesName = new ArrayList<>();
gamesName.addAll(moneyGained.keySet());
gamesName.addAll(moneyLost.keySet());
gamesName = gamesName.stream().distinct().collect(Collectors.toList());
if (gamesName.isEmpty()) {
return embed.withDescription("No statistics yet.");
}
Map<String, AtomicInteger> commandsUsed = CommandStatsManager.get(CommandEnum.COMMAND_USED);
Map<String, Pair<Float, Long>> averageMap = new HashMap<>();
for (String gameName : gamesName) {
long gains = moneyGained.getOrDefault(gameName, new AtomicLong(0)).get();
long losses = moneyLost.getOrDefault(gameName, new AtomicLong(0)).get();
long usages = commandsUsed.get(gameName).get();
float average = ((float) gains - losses) / usages;
averageMap.put(gameName, new Pair<Float, Long>(average, usages));
}
Comparator<Entry<String, Pair<Float, Long>>> comparator = (v1, v2) -> v1.getValue().getSecond().compareTo(v2.getValue().getSecond());
Map<String, Pair<Float, Long>> sortedMap = Utils.sortByValue(averageMap, comparator.reversed());
return embed.appendField("Name", FormatUtils.format(sortedMap.keySet().stream(), Object::toString, "\n"), true).appendField("Average", FormatUtils.format(sortedMap.values().stream().map(Pair::getFirst), num -> FormatUtils.formatNum(num.intValue()), "\n"), true).appendField("Count", FormatUtils.format(sortedMap.values().stream().map(Pair::getSecond), num -> FormatUtils.formatNum(num), "\n"), true);
}
Aggregations