Skip to content

Commit

Permalink
Release 1.15.1 (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs authored Aug 5, 2024
2 parents 281554c + fb69da9 commit 898991a
Show file tree
Hide file tree
Showing 65 changed files with 1,215 additions and 1,362 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use nix
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
allowed-conclusions: success
- uses: actions/checkout@v4
- uses: gradle/wrapper-validation-action@v1
- uses: gradle/wrapper-validation-action@v3
- name: Build Image
run: docker build . -f docker/Dockerfile -t ghcr.io/rainbowdashlabs/reputation-bot:${{ github.sha }}
- name: Login to Registry
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: gradle/wrapper-validation-action@v1
- uses: gradle/wrapper-validation-action@v3
- name: Set up JDK 19
uses: actions/setup-java@v4
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ buildNumber.properties
/out/

/site/
/.direnv
13 changes: 6 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ plugins {
alias(libs.plugins.shadow)
alias(libs.plugins.spotless)
java
`maven-publish`
}

group = "de.chojo"
Expand All @@ -25,12 +24,12 @@ spotless {

dependencies {
//discord
implementation("de.chojo", "cjda-util", "2.9.6+beta.19") {
implementation("de.chojo", "cjda-util", "2.9.8+jda-5.0.0") {
exclude(group = "club.minnced", module = "opus-java")
}

// database
implementation("org.postgresql", "postgresql", "42.7.1")
implementation("org.postgresql", "postgresql", "42.7.3")
implementation(libs.bundles.sadu)

// Logging
Expand All @@ -39,17 +38,17 @@ dependencies {
exclude("org.apache.logging.log4j")
}

implementation("org.knowm.xchart", "xchart", "3.8.7")
implementation("org.knowm.xchart", "xchart", "3.8.8")

// unit testing
testImplementation(platform("org.junit:junit-bom:5.10.1"))
testImplementation(platform("org.junit:junit-bom:5.10.3"))
testImplementation("org.junit.jupiter", "junit-jupiter")
testImplementation("org.knowm.xchart", "xchart", "3.8.7")
testImplementation("org.knowm.xchart", "xchart", "3.8.8")
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(19))
languageVersion.set(JavaLanguageVersion.of(21))
}
withSourcesJar()
withJavadocJar()
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM gradle:jdk19-alpine as build
FROM gradle:jdk21-alpine as build

COPY . .
RUN gradle clean build --no-daemon
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
database:
networks:
- repbot
image: postgres:16.1
image: postgres:16.3
expose:
- 5432
volumes:
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
22 changes: 12 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
8 changes: 4 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ dependencyResolutionManagement {
versionCatalogs {
create("libs") {
// misc
version("sadu", "1.4.0")
version("sadu", "2.2.1")
library("sadu-queries", "de.chojo.sadu", "sadu-queries").versionRef("sadu")
library("sadu-updater", "de.chojo.sadu", "sadu-updater").versionRef("sadu")
library("sadu-postgresql", "de.chojo.sadu", "sadu-postgresql").versionRef("sadu")
library("sadu-datasource", "de.chojo.sadu", "sadu-datasource").versionRef("sadu")
bundle("sadu", listOf("sadu-queries", "sadu-updater", "sadu-postgresql", "sadu-datasource"))

version("log4j", "2.22.1")
library("slf4j-api", "org.slf4j:slf4j-api:2.0.11")
version("log4j", "2.23.1")
library("slf4j-api", "org.slf4j:slf4j-api:2.0.13")
library("log4j-core", "org.apache.logging.log4j", "log4j-core").versionRef("log4j")
library("log4j-slf4j2", "org.apache.logging.log4j", "log4j-slf4j2-impl").versionRef("log4j")
library("log4j-jsontemplate","org.apache.logging.log4j", "log4j-layout-template-json").versionRef("log4j")
bundle("log4j", listOf("slf4j-api", "log4j-core", "log4j-slf4j2", "log4j-jsontemplate"))

// plugins
plugin("spotless", "com.diffplug.spotless").version("6.24.0")
plugin("spotless", "com.diffplug.spotless").version("6.25.0")
plugin("shadow", "com.github.johnrengelman.shadow").version("8.1.1")

}
Expand Down
6 changes: 6 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{ pkgs ? import <nixpkgs> {}, ... }:

pkgs.mkShell {
packages = with pkgs; [jdk21];
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class BaseAnalyzer {
public void onSlashCommand(SlashCommandInteractionEvent event, EventContext context, Reputation reputation) {
var optMessageId = ValueParser.parseLong(event.getOption("message_id").getAsString());
var optMessageId = ValueParser.parseLong(event.getOption("messageid").getAsString());
if (optMessageId.isEmpty()) {
event.reply(context.localize("error.invalidMessage")).setEphemeral(true).queue();
return;
Expand Down
64 changes: 36 additions & 28 deletions src/main/java/de/chojo/repbot/core/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
import de.chojo.repbot.dao.access.Analyzer;
import de.chojo.repbot.dao.access.Cleanup;
import de.chojo.repbot.dao.access.Gdpr;
import de.chojo.repbot.dao.access.gdpr.RemovalTask;
import de.chojo.repbot.dao.provider.Guilds;
import de.chojo.repbot.dao.provider.Metrics;
import de.chojo.repbot.dao.provider.Voice;
import de.chojo.repbot.util.LogNotify;
import de.chojo.sadu.databases.PostgreSql;
import de.chojo.sadu.datasource.DataSourceCreator;
import de.chojo.sadu.mapper.RowMapperRegistry;
import de.chojo.sadu.mapper.rowmapper.RowMapper;
import de.chojo.sadu.postgresql.databases.PostgreSql;
import de.chojo.sadu.postgresql.mapper.PostgresqlMapper;
import de.chojo.sadu.queries.configuration.QueryConfiguration;
import de.chojo.sadu.updater.QueryReplacement;
import de.chojo.sadu.updater.SqlUpdater;
import de.chojo.sadu.wrapper.QueryBuilderConfig;
import org.slf4j.Logger;

import java.io.IOException;
Expand Down Expand Up @@ -50,8 +54,8 @@ public static Data create(Threading threading, Configuration configuration) thro
}

public void init() throws SQLException, IOException {
configure();
initConnection();
configure();
updateDatabase();
initDao();
}
Expand All @@ -72,46 +76,50 @@ public void initConnection() {
private void updateDatabase() throws IOException, SQLException {
var schema = configuration.database().schema();
SqlUpdater.builder(dataSource, PostgreSql.get())
.setReplacements(new QueryReplacement("repbot_schema", schema))
.setVersionTable(schema + ".repbot_version")
.setSchemas(schema)
.execute();
.setReplacements(new QueryReplacement("repbot_schema", schema))
.setVersionTable(schema + ".repbot_version")
.setSchemas(schema)
.execute();
}

private void configure() {
log.info("Configuring QueryBuilder");
log.info("Configuring Query Configuration");
var logger = getLogger("DbLogger");
QueryBuilderConfig.setDefault(QueryBuilderConfig.builder()
.withExceptionHandler(err -> logger.error(LogNotify.NOTIFY_ADMIN, "An error occured during a database request", err))
.withExecutor(threading.repBotWorker())
.build());
var registry = new RowMapperRegistry();
registry.register(RowMapper.forClass(RemovalTask.class).mapper(RemovalTask::build).build());
registry.register(PostgresqlMapper.getDefaultMapper());
QueryConfiguration.setDefault(
QueryConfiguration.builder(dataSource)
.setExceptionHandler(err -> logger.error(LogNotify.NOTIFY_ADMIN, "An error occured during a database request", err))
.setRowMapperRegistry(registry)
.build());
}

private void initDao() {
log.info("Creating DAOs");
guilds = new Guilds(dataSource, configuration);
gdpr = new Gdpr(dataSource, configuration);
cleanup = new Cleanup(dataSource);
guilds = new Guilds(configuration);
gdpr = new Gdpr(configuration);
cleanup = new Cleanup();
metrics = new Metrics(dataSource);
analyzer = new Analyzer(dataSource, configuration);
voice = new Voice(dataSource, configuration);
analyzer = new Analyzer(configuration);
voice = new Voice(configuration);
}

private HikariDataSource getConnectionPool() {
log.info("Creating connection pool.");
var data = configuration.database();
return DataSourceCreator.create(PostgreSql.get())
.configure(config -> config
.host(data.host())
.port(data.port())
.user(data.user())
.password(data.password())
.database(data.database()))
.create()
.withMaximumPoolSize(data.poolSize())
.withThreadFactory(Threading.createThreadFactory(threading.hikariGroup()))
.forSchema(data.schema())
.build();
.configure(config -> config
.host(data.host())
.port(data.port())
.user(data.user())
.password(data.password())
.database(data.database()))
.create()
.withMaximumPoolSize(data.poolSize())
.withThreadFactory(Threading.createThreadFactory(threading.hikariGroup()))
.forSchema(data.schema())
.build();
}

public Guilds guilds() {
Expand Down
43 changes: 22 additions & 21 deletions src/main/java/de/chojo/repbot/dao/access/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,40 @@
*/
package de.chojo.repbot.dao.access;

import de.chojo.jdautil.util.Futures;
import de.chojo.repbot.config.Configuration;
import de.chojo.repbot.util.LogNotify;
import de.chojo.sadu.base.QueryFactory;
import de.chojo.sadu.queries.api.query.Query;
import org.slf4j.Logger;

import javax.sql.DataSource;

import static de.chojo.sadu.queries.api.call.Call.call;
import static org.slf4j.LoggerFactory.getLogger;

public class Analyzer extends QueryFactory {
public class Analyzer {
private static final Logger log = getLogger(Analyzer.class);
private final Configuration configuration;

public Analyzer(DataSource dataSource, Configuration configuration) {
super(dataSource);
public Analyzer(Configuration configuration) {
this.configuration = configuration;
}

public void cleanup() {
builder().query("""
DELETE FROM analyzer_results WHERE analyzed < NOW() - ?::interval;
""")
.parameter(stmt -> stmt.setString("%d HOURS".formatted(configuration.cleanup().analyzerLogHours())))
.delete()
.send()
.whenComplete(Futures.whenComplete(res -> log.debug("Deleted {} entries from analyzer log", res.rows()),
err -> log.error(LogNotify.NOTIFY_ADMIN, "Could not cleanup analyzer log.", err)));
builder().query("DELETE FROM reputation_results WHERE submitted < now() - ?::interval")
.parameter(stmt -> stmt.setString("%d HOURS".formatted(configuration.cleanup().analyzerLogHours())))
.delete()
.send()
.whenComplete(Futures.whenComplete(res -> log.debug("Deleted {} entries from reputation results", res.rows()),
err -> log.error(LogNotify.NOTIFY_ADMIN, "Could not cleanup reputation results.", err)));
var delete = Query.query("""
DELETE FROM analyzer_results WHERE analyzed < now() - ?::INTERVAL;
""")
.single(call().bind("%d HOURS".formatted(configuration.cleanup().analyzerLogHours())))
.delete();
if (delete.changed()) {
log.debug("Deleted {} entries from analyzer log", delete.rows());
} else {
delete.exceptions().forEach(e -> log.error(LogNotify.NOTIFY_ADMIN, "Could not cleanup analyzer log.", e));
}
delete = Query.query("DELETE FROM reputation_results WHERE submitted < now() - ?::INTERVAL")
.single(call().bind("%d HOURS".formatted(configuration.cleanup().analyzerLogHours())))
.delete();
if (delete.changed()) {
log.debug("Deleted {} entries from reputation results", delete.rows());
} else {
delete.exceptions().forEach(e -> log.error(LogNotify.NOTIFY_ADMIN, "Could not cleanup analyzer log.", e));
}
}
}
Loading

0 comments on commit 898991a

Please sign in to comment.