Search in sources :

Example 1 with WhoisCommand

use of commands.classic.WhoisCommand in project KaellyBot by Kaysoro.

the class TooMuchDiscordException method throwException.

@Override
public void throwException(Message message, Command command, Language lg, Object... arguments) {
    AnkamaBug bug = null;
    String gender = Translator.getLabel(lg, "exception.object." + objectKey + ".gender");
    StringBuilder st = new StringBuilder(Translator.getLabel(lg, "exception.toomuch.toomuch." + gender)).append(" ").append(Translator.getLabel(lg, "exception.object." + objectKey + ".plural")).append(" ").append(Translator.getLabel(lg, "exception.toomuch.found." + gender));
    if (arguments.length > 0) {
        List<Object> objects = (List<Object>) arguments[0];
        long similarOcc = objects.stream().collect(Collectors.groupingBy(e -> e, Collectors.counting())).values().stream().max(Long::compareTo).orElse(0L);
        if (similarOcc > 1) {
            if (command instanceof WhoisCommand)
                bug = AnkamaBug.GHOST_CHARACTER;
            else if (command instanceof GuildCommand)
                bug = AnkamaBug.GHOST_GUILD;
            else if (command instanceof AllianceCommand)
                bug = AnkamaBug.GHOST_ALLY;
        }
        if (objects.size() <= ITEM_LIMIT) {
            st.append(": ");
            for (Object object : objects) if (isTranslatable)
                st.append(Translator.getLabel(lg, object.toString())).append(", ");
            else
                st.append(object.toString()).append(", ");
            st.delete(st.length() - 2, st.length()).append(".");
        } else
            st.append(". ").append(Translator.getLabel(lg, "exception.toomuch.items"));
    } else {
        if (st.substring(st.length() - 1, st.length()).matches("\\s+"))
            st.delete(st.length() - 1, st.length());
        st.append(".");
    }
    if (bug != null) {
        final AnkamaBug BUG = bug;
        message.getChannel().flatMap(channel -> channel.createEmbed(BUG.decorateEmbed(st.toString(), lg))).subscribe();
    } else
        message.getChannel().flatMap(channel -> channel.createMessage(st.toString())).subscribe();
}
Also used : GuildCommand(commands.classic.GuildCommand) AnkamaBug(enums.AnkamaBug) Language(enums.Language) WhoisCommand(commands.classic.WhoisCommand) List(java.util.List) Message(discord4j.core.object.entity.Message) Command(commands.model.Command) Translator(util.Translator) Collectors(java.util.stream.Collectors) AllianceCommand(commands.classic.AllianceCommand) AnkamaBug(enums.AnkamaBug) WhoisCommand(commands.classic.WhoisCommand) GuildCommand(commands.classic.GuildCommand) AllianceCommand(commands.classic.AllianceCommand) List(java.util.List)

Example 2 with WhoisCommand

use of commands.classic.WhoisCommand in project KaellyBot by Kaysoro.

the class NotFoundDiscordException method throwException.

@Override
public void throwException(Message message, Command command, Language lg, Object... arguments) {
    AnkamaBug bug = null;
    if (command instanceof WhoisCommand)
        bug = AnkamaBug.CHARACTER_NOT_FOUND;
    else if (command instanceof GuildCommand)
        bug = AnkamaBug.GUILD_NOT_FOUND;
    else if (command instanceof AllianceCommand)
        bug = AnkamaBug.ALLY_NOT_FOUND;
    else if (command instanceof ItemCommand)
        if (message.getContent().contains("'"))
            bug = AnkamaBug.ITEM_NOT_FOUND_APOSTROPHE;
        else if (message.getContent().toLowerCase().contains(Translator.getLabel(lg, "equip.muldo").toLowerCase()) || message.getContent().toLowerCase().contains(Translator.getLabel(lg, "equip.volkorne").toLowerCase()))
            bug = AnkamaBug.ITEM_PAGE_MULDO_VOLKORNE_NOT_FOUND;
    String gender = Translator.getLabel(lg, "exception.object." + objectKey + ".gender");
    String text = Translator.getLabel(lg, "exception.notfound.not." + gender) + " " + Translator.getLabel(lg, "exception.object." + objectKey + ".singular") + " " + Translator.getLabel(lg, "exception.notfound.found." + gender) + ".";
    if (bug != null) {
        final AnkamaBug BUG = bug;
        message.getChannel().flatMap(channel -> channel.createEmbed(BUG.decorateEmbed(text, lg))).subscribe();
    } else
        message.getChannel().flatMap(channel -> channel.createMessage(text)).subscribe();
}
Also used : GuildCommand(commands.classic.GuildCommand) AnkamaBug(enums.AnkamaBug) Language(enums.Language) WhoisCommand(commands.classic.WhoisCommand) ItemCommand(commands.classic.ItemCommand) Message(discord4j.core.object.entity.Message) Command(commands.model.Command) Translator(util.Translator) AllianceCommand(commands.classic.AllianceCommand) AnkamaBug(enums.AnkamaBug) WhoisCommand(commands.classic.WhoisCommand) GuildCommand(commands.classic.GuildCommand) ItemCommand(commands.classic.ItemCommand) AllianceCommand(commands.classic.AllianceCommand)

Aggregations

AllianceCommand (commands.classic.AllianceCommand)2 GuildCommand (commands.classic.GuildCommand)2 WhoisCommand (commands.classic.WhoisCommand)2 Command (commands.model.Command)2 Message (discord4j.core.object.entity.Message)2 AnkamaBug (enums.AnkamaBug)2 Language (enums.Language)2 Translator (util.Translator)2 ItemCommand (commands.classic.ItemCommand)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1