X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fxdcc%2Fui%2Fstdin%2FStatsCommand.java;h=07f228864a9e94eaeac6f70f5b01dad4c05894f1;hb=57e8c8f027adafe3323eb19912476fbd3b1fc317;hp=85b92d119f8e0d767af88e183bfb05da2c511b7f;hpb=e24cf5ee1b6f06840e4307abb17549856ee09297;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..07f2288 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,27 @@ 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; + } - 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 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())); + StringJoiner joinedChannels = new StringJoiner(", "); + network.getChannels().stream().forEach( + (channel) -> joinedChannels.add(channel)); + StringJoiner forceJoinedChannels = new StringJoiner(", "); + network.getForcedChannels().stream().forEach((channel) -> forceJoinedChannels.add(channel)); + outputWriter.write(format(" Joined %s, force-joined %s.\n", + joinedChannels, forceJoinedChannels)); + outputWriter.write(format(" %d bots serving %d packs.\n", network.getBotCount(), network.getPackCount())); } }