Skip to content

Hotfix: Rewrite logic for acquiring RSS target channels #1090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.utils.cache.SnowflakeCacheView;
import org.apache.commons.text.StringEscapeUtils;
import org.jetbrains.annotations.Nullable;
import org.jooq.tools.StringUtils;
Expand Down Expand Up @@ -125,8 +126,8 @@ public void runRoutine(@Nonnull JDA jda) {
private void sendRSS(JDA jda, RSSFeed feedConfig) {
List<TextChannel> textChannels = getTextChannelsFromFeed(jda, feedConfig);
if (textChannels.isEmpty()) {
logger.warn("Tried to send an RSS post, got empty response (channel {} not found)",
feedConfig.targetChannelPattern());
logger.warn(
"Tried to send an RSS post, but neither a target channel nor a fallback channel was found.");
return;
}

Expand Down Expand Up @@ -326,18 +327,18 @@ private static boolean isValidDateFormat(Item rssItem, RSSFeed feedConfig) {
* @return an {@link List} of the text channels found, or empty if none are found
*/
private List<TextChannel> getTextChannelsFromFeed(JDA jda, RSSFeed feed) {
// Attempt to find the target channel, use the fallback otherwise
if (targetChannelPatterns.containsKey(feed)) {
return jda.getTextChannelCache()
.stream()
.filter(channel -> targetChannelPatterns.get(feed).test(channel.getName()))
.toList();
} else {
return jda.getTextChannelCache()
.stream()
.filter(channel -> fallbackChannelPattern.test(channel.getName()))
.toList();
final SnowflakeCacheView<TextChannel> textChannelCache = jda.getTextChannelCache();
List<TextChannel> textChannels = textChannelCache.stream()
.filter(channel -> targetChannelPatterns.get(feed).test(channel.getName()))
.toList();

if (!textChannels.isEmpty()) {
return textChannels;
}

return textChannelCache.stream()
.filter(channel -> fallbackChannelPattern.test(channel.getName()))
.toList();
}

/**
Expand Down