Search in sources :

Example 11 with Language

use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.

the class JobCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Language lg = Translator.getLanguageFrom(message.getChannel());
        Matcher m = getMatcher(message);
        m.find();
        // TODO
        new BasicDiscordException("exception.basic.in_developpment");
    }
    return false;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) BasicDiscordException(exceptions.BasicDiscordException)

Example 12 with Language

use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.

the class MonsterCommand 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();
            String editedName = removeUselessWords(normalName);
            BestMatcher matcher = new BestMatcher(normalName);
            try {
                matcher.evaluateAll(getListRequestableFrom(getSearchURL(lg, editedName), message, notFoundMonster));
                if (matcher.isUnique()) {
                    // We have found it !
                    Embedded monster = Monster.getMonster(lg, Translator.getLabel(lg, "game.url") + matcher.getBest().getUrl());
                    if (m.group(1) != null)
                        Message.sendEmbed(message.getChannel(), monster.getMoreEmbedObject(lg));
                    else
                        Message.sendEmbed(message.getChannel(), monster.getEmbedObject(lg));
                } else if (// Too much monsters
                !matcher.isEmpty())
                    tooMuchMonsters.throwException(message, this, lg, matcher.getBests());
                else
                    // empty
                    notFoundMonster.throwException(message, this, lg);
            } catch (IOException e) {
                ExceptionManager.manageIOException(e, message, this, lg, notFoundMonster);
            }
            return true;
        } else
            noExternalEmojiPermission.throwException(message, this, lg);
    }
    return false;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) IOException(java.io.IOException)

Example 13 with Language

use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.

the class PortalCommand 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 (m.group(1) == null && m.group(5) == null) {
            // No dimension precised
            for (Portal pos : Guild.getGuild(message.getGuild()).getPortals()) Message.sendEmbed(message.getChannel(), pos.getEmbedObject(lg));
        } else {
            List<Portal> portals = new ArrayList<>();
            if (m.group(1) != null)
                portals = getPortal(m.group(1), Guild.getGuild(message.getGuild()));
            if (portals.size() == 1) {
                if (m.group(2) != null)
                    portals.get(0).setCoordonate(Position.parse("[" + m.group(3) + "," + m.group(4) + "]"), message.getAuthor().getDisplayName(message.getGuild()));
                if (m.group(5) != null)
                    portals.get(0).setUtilisation(Integer.parseInt(m.group(5).replaceAll("\\s", "")), message.getAuthor().getDisplayName(message.getGuild()));
                Message.sendEmbed(message.getChannel(), portals.get(0).getEmbedObject(lg));
            } else if (portals.size() > 1)
                tooMuchPortals.throwException(message, this, lg);
            else
                notFoundPortal.throwException(message, this, lg);
        }
    }
    return false;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Portal(data.Portal)

Example 14 with Language

use of ai.elimu.model.v2.enums.Language 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 15 with Language

use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.

the class Message method sendText.

public static void sendText(IChannel channel, String content) {
    Language lg = Translator.getLanguageFrom(channel);
    RequestBuffer.request(() -> {
        try {
            new MessageBuilder(ClientConfig.DISCORD()).withChannel(channel).withContent(content).build();
        } catch (RateLimitException e) {
            LoggerFactory.getLogger(Message.class).warn(e.getMessage(), e);
            throw e;
        } catch (DiscordException e) {
            Reporter.report(e, channel.isPrivate() ? null : channel.getGuild(), channel);
            LoggerFactory.getLogger(Message.class).error(e.getMessage(), e);
        } catch (MissingPermissionsException e) {
            LoggerFactory.getLogger(Message.class).warn(Constants.name + " n'a pas les permissions pour appliquer cette requĂȘte.");
            new MissingPermissionDiscordException().throwException(channel, lg, e);
        } catch (Exception e) {
            Reporter.report(e, channel.isPrivate() ? null : channel.getGuild(), channel);
            LoggerFactory.getLogger(Message.class).error(e.getMessage(), e);
        }
        return null;
    });
}
Also used : MissingPermissionDiscordException(exceptions.MissingPermissionDiscordException) Language(enums.Language) MissingPermissionDiscordException(exceptions.MissingPermissionDiscordException) MissingPermissionDiscordException(exceptions.MissingPermissionDiscordException)

Aggregations

Language (enums.Language)43 Matcher (java.util.regex.Matcher)27 ArrayList (java.util.ArrayList)19 IOException (java.io.IOException)13 Language (ai.elimu.model.v2.enums.Language)12 StoryBookParagraph (ai.elimu.model.content.StoryBookParagraph)10 Word (ai.elimu.model.content.Word)10 HashMap (java.util.HashMap)7 StoryBook (ai.elimu.model.content.StoryBook)6 StoryBookChapter (ai.elimu.model.content.StoryBookChapter)6 ChannelLanguage (data.ChannelLanguage)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Letter (ai.elimu.model.content.Letter)5 List (java.util.List)5 Image (ai.elimu.model.content.multimedia.Image)4 AbstractCommand (commands.model.AbstractCommand)4 Command (commands.model.Command)4 Guild (data.Guild)4 Scheduled (org.springframework.scheduling.annotation.Scheduled)4 Audio (ai.elimu.model.content.multimedia.Audio)3