Skip to content

Commit b089ae3

Browse files
committed
Merge develop into feat/help-thread-stats
1 parent 4c75144 commit b089ae3

34 files changed

+1697
-144
lines changed

.github/workflows/docker-publish.yaml

Lines changed: 0 additions & 34 deletions
This file was deleted.

.woodpecker.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
when:
2+
branch:
3+
- develop
4+
- master
5+
event: push
6+
7+
steps:
8+
publish:
9+
image: eclipse-temurin:25-jdk
10+
environment:
11+
REGISTRY_USER:
12+
from_secret: REGISTRY_USER
13+
REGISTRY_PASSWORD:
14+
from_secret: REGISTRY_PASSWORD
15+
BRANCH_NAME: ${CI_COMMIT_BRANCH}
16+
commands:
17+
- echo ${CI_COMMIT_BRANCH}
18+
- ./gradlew jib
19+
20+
deploy:
21+
image: alpine
22+
depends_on:
23+
- publish
24+
environment:
25+
WATCHTOWER_TOKEN:
26+
from_secret: WATCHTOWER_TOKEN
27+
commands:
28+
- apk add --no-cache curl
29+
- |
30+
curl -H "Authorization: Bearer $WATCHTOWER_TOKEN" https://togetherjava.org:5003/v1/update

CLA.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ IF THE DISCLAIMER AND DAMAGE WAIVER MENTIONED IN SECTION 5. AND SECTION 6. CANNO
115115

116116
### Us
117117

118-
Name: Daniel Tischner (aka Zabuzard, acting on behalf of Together Java)
119-
120118
Organization: https://github.com/Together-Java
121119

122120
Contact: https://discord.com/invite/XXFUXzK

