Search in sources :

Example 1 with LongLongPair

use of ml.duncte123.skybot.objects.pairs.LongLongPair in project SkyBot by duncte123.

the class ShardInfoCommand method getConnectedVoiceChannels.

private LongLongPair getConnectedVoiceChannels(ShardManager shardManager) {
    final AtomicLong connectedVC = new AtomicLong();
    final AtomicLong listeningVC = new AtomicLong();
    shardManager.getShardCache().forEach((jda) -> {
        final LongLongPair shardStats = getConnectedVoiceChannels(jda);
        connectedVC.addAndGet(shardStats.getFirst());
        listeningVC.addAndGet(shardStats.getSecond());
    });
    return new LongLongPair(connectedVC.get(), listeningVC.get());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) LongLongPair(ml.duncte123.skybot.objects.pairs.LongLongPair)

Example 2 with LongLongPair

use of ml.duncte123.skybot.objects.pairs.LongLongPair in project SkyBot by duncte123.

the class ShardInfoCommand method embedTable.

private void embedTable(CommandContext ctx) {
    final EmbedBuilder embedBuilder = new EmbedBuilder();
    final int currentShard = ctx.getJDA().getShardInfo().getShardId();
    final ShardManager shardManager = ctx.getJDA().getShardManager();
    final ShardCacheView shardCache = shardManager.getShardCache();
    final List<JDA> shards = new ArrayList<>(shardCache.asList());
    Collections.reverse(shards);
    for (final JDA shard : shards) {
        final StringBuilder valueBuilder = new StringBuilder();
        final LongLongPair channelStats = getConnectedVoiceChannels(shard);
        valueBuilder.append("**Status:** ").append(getShardStatus(shard)).append("\n**Ping:** ").append(shard.getGatewayPing()).append("\n**Guilds:** ").append(shard.getGuildCache().size()).append("\n**VCs:** ").append(channelStats.getFirst()).append(" / ").append(channelStats.getSecond());
        final int shardId = shard.getShardInfo().getShardId();
        embedBuilder.addField(String.format("Shard #%s%s", shardId, shardId == currentShard ? " (current)" : ""), valueBuilder.toString(), true);
    }
    final long connectedShards = shardCache.applyStream((s) -> s.filter((shard) -> shard.getStatus() == JDA.Status.CONNECTED).count());
    final String avgPing = new DecimalFormat("###").format(shardManager.getAverageGatewayPing());
    final long guilds = shardManager.getGuildCache().size();
    final LongLongPair channelStats = getConnectedVoiceChannels(shardManager);
    embedBuilder.addField("Total/Average", String.format("**Connected:** %s\n**Ping:** %s\n**Guilds:** %s\n**VCs:** %s / %s", connectedShards, avgPing, guilds, channelStats.getFirst(), channelStats.getSecond()), false);
    sendEmbed(ctx, embedBuilder);
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) LongLongPair(ml.duncte123.skybot.objects.pairs.LongLongPair) JDA(net.dv8tion.jda.api.JDA) ShardCacheView(net.dv8tion.jda.api.utils.cache.ShardCacheView) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) ShardManager(net.dv8tion.jda.api.sharding.ShardManager)

Example 3 with LongLongPair

use of ml.duncte123.skybot.objects.pairs.LongLongPair in project SkyBot by duncte123.

the class ShardInfoCommand method asciiInfo.

