Skip to content

Java RSS Feed #1037

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 54 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
630c02f
wip: initial commit
nateweisz Feb 22, 2024
03036e4
style(spotlessApply): run uncalled task
christolis Feb 22, 2024
28b6160
fix: register routine in features list
christolis Feb 22, 2024
b494cd3
feat: update config.json.template
christolis Feb 22, 2024
c746bfa
wip(rss-config): change config design
christolis Feb 22, 2024
cbaa40b
feat: make targetChannelPattern into a Map
christolis Feb 22, 2024
dbcd59b
refactor: don't hardcode number
christolis Feb 22, 2024
6e5f34a
feat: improve constructEmbedMessage
christolis Feb 22, 2024
2d93e9f
feat: improve the description constructing
christolis Feb 22, 2024
2da57d6
feat: increase MAX_CONTENTS to 300
christolis Feb 22, 2024
066b2e9
wip: changes
christolis Feb 22, 2024
728d08b
feat(rss-feed): convert polling interval to be configurable
nateweisz Feb 22, 2024
cae7e38
feat: improve date parsing
christolis Feb 22, 2024
9eb905b
feat: update config.json.template
christolis Feb 22, 2024
a75be80
feat: improve date handling and add embed timestamp
christolis Feb 22, 2024
faf8e85
fix: malformed `config.json.template`
nateweisz Feb 28, 2024
b77955f
fix: now correctly finds the latest date
nateweisz Feb 28, 2024
d068973
feat: improve date handling and add embed timestamp
christolis Feb 22, 2024
964c080
fix: now correctly finds the latest date
nateweisz Feb 28, 2024
5a19fe9
feat: you can now optionally declare a specific channel for a feed to…
nateweisz Feb 29, 2024
0a3c293
finished javadoc todos
nateweisz Feb 29, 2024
b52e95e
improved embed
nateweisz Feb 29, 2024
66a4350
feat(rss-routine): working version
christolis Feb 29, 2024
56eb1b8
feat(rss-routine): increase MAX_CONTENTS to 1000
christolis Feb 29, 2024
0c0770a
refactor(rss-routine): rename to RSSHandlerRoutine
christolis Feb 29, 2024
9629b35
docs(rss-routine): add JavaDocs for constructor and class
christolis Feb 29, 2024
19befa6
feat: add @NotNull annotation
christolis Feb 29, 2024
fc682ca
Update RSSHandlerRoutine.java
nateweisz Feb 29, 2024
184aee7
fix: reverse feed so it posts in correct order
nateweisz Feb 29, 2024
44df6b4
refactor: use variable types instead of var
christolis Feb 29, 2024
39a6986
feat: use fetchAny() instead of fetch()
christolis Feb 29, 2024
061ab50
fix(rss-handler): remove redundant empty check
christolis Feb 29, 2024
15510bf
refactor(rss-handler): remove AtomicReference usage
christolis Feb 29, 2024
31bf197
resolve a couple issues
nateweisz Mar 1, 2024
851fb06
refactor(rss): switch to using a record for the config
christolis Mar 1, 2024
2b6bc7c
feat: rename to fallbackChannelPattern
christolis Mar 1, 2024
e3028fa
refactor: remove unnecessary throws exception in method signature
christolis Mar 1, 2024
34974e5
docs: add a few missing parameters and fix typos
christolis Mar 1, 2024
e284315
refactor: reduce try-catch scope and added clarifying comment
christolis Mar 1, 2024
9deaa02
perf: use Stream instead of StringBuilder
christolis Mar 1, 2024
237d6ba
refactor: put fallback case into an else statement
christolis Mar 1, 2024
b48c327
refactor: switch to Map#containsKey() for targetChannelPatterns
christolis Mar 1, 2024
e257595
feat: modularize sendRss() method and improve variable names
christolis Mar 1, 2024
18135e6
refactor: remove star import
christolis Mar 1, 2024
48f0e76
fix: add Objects#requireNonNull() on rssConfig
christolis Mar 5, 2024
6f9e2dd
changes
christolis Mar 10, 2024
7f14bc2
feat: improvements from code reviews
christolis Mar 10, 2024
82fd9b7
feat: add DateTimeParseException in signature
christolis Mar 20, 2024
32f5f9b
refactor: use .orElseThrow() instead of .get()
christolis Apr 4, 2024
cf67e4d
fixed missing coma after rss configuration
nateweisz Apr 9, 2024
2fb249f
fix(rss): feeds support multiple channels
nateweisz Apr 9, 2024
0c7231a
Optional<List<TextChannel>> -> List<TextChannel>
nateweisz Apr 9, 2024
49bdf53
extract item post predicate to seperate function
nateweisz Apr 9, 2024
dfcd27e
various changes from null to optional
nateweisz Apr 9, 2024
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
3 changes: 3 additions & 0 deletions application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ dependencies {

implementation 'org.kohsuke:github-api:1.321'

implementation 'org.apache.commons:commons-text:1.11.0'
implementation 'com.apptasticsoftware:rssreader:3.6.0'

testImplementation 'org.mockito:mockito-core:5.11.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.0'
Expand Down
15 changes: 13 additions & 2 deletions application/config.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@
"special": [
]
},
"memberCountCategoryPattern": "Info",
"selectRolesChannelPattern": "select-your-roles"
"selectRolesChannelPattern": "select-your-roles",
"rssConfig": {
"feeds": [
{
"url": "<rss_feed_url>",
"targetChannelPattern": "<target_channel_pattern>",
"dateFormatterPattern": "EEE, dd MMM yyyy HH:mm:ss zzz"
}
],
"fallbackChannelPattern": "<fallback_channel_pattern>",
"pollIntervalInMinutes": 10
},
"memberCountCategoryPattern": "Info"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.List;
import java.util.Objects;


