Search in sources :

Example 6 with RateLimitException

use of sx.blah.discord.util.RateLimitException in project S-argo by Expugn.

the class WeaponScout 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() {
    if (!SIMPLE_MESSAGE) {
        scoutMenu.withAuthorName(SELECTED_BANNER.getBannerName());
        setupScoutMenu();
        if (!generateImage || IMAGE_DISABLED)
            scoutMenu.appendField("- Weapon Result -", weaponString, false);
        scoutMenu.withAuthorIcon(new GitHubImage("images/System/Scout_Icon.png").getURL());
        scoutMenu.withColor(139, 69, 19);
        if (weapons.get(0).getRarity() == 2)
            scoutMenu.withThumbnail(new GitHubImage("images/System/Brown_Chest.png").getURL());
        else if (weapons.get(0).getRarity() == 3)
            scoutMenu.withThumbnail(new GitHubImage("images/System/Blue_Chest.png").getURL());
        else if (weapons.get(0).getRarity() == 4)
            scoutMenu.withThumbnail(new GitHubImage("images/System/Red_Chest.png").getURL());
        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();
        if (!generateImage || IMAGE_DISABLED) {
            simpleMessage += "**- Weapon Result -**" + "\n";
            simpleMessage += weaponString;
        }
        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 : 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)

Example 7 with RateLimitException

use of sx.blah.discord.util.RateLimitException in project Discord4J by Discord4J.

the class RoleBot method handle.

/**
 * Client is ready to interact with Discord.
 * @see ReadyBot
 */
@Override
public void handle(ReadyEvent event) {
    try {
        // Gets the first guild the bot is a member of. (NOTE: This is only for demonstration. Getting guilds in this way is NOT recommended. Use IDs or events instead.)
        IGuild guild = event.getClient().getGuilds().get(0);
        // Instantiate a RoleBuilder which will aide in the creation of the role.
        RoleBuilder roleBuilder = new RoleBuilder(guild);
        // Set the new role's name
        roleBuilder.withName("Awesome Role");
        // Set the new role's color
        roleBuilder.withColor(Color.GREEN);
        // Make the new role display separately from others in Discord.
        roleBuilder.setHoist(true);
        // Allow this role to be mentionable in chat.
        roleBuilder.setMentionable(true);
        // Assign the Administrator permission to this role.
        roleBuilder.withPermissions(EnumSet.of(Permissions.ADMINISTRATOR));
        // Add the role to the guild in Discord.
        IRole role = roleBuilder.build();
        // Gets the user of the bot
        IUser ourUser = event.getClient().getOurUser();
        // Assigns our new role to the bot. NOTE: This will make the bot's ONLY role our role.
        guild.editUserRoles(ourUser, new IRole[] { role });
    } catch (MissingPermissionsException | RateLimitException | DiscordException e) {
        // Error occurred
        e.printStackTrace();
    }
}
Also used : IRole(sx.blah.discord.handle.obj.IRole) RateLimitException(sx.blah.discord.util.RateLimitException) DiscordException(sx.blah.discord.util.DiscordException) IUser(sx.blah.discord.handle.obj.IUser) MissingPermissionsException(sx.blah.discord.util.MissingPermissionsException) IGuild(sx.blah.discord.handle.obj.IGuild) RoleBuilder(sx.blah.discord.util.RoleBuilder)

Aggregations

RateLimitException (sx.blah.discord.util.RateLimitException)7 IMessage (sx.blah.discord.handle.obj.IMessage)4 DiscordException (sx.blah.discord.util.DiscordException)4 GitHubImage (io.github.spugn.Sargo.Utilities.GitHubImage)3 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)3 MissingPermissionsException (sx.blah.discord.util.MissingPermissionsException)3 IChannel (sx.blah.discord.handle.obj.IChannel)2 IUser (sx.blah.discord.handle.obj.IUser)2 Config (com.github.vaerys.pogos.Config)1 GlobalData (com.github.vaerys.pogos.GlobalData)1 WarningMessage (io.github.spugn.Sargo.Objects.WarningMessage)1 ScoutMasterParser (io.github.spugn.Sargo.XMLParsers.ScoutMasterParser)1 ExecutorService (java.util.concurrent.ExecutorService)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 IDiscordClient (sx.blah.discord.api.IDiscordClient)1 EventDispatcher (sx.blah.discord.api.events.EventDispatcher)1