Skip to content

Commit

Permalink
squashed everything(kinda)
Browse files Browse the repository at this point in the history
  • Loading branch information
java-coding-prodigy committed Oct 6, 2023
1 parent 2b0034b commit 9e129af
Show file tree
Hide file tree
Showing 22 changed files with 360 additions and 146 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:

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

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -95,4 +95,4 @@ jobs:
./gradlew build
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
6 changes: 3 additions & 3 deletions application/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
dependencies {
classpath 'org.xerial:sqlite-jdbc:3.42.0.0'
classpath 'org.xerial:sqlite-jdbc:3.43.0.0'
}
}

plugins {
id 'application'
id 'com.google.cloud.tools.jib' version '3.3.0'
id 'com.google.cloud.tools.jib' version '3.4.0'
id 'com.github.johnrengelman.shadow' version '8.1.0'
id 'database-settings'
}
Expand Down Expand Up @@ -74,7 +74,7 @@ dependencies {

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

implementation 'org.kohsuke:github-api:1.315'
implementation 'org.kohsuke:github-api:1.316'

testImplementation 'org.mockito:mockito-core:5.3.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
Expand Down
26 changes: 19 additions & 7 deletions application/config.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"databasePath": "local-database.db",
"projectWebsite": "https://github.com/Together-Java/TJ-Bot",
"discordGuildInvite": "https://discord.com/invite/XXFUXzK",
"modAuditLogChannelPattern": "mod_audit_log",
"modAuditLogChannelPattern": "mod-audit-log",
"modMailChannelPattern": "modmail",
"mutedRolePattern": "Muted",
"heavyModerationRolePattern": "Moderator",
"softModerationRolePattern": "Moderator|Community Ambassador",
"tagManageRolePattern": "Moderator|Community Ambassador|Top Helpers .+",
"excludeCodeAutoDetectionRolePattern": "Top Helpers .+|Moderator|Community Ambassador|Expert",
"suggestions": {
"channelPattern": "tj_suggestions",
"channelPattern": "tj-suggestions",
"upVoteEmoteName": "peepo_yes",
"downVoteEmoteName": "peepo_no"
},
Expand Down Expand Up @@ -89,15 +89,27 @@
"logInfoChannelWebhook": "<put_your_webhook_here>",
"logErrorChannelWebhook": "<put_your_webhook_here>",
"openaiApiKey": "<check pins in #tjbot_discussion for the key>",
"sourceCodeBaseUrl": "<https://github.com/<your_account_here>/<your_repo_here>/blob/master/application/src/main/java/>"
"sourceCodeBaseUrl": "https://github.com/Together-Java/TJ-Bot/blob/master/application/src/main/java/",
"jshell": {
"baseUrl": "<put_jshell_rest_api_url_here>",
"rateLimitWindowSeconds": 10,
"rateLimitRequestsInWindow": 3
},
"helperPruneConfig": {
"roleFullLimit": 100,
"roleFullThreshold": 95,
"pruneMemberAmount": 7,
"inactivateAfterDays": 90,
"recentlyJoinedDays": 4
},
"featureBlacklist": {
"normal": [
],
"special": [
]
}
"oofsAndLmaos": {
"oofEmojiName": ":oof:"
"lmaoEmojiName": ":lmao"
"starboardChannelId": <put_channel_id_here>
"starboard": {
"emojiNames" : ["star"],
"channelPattern": "starboard"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public final class Config {
private final String openaiApiKey;
private final String sourceCodeBaseUrl;
private final JShellConfig jshell;
private final OofsAndLmaosConfig oofsAndLmaos;
private final StarboardConfig starboard;
private final HelperPruneConfig helperPruneConfig;
private final FeatureBlacklistConfig featureBlacklistConfig;


@SuppressWarnings("ConstructorWithTooManyParameters")
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
Expand Down Expand Up @@ -77,8 +80,12 @@ private Config(@JsonProperty(value = "token", required = true) String token,
required = true) String logErrorChannelWebhook,
@JsonProperty(value = "openaiApiKey", required = true) String openaiApiKey,
@JsonProperty(value = "sourceCodeBaseUrl", required = true) String sourceCodeBaseUrl,
@JsonProperty(value = "jshell", required = true) JShellConfig jshell,
@JsonProperty(value = "oofsAndLmaos", required = true) OofsAndLmaosConfig oofsAndLmaos) {
@JsonProperty(value = "jshell", required = true) JShellConfig jshell,
@JsonProperty(value = "starboard", required = true) StarboardConfig starboard,
@JsonProperty(value = "helperPruneConfig",
required = true) HelperPruneConfig helperPruneConfig,
@JsonProperty(value = "featureBlacklist",
required = true) FeatureBlacklistConfig featureBlacklistConfig) {
this.token = Objects.requireNonNull(token);
this.gistApiKey = Objects.requireNonNull(gistApiKey);
this.databasePath = Objects.requireNonNull(databasePath);
Expand All @@ -104,7 +111,9 @@ private Config(@JsonProperty(value = "token", required = true) String token,
this.openaiApiKey = Objects.requireNonNull(openaiApiKey);
this.sourceCodeBaseUrl = Objects.requireNonNull(sourceCodeBaseUrl);
this.jshell = Objects.requireNonNull(jshell);
this.oofsAndLmaos = Objects.requireNonNull(oofsAndLmaos);
this.starboard = Objects.requireNonNull(starboard);
this.helperPruneConfig = Objects.requireNonNull(helperPruneConfig);
this.featureBlacklistConfig = Objects.requireNonNull(featureBlacklistConfig);
}

/**
Expand Down Expand Up @@ -344,8 +353,35 @@ public String getSourceCodeBaseUrl() {
*/
public JShellConfig getJshell() {
return jshell;
}
public OofsAndLmaosConfig getOofsAndLmaos() {
return oofsAndLmaos;
}

/**
* Gets the config for the Starboard. The starboard displays certain messages in a special
* channel {@link StarboardConfig#channelPattern()} if a user reacts with one of the recognized
* emojis{@link StarboardConfig#emojiNames()}
*
* @return the config of the Starboard
*/
public StarboardConfig getStarboard() {
return starboard;
}

/**
* Gets the config for automatic pruning of helper roles.
*
* @return the configuration
*/
public HelperPruneConfig getHelperPruneConfig() {
return helperPruneConfig;
}

/**
* The configuration of blacklisted features.
*
* @return configuration of blacklisted features
*/
public FeatureBlacklistConfig getFeatureBlacklistConfig() {
return featureBlacklistConfig;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.togetherjava.tjbot.config;

import com.fasterxml.jackson.annotation.JsonCreator;

import java.util.Set;

/**
* Blacklist of features, use {@link FeatureBlacklist#isEnabled(T)} to test if a feature is enabled.
* If a feature is blacklisted, it won't be enabled by the bot, and so will be ignored.
*
* @param <T> the type of the feature identifier
*/
public class FeatureBlacklist<T> {
private final Set<T> featureIdentifierBlacklist;

/**
* Creates a feature blacklist
*
* @param featureIdentifierBlacklist a set of identifiers which are blacklisted
*/
@JsonCreator
public FeatureBlacklist(Set<T> featureIdentifierBlacklist) {
this.featureIdentifierBlacklist = Set.copyOf(featureIdentifierBlacklist);
}

/**
* Returns if a feature is enabled or not.
*
* @param featureId the identifier of the feature
* @return true if a feature is enabled, false otherwise
*/
public boolean isEnabled(T featureId) {
return !featureIdentifierBlacklist.contains(featureId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.togetherjava.tjbot.config;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Objects;

/**
* Configuration of the feature blacklist, any feature present here will be disabled.
*
* @param normal the normal features, which are present in
* {@link org.togetherjava.tjbot.features.Features}
* @param special the special features, which require special code
*/
public record FeatureBlacklistConfig(
@JsonProperty(value = "normal", required = true) FeatureBlacklist<Class<?>> normal,
@JsonProperty(value = "special", required = true) FeatureBlacklist<String> special) {

/**
* Creates a FeatureBlacklistConfig.
*
* @param normal the list of normal features, must be not null
* @param special the list of special features, must be not null
*/
public FeatureBlacklistConfig {
Objects.requireNonNull(normal);
Objects.requireNonNull(special);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.togetherjava.tjbot.config;


/**
* Config for automatic pruning of helper roles, see
* {@link org.togetherjava.tjbot.features.help.AutoPruneHelperRoutine}.
*
* @param roleFullLimit if a helper role contains that many users, it is considered full and pruning
* must occur
* @param roleFullThreshold if a helper role contains that many users, pruning will start to occur
* to prevent reaching the limit
* @param pruneMemberAmount amount of users to remove from helper roles during a prune
* @param inactivateAfterDays after how many days of inactivity a user is eligible for pruning
* @param recentlyJoinedDays if a user is with the server for just this amount of days, they are
* protected from pruning
*/
public record HelperPruneConfig(int roleFullLimit, int roleFullThreshold, int pruneMemberAmount,
int inactivateAfterDays, int recentlyJoinedDays) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.togetherjava.tjbot.config;

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

import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;

/**
* Starboard Config
*
* @param emojiNames the List of emojis which are recognized by the starboard
* @param channelPattern the pattern of the channel with the starboard
*/
@JsonRootName("starboard")
public record StarboardConfig(List<String> emojiNames, Pattern channelPattern) {
/**
* Creates a Starboard config.
*
* @param emojiNames the List of emojis which are recognized by the starboard
* @param channelPattern the pattern of the channel with the starboard
*/
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public StarboardConfig {
Objects.requireNonNull(emojiNames);
Objects.requireNonNull(channelPattern);
}

/**
* Gets the list of emotes that are recognized by the starboard feature. A message that is
* reacted on with an emote in this list will be reposted in a special channel
* {@link #channelPattern()}.
* <p>
* Empty to deactivate the feature.
*
* @return The List of emojis recognized by the starboard
*/
@Override
public List<String> emojiNames() {
return emojiNames;
}

/**
* Gets the pattern of the channel with the starboard. Deactivate by using a non-existent
* channel name.
*
* @return the pattern of the channel with the starboard
*/
public Pattern channelPattern() {
return channelPattern;
}
}
Loading

0 comments on commit 9e129af

Please sign in to comment.