Search in sources :

Example 1 with Embedded

use of data.Embedded in project KaellyBot by Kaysoro.

the class ResourceCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Matcher m = getMatcher(message);
        Language lg = Translator.getLanguageFrom(message.getChannel());
        m.find();
        String normalName = Normalizer.normalize(m.group(2).trim(), Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "").toLowerCase();
        BestMatcher matcher = new BestMatcher(normalName);
        try {
            for (TypeResource resource : TypeResource.values()) {
                String[] names = resource.getNames(lg);
                gatherData(message, matcher, names, normalName, resource, notFoundRsrc);
            }
            if (matcher.isEmpty())
                for (SuperTypeResource type : SuperTypeResource.values()) matcher.evaluateAll(getListRequestableFrom(getSearchURL(type.getUrl(lg), normalName, null, lg), message, notFoundRsrc));
            if (matcher.isUnique()) {
                // We have found it !
                Embedded resource = Resource.getResource(lg, Translator.getLabel(lg, "game.url") + matcher.getBest().getUrl());
                if (m.group(1) != null)
                    Message.sendEmbed(message.getChannel(), resource.getMoreEmbedObject(lg));
                else
                    Message.sendEmbed(message.getChannel(), resource.getEmbedObject(lg));
            } else if (// Too much items
            !matcher.isEmpty())
                tooMuchRsrcs.throwException(message, this, lg, matcher.getBests());
            else
                // empty
                notFoundRsrc.throwException(message, this, lg);
        } catch (IOException e) {
            ExceptionManager.manageIOException(e, message, this, lg, notFoundRsrc);
        }
        return true;
    }
    return false;
}
Also used : TypeResource(enums.TypeResource) SuperTypeResource(enums.SuperTypeResource) BestMatcher(util.BestMatcher) Language(enums.Language) BestMatcher(util.BestMatcher) Matcher(java.util.regex.Matcher) Embedded(data.Embedded) IOException(java.io.IOException) SuperTypeResource(enums.SuperTypeResource)

Example 2 with Embedded

use of data.Embedded 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)

Aggregations

Embedded (data.Embedded)2 Language (enums.Language)2 IOException (java.io.IOException)2 Matcher (java.util.regex.Matcher)2 SuperTypeEquipment (enums.SuperTypeEquipment)1 SuperTypeResource (enums.SuperTypeResource)1 TypeEquipment (enums.TypeEquipment)1 TypeResource (enums.TypeResource)1 BestMatcher (util.BestMatcher)1