import static java.lang.String.format;
import static net.pterodactylus.irc.event.ChannelNotJoined.Reason.banned;
+import static net.pterodactylus.irc.event.ChannelNotJoined.Reason.inviteOnly;
import static net.pterodactylus.irc.event.ChannelNotJoined.Reason.registeredNicknamesOnly;
import static net.pterodactylus.irc.util.MessageCleaner.getDefaultInstance;
import static net.pterodactylus.xdcc.data.Channel.TO_NETWORK;
}
Map<Long, Network> timesForNextConnects = new TreeMap<>(missingNetworks.stream()
- .collect(Collectors.toMap(connectionBackoff::getBackoff, Function.identity(), (network, ignore) -> network)));
+ .collect(Collectors.toMap(connectionBackoff::getConnectionTime, Function.identity(), (network, ignore) -> network)));
Optional<Entry<Long, Network>> firstNetwork = Optional.fromNullable(timesForNextConnects.entrySet().stream().findFirst().orElse(null));
if (!firstNetwork.isPresent()) {
continue;
}
- if (firstNetwork.get().getKey() > 0) {
- eventBus.post(new GenericMessage(String.format("Waiting %d minutes to connect to %s...", TimeUnit.MILLISECONDS.toMinutes(firstNetwork.get().getKey()), firstNetwork.get().getValue().name())));
+ if (firstNetwork.get().getKey() > System.currentTimeMillis()) {
+ 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());
+ syncObject.wait(firstNetwork.get().getKey() - System.currentTimeMillis());
} catch (InterruptedException ie1) {
/* ignore. */
}
if (!isRunning()) {
break;
}
+ if (firstNetwork.get().getKey() > System.currentTimeMillis()) {
+ continue;
+ }
}
connectNetwork(firstNetwork.get().getValue());
.forEach(bot -> networkBots.row(network.get())
.remove(bot.name()));
+ channelBanManager.ban(channel.get());
if (channelNotJoined.reason() == registeredNicknamesOnly) {
- channels.remove(channel.get());
eventBus.post(new GenericMessage(
format("Not trying to join %s anymore.", channel.get())));
- return;
- }
- if (channelNotJoined.reason() == banned) {
- channelBanManager.ban(channel.get());
+ } else if (channelNotJoined.reason() == inviteOnly) {
+ eventBus.post(new GenericMessage(
+ format("%s is invite-only, suspending join for a day.",
+ channel.get())));
+ } else if (channelNotJoined.reason() == banned) {
eventBus.post(new GenericMessage(
format("Banned from %s, suspending join for a day.",
channel.get())));
- return;
+ } else {
+ eventBus.post(new GenericMessage(
+ format("Could not join %s: %s", channelNotJoined.channel(),
+ channelNotJoined.reason())));
}
-
- eventBus.post(new GenericMessage(
- format("Could not join %s: %s", channelNotJoined.channel(),
- channelNotJoined.reason())));
}
/**