use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.
the class DofusEncyclopediaRequestCommand method gatherData.
protected void gatherData(IMessage message, BestMatcher matcher, String[] names, String normalName, Type type, DiscordException notFound) throws UnsupportedEncodingException {
Language lg = Translator.getLanguageFrom(message.getChannel());
String editedName = removeUselessWords(normalName);
for (String name : names) {
String potentialName = Normalizer.normalize(name, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "").toLowerCase();
if (normalName.equals(potentialName)) {
matcher.evaluateAll(getListRequestableFrom(getSearchURL(type.getType().getUrl(lg), potentialName, type.getTypeID(), lg), message, notFound));
break;
} else if (normalName.contains(potentialName)) {
matcher.evaluateAll(getListRequestableFrom(getSearchURL(type.getType().getUrl(lg), editedName.replace(potentialName, "").trim(), type.getTypeID(), lg), message, notFound));
break;
}
}
}
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"));
IChannel chan = ClientConfig.DISCORD().getChannelByID(idChan);
if (chan != null && !chan.isDeleted())
channelLanguages.put(chan.getLongID(), new ChannelLanguage(lang, idChan));
else {
new ChannelLanguage(lang, idChan).removeToDatabase();
LOG.info("Chan deleted : " + 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 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 {
IChannel chan = ClientConfig.DISCORD().getChannelByID(Long.parseLong(finder.getChan()));
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()) {
Message.sendEmbed(chan, rss.getEmbedObject(lg));
lastRSS = rss.getDate();
}
if (lastRSS != -1)
finder.setLastRSS(lastRSS);
} catch (Exception e) {
LOG.error("RSSFinder", e);
}
}, 0, DELTA, TimeUnit.MINUTES);
}
}
use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.
the class GuildCreateListener method onReady.
@EventSubscriber
public void onReady(GuildCreateEvent event) {
try {
if (!Guild.getGuilds().containsKey(event.getGuild().getStringID())) {
Guild guild = new Guild(event.getGuild().getStringID(), event.getGuild().getName(), Translator.detectLanguage(event.getGuild().getDefaultChannel()));
guild.addToDatabase();
Language lg = guild.getLanguage();
LOG.info("La guilde " + guild.getId() + " - " + guild.getName() + " a ajouté " + Constants.name);
String customMessage = Translator.getLabel(lg, "welcome.message");
customMessage = customMessage.replaceAll("\\{name\\}", Constants.name).replaceAll("\\{game\\}", Constants.game).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\\}", new AlmanaxCommand().getName()).replaceAll("\\{rss\\}", new RSSCommand().getName()).replaceAll("\\{owner\\}", event.getGuild().getOwner().mention()).replaceAll("\\{guild\\}", event.getGuild().getName());
if (event.getGuild().getDefaultChannel() != null && event.getGuild().getDefaultChannel().getModifiedPermissions(ClientConfig.DISCORD().getOurUser()).contains(Permissions.SEND_MESSAGES))
Message.sendText(event.getGuild().getDefaultChannel(), customMessage);
else
try {
Message.sendText(event.getGuild().getOwner().getOrCreatePMChannel(), customMessage);
} catch (DiscordException e) {
LOG.warn("onReady", "Impossible de contacter l'administrateur de la guilde [" + guild.getName() + "].");
}
Message.sendText(ClientConfig.DISCORD().getChannelByID(Constants.chanReportID), "[NEW] **" + guild.getName() + "** (" + guild.getLanguage().getAbrev() + "), +" + event.getGuild().getUsers().size() + " utilisateurs");
}
} catch (Exception e) {
Reporter.report(e, event.getGuild());
LOG.error("onReady", e);
}
}
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) {
LoggerFactory.getLogger(Translator.class).error("Translator.getLanguageDetector", e);
}
}
return languageDetector;
}
Aggregations