use of discord4j.discordjson.json.EmbedData in project KaellyBot by Kaysoro.
the class AlmanaxCalendar method start.
public static void start() {
if (!isStarted) {
isStarted = true;
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
long firstDelay = LocalDateTime.now().until(LocalDate.now().plusDays(1).atStartOfDay().plusMinutes(1), ChronoUnit.MINUTES);
long period = TimeUnit.DAYS.toMinutes(1);
scheduler.scheduleAtFixedRate(() -> {
boolean success = false;
Map<Language, EmbedData> almanax = new HashMap<>();
while (!success) try {
almanax.clear();
for (Language lg : Language.values()) almanax.put(lg, Almanax.get(lg, new Date()).decorateRestEmbedObject(lg));
success = true;
} catch (IOException e) {
ExceptionManager.manageSilentlyIOException(e);
try {
// 5min
Thread.sleep(300000);
} catch (InterruptedException e1) {
LOG.error("start", e1);
}
}
for (AlmanaxCalendar calendar : getAlmanaxCalendars().values()) {
try {
RestChannel chan = ClientConfig.DISCORD().getChannelById(Snowflake.of(calendar.chan));
Language lg = Translator.getLanguageFrom(chan);
chan.createMessage(almanax.get(lg)).doOnError(error -> {
if (error instanceof ClientException) {
LOG.warn("AlmanaxCalendar: no access on " + calendar.getChan());
calendar.removeToDatabase();
} else
LOG.error("AlmanaxCalendar", error);
}).subscribe();
} catch (ClientException e) {
LOG.warn("AlmanaxCalendar: no access on " + calendar.getChan());
calendar.removeToDatabase();
} catch (Exception e) {
LOG.error("AlmanaxCalendar", e);
}
}
}, firstDelay, period, TimeUnit.MINUTES);
}
}
Aggregations