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()) {
YTFeedConfig config = ytfeeds.get(s);
YTFeed feed = config.getFeed();
feed.post();
feed.post(config);
config.setLastPosted(feed.getLastVideo(), feed.getLastVideoTimestamp());
}
}

View File

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