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;
}
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 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;
}
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;
}
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;
}
Aggregations