Skip to content

Commit

Permalink
Remove redis dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabricio20 committed Sep 23, 2024
1 parent e66c446 commit abc6b72
Show file tree
Hide file tree
Showing 39 changed files with 136 additions and 495 deletions.
2 changes: 0 additions & 2 deletions bot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ dependencies {
implementation('io.sentry:sentry-logback:6.2.1')

// Spring
implementation('redis.clients:jedis:4.2.1')
implementation('org.mariadb.jdbc:mariadb-java-client')
implementation('com.github.ben-manes.caffeine:caffeine:3.1.0')
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-data-redis')

// Development
testImplementation 'org.springframework.boot:spring-boot-starter-test'
Expand Down
11 changes: 2 additions & 9 deletions bot/src/main/java/net/lindseybot/bot/spring/DiscordConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import net.lindseybot.shared.properties.ShardProperties;
import net.lindseybot.shared.worker.InteractionHandler;
import net.lindseybot.shared.worker.InteractionService;
import net.lindseybot.shared.worker.Metrics;
import net.lindseybot.shared.worker.impl.DefaultInteractionListener;
import net.lindseybot.shared.worker.impl.DefaultInteractionService;
import net.lindseybot.shared.worker.impl.PooledEventManager;
Expand All @@ -19,7 +18,6 @@
import org.springframework.context.annotation.Configuration;

import javax.security.auth.login.LoginException;
import java.io.IOException;
import java.util.List;

@Slf4j
Expand Down Expand Up @@ -57,15 +55,10 @@ public InteractionService interactionService(List<InteractionHandler> handlers)
return new DefaultInteractionService(handlers);
}

@Bean
public Metrics metrics() throws IOException {
return new Metrics();
}

@Bean
public DefaultInteractionListener interactionListener(
InteractionService service, IEventManager api, Messenger msg, Metrics metrics) {
return new DefaultInteractionListener(service, api, msg, metrics);
InteractionService service, IEventManager api, Messenger msg) {
return new DefaultInteractionListener(service, api, msg);
}

}
58 changes: 0 additions & 58 deletions bot/src/main/java/net/lindseybot/bot/spring/RedisConfig.java

This file was deleted.

14 changes: 0 additions & 14 deletions bot/src/main/java/net/lindseybot/bot/spring/WorkerConfig.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package net.lindseybot.bot.spring;

