Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
Found an edge case
Browse files Browse the repository at this point in the history
- Manually added bans from KSoft admins have null mod IDs, making getModId() hang forever
  • Loading branch information
BenjaminUrquhart authored Oct 28, 2018
1 parent 57c8bc0 commit d2c6677
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
2 changes: 0 additions & 2 deletions src/main/java/net/explodingbush/ksoftapi/KSoftAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import net.explodingbush.ksoftapi.enums.Routes;
import net.explodingbush.ksoftapi.utils.Checks;

import static net.explodingbush.ksoftapi.enums.Routes.REDDIT_URL;

public class KSoftAPI {

private final String token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public RedditAction setSubreddit(String subreddit) {
public Reddit execute() throws LoginException, MissingArgumentException {
Response response;
JSONObject json;
if (request == null || type == ImageType.RANDOM_REDDIT && this.subreddit == null) {
if (request == null || type.equals(ImageType.RANDOM_REDDIT) && this.subreddit == null) {
throw new MissingArgumentException("Subreddit not defined");
}
if (subreddit != null && type != ImageType.RANDOM_REDDIT) {
if (subreddit != null && !type.equals(ImageType.RANDOM_REDDIT)) {
logger.warn("You're setting a subreddit, but ImageType is not RANDOM_REDDIT");
}

if (type == ImageType.RANDOM_REDDIT) {
if (type.equals(ImageType.RANDOM_REDDIT)) {
request = request.concat(subreddit);
response = new JSONBuilder().requestKsoftResponse(request, token);
if (response.code() == 500 || response.code() == 404 || response.code() == 130) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import net.explodingbush.ksoftapi.entities.Ban;
import net.explodingbush.ksoftapi.exceptions.MissingArgumentException;
import net.explodingbush.ksoftapi.exceptions.NotFoundException;

import org.json.JSONArray;
import org.json.JSONObject;

Expand Down Expand Up @@ -44,6 +46,9 @@ public String getEffectiveName() {

@Override
public long getModId() {
if(json.isNull("moderator_id")){
throw new NotFoundException("Moderator ID not found!");
}
return json.getLong("moderator_id");
}

Expand Down
40 changes: 20 additions & 20 deletions src/main/java/net/explodingbush/ksoftapi/enums/Routes.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package net.explodingbush.ksoftapi.enums;

public enum Routes {

BAN_ADD("https://api.ksoft.si/bans/add"),
BAN_INFO("https://api.ksoft.si/bans/info?user="),
BAN_LIST("https://api.ksoft.si/bans/list?per_page="),
IMAGE("https://api.ksoft.si/images/random-image?tag=%s&nsfw=%s"),
WIKIHOW("https://api.ksoft.si/images/random-wikihow?nsfw=%s"),
REDDIT("https://api.ksoft.si/meme/");

private final String route;

private Routes(String route){
this.route = route;
}
public String toString(){
return this.route;
}
}
package net.explodingbush.ksoftapi.enums;

public enum Routes {

BAN_ADD("https://api.ksoft.si/bans/add"),
BAN_INFO("https://api.ksoft.si/bans/info?user="),
BAN_LIST("https://api.ksoft.si/bans/list?per_page="),
IMAGE("https://api.ksoft.si/images/random-image?tag=%s&nsfw=%s"),
WIKIHOW("https://api.ksoft.si/images/random-wikihow?nsfw=%s"),
REDDIT("https://api.ksoft.si/meme/");

private final String route;

private Routes(String route){
this.route = route;
}
public String toString(){
return this.route;
}
}

0 comments on commit d2c6677

Please sign in to comment.