Skip to content

Commit 6d2848e

Browse files
authored
Merge branch 'develop' into feat/meta-data-v2
2 parents ca6d4d4 + 9ff5cb8 commit 6d2848e

File tree

112 files changed

+2692
-1097
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+2692
-1097
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text eol=lf

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @Together-Java/moderators @Together-Java/maintainers
1+
* @Together-Java/maintainers

application/build.gradle

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
buildscript {
22
dependencies {
3-
classpath 'org.xerial:sqlite-jdbc:3.44.0.0'
3+
classpath 'org.xerial:sqlite-jdbc:3.45.0.0'
44
}
55
}
66

@@ -46,9 +46,9 @@ dependencies {
4646
implementation project(':utils')
4747
implementation project(':formatter')
4848

49-
implementation 'net.dv8tion:JDA:5.0.0-alpha.20'
49+
implementation 'net.dv8tion:JDA:5.0.0-beta.21'
5050

51-
implementation 'org.apache.logging.log4j:log4j-core:2.22.0'
51+
implementation 'org.apache.logging.log4j:log4j-core:2.23.0'
5252
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j18-impl:2.18.0'
5353

5454
implementation 'club.minnced:discord-webhooks:0.8.2'
@@ -67,16 +67,20 @@ dependencies {
6767
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion"
6868
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:$jacksonVersion"
6969
implementation "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
70+
implementation "com.sigpwned:jackson-modules-java17-sealed-classes:0.0.0"
7071

7172
implementation 'com.github.freva:ascii-table:1.8.0'
7273

7374
implementation 'io.github.url-detector:url-detector:0.1.23'
7475

7576
implementation 'com.github.ben-manes.caffeine:caffeine:3.1.1'
7677

77-
implementation 'org.kohsuke:github-api:1.318'
78+
implementation 'org.kohsuke:github-api:1.321'
7879

79-
testImplementation 'org.mockito:mockito-core:5.3.1'
80+
implementation 'org.apache.commons:commons-text:1.11.0'
81+
implementation 'com.apptasticsoftware:rssreader:3.6.0'
82+
83+
testImplementation 'org.mockito:mockito-core:5.11.0'
8084
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
8185
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.0'
8286
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

application/config.json.template

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"token": "<put_your_token_here>",
3-
"gistApiKey": "<your_gist_personal_access_token>",
3+
"githubApiKey": "<your_github_personal_access_token>",
44
"databasePath": "local-database.db",
55
"projectWebsite": "https://github.com/Together-Java/TJ-Bot",
66
"discordGuildInvite": "https://discord.com/invite/XXFUXzK",
@@ -86,6 +86,8 @@
8686
"wsf",
8787
"wsh"
8888
],
89+
"githubReferencingEnabledChannelPattern": "server-suggestions|tjbot-discussion|modernjava-discussion",
90+
"githubRepositories": [403389278,587644974,601602394],
8991
"logInfoChannelWebhook": "<put_your_webhook_here>",
9092
"logErrorChannelWebhook": "<put_your_webhook_here>",
9193
"openaiApiKey": "<check pins in #tjbot_discussion for the key>",
@@ -95,18 +97,23 @@
9597
"rateLimitWindowSeconds": 10,
9698
"rateLimitRequestsInWindow": 3
9799
},
98-
"helperPruneConfig": {
99-
"roleFullLimit": 100,
100-
"roleFullThreshold": 95,
101-
"pruneMemberAmount": 7,
102-
"inactivateAfterDays": 90,
103-
"recentlyJoinedDays": 4
104-
},
105100
"featureBlacklist": {
106101
"normal": [
107102
],
108103
"special": [
109104
]
110105
},
111-
"selectRolesChannelPattern": "select-your-roles"
106+
"selectRolesChannelPattern": "select-your-roles",
107+
"rssConfig": {
108+
"feeds": [
109+
{
110+
"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&amp;publicFeed=true",
111+
"targetChannelPattern": "java-news-and-changes",
112+
"dateFormatterPattern": "yyyy-MM-dd'T'HH:mm:ssX"
113+
}
114+
],
115+
"fallbackChannelPattern": "java-news-and-changes",
116+
"pollIntervalInMinutes": 10
117+
},
118+
"memberCountCategoryPattern": "Info"
112119
}

