Skip to content
Open
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
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ dependencies {
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
implementation("org.apache.commons:commons-lang3:3.20.0")

implementation("com.eternalcode:eternalcode-commons-shared:1.3.3")
implementation("com.eternalcode:eternalcode-commons-shared:1.3.4")
implementation("com.eternalcode:eternalcode-commons-loom:1.3.4")

implementation("dev.skywolfxp:discord-channel-html-transcript:3.0.0")
}
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/com/eternalcode/discordapp/DiscordApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,18 @@
import com.eternalcode.discordapp.feature.review.command.GitHubReviewCommand;
import com.eternalcode.discordapp.feature.review.database.GitHubReviewMentionRepository;
import com.eternalcode.discordapp.feature.review.database.GitHubReviewMentionRepositoryImpl;
import com.eternalcode.discordapp.scheduler.Scheduler;
import com.eternalcode.discordapp.scheduler.VirtualThreadSchedulerImpl;
import com.eternalcode.commons.scheduler.loom.LoomScheduler;
import com.eternalcode.commons.scheduler.loom.LoomSchedulerImpl;
import com.eternalcode.commons.scheduler.loom.MainThreadDispatcher;
import com.eternalcode.discordapp.feature.ticket.TicketConfigurer;
import com.jagrosh.jdautilities.command.CommandClient;
import com.jagrosh.jdautilities.command.CommandClientBuilder;
import io.sentry.Sentry;
import java.io.File;
import java.time.Duration;
import java.util.EnumSet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
Expand All @@ -72,7 +75,7 @@ public class DiscordApp {

private static final Logger LOGGER = LoggerFactory.getLogger(DiscordApp.class);
private static final Duration REMINDER_INTERVAL = Duration.ofHours(24);
private Scheduler scheduler;
private LoomScheduler scheduler;
private GitHubReviewReminderService reminderService;
private JDA jda;
private DatabaseManager databaseManager;
Expand Down Expand Up @@ -117,7 +120,7 @@ private void runApplication() throws Exception {

LOGGER.info("Initializing core components...");
OkHttpClient httpClient = new OkHttpClient();
Scheduler scheduler = new VirtualThreadSchedulerImpl();
LoomScheduler scheduler = new LoomSchedulerImpl(MainThreadDispatcher.synchronous());
DatabaseManager databaseManager = new DatabaseManager(databaseConfig, new File("database"));
databaseManager.connect();
ObserverRegistry observerRegistry = new ObserverRegistry();
Expand Down Expand Up @@ -163,8 +166,10 @@ private void runApplication() throws Exception {

LOGGER.info("Initializing Discord bot...");
FilterService filterService = new FilterService().register(new RenovateForcedPushFilter());

ExecutorService virtualThreadExecutor = Executors.newVirtualThreadPerTaskExecutor();
JDA jda = JDABuilder.createDefault(appConfig.token)
.setEventPool(virtualThreadExecutor, true)
.setCallbackPool(virtualThreadExecutor, true)
.addEventListeners(
new ExperienceMessageListener(experienceConfig, experienceService),
new ExperienceReactionListener(experienceConfig, experienceService),
Expand Down Expand Up @@ -208,7 +213,6 @@ private void runApplication() throws Exception {
jda,
mentionRepo,
appConfig,
scheduler,
REMINDER_INTERVAL
);
reminderService.start();
Expand All @@ -219,13 +223,13 @@ private void runApplication() throws Exception {
});

LOGGER.info("Starting scheduled tasks...");
scheduler.schedule(new GuildStatisticsTask(guildStats), Duration.ofMinutes(5));
scheduler.runAsyncLater(new GuildStatisticsTask(guildStats), Duration.ofMinutes(5));
new GitHubReviewTask(reviewService, jda, scheduler).start();
scheduler.scheduleRepeating(new AutoMessageTask(autoMsgService), appConfig.autoMessagesConfig.interval);
scheduler.runAsyncTimer(new AutoMessageTask(autoMsgService), Duration.ZERO, appConfig.autoMessagesConfig.interval);

LOGGER.info("Auto messages scheduled with interval: {}", appConfig.autoMessagesConfig.interval);

scheduler.scheduleRepeating(new MeetingCleanupTask(meetingService, jda), Duration.ofHours(1));
scheduler.runAsyncTimer(new MeetingCleanupTask(meetingService, jda), Duration.ZERO, Duration.ofHours(1));

this.scheduler = scheduler;
this.reminderService = reminderService;
Expand All @@ -238,7 +242,7 @@ private void shutdown() {

try {
if (scheduler != null) {
scheduler.shutdown();
scheduler.shutdown(Duration.ofSeconds(30));
LOGGER.info("Scheduler stopped");
}

Expand Down
Loading