From dd07603fe3cd22905cfcdb0a88cdc5ba6db492bc Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 6 Jul 2024 15:13:08 +0200 Subject: [PATCH] Fix /bug, Discord Commands Signed-off-by: Lixfel --- CommonCore | 2 +- .../discord/listeners/ChannelListener.java | 12 ++++++------ .../discord/listeners/DiscordTicketHandler.java | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CommonCore b/CommonCore index 1237a69..d000b86 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 1237a699ba244ecfac65478df34e714afbe2366e +Subproject commit d000b8687d93eb43520bbf6685281099055eab9f diff --git a/src/de/steamwar/velocitycore/discord/listeners/ChannelListener.java b/src/de/steamwar/velocitycore/discord/listeners/ChannelListener.java index 2fffa1a..7665c40 100644 --- a/src/de/steamwar/velocitycore/discord/listeners/ChannelListener.java +++ b/src/de/steamwar/velocitycore/discord/listeners/ChannelListener.java @@ -74,17 +74,17 @@ public class ChannelListener extends ListenerAdapter { if(sender.user().getDiscordId() == null) return; - VelocityCore.getLogger().log(Level.INFO, "%s -> executed Discord command /%s %s".formatted(sender.user().getUserName(), event.getName(), event.getOption(DiscordBot.ARGUMENT_NAME).getAsString())); - SWCommand command = DiscordBot.getCommands().get(event.getName()); - UserPerm permission = command.getPermission(); - if(permission != null && !sender.user().perms().contains(permission)) - return; - OptionMapping option = event.getOption(DiscordBot.ARGUMENT_NAME); String args = ""; if(option != null) args = option.getAsString(); + VelocityCore.getLogger().log(Level.INFO, "%s -> executed Discord command /%s %s".formatted(sender.user().getUserName(), event.getName(), args)); + SWCommand command = DiscordBot.getCommands().get(event.getName()); + UserPerm permission = command.getPermission(); + if(permission != null && !sender.user().perms().contains(permission)) + return; + command.execute(sender, args.split(" ")); }); } diff --git a/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java b/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java index 914355d..692d475 100644 --- a/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java +++ b/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java @@ -32,6 +32,7 @@ import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Emoji; +import net.dv8tion.jda.api.entities.MessageChannel; import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent; @@ -83,8 +84,8 @@ public class DiscordTicketHandler extends ListenerAdapter { @Override public void onGenericComponentInteractionCreate(@NotNull GenericComponentInteractionCreateEvent event) { - TextChannel channel = event.getTextChannel(); - if(channel.getParent() != null && channel.getParent().getId().equals(TICKET_CATEGORY) && event.getComponentId().startsWith("close-")) { + MessageChannel messageChannel = event.getChannel(); + if(messageChannel instanceof TextChannel channel && channel.getParent() != null && channel.getParent().getId().equals(TICKET_CATEGORY) && event.getComponentId().startsWith("close-")) { LinkedList messages = channel.getIterableHistory().complete().stream() .filter(message -> !message.getAuthor().isSystem() && !message.getAuthor().isBot()) .map(message -> {