Search in sources :

Example 31 with Language

use of ai.elimu.model.v2.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 32 with Language

use of ai.elimu.model.v2.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 33 with Language

use of ai.elimu.model.v2.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 34 with Language

use of ai.elimu.model.v2.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 35 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)

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