4
4
import com .apptasticsoftware .rssreader .RssReader ;
5
5
import net .dv8tion .jda .api .EmbedBuilder ;
6
6
import net .dv8tion .jda .api .JDA ;
7
- import net .dv8tion .jda .api .entities .MessageEmbed ;
8
7
import net .dv8tion .jda .api .entities .channel .concrete .TextChannel ;
9
8
import net .dv8tion .jda .api .utils .cache .SnowflakeCacheView ;
9
+ import net .dv8tion .jda .api .utils .messages .MessageCreateData ;
10
10
import org .apache .commons .text .StringEscapeUtils ;
11
11
import org .jetbrains .annotations .Nullable ;
12
12
import org .jooq .tools .StringUtils ;
@@ -79,6 +79,7 @@ public final class RSSHandlerRoutine implements Routine {
79
79
private final RssReader rssReader ;
80
80
private final RSSFeedsConfig config ;
81
81
private final Predicate <String > fallbackChannelPattern ;
82
+ private final Predicate <String > isVideoLink ;
82
83
private final Map <RSSFeed , Predicate <String >> targetChannelPatterns ;
83
84
private final int interval ;
84
85
private final Database database ;
@@ -95,6 +96,7 @@ public RSSHandlerRoutine(Config config, Database database) {
95
96
this .database = database ;
96
97
this .fallbackChannelPattern =
97
98
Pattern .compile (this .config .fallbackChannelPattern ()).asMatchPredicate ();
99
+ isVideoLink = Pattern .compile (this .config .videoLinkPattern ()).asMatchPredicate ();
98
100
this .targetChannelPatterns = new HashMap <>();
99
101
this .config .feeds ().forEach (feed -> {
100
102
if (feed .targetChannelPattern () != null ) {
@@ -155,7 +157,7 @@ private void sendRSS(JDA jda, RSSFeed feedConfig) {
155
157
}
156
158
rssItems .reversed ()
157
159
.stream ()
158
- .filter (shouldItemBePosted .get ())
160
+ .filter (shouldItemBePosted .orElseThrow ())
159
161
.forEachOrdered (item -> postItem (textChannels , item , feedConfig ));
160
162
}
161
163
@@ -241,8 +243,8 @@ private Optional<ZonedDateTime> getLatestPostDateFromItems(List<Item> items,
241
243
* @param feedConfig the RSS feed configuration
242
244
*/
243
245
private void postItem (List <TextChannel > textChannels , Item rssItem , RSSFeed feedConfig ) {
244
- MessageEmbed embed = constructEmbedMessage (rssItem , feedConfig ). build ( );
245
- textChannels .forEach (channel -> channel .sendMessageEmbeds ( List . of ( embed ) ).queue ());
246
+ MessageCreateData message = constructMessage (rssItem , feedConfig );
247
+ textChannels .forEach (channel -> channel .sendMessage ( message ).queue ());
246
248
}
247
249
248
250
/**
@@ -346,13 +348,18 @@ private List<TextChannel> getTextChannelsFromFeed(JDA jda, RSSFeed feed) {
346
348
}
347
349
348
350
/**
349
- * Provides the {@link EmbedBuilder} from an RSS item used for sending RSS posts.
351
+ * Provides the message from an RSS item used for sending RSS posts.
350
352
*
351
353
* @param item the RSS item to construct the embed message from
352
354
* @param feedConfig the configuration of the RSS feed
353
- * @return the constructed {@link EmbedBuilder} containing information from the RSS item
355
+ * @return the constructed message containing information from the RSS item
354
356
*/
355
- private static EmbedBuilder constructEmbedMessage (Item item , RSSFeed feedConfig ) {
357
+ private MessageCreateData constructMessage (Item item , RSSFeed feedConfig ) {
358
+ if (item .getLink ().filter (isVideoLink ).isPresent ()) {
359
+ // Automatic video previews are created on normal messages, not on embeds
360
+ return MessageCreateData .fromContent (item .getLink ().orElseThrow ());
361
+ }
362
+
356
363
final EmbedBuilder embedBuilder = new EmbedBuilder ();
357
364
String title = item .getTitle ().orElse ("No title" );
358
365
String titleLink = item .getLink ().orElse ("" );
@@ -381,7 +388,7 @@ private static EmbedBuilder constructEmbedMessage(Item item, RSSFeed feedConfig)
381
388
embedBuilder .setDescription ("No description" );
382
389
}
383
390
384
- return embedBuilder ;
391
+ return MessageCreateData . fromEmbeds ( embedBuilder . build ()) ;
385
392
}
386
393
387
394
/**
0 commit comments