- if (words[0].equalsIgnoreCase("search")) {
- lastResult.clear();
- for (Bot bot : Lists.newArrayList(core.bots())) {
- for (Pack pack : Lists.newArrayList(bot)) {
- boolean found = true;
- for (int wordIndex = 1; wordIndex < words.length; ++wordIndex) {
- if (words[wordIndex].startsWith("-") && pack.name().toLowerCase().contains(words[wordIndex].toLowerCase().substring(1))) {
- found = false;
- break;
- }
- if (!words[wordIndex].startsWith("-") && !pack.name().toLowerCase().contains(words[wordIndex].toLowerCase())) {
- found = false;
- break;
- }
- }
- if (found) {
- lastResult.add(new Result(bot, pack));
- }
- }
- }
- Collections.sort(lastResult);
- int counter = 0;
- for (Result result : lastResult) {
- writeLine(String.format("[%d] %s (%s) from %s (#%s) on %s", counter++, result.pack().name(), result.pack().size(), result.bot().name(), result.pack().id(), result.bot().network().name()));
- }
- writeLine("End of Search.");
- } else if (words[0].equalsIgnoreCase("dcc")) {
- int counter = 0;
- for (Download download : core.downloads()) {
- DccReceiver dccReceiver = download.dccReceiver();
- if (dccReceiver == null) {
- /* download has not even started. */
- writer.write(String.format("[%d] %s requested from %s (not started yet)\n", counter++, download.pack().name(), download.bot().name()));
- continue;
- }
- writer.write(String.format("[%d] %s from %s (%s, ", counter++, dccReceiver.filename(), download.bot().name(), f(dccReceiver.size())));
- if (dccReceiver.isRunning()) {
- writer.write(String.format("%.1f%%, %s", dccReceiver.progress() * 100.0 / dccReceiver.size(), f(dccReceiver.currentRate())));
- } else {
- if (dccReceiver.progress() >= dccReceiver.size()) {
- writer.write(String.format("complete, %s", f(dccReceiver.overallRate())));
- } else {
- writer.write(String.format("aborted at %.1f%%, %s", dccReceiver.progress() * 100.0 / dccReceiver.size(), f(dccReceiver.currentRate())));
- }
- }
- writer.write("/s)\n");
- }
- writeLine("End of DCCs.");
- } else if (words[0].equalsIgnoreCase("get")) {
- Integer index = Ints.tryParse(words[1]);
- 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());
- }
- }
-
- writeLine(String.format("%d channels (%d joined, %d extra), %d bots offering %d packs (%d unique).", configuredChannelsCount, joinedChannelsCount, extraChannelsCount, bots.size(), packsCount, packNames.size()));
- } else if (words[0].equalsIgnoreCase("connections")) {
- lastConnections.clear();
- int counter = 0;
- for (Connection connection : core.connections()) {
- lastConnections.add(connection);
- writer.write(String.format("[%d] %s:%d, %s/s\n", counter++, connection.hostname(), connection.port(), f(connection.getInputRate())));
- }
- writeLine("End of connections.");
- } else if (words[0].equalsIgnoreCase("disconnect")) {
- if ((words.length == 1) || ("all".equals(words[1]))) {
- for (Connection connection : lastConnections) {
- core.closeConnection(connection);
- }
- } else {
- Integer index = Ints.tryParse(words[1]);
- if ((index != null) && (index < lastConnections.size())) {
- core.closeConnection(lastConnections.get(index));
- }
- }