use of enums.Language in project KaellyBot by Kaysoro.
the class TutorialCommand method getListTutoFrom.
private List<Requestable> getListTutoFrom(String url, IMessage message) {
List<Requestable> result = new ArrayList<>();
Language lg = Translator.getLanguageFrom(message.getChannel());
try {
Document doc = JSoupManager.getDocument(url);
Elements elems = doc.getElementById("wsite-search-list").getElementsByTag("a");
for (Element element : elems) result.add(new Requestable(element.child(0).text(), element.attr("href")));
} catch (IOException e) {
ExceptionManager.manageIOException(e, message, this, lg, notFoundTuto);
return new ArrayList<>();
} catch (Exception e) {
ExceptionManager.manageException(e, message, this, lg);
return new ArrayList<>();
}
return result;
}
use of enums.Language in project KaellyBot by Kaysoro.
the class TutorialCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
Matcher m = getMatcher(message);
m.find();
Language lg = Translator.getLanguageFrom(message.getChannel());
String normalName = Normalizer.normalize(m.group(1).trim(), Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "").toLowerCase();
String editedName = removeUselessWords(normalName);
BestMatcher matcher = new BestMatcher(normalName);
try {
matcher.evaluateAll(getListTutoFrom(getSearchURL(editedName), message));
if (// We have found it !
matcher.isUnique())
Message.sendText(message.getChannel(), Translator.getLabel(lg, "tutorial.request") + " " + Constants.dofusPourLesNoobURL + matcher.getBest().getUrl());
else if (// Too much tutos
!matcher.isEmpty())
tooMuchTutos.throwException(message, this, lg, matcher.getBests());
else
// empty
notFoundTuto.throwException(message, this, lg);
} catch (IOException e) {
ExceptionManager.manageIOException(e, message, this, lg, notFoundTuto);
}
return true;
}
return false;
}
use of enums.Language in project KaellyBot by Kaysoro.
the class CommandCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
Language lg = Translator.getLanguageFrom(message.getChannel());
if (isUserHasEnoughRights(message)) {
Guild guild = Guild.getGuild(message.getGuild());
Matcher m = getMatcher(message);
m.find();
List<Command> potentialCmds = new ArrayList<>();
String commandName = m.group(1).trim();
for (Command command : CommandManager.getCommands()) if (command.isPublic() && !command.isAdmin() && command.getName().contains(commandName))
potentialCmds.add(command);
if (potentialCmds.size() == 1) {
Command command = potentialCmds.get(0);
String value = m.group(2);
if (command instanceof CommandCommand) {
Message.sendText(message.getChannel(), Translator.getLabel(lg, "command.request.1"));
return false;
}
if (value.matches("false") || value.matches("1") || value.matches("off")) {
if (!guild.getForbiddenCommands().containsKey(command.getName())) {
new CommandForbidden(command, guild).addToDatabase();
Message.sendText(message.getChannel(), Translator.getLabel(lg, "command.request.2") + " *" + commandName + "* " + Translator.getLabel(lg, "command.request.3"));
} else
forbiddenCmdFound.throwException(message, this, lg);
} else if (value.matches("true") || value.matches("0") || value.matches("on")) {
if (guild.getForbiddenCommands().containsKey(command.getName())) {
guild.getForbiddenCommands().get(command.getName()).removeToDatabase();
Message.sendText(message.getChannel(), Translator.getLabel(lg, "command.request.2") + " *" + commandName + "* " + Translator.getLabel(lg, "command.request.4"));
} else
forbiddenCmdNotFound.throwException(message, this, lg);
} else
new BadUseCommandDiscordException().throwException(message, this, lg);
} else if (potentialCmds.isEmpty())
notFoundCmd.throwException(message, this, lg);
else
tooMuchCmds.throwException(message, this, lg);
} else
noEnoughRights.throwException(message, this, lg);
}
return false;
}
use of enums.Language in project KaellyBot by Kaysoro.
the class PrefixCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
Language lg = Translator.getLanguageFrom(message.getChannel());
if (isUserHasEnoughRights(message)) {
Matcher m = getMatcher(message);
m.find();
String newPrefix = m.group(1).trim();
if (newPrefix.length() >= 1 && newPrefix.length() <= Constants.prefixeLimit) {
Guild.getGuild(message.getGuild()).setPrefixe(newPrefix);
Message.sendText(message.getChannel(), Translator.getLabel(lg, "prefix.request.1").replace("{prefix}", getPrefixMdEscaped(message)));
try {
Message.sendText(message.getGuild().getOwner().getOrCreatePMChannel(), Translator.getLabel(lg, "prefix.request.2").replace("{prefix}", getPrefixMdEscaped(message)).replace("{guild.name}", message.getGuild().getName()));
} catch (DiscordException e) {
LOG.warn("request", "Impossible de contacter l'administrateur de la guilde [" + message.getGuild().getName() + "].");
}
return true;
} else
prefixeOutOfBounds.throwException(message, this, lg);
} else
noEnoughRights.throwException(message, this, lg);
}
return false;
}
use of 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;
}
Aggregations