Search in sources :

Example 1 with Dungeon

use of enums.Dungeon in project KaellyBot by Kaysoro.

the class RandomCommand method request.

@Override
public void request(MessageCreateEvent event, Message message, Matcher m, Language lg) {
    Random r = new Random();
    Matcher tmp;
    if (m.group(1) == null || m.group(1).trim().isEmpty()) {
        boolean value = r.nextBoolean();
        message.getChannel().flatMap(chan -> chan.createMessage(value ? Translator.getLabel(lg, "random.request.1") : Translator.getLabel(lg, "random.request.2") + " !")).subscribe();
    } else if (m.group(1).matches("\\s+-?\\d+")) {
        try {
            int limit = Integer.parseInt(m.group(1).trim());
            if (limit > 0)
                message.getChannel().flatMap(chan -> chan.createMessage(r.nextInt(limit) + " !")).subscribe();
            else
                message.getChannel().flatMap(chan -> chan.createMessage(Translator.getLabel(lg, "random.request.3"))).subscribe();
        } catch (NumberFormatException e) {
            message.getChannel().flatMap(chan -> chan.createMessage(Translator.getLabel(lg, "random.request.4") + " " + Integer.MAX_VALUE + ").")).subscribe();
        }
    } else if ((tmp = Pattern.compile("\\s+-dj(\\s+\\d{1,3})?(\\s+\\d{1,3})?").matcher(m.group(1))).matches()) {
        int level = DEFAULT_LEVEL;
        int tolerance = DEFAULT_TOLERANCE;
        if (tmp.group(1) != null) {
            level = Integer.parseInt(tmp.group(1).trim());
            level = level - level % 10;
            if (level > DEFAULT_LEVEL)
                level = DEFAULT_LEVEL;
            if (level < MIN_LEVEL)
                level = MIN_LEVEL;
        }
        if (tmp.group(2) != null)
            tolerance = Integer.parseInt(tmp.group(2).trim());
        else if (tmp.group(1) == null)
            tolerance = MAX_TOLERANCE;
        final int finalLevel = level;
        final int finalTolerance = tolerance;
        List<Dungeon> djs = Arrays.stream(Dungeon.values()).filter(dj -> dj.filterByLevel(finalLevel, finalTolerance)).collect(Collectors.toList());
        Dungeon selected = djs.get(r.nextInt(djs.size()));
        if (selected.isEvent() && djs.size() > 1) {
            Dungeon selected2 = selected;
            while (selected == selected2 || selected2.isEvent()) selected2 = djs.get(r.nextInt(djs.size()));
            final Dungeon SELECTED2 = selected2;
            message.getChannel().flatMap(chan -> chan.createMessage(Translator.getLabel(lg, "random.request.6").replace("{dj}", selected.getLabel(lg)).replace("{dj2}", SELECTED2.getLabel(lg)).replace("{size}", String.valueOf(djs.size())))).subscribe();
        } else
            message.getChannel().flatMap(chan -> chan.createMessage(Translator.getLabel(lg, "random.request.5").replace("{dj}", selected.getLabel(lg)).replace("{size}", String.valueOf(djs.size())))).subscribe();
    } else if (m.group(1).matches("\\s+-dj(\\s+\\d+)?(\\s+\\d+)?"))
        badUse.throwException(message, this, lg);
    else {
        String value = m.group(1).trim();
        String[] values = value.split("\\s+");
        message.getChannel().flatMap(chan -> chan.createMessage(values[r.nextInt(values.length)] + " !")).subscribe();
    }
}
Also used : Language(enums.Language) MessageCreateEvent(discord4j.core.event.domain.message.MessageCreateEvent) Arrays(java.util.Arrays) List(java.util.List) AbstractCommand(commands.model.AbstractCommand) Matcher(java.util.regex.Matcher) Message(discord4j.core.object.entity.Message) Random(java.util.Random) Translator(util.Translator) Pattern(java.util.regex.Pattern) Dungeon(enums.Dungeon) Collectors(java.util.stream.Collectors) Random(java.util.Random) Matcher(java.util.regex.Matcher) Dungeon(enums.Dungeon)

Aggregations

AbstractCommand (commands.model.AbstractCommand)1 MessageCreateEvent (discord4j.core.event.domain.message.MessageCreateEvent)1 Message (discord4j.core.object.entity.Message)1 Dungeon (enums.Dungeon)1 Language (enums.Language)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Random (java.util.Random)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Translator (util.Translator)1