private void asciiInfo(CommandContext ctx) {
    final List<String> headers = new ArrayList<>();
    headers.add("ID");
    headers.add("Status");
    headers.add("Ping");
    headers.add("Guilds");
    headers.add("VCs");
    List<List<String>> table = new ArrayList<>();
    final int currentShard = ctx.getJDA().getShardInfo().getShardId();
    final ShardManager shardManager = ctx.getJDA().getShardManager();
    final List<JDA> shards = new ArrayList<>(shardManager.getShards());
    Collections.reverse(shards);
    for (final JDA shard : shards) {
        final List<String> row = new ArrayList<>();
        final int shardId = shard.getShardInfo().getShardId();
        row.add(shardId + (currentShard == shardId ? " (current)" : ""));
        row.add(getShardStatus(shard));
        row.add(String.valueOf(shard.getGatewayPing()));
        row.add(String.valueOf(shard.getGuildCache().size()));
        final LongLongPair channelStats = getConnectedVoiceChannels(shard);
        row.add(channelStats.getFirst() + " / " + channelStats.getSecond());
        table.add(row);
        if (table.size() == 20) {
            MessageUtils.sendMsg(ctx, makeAsciiTable(headers, table, shardManager));
            table = new ArrayList<>();
        }
    }
    if (!table.isEmpty()) {
        MessageUtils.sendMsg(ctx, makeAsciiTable(headers, table, shardManager));
    }
}
Also used : LongLongPair(ml.duncte123.skybot.objects.pairs.LongLongPair) JDA(net.dv8tion.jda.api.JDA) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ShardManager(net.dv8tion.jda.api.sharding.ShardManager)

Example 4 with LongLongPair

use of ml.duncte123.skybot.objects.pairs.LongLongPair in project SkyBot by DuncteBot.

the class ShardInfoCommand method getConnectedVoiceChannels.

private LongLongPair getConnectedVoiceChannels(ShardManager shardManager) {
    final AtomicLong connectedVC = new AtomicLong();
    final AtomicLong listeningVC = new AtomicLong();
    shardManager.getShardCache().forEach((jda) -> {
        final LongLongPair shardStats = getConnectedVoiceChannels(jda);
        connectedVC.addAndGet(shardStats.getFirst());
        listeningVC.addAndGet(shardStats.getSecond());
    });
    return new LongLongPair(connectedVC.get(), listeningVC.get());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) LongLongPair(ml.duncte123.skybot.objects.pairs.LongLongPair)

Example 5 with LongLongPair

use of ml.duncte123.skybot.objects.pairs.LongLongPair in project SkyBot by DuncteBot.

the class ShardInfoCommand method asciiInfo.

private void asciiInfo(CommandContext ctx) {
    final List<String> headers = new ArrayList<>();
    headers.add("ID");
    headers.add("Status");
    headers.add("Ping");
    headers.add("Guilds");
    headers.add("VCs");
    List<List<String>> table = new ArrayList<>();
    final int currentShard = ctx.getJDA().getShardInfo().getShardId();
    final ShardManager shardManager = ctx.getJDA().getShardManager();
    final List<JDA> shards = new ArrayList<>(shardManager.getShards());
    Collections.reverse(shards);
    for (final JDA shard : shards) {
        final List<String> row = new ArrayList<>();
        final int shardId = shard.getShardInfo().getShardId();
        row.add(shardId + (currentShard == shardId ? " (current)" : ""));
        row.add(getShardStatus(shard));
        row.add(String.valueOf(shard.getGatewayPing()));
        row.add(String.valueOf(shard.getGuildCache().size()));
        final LongLongPair channelStats = getConnectedVoiceChannels(shard);
        row.add(channelStats.getFirst() + " / " + channelStats.getSecond());
        table.add(row);
        if (table.size() == 20) {
            MessageUtils.sendMsg(ctx, makeAsciiTable(headers, table, shardManager));
            table = new ArrayList<>();
        }
    }
    if (!table.isEmpty()) {
        MessageUtils.sendMsg(ctx, makeAsciiTable(headers, table, shardManager));
    }
}
Also used : LongLongPair(ml.duncte123.skybot.objects.pairs.LongLongPair) JDA(net.dv8tion.jda.api.JDA) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ShardManager(net.dv8tion.jda.api.sharding.ShardManager)

Aggregations

LongLongPair (ml.duncte123.skybot.objects.pairs.LongLongPair)8 DecimalFormat (java.text.DecimalFormat)4 ArrayList (java.util.ArrayList)4 JDA (net.dv8tion.jda.api.JDA)4 ShardManager (net.dv8tion.jda.api.sharding.ShardManager)4 ShardCacheView (net.dv8tion.jda.api.utils.cache.ShardCacheView)4 List (java.util.List)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)2