Reverse order and URL fix

This commit is contained in:
Norbi Peti 2016-10-08 17:29:11 +02:00
parent ac851a845b
commit 7db8c283f5

View file

@ -88,8 +88,8 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
JsonArray json = new JsonParser().parse(body).getAsJsonObject().get("data").getAsJsonObject() JsonArray json = new JsonParser().parse(body).getAsJsonObject().get("data").getAsJsonObject()
.get("children").getAsJsonArray(); .get("children").getAsJsonArray();
StringBuilder msgsb = new StringBuilder(); StringBuilder msgsb = new StringBuilder();
for (Object obj : json) { for (int i = json.size() - 1; i >= 0; i--) {
JsonObject item = (JsonObject) obj; JsonObject item = json.get(i).getAsJsonObject();
final JsonObject data = item.get("data").getAsJsonObject(); final JsonObject data = item.get("data").getAsJsonObject();
String author = data.get("author").getAsString(); String author = data.get("author").getAsString();
String title = data.get("title").getAsString(); String title = data.get("title").getAsString();
@ -106,15 +106,12 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
distinguished = null; distinguished = null;
else else
distinguished = distinguishedjson.getAsString(); distinguished = distinguishedjson.getAsString();
String url = data.get("url").getAsString(); String permalink = "https://www.reddit.com" + data.get("permalink").getAsString();
long date = data.get("created_utc").getAsLong(); long date = data.get("created_utc").getAsLong();
if (date <= lastannouncementtime) if (date <= lastannouncementtime)
break; break;
System.out.println("author: " + author); msgsb.append("A new post was submitted to the subreddit by ").append(author).append("\n")
System.out.println("title: " + title); .append(permalink).append("\n");
System.out.println("distinguished: " + distinguished);
System.out.println("url: " + url);
msgsb.insert(0, "A new post was submitted to the subreddit by " + author);
lastannouncementtime = date; lastannouncementtime = date;
File file = new File("TBMC", "DiscordRedditLastAnnouncement.txt"); File file = new File("TBMC", "DiscordRedditLastAnnouncement.txt");
Files.write(lastannouncementtime + "", file, StandardCharsets.UTF_8); Files.write(lastannouncementtime + "", file, StandardCharsets.UTF_8);