Started #2
This commit is contained in:
parent
b94a689a1e
commit
f0959c1abe
2 changed files with 54 additions and 4 deletions
6
pom.xml
6
pom.xml
|
@ -134,6 +134,10 @@
|
||||||
<artifactId>slf4j-jdk14</artifactId>
|
<artifactId>slf4j-jdk14</artifactId>
|
||||||
<version>1.7.21</version>
|
<version>1.7.21</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
||||||
|
<artifactId>ButtonCore</artifactId>
|
||||||
|
<version>master-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -5,18 +5,23 @@ import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
|
||||||
|
import buttondevteam.bucket.core.TBMCCoreAPI;
|
||||||
import sx.blah.discord.api.*;
|
import sx.blah.discord.api.*;
|
||||||
import sx.blah.discord.api.events.IListener;
|
import sx.blah.discord.api.events.IListener;
|
||||||
import sx.blah.discord.handle.impl.events.ReadyEvent;
|
import sx.blah.discord.handle.impl.events.ReadyEvent;
|
||||||
import sx.blah.discord.util.DiscordException;
|
|
||||||
import sx.blah.discord.util.MissingPermissionsException;
|
|
||||||
import sx.blah.discord.util.RateLimitException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hello world!
|
* Hello world!
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
|
private static final String SubredditURL = "https://www.reddit.com/r/ChromaGamers";
|
||||||
|
private static boolean stop = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
try {
|
try {
|
||||||
|
@ -25,6 +30,13 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
cb.withToken(IOUtils.toString(getClass().getResourceAsStream("/Token.txt"), Charsets.UTF_8));
|
cb.withToken(IOUtils.toString(getClass().getResourceAsStream("/Token.txt"), Charsets.UTF_8));
|
||||||
IDiscordClient dc = cb.login();
|
IDiscordClient dc = cb.login();
|
||||||
dc.getDispatcher().registerListener(this);
|
dc.getDispatcher().registerListener(this);
|
||||||
|
Runnable r = new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
FlairGetterThreadMethod();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Thread t = new Thread(r);
|
||||||
|
t.start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Bukkit.getPluginManager().disablePlugin(this);
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
|
@ -39,4 +51,38 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
stop = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FlairGetterThreadMethod() {
|
||||||
|
while (!stop) {
|
||||||
|
try {
|
||||||
|
String body = TBMCCoreAPI.DownloadString(SubredditURL + ".json?limit=10"); // TODO: Save last announcement
|
||||||
|
JsonArray json = new JsonParser().parse(body).getAsJsonArray().get(1).getAsJsonObject().get("data")
|
||||||
|
.getAsJsonObject().get("children").getAsJsonArray();
|
||||||
|
for (Object obj : json) {
|
||||||
|
JsonObject item = (JsonObject) obj;
|
||||||
|
String author = item.get("data").getAsJsonObject().get("author").getAsString();
|
||||||
|
String post = item.get("data").getAsJsonObject().get("body").getAsString();
|
||||||
|
System.out.println("author: " + author);
|
||||||
|
System.out.println("post: " + post);
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch (InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(10000);
|
||||||
|
} catch (InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue