Search in sources :

Example 51 with Language

use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.

the class TalkCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Language lg = Translator.getLanguageFrom(message.getChannel());
        Matcher m = getMatcher(message);
        m.find();
        String text = m.group(2).trim();
        if (m.group(1) != null) {
            long value = Long.parseLong(m.group(1).trim());
            lastChan = ClientConfig.DISCORD().getChannelByID(value);
        }
        if (lastChan == null) {
            notFoundChan.throwException(message, this, lg);
            return false;
        }
        if (lastChan.getModifiedPermissions(ClientConfig.DISCORD().getOurUser()).contains(Permissions.SEND_MESSAGES))
            Message.sendText(lastChan, text);
        else
            noSendTextPermission.throwException(message, this, lg);
        return true;
    }
    return false;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher)

Example 52 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 53 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 54 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 55 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)

Aggregations

Language (enums.Language)69 Matcher (java.util.regex.Matcher)43 ArrayList (java.util.ArrayList)29 AbstractCommand (commands.model.AbstractCommand)19 IOException (java.io.IOException)19 Translator (util.Translator)19 Message (discord4j.core.object.entity.Message)18 MessageCreateEvent (discord4j.core.event.domain.message.MessageCreateEvent)16 List (java.util.List)15 Language (ai.elimu.model.v2.enums.Language)12 Guild (data.Guild)12 StoryBookParagraph (ai.elimu.model.content.StoryBookParagraph)10 Word (ai.elimu.model.content.Word)10 ChannelLanguage (data.ChannelLanguage)10 Command (commands.model.Command)9 Snowflake (discord4j.common.util.Snowflake)8 BasicDiscordException (exceptions.BasicDiscordException)8 ServerDofus (data.ServerDofus)7 exceptions (exceptions)7 Document (org.jsoup.nodes.Document)7