Search in sources :

Example 1 with BadUseCommandDiscordException

use of exceptions.BadUseCommandDiscordException in project KaellyBot by Kaysoro.

the class AbstractCommand method request.

@Override
public boolean request(IMessage message) {
    boolean isFound = false;
    try {
        Language lg = Translator.getLanguageFrom(message.getChannel());
        Matcher m = getMatcher(message);
        isFound = m.find();
        // Caché si la fonction est désactivée/réservée aux admin et que l'auteur n'est pas super-admin
        if ((!isPublic() || isAdmin()) && message.getAuthor().getLongID() != Constants.authorId)
            return false;
        // La commande est trouvée
        if (isFound) {
            // Mais n'est pas utilisable en MP
            if (!isUsableInMP() && message.getChannel().isPrivate()) {
                notUsableInMp.throwException(message, this, lg);
                return false;
            } else // Mais est désactivée par la guilde
            if (!message.getChannel().isPrivate() && message.getAuthor().getLongID() != Constants.authorId && isForbidden(Guild.getGuild(message.getGuild()))) {
                commandForbidden.throwException(message, this, lg);
                return false;
            }
        } else // Mais est mal utilisée
        if (message.getContent().startsWith(getPrefix(message) + getName()))
            new BadUseCommandDiscordException().throwException(message, this, lg);
    } catch (Exception e) {
        Reporter.report(e, message.getGuild(), message.getChannel(), message.getAuthor(), message);
        LOG.error("request", e);
    }
    return isFound;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) BadUseCommandDiscordException(exceptions.BadUseCommandDiscordException) DiscordException(exceptions.DiscordException) BasicDiscordException(exceptions.BasicDiscordException) BadUseCommandDiscordException(exceptions.BadUseCommandDiscordException)

Example 2 with BadUseCommandDiscordException

use of exceptions.BadUseCommandDiscordException 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)

Aggregations

Language (enums.Language)2 BadUseCommandDiscordException (exceptions.BadUseCommandDiscordException)2 Matcher (java.util.regex.Matcher)2 BasicDiscordException (exceptions.BasicDiscordException)1 DiscordException (exceptions.DiscordException)1 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)1