7
7
import net .dv8tion .jda .api .entities .MessageEmbed ;
8
8
import net .dv8tion .jda .api .entities .channel .concrete .TextChannel ;
9
9
import org .apache .commons .text .StringEscapeUtils ;
10
+ import org .jetbrains .annotations .Nullable ;
10
11
import org .jooq .tools .StringUtils ;
11
12
import org .jsoup .Jsoup ;
12
13
import org .jsoup .nodes .Document ;
@@ -88,7 +89,12 @@ private void sendRSS(JDA jda, RSSFeed feed) {
88
89
textChannel .get ().sendMessageEmbeds (List .of (embed )).queue ();
89
90
});
90
91
91
- String lastDate = items .getFirst ().getPubDate ().orElseThrow ();
92
+ String lastDate = getLatestDate (items );
93
+
94
+ if (lastDate == null ) {
95
+ return ;
96
+ }
97
+
92
98
if (entry == null ) {
93
99
// Insert
94
100
database .write (context -> context .newRecord (RSS_FEED )
@@ -104,6 +110,26 @@ private void sendRSS(JDA jda, RSSFeed feed) {
104
110
.executeAsync ());
105
111
}
106
112
113
+ @ Nullable
114
+ private static String getLatestDate (List <Item > items ) {
115
+ String lastDate = null ;
116
+
117
+ for (Item item : items ) {
118
+ if (lastDate == null ) {
119
+ lastDate = item .getPubDate ().orElseThrow ();
120
+ continue ;
121
+ }
122
+
123
+ LocalDateTime formattedLastDate = getLocalDateTime (lastDate );
124
+ LocalDateTime itemDate = getLocalDateTime (item .getPubDate ().orElseThrow ());
125
+
126
+ if (itemDate .isAfter (formattedLastDate )) {
127
+ lastDate = item .getPubDate ().orElseThrow ();
128
+ }
129
+ }
130
+ return lastDate ;
131
+ }
132
+
107
133
private Optional <TextChannel > getTextChannelFromFeed (JDA jda , RSSFeed feed ) {
108
134
return jda .getTextChannelCache ()
109
135
.stream ()
0 commit comments