use of ai.elimu.model.v2.enums.Language 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);
}
}
use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.
the class ChannelLanguage method getChannelLanguages.
public static synchronized Map<Long, ChannelLanguage> getChannelLanguages() {
if (channelLanguages == null) {
channelLanguages = new ConcurrentHashMap<>();
Connexion connexion = Connexion.getInstance();
Connection connection = connexion.getConnection();
try {
PreparedStatement query = connection.prepareStatement("SELECT lang, id_chan FROM Channel_Language");
ResultSet resultSet = query.executeQuery();
while (resultSet.next()) {
long idChan = Long.parseLong(resultSet.getString("id_chan"));
Language lang = Language.valueOf(resultSet.getString("lang"));
channelLanguages.put(idChan, new ChannelLanguage(lang, idChan));
}
} catch (SQLException e) {
Reporter.report(e);
LOG.error("getChannlLanguages", e);
}
}
return channelLanguages;
}
use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.
the class NotFoundDiscordException method throwException.
@Override
public void throwException(Message message, Command command, Language lg, Object... arguments) {
AnkamaBug bug = null;
if (command instanceof WhoisCommand)
bug = AnkamaBug.CHARACTER_NOT_FOUND;
else if (command instanceof GuildCommand)
bug = AnkamaBug.GUILD_NOT_FOUND;
else if (command instanceof AllianceCommand)
bug = AnkamaBug.ALLY_NOT_FOUND;
else if (command instanceof ItemCommand)
if (message.getContent().contains("'"))
bug = AnkamaBug.ITEM_NOT_FOUND_APOSTROPHE;
else if (message.getContent().toLowerCase().contains(Translator.getLabel(lg, "equip.muldo").toLowerCase()) || message.getContent().toLowerCase().contains(Translator.getLabel(lg, "equip.volkorne").toLowerCase()))
bug = AnkamaBug.ITEM_PAGE_MULDO_VOLKORNE_NOT_FOUND;
String gender = Translator.getLabel(lg, "exception.object." + objectKey + ".gender");
String text = Translator.getLabel(lg, "exception.notfound.not." + gender) + " " + Translator.getLabel(lg, "exception.object." + objectKey + ".singular") + " " + Translator.getLabel(lg, "exception.notfound.found." + gender) + ".";
if (bug != null) {
final AnkamaBug BUG = bug;
message.getChannel().flatMap(channel -> channel.createEmbed(BUG.decorateEmbed(text, lg))).subscribe();
} else
message.getChannel().flatMap(channel -> channel.createMessage(text)).subscribe();
}
use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.
the class GuildCreateListener method onReady.
public Flux<MessageData> onReady(GuildCreateEvent event) {
try {
if (!Guild.getGuilds().containsKey(event.getGuild().getId().asString())) {
return event.getGuild().getChannels().filter(chan -> chan instanceof GuildMessageChannel).map(chan -> (GuildMessageChannel) chan).take(1).flatMap(chan -> {
Guild guild = new Guild(event.getGuild().getId().asString(), event.getGuild().getName(), Translator.detectLanguage(chan));
guild.addToDatabase();
Language lg = guild.getLanguage();
LOG.info("La guilde " + guild.getId() + " - " + guild.getName() + " a ajouté " + Constants.name);
return event.getGuild().getOwner().flatMap(owner -> {
String customMessage = Translator.getLabel(lg, "welcome.message").replaceAll("\\{name}", Constants.name).replaceAll("\\{game}", Constants.game.getName()).replaceAll("\\{prefix}", Constants.prefixCommand).replaceAll("\\{help}", HelpCommand.NAME).replaceAll("\\{server}", new ServerCommand().getName()).replaceAll("\\{lang}", new LanguageCommand().getName()).replaceAll("\\{twitter}", new TwitterCommand().getName()).replaceAll("\\{almanax-auto}", new AlmanaxAutoCommand().getName()).replaceAll("\\{rss}", new RSSCommand().getName()).replaceAll("\\{owner}", owner.getMention()).replaceAll("\\{guild}", event.getGuild().getName());
return chan.createMessage(customMessage).onErrorResume(ignored -> sendWelcomeMessageInPM(event, customMessage)).then(ClientConfig.DISCORD().getChannelById(Snowflake.of(Constants.chanReportID)).createMessage("[NEW] **" + event.getGuild().getName() + "** (" + guild.getLanguage().getAbrev() + "), +" + event.getGuild().getMemberCount() + " utilisateurs"));
});
});
}
} catch (Exception e) {
Reporter.report(e, event.getGuild());
LOG.error("onReady", e);
}
return Flux.empty();
}
use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.
the class Translator method getLanguageDetector.
private static LanguageDetector getLanguageDetector() {
if (languageDetector == null) {
try {
List<String> languages = new ArrayList<>();
for (Language lg : Language.values()) languages.add(lg.getAbrev().toLowerCase());
List<LanguageProfile> languageProfiles = new LanguageProfileReader().read(languages);
languageDetector = LanguageDetectorBuilder.create(NgramExtractors.standard()).withProfiles(languageProfiles).build();
} catch (IOException e) {
LOG.error("Translator.getLanguageDetector", e);
}
}
return languageDetector;
}
Aggregations