Skip to content

Commit 9e129af

Browse files
squashed everything(kinda)
1 parent 2b0034b commit 9e129af

22 files changed

+360
-146
lines changed

.github/workflows/code-analysis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272

7373
# Initializes the CodeQL tools for scanning.
7474
- name: Initialize CodeQL
75-
uses: github/codeql-action/init@v1
75+
uses: github/codeql-action/init@v2
7676
with:
7777
languages: ${{ matrix.language }}
7878
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -83,7 +83,7 @@ jobs:
8383
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
8484
# If this step fails, then you should remove it and run the build manually (see below)
8585
#- name: Autobuild
86-
# uses: github/codeql-action/autobuild@v1
86+
# uses: github/codeql-action/autobuild@v2
8787

8888
# ℹ️ Command-line programs to run using the OS shell.
8989
# 📚 https://git.io/JvXDl
@@ -95,4 +95,4 @@ jobs:
9595
./gradlew build
9696
9797
- name: Perform CodeQL Analysis
98-
uses: github/codeql-action/analyze@v1
98+
uses: github/codeql-action/analyze@v2

application/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
buildscript {
22
dependencies {
3-
classpath 'org.xerial:sqlite-jdbc:3.42.0.0'
3+
classpath 'org.xerial:sqlite-jdbc:3.43.0.0'
44
}
55
}
66

