use of discord4j.rest.entity.RestChannel 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);
}
}
use of discord4j.rest.entity.RestChannel in project KaellyBot by Kaysoro.
the class GuildLeaveListener method onReady.
public Mono<MessageData> onReady(GuildDeleteEvent event) {
try {
Optional<Guild> optionalGuild = event.getGuild().map(guildEvent -> Guild.getGuild(guildEvent, false));
if (optionalGuild.isPresent()) {
Guild guild = optionalGuild.get();
guild.removeToDatabase();
LOG.info("La guilde " + event.getGuildId().asString() + " - " + guild.getName() + " a supprimé " + Constants.name);
RestChannel channel = ClientConfig.DISCORD().getChannelById(Snowflake.of(Constants.chanReportID));
return channel.createMessage("[LOSE] **" + optionalGuild.get().getName() + "**, -" + event.getGuild().map(discord4j.core.object.entity.Guild::getMemberCount).orElse(0) + " utilisateurs");
}
} catch (Exception e) {
Reporter.report(e, event.getGuild().orElse(null));
LOG.error("onReady", e);
}
return Mono.empty();
}
use of discord4j.rest.entity.RestChannel in project KaellyBot by Kaysoro.
the class RSSFinder method start.
public static void start() {
if (!isStarted) {
isStarted = true;
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(() -> {
Map<Language, List<RSS>> allFeeds = new HashMap<>();
for (Language lg : Language.values()) allFeeds.put(lg, RSS.getRSSFeeds(lg));
for (RSSFinder finder : getRSSFinders().values()) try {
RestChannel chan = ClientConfig.DISCORD().getChannelById(Snowflake.of(finder.chan));
Language lg = Translator.getLanguageFrom(chan);
List<RSS> rssFeeds = allFeeds.get(Translator.getLanguageFrom(chan));
long lastRSS = -1;
for (RSS rss : rssFeeds) if (rss.getDate() > finder.getLastRSS()) {
chan.createMessage(rss.decorateRestEmbedObject(lg)).doOnError(error -> {
if (error instanceof ClientException) {
LOG.warn("RSSFinder: no access on " + finder.getChan());
finder.removeToDatabase();
} else
LOG.error("RSSFinder", error);
}).subscribe();
lastRSS = rss.getDate();
}
if (lastRSS != -1)
finder.setLastRSS(lastRSS);
} catch (ClientException e) {
LOG.warn("RSSFinder: no access on " + finder.getChan());
finder.removeToDatabase();
} catch (Exception e) {
Reporter.report(e);
LOG.error("RSSFinder", e);
}
}, 0, DELTA, TimeUnit.MINUTES);
}
}
Aggregations