|
|
@ -7,7 +7,6 @@ import net.dv8tion.jda.api.entities.TextChannel; |
|
|
|
import org.json.JSONArray; |
|
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.Executors; |
|
|
|
import java.util.concurrent.ScheduledExecutorService; |
|
|
@ -26,16 +25,15 @@ public class SauceProvider { |
|
|
|
private static MessageEmbed notFoundEmbed = null; |
|
|
|
|
|
|
|
public SauceProvider(int timer) { |
|
|
|
this(); |
|
|
|
lastKnownSauce = this.getNewestIndex(); |
|
|
|
ScheduledExecutorService sauceScheduler = Executors.newScheduledThreadPool(1); |
|
|
|
sauceScheduler.scheduleAtFixedRate(this::provideSauce, 0, timer, TimeUnit.SECONDS); |
|
|
|
new Thread(this::initSauceProviding).start(); |
|
|
|
} |
|
|
|
|
|
|
|
public SauceProvider() { |
|
|
|
if (lastKnownSauce == -1) { |
|
|
|
this.lastKnownSauce = this.getNewestIndex(); |
|
|
|
} |
|
|
|
public SauceProvider(int timer, int lastKnownSauce) { |
|
|
|
this(timer); |
|
|
|
this.lastKnownSauce = lastKnownSauce; |
|
|
|
} |
|
|
|
|
|
|
|
public static MessageEmbed getSauce(int index) { |
|
|
@ -131,7 +129,9 @@ public class SauceProvider { |
|
|
|
|
|
|
|
private int getNewestIndex() { |
|
|
|
JSONObject result = getParsedSauceData("https://r34-json.herokuapp.com/posts?limit=1&q=index"); |
|
|
|
return result.getJSONArray("posts").getJSONObject(0).getInt("id"); |
|
|
|
int id = result.getJSONArray("posts").getJSONObject(0).getInt("id"); |
|
|
|
Logger.logDebug("Neuste Soßen-ID: " + id); |
|
|
|
return id; |
|
|
|
} |
|
|
|
|
|
|
|
private static JSONObject getParsedSauceData(String url) { |
|
|
|