Search in sources :

Example 1 with Pair

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();
    }
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IMessage(sx.blah.discord.handle.obj.IMessage) Pair(me.shadorc.shadbot.utils.object.Pair)

Example 2 with Pair

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);
}
Also used : StatsJSON(me.shadorc.shadbot.data.stats.annotation.StatsJSON) LottoManager(me.shadorc.shadbot.data.lotto.LottoManager) HashMap(java.util.HashMap) StatsInit(me.shadorc.shadbot.data.stats.annotation.StatsInit) FormatUtils(me.shadorc.shadbot.utils.FormatUtils) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Pair(me.shadorc.shadbot.utils.object.Pair) AtomicLong(java.util.concurrent.atomic.AtomicLong) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) List(java.util.List) JSONObject(org.json.JSONObject) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) AbstractCommand(me.shadorc.shadbot.core.command.AbstractCommand) Entry(java.util.Map.Entry) CommandEnum(me.shadorc.shadbot.data.stats.CommandStatsManager.CommandEnum) EmbedUtils(me.shadorc.shadbot.utils.embed.EmbedUtils) Comparator(java.util.Comparator) Collections(java.util.Collections) Utils(me.shadorc.shadbot.utils.Utils) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AtomicLong(java.util.concurrent.atomic.AtomicLong) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) Entry(java.util.Map.Entry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicLong(java.util.concurrent.atomic.AtomicLong) Pair(me.shadorc.shadbot.utils.object.Pair)

Aggregations

Pair (me.shadorc.shadbot.utils.object.Pair)2 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Collectors (java.util.stream.Collectors)1 AbstractCommand (me.shadorc.shadbot.core.command.AbstractCommand)1 LottoManager (me.shadorc.shadbot.data.lotto.LottoManager)1 CommandEnum (me.shadorc.shadbot.data.stats.CommandStatsManager.CommandEnum)1 StatsInit (me.shadorc.shadbot.data.stats.annotation.StatsInit)1 StatsJSON (me.shadorc.shadbot.data.stats.annotation.StatsJSON)1 FormatUtils (me.shadorc.shadbot.utils.FormatUtils)1 Utils (me.shadorc.shadbot.utils.Utils)1 EmbedUtils (me.shadorc.shadbot.utils.embed.EmbedUtils)1