|
6 | 6 | import net.dv8tion.jda.api.JDA;
|
7 | 7 | import net.dv8tion.jda.api.entities.MessageEmbed;
|
8 | 8 | import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
| 9 | +import net.dv8tion.jda.api.utils.cache.SnowflakeCacheView; |
9 | 10 | import org.apache.commons.text.StringEscapeUtils;
|
10 | 11 | import org.jetbrains.annotations.Nullable;
|
11 | 12 | import org.jooq.tools.StringUtils;
|
@@ -125,8 +126,8 @@ public void runRoutine(@Nonnull JDA jda) {
|
125 | 126 | private void sendRSS(JDA jda, RSSFeed feedConfig) {
|
126 | 127 | List<TextChannel> textChannels = getTextChannelsFromFeed(jda, feedConfig);
|
127 | 128 | if (textChannels.isEmpty()) {
|
128 |
| - logger.warn("Tried to send an RSS post, got empty response (channel {} not found)", |
129 |
| - feedConfig.targetChannelPattern()); |
| 129 | + logger.warn( |
| 130 | + "Tried to send an RSS post, but neither a target channel nor a fallback channel was found."); |
130 | 131 | return;
|
131 | 132 | }
|
132 | 133 |
|
@@ -326,18 +327,18 @@ private static boolean isValidDateFormat(Item rssItem, RSSFeed feedConfig) {
|
326 | 327 | * @return an {@link List} of the text channels found, or empty if none are found
|
327 | 328 | */
|
328 | 329 | private List<TextChannel> getTextChannelsFromFeed(JDA jda, RSSFeed feed) {
|
329 |
| - // Attempt to find the target channel, use the fallback otherwise |
330 |
| - if (targetChannelPatterns.containsKey(feed)) { |
331 |
| - return jda.getTextChannelCache() |
332 |
| - .stream() |
333 |
| - .filter(channel -> targetChannelPatterns.get(feed).test(channel.getName())) |
334 |
| - .toList(); |
335 |
| - } else { |
336 |
| - return jda.getTextChannelCache() |
337 |
| - .stream() |
338 |
| - .filter(channel -> fallbackChannelPattern.test(channel.getName())) |
339 |
| - .toList(); |
| 330 | + final SnowflakeCacheView<TextChannel> textChannelCache = jda.getTextChannelCache(); |
| 331 | + List<TextChannel> textChannels = textChannelCache.stream() |
| 332 | + .filter(channel -> targetChannelPatterns.get(feed).test(channel.getName())) |
| 333 | + .toList(); |
| 334 | + |
| 335 | + if (!textChannels.isEmpty()) { |
| 336 | + return textChannels; |
340 | 337 | }
|
| 338 | + |
| 339 | + return textChannelCache.stream() |
| 340 | + .filter(channel -> fallbackChannelPattern.test(channel.getName())) |
| 341 | + .toList(); |
341 | 342 | }
|
342 | 343 |
|
343 | 344 | /**
|
|
0 commit comments