Search in sources :

Example 36 with Language

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

Example 37 with Language

use of ai.elimu.model.v2.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;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) IOException(java.io.IOException)

Example 38 with Language

use of ai.elimu.model.v2.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;
}
Also used : CommandForbidden(data.CommandForbidden) Language(enums.Language) Matcher(java.util.regex.Matcher) AbstractCommand(commands.model.AbstractCommand) Command(commands.model.Command) ArrayList(java.util.ArrayList) Guild(data.Guild)

Example 39 with Language

use of ai.elimu.model.v2.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;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) AdvancedDiscordException(exceptions.AdvancedDiscordException) BasicDiscordException(exceptions.BasicDiscordException) DiscordException(sx.blah.discord.util.DiscordException)

Example 40 with Language

use of ai.elimu.model.v2.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;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) ServerDofus(data.ServerDofus) ArrayList(java.util.ArrayList) List(java.util.List) Guild(data.Guild)

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