Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 11 additions & 1 deletion application/config.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,15 @@
"archiveCategoryPattern": "Voice Channel Archives",
"cleanChannelsAmount": 20,
"minimumChannelsAmount": 40
}
},
"numericScoreConfig": [
{
"forumId": "<the_forum_channel_id>",
"upVoteEmoteName": "peepo_yes",
"downVoteEmoteName": "peepo_no",
"zeroScore": "0️⃣",
"positiveScores": ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"],
"negativeScores": ["🟡", "🟠", "🔴"]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public final class Config {
private final QuoteBoardConfig quoteBoardConfig;
private final TopHelpersConfig topHelpers;
private final DynamicVoiceChatConfig dynamicVoiceChatConfig;
private final List<NumericScoreConfig> numericScoreConfigs;

@SuppressWarnings("ConstructorWithTooManyParameters")
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
Expand Down Expand Up @@ -108,7 +109,9 @@ private Config(@JsonProperty(value = "token", required = true) String token,
required = true) QuoteBoardConfig quoteBoardConfig,
@JsonProperty(value = "topHelpers", required = true) TopHelpersConfig topHelpers,
@JsonProperty(value = "dynamicVoiceChatConfig",
required = true) DynamicVoiceChatConfig dynamicVoiceChatConfig) {
required = true) DynamicVoiceChatConfig dynamicVoiceChatConfig,
@JsonProperty(value = "numericScoreConfig",
required = true) List<NumericScoreConfig> numericScoreConfigs) {
this.token = Objects.requireNonNull(token);
this.githubApiKey = Objects.requireNonNull(githubApiKey);
this.databasePath = Objects.requireNonNull(databasePath);
Expand Down Expand Up @@ -146,6 +149,7 @@ private Config(@JsonProperty(value = "token", required = true) String token,
this.quoteBoardConfig = Objects.requireNonNull(quoteBoardConfig);
this.topHelpers = Objects.requireNonNull(topHelpers);
this.dynamicVoiceChatConfig = Objects.requireNonNull(dynamicVoiceChatConfig);
this.numericScoreConfigs = Objects.requireNonNull(numericScoreConfigs);
}

/**
Expand Down Expand Up @@ -486,4 +490,13 @@ public TopHelpersConfig getTopHelpers() {
public DynamicVoiceChatConfig getDynamicVoiceChatConfig() {
return dynamicVoiceChatConfig;
}

/**
* Gets the list of numeric score configurations for project forum channels.
*
* @return the numeric score configurations
*/
public List<NumericScoreConfig> getNumericScoreConfigs() {
return Collections.unmodifiableList(numericScoreConfigs);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.togetherjava.tjbot.config;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;

import org.togetherjava.tjbot.features.projects.ProjectsNumericScoreListener;

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

/**
* Configuration for the numeric score feature on forum posts, see
* {@link ProjectsNumericScoreListener}.
*
* @param forumId the ID of the Discord forum channel to apply the score system to
* @param upVoteEmoteName the name of the emoji used for upvoting (custom emoji name or raw unicode)
* @param downVoteEmoteName the name of the emoji used for downvoting (custom emoji name or raw
* unicode)
* @param zeroScore the emoji to display when the score is zero
* @param positiveScores the emojis to display for positive scores, ordered from +1 upwards
* @param negativeScores the emojis to display for negative scores, ordered from -1 downwards
*/
@JsonRootName("numericScoreConfig")
public record NumericScoreConfig(@JsonProperty(value = "forumId", required = true) long forumId,
@JsonProperty(value = "upVoteEmoteName", required = true) String upVoteEmoteName,
@JsonProperty(value = "downVoteEmoteName", required = true) String downVoteEmoteName,
@JsonProperty(value = "zeroScore", required = true) String zeroScore,
@JsonProperty(value = "positiveScores", required = true) List<String> positiveScores,
@JsonProperty(value = "negativeScores", required = true) List<String> negativeScores) {

/**
* Creates a NumericScoreConfig and validates its fields.
*/
public NumericScoreConfig {
Objects.requireNonNull(upVoteEmoteName);
Objects.requireNonNull(downVoteEmoteName);
Objects.requireNonNull(zeroScore);
positiveScores = List.copyOf(Objects.requireNonNull(positiveScores));
negativeScores = List.copyOf(Objects.requireNonNull(negativeScores));
if (positiveScores.isEmpty()) {
throw new IllegalArgumentException("positiveScores must not be empty");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.togetherjava.tjbot.features.moderation.scam.ScamHistoryPurgeRoutine;
import org.togetherjava.tjbot.features.moderation.scam.ScamHistoryStore;
import org.togetherjava.tjbot.features.moderation.temp.TemporaryModerationRoutine;
import org.togetherjava.tjbot.features.projects.ProjectsNumericScoreListener;
import org.togetherjava.tjbot.features.projects.ProjectsThreadCreatedListener;
import org.togetherjava.tjbot.features.reminder.RemindRoutine;
import org.togetherjava.tjbot.features.reminder.ReminderCommand;
Expand Down Expand Up @@ -182,6 +183,7 @@ public static Collection<Feature> createFeatures(JDA jda, Database database, Con
features.add(helpThreadCreatedListener);
features.add(new HelpThreadLifecycleListener(helpSystemHelper, database));
features.add(new ProjectsThreadCreatedListener(config));
features.add(new ProjectsNumericScoreListener(config));

// Message context commands
features.add(new TransferQuestionCommand(config, chatGptService));
Expand Down
Loading
Loading