use of data.ServerDofus in project KaellyBot by Kaysoro.
the class AlignmentCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
Language lg = Translator.getLanguageFrom(message.getChannel());
Matcher m = getMatcher(message);
m.matches();
String content = m.group(1).trim();
// Initialisation du Filtre
City city;
Order order;
IUser user = message.getAuthor();
ServerDofus server = Guild.getGuild(message.getGuild()).getServerDofus();
List<ServerDofus> servers;
// Consultation filtré par niveau
if ((m = Pattern.compile(">\\s+(\\d{1,3})(\\s+.+)?").matcher(content)).matches()) {
Message.sendText(message.getChannel(), "Consultation filtré par niveau");
// TODO
} else {
// L'utilisateur concerné est-il l'auteur de la commande ?
if (Pattern.compile("^<@[!|&]?\\d+>").matcher(content).find()) {
content = content.replaceFirst("<@[!|&]?\\d+>", "").trim();
user = message.getMentions().get(0);
}
// Consultation des données filtrés par utilisateur
if (!(servers = findServer(content)).isEmpty() && (m = Pattern.compile("(.+)").matcher(content)).matches() || content.isEmpty()) {
Message.sendText(message.getChannel(), "Consultation des données utilisateur");
// TODO
} else // Enregistrement des données
if ((m = Pattern.compile("(\\p{L}+)\\s+(\\p{L}+)\\s+(\\d{1,3})(\\s+.+)?").matcher(content)).matches()) {
if (user == message.getAuthor() || user != message.getAuthor() && isUserHasEnoughRights(message)) {
// Parsing des données et traitement des divers exceptions
List<City> cities = findCity(m.group(1), lg);
if (!checkData(cities, tooMuchCities, notFoundCity, message, lg))
return false;
city = cities.get(0);
List<Order> orders = findOrder(m.group(2), lg);
if (!checkData(orders, tooMuchOrders, notFoundOrder, message, lg))
return false;
order = orders.get(0);
int level = Integer.parseInt(m.group(3));
if (m.group(4) != null) {
servers = findServer(m.group(4));
if (!checkData(servers, tooMuchServers, notFoundServer, message, lg))
return false;
server = servers.get(0);
} else if (server == null) {
notFoundGuildServer.throwException(message, this, lg);
return false;
}
if (OrderUser.getOrders().containsKey(Quadruple.of(user.getLongID(), server, city, order)))
OrderUser.getOrders().get(Quadruple.of(user.getLongID(), server, city, order)).setLevel(level);
else
new OrderUser(user.getLongID(), server, city, order, level).addToDatabase();
if (level != 0)
Message.sendText(message.getChannel(), "align.save");
else
Message.sendText(message.getChannel(), "align.reset");
} else
noEnoughRights.throwException(message, this, lg);
} else // Consultation filtré par cité et/ou par ordre
if ((m = Pattern.compile("(\\p{L}+)(\\s+\\p{L}+)?(\\s+[\\p{L}|\\W]+)?").matcher(content)).matches()) {
Message.sendText(message.getChannel(), "Consultation filtré par cité et/ou par ordre");
// TODO
} else
badUse.throwException(message, this, lg);
}
}
return false;
}
use of data.ServerDofus in project KaellyBot by Kaysoro.
the class PortalFinder method start.
public static void start() {
if (!isStarted) {
isStarted = true;
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(() -> {
try {
for (Guild guild : Guild.getGuilds().values()) if (guild.getServerDofus() != null) {
// Server renseigné ?
ServerDofus server = guild.getServerDofus();
// Si les positions ne sont plus d'actualités, on les met à jour
if (System.currentTimeMillis() - server.getLastSweetRefresh() > DELTA)
server.setSweetPortals(Portal.getSweetPortals(server));
guild.mergePortals(server.getSweetPortals());
}
} catch (IOException e) {
ExceptionManager.manageSilentlyIOException(e);
} catch (Exception e) {
ExceptionManager.manageSilentlyException(e);
}
}, 0, 20, TimeUnit.MINUTES);
}
}
use of data.ServerDofus in project KaellyBot by Kaysoro.
the class GuildCommand 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 pseudo = m.group(1).trim().toLowerCase();
StringBuilder url;
try {
url = new StringBuilder(Translator.getLabel(lg, "game.url")).append(Translator.getLabel(lg, "guild.url")).append("?").append(forPseudo).append(URLEncoder.encode(pseudo, "UTF-8"));
} catch (UnsupportedEncodingException e) {
ExceptionManager.manageException(e, message, this, lg);
return false;
}
if (m.group(2) != null) {
String serverName = m.group(2).trim().toLowerCase();
List<ServerDofus> result = new ArrayList<>();
for (ServerDofus server : ServerDofus.getServersDofus()) if (server.getName().toLowerCase().startsWith(serverName))
result.add(server);
if (result.size() == 1)
url.append("&").append(forServer).append(result.get(0).getId());
else {
if (!result.isEmpty())
tooMuchServers.throwException(message, this, lg);
else
notFoundServer.throwException(message, this, lg);
return false;
}
}
try {
Document doc = JSoupManager.getDocument(url.toString());
Elements elems = doc.getElementsByClass("ak-bg-odd");
elems.addAll(doc.getElementsByClass("ak-bg-even"));
if (!elems.isEmpty()) {
// on boucle jusqu'à temps de trouver la bonne guilde (ie la plus proche du nom donnée)
List<String> result = new ArrayList<>();
List<String> servers = new ArrayList<>();
for (Element element : elems) if (pseudo.equals(element.child(1).text().trim().toLowerCase())) {
result.add(element.child(1).select("a").attr("href"));
servers.add(element.child(3).text());
}
if (result.size() == 1) {
DofusGuild guildPage = DofusGuild.getDofusGuild(Translator.getLabel(lg, "game.url") + result.get(0), lg);
Message.sendEmbed(message.getChannel(), guildPage.getEmbedObject(lg));
} else if (result.size() > 1)
tooMuchGuilds.throwException(message, this, lg, servers);
else
notFoundGuild.throwException(message, this, lg);
} else
notFoundGuild.throwException(message, this, lg);
} catch (IOException e) {
ExceptionManager.manageIOException(e, message, this, lg, guildPageInaccessible);
} catch (Exception e) {
ExceptionManager.manageException(e, message, this, lg);
}
}
return false;
}
use of data.ServerDofus in project KaellyBot by Kaysoro.
the class WhoisCommand 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 pseudo = m.group(1).trim().toLowerCase();
StringBuilder url;
try {
url = new StringBuilder(Translator.getLabel(lg, "game.url")).append(Translator.getLabel(lg, "character.url")).append("?").append(forPseudo).append(URLEncoder.encode(pseudo, "UTF-8"));
} catch (UnsupportedEncodingException e) {
ExceptionManager.manageException(e, message, this, lg);
return false;
}
if (m.group(2) != null) {
String serverName = m.group(2).trim().toLowerCase();
List<ServerDofus> result = new ArrayList<>();
for (ServerDofus server : ServerDofus.getServersDofus()) if (server.getName().toLowerCase().startsWith(serverName))
result.add(server);
if (result.size() == 1)
url.append("&").append(forServer).append(result.get(0).getId());
else {
if (!result.isEmpty())
tooMuchServers.throwException(message, this, lg);
else
notFoundServer.throwException(message, this, lg);
return false;
}
}
try {
Document doc = JSoupManager.getDocument(url.toString());
Elements elems = doc.getElementsByClass("ak-bg-odd");
elems.addAll(doc.getElementsByClass("ak-bg-even"));
if (!elems.isEmpty()) {
// on boucle jusqu'à temps de trouver le bon personnage (ie le plus proche du nom donnée)
List<String> result = new ArrayList<>();
List<String> servers = new ArrayList<>();
for (Element element : elems) if (pseudo.equals(element.child(1).text().trim().toLowerCase())) {
result.add(element.child(1).select("a").attr("href"));
servers.add(element.child(element.children().size() - 2).text());
}
if (result.size() == 1) {
Connection.Response response = JSoupManager.getResponse(Translator.getLabel(lg, "game.url") + result.get(0));
if (!response.url().getPath().endsWith(Translator.getLabel(lg, "whois.request"))) {
Character characPage = Character.getCharacter(Translator.getLabel(lg, "game.url") + result.get(0), lg);
Message.sendEmbed(message.getChannel(), characPage.getEmbedObject(lg));
} else
characterTooOld.throwException(message, this, lg);
} else if (result.size() > 1)
tooMuchCharacters.throwException(message, this, lg, servers);
else
notFoundCharacter.throwException(message, this, lg);
} else
notFoundCharacter.throwException(message, this, lg);
} catch (IOException e) {
ExceptionManager.manageIOException(e, message, this, lg, characterPageInaccessible);
} catch (Exception e) {
ExceptionManager.manageException(e, message, this, lg);
}
}
return false;
}
use of data.ServerDofus 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