Fixed new video not posting to Discord

This commit is contained in:
2026-06-27 02:11:07 -05:00
parent 0d5b23211a
commit 6ab258e765
2 changed files with 93 additions and 33 deletions

View File

@@ -275,7 +275,7 @@ public class BiscuitGuild {
for(String s : ytfeeds.keySet()) { for(String s : ytfeeds.keySet()) {
YTFeedConfig config = ytfeeds.get(s); YTFeedConfig config = ytfeeds.get(s);
YTFeed feed = config.getFeed(); YTFeed feed = config.getFeed();
feed.post(); feed.post(config);
config.setLastPosted(feed.getLastVideo(), feed.getLastVideoTimestamp()); config.setLastPosted(feed.getLastVideo(), feed.getLastVideoTimestamp());
} }
} }

View File

@@ -74,38 +74,98 @@ public class YTFeed {
lastVideoTimestamp = link; lastVideoTimestamp = link;
} }
public void post(){ public void post(YTFeedConfig config) {
List<YTEntry> ytentries = getEntries(); List<YTEntry> ytentries = getEntries();
int index = 0;
int lastVidIndex = -1; if (ytentries == null || ytentries.isEmpty()) {
for(YTEntry entry : ytentries) { return;
String link = entry.getURL(); }
if(link.equals(lastVideo)) {
lastVidIndex = index; YTEntry newestEntry = ytentries.getLast();
}
index++; if (newestEntry.getTimestamp() == null || newestEntry.getTimestamp().trim().isEmpty()) {
} guild.error("Could not retrieve YouTube feed newest timestamp for " + alias + "!");
index = 0; return;
for(YTEntry entry : ytentries) { }
String timestamp = entry.getTimestamp();
Instant entryTimestamp = parseTimestamp(timestamp); Instant lastInstant = getLastInstant();
if(entryTimestamp == null) {
guild.error("Could not retrieve YouTube feed entry timestamp!"); if (lastInstant == null) {
return; guild.log("Recovering missing YouTube feed last timestamp for " + alias + ".");
}
if(getLastInstant() == null) { if (lastVideo != null && !lastVideo.trim().isEmpty()) {
guild.error("Could not retrieve YouTube feed last timestamp!"); for (YTEntry entry : ytentries) {
return; if (entry.getURL().equals(lastVideo)) {
} String recoveredTimestamp = entry.getTimestamp();
if(index > lastVidIndex && entryTimestamp.isAfter(getLastInstant())) {
String link = entry.getURL(); if (recoveredTimestamp == null || recoveredTimestamp.trim().isEmpty()) {
lastVideo = link; guild.error("Could not recover timestamp for saved YouTube video for " + alias + ".");
lastVideoTimestamp = timestamp; return;
MessageText.send(channel, message); }
MessageText.send(channel, entry.getEmbedMessage());
} lastVideoTimestamp = recoveredTimestamp;
index++; config.setLastPosted(lastVideo, recoveredTimestamp);
} lastInstant = parseTimestamp(recoveredTimestamp);
guild.log("Recovered YouTube feed last timestamp for " + alias + ".");
break;
}
}
}
if (lastInstant == null) {
guild.log("Could not recover saved YouTube video timestamp for " + alias
+ ". Initializing to newest entry without posting backlog.");
lastVideo = newestEntry.getURL();
lastVideoTimestamp = newestEntry.getTimestamp();
config.setLastPosted(lastVideo, lastVideoTimestamp);
return;
}
}
int index = 0;
int lastVidIndex = -1;
for (YTEntry entry : ytentries) {
String link = entry.getURL();
if (link.equals(lastVideo)) {
lastVidIndex = index;
break;
}
index++;
}
index = 0;
for (YTEntry entry : ytentries) {
String timestamp = entry.getTimestamp();
Instant entryTimestamp = parseTimestamp(timestamp);
if (entryTimestamp == null) {
guild.error("Could not retrieve YouTube feed entry timestamp for " + alias + "!");
return;
}
if (index > lastVidIndex && entryTimestamp.isAfter(lastInstant)) {
String link = entry.getURL();
MessageText.send(channel, message);
MessageText.send(channel, entry.getEmbedMessage());
lastVideo = link;
lastVideoTimestamp = timestamp;
config.setLastPosted(link, timestamp);
lastInstant = entryTimestamp;
}
index++;
}
} }
public List<YTEntry> getEntries() { public List<YTEntry> getEntries() {