Iterative
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
function plugin(message, user)
|
||||||
|
local index;
|
||||||
|
local concat;
|
||||||
|
if(string.find(message, "https://derpicdn.net/img"))then
|
||||||
|
if(string.find(message, "view/"))then
|
||||||
|
index = string.find(message, "/[^/]*$");
|
||||||
|
return "!derpi ID:" .. string.sub(message, index + 1, string.find(message, ".[^.]*$")-1);
|
||||||
|
else
|
||||||
|
if(string.find(message, "download/"))then
|
||||||
|
index = string.find(message, "_");
|
||||||
|
concat = string.sub(message, 0, index-1);
|
||||||
|
return "!derpi ID:" .. string.sub(concat, string.find(message, "/[^/]*$") + 1);
|
||||||
|
else
|
||||||
|
index = string.find(message, "/[^/]*$");
|
||||||
|
concat = string.sub(message, 0, index - 1);
|
||||||
|
index = string.find(concat, "/[^/]*$");
|
||||||
|
|
||||||
|
return "!derpi ID:" .. string.sub(concat, index + 1);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
function plugin(message, user)
|
||||||
|
if(string.find(message, "https://static1.e621.net/data") or string.find(message, "https://static1.e926.net/data"))then
|
||||||
|
if(string.find(message, " "))then
|
||||||
|
message = string.sub(message, 0, string.find(message, " "));
|
||||||
|
end
|
||||||
|
return "!e6 md5:" .. string.sub(message, string.find(message, "/[^/]*$") + 1 ,string.find(message, ".[^.]*$") - 1);
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package commands.general;
|
||||||
|
|
||||||
|
import core.Command;
|
||||||
|
import core.LocStrings;
|
||||||
|
import dataStructures.KittyChannel;
|
||||||
|
import dataStructures.KittyEmbed;
|
||||||
|
import dataStructures.KittyGuild;
|
||||||
|
import dataStructures.KittyRating;
|
||||||
|
import dataStructures.KittyRole;
|
||||||
|
import dataStructures.KittyUser;
|
||||||
|
import dataStructures.Response;
|
||||||
|
import dataStructures.UserInput;
|
||||||
|
import network.NetworkDerpi;
|
||||||
|
|
||||||
|
public class CommandDerpi extends Command
|
||||||
|
{
|
||||||
|
NetworkDerpi searcher = new NetworkDerpi();
|
||||||
|
KittyEmbed response;
|
||||||
|
|
||||||
|
// Required constructor
|
||||||
|
public CommandDerpi(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpText() { return "Will search derpibooru for the tags entered, if KittyBot's content filter allows it"; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||||
|
{
|
||||||
|
if(guild.contentRating == KittyRating.Filtered)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
response = searcher.getDerpi(input.args.replace(',', ' ') + " safe").output();
|
||||||
|
res.send(response);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
res.send(LocStrings.stub("DerpiError"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(input.args == null || input.args.length() == 0)
|
||||||
|
res.send("DerpiNoSearchError");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
response = searcher.getDerpi(input.args).output();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
res.send(response);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
res.send(LocStrings.stub("DerpiError"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(input.args.startsWith("ID:"))
|
||||||
|
{
|
||||||
|
response = searcher.getDerpiByID(input.args.substring(input.args.indexOf(':'))).output();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
res.send(response);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
res.send(LocStrings.stub("DerpiError"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package commands.general;
|
||||||
|
|
||||||
|
import core.Command;
|
||||||
|
import core.LocStrings;
|
||||||
|
import dataStructures.*;
|
||||||
|
import network.NetworkE6;
|
||||||
|
|
||||||
|
public class CommandE6 extends Command
|
||||||
|
{
|
||||||
|
NetworkE6 searcher = new NetworkE6();
|
||||||
|
KittyEmbed response;
|
||||||
|
|
||||||
|
public CommandE6(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpText()
|
||||||
|
{
|
||||||
|
String toRet = "Will search e6";
|
||||||
|
toRet += "21 for the tags entered, if KittyBot's content filter allows it";
|
||||||
|
return toRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||||
|
{
|
||||||
|
if(guild.contentRating == KittyRating.Filtered || !guild.channels.get(Long.getLong(channel.uniqueID)).mature)
|
||||||
|
{
|
||||||
|
if(!guild.channels.get(Long.getLong(channel.uniqueID)).mature)
|
||||||
|
{
|
||||||
|
res.send("This channel is SFW only! Have some (probably) wholesome content ^^~");
|
||||||
|
}
|
||||||
|
response = searcher.getE6(input.args + " rating:safe").output();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
res.send(response);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
res.send(LocStrings.stub("E6Blacklisted"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(input.args == null || input.args.length() == 0)
|
||||||
|
res.send("E6NoSearchError");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
response = searcher.getE6(input.args).output();
|
||||||
|
res.send(response);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
res.send(LocStrings.stub("E6Blacklisted"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -108,6 +108,9 @@ public class CommandManager
|
|||||||
this.register(LocCommands.stub("music"), new CommandMusicMain(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("music"), new CommandMusicMain(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("defaultdance"), new CommandDefaultDance(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("defaultdance"), new CommandDefaultDance(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("getsauce"), new CommandGetSauce(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("getsauce"), new CommandGetSauce(KittyRole.General, KittyRating.Safe));
|
||||||
|
|
||||||
|
this.register(LocCommands.stub("e6"), new CommandE6(KittyRole.General, KittyRating.Filtered));
|
||||||
|
this.register(LocCommands.stub("derpi"), new CommandDerpi(KittyRole.General, KittyRating.Filtered));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allows the command manager to keep track of a command. Takes a pair (the un-localized and localzied commands)
|
// Allows the command manager to keep track of a command. Takes a pair (the un-localized and localzied commands)
|
||||||
|
|||||||
@@ -1,40 +1,57 @@
|
|||||||
package dataStructures;
|
package dataStructures;
|
||||||
|
|
||||||
// This is a structure representing an image reponse for handing around.
|
import java.awt.Color;
|
||||||
|
|
||||||
|
// This is a structure representing an image response for handing around.
|
||||||
public class GenericImage
|
public class GenericImage
|
||||||
{
|
{
|
||||||
private String artist;
|
private KittyEmbed response= new KittyEmbed();
|
||||||
private String postURL;
|
|
||||||
private String imageURL;
|
|
||||||
|
|
||||||
public GenericImage(String artist, String postURL, String imageURL)
|
public GenericImage(String artist, String postURL, String imageURL)
|
||||||
{
|
{
|
||||||
this.artist = artist;
|
response.authorText = null;
|
||||||
this.postURL = postURL;
|
response.color = new Color(0,0,0);
|
||||||
this.imageURL = imageURL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void editArtist(String artist)
|
public void editArtist(String artist)
|
||||||
{
|
{
|
||||||
this.artist = artist;
|
response.authorText = artist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void editAuthorImage(String URL)
|
||||||
|
{
|
||||||
|
response.authorImage = URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void editPostURL(String postURL)
|
public void editPostURL(String postURL)
|
||||||
{
|
{
|
||||||
this.postURL = postURL;
|
response.authorLink = postURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void editImageURL(String imageURL)
|
public void editImageURL(String imageURL)
|
||||||
{
|
{
|
||||||
this.imageURL = imageURL;
|
response.imageURL = imageURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString()
|
public void editDescriptionText(String score)
|
||||||
{
|
{
|
||||||
if(imageURL.isEmpty())
|
response.descriptionText = score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void editFooterText(String tags)
|
||||||
{
|
{
|
||||||
return "I couldn't find anything! Please try again!";
|
response.footerText = tags;
|
||||||
}
|
}
|
||||||
return "Artist: " + artist + "\n<" + postURL.trim() + ">\n" + imageURL;
|
|
||||||
|
public KittyEmbed output()
|
||||||
|
{
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValid()
|
||||||
|
{
|
||||||
|
if(response.title != null)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import offline.Ref;
|
|||||||
import utils.*;
|
import utils.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the e621 request class, designed for form and parse requests that
|
* This is the e6 request class, designed for form and parse requests that
|
||||||
* use the e621 API, and is entirely static.
|
* use the e6 API, and is entirely static.
|
||||||
*
|
*
|
||||||
* If you ever find this class randomly not working,
|
* If you ever find this class randomly not working,
|
||||||
* it may be a good idea to make sure the user agent string is set in
|
* it may be a good idea to make sure the user agent string is set in
|
||||||
@@ -17,7 +17,7 @@ import utils.*;
|
|||||||
* @author Wisp
|
* @author Wisp
|
||||||
* Edited by Rin
|
* Edited by Rin
|
||||||
*/
|
*/
|
||||||
public class NetworkE621
|
public class NetworkE6
|
||||||
{
|
{
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
// Internal JSON class and variables //
|
// Internal JSON class and variables //
|
||||||
@@ -26,7 +26,7 @@ public class NetworkE621
|
|||||||
private static final String API_ROOT = "https://e621.net/post/index.json?";
|
private static final String API_ROOT = "https://e621.net/post/index.json?";
|
||||||
private static int maxSearchResults_ = 10;
|
private static int maxSearchResults_ = 10;
|
||||||
private static String[] blacklist = Ref.e621Blacklist;
|
private static String[] blacklist = Ref.e621Blacklist;
|
||||||
private class E621ResponseObject
|
private class E6ResponseObject
|
||||||
{
|
{
|
||||||
// public varaibles matching the case and the type we want for JSON.
|
// public varaibles matching the case and the type we want for JSON.
|
||||||
// There are many more fields, but if we don't provide some it just
|
// There are many more fields, but if we don't provide some it just
|
||||||
@@ -43,7 +43,7 @@ public class NetworkE621
|
|||||||
// Static methods //
|
// Static methods //
|
||||||
////////////////////
|
////////////////////
|
||||||
// Requests a specific image, then returns a few.
|
// Requests a specific image, then returns a few.
|
||||||
public GenericImage getE621(String input)
|
public GenericImage getE6(String input)
|
||||||
{
|
{
|
||||||
|
|
||||||
GenericImage image = new GenericImage("","","");
|
GenericImage image = new GenericImage("","","");
|
||||||
@@ -63,7 +63,7 @@ public class NetworkE621
|
|||||||
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.
|
||||||
E621ResponseObject[] imageObj = jsonParser_.fromJson(res, E621ResponseObject[].class);
|
E6ResponseObject[] imageObj = jsonParser_.fromJson(res, E6ResponseObject[].class);
|
||||||
|
|
||||||
// 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.
|
||||||
@@ -11,7 +11,7 @@ public class NetworkSauceNAO
|
|||||||
{
|
{
|
||||||
private static final Gson jsonParser_ = new Gson();
|
private static final Gson jsonParser_ = new Gson();
|
||||||
private static final String API_ROOT = "https://saucenao.com/search.php?db=999&output_type=2&numres=10&api_key=" + Ref.SauceNAOKey +"&url=";
|
private static final String API_ROOT = "https://saucenao.com/search.php?db=999&output_type=2&numres=10&api_key=" + Ref.SauceNAOKey +"&url=";
|
||||||
NetworkE621 e621Sauce = new NetworkE621();
|
NetworkE6 e6Sauce = new NetworkE6();
|
||||||
private class SauceNAOResponseObject
|
private class SauceNAOResponseObject
|
||||||
{
|
{
|
||||||
List<SauceNAOResult> results;
|
List<SauceNAOResult> results;
|
||||||
@@ -40,7 +40,7 @@ public class NetworkSauceNAO
|
|||||||
if(sauceUrl.startsWith("https://e621.net/post/show/"))
|
if(sauceUrl.startsWith("https://e621.net/post/show/"))
|
||||||
{
|
{
|
||||||
System.out.println("id:" + sauceUrl.substring(26));
|
System.out.println("id:" + sauceUrl.substring(26));
|
||||||
return e621Sauce.getE621("id:" + sauceUrl.substring(27)).toString();
|
return e6Sauce.getE6("id:" + sauceUrl.substring(27)).toString();
|
||||||
}
|
}
|
||||||
return sauce.results.get(0).data.ext_urls[0];
|
return sauce.results.get(0).data.ext_urls[0];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user