use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.
the class TwitterFinder method start.
public static void start() {
if (ClientConfig.TWITTER() != null) {
ClientConfig.TWITTER().addListener(new TwitterListener());
long[] twitterIDs = new long[Language.values().length];
int i = 0;
for (Language lg : Language.values()) twitterIDs[i++] = Long.parseLong(Translator.getLabel(lg, "twitter.id"));
ClientConfig.TWITTER().filter(new FilterQuery(0, twitterIDs, new String[] {}));
}
}
use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.
the class AbstractCommand method request.
@Override
public boolean request(IMessage message) {
boolean isFound = false;
try {
Language lg = Translator.getLanguageFrom(message.getChannel());
Matcher m = getMatcher(message);
isFound = m.find();
// Caché si la fonction est désactivée/réservée aux admin et que l'auteur n'est pas super-admin
if ((!isPublic() || isAdmin()) && message.getAuthor().getLongID() != Constants.authorId)
return false;
// La commande est trouvée
if (isFound) {
// Mais n'est pas utilisable en MP
if (!isUsableInMP() && message.getChannel().isPrivate()) {
notUsableInMp.throwException(message, this, lg);
return false;
} else // Mais est désactivée par la guilde
if (!message.getChannel().isPrivate() && message.getAuthor().getLongID() != Constants.authorId && isForbidden(Guild.getGuild(message.getGuild()))) {
commandForbidden.throwException(message, this, lg);
return false;
}
} else // Mais est mal utilisée
if (message.getContent().startsWith(getPrefix(message) + getName()))
new BadUseCommandDiscordException().throwException(message, this, lg);
} catch (Exception e) {
Reporter.report(e, message.getGuild(), message.getChannel(), message.getAuthor(), message);
LOG.error("request", e);
}
return isFound;
}
use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.
the class DofusRequestCommand method getListRequestableFrom.
protected List<Requestable> getListRequestableFrom(String url, IMessage message, DiscordException notFound) {
List<Requestable> result = new ArrayList<>();
Language lg = Translator.getLanguageFrom(message.getChannel());
try {
Document doc = JSoupManager.getDocument(url);
Elements elems = doc.getElementsByClass("ak-bg-odd");
elems.addAll(doc.getElementsByClass("ak-bg-even"));
for (Element element : elems) result.add(new Requestable(element.child(1).text(), element.child(1).select("a").attr("href")));
} catch (IOException e) {
ExceptionManager.manageIOException(e, message, this, lg, notFound);
return new ArrayList<>();
} catch (Exception e) {
ExceptionManager.manageException(e, message, this, lg);
return new ArrayList<>();
}
return result;
}
use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.
the class DistanceCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
Matcher m = getMatcher(message);
m.find();
Language lg = Translator.getLanguageFrom(message.getChannel());
Position position = new Position(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)));
StringBuilder st = new StringBuilder();
Transport zaap = null;
Transport transportLimited = null;
if (!position.isNull()) {
double minDist = Double.MAX_VALUE;
double minDistLimited = Double.MAX_VALUE;
for (Transport transport : Transport.values()) {
double tmp = transport.getPosition().getDistance(position);
if (transport.isFreeAccess() && (zaap == null || minDist > tmp)) {
zaap = transport;
minDist = tmp;
}
if (!transport.isFreeAccess() && (transportLimited == null || minDistLimited > tmp)) {
transportLimited = transport;
minDistLimited = tmp;
}
}
st.append(Translator.getLabel(lg, "distance.request.1")).append(" ").append(zaap.toDiscordString(lg));
if (minDist > minDistLimited)
st.append("\n").append(Translator.getLabel(lg, "distance.request.2")).append(" ").append(transportLimited.toDiscordString(lg));
} else
st.append(Translator.getLabel(lg, "distance.request.3"));
Message.sendText(message.getChannel(), st.toString());
}
return false;
}
use of ai.elimu.model.v2.enums.Language 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;
}
Aggregations