Search in sources :

Example 6 with Language

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

Example 7 with Language

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

Example 10 with Language

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;
}
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 ArrayList (java.util.ArrayList)19 IOException (java.io.IOException)13 Language (ai.elimu.model.v2.enums.Language)12 StoryBookParagraph (ai.elimu.model.content.StoryBookParagraph)10 Word (ai.elimu.model.content.Word)10 HashMap (java.util.HashMap)7 StoryBook (ai.elimu.model.content.StoryBook)6 StoryBookChapter (ai.elimu.model.content.StoryBookChapter)6 ChannelLanguage (data.ChannelLanguage)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Letter (ai.elimu.model.content.Letter)5 List (java.util.List)5 Image (ai.elimu.model.content.multimedia.Image)4 AbstractCommand (commands.model.AbstractCommand)4 Command (commands.model.Command)4 Guild (data.Guild)4 Scheduled (org.springframework.scheduling.annotation.Scheduled)4 Audio (ai.elimu.model.content.multimedia.Audio)3