Search in sources :

Example 41 with Language

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;
        }
    }
}
Also used : Language(enums.Language)

Example 42 with Language

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;
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) Language(enums.Language) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Connexion(util.Connexion)

Example 43 with Language

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);
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) IChannel(sx.blah.discord.handle.obj.IChannel) RSS(data.RSS) Language(enums.Language) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) List(java.util.List) SQLException(java.sql.SQLException)

Example 44 with Language

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);
    }
}
Also used : Language(enums.Language) DiscordException(sx.blah.discord.util.DiscordException) LanguageCommand(commands.config.LanguageCommand) Guild(data.Guild) DiscordException(sx.blah.discord.util.DiscordException) ServerCommand(commands.config.ServerCommand) TwitterCommand(commands.config.TwitterCommand) AlmanaxCommand(commands.classic.AlmanaxCommand) RSSCommand(commands.config.RSSCommand) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Example 45 with Language

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;
}
Also used : LanguageProfile(com.optimaize.langdetect.profiles.LanguageProfile) Language(enums.Language) ChannelLanguage(data.ChannelLanguage) LanguageProfileReader(com.optimaize.langdetect.profiles.LanguageProfileReader)

Aggregations

Language (enums.Language)43 Matcher (java.util.regex.Matcher)27 ArrayList (java.util.ArrayList)19 IOException (java.io.IOException)13 Language (ai.elimu.model.v2.enums.Language)12 StoryBookParagraph (ai.elimu.model.content.StoryBookParagraph)10 Word (ai.elimu.model.content.Word)10 HashMap (java.util.HashMap)7 StoryBook (ai.elimu.model.content.StoryBook)6 StoryBookChapter (ai.elimu.model.content.StoryBookChapter)6 ChannelLanguage (data.ChannelLanguage)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Letter (ai.elimu.model.content.Letter)5 List (java.util.List)5 Image (ai.elimu.model.content.multimedia.Image)4 AbstractCommand (commands.model.AbstractCommand)4 Command (commands.model.Command)4 Guild (data.Guild)4 Scheduled (org.springframework.scheduling.annotation.Scheduled)4 Audio (ai.elimu.model.content.multimedia.Audio)3