Skip to content

Commit

Permalink
Better output for large numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorel Ali (Skepter) committed Sep 25, 2017
1 parent d40a27d commit e964a30
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion SkepBot/src/io/github/skepter/skepbot/SkepBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public void onMessageReceived(MessageReceivedEvent event) {
long averageCooldown = ((cooldownTime - System.currentTimeMillis()) / 1000); //Gives a "human readable" estimate of how long they have to go
if(System.currentTimeMillis() > cooldownTime || isSkepter(event) || averageCooldown == 0 || playingHangman) {
cooldownsPerPerson.put(username, System.currentTimeMillis() + (COOLDOWN * 1000));

for(Module module : modules) {
module.init(username, mainMsg);
if(module.isReady()) {
Expand Down Expand Up @@ -505,6 +505,9 @@ public void onMessageReceived(MessageReceivedEvent event) {
}

private void sendMessage(MessageChannel channel, String str) {
if(str.length() > 2000) {
return;
}
if(str.length() > 256) {
channel.sendMessage(str.substring(0, 256)).queue();
channel.sendMessage(str.substring(256, str.length())).queue();
Expand Down
9 changes: 7 additions & 2 deletions SkepBot/src/io/github/skepter/skepbot/WebsiteGetters.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ public static String shortAnswersWolframAlpha(String query) throws IOException {
double b = Double.parseDouble(output.split("\\/")[1]);
double resultDouble = a / b;
DecimalFormat format = new DecimalFormat("#.00");
return format.format(resultDouble) + " (2 decimal places)";

if(resultDouble > Long.MAX_VALUE) {
return "Number is too large to compute";
} else {
return format.format(resultDouble) + " (2 decimal places)";
}
}

if(output.contains("I can help you to compute.")) {
Expand Down Expand Up @@ -124,7 +129,7 @@ public static String[] getDefinition(String wordToDefine) throws IOException {
String[] output = new String[arr.length()];

for(int i = 0; i < arr.length(); i++) {
output[i] = arr.getJSONObject(i).getString("defenition");
output[i] = arr.getJSONObject(i).getString("type") + ": "+ arr.getJSONObject(i).getString("defenition");
}

// JSONObject ob = null;
Expand Down

0 comments on commit e964a30

Please sign in to comment.