Search in sources :

Example 1 with BestMatcher

use of util.BestMatcher 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)

Aggregations

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