use of ml.duncte123.skybot.objects.pairs.LongLongPair in project SkyBot by DuncteBot.
the class ShardInfoCommand method makeAsciiTable.
/*
* These 2 functions have been inspired from FlareBot
* https://github.com/FlareBot/FlareBot/blob/master/src/main/java/stream/flarebot/flarebot/util/ShardUtils.java
*/
private String makeAsciiTable(List<String> headers, List<List<String>> table, ShardManager shardManager) {
final StringBuilder builder = new StringBuilder();
final int padding = 1;
final int[] widths = new int[headers.size()];
for (int i = 0; i < headers.size(); i++) {
if (headers.get(i).length() > widths[i]) {
widths[i] = headers.get(i).length();
}
}
for (final List<String> row : table) {
for (int i = 0; i < row.size(); i++) {
final String cell = row.get(i);
if (cell.length() > widths[i]) {
widths[i] = cell.length();
}
}
}
final LongLongPair channelStats = getConnectedVoiceChannels(shardManager);
final String statsString = channelStats.getFirst() + " / " + channelStats.getSecond();
if (statsString.length() > widths[widths.length - 1]) {
widths[widths.length - 1] = statsString.length();
}
if (widths[0] < 7) {
widths[0] = 7;
}
builder.append("```prolog\n");
final StringBuilder formatLine = new StringBuilder("║");
for (final int width : widths) {
formatLine.append(" %-").append(width).append("s ║");
}
formatLine.append('\n');
builder.append(appendSeparatorLine("╔", "╦", "╗", padding, widths)).append(String.format(formatLine.toString(), headers.toArray())).append(appendSeparatorLine("╠", "╬", "╣", padding, widths));
for (final List<String> row : table) {
builder.append(String.format(formatLine.toString(), row.toArray()));
}
builder.append(appendSeparatorLine("╠", "╬", "╣", padding, widths));
final ShardCacheView shardCache = shardManager.getShardCache();
final long shards = shardCache.applyStream((s) -> s.filter(shard -> shard.getStatus() == JDA.Status.CONNECTED).count());
final String connectedShards = String.valueOf(shards);
final String avgPing = new DecimalFormat("###").format(shardManager.getAverageGatewayPing());
final String guilds = String.valueOf(shardManager.getGuildCache().size());
builder.append(String.format(formatLine.toString(), "Sum/Avg", connectedShards, avgPing, guilds, statsString)).append(appendSeparatorLine("╚", "╩", "╝", padding, widths)).append("```");
return builder.toString();
}
use of ml.duncte123.skybot.objects.pairs.LongLongPair in project SkyBot by duncte123.
the class ShardInfoCommand method makeAsciiTable.
/*
* These 2 functions have been inspired from FlareBot
* https://github.com/FlareBot/FlareBot/blob/master/src/main/java/stream/flarebot/flarebot/util/ShardUtils.java
*/
private String makeAsciiTable(List<String> headers, List<List<String>> table, ShardManager shardManager) {
final StringBuilder builder = new StringBuilder();
final int padding = 1;
final int[] widths = new int[headers.size()];
for (int i = 0; i < headers.size(); i++) {
if (headers.get(i).length() > widths[i]) {
widths[i] = headers.get(i).length();
}
}
for (final List<String> row : table) {
for (int i = 0; i < row.size(); i++) {
final String cell = row.get(i);
if (cell.length() > widths[i]) {
widths[i] = cell.length();
}
}
}
final LongLongPair channelStats = getConnectedVoiceChannels(shardManager);
final String statsString = channelStats.getFirst() + " / " + channelStats.getSecond();
if (statsString.length() > widths[widths.length - 1]) {
widths[widths.length - 1] = statsString.length();
}
if (widths[0] < 7) {
widths[0] = 7;
}
builder.append("```prolog\n");
final StringBuilder formatLine = new StringBuilder("║");
for (final int width : widths) {
formatLine.append(" %-").append(width).append("s ║");
}
formatLine.append('\n');
builder.append(appendSeparatorLine("╔", "╦", "╗", padding, widths)).append(String.format(formatLine.toString(), headers.toArray())).append(appendSeparatorLine("╠", "╬", "╣", padding, widths));
for (final List<String> row : table) {
builder.append(String.format(formatLine.toString(), row.toArray()));
}
builder.append(appendSeparatorLine("╠", "╬", "╣", padding, widths));
final ShardCacheView shardCache = shardManager.getShardCache();
final long shards = shardCache.applyStream((s) -> s.filter(shard -> shard.getStatus() == JDA.Status.CONNECTED).count());
final String connectedShards = String.valueOf(shards);
final String avgPing = new DecimalFormat("###").format(shardManager.getAverageGatewayPing());
final String guilds = String.valueOf(shardManager.getGuildCache().size());
builder.append(String.format(formatLine.toString(), "Sum/Avg", connectedShards, avgPing, guilds, statsString)).append(appendSeparatorLine("╚", "╩", "╝", padding, widths)).append("```");
return builder.toString();
}
use of ml.duncte123.skybot.objects.pairs.LongLongPair in project SkyBot by DuncteBot.
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);
}
Aggregations