Skip to content

Commit 52cf8d0

Browse files
Release 1.15.2 (#652)
2 parents 718eb38 + 9e9075f commit 52cf8d0

19 files changed

+602
-401
lines changed

.github/workflows/verify.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ jobs:
1010
steps:
1111
- uses: actions/checkout@v4
1212
- uses: gradle/wrapper-validation-action@v3
13-
- name: Set up JDK 19
13+
- name: Set up JDK 21
1414
uses: actions/setup-java@v4
1515
with:
1616
distribution: temurin
17-
java-version: 19
17+
java-version: 21
1818
- name: Build with Gradle
1919
run: ./gradlew --build-cache build
2020
- name: Test with Gradle

build.gradle.kts

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group = "de.chojo"
10-
version = "1.15.1"
10+
version = "1.15.2"
1111

1212
repositories {
1313
mavenCentral()
@@ -25,12 +25,18 @@ spotless {
2525

2626
dependencies {
2727
//discord
28-
implementation("de.chojo", "cjda-util", "2.9.8+jda-5.0.0") {
28+
implementation("de.chojo", "cjda-util", "2.10.3+jda-5.1.0") {
2929
exclude(group = "club.minnced", module = "opus-java")
3030
}
3131

32+
val openapi = "6.4.0"
33+
34+
annotationProcessor("io.javalin.community.openapi:openapi-annotation-processor:$openapi")
35+
implementation("io.javalin.community.openapi:javalin-openapi-plugin:$openapi") // for /openapi route with JSON scheme
36+
implementation("io.javalin.community.openapi:javalin-swagger-plugin:$openapi") // for Swagger UI
37+
3238
// database
33-
implementation("org.postgresql", "postgresql", "42.7.3")
39+
implementation("org.postgresql", "postgresql", "42.7.5")
3440
implementation(libs.bundles.sadu)
3541

3642
// Logging
@@ -42,7 +48,7 @@ dependencies {
4248
implementation("org.knowm.xchart", "xchart", "3.8.8")
4349

4450
// unit testing
45-
testImplementation(platform("org.junit:junit-bom:5.10.3"))
51+
testImplementation(platform("org.junit:junit-bom:5.11.4"))
4652
testImplementation("org.junit.jupiter", "junit-jupiter")
4753
testImplementation("org.knowm.xchart", "xchart", "3.8.8")
4854
}

docker/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ services:
1212
database:
1313
networks:
1414
- repbot
15-
image: postgres:16.3
15+
image: postgres:17.2
1616
expose:
1717
- 5432
1818
volumes:

gradle/wrapper/gradle-wrapper.jar

79 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

+1-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ done
8686
# shellcheck disable=SC2034
8787
APP_BASE_NAME=${0##*/}
8888
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89-
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
90-
' "$PWD" ) || exit
89+
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
9190

9291
# Use the maximum available, or set MAX_FD != -1 to use that value.
9392
MAX_FD=maximum

settings.gradle.kts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
rootProject.name = "rep-bot"
22

33
plugins {
4-
id("org.gradle.toolchains.foojay-resolver-convention") version("0.8.0")
4+
id("org.gradle.toolchains.foojay-resolver-convention") version("0.9.0")
55
}
66

77
dependencyResolutionManagement {
88
versionCatalogs {
99
create("libs") {
1010
// misc
11-
version("sadu", "2.2.2")
11+
version("sadu", "2.3.1")
1212
library("sadu-queries", "de.chojo.sadu", "sadu-queries").versionRef("sadu")
1313
library("sadu-updater", "de.chojo.sadu", "sadu-updater").versionRef("sadu")
1414
library("sadu-postgresql", "de.chojo.sadu", "sadu-postgresql").versionRef("sadu")
1515
library("sadu-datasource", "de.chojo.sadu", "sadu-datasource").versionRef("sadu")
1616
bundle("sadu", listOf("sadu-queries", "sadu-updater", "sadu-postgresql", "sadu-datasource"))
1717

18-
version("log4j", "2.23.1")
19-
library("slf4j-api", "org.slf4j:slf4j-api:2.0.13")
18+
version("log4j", "2.24.3")
19+
library("slf4j-api", "org.slf4j:slf4j-api:2.0.16")
2020
library("log4j-core", "org.apache.logging.log4j", "log4j-core").versionRef("log4j")
2121
library("log4j-slf4j2", "org.apache.logging.log4j", "log4j-slf4j2-impl").versionRef("log4j")
2222
library("log4j-jsontemplate","org.apache.logging.log4j", "log4j-layout-template-json").versionRef("log4j")
2323
bundle("log4j", listOf("slf4j-api", "log4j-core", "log4j-slf4j2", "log4j-jsontemplate"))
2424

2525
// plugins
26-
plugin("spotless", "com.diffplug.spotless").version("6.25.0")
27-
plugin("shadow", "com.github.johnrengelman.shadow").version("8.1.1")
28-
26+
plugin("spotless", "com.diffplug.spotless").version("7.0.2")
27+
plugin("shadow", "com.gradleup.shadow").version("8.3.5")
2928
}
3029
}
3130
}

src/main/java/de/chojo/repbot/core/Web.java

+39-14
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
import de.chojo.jdautil.botlist.BotlistService;
99
import de.chojo.repbot.config.Configuration;
1010
import de.chojo.repbot.web.Api;
11+
import de.chojo.repbot.web.error.ApiException;
1112
import io.javalin.Javalin;
12-
import io.javalin.plugin.openapi.OpenApiOptions;
13-
import io.javalin.plugin.openapi.OpenApiPlugin;
14-
import io.javalin.plugin.openapi.ui.ReDocOptions;
15-
import io.javalin.plugin.openapi.ui.SwaggerOptions;
16-
import io.javalin.plugin.openapi.utils.OpenApiVersionUtil;
17-
import io.swagger.v3.oas.models.info.License;
13+
import io.javalin.openapi.OpenApiLicense;
14+
import io.javalin.openapi.plugin.OpenApiPlugin;
15+
import io.javalin.openapi.plugin.OpenApiPluginConfiguration;
16+
import io.javalin.openapi.plugin.swagger.SwaggerConfiguration;
17+
import io.javalin.openapi.plugin.swagger.SwaggerPlugin;
1818
import net.dv8tion.jda.api.entities.User;
1919
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
2020
import net.dv8tion.jda.api.requests.ErrorResponse;
@@ -51,19 +51,44 @@ public void init() {
5151
private void initApi() {
5252
var api = configuration.api();
5353

54-
var info = new io.swagger.v3.oas.models.info.Info().version("1.0").title("Reputation Bot API")
55-
.description("Documentation for the Reputation Bot API")
56-
.license(new License().name("GNU Affero General Public License v3.0")
57-
.url("https://github.com/RainbowDashLabs/reputation-bot/blob/master/LICENSE.md"));
54+
/*
5855
var options = new OpenApiOptions(info)
5956
.path("/json-docs")
6057
.reDoc(new ReDocOptions("/redoc")) // endpoint for redoc
6158
.swagger(new SwaggerOptions("/docs").title("Reputation Bot API"));
62-
OpenApiVersionUtil.INSTANCE.setLogWarnings(false);
59+
OpenApiVersionUtil.INSTANCE.setLogWarnings(false);*/
6360

64-
javalin = Javalin.create(config -> config.registerPlugin(new OpenApiPlugin(options)))
65-
.start(api.host(), api.port());
66-
new Api(javalin, data.metrics()).init();
61+
javalin = Javalin.create(config -> {
62+
config.registerPlugin(new OpenApiPlugin(this::configureOpenApi));
63+
config.registerPlugin(new SwaggerPlugin(this::configureSwagger));
64+
config.router.apiBuilder(() -> new Api(data.metrics()).init());
65+
})
66+
.start(api.host(), api.port());
67+
javalin.exception(ApiException.class, (err, ctx) -> ctx.result(err.getMessage()).status(err.status()));
68+
}
69+
70+
private void configureSwagger(SwaggerConfiguration swaggerConfiguration) {
71+
swaggerConfiguration.setDocumentationPath("/docs");
72+
swaggerConfiguration.setUiPath("/swagger-ui");
73+
}
74+
75+
private void configureOpenApi(OpenApiPluginConfiguration config) {
76+
config.withDocumentationPath("/docs")
77+
.withDefinitionConfiguration((version, definition) -> {
78+
definition.withInfo(info -> {
79+
info.setTitle("Reputation Bot API");
80+
info.setVersion("1.0");
81+
info.setDescription("Documentation for the Reputation Bot API");
82+
info.setLicense(new OpenApiLicense()
83+
.name("GNU Affero General Public License v3.0")
84+
.url("https://github.com/RainbowDashLabs/reputation-bot/blob/master/LICENSE.md")
85+
);
86+
});
87+
definition.withServer(openApiServer -> {
88+
openApiServer.setUrl("https://repbot.rainbowdashlabs.de");
89+
openApiServer.setDescription("Main server");
90+
});
91+
});
6792
}
6893

6994
private void initBotList() {

src/main/java/de/chojo/repbot/util/Messages.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ private static void handleMark(RestAction<Void> action) {
5858
ErrorResponse.UNKNOWN_MESSAGE,
5959
ErrorResponse.TOO_MANY_REACTIONS,
6060
ErrorResponse.REACTION_BLOCKED,
61-
ErrorResponse.UNKNOWN_CHANNEL));
61+
ErrorResponse.UNKNOWN_CHANNEL,
62+
ErrorResponse.THREAD_LOCKED));
6263
}
6364
}

src/main/java/de/chojo/repbot/web/Api.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
package de.chojo.repbot.web;
77

88
import de.chojo.repbot.dao.provider.Metrics;
9-
import de.chojo.repbot.web.erros.ApiException;
9+
import de.chojo.repbot.web.error.ApiException;
1010
import de.chojo.repbot.web.routes.v1.MetricsRoute;
1111
import io.javalin.Javalin;
12+
import io.javalin.apibuilder.ApiBuilder;
13+
import io.javalin.apibuilder.EndpointGroup;
14+
import io.javalin.router.Endpoint;
1215
import org.slf4j.Logger;
1316

1417
import static io.javalin.apibuilder.ApiBuilder.before;
@@ -17,20 +20,14 @@
1720

1821
public class Api {
1922
private static final Logger log = getLogger(Api.class);
20-
private final Javalin javalin;
2123
private final MetricsRoute metricsRoute;
2224

23-
public Api(Javalin javalin, Metrics metrics) {
24-
this.javalin = javalin;
25+
public Api(Metrics metrics) {
2526
metricsRoute = new MetricsRoute(metrics);
2627
}
2728

2829
public void init() {
29-
javalin.exception(ApiException.class, (err, ctx) -> ctx.result(err.getMessage()).status(err.status()));
30-
javalin.routes(() -> {
31-
before(ctx -> log.debug("Received request on {}.", ctx.path()));
32-
33-
path("v1", () -> path("metrics", metricsRoute::buildRoutes));
34-
});
30+
before(ctx -> log.debug("Received request on {}.", ctx.path()));
31+
path("v1", () -> path("metrics", metricsRoute::buildRoutes));
3532
}
3633
}

src/main/java/de/chojo/repbot/web/error/ApiException.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
*
44
* Copyright (C) RainbowDashLabs and Contributor
55
*/
6-
package de.chojo.repbot.web.erros;
6+
package de.chojo.repbot.web.error;
77

8-
import io.javalin.http.HttpCode;
8+
9+
import io.javalin.http.HttpStatus;
910

1011
public class ApiException extends RuntimeException {
11-
private final HttpCode status;
12+
private final HttpStatus status;
1213

13-
public ApiException(HttpCode status, String message) {
14+
public ApiException(HttpStatus status, String message) {
1415
super(message);
1516
this.status = status;
1617
}
1718

18-
public HttpCode status() {
19+
public HttpStatus status() {
1920
return status;
2021
}
2122
}

src/main/java/de/chojo/repbot/web/routes/v1/MetricsHolder.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
package de.chojo.repbot.web.routes.v1;
77

88
import de.chojo.repbot.dao.provider.Metrics;
9-
import de.chojo.repbot.web.erros.ApiException;
9+
import de.chojo.repbot.web.error.ApiException;
1010
import de.chojo.repbot.web.routes.RoutesBuilder;
1111
import de.chojo.repbot.web.routes.v1.metrics.MetricCache;
1212
import io.javalin.http.Context;
1313
import io.javalin.http.Handler;
14-
import io.javalin.http.HttpCode;
15-
import org.eclipse.jetty.http.HttpStatus;
14+
import io.javalin.http.HttpStatus;
1615
import org.slf4j.Logger;
1716

1817
import static org.slf4j.LoggerFactory.getLogger;
@@ -36,7 +35,7 @@ protected void writeImage(Context ctx, byte[] png) {
3635
ctx.header("X-Content-Type-Options", "nosniff");
3736
ctx.contentType("image/png");
3837

39-
ctx.result(png).status(HttpStatus.OK_200);
38+
ctx.result(png).status(HttpStatus.OK);
4039
}
4140

4241
protected int offset(Context context, int max) {
@@ -46,7 +45,7 @@ protected int offset(Context context, int max) {
4645
assertSize(offset, 0, max);
4746
return offset;
4847
} catch (NumberFormatException e) {
49-
throw new ApiException(HttpCode.BAD_REQUEST, "Offset is not a number, Got: " + param);
48+
throw new ApiException(HttpStatus.BAD_REQUEST, "Offset is not a number, Got: " + param);
5049
}
5150
}
5251

@@ -57,16 +56,16 @@ protected int count(Context context, int max) {
5756
assertSize(offset, 2, max);
5857
return offset;
5958
} catch (NumberFormatException e) {
60-
throw new ApiException(HttpCode.BAD_REQUEST, "Count is not a number, Got: " + param);
59+
throw new ApiException(HttpStatus.BAD_REQUEST, "Count is not a number, Got: " + param);
6160
}
6261
}
6362

6463
private void assertSize(int value, int min, int max) {
6564
if (value < min) {
66-
throw new ApiException(HttpCode.BAD_REQUEST, String.format("Value %s is too small. Min: %s", value, min));
65+
throw new ApiException(HttpStatus.BAD_REQUEST, String.format("Value %s is too small. Min: %s", value, min));
6766
}
6867
if (value > max) {
69-
throw new ApiException(HttpCode.BAD_REQUEST, String.format("Value %s is too large. Max: %s", value, max));
68+
throw new ApiException(HttpStatus.BAD_REQUEST, String.format("Value %s is too large. Max: %s", value, max));
7069
}
7170
}
7271

src/main/java/de/chojo/repbot/web/routes/v1/MetricsRoute.java

-49
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import de.chojo.repbot.web.routes.v1.metrics.Reputation;
1313
import de.chojo.repbot.web.routes.v1.metrics.Service;
1414
import de.chojo.repbot.web.routes.v1.metrics.Users;
15-
import io.swagger.v3.oas.models.parameters.Parameter;
1615

1716
public class MetricsRoute implements RoutesBuilder {
1817

@@ -52,52 +51,4 @@ public void buildRoutes() {
5251
users.buildRoutes();
5352
service.buildRoutes();
5453
}
55-
56-
private static void offsetDoc(Parameter parameter, String resolution, int maxValue) {
57-
setParameter(parameter, "%s offset. 0 is current %s. Max value is %s".formatted(resolution, resolution.toLowerCase(), maxValue));
58-
}
59-
60-
public static void offsetDayDoc(Parameter p) {
61-
offsetDoc(p, "Day", MAX_DAY_OFFSET);
62-
}
63-
64-
public static void offsetHourDoc(Parameter p) {
65-
offsetDoc(p, "Hour", MAX_HOUR_OFFSET);
66-
}
67-
68-
public static void offsetWeekDoc(Parameter p) {
69-
offsetDoc(p, "Week", MAX_WEEK_OFFSET);
70-
}
71-
72-
public static void offsetMonthDoc(Parameter p) {
73-
offsetDoc(p, "Month", MAX_MONTH_OFFSET);
74-
}
75-
76-
public static void offsetYearDoc(Parameter p) {
77-
offsetDoc(p, "Year", MAX_YEAR_OFFSET);
78-
}
79-
80-
private static void countDoc(Parameter parameter, String resolution, int maxValue) {
81-
setParameter(parameter, "%s count. Amount of previously %s in the chart. Max value is %s".formatted(resolution, resolution.toLowerCase(), maxValue));
82-
}
83-
84-
public static void countHourDoc(Parameter p) {
85-
countDoc(p, "Hours", MAX_HOURS);
86-
}
87-
88-
public static void countDayDoc(Parameter p) {
89-
countDoc(p, "Days", MAX_DAYS);
90-
}
91-
92-
public static void countWeekDoc(Parameter p) {
93-
countDoc(p, "Weeks", MAX_WEEKS);
94-
}
95-
96-
public static void countMonthDoc(Parameter p) {
97-
countDoc(p, "Months", MAX_MONTH);
98-
}
99-
100-
private static void setParameter(Parameter p, String description) {
101-
p.setDescription(description);
102-
}
10354
}

0 commit comments

Comments
 (0)