44import com .apptasticsoftware .rssreader .RssReader ;
55import net .dv8tion .jda .api .EmbedBuilder ;
66import net .dv8tion .jda .api .JDA ;
7- import net .dv8tion .jda .api .entities .MessageEmbed ;
87import net .dv8tion .jda .api .entities .channel .concrete .TextChannel ;
98import net .dv8tion .jda .api .utils .cache .SnowflakeCacheView ;
9+ import net .dv8tion .jda .api .utils .messages .MessageCreateData ;
1010import org .apache .commons .text .StringEscapeUtils ;
1111import org .jetbrains .annotations .Nullable ;
1212import org .jooq .tools .StringUtils ;
@@ -79,6 +79,7 @@ public final class RSSHandlerRoutine implements Routine {
7979 private final RssReader rssReader ;
8080 private final RSSFeedsConfig config ;
8181 private final Predicate <String > fallbackChannelPattern ;
82+ private final Predicate <String > isVideoLink ;
8283 private final Map <RSSFeed , Predicate <String >> targetChannelPatterns ;
8384 private final int interval ;
8485 private final Database database ;
@@ -95,6 +96,7 @@ public RSSHandlerRoutine(Config config, Database database) {
9596 this .database = database ;
9697 this .fallbackChannelPattern =
9798 Pattern .compile (this .config .fallbackChannelPattern ()).asMatchPredicate ();
99+ isVideoLink = Pattern .compile (this .config .videoLinkPattern ()).asMatchPredicate ();
98100 this .targetChannelPatterns = new HashMap <>();
99101 this .config .feeds ().forEach (feed -> {
100102 if (feed .targetChannelPattern () != null ) {
@@ -155,7 +157,7 @@ private void sendRSS(JDA jda, RSSFeed feedConfig) {
155157 }
156158 rssItems .reversed ()
157159 .stream ()
158- .filter (shouldItemBePosted .get ())
160+ .filter (shouldItemBePosted .orElseThrow ())
159161 .forEachOrdered (item -> postItem (textChannels , item , feedConfig ));
160162 }
161163
@@ -241,8 +243,8 @@ private Optional<ZonedDateTime> getLatestPostDateFromItems(List<Item> items,
241243 * @param feedConfig the RSS feed configuration
242244 */
243245 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 ());
246248 }
247249
248250 /**
@@ -346,13 +348,18 @@ private List<TextChannel> getTextChannelsFromFeed(JDA jda, RSSFeed feed) {
346348 }
347349
348350 /**
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.
350352 *
351353 * @param item the RSS item to construct the embed message from
352354 * @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
354356 */
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+
356363 final EmbedBuilder embedBuilder = new EmbedBuilder ();
357364 String title = item .getTitle ().orElse ("No title" );
358365 String titleLink = item .getLink ().orElse ("" );
@@ -381,7 +388,7 @@ private static EmbedBuilder constructEmbedMessage(Item item, RSSFeed feedConfig)
381388 embedBuilder .setDescription ("No description" );
382389 }
383390
384- return embedBuilder ;
391+ return MessageCreateData . fromEmbeds ( embedBuilder . build ()) ;
385392 }
386393
387394 /**
0 commit comments