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

Refactor/definition #149

Merged
merged 31 commits into from
Jan 5, 2025
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5ebb91d
first pass on new definition api
Kaktushose Dec 23, 2024
c48777a
make interaction interfaces records and first pass on new registry
Kaktushose Dec 25, 2024
54c75e8
update records
Kaktushose Dec 25, 2024
776ca02
fix invocation context
Kaktushose Dec 25, 2024
d87dc61
add missing parameter methods
Kaktushose Dec 25, 2024
fe4b191
rename
Kaktushose Dec 25, 2024
477597c
add reflection wrapper
Goldmensch Dec 25, 2024
e7f756e
add reflective descriptor
Goldmensch Dec 25, 2024
7953107
update definitions
Kaktushose Dec 25, 2024
ea5f6e8
update definitions
Kaktushose Dec 25, 2024
41cda31
fix shit ton of compile errors
Kaktushose Dec 26, 2024
821a477
cleanup
Kaktushose Dec 26, 2024
8e0ec84
formatting
Kaktushose Dec 26, 2024
28fa758
remove since tag
Kaktushose Dec 26, 2024
9534df8
update documentation
Kaktushose Dec 26, 2024
4524f9b
fix unit tests
Kaktushose Dec 26, 2024
5f81825
extract reflections out of InteractionRegistry
Kaktushose Dec 26, 2024
9b384b1
Use Iterable instead of List and introduce CustomId#independent
Goldmensch Dec 28, 2024
c2e5d4b
Restructure Definitions package and separate Context and SlashCommand
Goldmensch Dec 31, 2024
7d2438d
remove Permissions feature interface
Kaktushose Dec 31, 2024
05f588d
Forbid Definition#invoke by user and fix bug in CustomID
Goldmensch Dec 31, 2024
571aa8c
javadocs
Kaktushose Jan 3, 2025
f8822c3
Yeah..
Goldmensch Jan 3, 2025
d53982d
docs
Kaktushose Jan 4, 2025
e15f6d5
more javadoc
Kaktushose Jan 4, 2025
8c3f556
formatting
Kaktushose Jan 4, 2025
5397e8a
fix java tests
Kaktushose Jan 4, 2025
83c99f8
fix java tests
Kaktushose Jan 4, 2025
2b67173
fix wrong annotation
Kaktushose Jan 4, 2025
7b28c6f
fix codacy
Kaktushose Jan 5, 2025
d138ab4
small changes
Kaktushose Jan 5, 2025
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
Prev Previous commit
Next Next commit
docs
Kaktushose committed Jan 4, 2025
commit d53982d11248a126de088444f1f12562f76215ec
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@

import static com.github.kaktushose.jda.commands.definitions.interactions.command.SlashCommandDefinition.CooldownDefinition;

/// Central registry for all [InteractionDefinition]s.
public record InteractionRegistry(DependencyInjector dependencyInjector,
ValidatorRegistry validatorRegistry,
LocalizationFunction localizationFunction,
@@ -32,10 +33,18 @@ public record InteractionRegistry(DependencyInjector dependencyInjector,

private static final Logger log = LoggerFactory.getLogger(InteractionRegistry.class);

/// Constructs a new [InteractionRegistry]
/// @param injector the [DependencyInjector] to use
/// @param registry the corresponding [ValidatorRegistry]
/// @param function the [LocalizationFunction] to use
/// @param descriptor the [Descriptor] to use
public InteractionRegistry(DependencyInjector injector, ValidatorRegistry registry, LocalizationFunction function, Descriptor descriptor) {
this(injector, registry, function, descriptor, new HashSet<>());
}

/// Scans all given classes and registers the interactions defined in them.
///
/// @param classes the [Class]es to build the interactions from
public void index(Iterable<Class<?>> classes) {
int oldSize = definitions.size();

Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import com.github.kaktushose.jda.commands.definitions.description.ParameterDescription;
import com.github.kaktushose.jda.commands.definitions.features.CustomIdJDAEntity;
import com.github.kaktushose.jda.commands.definitions.features.JDAEntity;
import com.github.kaktushose.jda.commands.definitions.interactions.command.ParameterDefinition;
import com.github.kaktushose.jda.commands.dispatching.events.interactions.ModalEvent;
import com.github.kaktushose.jda.commands.internal.Helpers;
import net.dv8tion.jda.api.interactions.components.text.TextInput;
@@ -95,7 +96,8 @@ public String displayName() {
return title;
}


/// Representation of a modal text input defined by
/// [`TextInput`][com.github.kaktushose.jda.commands.annotations.interactions.TextInput]
public record TextInputDefinition(
@NotNull String label,
@NotNull String placeholder,
@@ -106,6 +108,10 @@ public record TextInputDefinition(
boolean required
) implements JDAEntity<TextInput>, Definition {

/// Builds a new [TextInputDefinition] from the given [ParameterDefinition]
///
/// @param parameter the [ParameterDefinition] to build the [TextInputDefinition] from
/// @return the new [TextInputDefinition]
public static Optional<TextInputDefinition> build(ParameterDescription parameter) {
var optional = parameter.annotation(com.github.kaktushose.jda.commands.annotations.interactions.TextInput.class);

@@ -135,8 +141,10 @@ public static Optional<TextInputDefinition> build(ParameterDescription parameter
return label;
}

/// Transforms this definition into a [TextInput]
@NotNull
@Override
public @NotNull TextInput toJDAEntity() {
public TextInput toJDAEntity() {
var textInput = TextInput.create(label, label, style).setRequired(required);

if (minValue != -1) {