From 3b4a2f2610189c8def0f70db94234b8b8879b521 Mon Sep 17 00:00:00 2001 From: Rapougnac Date: Mon, 26 Feb 2024 12:10:56 +0100 Subject: [PATCH 1/3] Expose the arguments list of the `execute` function --- lib/nyxx_commands.dart | 15 ++++++--------- lib/src/commands/chat_command.dart | 15 +++++++++++++++ lib/src/util/util.dart | 30 ++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/lib/nyxx_commands.dart b/lib/nyxx_commands.dart index 66f4ac8..c05be13 100644 --- a/lib/nyxx_commands.dart +++ b/lib/nyxx_commands.dart @@ -29,15 +29,6 @@ export 'src/commands/message_command.dart' show MessageCommand; export 'src/commands/options.dart' show CommandOptions; export 'src/commands/user_command.dart' show UserCommand; export 'src/context/autocomplete_context.dart' show AutocompleteContext; -export 'src/context/chat_context.dart' - show ChatContext, ChatContextData, InteractionChatContext, MessageChatContext; -export 'src/context/component_context.dart' - show - ComponentContextData, - ComponentContext, - ButtonComponentContext, - SelectMenuContext; -export 'src/context/context_manager.dart' show ContextManager; export 'src/context/base.dart' show CommandContext, @@ -49,6 +40,11 @@ export 'src/context/base.dart' InteractionInteractiveContext, InteractiveContext, ResponseLevel; +export 'src/context/chat_context.dart' + show ChatContext, ChatContextData, InteractionChatContext, MessageChatContext; +export 'src/context/component_context.dart' + show ComponentContextData, ComponentContext, ButtonComponentContext, SelectMenuContext; +export 'src/context/context_manager.dart' show ContextManager; export 'src/context/message_context.dart' show MessageContext; export 'src/context/modal_context.dart' show ModalContext; export 'src/context/user_context.dart' show UserContext; @@ -83,6 +79,7 @@ export 'src/util/util.dart' show Autocomplete, Choices, + CommandArgument, ComponentId, ComponentIdStatus, Description, diff --git a/lib/src/commands/chat_command.dart b/lib/src/commands/chat_command.dart index 25f60e8..7a1b545 100644 --- a/lib/src/commands/chat_command.dart +++ b/lib/src/commands/chat_command.dart @@ -279,8 +279,12 @@ class ChatCommand final List singleChecks = []; /// The types of the required and positional arguments of [execute], in the order they appear. + @Deprecated('Use arguments[].type instead') final List> argumentTypes = []; + /// The arguments of [execute], in the order they appear. + final List arguments = []; + @override final CommandOptions options; @@ -368,7 +372,18 @@ class ChatCommand } } + // ignore: deprecated_member_use_from_same_package argumentTypes.add(parameter.type); + arguments.add( + CommandArgument( + name: parameter.name, + isOptional: parameter.isOptional, + type: parameter.type, + description: parameter.description, + localizedDescriptions: parameter.localizedDescriptions, + localizedNames: parameter.localizedNames, + ), + ); } } diff --git a/lib/src/util/util.dart b/lib/src/util/util.dart index 228b76d..a018a52 100644 --- a/lib/src/util/util.dart +++ b/lib/src/util/util.dart @@ -649,3 +649,33 @@ Future computePermissions( return computeOverwrites(await computeBasePermissions()); } + +/// Represents a command argument. +class CommandArgument { + /// The name of this argument. + final String name; + + /// The localized names of this argument. + final Map? localizedNames; + + /// The description of this argument. + final String? description; + + /// The localized descriptions of this argument. + final Map? localizedDescriptions; + + /// The argument type. + final RuntimeType? type; + + /// Whether this argument is optional. + final bool isOptional; + + const CommandArgument({ + required this.name, + required this.isOptional, + this.localizedNames, + this.description, + this.localizedDescriptions, + this.type, + }); +} From ce954675a7e1dc6f7a0098c264928f544e98409a Mon Sep 17 00:00:00 2001 From: Rapougnac Date: Mon, 11 Mar 2024 15:33:52 +0100 Subject: [PATCH 2/3] Remove `CommandArgument` helper class --- lib/src/commands/chat_command.dart | 13 ++----------- lib/src/util/util.dart | 30 ------------------------------ 2 files changed, 2 insertions(+), 41 deletions(-) diff --git a/lib/src/commands/chat_command.dart b/lib/src/commands/chat_command.dart index 7a1b545..e732a40 100644 --- a/lib/src/commands/chat_command.dart +++ b/lib/src/commands/chat_command.dart @@ -283,7 +283,7 @@ class ChatCommand final List> argumentTypes = []; /// The arguments of [execute], in the order they appear. - final List arguments = []; + final List> arguments = []; @override final CommandOptions options; @@ -374,16 +374,7 @@ class ChatCommand // ignore: deprecated_member_use_from_same_package argumentTypes.add(parameter.type); - arguments.add( - CommandArgument( - name: parameter.name, - isOptional: parameter.isOptional, - type: parameter.type, - description: parameter.description, - localizedDescriptions: parameter.localizedDescriptions, - localizedNames: parameter.localizedNames, - ), - ); + arguments.add(parameter); } } diff --git a/lib/src/util/util.dart b/lib/src/util/util.dart index a018a52..228b76d 100644 --- a/lib/src/util/util.dart +++ b/lib/src/util/util.dart @@ -649,33 +649,3 @@ Future computePermissions( return computeOverwrites(await computeBasePermissions()); } - -/// Represents a command argument. -class CommandArgument { - /// The name of this argument. - final String name; - - /// The localized names of this argument. - final Map? localizedNames; - - /// The description of this argument. - final String? description; - - /// The localized descriptions of this argument. - final Map? localizedDescriptions; - - /// The argument type. - final RuntimeType? type; - - /// Whether this argument is optional. - final bool isOptional; - - const CommandArgument({ - required this.name, - required this.isOptional, - this.localizedNames, - this.description, - this.localizedDescriptions, - this.type, - }); -} From bb13af8f46b0da8dfd1749adeef5d5fccbe26f26 Mon Sep 17 00:00:00 2001 From: Rapougnac Date: Mon, 11 Mar 2024 15:37:30 +0100 Subject: [PATCH 3/3] Remove unknow export of `CommandArgument` --- lib/nyxx_commands.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/nyxx_commands.dart b/lib/nyxx_commands.dart index c05be13..5cf6b60 100644 --- a/lib/nyxx_commands.dart +++ b/lib/nyxx_commands.dart @@ -79,7 +79,6 @@ export 'src/util/util.dart' show Autocomplete, Choices, - CommandArgument, ComponentId, ComponentIdStatus, Description,