77
plugins {
88
id 'application'
9-
id 'com.google.cloud.tools.jib' version '3.3.0'
9+
id 'com.google.cloud.tools.jib' version '3.4.0'
1010
id 'com.github.johnrengelman.shadow' version '8.1.0'
1111
id 'database-settings'
1212
}
@@ -74,7 +74,7 @@ dependencies {
7474

7575
implementation 'com.github.ben-manes.caffeine:caffeine:3.1.1'
7676

77-
implementation 'org.kohsuke:github-api:1.315'
77+
implementation 'org.kohsuke:github-api:1.316'
7878

7979
testImplementation 'org.mockito:mockito-core:5.3.1'
8080
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'

application/config.json.template

+19-7
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
"databasePath": "local-database.db",
55
"projectWebsite": "https://github.com/Together-Java/TJ-Bot",
66
"discordGuildInvite": "https://discord.com/invite/XXFUXzK",
7-
"modAuditLogChannelPattern": "mod_audit_log",
7+
"modAuditLogChannelPattern": "mod-audit-log",
88
"modMailChannelPattern": "modmail",
99
"mutedRolePattern": "Muted",
1010
"heavyModerationRolePattern": "Moderator",
1111
"softModerationRolePattern": "Moderator|Community Ambassador",
1212
"tagManageRolePattern": "Moderator|Community Ambassador|Top Helpers .+",
1313
"excludeCodeAutoDetectionRolePattern": "Top Helpers .+|Moderator|Community Ambassador|Expert",
1414
"suggestions": {
15-
"channelPattern": "tj_suggestions",
15+
"channelPattern": "tj-suggestions",
1616
"upVoteEmoteName": "peepo_yes",
1717
"downVoteEmoteName": "peepo_no"
1818
},
@@ -89,15 +89,27 @@
8989
"logInfoChannelWebhook": "<put_your_webhook_here>",
9090
"logErrorChannelWebhook": "<put_your_webhook_here>",
9191
"openaiApiKey": "<check pins in #tjbot_discussion for the key>",
92-
"sourceCodeBaseUrl": "<https://github.com/<your_account_here>/<your_repo_here>/blob/master/application/src/main/java/>"
92+
"sourceCodeBaseUrl": "https://github.com/Together-Java/TJ-Bot/blob/master/application/src/main/java/",
9393
"jshell": {
9494
"baseUrl": "<put_jshell_rest_api_url_here>",
9595
"rateLimitWindowSeconds": 10,
9696
"rateLimitRequestsInWindow": 3
97+
},
98+
"helperPruneConfig": {
99+
"roleFullLimit": 100,
100+
"roleFullThreshold": 95,
101+
"pruneMemberAmount": 7,
102+
"inactivateAfterDays": 90,
103+
"recentlyJoinedDays": 4
104+
},
105+
"featureBlacklist": {
106+
"normal": [
107+
],
108+
"special": [
109+
]
97110
}
98-
"oofsAndLmaos": {
99-
"oofEmojiName": ":oof:"
100-
"lmaoEmojiName": ":lmao"
101-
"starboardChannelId": <put_channel_id_here>
111+
"starboard": {
112+
"emojiNames" : ["star"],
113+
"channelPattern": "starboard"
102114
}
103115
}

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

+43-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ public final class Config {
3939
private final String openaiApiKey;
4040
private final String sourceCodeBaseUrl;
4141
private final JShellConfig jshell;
42-
private final OofsAndLmaosConfig oofsAndLmaos;
42+
private final StarboardConfig starboard;
43+
private final HelperPruneConfig helperPruneConfig;
44+
private final FeatureBlacklistConfig featureBlacklistConfig;
45+
4346

4447
@SuppressWarnings("ConstructorWithTooManyParameters")
4548
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
@@ -77,8 +80,12 @@ private Config(@JsonProperty(value = "token", required = true) String token,
7780
required = true) String logErrorChannelWebhook,
7881
@JsonProperty(value = "openaiApiKey", required = true) String openaiApiKey,
7982
@JsonProperty(value = "sourceCodeBaseUrl", required = true) String sourceCodeBaseUrl,
80-
@JsonProperty(value = "jshell", required = true) JShellConfig jshell,
81-
@JsonProperty(value = "oofsAndLmaos", required = true) OofsAndLmaosConfig oofsAndLmaos) {
83+
@JsonProperty(value = "jshell", required = true) JShellConfig jshell,
84+
@JsonProperty(value = "starboard", required = true) StarboardConfig starboard,
85+
@JsonProperty(value = "helperPruneConfig",
86+
required = true) HelperPruneConfig helperPruneConfig,
87+
@JsonProperty(value = "featureBlacklist",
88+
required = true) FeatureBlacklistConfig featureBlacklistConfig) {
8289
this.token = Objects.requireNonNull(token);
8390
this.gistApiKey = Objects.requireNonNull(gistApiKey);
8491
this.databasePath = Objects.requireNonNull(databasePath);
@@ -104,7 +111,9 @@ private Config(@JsonProperty(value = "token", required = true) String token,
104111
this.openaiApiKey = Objects.requireNonNull(openaiApiKey);
105112
this.sourceCodeBaseUrl = Objects.requireNonNull(sourceCodeBaseUrl);
106113
this.jshell = Objects.requireNonNull(jshell);
107-
this.oofsAndLmaos = Objects.requireNonNull(oofsAndLmaos);
114+
this.starboard = Objects.requireNonNull(starboard);
115+
this.helperPruneConfig = Objects.requireNonNull(helperPruneConfig);
116+
this.featureBlacklistConfig = Objects.requireNonNull(featureBlacklistConfig);
108117
}
109118

110119
/**
@@ -344,8 +353,35 @@ public String getSourceCodeBaseUrl() {
344353
*/
345354
public JShellConfig getJshell() {
346355
return jshell;
347-
}
348-
public OofsAndLmaosConfig getOofsAndLmaos() {
349-
return oofsAndLmaos;
356+
}
357+
358+
/**
359+
* Gets the config for the Starboard. The starboard displays certain messages in a special
360+
* channel {@link StarboardConfig#channelPattern()} if a user reacts with one of the recognized
361+
* emojis{@link StarboardConfig#emojiNames()}
362+
*
363+
* @return the config of the Starboard
364+
*/
365+
public StarboardConfig getStarboard() {
366+
return starboard;
367+
}
368+
369+
/**
370+
* Gets the config for automatic pruning of helper roles.
371+
*
372+
* @return the configuration
373+
*/
374+
public HelperPruneConfig getHelperPruneConfig() {
375+
return helperPruneConfig;
376+
}
377+
378+
/**
379+
* The configuration of blacklisted features.
380+
*
381+
* @return configuration of blacklisted features
382+
*/
383+
public FeatureBlacklistConfig getFeatureBlacklistConfig() {
384+
return featureBlacklistConfig;
385+
350386
}
351387
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.togetherjava.tjbot.config;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
5+
import java.util.Set;
6+
7+
/**
8+
* Blacklist of features, use {@link FeatureBlacklist#isEnabled(T)} to test if a feature is enabled.
9+
* If a feature is blacklisted, it won't be enabled by the bot, and so will be ignored.
10+
*
11+
* @param <T> the type of the feature identifier
12+
*/
13+
public class FeatureBlacklist<T> {
14+
private final Set<T> featureIdentifierBlacklist;
15+
16+
/**
17+
* Creates a feature blacklist
18+
*
19+
* @param featureIdentifierBlacklist a set of identifiers which are blacklisted
20+
*/
21+
@JsonCreator
22+
public FeatureBlacklist(Set<T> featureIdentifierBlacklist) {
23+
this.featureIdentifierBlacklist = Set.copyOf(featureIdentifierBlacklist);
24+
}
25+
26+
/**
27+
* Returns if a feature is enabled or not.
28+
*
29+
* @param featureId the identifier of the feature
30+
* @return true if a feature is enabled, false otherwise
31+
*/
32+
public boolean isEnabled(T featureId) {
33+
return !featureIdentifierBlacklist.contains(featureId);
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.togetherjava.tjbot.config;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import java.util.Objects;
6+
7+
/**
8+
* Configuration of the feature blacklist, any feature present here will be disabled.
9+
*
10+
* @param normal the normal features, which are present in
11+
* {@link org.togetherjava.tjbot.features.Features}
12+
* @param special the special features, which require special code
13+
*/
14+
public record FeatureBlacklistConfig(
15+
@JsonProperty(value = "normal", required = true) FeatureBlacklist<Class<?>> normal,
16+
@JsonProperty(value = "special", required = true) FeatureBlacklist<String> special) {
17+
18+
/**
19+
* Creates a FeatureBlacklistConfig.
20+
*
21+
* @param normal the list of normal features, must be not null
22+
* @param special the list of special features, must be not null
23+
*/
24+
public FeatureBlacklistConfig {
25+
Objects.requireNonNull(normal);
26+
Objects.requireNonNull(special);
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.togetherjava.tjbot.config;
2+
3+
4+
/**
5+
* Config for automatic pruning of helper roles, see
6+
* {@link org.togetherjava.tjbot.features.help.AutoPruneHelperRoutine}.
7+
*
8+
* @param roleFullLimit if a helper role contains that many users, it is considered full and pruning
9+
* must occur
10+
* @param roleFullThreshold if a helper role contains that many users, pruning will start to occur
11+
* to prevent reaching the limit
12+
* @param pruneMemberAmount amount of users to remove from helper roles during a prune
13+
* @param inactivateAfterDays after how many days of inactivity a user is eligible for pruning
14+
* @param recentlyJoinedDays if a user is with the server for just this amount of days, they are
15+
* protected from pruning
16+
*/
17+
public record HelperPruneConfig(int roleFullLimit, int roleFullThreshold, int pruneMemberAmount,
18+
int inactivateAfterDays, int recentlyJoinedDays) {
19+
}

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

-30
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.togetherjava.tjbot.config;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonRootName;
5+
6+
import java.util.List;
7+
import java.util.Objects;
8+
import java.util.regex.Pattern;
9+
10+
/**
11+
* Starboard Config
12+
*
13+
* @param emojiNames the List of emojis which are recognized by the starboard
14+
* @param channelPattern the pattern of the channel with the starboard
15+
*/
16+
@JsonRootName("starboard")
17+
public record StarboardConfig(List<String> emojiNames, Pattern channelPattern) {
18+
/**
19+
* Creates a Starboard config.
20+
*
21+
* @param emojiNames the List of emojis which are recognized by the starboard
22+
* @param channelPattern the pattern of the channel with the starboard
23+
*/
24+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
25+
public StarboardConfig {
26+
Objects.requireNonNull(emojiNames);
27+
Objects.requireNonNull(channelPattern);
28+
}
29+
30+
/**
31+
* Gets the list of emotes that are recognized by the starboard feature. A message that is
32+
* reacted on with an emote in this list will be reposted in a special channel
33+
* {@link #channelPattern()}.
34+
* <p>
35+
* Empty to deactivate the feature.
36+
*
37+
* @return The List of emojis recognized by the starboard
38+
*/
39+
@Override
40+
public List<String> emojiNames() {
41+
return emojiNames;
42+
}
43+
44+
/**
45+
* Gets the pattern of the channel with the starboard. Deactivate by using a non-existent
46+
* channel name.
47+
*
48+
* @return the pattern of the channel with the starboard
49+
*/
50+
public Pattern channelPattern() {
51+
return channelPattern;
52+
}
53+
}

0 commit comments

Comments
 (0)