=Fixed Bug #10 GetSauce command incorrect output
Fixed multiple issues, stemming from change of E6 API
This commit is contained in:
@@ -1,29 +1,29 @@
|
|||||||
package commands.general;
|
package commands.general;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
import core.LocStrings;
|
import core.LocStrings;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
import dataStructures.KittyGuild;
|
import dataStructures.KittyGuild;
|
||||||
import dataStructures.KittyRating;
|
import dataStructures.KittyRating;
|
||||||
import dataStructures.KittyRole;
|
import dataStructures.KittyRole;
|
||||||
import dataStructures.KittyUser;
|
import dataStructures.KittyUser;
|
||||||
import dataStructures.Response;
|
import dataStructures.Response;
|
||||||
import dataStructures.UserInput;
|
import dataStructures.UserInput;
|
||||||
import network.NetworkSauceNAO;
|
import network.NetworkSauceNAO;
|
||||||
|
|
||||||
public class CommandGetSauce extends Command
|
public class CommandGetSauce extends Command
|
||||||
{
|
{
|
||||||
NetworkSauceNAO sauce = new NetworkSauceNAO();
|
NetworkSauceNAO sauce = new NetworkSauceNAO();
|
||||||
|
|
||||||
public CommandGetSauce(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandGetSauce(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHelpText() { return LocStrings.stub("GetSauceInfo"); };
|
public String getHelpText() { return LocStrings.stub("GetSauceInfo"); };
|
||||||
|
|
||||||
@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());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user