use of sx.blah.discord.util.RateLimitException 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();
}
use of sx.blah.discord.util.RateLimitException in project S-argo by Expugn.
the class TicketScout 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) {
setupScoutMenu();
if (!generateImage || IMAGE_DISABLED)
scoutMenu.appendField("- Weapon Result -", itemString, false);
scoutMenu.withAuthorIcon(new GitHubImage("images/System/Scout_Icon.png").getURL());
scoutMenu.withColor(255, 255, 255);
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()) + " | " + userTotalScouts + " Total Ticket Scouts");
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 {
setupScoutMenu();
if (!generateImage || IMAGE_DISABLED) {
simpleMessage += "**- Weapon Result -**" + "\n";
simpleMessage += itemString;
}
simpleMessage += (CHANNEL.getGuild().getUserByID(Long.parseLong(DISCORD_ID)).getName() + "#" + CHANNEL.getGuild().getUserByID(Long.parseLong(DISCORD_ID)).getDiscriminator()) + " | " + userTotalScouts + " Total Ticket Scouts";
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;
}
}
USER.upgradeExchangeSwords();
USER.saveData();
deleteTempDirectory();
}
use of sx.blah.discord.util.RateLimitException in project Ublisk by Derkades.
the class DiscordBot method onChat.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onChat(AsyncPlayerChatEvent event) {
if (!enabled) {
super.log(this, LogLevel.DEBUG, "Skipping discord bot for this message - module has not been initialized successfully.");
return;
}
Player player = event.getPlayer();
String message = "[" + player.getName() + "] " + event.getMessage();
IChannel channel = client.getChannelByID("310155421719724052");
try {
channel.sendMessage(message);
} catch (MissingPermissionsException e) {
e.printStackTrace();
} catch (RateLimitException e) {
e.printStackTrace();
} catch (DiscordException e) {
e.printStackTrace();
}
}
use of sx.blah.discord.util.RateLimitException in project Discord4J by Discord4J.
the class ParrotBot method handle.
/**
* Called when the client receives a message.
*/
@Override
public void handle(MessageReceivedEvent event) {
// Gets the message from the event object NOTE: This is not the content of the message, but the object itself
IMessage message = event.getMessage();
// Gets the channel in which this message was sent.
IChannel channel = message.getChannel();
try {
// Builds (sends) and new message in the channel that the original message was sent with the content of the original message.
new MessageBuilder(this.client).withChannel(channel).withContent(message.getContent()).build();
} catch (RateLimitException e) {
// RateLimitException thrown. The bot is sending messages too quickly!
System.err.print("Sending messages too quickly!");
e.printStackTrace();
} catch (DiscordException e) {
// DiscordException thrown. Many possibilities. Use getErrorMessage() to see what went wrong.
// Print the error message sent by Discord
System.err.print(e.getErrorMessage());
e.printStackTrace();
} catch (MissingPermissionsException e) {
// MissingPermissionsException thrown. The bot doesn't have permission to send the message!
System.err.print("Missing permissions for channel!");
e.printStackTrace();
}
}
use of sx.blah.discord.util.RateLimitException in project DiscordSailv2 by Vaerys-Dawn.
the class Main method main.
public static void main(String[] args) throws UnknownHostException {
// important, do not move
PatchHandler.preInitPatches();
logger = LoggerFactory.getLogger(Main.class);
logger.info("Starting bot...");
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
logger.info(">>> Running Shutdown Process <<<");
if (Globals.savingFiles) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Utility.sendStack(e);
}
}
Globals.saveFiles(true);
}
});
String token = null;
// you need to set a token in Token/Token.txt for the bot to run
try {
Discord4J.disableAudio();
FileHandler.createDirectory(Constants.DIRECTORY_STORAGE);
FileHandler.createDirectory(Constants.DIRECTORY_GLOBAL_IMAGES);
FileHandler.createDirectory(Constants.DIRECTORY_COMP);
FileHandler.createDirectory(Constants.DIRECTORY_BACKUPS);
FileHandler.createDirectory(Constants.DIRECTORY_TEMP);
FileHandler.createDirectory(Constants.DIRECTORY_OLD_FILES);
FileHandler.createDirectory(Constants.DIRECTORY_ERROR);
// load config phase 1
Config config = (Config) Config.create(Constants.FILE_CONFIG, new Config());
GlobalData globalData = (GlobalData) GlobalData.create(Constants.FILE_GLOBAL_DATA, new GlobalData());
config = Config.check(config);
// getting bot token
try {
token = FileHandler.readFromFile(Constants.FILE_TOKEN).get(0);
} catch (IndexOutOfBoundsException e) {
logger.error("!!!BOT TOKEN NOT VALID PLEASE CHECK \"Storage/Token.txt\" AND UPDATE THE TOKEN!!!");
System.exit(Constants.EXITCODE_STOP);
}
try {
List<String> pastebinToken = FileHandler.readFromFile(Constants.FILE_PASTEBIN_TOKEN);
Client.initPastebin(pastebinToken);
} catch (IndexOutOfBoundsException e) {
logger.info("No Pastebin Token found.");
}
// stuff that i cant getToggles to work because reasons, ignore completely
// try{
// List<String> richPresesnce = FileHandler.readFromFile(Constants.FILE_RPC_TOKEN);
// Client.initRichPresence(richPresesnce);
// }catch (IndexOutOfBoundsException e){
// logger.info("Rich presence information missing.");
// }
// try {
// List<String> imgurToken = FileHandler.readFromFile(Constants.FILE_IMGUR_TOKEN);
// Client.initImgur(imgurToken);
// } catch (IndexOutOfBoundsException e) {
// logger.info("No Patreon Token found.");
// }
IDiscordClient client = Client.createClient(token, false);
// load config phase 2
Globals.initConfig(client, config, globalData);
if (Globals.creatorID == 153159020528533505L) {
try {
List<String> patreonToken = FileHandler.readFromFile(Constants.FILE_PATREON_TOKEN);
Client.initPatreon(patreonToken);
} catch (IndexOutOfBoundsException e) {
logger.info("No Patreon Token found.");
}
}
Globals.validateConfig();
if (Globals.errorStack != null) {
logger.error(">\n> Begin Config Error Report <<\n" + "at " + Constants.DIRECTORY_STORAGE + Constants.FILE_CONFIG + "\n" + Globals.errorStack + ">> End Error Report <<");
System.exit(Constants.EXITCODE_STOP);
}
ThreadGroup group = new ThreadGroup("GuildCreateGroup");
final int[] count = new int[] { 0 };
// login + register listener.
client.login();
// initialize creatorID if it is completely unset:
if (config.creatorID == 0) {
IUser botOwner = client.getApplicationOwner();
config.creatorID = botOwner.getLongID();
Globals.creatorID = config.creatorID;
logger.info("Default creatorID set to user " + botOwner.getName() + "#" + botOwner.getDiscriminator());
// save it back out to file.
config.flushFile();
}
ExecutorService guildService = new ThreadPoolExecutor(2, 50, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<>(1000), r -> new Thread(group, r, group.getName() + "-Thread-" + ++count[0]));
ExecutorService commandService = new ThreadPoolExecutor(2, 50, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<>(1000), r -> new Thread(group, r, group.getName() + "-Thread-" + ++count[0]));
ExecutorService creatorService = new ThreadPoolExecutor(2, 50, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<>(1000), r -> new Thread(group, r, group.getName() + "-Thread-" + ++count[0]));
EventDispatcher dispatcher = client.getDispatcher();
dispatcher.registerListener(guildService, new GuildCreateListener());
dispatcher.registerListener(commandService, new AnnotationListener());
dispatcher.registerListener(creatorService, new CreatorHandler());
dispatcher.registerTemporaryListener(new InitEvent());
// validate config file
Globals.setVersion();
// Init Patch system.
// timed events getSlashCommands
new TimerHandler();
} catch (DiscordException ex) {
logger.error(ex.getErrorMessage());
} catch (RateLimitException e) {
Utility.sendStack(e);
}
}
Aggregations