|
28 | 28 | import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; |
29 | 29 | import net.dv8tion.jda.api.events.session.ShutdownEvent; |
30 | 30 | import net.dv8tion.jda.api.hooks.ListenerAdapter; |
| 31 | +import net.dv8tion.jda.api.interactions.commands.Command; |
31 | 32 | import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions; |
32 | 33 | import net.dv8tion.jda.api.interactions.commands.ICommandReference; |
33 | 34 | import net.dv8tion.jda.api.interactions.commands.OptionMapping; |
|
70 | 71 | import java.util.Arrays; |
71 | 72 | import java.util.Comparator; |
72 | 73 | import java.util.List; |
| 74 | +import java.util.Map; |
73 | 75 | import java.util.NoSuchElementException; |
74 | 76 | import java.util.Optional; |
75 | 77 | import java.util.Set; |
76 | 78 | import java.util.concurrent.CompletableFuture; |
| 79 | +import java.util.concurrent.ConcurrentHashMap; |
77 | 80 | import java.util.function.BiFunction; |
78 | 81 | import java.util.function.Consumer; |
79 | 82 | import java.util.function.Function; |
|
89 | 92 | @Value |
90 | 93 | @RequiredArgsConstructor |
91 | 94 | public class JdaCommandAdapter extends AbstractCommandAdapter implements PermissionChecker { |
92 | | - private final CommandManager manager; |
93 | | - Set<CommandCapability> capabilities = Set.of(CommandCapability.NAMED_ARGS); |
94 | | - JDA jda; |
95 | | - Event.Bus<GenericEvent> bus = new Event.Bus<>(); |
| 95 | + CommandManager manager; |
| 96 | + Map<String, Command> namedCommands = new ConcurrentHashMap<>(); |
| 97 | + Set<CommandCapability> capabilities = Set.of(CommandCapability.NAMED_ARGS); |
| 98 | + JDA jda; |
| 99 | + Event.Bus<GenericEvent> bus = new Event.Bus<>(); |
96 | 100 | @Nullable @NonFinal @Setter BiFunction<EmbedBuilder, User, EmbedBuilder> embedFinalizer = null; |
97 | 101 | @Setter @NonFinal boolean initialized = false; |
98 | 102 | @Setter @NonFinal boolean purgeCommands = false;//Debug.isDebug(); |
@@ -205,7 +209,12 @@ private void registerCommands() { |
205 | 209 | default -> {} |
206 | 210 | } |
207 | 211 |
|
208 | | - chain = chain == null ? jda.upsertCommand(cmd) : chain.flatMap($ -> jda.upsertCommand(cmd)); |
| 212 | + chain = (chain == null |
| 213 | + ? jda.upsertCommand(cmd) |
| 214 | + : chain.flatMap($ -> jda.upsertCommand(cmd))).map(it -> { |
| 215 | + namedCommands.put(it.getFullCommandName(), it); |
| 216 | + return it; |
| 217 | + }); |
209 | 218 | } |
210 | 219 |
|
211 | 220 | if (chain == null) chain = jda.retrieveApplicationInfo(); |
|
0 commit comments