diff --git a/bot/build.gradle b/bot/build.gradle index b35e831..9fbe1b3 100644 --- a/bot/build.gradle +++ b/bot/build.gradle @@ -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' diff --git a/bot/src/main/java/net/lindseybot/bot/spring/DiscordConfig.java b/bot/src/main/java/net/lindseybot/bot/spring/DiscordConfig.java index cb97e79..8954dcd 100644 --- a/bot/src/main/java/net/lindseybot/bot/spring/DiscordConfig.java +++ b/bot/src/main/java/net/lindseybot/bot/spring/DiscordConfig.java @@ -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; @@ -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 @@ -57,15 +55,10 @@ public InteractionService interactionService(List 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); } } diff --git a/bot/src/main/java/net/lindseybot/bot/spring/RedisConfig.java b/bot/src/main/java/net/lindseybot/bot/spring/RedisConfig.java deleted file mode 100644 index dc8a940..0000000 --- a/bot/src/main/java/net/lindseybot/bot/spring/RedisConfig.java +++ /dev/null @@ -1,58 +0,0 @@ -package net.lindseybot.bot.spring; - -import net.dv8tion.jda.api.sharding.ShardManager; -import net.lindseybot.shared.worker.legacy.LegacyListener; -import org.springframework.boot.autoconfigure.data.redis.RedisProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.data.redis.connection.RedisConnection; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.data.redis.connection.RedisStandaloneConfiguration; -import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.listener.ChannelTopic; -import org.springframework.data.redis.listener.PatternTopic; -import org.springframework.data.redis.listener.RedisMessageListenerContainer; - -@Configuration -public class RedisConfig { - - @Bean - @Primary - public RedisProperties redisProperties() { - return new RedisProperties(); - } - - @Bean - @Primary - public RedisConnectionFactory redisFactory(RedisProperties properties) { - RedisStandaloneConfiguration config = - new RedisStandaloneConfiguration(properties.getHost(), properties.getPort()); - if (properties.getPassword() != null && !properties.getPassword().isBlank()) { - config.setPassword(properties.getPassword()); - } - return new LettuceConnectionFactory(config); - } - - @Bean - public RedisConnection redisConnection(RedisConnectionFactory factory) { - return factory.getConnection(); - } - - @Bean - public RedisTemplate redisTemplate(RedisConnectionFactory factory) { - RedisTemplate template = new RedisTemplate<>(); - template.setConnectionFactory(factory); - return template; - } - - @Bean - public RedisMessageListenerContainer listeners(RedisConnectionFactory factory, ShardManager api) { - RedisMessageListenerContainer container = new RedisMessageListenerContainer(); - container.setConnectionFactory(factory); - container.addMessageListener(new LegacyListener(api), new ChannelTopic("legacy")); - return container; - } - -} diff --git a/bot/src/main/java/net/lindseybot/bot/spring/WorkerConfig.java b/bot/src/main/java/net/lindseybot/bot/spring/WorkerConfig.java index b8b8f82..27d177d 100644 --- a/bot/src/main/java/net/lindseybot/bot/spring/WorkerConfig.java +++ b/bot/src/main/java/net/lindseybot/bot/spring/WorkerConfig.java @@ -1,6 +1,5 @@ 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; @@ -8,13 +7,9 @@ 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 { @@ -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); diff --git a/bot/src/main/resources/application.yml b/bot/src/main/resources/application.yml index 5a2fd9c..83495ac 100644 --- a/bot/src/main/resources/application.yml +++ b/bot/src/main/resources/application.yml @@ -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 diff --git a/common/build.gradle b/common/build.gradle index cd0a0be..4860e2e 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -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') diff --git a/common/src/main/java/net/lindseybot/shared/worker/Metrics.java b/common/src/main/java/net/lindseybot/shared/worker/Metrics.java deleted file mode 100644 index 7968956..0000000 --- a/common/src/main/java/net/lindseybot/shared/worker/Metrics.java +++ /dev/null @@ -1,40 +0,0 @@ -package net.lindseybot.shared.worker; - -import io.prometheus.client.CollectorRegistry; -import io.prometheus.client.Summary; -import io.prometheus.client.exporter.HTTPServer; -import lombok.extern.slf4j.Slf4j; - -import java.io.Closeable; -import java.io.IOException; - -@Slf4j -public class Metrics implements Closeable { - - private final HTTPServer server; - - private final Summary commands; - - public Metrics() throws IOException { - CollectorRegistry registry = new CollectorRegistry(); - this.server = new HTTPServer.Builder() - .withPort(1234) - .withRegistry(registry) - .build(); - this.commands = Summary.build() - .name("lindsey_commands") - .help("Command execution timings.") - .labelNames("name", "slash") - .register(registry); - } - - @Override - public void close() { - this.server.close(); - } - - public Summary.Child commands(String name, boolean slash) { - return this.commands.labels(name, String.valueOf(slash)); - } - -} diff --git a/common/src/main/java/net/lindseybot/shared/worker/impl/DefaultInteractionListener.java b/common/src/main/java/net/lindseybot/shared/worker/impl/DefaultInteractionListener.java index 1c4e69d..3f95e2d 100644 --- a/common/src/main/java/net/lindseybot/shared/worker/impl/DefaultInteractionListener.java +++ b/common/src/main/java/net/lindseybot/shared/worker/impl/DefaultInteractionListener.java @@ -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; @@ -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; @@ -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 @@ -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) { @@ -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); @@ -118,7 +112,7 @@ public void onButtonInteraction(@NotNull ButtonInteractionEvent event) { event.deferEdit() .queue(); } else { - event.deferReply(reference.isEdit()) + event.deferReply(false) .queue(); } } @@ -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); @@ -156,7 +150,7 @@ public void onStringSelectInteraction(@NotNull StringSelectInteractionEvent even event.deferEdit() .queue(); } else { - event.deferReply(reference.isEdit()) + event.deferReply(false) .queue(); } } @@ -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); @@ -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(); } diff --git a/common/src/main/java/net/lindseybot/shared/worker/impl/DiscordInterceptor.java b/common/src/main/java/net/lindseybot/shared/worker/impl/DiscordInterceptor.java deleted file mode 100644 index d128ca3..0000000 --- a/common/src/main/java/net/lindseybot/shared/worker/impl/DiscordInterceptor.java +++ /dev/null @@ -1,113 +0,0 @@ -package net.lindseybot.shared.worker.impl; - -import lombok.extern.slf4j.Slf4j; -import okhttp3.HttpUrl; -import okhttp3.Interceptor; -import okhttp3.Request; -import okhttp3.Response; -import org.jetbrains.annotations.NotNull; - -import java.io.IOException; -import java.net.URL; - -@Slf4j -public class DiscordInterceptor implements Interceptor { - - private volatile String host; - private volatile Integer port; - private volatile String scheme; - - public DiscordInterceptor(URL url) { - this.host = url.getHost(); - this.scheme = url.getProtocol(); - if (url.getPort() != -1) { - this.port = url.getPort(); - } - } - - public DiscordInterceptor(String host) { - this.host = host; - } - - public DiscordInterceptor(String host, int port) { - this.host = host; - this.port = port; - } - - public DiscordInterceptor(String host, int port, String scheme) { - this.host = host; - this.port = port; - this.scheme = scheme; - } - - public void setHost(String host) { - this.host = host; - } - - public void setPort(Integer port) { - this.port = port; - } - - public void setScheme(String scheme) { - this.scheme = scheme; - } - - @Override - public @NotNull Response intercept(@NotNull Chain chain) throws IOException { - Request request = chain.request(); - if (!"discord.com".equals(request.url().host())) { - return chain.proceed(request); - } - HttpUrl.Builder builder = request.url() - .newBuilder(); - if (this.host != null) { - builder.host(this.host); - } - if (this.port != null) { - builder.port(this.port); - } - if (this.scheme != null) { - builder.scheme(scheme); - } - Response response = chain.proceed(request.newBuilder() - .url(builder.build()).build()); - if (response.code() == 429) { - if (response.body() != null) { - response.close(); - } - log.warn("Encountered 429 on route: " + request.url().pathSegments() + ".. retrying."); - response = chain.proceed(request.newBuilder() - .url(builder.build()).build()); - if (response.code() == 429) { - log.warn("Encountered another 429 on route: " + request.url().pathSegments() + ". Failing request."); - return replaceStatus(response); - } else { - return stripHeaders(response); - } - } else { - return this.stripHeaders(response); - } - } - - private Response replaceStatus(Response response) { - return stripHeaders(response.newBuilder().code(400).build()); - } - - private Response stripHeaders(Response response) { - return response.newBuilder() - .removeHeader("X-RateLimit-Global") - .removeHeader("X-RateLimit-Global".toLowerCase()) - .removeHeader("X-RateLimit-Limit") - .removeHeader("X-RateLimit-Limit".toLowerCase()) - .removeHeader("X-RateLimit-Remaining") - .removeHeader("X-RateLimit-Remaining".toLowerCase()) - .removeHeader("X-RateLimit-Reset") - .removeHeader("X-RateLimit-Reset".toLowerCase()) - .removeHeader("X-RateLimit-Reset-After") - .removeHeader("X-RateLimit-Reset-After".toLowerCase()) - .removeHeader("X-RateLimit-Bucket") - .removeHeader("X-RateLimit-Bucket".toLowerCase()) - .build(); - } - -} diff --git a/common/src/main/java/net/lindseybot/shared/worker/impl/GatewayController.java b/common/src/main/java/net/lindseybot/shared/worker/impl/GatewayController.java deleted file mode 100644 index 5f35814..0000000 --- a/common/src/main/java/net/lindseybot/shared/worker/impl/GatewayController.java +++ /dev/null @@ -1,31 +0,0 @@ -package net.lindseybot.shared.worker.impl; - -import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.utils.ConcurrentSessionController; -import net.lindseybot.shared.properties.BotProperties; -import net.lindseybot.shared.properties.ShardProperties; -import org.jetbrains.annotations.NotNull; - -public class GatewayController extends ConcurrentSessionController { - - private final BotProperties config; - - public GatewayController(BotProperties config) { - this.config = config; - } - - @NotNull - @Override - public String getGateway() { - return config.getGateway(); - } - - @NotNull - @Override - public ShardedGateway getShardedGateway(@NotNull JDA api) { - ShardProperties shards = config.getShards(); - int concurrency = shards.getTotal() > 2 ? 16 : shards.getTotal(); - return new ShardedGateway(config.getGateway(), shards.getTotal(), concurrency); - } - -} diff --git a/common/src/main/java/net/lindseybot/shared/worker/impl/IsFakeSlash.java b/common/src/main/java/net/lindseybot/shared/worker/impl/IsFakeSlash.java new file mode 100644 index 0000000..639b025 --- /dev/null +++ b/common/src/main/java/net/lindseybot/shared/worker/impl/IsFakeSlash.java @@ -0,0 +1,11 @@ +package net.lindseybot.shared.worker.impl; + +import net.dv8tion.jda.api.entities.Message; +import org.jetbrains.annotations.NotNull; + +public interface IsFakeSlash { + + @NotNull + Message getMessage(); + +} diff --git a/common/src/main/java/net/lindseybot/shared/worker/impl/MessengerImpl.java b/common/src/main/java/net/lindseybot/shared/worker/impl/MessengerImpl.java index 8aca08e..a30019c 100644 --- a/common/src/main/java/net/lindseybot/shared/worker/impl/MessengerImpl.java +++ b/common/src/main/java/net/lindseybot/shared/worker/impl/MessengerImpl.java @@ -12,7 +12,6 @@ import net.dv8tion.jda.api.utils.messages.MessageCreateData; import net.dv8tion.jda.api.utils.messages.MessageEditData; import net.lindseybot.shared.entities.discord.FMessage; -import net.lindseybot.shared.worker.legacy.FakeSlashCommand; import net.lindseybot.shared.worker.services.DiscordAdapter; import net.lindseybot.shared.worker.services.Messenger; import org.jetbrains.annotations.NotNull; @@ -39,7 +38,7 @@ private MessageEditData toEdit(FMessage message, ISnowflake member) { @Override public void reply(@NotNull SlashCommandInteractionEvent event, @NotNull FMessage message) { MessageCreateData content = this.toNew(message, event.getMember()); - if (event instanceof FakeSlashCommand fake) { + if (event instanceof IsFakeSlash fake) { this.reply(fake.getMessage(), message); } else if (event.isAcknowledged()) { var hook = event.getHook() @@ -109,7 +108,7 @@ public void reply(@NotNull ModalInteractionEvent event, @NotNull FMessage messag @Override public void edit(@NotNull SlashCommandInteractionEvent event, @NotNull FMessage message) { MessageEditData content = this.toEdit(message, event.getMember()); - if (event instanceof FakeSlashCommand fake) { + if (event instanceof IsFakeSlash fake) { this.reply(fake.getMessage(), message); } else if (event.isAcknowledged()) { var hook = event.getHook() diff --git a/common/src/main/java/net/lindseybot/shared/worker/legacy/LegacyListener.java b/common/src/main/java/net/lindseybot/shared/worker/legacy/LegacyListener.java deleted file mode 100644 index bd0e570..0000000 --- a/common/src/main/java/net/lindseybot/shared/worker/legacy/LegacyListener.java +++ /dev/null @@ -1,128 +0,0 @@ -package net.lindseybot.shared.worker.legacy; - -import com.fasterxml.jackson.databind.ObjectMapper; -import gnu.trove.map.TLongObjectMap; -import lombok.extern.slf4j.Slf4j; -import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.User; -import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; -import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; -import net.dv8tion.jda.api.exceptions.InsufficientPermissionException; -import net.dv8tion.jda.api.sharding.ShardManager; -import net.dv8tion.jda.api.utils.MiscUtil; -import net.lindseybot.shared.worker.impl.DefaultInteractionListener; -import org.jetbrains.annotations.NotNull; -import org.springframework.data.redis.connection.Message; -import org.springframework.data.redis.connection.MessageListener; - -import java.io.IOException; -import java.util.Map; - -@Slf4j -public class LegacyListener implements MessageListener { - - private final ShardManager api; - private final ObjectMapper objectMapper = new ObjectMapper(); - - private DefaultInteractionListener listener = null; - - public LegacyListener(ShardManager api) { - this.api = api; - } - - @Override - public void onMessage(@NotNull Message message, byte[] pattern) { - FakeSlashData data; - try { - data = objectMapper.readValue(message.getBody(), FakeSlashData.class); - } catch (IOException ex) { - return; - } - Guild guild = this.api.getGuildById(data.getGuildId()); - if (guild == null) { - return; - } - this.resolve(guild, data.getOptions()); - // -- - GuildChannel channel = guild.getGuildChannelById(data.getChannelId()); - if (!(channel instanceof GuildMessageChannel msgChannel)) { - return; - } else if (!msgChannel.canTalk()) { - return; - } - try { - var msg = msgChannel.retrieveMessageById(data.getMessageId()) - .complete(); - if (msg == null) { - return; - } - FakeSlashCommand command = new FakeSlashCommand(this.api, data, msg); - DefaultInteractionListener listener = this.getListener(); - if (listener == null) { - log.warn("Received a legacy command but no listener was found."); - return; - } - listener.onSlashCommandInteraction(command); - } catch (InsufficientPermissionException ex) { - // Ignored - } - } - - private void resolve(Guild guild, Map options) { - options.forEach((name, value) -> { - switch (value.getType()) { - case USER -> { - TLongObjectMap resolved = MiscUtil.newLongMap(); - Member member = guild.retrieveMemberById(value.getValue()) - .complete(); - if (member != null) { - resolved.put(member.getIdLong(), member); - value.setResolved(resolved); - return; - } - User user = this.api.retrieveUserById(value.getValue()) - .complete(); - if (user != null) { - resolved.put(user.getIdLong(), user); - value.setResolved(resolved); - } else { - log.warn("Invalid user: " + value.getValue()); - } - } - case CHANNEL -> { - GuildChannel channel = guild.getGuildChannelById(value.getValue()); - if (channel == null) { - log.warn("Invalid channel: " + value.getValue()); - return; - } - TLongObjectMap resolved = MiscUtil.newLongMap(); - resolved.put(channel.getIdLong(), channel); - value.setResolved(resolved); - } - case ROLE -> { - Role role = guild.getRoleById(value.getValue()); - if (role == null) { - log.warn("Invalid role: " + value.getValue()); - return; - } - TLongObjectMap resolved = MiscUtil.newLongMap(); - resolved.put(role.getIdLong(), role); - value.setResolved(resolved); - } - } - }); - } - - private DefaultInteractionListener getListener() { - if (this.listener == null) { - listener = (DefaultInteractionListener) api.getShards().get(0) - .getRegisteredListeners() - .stream().filter(l -> l.getClass().getName().equals(DefaultInteractionListener.class.getName())) - .findAny().orElse(null); - } - return this.listener; - } - -} diff --git a/module-legacy/build.gradle b/module-legacy/build.gradle index 6adabe9..53f1fdb 100644 --- a/module-legacy/build.gradle +++ b/module-legacy/build.gradle @@ -35,10 +35,9 @@ dependencies { implementation project(':common') api('redis.clients:jedis:4.2.1') - api("com.fasterxml.jackson.core:jackson-databind:${JACKSON_VERSION}") + api('net.sf.trove4j:trove4j:3.0.3') // Spring - implementation('org.springframework.boot:spring-boot-starter-data-redis') implementation('org.springframework.boot:spring-boot-starter-data-jpa') implementation('org.springframework.boot:spring-boot-starter') diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/AnimeConverter.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/AnimeConverter.java index e8181f4..1562d33 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/AnimeConverter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/AnimeConverter.java @@ -3,8 +3,8 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.lindseybot.legacy.models.SlashConverter; -import net.lindseybot.shared.worker.legacy.FakeOptionMapping; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeOptionMapping; +import net.lindseybot.legacy.fake.FakeSlashData; import org.springframework.stereotype.Component; @Component diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/CalcConverter.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/CalcConverter.java index d022b6d..eb2f525 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/CalcConverter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/CalcConverter.java @@ -3,8 +3,8 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.lindseybot.legacy.models.SlashConverter; -import net.lindseybot.shared.worker.legacy.FakeOptionMapping; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeOptionMapping; +import net.lindseybot.legacy.fake.FakeSlashData; import org.springframework.stereotype.Component; @Component diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/ColorConverter.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/ColorConverter.java index 6f4ad19..8b9ff73 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/ColorConverter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/ColorConverter.java @@ -3,8 +3,8 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.lindseybot.legacy.models.SlashConverter; -import net.lindseybot.shared.worker.legacy.FakeOptionMapping; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeOptionMapping; +import net.lindseybot.legacy.fake.FakeSlashData; import org.springframework.stereotype.Component; @Component diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/CookiesConverter.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/CookiesConverter.java index 27f23eb..80b6d29 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/CookiesConverter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/CookiesConverter.java @@ -6,8 +6,8 @@ import net.lindseybot.legacy.models.SlashConverter; import net.lindseybot.legacy.services.FinderUtil; import net.lindseybot.shared.entities.discord.Label; -import net.lindseybot.shared.worker.legacy.FakeOptionMapping; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeOptionMapping; +import net.lindseybot.legacy.fake.FakeSlashData; import net.lindseybot.shared.worker.services.Messenger; import org.springframework.stereotype.Component; diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/DanbooruConverter.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/DanbooruConverter.java index cce5759..006b312 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/DanbooruConverter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/DanbooruConverter.java @@ -3,8 +3,8 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.lindseybot.legacy.models.SlashConverter; -import net.lindseybot.shared.worker.legacy.FakeOptionMapping; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeOptionMapping; +import net.lindseybot.legacy.fake.FakeSlashData; import org.springframework.stereotype.Component; @Component diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/DefineConverter.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/DefineConverter.java index 7414cb8..c7aa2f0 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/DefineConverter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/DefineConverter.java @@ -3,8 +3,8 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.lindseybot.legacy.models.SlashConverter; -import net.lindseybot.shared.worker.legacy.FakeOptionMapping; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeOptionMapping; +import net.lindseybot.legacy.fake.FakeSlashData; import org.springframework.stereotype.Component; @Component diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/E621Converter.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/E621Converter.java index 51ac010..9764326 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/E621Converter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/E621Converter.java @@ -3,8 +3,8 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.lindseybot.legacy.models.SlashConverter; -import net.lindseybot.shared.worker.legacy.FakeOptionMapping; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeOptionMapping; +import net.lindseybot.legacy.fake.FakeSlashData; import org.springframework.stereotype.Component; @Component diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/FlipConverter.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/FlipConverter.java index dd5dc58..99c966e 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/FlipConverter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/FlipConverter.java @@ -2,7 +2,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.lindseybot.legacy.models.SlashConverter; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeSlashData; import org.springframework.stereotype.Component; @Component diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/GelbooruConverter.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/GelbooruConverter.java index 2590bc9..6cec35a 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/GelbooruConverter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/GelbooruConverter.java @@ -3,8 +3,8 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.lindseybot.legacy.models.SlashConverter; -import net.lindseybot.shared.worker.legacy.FakeOptionMapping; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeOptionMapping; +import net.lindseybot.legacy.fake.FakeSlashData; import org.springframework.stereotype.Component; @Component diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/HackBanConverter.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/HackBanConverter.java index bd8d8e3..0689e69 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/HackBanConverter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/HackBanConverter.java @@ -4,8 +4,8 @@ import net.dv8tion.jda.api.interactions.commands.OptionType; import net.lindseybot.legacy.models.SlashConverter; import net.lindseybot.shared.entities.discord.Label; -import net.lindseybot.shared.worker.legacy.FakeOptionMapping; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeOptionMapping; +import net.lindseybot.legacy.fake.FakeSlashData; import net.lindseybot.shared.worker.services.Messenger; import org.springframework.stereotype.Component; diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/LeaderboardConverter.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/LeaderboardConverter.java index 2077948..ad87029 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/LeaderboardConverter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/LeaderboardConverter.java @@ -3,8 +3,8 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.lindseybot.legacy.models.SlashConverter; -import net.lindseybot.shared.worker.legacy.FakeOptionMapping; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeOptionMapping; +import net.lindseybot.legacy.fake.FakeSlashData; import org.springframework.stereotype.Component; @Component diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/PrefixHandler.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/PrefixHandler.java index 381934d..f8b5332 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/PrefixHandler.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/PrefixHandler.java @@ -5,7 +5,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.lindseybot.legacy.models.SlashConverter; import net.lindseybot.legacy.services.LegacyService; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeSlashData; import org.springframework.stereotype.Component; @Component diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/ProfileConverter.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/ProfileConverter.java index 84e98f5..494137e 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/ProfileConverter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/ProfileConverter.java @@ -6,8 +6,8 @@ import net.lindseybot.legacy.models.SlashConverter; import net.lindseybot.legacy.services.FinderUtil; import net.lindseybot.shared.entities.discord.Label; -import net.lindseybot.shared.worker.legacy.FakeOptionMapping; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeOptionMapping; +import net.lindseybot.legacy.fake.FakeSlashData; import net.lindseybot.shared.worker.services.Messenger; import org.springframework.stereotype.Component; diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/PruneConverter.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/PruneConverter.java index 0e79b9a..12ceefe 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/PruneConverter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/PruneConverter.java @@ -6,8 +6,8 @@ import net.lindseybot.legacy.models.SlashConverter; import net.lindseybot.legacy.services.FinderUtil; import net.lindseybot.shared.entities.discord.Label; -import net.lindseybot.shared.worker.legacy.FakeOptionMapping; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeOptionMapping; +import net.lindseybot.legacy.fake.FakeSlashData; import net.lindseybot.shared.worker.services.Messenger; import org.springframework.stereotype.Component; diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/RollConverter.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/RollConverter.java index 99a84f3..f903f2b 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/RollConverter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/RollConverter.java @@ -4,8 +4,8 @@ import net.dv8tion.jda.api.interactions.commands.OptionType; import net.lindseybot.legacy.models.SlashConverter; import net.lindseybot.shared.entities.discord.Label; -import net.lindseybot.shared.worker.legacy.FakeOptionMapping; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeOptionMapping; +import net.lindseybot.legacy.fake.FakeSlashData; import net.lindseybot.shared.worker.services.Messenger; import org.springframework.stereotype.Component; diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/Rule34Converter.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/Rule34Converter.java index 87cd394..c3ab146 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/Rule34Converter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/Rule34Converter.java @@ -3,8 +3,8 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.lindseybot.legacy.models.SlashConverter; -import net.lindseybot.shared.worker.legacy.FakeOptionMapping; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeOptionMapping; +import net.lindseybot.legacy.fake.FakeSlashData; import org.springframework.stereotype.Component; @Component diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/ScrambleConverter.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/ScrambleConverter.java index a119e45..62dfb28 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/ScrambleConverter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/ScrambleConverter.java @@ -2,7 +2,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.lindseybot.legacy.models.SlashConverter; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeSlashData; import org.springframework.stereotype.Component; @Component diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/SoftBanConverter.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/SoftBanConverter.java index bc56837..b2f1563 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/SoftBanConverter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/SoftBanConverter.java @@ -6,8 +6,8 @@ import net.lindseybot.legacy.models.SlashConverter; import net.lindseybot.legacy.services.FinderUtil; import net.lindseybot.shared.entities.discord.Label; -import net.lindseybot.shared.worker.legacy.FakeOptionMapping; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeOptionMapping; +import net.lindseybot.legacy.fake.FakeSlashData; import net.lindseybot.shared.worker.services.Messenger; import org.springframework.stereotype.Component; diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/commands/VoiceConverter.java b/module-legacy/src/main/java/net/lindseybot/legacy/commands/VoiceConverter.java index b134ce3..62f1486 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/commands/VoiceConverter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/commands/VoiceConverter.java @@ -6,8 +6,8 @@ import net.lindseybot.legacy.models.SlashConverter; import net.lindseybot.legacy.services.FinderUtil; import net.lindseybot.shared.entities.discord.Label; -import net.lindseybot.shared.worker.legacy.FakeOptionMapping; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeOptionMapping; +import net.lindseybot.legacy.fake.FakeSlashData; import net.lindseybot.shared.worker.services.Messenger; import org.springframework.stereotype.Component; diff --git a/common/src/main/java/net/lindseybot/shared/worker/legacy/FakeOptionMapping.java b/module-legacy/src/main/java/net/lindseybot/legacy/fake/FakeOptionMapping.java similarity index 89% rename from common/src/main/java/net/lindseybot/shared/worker/legacy/FakeOptionMapping.java rename to module-legacy/src/main/java/net/lindseybot/legacy/fake/FakeOptionMapping.java index 1c50fea..5febe48 100644 --- a/common/src/main/java/net/lindseybot/shared/worker/legacy/FakeOptionMapping.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/fake/FakeOptionMapping.java @@ -1,4 +1,4 @@ -package net.lindseybot.shared.worker.legacy; +package net.lindseybot.legacy.fake; import com.fasterxml.jackson.annotation.JsonIgnore; import gnu.trove.map.TLongObjectMap; diff --git a/common/src/main/java/net/lindseybot/shared/worker/legacy/FakeSlashCommand.java b/module-legacy/src/main/java/net/lindseybot/legacy/fake/FakeSlashCommand.java similarity index 95% rename from common/src/main/java/net/lindseybot/shared/worker/legacy/FakeSlashCommand.java rename to module-legacy/src/main/java/net/lindseybot/legacy/fake/FakeSlashCommand.java index f139d8f..4dccae8 100644 --- a/common/src/main/java/net/lindseybot/shared/worker/legacy/FakeSlashCommand.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/fake/FakeSlashCommand.java @@ -1,4 +1,4 @@ -package net.lindseybot.shared.worker.legacy; +package net.lindseybot.legacy.fake; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; @@ -14,13 +14,14 @@ import net.dv8tion.jda.api.utils.data.DataObject; import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import net.dv8tion.jda.api.utils.messages.MessageCreateData; -import net.lindseybot.shared.worker.legacy.proxy.ProxyRestAction; +import net.lindseybot.legacy.fake.proxy.ProxyRestAction; +import net.lindseybot.shared.worker.impl.IsFakeSlash; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; -public class FakeSlashCommand extends SlashCommandInteractionEvent { +public class FakeSlashCommand extends SlashCommandInteractionEvent implements IsFakeSlash { private final FakeSlashData data; private final Message message; diff --git a/common/src/main/java/net/lindseybot/shared/worker/legacy/FakeSlashData.java b/module-legacy/src/main/java/net/lindseybot/legacy/fake/FakeSlashData.java similarity index 89% rename from common/src/main/java/net/lindseybot/shared/worker/legacy/FakeSlashData.java rename to module-legacy/src/main/java/net/lindseybot/legacy/fake/FakeSlashData.java index d9c9856..9097635 100644 --- a/common/src/main/java/net/lindseybot/shared/worker/legacy/FakeSlashData.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/fake/FakeSlashData.java @@ -1,4 +1,4 @@ -package net.lindseybot.shared.worker.legacy; +package net.lindseybot.legacy.fake; import lombok.Getter; import lombok.Setter; diff --git a/common/src/main/java/net/lindseybot/shared/worker/legacy/proxy/ProxyRestAction.java b/module-legacy/src/main/java/net/lindseybot/legacy/fake/proxy/ProxyRestAction.java similarity index 98% rename from common/src/main/java/net/lindseybot/shared/worker/legacy/proxy/ProxyRestAction.java rename to module-legacy/src/main/java/net/lindseybot/legacy/fake/proxy/ProxyRestAction.java index 7ff553a..26f3984 100644 --- a/common/src/main/java/net/lindseybot/shared/worker/legacy/proxy/ProxyRestAction.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/fake/proxy/ProxyRestAction.java @@ -1,4 +1,4 @@ -package net.lindseybot.shared.worker.legacy.proxy; +package net.lindseybot.legacy.fake.proxy; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.IMentionable; @@ -11,7 +11,7 @@ import net.dv8tion.jda.api.utils.FileUpload; import net.dv8tion.jda.api.utils.messages.MessageCreateData; import net.dv8tion.jda.api.utils.messages.MessagePollData; -import net.lindseybot.shared.worker.legacy.FakeSlashCommand; +import net.lindseybot.legacy.fake.FakeSlashCommand; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/listeners/CommandListener.java b/module-legacy/src/main/java/net/lindseybot/legacy/listeners/CommandListener.java index 067d644..b0d8c11 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/listeners/CommandListener.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/listeners/CommandListener.java @@ -1,19 +1,25 @@ package net.lindseybot.legacy.listeners; -import com.fasterxml.jackson.databind.ObjectMapper; +import gnu.trove.map.TLongObjectMap; import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.IEventManager; import net.dv8tion.jda.api.hooks.ListenerAdapter; +import net.dv8tion.jda.api.interactions.commands.OptionType; +import net.dv8tion.jda.api.utils.MiscUtil; +import net.lindseybot.legacy.fake.FakeSlashCommand; +import net.lindseybot.legacy.fake.FakeSlashData; import net.lindseybot.legacy.models.SlashConverter; import net.lindseybot.legacy.services.LegacyService; import net.lindseybot.shared.entities.discord.Label; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.shared.worker.impl.DefaultInteractionListener; import net.lindseybot.shared.worker.services.Messenger; import org.jetbrains.annotations.NotNull; -import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; import java.util.ArrayList; @@ -31,25 +37,24 @@ public class CommandListener extends ListenerAdapter { private final LegacyService legacy; private final Pattern pattern = Pattern.compile("(?:([^\\s\"]+)|\"((?:\\w+|\\\\\"|[^\"])+)\")"); - private final Map converters; - private final StringRedisTemplate redis; - private final ObjectMapper objectMapper = new ObjectMapper(); + private final Map converters = new HashMap<>(); + private final DefaultInteractionListener listener; - public CommandListener(IEventManager api, - Messenger msg, - LegacyService legacy, - List converters, - StringRedisTemplate redis) { - api.register(this); + public CommandListener( + Messenger msg, + LegacyService legacy, + DefaultInteractionListener listener, + List converters, + IEventManager api) { this.msg = msg; this.legacy = legacy; - this.redis = redis; - this.converters = new HashMap<>(); + this.listener = listener; converters.forEach((c) -> { for (String name : c.getNames()) { this.converters.put(name, c); } }); + api.register(this); } @Override @@ -82,7 +87,7 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) { } else { arguments.remove(0); } - // -- Convert & Send + // -- Parse all arguments using converter SlashConverter converter = this.converters.get(name); if (converter == null) { return; @@ -91,13 +96,49 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) { if (data == null) { return; } - String json; - try { - json = objectMapper.writeValueAsString(data); - } catch (Exception ex) { - return; - } - redis.convertAndSend("legacy", json); + // -- Populate special parameters + data.getOptions().forEach((optName, option) -> { + if (option.getType() == OptionType.USER) { + TLongObjectMap resolved = MiscUtil.newLongMap(); + Member member = event.getGuild().retrieveMemberById(option.getValue()) + .complete(); + if (member != null) { + resolved.put(member.getIdLong(), member); + option.setResolved(resolved); + return; + } + User user = event.getJDA().retrieveUserById(option.getValue()) + .complete(); + if (user != null) { + resolved.put(user.getIdLong(), user); + option.setResolved(resolved); + } else { + log.warn("Invalid user: {}", option.getValue()); + } + } else if (option.getType() == OptionType.CHANNEL) { + GuildChannel channel = event.getGuild().getGuildChannelById(option.getValue()); + if (channel == null) { + log.warn("Invalid channel: {}", option.getValue()); + return; + } + TLongObjectMap resolved = MiscUtil.newLongMap(); + resolved.put(channel.getIdLong(), channel); + option.setResolved(resolved); + } else if (option.getType() == OptionType.ROLE) { + Role role = event.getGuild().getRoleById(option.getValue()); + if (role == null) { + log.warn("Invalid role: {}", option.getValue()); + return; + } + TLongObjectMap resolved = MiscUtil.newLongMap(); + resolved.put(role.getIdLong(), role); + option.setResolved(resolved); + } + }); + // -- Fire slash command event + FakeSlashCommand command = new FakeSlashCommand( + event.getJDA().getShardManager(), data, event.getMessage()); + this.listener.onSlashCommandInteraction(command); } private String findPrefix(String message, Guild guild, Member self) { diff --git a/module-legacy/src/main/java/net/lindseybot/legacy/models/SlashConverter.java b/module-legacy/src/main/java/net/lindseybot/legacy/models/SlashConverter.java index fab25ec..c7f6a94 100644 --- a/module-legacy/src/main/java/net/lindseybot/legacy/models/SlashConverter.java +++ b/module-legacy/src/main/java/net/lindseybot/legacy/models/SlashConverter.java @@ -1,7 +1,7 @@ package net.lindseybot.legacy.models; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; -import net.lindseybot.shared.worker.legacy.FakeSlashData; +import net.lindseybot.legacy.fake.FakeSlashData; public abstract class SlashConverter {