Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the arguments list of the execute function #154

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions lib/nyxx_commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -83,6 +79,7 @@ export 'src/util/util.dart'
show
Autocomplete,
Choices,
CommandArgument,
ComponentId,
ComponentIdStatus,
Description,
Expand Down
15 changes: 15 additions & 0 deletions lib/src/commands/chat_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,12 @@ class ChatCommand
final List<AbstractCheck> singleChecks = [];

/// The types of the required and positional arguments of [execute], in the order they appear.
@Deprecated('Use arguments[].type instead')
final List<RuntimeType<dynamic>> argumentTypes = [];

/// The arguments of [execute], in the order they appear.
final List<CommandArgument> arguments = [];

@override
final CommandOptions options;

Expand Down Expand Up @@ -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,
),
);
}
}

Expand Down
30 changes: 30 additions & 0 deletions lib/src/util/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -649,3 +649,33 @@ Future<Permissions> computePermissions(

return computeOverwrites(await computeBasePermissions());
}

/// Represents a command argument.
class CommandArgument {
Rapougnac marked this conversation as resolved.
Show resolved Hide resolved
/// The name of this argument.
final String name;

/// The localized names of this argument.
final Map<Locale, String>? localizedNames;

/// The description of this argument.
final String? description;

/// The localized descriptions of this argument.
final Map<Locale, String>? localizedDescriptions;

/// The argument type.
final RuntimeType<dynamic>? 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,
});
}
Loading