Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v4.7 #942

Merged
merged 23 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fb149bc
Bump org.kohsuke:github-api from 1.315 to 1.316 (#874)
dependabot[bot] Sep 20, 2023
2bd3c3f
[FeatureBlacklist] Done (#886)
Alathreon Sep 22, 2023
5ba5835
hotfix feature_blacklist -> featureBlacklist
Zabuzard Sep 22, 2023
233cb9d
Bump com.google.cloud.tools.jib from 3.3.0 to 3.4.0 (#896)
dependabot[bot] Sep 22, 2023
68deee0
Remove the use of the deprecated `packages` attribute (#894)
SquidXTV Sep 25, 2023
0d2f654
Pin the correct message in questions thread (#893)
SquidXTV Sep 25, 2023
68b08ed
Bump org.sonarqube from 4.3.0.3225 to 4.4.0.3356 (#904)
dependabot[bot] Sep 28, 2023
6b9f572
Update Workflows (#903)
java-coding-prodigy Sep 28, 2023
0f3ab26
Bump Java Version to 20 (#902)
java-coding-prodigy Oct 3, 2023
930e938
Catch error when unable to send DM (#909)
christolis Oct 8, 2023
ce83d69
Bump org.apache.logging.log4j:log4j-core from 2.20.0 to 2.21.0 (#913)
dependabot[bot] Oct 17, 2023
3224d4c
Bump com.diffplug.spotless from 6.21.0 to 6.22.0 (#906)
dependabot[bot] Oct 20, 2023
fba9265
Transfer Feature reopen (#905)
ankitsmt211 Oct 20, 2023
ac981fc
Remove Stale-Bot (#916)
Zabuzard Oct 22, 2023
9ea9cbd
ChatGPT response Dismiss button (#901)
SquidXTV Oct 22, 2023
3220fcb
Bump org.kohsuke:github-api from 1.316 to 1.317 (#925)
dependabot[bot] Oct 23, 2023
1b38951
fix inability to read embeds in helper threads (#915)
ankitsmt211 Oct 23, 2023
82df6ee
forbid question transfer command on bot users (#929)
ankitsmt211 Oct 23, 2023
0590b36
refactor method for generating title of forum post (#932)
ankitsmt211 Oct 24, 2023
50a6bcd
javadoc fix transfer feature (#936)
ankitsmt211 Oct 26, 2023
10f2575
refactor methods to handle invalid transfers (#933)
ankitsmt211 Nov 1, 2023
2529337
Bump gradle.plugin.org.flywaydb:gradle-plugin-publishing (#941)
dependabot[bot] Nov 2, 2023
3301ea5
Bump org.flywaydb:flyway-core from 9.22.0 to 10.0.0 (#940)
dependabot[bot] Nov 2, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/basic-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Basic checks
on: [pull_request]

env:
JAVA_VERSION: 19
JAVA_VERSION: 20

jobs:
spotless:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- cron: '0 20 * * 4'

env:
JAVA_VERSION: 19
JAVA_VERSION: 20

jobs:
sonar:
Expand Down 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
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- 'master'

env:
JAVA_VERSION: 19
JAVA_VERSION: 20

jobs:
docker:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Docker Verify
on: [pull_request]

env:
JAVA_VERSION: 19
JAVA_VERSION: 20

jobs:
docker:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/releases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defaults:
shell: bash

env:
JAVA_VERSION: 19
JAVA_VERSION: 20

jobs:

Expand Down
34 changes: 0 additions & 34 deletions .github/workflows/stale.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# TJ-Bot

[![codefactor](https://img.shields.io/codefactor/grade/github/together-java/tj-bot)](https://www.codefactor.io/repository/github/together-java/tj-bot)
![Java](https://img.shields.io/badge/Java-19-ff696c)
![Java](https://img.shields.io/badge/Java-20-ff696c)
[![license](https://img.shields.io/github/license/Together-Java/TJ-Bot)](https://github.com/Together-Java/TJ-Bot/blob/master/LICENSE)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/Together-Java/TJ-Bot?label=release)

Expand Down
8 changes: 4 additions & 4 deletions application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {

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 All @@ -18,7 +18,7 @@ repositories {
var outputImage = 'togetherjava.org:5001/togetherjava/tjbot:' + System.getenv('BRANCH_NAME') ?: 'latest'

jib {
from.image = 'eclipse-temurin:19'
from.image = 'eclipse-temurin:20'
to {
image = outputImage
auth {
Expand Down Expand Up @@ -48,7 +48,7 @@ dependencies {

implementation 'net.dv8tion:JDA:5.0.0-alpha.20'

implementation 'org.apache.logging.log4j:log4j-core:2.20.0'
implementation 'org.apache.logging.log4j:log4j-core:2.21.0'
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j18-impl:2.18.0'

implementation 'club.minnced:discord-webhooks:0.8.2'
Expand All @@ -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.317'

testImplementation 'org.mockito:mockito-core:5.3.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
Expand Down
6 changes: 6 additions & 0 deletions application/config.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,11 @@
"pruneMemberAmount": 7,
"inactivateAfterDays": 90,
"recentlyJoinedDays": 4
},
"featureBlacklist": {
"normal": [
],
"special": [
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public final class Config {
private final String sourceCodeBaseUrl;
private final JShellConfig jshell;
private final HelperPruneConfig helperPruneConfig;
private final FeatureBlacklistConfig featureBlacklistConfig;

@SuppressWarnings("ConstructorWithTooManyParameters")
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
Expand Down Expand Up @@ -79,7 +80,9 @@ private Config(@JsonProperty(value = "token", required = true) String token,
@JsonProperty(value = "sourceCodeBaseUrl", required = true) String sourceCodeBaseUrl,
@JsonProperty(value = "jshell", required = true) JShellConfig jshell,
@JsonProperty(value = "helperPruneConfig",
required = true) HelperPruneConfig 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 @@ -106,6 +109,7 @@ private Config(@JsonProperty(value = "token", required = true) String token,
this.sourceCodeBaseUrl = Objects.requireNonNull(sourceCodeBaseUrl);
this.jshell = Objects.requireNonNull(jshell);
this.helperPruneConfig = Objects.requireNonNull(helperPruneConfig);
this.featureBlacklistConfig = Objects.requireNonNull(featureBlacklistConfig);
}

/**
Expand Down Expand Up @@ -355,4 +359,13 @@ public JShellConfig getJshell() {
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
Expand Up @@ -3,6 +3,8 @@
import net.dv8tion.jda.api.JDA;

import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.config.FeatureBlacklist;
import org.togetherjava.tjbot.config.FeatureBlacklistConfig;
import org.togetherjava.tjbot.db.Database;
import org.togetherjava.tjbot.features.basic.PingCommand;
import org.togetherjava.tjbot.features.basic.RoleSelectCommand;
Expand All @@ -19,6 +21,7 @@
import org.togetherjava.tjbot.features.code.CodeMessageManualDetection;
import org.togetherjava.tjbot.features.filesharing.FileSharingMessageListener;
import org.togetherjava.tjbot.features.help.*;
import org.togetherjava.tjbot.features.jshell.JShellCommand;
import org.togetherjava.tjbot.features.jshell.JShellEval;
import org.togetherjava.tjbot.features.mathcommands.TeXCommand;
import org.togetherjava.tjbot.features.mathcommands.wolframalpha.WolframAlphaCommand;
Expand Down Expand Up @@ -73,14 +76,16 @@ private Features() {
* @return a collection of all features
*/
public static Collection<Feature> createFeatures(JDA jda, Database database, Config config) {
FeatureBlacklistConfig blacklistConfig = config.getFeatureBlacklistConfig();
JShellEval jshellEval = new JShellEval(config.getJshell());

TagSystem tagSystem = new TagSystem(database);
BookmarksSystem bookmarksSystem = new BookmarksSystem(config, database);
ModerationActionsStore actionsStore = new ModerationActionsStore(database);
ModAuditLogWriter modAuditLogWriter = new ModAuditLogWriter(config);
ScamHistoryStore scamHistoryStore = new ScamHistoryStore(database);
CodeMessageHandler codeMessageHandler = new CodeMessageHandler(jshellEval);
CodeMessageHandler codeMessageHandler =
new CodeMessageHandler(blacklistConfig.special(), jshellEval);
ChatGptService chatGptService = new ChatGptService(config);
HelpSystemHelper helpSystemHelper = new HelpSystemHelper(config, database, chatGptService);

Expand Down Expand Up @@ -121,6 +126,7 @@ public static Collection<Feature> createFeatures(JDA jda, Database database, Con
features.add(new HelpThreadCreatedListener(helpSystemHelper));

// Message context commands
features.add(new TransferQuestionCommand(config));

// User context commands

Expand Down Expand Up @@ -151,7 +157,9 @@ public static Collection<Feature> createFeatures(JDA jda, Database database, Con
features.add(new ReportCommand(config));
features.add(new BookmarksCommand(bookmarksSystem));
features.add(new ChatGptCommand(chatGptService));
// features.add(new JShellCommand(jshellEval));
return features;
features.add(new JShellCommand(jshellEval));

FeatureBlacklist<Class<?>> blacklist = blacklistConfig.normal();
return features.stream().filter(f -> blacklist.isEnabled(f.getClass())).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.togetherjava.tjbot.config.FeatureBlacklist;
import org.togetherjava.tjbot.features.MessageReceiverAdapter;
import org.togetherjava.tjbot.features.UserInteractionType;
import org.togetherjava.tjbot.features.UserInteractor;
Expand All @@ -30,6 +31,7 @@
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* Handles code in registered messages and offers code actions to the user, such as formatting their
Expand Down Expand Up @@ -63,14 +65,18 @@ public final class CodeMessageHandler extends MessageReceiverAdapter implements

/**
* Creates a new instance.
*
*
* @param blacklist the feature blacklist, used to test if certain code actions should be
* disabled
* @param jshellEval used to execute java code and build visual result
*/
public CodeMessageHandler(JShellEval jshellEval) {
public CodeMessageHandler(FeatureBlacklist<String> blacklist, JShellEval jshellEval) {
componentIdInteractor = new ComponentIdInteractor(getInteractionType(), getName());

List<CodeAction> codeActions =
List.of(new FormatCodeCommand()/* , new EvalCodeCommand(jshellEval) */);
Stream.of(new FormatCodeCommand(), new EvalCodeCommand(jshellEval))
.filter(a -> blacklist.isEnabled(a.getClass().getSimpleName()))
.toList();

labelToCodeAction = codeActions.stream()
.collect(Collectors.toMap(CodeAction::getLabel, Function.identity(), (x, y) -> y,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ private void pruneMemberFromRole(Member member, Role role, ForumChannel helpForu
guild.removeRoleFromMember(member, role)
.flatMap(any -> member.getUser().openPrivateChannel())
.flatMap(channel -> channel.sendMessage(dmMessage))
.queue();
.queue(null, failure -> logger.debug(
"Failed sending a DM to user ({}) while pruning them from a helper role.",
member.getId()));
}

private void warnModsAbout(String message, Guild guild) {
Expand Down
Loading
Loading