Add “stats” command.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 10 Apr 2013 06:24:50 +0000 (08:24 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 10 Apr 2013 06:27:07 +0000 (08:27 +0200)
src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java

index 497c5fd..ad6cde1 100644 (file)
@@ -20,8 +20,10 @@ package net.pterodactylus.xdcc.ui.stdin;
 import java.io.BufferedReader;
 import java.io.Reader;
 import java.io.Writer;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Set;
 
 import net.pterodactylus.irc.DccReceiver;
 import net.pterodactylus.xdcc.core.Core;
@@ -29,6 +31,7 @@ import net.pterodactylus.xdcc.data.Bot;
 import net.pterodactylus.xdcc.data.Pack;
 
 import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
 import com.google.common.primitives.Ints;
 import com.google.common.util.concurrent.AbstractExecutionThreadService;
 
@@ -115,6 +118,21 @@ public class CommandReader extends AbstractExecutionThreadService {
                                if ((index != null) && (index < lastResult.size())) {
                                        core.fetch(lastResult.get(index).bot(), lastResult.get(index).pack());
                                }
+                       } else if (words[0].equalsIgnoreCase("stats")) {
+                               int configuredChannelsCount = core.channels().size();
+                               int joinedChannelsCount = core.joinedChannels().size();
+                               int extraChannelsCount = core.extraChannels().size();
+                               Collection<Bot> bots = core.bots();
+                               Set<String> packNames = Sets.newHashSet();
+                               int packsCount = 0;
+                               for (Bot bot : bots) {
+                                       packsCount += bot.packs().size();
+                                       for (Pack pack : bot) {
+                                               packNames.add(pack.name());
+                                       }
+                               }
+
+                               writer.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()));
                        }
 
                        lastLine = line;