Search in sources :

Example 56 with Language

use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.

the class ServerCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Guild guild = Guild.getGuild(message.getGuild());
        Language lg = Translator.getLanguageFrom(message.getChannel());
        Matcher m = getMatcher(message);
        m.find();
        if (m.group(1) != null)
            if (isUserHasEnoughRights(message)) {
                String serverName = m.group(1).toLowerCase().trim();
                if (!serverName.equals("-reset")) {
                    serverName = Normalizer.normalize(serverName, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "").replaceAll("\\W+", "").trim();
                    List<ServerDofus> result = new ArrayList<>();
                    for (ServerDofus server : ServerDofus.getServersDofus()) if (Normalizer.normalize(server.getName(), Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "").replaceAll("\\W+", "").toLowerCase().trim().startsWith(serverName))
                        result.add(server);
                    if (result.size() == 1) {
                        if (guild.getServerDofus() != null && guild.getServerDofus() != result.get(0))
                            guild.resetPortals();
                        guild.setServer(result.get(0));
                        guild.mergePortals(result.get(0).getSweetPortals());
                        Message.sendText(message.getChannel(), Translator.getLabel(lg, "server.request.1").replace("{game}", Constants.game) + " " + guild.getName() + " " + Translator.getLabel(lg, "server.request.2") + " " + result.get(0).getName() + ".");
                    } else if (result.isEmpty())
                        notFoundServer.throwException(message, this, lg);
                    else
                        tooMuchServers.throwException(message, this, lg, result);
                } else {
                    guild.setServer(null);
                    Message.sendText(message.getChannel(), guild.getName() + " " + Translator.getLabel(lg, "server.request.3").replace("{game}", Constants.game));
                }
            } else
                noEnoughRights.throwException(message, this, lg);
        else {
            if (guild.getServerDofus() != null)
                Message.sendText(message.getChannel(), guild.getName() + " " + Translator.getLabel(lg, "server.request.4") + " " + guild.getServerDofus().getName() + ".");
            else
                Message.sendText(message.getChannel(), guild.getName() + " " + Translator.getLabel(lg, "server.request.5").replace("{game}", Constants.game));
        }
    }
    return false;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) ServerDofus(data.ServerDofus) ArrayList(java.util.ArrayList) List(java.util.List) Guild(data.Guild)

Example 57 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 58 with Language

use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.

the class Translator method detectLanguage.

public static Language detectLanguage(IChannel channel) {
    Language result = Constants.defaultLanguage;
    Map<Language, Integer> languages = new HashMap<>();
    for (Language lang : Language.values()) languages.put(lang, 0);
    languages.put(null, 0);
    List<String> sources = getReformatedMessages(channel);
    for (String source : sources) {
        Language lg = getLanguageFrom(source);
        languages.put(lg, languages.get(lg) + 1);
    }
    Map.Entry<Language, Integer> better = null;
    for (Map.Entry<Language, Integer> chosenLanguage : languages.entrySet()) {
        if (better == null)
            better = chosenLanguage;
        if (better.getValue() < chosenLanguage.getValue())
            better = chosenLanguage;
    }
    try {
        if (better.getKey() != null)
            return better.getKey();
    } catch (NullPointerException e) {
        LoggerFactory.getLogger(Translator.class).warn("Translator.detectLanguage", e);
    }
    return result;
}
Also used : Language(enums.Language) ChannelLanguage(data.ChannelLanguage) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 59 with Language

use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.

the class Translator method getLanguageFrom.

public static Language getLanguageFrom(IChannel channel) {
    Language result = Constants.defaultLanguage;
    if (!channel.isPrivate()) {
        Guild guild = Guild.getGuild(channel.getGuild());
        result = guild.getLanguage();
        ChannelLanguage channelLanguage = ChannelLanguage.getChannelLanguages().get(channel.getLongID());
        if (channelLanguage != null)
            result = channelLanguage.getLang();
    }
    return result;
}
Also used : ChannelLanguage(data.ChannelLanguage) Language(enums.Language) ChannelLanguage(data.ChannelLanguage) Guild(data.Guild)

Example 60 with Language

use of ai.elimu.model.v2.enums.Language in project webapp by elimu-ai.

the class DomainHelper method getBaseUrl.

public static String getBaseUrl() {
    // Read property set on the command line:
    // mvn clean verify -P regression-testing-rest -D base.url=http://eng.test.elimu.ai
    String baseUrlSystemProperty = System.getProperty("base.url");
    logger.info("baseUrlSystemProperty: \"" + baseUrlSystemProperty + "\"");
    String baseUrl = baseUrlSystemProperty;
    if (StringUtils.isBlank(baseUrl)) {
        // Read property set in the "config.properties" file
        // This will trigger if no "base.url" property is set on the command line
        InputStream inputStream = DomainHelper.class.getClassLoader().getResourceAsStream("config.properties");
        Properties properties = new Properties();
        try {
            properties.load(inputStream);
            String contentLanguageProperty = properties.getProperty("content.language");
            logger.info("contentLanguageProperty: \"" + contentLanguageProperty + "\"");
            Language language = Language.valueOf(contentLanguageProperty);
            baseUrl = "http://" + language.toString().toLowerCase() + ".test.elimu.ai";
        } catch (IOException ex) {
            logger.error(ex);
        }
    }
    logger.info("baseUrl: \"" + baseUrl + "\"");
    return baseUrl;
}
Also used : Language(ai.elimu.model.v2.enums.Language) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties)

Aggregations

Language (enums.Language)69 Matcher (java.util.regex.Matcher)43 ArrayList (java.util.ArrayList)29 AbstractCommand (commands.model.AbstractCommand)19 IOException (java.io.IOException)19 Translator (util.Translator)19 Message (discord4j.core.object.entity.Message)18 MessageCreateEvent (discord4j.core.event.domain.message.MessageCreateEvent)16 List (java.util.List)15 Language (ai.elimu.model.v2.enums.Language)12 Guild (data.Guild)12 StoryBookParagraph (ai.elimu.model.content.StoryBookParagraph)10 Word (ai.elimu.model.content.Word)10 ChannelLanguage (data.ChannelLanguage)10 Command (commands.model.Command)9 Snowflake (discord4j.common.util.Snowflake)8 BasicDiscordException (exceptions.BasicDiscordException)8 ServerDofus (data.ServerDofus)7 exceptions (exceptions)7 Document (org.jsoup.nodes.Document)7