application/build.gradle

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ dependencies {
5757

5858
implementation 'io.mikael:urlbuilder:2.0.9'
5959

60-
implementation 'org.jsoup:jsoup:1.21.1'
60+
implementation 'org.jsoup:jsoup:1.22.1'
6161

6262
implementation 'org.scilab.forge:jlatexmath:1.0.7'
6363
implementation 'org.scilab.forge:jlatexmath-font-greek:1.0.7'
@@ -69,7 +69,7 @@ dependencies {
6969
implementation "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
7070
implementation "com.sigpwned:jackson-modules-java17-sealed-classes:2.19.0.0"
7171

72-
implementation 'com.github.freva:ascii-table:1.8.0'
72+
implementation 'com.github.freva:ascii-table:1.9.0'
7373

7474
implementation 'io.github.url-detector:url-detector:0.1.23'
7575

@@ -80,14 +80,13 @@ dependencies {
8080
implementation 'org.apache.commons:commons-text:1.15.0'
8181
implementation 'com.apptasticsoftware:rssreader:3.12.0'
8282

83-
testImplementation 'org.mockito:mockito-core:5.20.0'
83+
testImplementation 'org.mockito:mockito-core:5.21.0'
8484
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
8585
testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
8686
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
8787
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
8888

89-
implementation "com.theokanning.openai-gpt3-java:api:$chatGPTVersion"
90-
implementation "com.theokanning.openai-gpt3-java:service:$chatGPTVersion"
89+
implementation "com.openai:openai-java:$chatGPTVersion"
9190
}
9291

9392
application {

application/config.json.template

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,25 @@
194194
"videoLinkPattern": "http(s)?://www\\.youtube.com.*",
195195
"pollIntervalInMinutes": 10
196196
},
197+
"quoteBoardConfig": {
198+
"minimumReactionsToTrigger": 5,
199+
"channel": "quotes",
200+
"reactionEmoji": "⭐"
201+
},
197202
"memberCountCategoryPattern": "Info",
198203
"topHelpers": {
199204
"rolePattern": "Top Helper.*",
200205
"assignmentChannelPattern": "community-commands",
201206
"announcementChannelPattern": "hall-of-fame"
207+
},
208+
"dynamicVoiceChatConfig": {
209+
"dynamicChannelPatterns": [
210+
"Gaming",
211+
"Support/Studying Room",
212+
"Chit Chat"
213+
],
214+
"archiveCategoryPattern": "Voice Channel Archives",
215+
"cleanChannelsAmount": 20,
216+
"minimumChannelsAmount": 40
202217
}
203218
}

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public final class Config {
4848
private final RSSFeedsConfig rssFeedsConfig;
4949
private final String selectRolesChannelPattern;
5050
private final String memberCountCategoryPattern;
51+
private final QuoteBoardConfig quoteBoardConfig;
5152
private final TopHelpersConfig topHelpers;
53+
private final DynamicVoiceChatConfig dynamicVoiceChatConfig;
5254

5355
@SuppressWarnings("ConstructorWithTooManyParameters")
5456
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
@@ -102,7 +104,11 @@ private Config(@JsonProperty(value = "token", required = true) String token,
102104
@JsonProperty(value = "rssConfig", required = true) RSSFeedsConfig rssFeedsConfig,
103105
@JsonProperty(value = "selectRolesChannelPattern",
104106
required = true) String selectRolesChannelPattern,
105-
@JsonProperty(value = "topHelpers", required = true) TopHelpersConfig topHelpers) {
107+
@JsonProperty(value = "quoteBoardConfig",
108+
required = true) QuoteBoardConfig quoteBoardConfig,
109+
@JsonProperty(value = "topHelpers", required = true) TopHelpersConfig topHelpers,
110+
@JsonProperty(value = "dynamicVoiceChatConfig",
111+
required = true) DynamicVoiceChatConfig dynamicVoiceChatConfig) {
106112
this.token = Objects.requireNonNull(token);
107113
this.githubApiKey = Objects.requireNonNull(githubApiKey);
108114
this.databasePath = Objects.requireNonNull(databasePath);
@@ -137,7 +143,9 @@ private Config(@JsonProperty(value = "token", required = true) String token,
137143
this.featureBlacklistConfig = Objects.requireNonNull(featureBlacklistConfig);
138144
this.rssFeedsConfig = Objects.requireNonNull(rssFeedsConfig);
139145
this.selectRolesChannelPattern = Objects.requireNonNull(selectRolesChannelPattern);
146+
this.quoteBoardConfig = Objects.requireNonNull(quoteBoardConfig);
140147
this.topHelpers = Objects.requireNonNull(topHelpers);
148+
this.dynamicVoiceChatConfig = Objects.requireNonNull(dynamicVoiceChatConfig);
141149
}
142150

143151
/**
@@ -431,6 +439,18 @@ public String getSelectRolesChannelPattern() {
431439
return selectRolesChannelPattern;
432440
}
433441

442+
/**
443+
* The configuration of the quote messages config.
444+
*
445+
* <p>
446+
* >The configuration of the quote board feature. Quotes user selected messages.
447+
*
448+
* @return configuration of quote messages config
449+
*/
450+
public QuoteBoardConfig getQuoteBoardConfig() {
451+
return quoteBoardConfig;
452+
}
453+
434454
/**
435455
* Gets the pattern matching the category that is used to display the total member count.
436456
*
@@ -457,4 +477,13 @@ public RSSFeedsConfig getRSSFeedsConfig() {
457477
public TopHelpersConfig getTopHelpers() {
458478
return topHelpers;
459479
}
480+
481+
/**
482+
* Gets the dynamic voice chat configuration
483+
*
484+
* @return the dynamic voice chat configuration
485+
*/
486+
public DynamicVoiceChatConfig getDynamicVoiceChatConfig() {
487+
return dynamicVoiceChatConfig;
488+
}
460489
}
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+
import java.util.regex.Pattern;
8+
9+
/**
10+
* Configuration for the dynamic voice chat feature.
11+
*
12+
* @param archiveCategoryPattern the name of the Discord Guild category in which the archived
13+
* channels will go
14+
* @param cleanChannelsAmount the amount of channels to clean once a cleanup is triggered
15+
* @param minimumChannelsAmount the amount of voice channels for the archive category to have before
16+
* a cleanup triggers
17+
*/
18+
public record DynamicVoiceChatConfig(
19+
@JsonProperty(value = "dynamicChannelPatterns",
20+
required = true) List<Pattern> dynamicChannelPatterns,
21+
@JsonProperty(value = "archiveCategoryPattern",
22+
required = true) String archiveCategoryPattern,
23+
@JsonProperty(value = "cleanChannelsAmount") int cleanChannelsAmount,
24+
@JsonProperty(value = "minimumChannelsAmount", required = true) int minimumChannelsAmount) {
25+
26+
/**
27+
* Constructs an instance of {@code DynamicVoiceChatConfig} and throws if
28+
* {@code dynamicChannelPatterns} or @{code archiveCategoryPattern} is null.
29+
*/
30+
public DynamicVoiceChatConfig {
31+
Objects.requireNonNull(dynamicChannelPatterns);
32+
Objects.requireNonNull(archiveCategoryPattern);
33+
}
34+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.togetherjava.tjbot.config;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import com.fasterxml.jackson.annotation.JsonRootName;
5+
import org.apache.logging.log4j.LogManager;
6+
7+
import org.togetherjava.tjbot.features.basic.QuoteBoardForwarder;
8+
9+
import java.util.Objects;
10+
11+
/**
12+
* Configuration for the quote board feature, see {@link QuoteBoardForwarder}.
13+
*/
14+
@JsonRootName("quoteBoardConfig")
15+
public record QuoteBoardConfig(
16+
@JsonProperty(value = "minimumReactionsToTrigger", required = true) int minimumReactions,
17+
@JsonProperty(required = true) String channel,
18+
@JsonProperty(value = "reactionEmoji", required = true) String reactionEmoji) {
19+
20+
/**
21+
* Creates a QuoteBoardConfig.
22+
*
23+
* @param minimumReactions the minimum amount of reactions
24+
* @param channel the pattern for the board channel
25+
* @param reactionEmoji the emoji with which users should react to
26+
*/
27+
public QuoteBoardConfig {
28+
if (minimumReactions <= 0) {
29+
throw new IllegalArgumentException("minimumReactions must be greater than zero");
30+
}
31+
Objects.requireNonNull(channel);
32+
if (channel.isBlank()) {
33+
throw new IllegalArgumentException("channel must not be empty or blank");
34+
}
35+
Objects.requireNonNull(reactionEmoji);
36+
if (reactionEmoji.isBlank()) {
37+
throw new IllegalArgumentException("reactionEmoji must not be empty or blank");
38+
}
39+
LogManager.getLogger(QuoteBoardConfig.class)
40+
.debug("Quote-Board configs loaded: minimumReactions={}, channel='{}', reactionEmoji='{}'",
41+
minimumReactions, channel, reactionEmoji);
42+
}
43+
}

application/src/main/java/org/togetherjava/tjbot/features/Features.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.togetherjava.tjbot.db.Database;
99
import org.togetherjava.tjbot.features.basic.MemberCountDisplayRoutine;
1010
import org.togetherjava.tjbot.features.basic.PingCommand;
11+
import org.togetherjava.tjbot.features.basic.QuoteBoardForwarder;
1112
import org.togetherjava.tjbot.features.basic.RoleSelectCommand;
1213
import org.togetherjava.tjbot.features.basic.SlashCommandEducator;
1314
import org.togetherjava.tjbot.features.basic.SuggestionsUpDownVoter;
@@ -40,6 +41,8 @@
4041
import org.togetherjava.tjbot.features.mathcommands.TeXCommand;
4142
import org.togetherjava.tjbot.features.mathcommands.wolframalpha.WolframAlphaCommand;
4243
import org.togetherjava.tjbot.features.mediaonly.MediaOnlyChannelListener;
44+
import org.togetherjava.tjbot.features.messages.MessageCommand;
45+
import org.togetherjava.tjbot.features.messages.RewriteCommand;
4346
import org.togetherjava.tjbot.features.moderation.BanCommand;
4447
import org.togetherjava.tjbot.features.moderation.KickCommand;
4548
import org.togetherjava.tjbot.features.moderation.ModerationActionsStore;
@@ -78,6 +81,7 @@
7881
import org.togetherjava.tjbot.features.tophelper.TopHelpersMessageListener;
7982
import org.togetherjava.tjbot.features.tophelper.TopHelpersPurgeMessagesRoutine;
8083
import org.togetherjava.tjbot.features.tophelper.TopHelpersService;
84+
import org.togetherjava.tjbot.features.voicechat.DynamicVoiceChat;
8185

8286
import java.util.ArrayList;
8387
import java.util.Collection;
@@ -161,6 +165,10 @@ public static Collection<Feature> createFeatures(JDA jda, Database database, Con
161165
features.add(new CodeMessageManualDetection(codeMessageHandler));
162166
features.add(new SlashCommandEducator());
163167
features.add(new PinnedNotificationRemover(config));
168+
features.add(new QuoteBoardForwarder(config));
169+
170+
// Voice receivers
171+
features.add(new DynamicVoiceChat(config));
164172

165173
// Event receivers
166174
features.add(new RejoinModerationRoleListener(actionsStore, config));
@@ -204,6 +212,8 @@ public static Collection<Feature> createFeatures(JDA jda, Database database, Con
204212
features.add(new BookmarksCommand(bookmarksSystem));
205213
features.add(new ChatGptCommand(chatGptService, helpSystemHelper));
206214
features.add(new JShellCommand(jshellEval));
215+
features.add(new MessageCommand());
216+
features.add(new RewriteCommand(chatGptService));
207217
features.add(new HelpThreadStatsCommand(database));
208218

209219
FeatureBlacklist<Class<?>> blacklist = blacklistConfig.normal();

application/src/main/java/org/togetherjava/tjbot/features/MessageReceiver.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.dv8tion.jda.api.events.message.MessageDeleteEvent;
44
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
55
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
6+
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
67

78
import java.util.regex.Pattern;
89

@@ -56,4 +57,13 @@ public interface MessageReceiver extends Feature {
5657
* message that was deleted
5758
*/
5859
void onMessageDeleted(MessageDeleteEvent event);
60+
61+
/**
62+
* Triggered by the core system whenever a new reaction was added to a message in a text channel
63+
* of a guild the bot has been added to.
64+
*
65+
* @param event the event that triggered this, containing information about the corresponding
66+
* reaction that was added
67+
*/
68+
void onMessageReactionAdd(MessageReactionAddEvent event);
5969
}

0 commit comments

Comments
 (0)