Search in sources :

Example 6 with Language

use of 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[] {}));
    }
}
Also used : Language(enums.Language) TwitterListener(listeners.TwitterListener) FilterQuery(twitter4j.FilterQuery)

Example 7 with Language

use of 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;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) BadUseCommandDiscordException(exceptions.BadUseCommandDiscordException) DiscordException(exceptions.DiscordException) BasicDiscordException(exceptions.BasicDiscordException) BadUseCommandDiscordException(exceptions.BadUseCommandDiscordException)

Example 8 with Language

use of 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;
}
Also used : Language(enums.Language) Requestable(util.Requestable) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) IOException(java.io.IOException) DiscordException(exceptions.DiscordException)

Example 9 with Language

use of 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;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) Position(data.Position) Transport(enums.Transport)

Example 10 with Language

use of 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;
}
Also used : DofusGuild(data.DofusGuild) Matcher(java.util.regex.Matcher) ServerDofus(data.ServerDofus) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Language(enums.Language)

Aggregations

Language (enums.Language)43 Matcher (java.util.regex.Matcher)27 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)10 ChannelLanguage (data.ChannelLanguage)6 AbstractCommand (commands.model.AbstractCommand)4 Command (commands.model.Command)4 Guild (data.Guild)4 ServerDofus (data.ServerDofus)4 BasicDiscordException (exceptions.BasicDiscordException)3 DiscordException (exceptions.DiscordException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 SQLException (java.sql.SQLException)3 List (java.util.List)3 Document (org.jsoup.nodes.Document)3 Element (org.jsoup.nodes.Element)3 Elements (org.jsoup.select.Elements)3 Almanax (data.Almanax)2 Embedded (data.Embedded)2 BadUseCommandDiscordException (exceptions.BadUseCommandDiscordException)2