Search in sources :

Example 1 with AboutCommand

use of commands.classic.AboutCommand 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)

Aggregations

AboutCommand (commands.classic.AboutCommand)1 AbstractCommand (commands.model.AbstractCommand)1 Command (commands.model.Command)1 Language (enums.Language)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1