Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs committed Aug 18, 2024
1 parent 461a21a commit 1bebb42
Show file tree
Hide file tree
Showing 23 changed files with 446 additions and 476 deletions.
13 changes: 4 additions & 9 deletions bot/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,18 @@ dependencies {
implementation(project(":plugin-api"))

// discord
implementation("de.chojo", "cjda-util", "2.7.8+alpha.22-DEV") {
implementation("de.chojo", "cjda-util", "2.9.8+jda-5.0.0") {
exclude(module = "opus-java")
}
implementation("io.javalin", "javalin-bundle", "4.4.0")
implementation(libs.javalin.bundle)
implementation("net.lingala.zip4j", "zip4j", "2.11.2")

// database
implementation("de.chojo.sadu", "sadu-queries", "1.2.0")
implementation("de.chojo.sadu", "sadu-updater", "1.2.0")
implementation("de.chojo.sadu", "sadu-datasource", "1.2.0")
implementation("de.chojo.sadu", "sadu-postgresql", "1.2.0")
implementation(libs.bundles.sadu)
implementation("org.postgresql", "postgresql", "42.3.3")

// Logging
implementation("org.slf4j", "slf4j-api", "2.0.3")
implementation("org.apache.logging.log4j", "log4j-core", "2.19.0")
implementation("org.apache.logging.log4j", "log4j-slf4j2-impl", "2.19.0")
implementation(libs.bundles.logging)
implementation("club.minnced", "discord-webhooks", "0.7.5")

// unit testing
Expand Down
50 changes: 25 additions & 25 deletions bot/src/main/java/de/chojo/gamejam/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import de.chojo.jdautil.interactions.dispatching.InteractionHub;
import de.chojo.jdautil.localization.ILocalizer;
import de.chojo.jdautil.localization.Localizer;
import de.chojo.sadu.databases.PostgreSql;
import de.chojo.sadu.core.exceptions.ExceptionTransformer;
import de.chojo.sadu.datasource.DataSourceCreator;
import de.chojo.sadu.exceptions.ExceptionTransformer;
import de.chojo.sadu.mapper.PostgresqlMapper;
import de.chojo.sadu.mapper.RowMapperRegistry;
import de.chojo.sadu.postgresql.databases.PostgreSql;
import de.chojo.sadu.postgresql.mapper.PostgresqlMapper;
import de.chojo.sadu.queries.api.configuration.QueryConfiguration;
import de.chojo.sadu.updater.QueryReplacement;
import de.chojo.sadu.updater.SqlUpdater;
import de.chojo.sadu.wrapper.QueryBuilderConfig;
import net.dv8tion.jda.api.interactions.DiscordLocale;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.requests.RestAction;
Expand Down Expand Up @@ -128,7 +128,7 @@ private void buildLocale() {
localizer = Localizer.builder(DiscordLocale.ENGLISH_US)
.addLanguage(DiscordLocale.GERMAN)
.withLanguageProvider(guild -> Optional.ofNullable(guilds.guild(guild).settings().locale())
.map(DiscordLocale::from))
.map(DiscordLocale::from))
.build();
}

Expand All @@ -144,48 +144,48 @@ private void buildCommands() {
new Server(guilds, serverService, configuration),
new ServerAdmin(guilds, serverService))
.withPagination(builder -> builder.withLocalizer(localizer)
.withCache(cache -> cache.expireAfterAccess(30, TimeUnit.MINUTES)))
.withCache(cache -> cache.expireAfterAccess(30, TimeUnit.MINUTES)))
.withMenuService(builder -> builder.withLocalizer(localizer)
.withCache(cache -> cache.expireAfterAccess(30, TimeUnit.MINUTES)))
.withCache(cache -> cache.expireAfterAccess(30, TimeUnit.MINUTES)))
.withModalService(builder -> builder.withLocalizer(localizer))
.build();
}

private void initBot() {
shardManager = DefaultShardManagerBuilder.createDefault(configuration.baseSettings().token())
.enableIntents(
GatewayIntent.GUILD_MEMBERS,
GatewayIntent.DIRECT_MESSAGES,
GatewayIntent.GUILD_MESSAGES)
.setMemberCachePolicy(MemberCachePolicy.DEFAULT)
.setEventPool(Executors.newScheduledThreadPool(5, createThreadFactory("Event Worker")))
.build();
.enableIntents(
GatewayIntent.GUILD_MEMBERS,
GatewayIntent.DIRECT_MESSAGES,
GatewayIntent.GUILD_MESSAGES)
.setMemberCachePolicy(MemberCachePolicy.DEFAULT)
.setEventPool(Executors.newScheduledThreadPool(5, createThreadFactory("Event Worker")))
.build();
RestAction.setDefaultFailure(throwable -> log.error("Unhandled exception occured: ", throwable));
serverService.inject(new Teams(dataSource, guilds, shardManager));
serverService.inject(new Teams(guilds, shardManager));
serverService.syncVelocity();
}

