import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.time.Duration;
+import java.time.Instant;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
/** The logger. */
private static final Logger logger = Logger.getLogger(Core.class.getName());
+ private final Instant startup = Instant.now();
private final Object syncObject = new Object();
/** The event bus. */
private final EventBus eventBus;
Network network = entry.getKey();
Collection<Bot> bots = networkBots.row(network).values();
int packCount = bots.stream().mapToInt((bot) -> bot.packs().size()).reduce((a, b) -> a + b).orElse(0);
- return new ConnectedNetwork(network, entry.getValue().hostname(),
- entry.getValue().port(), entry.getValue().nickname(),
+ Connection connection = entry.getValue();
+ return new ConnectedNetwork(network, connection.hostname(),
+ connection.port(),
+ connection.getUptime().get(),
+ connection.nickname(),
channels.stream()
.filter((channel) -> channel.network()
.equals(network))
return downloads.values();
}
+ public Duration getUptime() {
+ return Duration.between(startup, Instant.now());
+ }
+
//
// ACTIONS
//
continue;
}
if (firstNetwork.get().getKey() > System.currentTimeMillis()) {
- eventBus.post(new GenericMessage(String.format("Waiting %d minutes to connect to %s...", TimeUnit.MILLISECONDS.toMinutes(firstNetwork.get().getKey() - System.currentTimeMillis()), firstNetwork.get().getValue().name())));
+ eventBus.post(new GenericMessage(String.format("Will connect to %2$s at %1$tH:%1$tM...", firstNetwork.get().getKey(), firstNetwork.get().getValue().name())));
synchronized (syncObject) {
try {
syncObject.wait(firstNetwork.get().getKey() - System.currentTimeMillis());
return;
}
networkConnections.remove(network.get());
- if (!connection.established()) {
- return;
- }
/* find all channels that need to be removed. */
for (Collection<Channel> channels : ImmutableList.of(joinedChannels, extraChannels)) {
channelBanManager.ban(channel.get());
if (channelNotJoined.reason() == registeredNicknamesOnly) {
eventBus.post(new GenericMessage(
- format("Not trying to join %s anymore.", channel.get())));
+ format("%s requires nickname registration, suspending join for a day.",
+ channel.get())));
} else if (channelNotJoined.reason() == inviteOnly) {
eventBus.post(new GenericMessage(
format("%s is invite-only, suspending join for a day.",
"Kicked from %s by %s: %s",
kickedFromChannel.channel(),
kickedFromChannel.kicker(),
- kickedFromChannel.reason().or("<unknown>")
+ kickedFromChannel.reason().orElse("<unknown>")
)));
}
}