/**
* Configuration of the application. Create instances using {@link #load(Path)}.
*/
Expand Down Expand Up @@ -42,6 +43,7 @@ public final class Config {
private final String sourceCodeBaseUrl;
private final JShellConfig jshell;
private final FeatureBlacklistConfig featureBlacklistConfig;
private final RSSFeedsConfig rssFeedsConfig;
private final String selectRolesChannelPattern;
private final String memberCountCategoryPattern;

Expand Down Expand Up @@ -90,6 +92,7 @@ private Config(@JsonProperty(value = "token", required = true) String token,
required = true) String memberCountCategoryPattern,
@JsonProperty(value = "featureBlacklist",
required = true) FeatureBlacklistConfig featureBlacklistConfig,
@JsonProperty(value = "rssConfig", required = true) RSSFeedsConfig rssFeedsConfig,
@JsonProperty(value = "selectRolesChannelPattern",
required = true) String selectRolesChannelPattern) {
this.token = Objects.requireNonNull(token);
Expand Down Expand Up @@ -122,6 +125,7 @@ private Config(@JsonProperty(value = "token", required = true) String token,
this.sourceCodeBaseUrl = Objects.requireNonNull(sourceCodeBaseUrl);
this.jshell = Objects.requireNonNull(jshell);
this.featureBlacklistConfig = Objects.requireNonNull(featureBlacklistConfig);
this.rssFeedsConfig = Objects.requireNonNull(rssFeedsConfig);
this.selectRolesChannelPattern = Objects.requireNonNull(selectRolesChannelPattern);
}

Expand Down Expand Up @@ -405,4 +409,13 @@ public String getSelectRolesChannelPattern() {
public String getMemberCountCategoryPattern() {
return memberCountCategoryPattern;
}

/**
* Gets the RSS feeds configuration.
*
* @return the RSS feeds configuration
*/
public RSSFeedsConfig getRSSFeedsConfig() {
return rssFeedsConfig;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.togetherjava.tjbot.config;

import com.fasterxml.jackson.annotation.JsonProperty;

import javax.annotation.Nullable;

import java.util.Objects;

/**
* Represents an RSS feed configuration.
*/
public record RSSFeed(@JsonProperty(value = "url", required = true) String url,
@JsonProperty(value = "targetChannelPattern") @Nullable String targetChannelPattern,
@JsonProperty(value = "dateFormatterPattern",
required = true) String dateFormatterPattern) {

/**
* Constructs an RSSFeed object.
*
* @param url the URL of the RSS feed
* @param targetChannelPattern the target channel pattern
* @param dateFormatterPattern the date formatter pattern
* @throws NullPointerException if any of the parameters are null
*/
public RSSFeed {
Objects.requireNonNull(url);
Objects.requireNonNull(targetChannelPattern);
Objects.requireNonNull(dateFormatterPattern);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.togetherjava.tjbot.config;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;
import java.util.Objects;

/**
* Represents the configuration for an RSS feed, which includes the list of feeds to subscribe to, a
* pattern for identifying Java news channels, and the interval (in minutes) for polling the feeds.
*
* @param feeds The list of RSS feeds to subscribe to.
* @param fallbackChannelPattern The pattern used to identify the fallback text channel to use.
* @param pollIntervalInMinutes The interval (in minutes) for polling the RSS feeds for updates.
*/
public record RSSFeedsConfig(@JsonProperty(value = "feeds", required = true) List<RSSFeed> feeds,
@JsonProperty(value = "fallbackChannelPattern",
required = true) String fallbackChannelPattern,
@JsonProperty(value = "pollIntervalInMinutes", required = true) int pollIntervalInMinutes) {

/**
* Constructs a new {@link RSSFeedsConfig}.
*
* @param feeds The list of RSS feeds to subscribe to.
* @param fallbackChannelPattern The pattern used to identify the fallback text channel to use.
* @param pollIntervalInMinutes The interval (in minutes) for polling the RSS feeds for updates.
* @throws NullPointerException if any of the parameters (feeds or fallbackChannelPattern) are
* null
*/
public RSSFeedsConfig {
Objects.requireNonNull(feeds);
Objects.requireNonNull(fallbackChannelPattern);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.togetherjava.tjbot.features.github.GitHubCommand;
import org.togetherjava.tjbot.features.github.GitHubReference;
import org.togetherjava.tjbot.features.help.*;
import org.togetherjava.tjbot.features.javamail.RSSHandlerRoutine;
import org.togetherjava.tjbot.features.jshell.JShellCommand;
import org.togetherjava.tjbot.features.jshell.JShellEval;
import org.togetherjava.tjbot.features.mathcommands.TeXCommand;
Expand Down Expand Up @@ -109,6 +110,7 @@ public static Collection<Feature> createFeatures(JDA jda, Database database, Con
features.add(new HelpThreadAutoArchiver(helpSystemHelper));
features.add(new LeftoverBookmarksCleanupRoutine(bookmarksSystem));
features.add(new MemberCountDisplayRoutine(config));
features.add(new RSSHandlerRoutine(config, database));

// Message receivers
features.add(new TopHelpersMessageListener(database, config));
Expand Down
Loading