X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fxdcc%2Fui%2Fstdin%2FStatsCommand.java;h=d40cc82ed93e4d5cb30b4aab2dd8dd6ebc362c19;hb=798d9da09a3f9804ccbb488478c591a4928b05ac;hp=85b92d119f8e0d767af88e183bfb05da2c511b7f;hpb=1ca482cdf4956eb7dcdcfd75c4d0412cf0261fdf;p=xudocci.git diff --git a/src/main/java/net/pterodactylus/xdcc/ui/stdin/StatsCommand.java b/src/main/java/net/pterodactylus/xdcc/ui/stdin/StatsCommand.java index 85b92d1..d40cc82 100644 --- a/src/main/java/net/pterodactylus/xdcc/ui/stdin/StatsCommand.java +++ b/src/main/java/net/pterodactylus/xdcc/ui/stdin/StatsCommand.java @@ -17,19 +17,17 @@ package net.pterodactylus.xdcc.ui.stdin; +import static java.lang.String.format; import static java.util.Collections.emptyList; import java.io.IOException; import java.io.Writer; import java.util.Collection; import java.util.List; -import java.util.Set; +import java.util.StringJoiner; import net.pterodactylus.xdcc.core.Core; -import net.pterodactylus.xdcc.data.Bot; -import net.pterodactylus.xdcc.data.Pack; - -import com.google.common.collect.Sets; +import net.pterodactylus.xdcc.data.ConnectedNetwork; /** * Command that outputs a short statistic of what is going on. @@ -38,23 +36,12 @@ import com.google.common.collect.Sets; */ public class StatsCommand implements Command { - /** The core to operate on. */ private final Core core; - /** - * Creates a new stats command. - * - * @param core - * The core to operate on - */ public StatsCommand(Core core) { this.core = core; } - // - // COMMAND METHODS - // - @Override public String getName() { return "stats"; @@ -67,22 +54,46 @@ public class StatsCommand implements Command { @Override public State execute(State state, List parameters, Writer outputWriter) throws IOException { - int configuredChannelsCount = core.channels().size(); - int joinedChannelsCount = core.joinedChannels().size(); - int extraChannelsCount = core.extraChannels().size(); - Collection bots = core.bots(); - Set packNames = Sets.newHashSet(); - int packsCount = 0; - for (Bot bot : bots) { - packsCount += bot.packs().size(); - for (Pack pack : bot) { - packNames.add(pack.name()); + int totalBotCount = 0; + int totalPackCount = 0; + for (ConnectedNetwork network : core.connectedNetworks()) { + dumpNetworkStats(outputWriter, network); + totalBotCount += network.getBotCount(); + totalPackCount += network.getPackCount(); + } + outputWriter.write(format("Total: %d bots, %d packs.\n", totalBotCount, totalPackCount)); + return null; + } + + private void dumpNetworkStats(Writer outputWriter, + ConnectedNetwork network) throws IOException { + outputWriter.write(format("Connected to %s via %s:%d.\n", + network.getNetwork().name(), network.getHostname(), + network.getPort(), network.getNickname())); + String joinedChannels = joinChannelNames(network.getChannels()); + String forcedChannels = joinChannelNames(network.getForcedChannels()); + if (forcedChannels.isEmpty()) { + if (!joinedChannels.isEmpty()) { + outputWriter.write(format(" Joined %s.\n", joinedChannels)); + } + } else { + if (joinedChannels.isEmpty()) { + outputWriter.write( + format(" Force-joined %s.\n", forcedChannels)); + } else { + outputWriter.write(format(" Joined %s, force-joined %s.\n", + joinedChannels, forcedChannels)); } } + outputWriter.write( + format(" %d bots serving %d packs.\n", network.getBotCount(), + network.getPackCount())); + } - outputWriter.write(String.format("%d channels (%d joined, %d extra), %d bots offering %d packs (%d unique).\n", configuredChannelsCount, joinedChannelsCount, extraChannelsCount, bots.size(), packsCount, packNames.size())); - outputWriter.flush(); - return state; + private String joinChannelNames(Collection channels) { + StringJoiner joinedChannels = new StringJoiner(", "); + channels.stream().forEach((channel) -> joinedChannels.add(channel)); + return joinedChannels.toString(); } }