From 7874473c69b4b7825c4f21dcd9c16f9436cc8c03 Mon Sep 17 00:00:00 2001 From: MattyHD0 Date: Tue, 14 Nov 2023 20:36:33 -0300 Subject: [PATCH 1/4] updated jda version --- Discord/pom.xml | 2 +- .../fixeddev/commandflow/discord/DiscordAuthorizer.java | 4 ++-- .../me/fixeddev/commandflow/discord/MessageListener.java | 8 ++++---- .../commandflow/discord/factory/DiscordModule.java | 2 +- .../me/fixeddev/commandflow/discord/part/MemberPart.java | 2 +- .../commandflow/discord/part/TextChannelPart.java | 2 +- .../me/fixeddev/commandflow/discord/part/UserPart.java | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Discord/pom.xml b/Discord/pom.xml index 59e048be..ccf459a3 100644 --- a/Discord/pom.xml +++ b/Discord/pom.xml @@ -25,7 +25,7 @@ net.dv8tion JDA - 4.2.0_208 + 5.0.0-beta.17 me.fixeddev diff --git a/Discord/src/main/java/me/fixeddev/commandflow/discord/DiscordAuthorizer.java b/Discord/src/main/java/me/fixeddev/commandflow/discord/DiscordAuthorizer.java index f359eb77..ec5c0f98 100644 --- a/Discord/src/main/java/me/fixeddev/commandflow/discord/DiscordAuthorizer.java +++ b/Discord/src/main/java/me/fixeddev/commandflow/discord/DiscordAuthorizer.java @@ -3,9 +3,9 @@ import me.fixeddev.commandflow.Authorizer; import me.fixeddev.commandflow.Namespace; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.GuildChannel; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; public class DiscordAuthorizer implements Authorizer { @@ -22,7 +22,7 @@ public boolean isAuthorized(Namespace namespace, String permission) { return true; } - GuildChannel channel = message.getTextChannel(); + GuildChannel channel = message.getGuildChannel(); Permission permissionValue; try { diff --git a/Discord/src/main/java/me/fixeddev/commandflow/discord/MessageListener.java b/Discord/src/main/java/me/fixeddev/commandflow/discord/MessageListener.java index 3c67bec0..d5e9c646 100644 --- a/Discord/src/main/java/me/fixeddev/commandflow/discord/MessageListener.java +++ b/Discord/src/main/java/me/fixeddev/commandflow/discord/MessageListener.java @@ -11,9 +11,9 @@ import me.fixeddev.commandflow.exception.NoPermissionsException; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.User; -import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.kyori.adventure.text.Component; @@ -28,11 +28,11 @@ public MessageListener(CommandManager commandManager, String commandPrefix) { } @Override - public void onGuildMessageReceived(GuildMessageReceivedEvent event) { + public void onMessageReceived(MessageReceivedEvent event) { Member member = event.getMember(); User user = event.getAuthor(); Message message = event.getMessage(); - TextChannel channel = event.getChannel(); + TextChannel channel = event.getChannel().asTextChannel(); String rawMessage = event.getMessage().getContentRaw(); diff --git a/Discord/src/main/java/me/fixeddev/commandflow/discord/factory/DiscordModule.java b/Discord/src/main/java/me/fixeddev/commandflow/discord/factory/DiscordModule.java index 32a7012c..531564cd 100644 --- a/Discord/src/main/java/me/fixeddev/commandflow/discord/factory/DiscordModule.java +++ b/Discord/src/main/java/me/fixeddev/commandflow/discord/factory/DiscordModule.java @@ -5,8 +5,8 @@ import me.fixeddev.commandflow.discord.annotation.Sender; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; public class DiscordModule extends AbstractModule { diff --git a/Discord/src/main/java/me/fixeddev/commandflow/discord/part/MemberPart.java b/Discord/src/main/java/me/fixeddev/commandflow/discord/part/MemberPart.java index e15a104b..27360bf3 100644 --- a/Discord/src/main/java/me/fixeddev/commandflow/discord/part/MemberPart.java +++ b/Discord/src/main/java/me/fixeddev/commandflow/discord/part/MemberPart.java @@ -32,7 +32,7 @@ public String getName() { @Override public List parseValue(CommandContext context, ArgumentStack stack, CommandPart parent) throws ArgumentParseException { Message message = context.getObject(Message.class, DiscordCommandManager.MESSAGE_NAMESPACE); - Guild guild = message.getTextChannel().getGuild(); + Guild guild = message.getGuild(); String target = stack.next(); diff --git a/Discord/src/main/java/me/fixeddev/commandflow/discord/part/TextChannelPart.java b/Discord/src/main/java/me/fixeddev/commandflow/discord/part/TextChannelPart.java index bdb096d5..d0448d95 100644 --- a/Discord/src/main/java/me/fixeddev/commandflow/discord/part/TextChannelPart.java +++ b/Discord/src/main/java/me/fixeddev/commandflow/discord/part/TextChannelPart.java @@ -8,7 +8,7 @@ import me.fixeddev.commandflow.part.CommandPart; import me.fixeddev.commandflow.stack.ArgumentStack; import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.kyori.adventure.text.Component; import java.util.Collections; diff --git a/Discord/src/main/java/me/fixeddev/commandflow/discord/part/UserPart.java b/Discord/src/main/java/me/fixeddev/commandflow/discord/part/UserPart.java index 0b7f84cb..c7f65eec 100644 --- a/Discord/src/main/java/me/fixeddev/commandflow/discord/part/UserPart.java +++ b/Discord/src/main/java/me/fixeddev/commandflow/discord/part/UserPart.java @@ -26,7 +26,7 @@ public UserPart(String name) { @Override public List parseValue(CommandContext context, ArgumentStack stack, CommandPart parent) throws ArgumentParseException { Message message = context.getObject(Message.class, DiscordCommandManager.MESSAGE_NAMESPACE); - Guild guild = message.getTextChannel().getGuild(); + Guild guild = message.getGuild(); String target = stack.next(); From c3cf84e50a57b5fdf9be1475be0d8af2b42afafa Mon Sep 17 00:00:00 2001 From: MattyHD0 Date: Wed, 15 Nov 2023 17:05:56 -0300 Subject: [PATCH 2/4] fixed StringIndexOutOfBoundsException --- .../me/fixeddev/commandflow/discord/MessageListener.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Discord/src/main/java/me/fixeddev/commandflow/discord/MessageListener.java b/Discord/src/main/java/me/fixeddev/commandflow/discord/MessageListener.java index d5e9c646..8c14541c 100644 --- a/Discord/src/main/java/me/fixeddev/commandflow/discord/MessageListener.java +++ b/Discord/src/main/java/me/fixeddev/commandflow/discord/MessageListener.java @@ -42,7 +42,11 @@ public void onMessageReceived(MessageReceivedEvent event) { rawMessage = rawMessage.substring(commandPrefix.length()); - String label = rawMessage.substring(0, rawMessage.indexOf(" ")); + String label = rawMessage; + + if(label.indexOf(" ") > 0){ + label = rawMessage.substring(0, rawMessage.indexOf(" ")); + } Namespace namespace = Namespace.create(); From 7b782333dd4d92a13fdba2ceb305055ced190ef5 Mon Sep 17 00:00:00 2001 From: MattyHD0 Date: Wed, 15 Nov 2023 17:21:04 -0300 Subject: [PATCH 3/4] fixed channel can be any channel type --- .../me/fixeddev/commandflow/discord/MessageListener.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Discord/src/main/java/me/fixeddev/commandflow/discord/MessageListener.java b/Discord/src/main/java/me/fixeddev/commandflow/discord/MessageListener.java index 8c14541c..96f44d2d 100644 --- a/Discord/src/main/java/me/fixeddev/commandflow/discord/MessageListener.java +++ b/Discord/src/main/java/me/fixeddev/commandflow/discord/MessageListener.java @@ -12,6 +12,7 @@ import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.channel.concrete.PrivateChannel; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; @@ -29,6 +30,11 @@ public MessageListener(CommandManager commandManager, String commandPrefix) { @Override public void onMessageReceived(MessageReceivedEvent event) { + + if(!(event.getChannel() instanceof TextChannel)){ + return; + } + Member member = event.getMember(); User user = event.getAuthor(); Message message = event.getMessage(); @@ -57,7 +63,7 @@ public void onMessageReceived(MessageReceivedEvent event) { namespace.setObject(String.class, "label", label); try { - commandManager.execute(namespace, rawMessage.substring(commandPrefix.length())); + commandManager.execute(namespace, rawMessage); } catch (CommandException e) { CommandException exceptionToSend = e; From b1e1fa0228c986392eb9f62ca34335db4679c95e Mon Sep 17 00:00:00 2001 From: MattyHD0 Date: Wed, 15 Nov 2023 17:41:50 -0300 Subject: [PATCH 4/4] fixed false unknown-channel exception caused by some snowflakes having a length greater than 20 --- .../me/fixeddev/commandflow/discord/utils/ArgumentsUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Discord/src/main/java/me/fixeddev/commandflow/discord/utils/ArgumentsUtils.java b/Discord/src/main/java/me/fixeddev/commandflow/discord/utils/ArgumentsUtils.java index 47a0f0d5..160d6e4e 100644 --- a/Discord/src/main/java/me/fixeddev/commandflow/discord/utils/ArgumentsUtils.java +++ b/Discord/src/main/java/me/fixeddev/commandflow/discord/utils/ArgumentsUtils.java @@ -36,7 +36,7 @@ public static boolean isRoleMention(String argument) { private static boolean isMention(String argument, String mentionTypeIdentifier) { return argument.startsWith("<" + mentionTypeIdentifier) && argument.endsWith(">") - && argument.length() == (20 + mentionTypeIdentifier.length()); + && argument.length() >= (20 + mentionTypeIdentifier.length()); } }