=Fixed Bug #10 GetSauce command incorrect output

Fixed multiple issues, stemming from change of E6 API
This commit is contained in:
Alex Stewart
2020-03-27 02:54:33 -04:00
parent cab2370f89
commit d86adaf3e2
3 changed files with 41 additions and 39 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ public class CommandGetSauce extends Command
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
res.send(sauce.getSauce(input.args)); res.send(sauce.getSauce(input.args).output());
} }
} }
+7 -6
View File
@@ -92,14 +92,12 @@ public class NetworkE6
// tag by default. User-provided tags, therefore, will override it. // tag by default. User-provided tags, therefore, will override it.
// If order:score is provided, that will be honored over order:random. // If order:score is provided, that will be honored over order:random.
String res = HTTPUtils.sendGETRequest(API_ROOT + "tags=order:random%20" + input + "&limit=" + maxSearchResults_); String res = HTTPUtils.sendGETRequest(API_ROOT + "tags=order:random%20" + input + "&limit=" + maxSearchResults_);
System.out.println("LOOK HERE: " + res);
if(res != null) if(res != null)
{ {
// Use class evaluation on an array of the response imageObject to be able to hold multiple. // Use class evaluation on an array of the response imageObject to be able to hold multiple.
System.out.println("Still");
E6ResponseObject imageObj = jsonParser_.fromJson(res, E6ResponseObject.class); E6ResponseObject imageObj = jsonParser_.fromJson(res, E6ResponseObject.class);
System.out.println("Broken");
// For now, we really just wanna display images and their source. // For now, we really just wanna display images and their source.
// Append them all separately to a response string w/ some flavor text. // Append them all separately to a response string w/ some flavor text.
if(imageObj.posts.length < 1) if(imageObj.posts.length < 1)
@@ -110,6 +108,7 @@ public class NetworkE6
{ {
for(int i = 0; i < imageObj.posts.length; ++i) for(int i = 0; i < imageObj.posts.length; ++i)
{ {
System.out.println(imageObj.posts.length);
String [] TagsList = imageObj.posts[i].tags.general; String [] TagsList = imageObj.posts[i].tags.general;
blacklisted = false; blacklisted = false;
for(int j = 0; j < blacklist.length; j++) for(int j = 0; j < blacklist.length; j++)
@@ -133,9 +132,9 @@ public class NetworkE6
image.editPostURL("https://e621.net/posts/" + imageObj.posts[i].id); image.editPostURL("https://e621.net/posts/" + imageObj.posts[i].id);
if(imageObj.posts[i].tags.artist.length > 0) if(imageObj.posts[i].tags.artist.length > 0)
{ {
String artists = ""; String artists = imageObj.posts[i].tags.artist[0];
for(int j = 0; j < imageObj.posts[i].tags.artist.length; j++) for(int j = 1; j < imageObj.posts[i].tags.artist.length; j++)
artists += imageObj.posts[i].tags.artist[j]; artists += ", " + imageObj.posts[i].tags.artist[j];
image.editArtist(artists); image.editArtist(artists);
} }
else else
@@ -190,6 +189,8 @@ public class NetworkE6
if(image.output().authorText != null) if(image.output().authorText != null)
{ {
System.out.println(image);
System.out.println(image.toString());
return image; return image;
} }
} }
+6 -5
View File
@@ -4,6 +4,7 @@ import java.util.List;
import com.google.gson.Gson; import com.google.gson.Gson;
import dataStructures.GenericImage;
import offline.Ref; import offline.Ref;
import utils.HTTPUtils; import utils.HTTPUtils;
@@ -27,7 +28,7 @@ public class NetworkSauceNAO
String [] ext_urls; String [] ext_urls;
} }
public String getSauce(String input) public GenericImage getSauce(String input)
{ {
input = input.trim(); input = input.trim();
input = input.replace("+", "%2B"); input = input.replace("+", "%2B");
@@ -39,11 +40,11 @@ public class NetworkSauceNAO
String sauceUrl = sauce.results.get(0).data.ext_urls[0]; String sauceUrl = sauce.results.get(0).data.ext_urls[0];
if(sauceUrl.startsWith("https://e621.net/post/show/")) if(sauceUrl.startsWith("https://e621.net/post/show/"))
{ {
System.out.println("id:" + sauceUrl.substring(26)); return e6Sauce.getE6("id:" + sauceUrl.substring(27));
System.out.println("HERE");
return e6Sauce.getE6("id:" + sauceUrl.substring(27)).toString();
} }
return sauce.results.get(0).data.ext_urls[0]; GenericImage unknown = new GenericImage("", "","");
return unknown;
// return sauce.results.get(0).data.ext_urls[0];
} }
} }