Search in sources :

Example 26 with Language

use of enums.Language in project KaellyBot by Kaysoro.

the class RandomCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Language lg = Translator.getLanguageFrom(message.getChannel());
        Matcher m = getMatcher(message);
        m.find();
        if (m.group(1) == null) {
            boolean value = new Random().nextBoolean();
            Message.sendText(message.getChannel(), value ? Translator.getLabel(lg, "random.request.1") : Translator.getLabel(lg, "random.request.2") + " !");
        } else if (m.group(1).matches("\\s+-?\\d+")) {
            try {
                int limit = Integer.parseInt(m.group(1).trim());
                if (limit > 0)
                    Message.sendText(message.getChannel(), new Random().nextInt(limit) + " !");
                else
                    Message.sendText(message.getChannel(), Translator.getLabel(lg, "random.request.3"));
            } catch (NumberFormatException e) {
                Message.sendText(message.getChannel(), Translator.getLabel(lg, "random.request.4") + " " + Integer.MAX_VALUE + ").");
            }
        } else {
            String value = m.group(1).trim();
            String[] values = value.split("\\s+");
            Message.sendText(message.getChannel(), values[new Random().nextInt(values.length)] + " !");
        }
    }
    return false;
}
Also used : Language(enums.Language) Random(java.util.Random) Matcher(java.util.regex.Matcher)

Example 27 with Language

use of enums.Language in project KaellyBot by Kaysoro.

the class AdminCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        String prefixe = getPrefixMdEscaped(message);
        Language lg = Translator.getLanguageFrom(message.getChannel());
        Matcher m = getMatcher(message);
        m.find();
        StringBuilder st = new StringBuilder();
        boolean argumentFound = m.group(1) != null && m.group(1).replaceAll("^\\s+", "").length() > 0;
        for (Command command : CommandManager.getCommands()) if (command.isAdmin()) {
            if (!argumentFound)
                st.append(command.help(lg, prefixe)).append("\n");
            else if (command.getName().equals(m.group(1).trim())) {
                st.append(command.helpDetailed(lg, prefixe));
                break;
            }
        }
        if (argumentFound && st.length() == 0)
            notFound.throwException(message, this, lg);
        else
            Message.sendText(message.getChannel(), st.toString());
        return true;
    }
    return false;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) AbstractCommand(commands.model.AbstractCommand) Command(commands.model.Command)

Example 28 with Language

use of enums.Language in project KaellyBot by Kaysoro.

the class AvailableCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Matcher m = getMatcher(message);
        m.find();
        Language lg = Translator.getLanguageFrom(message.getChannel());
        List<Command> potentialCmds = new ArrayList<>();
        String commandName = m.group(1).trim();
        for (Command command : CommandManager.getCommands()) if (!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 AvailableCommand || command instanceof AboutCommand) {
                Message.sendText(message.getChannel(), Translator.getLabel(lg, "announce.request.1"));
                return false;
            }
            if (value.matches("false") || value.matches("1") || value.matches("off")) {
                if (command.isPublic()) {
                    command.setPublic(false);
                    Message.sendText(message.getChannel(), Translator.getLabel(lg, "announce.request.2") + " *" + commandName + "* " + Translator.getLabel(lg, "announce.request.3"));
                } else
                    forbiddenCmdFound.throwException(message, this, lg);
            } else if (value.matches("true") || value.matches("0") || value.matches("on")) {
                if (!command.isPublic()) {
                    command.setPublic(true);
                    Message.sendText(message.getChannel(), Translator.getLabel(lg, "announce.request.2") + "*" + commandName + "* " + Translator.getLabel(lg, "announce.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);
    }
    return false;
}
Also used : AboutCommand(commands.classic.AboutCommand) Language(enums.Language) Matcher(java.util.regex.Matcher) AbstractCommand(commands.model.AbstractCommand) AboutCommand(commands.classic.AboutCommand) Command(commands.model.Command) ArrayList(java.util.ArrayList)

Example 29 with Language

use of enums.Language in project KaellyBot by Kaysoro.

the class StatCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Matcher m = getMatcher(message);
        m.find();
        Language lg = Translator.getLanguageFrom(message.getChannel());
        int totalUser = 0;
        for (IGuild guild : ClientConfig.DISCORD().getGuilds()) totalUser += guild.getUsers().size();
        String answer = Translator.getLabel(lg, "stat.request").replace("{guilds.size}", String.valueOf(ClientConfig.DISCORD().getGuilds().size())).replace("{users.size}", String.valueOf(ClientConfig.DISCORD().getUsers().size())).replace("{users_max.size}", String.valueOf(totalUser));
        Message.sendText(message.getChannel(), answer);
    }
    return false;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) IGuild(sx.blah.discord.handle.obj.IGuild)

Example 30 with Language

use of 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)

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