-
-
Notifications
You must be signed in to change notification settings - Fork 98
Description
Problem
Our RSS feed feature sometimes posts entries that essentially consist only of a YouTube video. But it posts those as embed currently (which is okay for normal text-messages), but that prevents Discord from adding the in-discord video preview with the embedded player.
Regular Text - okay ✅
YouTube link as embed - not okay ❌
YouTube desired player 🎯
Solution
The fix is simple. We want to post such a message as normal text message instead of embed. I.e.
channel.sendMessage("https://www.youtube.com/shorts/Lu8Lc20nGuQ").queue()
Instead of what we currently do, which is something like:
channel.sendMessageEmbeds(List.of(embed)).queue()
Details
The logic for all of this currently is at RssHandlerRoutine.java
methods postItem
and constructEmbedMessage
.
Former needs to be slightly tweaked to not assume only being able to send embeds. Therefore, constructEmbedMessage
should be changed to return an object of type MessageCreateData
instead of Embed
(and renamed to something like constructMessage
or constructItemMessage
).
postItem
can then be changed from:
MessageEmbed embed = constructEmbedMessage(rssItem, feedConfig).build();
textChannels.forEach(channel -> channel.sendMessageEmbeds(List.of(embed)).queue());
to
MessageCreateData message = constructMessage(rssItem, feedConfig);
textChannels.forEach(channel -> channel.sendMessage(message).queue());
The method constructMessage
(currently constructEmbedMessage
) will then receive the logic to check for youtube links. If no YouTube link, it will use the existing logic (creating an embed).
Therefore, we want to check the link provided in the Item
, i.e. item.getLink()
. If that starts with http://www.youtube.com
or https://www.youtube.com
, we want to make a normal text message instead:
if (item.getLink().isPresent() && item.getLink().startsWith(...)) {
return MessageCreateData.fromContent(link);
}
Use Config (optional)
Ideally, we do not hardcode the youtube-pattern but utilize our config for that. See RSSFeedsConfig.java
, which currently handles this part of the config.json
(and config.json.template
):
"rssConfig": {
"feeds": [
{
"url": "https://wiki.openjdk.org/spaces/createrssfeed.action?types=page&types=comment&types=blogpost&types=mail&types=attachment&spaces=JDKUpdates&maxResults=15&title=%5BJDK+Updates%5D+All+Content+Feed&publicFeed=true",
"targetChannelPattern": "java-news-and-changes",
"dateFormatterPattern": "yyyy-MM-dd'T'HH:mm:ssX"
}
],
"fallbackChannelPattern": "java-news-and-changes",
"pollIntervalInMinutes": 10
}
What we want is to add a new parameter here, something like:
"videoLinkPattern": "http(s)?://www\\.youtube.com.*"
This pattern would then end up being interpreted as REGEX pattern by our check in RssHandlerRoutine
. Something like:
isVideoLink = Pattern.compile(config.videoLinkPattern()).asMatchPredicate();
and then
if (item.getLink().filter(isVideoLink).orElse(false)) {
return MessageCreateData.fromContent(item.getLink().orElseThrow());
}
(the class already does something very similar with fallbackChannelPattern
, so that can act as example)