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();
}
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();
}
}
Aggregations