Skip to content
Draft
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
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.gradle
**/build
.git
.idea
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This dockerfile is far from best practice and is a pure "Make it work" approach. Please do not use it as a reference of any kind.
FROM gradle:jdk21-alpine as build
FROM gradle:jdk25-alpine as build

COPY . .
RUN gradle clean :bot:build :plugin-paper:build --no-daemon
Expand Down
10 changes: 10 additions & 0 deletions bot/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,26 @@ dependencies {
implementation("de.chojo", "cjda-util", "2.14.5+jda-6.3.0") {
exclude(module = "opus-java")
}

implementation("net.dv8tion", "JDA", "6.4.1")

implementation(libs.javalin.bundle)
implementation(libs.javalin.openapi)
implementation(libs.javalin.swagger)
annotationProcessor(libs.javalin.annotation)
implementation("net.lingala.zip4j", "zip4j", "2.11.6")

// config
implementation("dev.chojo", "ocular", "2.2.1")
implementation("tools.jackson.dataformat:jackson-dataformat-yaml:3.1.4")

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

// docker api
implementation(libs.bundles.docker)

// Logging
implementation(libs.bundles.logging)
implementation("club.minnced", "discord-webhooks", "0.8.4")
Expand Down
1 change: 1 addition & 0 deletions bot/src/main/java/de/chojo/gamejam/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ private void buildLocale() {
.addLanguage(DiscordLocale.GERMAN)
.withLanguageProvider(guild -> Optional.ofNullable(guilds.guild(guild).settings().locale())
.map(DiscordLocale::from))
.withGuildLocaleCodeProvider((guild, s) -> Optional.empty())
.build();
}

Expand Down
4 changes: 2 additions & 2 deletions bot/src/main/java/de/chojo/gamejam/api/v1/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ private void handle(@NotNull Context ctx) {

ctx.status(HttpStatus.ACCEPTED);
String restart = ctx.queryParam("restart");
if ("true".equals(restart) && teamServer.running()) {
if ("true".equals(restart) && teamServer.isRunning()) {
teamServer.restart();
} else if (teamServer.running()) {
} else if (teamServer.isRunning()) {
teamServer.send("say Plugin Updated");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package de.chojo.gamejam.commands.server.configure;

import de.chojo.gamejam.commands.server.Server;
import de.chojo.gamejam.server.TeamServer;
import de.chojo.jdautil.interactions.slash.structure.handler.SlashHandler;
import de.chojo.jdautil.util.Futures;
import de.chojo.jdautil.wrapper.EventContext;
Expand Down Expand Up @@ -37,7 +36,7 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
.POST(HttpRequest.BodyPublishers.ofString(String.valueOf(event.getOption("amount").getAsInt())))
.build();

if (!teamServer.running()) {
if (!teamServer.isRunning()) {
event.reply(context.localize("error.servernotrunning")).queue();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont

var teamServer = optServer.get();

if (!teamServer.running()) {
if (!teamServer.isRunning()) {
event.reply(context.localize("error.servernotrunning")).queue();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package de.chojo.gamejam.commands.server.configure;

import de.chojo.gamejam.commands.server.Server;
import de.chojo.gamejam.server.TeamServer;
import de.chojo.jdautil.interactions.slash.structure.handler.SlashHandler;
import de.chojo.jdautil.util.Futures;
import de.chojo.jdautil.wrapper.EventContext;
Expand All @@ -34,7 +33,7 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont

var teamServer = optServer.get();

if (!teamServer.running()) {
if (!teamServer.isRunning()) {
event.reply(context.localize("error.servernotrunning")).queue();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package de.chojo.gamejam.commands.server.configure;

import de.chojo.gamejam.commands.server.Server;
import de.chojo.gamejam.server.TeamServer;
import de.chojo.jdautil.interactions.slash.structure.handler.SlashHandler;
import de.chojo.jdautil.util.Futures;
import de.chojo.jdautil.wrapper.EventContext;
Expand All @@ -34,7 +33,7 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont

var teamServer = optServer.get();

if (!teamServer.running()) {
if (!teamServer.isRunning()) {
event.reply(context.localize("error.servernotrunning")).queue();
return;
}
Expand Down
20 changes: 10 additions & 10 deletions bot/src/main/java/de/chojo/gamejam/commands/server/process/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.utils.FileUpload;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

public class Log implements SlashHandler {
Expand All @@ -27,16 +30,13 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
var optServer = server.getServer(event, context);
if(optServer.isEmpty())return;
var teamServer = optServer.get();
var logFile = teamServer.logFile();
String content;
try {
content = Files.readString(logFile);
} catch (IOException e) {
content = "";
var logs = teamServer.logs(0);
var content = logs.substring(Math.max(logs.length() - 1950, 0));
try(InputStream inputStream = new ByteArrayInputStream(logs.getBytes(StandardCharsets.UTF_8))) {
event.reply("```log%n%s%n```".formatted(content))
.addFiles(FileUpload.fromData(inputStream, "latest.log"))
.queue();
} catch (IOException _) {
}
content = content.substring(Math.max(content.length() - 1950, 0));
event.reply("```log%n%s%n```".formatted(content))
.addFiles(FileUpload.fromData(logFile, "latest.log"))
.queue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
if(optServer.isEmpty())return;
var teamServer = optServer.get();
if (teamServer.exists()) {
teamServer.stop(true)
.thenRun(() -> event.getHook().editOriginal(context.localize("command.server.process.restart.message.restarted")).queue());
teamServer.stop();
event.getHook().editOriginal(context.localize("command.server.process.restart.message.restarted")).queue();
event.reply(context.localize("command.server.process.restart.message.restarting")).queue();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
var teamServer = optServer.get();
if (teamServer.exists()) {
event.reply(context.localize("command.server.process.stop.message.stopping")).queue();
teamServer.stop(false).thenRun(() -> event.getHook().editOriginal(
teamServer.stop().thenRun(() -> event.getHook().editOriginal(
context.localize("command.server.process.stop.message.stopped")).queue());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
var count = jam.teams().teams().stream()
.map(serverService::get)
.filter(server -> {
var running = server.running();
var running = server.isRunning();
if (running) {
server.stop(true);
server.stop();
}
return running;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
}

var started = optTeam.map(serverService::get).map(server -> {
var running = server.running();
var running = server.isRunning();
server.restart();
return running;
}).orElse(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
var count = jam.teams().teams().stream()
.map(serverService::get)
.map(server -> {
var running = server.running();
server.stop(false);
var running = server.isRunning();
server.stop();
return running;
})
.filter(v -> v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
}

var started = optTeam.map(serverService::get).map(server -> {
var running = server.running();
var running = server.isRunning();
server.stop();
return running;
}).orElse(false);
Expand Down
18 changes: 12 additions & 6 deletions bot/src/main/java/de/chojo/gamejam/configuration/ConfigFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@

package de.chojo.gamejam.configuration;

import de.chojo.gamejam.configuration.elements.Api;
import de.chojo.gamejam.configuration.elements.BaseSettings;
import de.chojo.gamejam.configuration.elements.Database;
import de.chojo.gamejam.configuration.elements.Plugins;
import de.chojo.gamejam.configuration.elements.ServerManagement;
import de.chojo.gamejam.configuration.elements.ServerTemplate;
import de.chojo.gamejam.configuration.elements.*;

@SuppressWarnings("FieldMayBeFinal")
public class ConfigFile {
private BaseSettings baseSettings = new BaseSettings();
private Database database = new Database();
private Api api = new Api();
private ServerManagement serverManagement = new ServerManagement();

private Docker docker = new Docker();
private Plugins plugins = new Plugins();

public void setServerTemplate(ServerTemplate serverTemplate) {
this.serverTemplate = serverTemplate;
}

private ServerTemplate serverTemplate = new ServerTemplate();

public BaseSettings baseSettings() {
Expand All @@ -38,6 +40,10 @@ public ServerManagement serverManagement(){
return serverManagement;
}

public Docker docker() {
return docker;
}

public Plugins plugins() {
return plugins;
}
Expand Down
38 changes: 22 additions & 16 deletions bot/src/main/java/de/chojo/gamejam/configuration/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@

package de.chojo.gamejam.configuration;

import de.chojo.gamejam.configuration.elements.Api;
import de.chojo.gamejam.configuration.elements.BaseSettings;
import de.chojo.gamejam.configuration.elements.Database;
import de.chojo.gamejam.configuration.elements.Plugins;
import de.chojo.gamejam.configuration.elements.ServerManagement;
import de.chojo.gamejam.configuration.elements.ServerTemplate;
import de.chojo.jdautil.configuration.BaseConfiguration;

public class Configuration extends BaseConfiguration<ConfigFile> {
import de.chojo.gamejam.configuration.elements.*;
import dev.chojo.ocular.Configurations;
import dev.chojo.ocular.dataformats.YamlDataFormat;
import dev.chojo.ocular.key.Key;

import java.nio.file.Path;
import java.util.List;

public class Configuration extends Configurations<ConfigFile> {
public static final Key<ConfigFile> MAIN = Key.builder(Path.of("config.yml"), ConfigFile::new).build();

private Configuration() {
super(new ConfigFile());
super(Path.of("config"), MAIN, List.of(new YamlDataFormat()), Configuration.class.getClassLoader(), null);
}

public static Configuration create() {
Expand All @@ -27,26 +29,30 @@ public static Configuration create() {


public Database database() {
return config().database();
return main().database();
}

public Docker docker() {
return main().docker();
}

public BaseSettings baseSettings() {
return config().baseSettings();
return main().baseSettings();
}

public Api api() {
return config().api();
return main().api();
}

public ServerManagement serverManagement() {
return config().serverManagement();
return main().serverManagement();
}

public Plugins plugins() {
return config().plugins();
return main().plugins();
}

public ServerTemplate serverTemplate() {
return config().serverTemplate();
return main().serverTemplate();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
*
* Copyright (C) 2022 DevCord Team and Contributor
*/

package de.chojo.gamejam.configuration.elements;

@SuppressWarnings({"FieldMayBeFinal", "FieldCanBeLocal"})
public class Docker {
private String host = "unix:///var/run/docker.sock";
private String certPath = "/home/user/.docker";
private boolean tlsVerify = true;
private String registryUsername;
private String registryPassword;
private String registryEmail;
private String registryUrl;
private String networkName = "plugin-jam-network";

public String getHost() {
return host;
}

public String getCertPath() {
return certPath;
}

public boolean isTlsVerify() {
return tlsVerify;
}

public String getRegistryUsername() {
return registryUsername;
}

public String getRegistryPassword() {
return registryPassword;
}

public String getRegistryEmail() {
return registryEmail;
}

public String getRegistryUrl() {
return registryUrl;
}

public String getNetworkName() {
return networkName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@
@SuppressWarnings({"FieldMayBeFinal", "FieldCanBeLocal"})
public class Plugins {
private String pluginDir = "plugins";
private List<String> defaultPlugins = List.of();

public String pluginDir() {
return pluginDir;
}

public List<String> defaultPlugins() {
return defaultPlugins;
}

private Path pluginPath() {
return Path.of(pluginDir);
}
Expand Down
Loading