Search in sources :

Example 46 with Language

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

the class MapCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Language lg = Translator.getLanguageFrom(message.getChannel());
        List<String> classicMaps = new ArrayList<>();
        for (int i = 1; i < 18; i++) classicMaps.add(String.valueOf(i));
        List<String> maps = new ArrayList<>();
        Matcher m = getMatcher(message);
        m.find();
        if (m.group(1) == null && m.group(2) == null)
            maps.addAll(classicMaps);
        else if (m.group(2) != null) {
            String[] text = m.group(2).trim().toUpperCase().split("\\s+");
            for (String value : text) {
                value = getNumberValue(value);
                if (value != null)
                    maps.add(value);
            }
        } else {
            new BadUseCommandDiscordException().throwException(message, this, lg);
            return false;
        }
        if (m.group(1) == null && maps.isEmpty()) {
            new BadUseCommandDiscordException().throwException(message, this, lg);
            return false;
        } else if (m.group(1) != null) {
            classicMaps.removeAll(maps);
            maps = classicMaps;
        }
        String number = maps.get(new Random().nextInt(maps.size()));
        String url = Constants.turnamentMapImg.replace("{number}", number);
        String[] punchlines = Translator.getLabel(lg, "map.punchline").split(";");
        String punchline = punchlines[new Random().nextInt(punchlines.length)];
        EmbedBuilder builder = new EmbedBuilder();
        builder.withTitle(Translator.getLabel(lg, "map.embed.title") + " " + numberToRoman(number));
        builder.withDescription(punchline);
        builder.withImage(url);
        builder.withColor(new Random().nextInt(16777216));
        builder.withImage(url);
        Message.sendEmbed(message.getChannel(), builder.build());
    }
    return false;
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) Language(enums.Language) Matcher(java.util.regex.Matcher) BadUseCommandDiscordException(exceptions.BadUseCommandDiscordException)

Example 47 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 48 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 49 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 50 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)

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