Search in sources :

Example 1 with ScoutMasterParser

use of io.github.spugn.Sargo.XMLParsers.ScoutMasterParser in project S-argo by Expugn.

the class CharacterScout method displayAndSave.

/**
 * Displays the scout results to the channel where the command was
 * requested and save the results to the user file afterwards. If
 * the results fail to display for any reason then the user file
 * is not saved.
 */
void displayAndSave() {
    ScoutMasterParser smp = new ScoutMasterParser();
    if (!SIMPLE_MESSAGE) {
        scoutMenu.withAuthorName(SELECTED_BANNER.getBannerName());
        setupScoutMenu();
        if (!generateImage || IMAGE_DISABLED)
            scoutMenu.appendField("- Scout Result -", characterString, false);
        scoutMenu.withDesc(smp.getQuote());
        scoutMenu.withAuthorIcon(new GitHubImage("images/System/Scout_Icon.png").getURL());
        scoutMenu.withColor(244, 233, 167);
        scoutMenu.withThumbnail(smp.getImage(highestRarity));
        scoutMenu.withFooterIcon(new GitHubImage("images/System/Memory_Diamond_Icon.png").getURL());
        scoutMenu.withFooterText((CHANNEL.getGuild().getUserByID(Long.parseLong(DISCORD_ID)).getName() + "#" + CHANNEL.getGuild().getUserByID(Long.parseLong(DISCORD_ID)).getDiscriminator()) + " | " + USER.getMemoryDiamonds() + " Memory Diamonds Left");
        LOGGER.debug("Displaying Scout Result...");
        IMessage display = null;
        try {
            if (generateImage && !IMAGE_DISABLED)
                display = CHANNEL.sendFile(scoutMenu.build(), new File(tempUserDirectory + "/results.png"));
            else
                display = CHANNEL.sendMessage(scoutMenu.build());
        } catch (FileNotFoundException e) {
            CHANNEL.sendMessage(new WarningMessage("FAILED TO GENERATE IMAGE", "Unable to display scout result.").get().build());
            display.delete();
            deleteTempDirectory();
            return;
        } catch (RateLimitException e) {
            EmbedBuilder rateLimited = new WarningMessage("RATE LIMIT EXCEPTION", "Slow down on the requests!").get();
            try {
                display.edit(rateLimited.build());
            } catch (NullPointerException a) {
            // DO SOMETHING
            }
            deleteTempDirectory();
            return;
        }
    } else {
        simpleMessage += "**" + SELECTED_BANNER.getBannerName() + "**" + "\n";
        setupScoutMenu();
        simpleMessage += smp.getQuote() + "\n";
        if (!generateImage || IMAGE_DISABLED) {
            simpleMessage += "**- Scout Result -**" + "\n";
            simpleMessage += characterString;
        }
        simpleMessage += (CHANNEL.getGuild().getUserByID(Long.parseLong(DISCORD_ID)).getName() + "#" + CHANNEL.getGuild().getUserByID(Long.parseLong(DISCORD_ID)).getDiscriminator()) + " | " + USER.getMemoryDiamonds() + " Memory Diamonds Left";
        LOGGER.debug("Displaying Scout Result...");
        IMessage display = null;
        try {
            if (generateImage && !IMAGE_DISABLED) {
                display = CHANNEL.sendFile(simpleMessage, new File(tempUserDirectory + "/results.png"));
            } else {
                display = CHANNEL.sendMessage(simpleMessage);
            }
        } catch (FileNotFoundException e) {
            CHANNEL.sendMessage(new WarningMessage("FAILED TO GENERATE IMAGE", "Unable to display scout result.").get().build());
            display.delete();
            deleteTempDirectory();
            return;
        } catch (RateLimitException e) {
            EmbedBuilder rateLimited = new WarningMessage("RATE LIMIT EXCEPTION", "Slow down on the requests!").get();
            try {
                display.edit(rateLimited.build());
            } catch (NullPointerException a) {
            // DO SOMETHING
            }
            deleteTempDirectory();
            return;
        }
    }
    LOGGER.debug("Saving User Data...");
    USER.saveData();
    deleteTempDirectory();
}
Also used : ScoutMasterParser(io.github.spugn.Sargo.XMLParsers.ScoutMasterParser) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) RateLimitException(sx.blah.discord.util.RateLimitException) GitHubImage(io.github.spugn.Sargo.Utilities.GitHubImage) IMessage(sx.blah.discord.handle.obj.IMessage) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File)

Aggregations

GitHubImage (io.github.spugn.Sargo.Utilities.GitHubImage)1 ScoutMasterParser (io.github.spugn.Sargo.XMLParsers.ScoutMasterParser)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IMessage (sx.blah.discord.handle.obj.IMessage)1 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)1 RateLimitException (sx.blah.discord.util.RateLimitException)1