application/src/main/java/org/togetherjava/tjbot/config/Config.java

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
import java.util.List;
1212
import java.util.Objects;
1313

14+
1415
/**
1516
* Configuration of the application. Create instances using {@link #load(Path)}.
1617
*/
1718
public final class Config {
1819
private final String token;
19-
private final String gistApiKey;
20+
private final String githubApiKey;
2021
private final String databasePath;
2122
private final String projectWebsite;
2223
private final String discordGuildInvite;
@@ -36,17 +37,20 @@ public final class Config {
3637
private final String mediaOnlyChannelPattern;
3738
private final String logInfoChannelWebhook;
3839
private final String logErrorChannelWebhook;
40+
private final String githubReferencingEnabledChannelPattern;
41+
private final List<Long> githubRepositories;
3942
private final String openaiApiKey;
4043
private final String sourceCodeBaseUrl;
4144
private final JShellConfig jshell;
42-
private final HelperPruneConfig helperPruneConfig;
4345
private final FeatureBlacklistConfig featureBlacklistConfig;
46+
private final RSSFeedsConfig rssFeedsConfig;
4447
private final String selectRolesChannelPattern;
48+
private final String memberCountCategoryPattern;
4549

4650
@SuppressWarnings("ConstructorWithTooManyParameters")
4751
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
4852
private Config(@JsonProperty(value = "token", required = true) String token,
49-
@JsonProperty(value = "gistApiKey", required = true) String gistApiKey,
53+
@JsonProperty(value = "githubApiKey", required = true) String githubApiKey,
5054
@JsonProperty(value = "databasePath", required = true) String databasePath,
5155
@JsonProperty(value = "projectWebsite", required = true) String projectWebsite,
5256
@JsonProperty(value = "discordGuildInvite", required = true) String discordGuildInvite,
@@ -77,19 +81,25 @@ private Config(@JsonProperty(value = "token", required = true) String token,
7781
required = true) String logInfoChannelWebhook,
7882
@JsonProperty(value = "logErrorChannelWebhook",
7983
required = true) String logErrorChannelWebhook,
84+
@JsonProperty(value = "githubReferencingEnabledChannelPattern",
85+
required = true) String githubReferencingEnabledChannelPattern,
86+
@JsonProperty(value = "githubRepositories",
87+
required = true) List<Long> githubRepositories,
8088
@JsonProperty(value = "openaiApiKey", required = true) String openaiApiKey,
8189
@JsonProperty(value = "sourceCodeBaseUrl", required = true) String sourceCodeBaseUrl,
8290
@JsonProperty(value = "jshell", required = true) JShellConfig jshell,
83-
@JsonProperty(value = "helperPruneConfig",
84-
required = true) HelperPruneConfig helperPruneConfig,
91+
@JsonProperty(value = "memberCountCategoryPattern",
92+
required = true) String memberCountCategoryPattern,
8593
@JsonProperty(value = "featureBlacklist",
8694
required = true) FeatureBlacklistConfig featureBlacklistConfig,
95+
@JsonProperty(value = "rssConfig", required = true) RSSFeedsConfig rssFeedsConfig,
8796
@JsonProperty(value = "selectRolesChannelPattern",
8897
required = true) String selectRolesChannelPattern) {
8998
this.token = Objects.requireNonNull(token);
90-
this.gistApiKey = Objects.requireNonNull(gistApiKey);
99+
this.githubApiKey = Objects.requireNonNull(githubApiKey);
91100
this.databasePath = Objects.requireNonNull(databasePath);
92101
this.projectWebsite = Objects.requireNonNull(projectWebsite);
102+
this.memberCountCategoryPattern = Objects.requireNonNull(memberCountCategoryPattern);
93103
this.discordGuildInvite = Objects.requireNonNull(discordGuildInvite);
94104
this.modAuditLogChannelPattern = Objects.requireNonNull(modAuditLogChannelPattern);
95105
this.modMailChannelPattern = Objects.requireNonNull(modMailChannelPattern);
@@ -108,11 +118,14 @@ private Config(@JsonProperty(value = "token", required = true) String token,
108118
this.blacklistedFileExtension = Objects.requireNonNull(blacklistedFileExtension);
109119
this.logInfoChannelWebhook = Objects.requireNonNull(logInfoChannelWebhook);
110120
this.logErrorChannelWebhook = Objects.requireNonNull(logErrorChannelWebhook);
121+
this.githubReferencingEnabledChannelPattern =
122+
Objects.requireNonNull(githubReferencingEnabledChannelPattern);
123+
this.githubRepositories = Objects.requireNonNull(githubRepositories);
111124
this.openaiApiKey = Objects.requireNonNull(openaiApiKey);
112125
this.sourceCodeBaseUrl = Objects.requireNonNull(sourceCodeBaseUrl);
113126
this.jshell = Objects.requireNonNull(jshell);
114-
this.helperPruneConfig = Objects.requireNonNull(helperPruneConfig);
115127
this.featureBlacklistConfig = Objects.requireNonNull(featureBlacklistConfig);
128+
this.rssFeedsConfig = Objects.requireNonNull(rssFeedsConfig);
116129
this.selectRolesChannelPattern = Objects.requireNonNull(selectRolesChannelPattern);
117130
}
118131

@@ -167,15 +180,15 @@ public String getToken() {
167180
}
168181

169182
/**
170-
* Gets the API Key of GitHub to upload pastes via the API.
183+
* Gets the API Key of GitHub.
171184
*
172-
* @return the upload services API Key
185+
* @return the API Key
173186
* @see <a href=
174187
* "https://docs.github.com/en/enterprise-server@3.4/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token">Create
175188
* a GitHub key</a>
176189
*/
177-
public String getGistApiKey() {
178-
return gistApiKey;
190+
public String getGitHubApiKey() {
191+
return githubApiKey;
179192
}
180193

181194
/**
@@ -308,6 +321,20 @@ public List<String> getBlacklistedFileExtensions() {
308321
return Collections.unmodifiableList(blacklistedFileExtension);
309322
}
310323

324+
/**
325+
* The REGEX pattern used to identify the channels that support GitHub issue referencing.
326+
*/
327+
public String getGitHubReferencingEnabledChannelPattern() {
328+
return githubReferencingEnabledChannelPattern;
329+
}
330+
331+
/**
332+
* The list of repositories that are searched when referencing a GitHub issue.
333+
*/
334+
public List<Long> getGitHubRepositories() {
335+
return githubRepositories;
336+
}
337+
311338
/**
312339
* The Discord channel webhook for posting log messages with levels INFO, DEBUG and TRACE.
313340
*
@@ -355,15 +382,6 @@ public JShellConfig getJshell() {
355382
return jshell;
356383
}
357384

358-
/**
359-
* Gets the config for automatic pruning of helper roles.
360-
*
361-
* @return the configuration
362-
*/
363-
public HelperPruneConfig getHelperPruneConfig() {
364-
return helperPruneConfig;
365-
}
366-
367385
/**
368386
* The configuration of blacklisted features.
369387
*
@@ -382,4 +400,22 @@ public FeatureBlacklistConfig getFeatureBlacklistConfig() {
382400
public String getSelectRolesChannelPattern() {
383401
return selectRolesChannelPattern;
384402
}
403+
404+
/**
405+
* Gets the pattern matching the category that is used to display the total member count.
406+
*
407+
* @return the categories name types
408+
*/
409+
public String getMemberCountCategoryPattern() {
410+
return memberCountCategoryPattern;
411+
}
412+
413+
/**
414+
* Gets the RSS feeds configuration.
415+
*
416+
* @return the RSS feeds configuration
417+
*/
418+
public RSSFeedsConfig getRSSFeedsConfig() {
419+
return rssFeedsConfig;
420+
}
385421
}

application/src/main/java/org/togetherjava/tjbot/config/FeatureBlacklist.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package org.togetherjava.tjbot.config;
22

33
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
46

57
import java.util.Set;
8+
import java.util.function.Function;
9+
import java.util.stream.Stream;
610

711
/**
812
* Blacklist of features, use {@link FeatureBlacklist#isEnabled(T)} to test if a feature is enabled.
@@ -13,6 +17,8 @@
1317
public class FeatureBlacklist<T> {
1418
private final Set<T> featureIdentifierBlacklist;
1519

20+
private static final Logger logger = LoggerFactory.getLogger(FeatureBlacklist.class);
21+
1622
/**
1723
* Creates a feature blacklist
1824
*
@@ -32,4 +38,25 @@ public FeatureBlacklist(Set<T> featureIdentifierBlacklist) {
3238
public boolean isEnabled(T featureId) {
3339
return !featureIdentifierBlacklist.contains(featureId);
3440
}
41+
42+
/**
43+
* Filters features stream to only having enabled features and logs any disabled features.
44+
*
45+
* @param features the feature stream to be filtered
46+
* @param idExtractor function to get the class name of an object
47+
* @return stream of features that are enabled
48+
*/
49+
public <F> Stream<F> filterStream(Stream<F> features,
50+
Function<? super F, ? extends T> idExtractor) {
51+
return features.filter(f -> {
52+
T id = idExtractor.apply(f);
53+
if (!this.isEnabled(id)) {
54+
logger.info("Feature {} is disabled", id);
55+
return false;
56+
}
57+
return true;
58+
});
59+
}
60+
61+
3562
}

application/src/main/java/org/togetherjava/tjbot/config/HelperPruneConfig.java

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.togetherjava.tjbot.config;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import javax.annotation.Nullable;
6+
7+
import java.util.Objects;
8+
9+
/**
10+
* Represents an RSS feed configuration.
11+
*/
12+
public record RSSFeed(@JsonProperty(value = "url", required = true) String url,
13+
@JsonProperty(value = "targetChannelPattern") @Nullable String targetChannelPattern,
14+
@JsonProperty(value = "dateFormatterPattern",
15+
required = true) String dateFormatterPattern) {
16+
17+
/**
18+
* Constructs an RSSFeed object.
19+
*
20+
* @param url the URL of the RSS feed
21+
* @param targetChannelPattern the target channel pattern
22+
* @param dateFormatterPattern the date formatter pattern
23+
* @throws NullPointerException if any of the parameters are null
24+
*/
25+
public RSSFeed {
26+
Objects.requireNonNull(url);
27+
Objects.requireNonNull(targetChannelPattern);
28+
Objects.requireNonNull(dateFormatterPattern);
29+
}
30+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.togetherjava.tjbot.config;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import java.util.List;
6+
import java.util.Objects;
7+
8+
/**
9+
* Represents the configuration for an RSS feed, which includes the list of feeds to subscribe to, a
10+
* pattern for identifying Java news channels, and the interval (in minutes) for polling the feeds.
11+
*
12+
* @param feeds The list of RSS feeds to subscribe to.
13+
* @param fallbackChannelPattern The pattern used to identify the fallback text channel to use.
14+
* @param pollIntervalInMinutes The interval (in minutes) for polling the RSS feeds for updates.
15+
*/
16+
public record RSSFeedsConfig(@JsonProperty(value = "feeds", required = true) List<RSSFeed> feeds,
17+
@JsonProperty(value = "fallbackChannelPattern",
18+
required = true) String fallbackChannelPattern,
19+
@JsonProperty(value = "pollIntervalInMinutes", required = true) int pollIntervalInMinutes) {
20+
21+
/**
22+
* Constructs a new {@link RSSFeedsConfig}.
23+
*
24+
* @param feeds The list of RSS feeds to subscribe to.
25+
* @param fallbackChannelPattern The pattern used to identify the fallback text channel to use.
26+
* @param pollIntervalInMinutes The interval (in minutes) for polling the RSS feeds for updates.
27+
* @throws NullPointerException if any of the parameters (feeds or fallbackChannelPattern) are
28+
* null
29+
*/
30+
public RSSFeedsConfig {
31+
Objects.requireNonNull(feeds);
32+
Objects.requireNonNull(fallbackChannelPattern);
33+
}
34+
}

0 commit comments

Comments
 (0)