Search in sources :

Example 21 with Language

use of enums.Language in project KaellyBot by Kaysoro.

the class RSSCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Language lg = Translator.getLanguageFrom(message.getChannel());
        // On check si la personne a bien les droits pour exécuter cette commande
        if (isUserHasEnoughRights(message)) {
            Matcher m = getMatcher(message);
            m.find();
            String value = m.group(1);
            if (value.matches("\\s+true") || value.matches("\\s+0") || value.matches("\\s+on")) {
                if (!RSSFinder.getRSSFinders().containsKey(message.getChannel().getStringID())) {
                    new RSSFinder(message.getGuild().getStringID(), message.getChannel().getStringID()).addToDatabase();
                    Message.sendText(message.getChannel(), Translator.getLabel(lg, "rss.request.1").replace("{game.url}", Translator.getLabel(lg, "game.url")));
                } else
                    rssFound.throwException(message, this, lg);
            } else if (value.matches("\\s+false") || value.matches("\\s+1") || value.matches("\\s+off"))
                if (RSSFinder.getRSSFinders().containsKey(message.getChannel().getStringID())) {
                    RSSFinder.getRSSFinders().get(message.getChannel().getStringID()).removeToDatabase();
                    Message.sendText(message.getChannel(), Translator.getLabel(lg, "rss.request.2").replace("{game.url}", Translator.getLabel(lg, "game.url")));
                } else
                    rssNotFound.throwException(message, this, lg);
            else
                new BadUseCommandDiscordException().throwException(message, this, lg);
        } else
            noEnoughRights.throwException(message, this, lg);
    }
    return false;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) RSSFinder(finders.RSSFinder)

Example 22 with Language

use of enums.Language in project KaellyBot by Kaysoro.

the class TwitterCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Language lg = Translator.getLanguageFrom(message.getChannel());
        // On check si la personne a bien les droits pour exécuter cette commande
        if (isUserHasEnoughRights(message)) {
            Matcher m = getMatcher(message);
            m.find();
            String value = m.group(1);
            if (value.matches("\\s+true") || value.matches("\\s+0") || value.matches("\\s+on")) {
                if (!TwitterFinder.getTwitterChannels().containsKey(message.getChannel().getLongID())) {
                    new TwitterFinder(message.getGuild().getLongID(), message.getChannel().getLongID()).addToDatabase();
                    Message.sendText(message.getChannel(), Translator.getLabel(lg, "twitter.request.1").replace("{twitter.name}", Translator.getLabel(lg, "twitter.name")));
                } else
                    twitterFound.throwException(message, this, lg);
            } else if (value.matches("\\s+false") || value.matches("\\s+1") || value.matches("\\s+off")) {
                if (TwitterFinder.getTwitterChannels().containsKey(message.getChannel().getLongID())) {
                    TwitterFinder.getTwitterChannels().get(message.getChannel().getLongID()).removeToDatabase();
                    Message.sendText(message.getChannel(), Translator.getLabel(lg, "twitter.request.2").replace("{twitter.name}", Translator.getLabel(lg, "twitter.name")));
                } else
                    twitterNotFound.throwException(message, this, lg);
            } else
                new BadUseCommandDiscordException().throwException(message, this, lg);
        } else
            noEnoughRights.throwException(message, this, lg);
    }
    return false;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) TwitterFinder(finders.TwitterFinder)

Example 23 with Language

use of enums.Language in project KaellyBot by Kaysoro.

the class HelpCommand 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.isPublic() && !command.isAdmin() && (message.getChannel().isPrivate() || !command.isForbidden(Guild.getGuild(message.getGuild())))) {
            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)
            notFoundCmd.throwException(message, this, lg);
        else
            Message.sendText(message.getChannel(), st.toString());
    }
    return false;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) AbstractCommand(commands.model.AbstractCommand) Command(commands.model.Command)

Example 24 with Language

use of enums.Language in project KaellyBot by Kaysoro.

the class ItemCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Matcher m = getMatcher(message);
        Language lg = Translator.getLanguageFrom(message.getChannel());
        m.find();
        if (message.getChannel().getModifiedPermissions(ClientConfig.DISCORD().getOurUser()).contains(Permissions.USE_EXTERNAL_EMOJIS) && ClientConfig.DISCORD().getOurUser().getPermissionsForGuild(message.getGuild()).contains(Permissions.USE_EXTERNAL_EMOJIS)) {
            String normalName = Normalizer.normalize(m.group(2).trim(), Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "").toLowerCase();
            BestMatcher matcher = new BestMatcher(normalName);
            try {
                for (TypeEquipment equip : TypeEquipment.values()) {
                    String[] names = equip.getNames(lg);
                    gatherData(message, matcher, names, normalName, equip, notFoundItem);
                }
                if (matcher.isEmpty())
                    for (SuperTypeEquipment type : SuperTypeEquipment.values()) matcher.evaluateAll(getListRequestableFrom(getSearchURL(type.getUrl(lg), normalName, null, lg), message, notFoundItem));
                if (matcher.isUnique()) {
                    // We have found it !
                    Embedded item = Item.getItem(lg, Translator.getLabel(lg, "game.url") + matcher.getBest().getUrl());
                    if (m.group(1) != null)
                        Message.sendEmbed(message.getChannel(), item.getMoreEmbedObject(lg));
                    else
                        Message.sendEmbed(message.getChannel(), item.getEmbedObject(lg));
                } else if (// Too much items
                !matcher.isEmpty())
                    tooMuchItems.throwException(message, this, lg, matcher.getBests());
                else
                    // empty
                    notFoundItem.throwException(message, this, lg);
            } catch (IOException e) {
                ExceptionManager.manageIOException(e, message, this, lg, notFoundItem);
            }
            return true;
        } else
            noExternalEmojiPermission.throwException(message, this, lg);
    }
    return false;
}
Also used : SuperTypeEquipment(enums.SuperTypeEquipment) SuperTypeEquipment(enums.SuperTypeEquipment) TypeEquipment(enums.TypeEquipment) Language(enums.Language) Matcher(java.util.regex.Matcher) Embedded(data.Embedded) IOException(java.io.IOException)

Example 25 with Language

use of 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)

Aggregations

Language (enums.Language)43 Matcher (java.util.regex.Matcher)27 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)10 ChannelLanguage (data.ChannelLanguage)6 AbstractCommand (commands.model.AbstractCommand)4 Command (commands.model.Command)4 Guild (data.Guild)4 ServerDofus (data.ServerDofus)4 BasicDiscordException (exceptions.BasicDiscordException)3 DiscordException (exceptions.DiscordException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 SQLException (java.sql.SQLException)3 List (java.util.List)3 Document (org.jsoup.nodes.Document)3 Element (org.jsoup.nodes.Element)3 Elements (org.jsoup.select.Elements)3 Almanax (data.Almanax)2 Embedded (data.Embedded)2 BadUseCommandDiscordException (exceptions.BadUseCommandDiscordException)2