private void initDb() throws IOException, SQLException {
var mapperRegistry = new RowMapperRegistry();
mapperRegistry.register(PostgresqlMapper.getDefaultMapper());
QueryBuilderConfig.setDefault(QueryBuilderConfig.builder()
.withExceptionHandler(err -> log.error(ExceptionTransformer.prettyException(err), err))
.withExecutor(createExecutor("DataWorker"))
.rowMappers(mapperRegistry)
.build());

dataSource = DataSourceCreator.create(PostgreSql.get())
.configure(config -> {
config.host(configuration.database().host())
.port(configuration.database().port())
.database(configuration.database().database())
.user(configuration.database().user())
.password(configuration.database().password());
.port(configuration.database().port())
.database(configuration.database().database())
.user(configuration.database().user())
.password(configuration.database().password());
})
.create()
.forSchema(configuration.database().schema())
.build();

QueryConfiguration.setDefault(QueryConfiguration.builder(dataSource)
.setExceptionHandler(err -> log.error(ExceptionTransformer.prettyException(err), err))
.setRowMapperRegistry(mapperRegistry)
.build());


SqlUpdater.builder(dataSource, PostgreSql.get())
.setReplacements(new QueryReplacement("gamejam", configuration.database().schema()))
.setSchemas(configuration.database().schema())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.utils.messages.MessageEditData;

import java.util.Collections;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -55,8 +56,8 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont

context.registerPage(new ListPageBag<>(servers) {
@Override
public CompletableFuture<MessageEmbed> buildPage() {
return currentElement().detailStatus(context);
public CompletableFuture<MessageEditData> buildPage() {
return currentElement().detailStatus(context).thenApply(MessageEditData::fromEmbeds);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
.ifPresentOrElse(language -> {
settings.locale(language.getLocale());
event.reply(context.localize("command.settings.locale.message.updated")).setEphemeral(true).queue();
context.commandHub().refreshGuildCommands(event.getGuild());
context.interactionHub().refreshGuildCommands(event.getGuild());
}, () -> event.reply(context.localize("command.settings.locale.message.invalid")).setEphemeral(true).queue());

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import de.chojo.jdautil.wrapper.EventContext;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.utils.messages.MessageEditData;

import java.util.concurrent.CompletableFuture;

Expand All @@ -35,8 +36,8 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont

context.registerPage(new PrivateListPageBag<>(jam.teams().teams(), event.getUser().getIdLong()) {
@Override
public CompletableFuture<MessageEmbed> buildPage() {
return CompletableFuture.supplyAsync(() -> currentElement().profileEmbed(context.guildLocalizer()));
public CompletableFuture<MessageEditData> buildPage() {
return CompletableFuture.supplyAsync(() -> MessageEditData.fromEmbeds(currentElement().profileEmbed(context.guildLocalizer())));
}
}, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import de.chojo.jdautil.wrapper.EventContext;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
import net.dv8tion.jda.api.utils.messages.MessageEditData;

import java.util.concurrent.CompletableFuture;

Expand Down Expand Up @@ -43,13 +45,13 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont

var pageBag = new ListPageBag<>(ranking) {
@Override
public CompletableFuture<MessageEmbed> buildPage() {
public CompletableFuture<MessageEditData> buildPage() {
var teamVote = currentElement();
var embed = new LocalizedEmbedBuilder(context.guildLocalizer())
.setTitle(teamVote.rank() + " | " + teamVote.team().meta().name())
.addField("command.votes.ranking.embed.votes", String.valueOf(teamVote.votes()), true)
.build();
return CompletableFuture.completedFuture(embed);
return CompletableFuture.completedFuture(MessageEditData.fromEmbeds(embed));
}
};
context.registerPage(pageBag, true);
Expand Down
7 changes: 4 additions & 3 deletions bot/src/main/java/de/chojo/gamejam/data/access/Guilds.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public class Guilds {
private final Cache<Long, JamGuild> cache = CacheBuilder.newBuilder().expireAfterAccess(10, TimeUnit.MINUTES)
.build();
.build();
private final DataSource dataSource;

public Guilds(DataSource dataSource) {
Expand All @@ -31,15 +31,16 @@ public JamGuild guild(Interaction interaction) {

public JamGuild guild(Guild guild) {
try {
return cache.get(guild.getIdLong(), () -> new JamGuild(dataSource, guild)).refresh(guild);
return cache.get(guild.getIdLong(), () -> new JamGuild(guild)).refresh(guild);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}

}

public JamGuild guild(long guild) {
try {
return cache.get(guild, () -> new JamGuild(dataSource, guild));
return cache.get(guild, () -> new JamGuild(guild));
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
Expand Down
29 changes: 13 additions & 16 deletions bot/src/main/java/de/chojo/gamejam/data/access/Teams.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,41 @@
package de.chojo.gamejam.data.access;

import de.chojo.gamejam.data.dao.guild.jams.jam.teams.Team;
import de.chojo.sadu.base.QueryFactory;
import net.dv8tion.jda.api.sharding.ShardManager;
import org.slf4j.Logger;

import javax.sql.DataSource;
import java.util.Optional;

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

public class Teams extends QueryFactory {
public class Teams {
private static final Logger log = getLogger(Teams.class);
private final Guilds guilds;
private final ShardManager shardManager;

public Teams(DataSource dataSource, Guilds guilds, ShardManager shardManager) {
super(dataSource);
public Teams(Guilds guilds, ShardManager shardManager) {
this.guilds = guilds;
this.shardManager = shardManager;
}

public Optional<Team> byId(int id) {
return builder(Team.class)
.query("""
SELECT guild_id
FROM team t
LEFT JOIN jam j ON t.jam_id = j.id
WHERE t.id = ?
""")
.parameter(stmt -> stmt.setInt(id))
.readRow(row -> {
return query("""
SELECT guild_id
FROM team t
LEFT JOIN jam j ON t.jam_id = j.id
WHERE t.id = ?
""")
.single(call().bind(id))
.map(row -> {
var guildId = row.getLong("guild_id");
var guildById = shardManager.getGuildById(guildId);
if (guildById == null) {
log.warn("Could not find guild with id {}", guildId);
return guilds.guild(guildId).teams().byId(id).orElse(null);
}
return guilds.guild(guildById).teams().byId(id).orElse(null);
})
.firstSync();
}).first();
}
}
32 changes: 14 additions & 18 deletions bot/src/main/java/de/chojo/gamejam/data/dao/JamGuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,44 @@
import de.chojo.gamejam.data.dao.guild.Jams;
import de.chojo.gamejam.data.dao.guild.Settings;
import de.chojo.gamejam.data.dao.guild.Teams;
import de.chojo.sadu.base.QueryFactory;
import net.dv8tion.jda.api.entities.Guild;

import javax.sql.DataSource;
import static de.chojo.sadu.queries.api.call.Call.call;
import static de.chojo.sadu.queries.api.query.Query.query;

public class JamGuild extends QueryFactory {
public class JamGuild {
private final long guildId;
private Guild guild;
private final Jams jams;
private final Teams teams;

public JamGuild(DataSource dataSource, Guild guild) {
super(dataSource);
public JamGuild(Guild guild) {
this.guild = guild;
this.guildId = guild.getIdLong();
jams = new Jams(this);
teams = new Teams(this);
}

public JamGuild(DataSource dataSource, long guild) {
super(dataSource);
public JamGuild(long guild) {
this.guild = null;
this.guildId = guild;
jams = new Jams(this);
teams = new Teams(this);
}

public Settings settings() {
return builder(Settings.class)
.query("SELECT manager_role, locale FROM settings WHERE guild_id = ?")
.parameter(p -> p.setLong(guild.getIdLong()))
.readRow(r -> new Settings(this, guild.getIdLong(), r.getString("locale"), r.getLong("manager_role")))
.firstSync()
.orElseGet(() -> new Settings(this, guild.getIdLong()));
return query("SELECT manager_role, locale FROM settings WHERE guild_id = ?")
.single(call().bind(guild.getIdLong()))
.map(r -> new Settings(guild.getIdLong(), r.getString("locale"), r.getLong("manager_role")))
.first()
.orElseGet(() -> new Settings(guild.getIdLong()));
}

public JamSettings jamSettings() {
return builder(JamSettings.class)
.query("SELECT jam_role, team_size FROM jam_settings WHERE guild_id = ?")
.parameter(p -> p.setLong(guild.getIdLong()))
.readRow(r -> new JamSettings(this, r.getInt("team_size"), r.getLong("jam_role")))
.firstSync()
return query("SELECT jam_role, team_size FROM jam_settings WHERE guild_id = ?")
.single(call().bind(guild.getIdLong()))
.map(r -> new JamSettings(this, r.getInt("team_size"), r.getLong("jam_role")))
.first()
.orElseGet(() -> new JamSettings(this));
}

Expand Down
Loading

0 comments on commit 1bebb42

Please sign in to comment.