import com.github.benmanes.caffeine.cache.Caffeine;
import net.lindseybot.shared.properties.BotProperties;
import net.lindseybot.shared.worker.impl.MessengerImpl;
import net.lindseybot.shared.worker.services.DiscordAdapter;
import net.lindseybot.shared.worker.services.Messenger;
import net.lindseybot.shared.worker.services.ProfileService;
import net.lindseybot.shared.worker.services.Translator;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class WorkerConfig {

Expand All @@ -24,15 +19,6 @@ public BotProperties bot() {
return new BotProperties();
}

@Bean
public CacheManager cacheManager() {
CaffeineCacheManager manager = new CaffeineCacheManager();
manager.setCaffeine(Caffeine.newBuilder()
.maximumSize(15_000)
.expireAfterWrite(60, TimeUnit.MINUTES));
return manager;
}

@Bean
public Messenger messenger(DiscordAdapter adapter) {
return new MessengerImpl(adapter);
Expand Down
5 changes: 0 additions & 5 deletions bot/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,3 @@ spring:
database-platform: org.hibernate.dialect.MariaDBDialect
hibernate:
ddl-auto: validate
data:
redis:
port: 6379
password: password
host: 127.0.0.1
6 changes: 0 additions & 6 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,10 @@ dependencies {
api("org.json:json:${ORG_JSON_VERSION}")
api("net.jodah:expiringmap:${EXPIRING_MAP_VERSION}")
api("com.fasterxml.jackson.core:jackson-databind:${JACKSON_VERSION}")
implementation('net.sf.trove4j:trove4j:3.0.3') // fake options

// Prometheus
api('org.jetbrains:annotations:24.0.0')
api('io.prometheus:simpleclient:0.16.0')
api('io.prometheus:simpleclient_httpserver:0.16.0')

// Spring
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-data-redis')

// Development
testImplementation('org.springframework.boot:spring-boot-starter-test')
Expand Down
40 changes: 0 additions & 40 deletions common/src/main/java/net/lindseybot/shared/worker/Metrics.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.lindseybot.shared.worker.impl;

import io.prometheus.client.Summary;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.channel.attribute.IAgeRestrictedChannel;
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
Expand All @@ -17,9 +16,7 @@
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.lindseybot.shared.entities.discord.Label;
import net.lindseybot.shared.worker.InteractionService;
import net.lindseybot.shared.worker.Metrics;
import net.lindseybot.shared.worker.UserError;
import net.lindseybot.shared.worker.legacy.FakeSlashCommand;
import net.lindseybot.shared.worker.reference.*;
import net.lindseybot.shared.worker.services.Messenger;
import org.jetbrains.annotations.NotNull;
Expand All @@ -33,21 +30,19 @@
public class DefaultInteractionListener extends ListenerAdapter {

private final Messenger msg;
private final Metrics metrics;
private final InteractionService service;
private final ThreadPoolTaskExecutor taskExecutor;

public DefaultInteractionListener(InteractionService service,
IEventManager api,
Messenger msg,
Metrics metrics) {
public DefaultInteractionListener(
InteractionService service,
IEventManager api,
Messenger msg) {
this.service = service;
this.msg = msg;
api.register(this);
taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setThreadNamePrefix("commands-");
taskExecutor.initialize();
this.metrics = metrics;
}

@Override
Expand All @@ -63,17 +58,16 @@ public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent even
return;
}
try {
Summary.Child timer = this.metrics.commands(event.getName(), !(event instanceof FakeSlashCommand));
this.taskExecutor.submit(() -> timer.observe(timer.time(() -> {
this.taskExecutor.submit(() -> {
try {
reference.invoke(event);
} catch (UserError error) {
this.msg.error(event, error.getLabel());
} catch (Exception ex) {
log.error("Failed to execute command: " + event.getFullCommandName(), ex);
log.error("Failed to execute command: {}", event.getFullCommandName(), ex);
this.msg.error(event, Label.of("error.internal"));
}
}))).get(1500, TimeUnit.MILLISECONDS);
}).get(1500, TimeUnit.MILLISECONDS);
} catch (ExecutionException | InterruptedException e) {
log.error("Failed to schedule command execution", e);
} catch (TimeoutException e) {
Expand Down Expand Up @@ -103,7 +97,7 @@ public void onButtonInteraction(@NotNull ButtonInteractionEvent event) {
} catch (UserError error) {
this.msg.error(event, error.getLabel());
} catch (Exception ex) {
log.error("Failed to execute button: " + event.getComponentId(), ex);
log.error("Failed to execute button: {}", event.getComponentId(), ex);
this.msg.error(event, Label.of("error.internal"));
}
}).get(1500, TimeUnit.MILLISECONDS);
Expand All @@ -118,7 +112,7 @@ public void onButtonInteraction(@NotNull ButtonInteractionEvent event) {
event.deferEdit()
.queue();
} else {
event.deferReply(reference.isEdit())
event.deferReply(false)
.queue();
}
}
Expand All @@ -141,7 +135,7 @@ public void onStringSelectInteraction(@NotNull StringSelectInteractionEvent even
} catch (UserError error) {
this.msg.error(event, error.getLabel());
} catch (Exception ex) {
log.error("Failed to execute select menu: " + event.getComponentId(), ex);
log.error("Failed to execute select menu: {}", event.getComponentId(), ex);
this.msg.error(event, Label.of("error.internal"));
}
}).get(1500, TimeUnit.MILLISECONDS);
Expand All @@ -156,7 +150,7 @@ public void onStringSelectInteraction(@NotNull StringSelectInteractionEvent even
event.deferEdit()
.queue();
} else {
event.deferReply(reference.isEdit())
event.deferReply(false)
.queue();
}
}
Expand Down Expand Up @@ -200,7 +194,7 @@ public void onMessageContextInteraction(@NotNull MessageContextInteractionEvent
} catch (UserError error) {
this.msg.error(event, error.getLabel());
} catch (Exception ex) {
log.error("Failed to execute message command: " + id, ex);
log.error("Failed to execute message command: {}", id, ex);
this.msg.error(event, Label.of("error.internal"));
}
}).get(1500, TimeUnit.MILLISECONDS);
Expand Down Expand Up @@ -270,7 +264,7 @@ public void onModalInteraction(@NotNull ModalInteractionEvent event) {
if (event.isAcknowledged()) {
return;
}
log.warn("Timed out during user execution: {}", id);
log.warn("Timed out during modal execution: {}", id);
event.deferReply(reference.isEphemeral())
.queue();
}
Expand Down
Loading

0 comments on commit abc6b72

Please sign in to comment.