Skip to content

Commit e716733

Browse files
committed
Merge branch 'main' into other/formatter
# Conflicts: # gradle/libs.versions.toml
2 parents 33c05cc + 22c363f commit e716733

File tree

20 files changed

+225
-43
lines changed

20 files changed

+225
-43
lines changed

core/src/main/java/io/github/kaktushose/jdac/JDACBuilder.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.github.kaktushose.jdac;
22

3-
import dev.goldmensch.fluava.Fluava;
43
import io.github.kaktushose.jdac.configuration.Extension;
54
import io.github.kaktushose.jdac.configuration.ExtensionFilter;
65
import io.github.kaktushose.jdac.configuration.Property;
@@ -127,7 +126,7 @@ public class JDACBuilder {
127126
addFallback(GLOBAL_REPLY_CONFIG, _ -> new ReplyConfig());
128127
addFallback(SHUTDOWN_JDA, _ -> true);
129128
addFallback(LOCALIZE_COMMANDS, _ -> true);
130-
addFallback(LOCALIZER, _ -> new FluavaLocalizer(Fluava.create(Locale.ENGLISH)));
129+
addFallback(LOCALIZER, _ -> FluavaLocalizer.create(Locale.ENGLISH));
131130
addFallback(PERMISSION_PROVIDER, _ -> new DefaultPermissionsProvider());
132131
addFallback(ERROR_MESSAGE_FACTORY, ctx -> new DefaultErrorMessageFactory(ctx.get(MESSAGE_RESOLVER)));
133132
addFallback(GUILD_SCOPE_PROVIDER, _ -> new DefaultGuildScopeProvider());
@@ -155,7 +154,7 @@ public class JDACBuilder {
155154
});
156155
addFallback(EMBEDS, ctx -> ctx.get(EMBED_CONFIG_INTERNAL).build());
157156

158-
addFallback(LOCALIZATION_FUNCTION, ctx -> new JDACLocalizationFunction(ctx.get(BUNDLE_FINDER), ctx.get(DEFINITIONS), ctx.get(MESSAGE_RESOLVER)));
157+
addFallback(LOCALIZATION_FUNCTION, JDACLocalizationFunction.PROVIDER_FUNC);
159158
addFallback(BUNDLE_FINDER, ctx -> new BundleFinder(ctx.get(DESCRIPTOR)));
160159
addFallback(I18N, ctx -> new I18n(ctx.get(BUNDLE_FINDER), ctx.get(LOCALIZER)));
161160

@@ -360,14 +359,14 @@ public <T> JDACBuilder setProperty(Property<T> property, Function<PropertyProvid
360359
/// This method applies all found implementations of [Extension],
361360
/// instantiates an instance of [JDACommands] and starts the framework.
362361
public JDACommands start() {
362+
log.info("Starting JDA-Commands...");
363+
363364
Extensions extensions = loadExtensions();
364365

365366
IntrospectionImpl introspection = new IntrospectionImpl(new Lifecycle(), properties.createResolver(), Stage.CONFIGURATION);
366367

367368
return ScopedValue.where(IntrospectionImpl.INTROSPECTION, introspection).call(() -> {
368369
try {
369-
log.info("Starting JDA-Commands...");
370-
371370
Middlewares middlewares = new Middlewares(introspection.get(MIDDLEWARE), introspection.get(ERROR_MESSAGE_FACTORY), introspection.get(PERMISSION_PROVIDER));
372371
TypeAdapters typeAdapters = new TypeAdapters(introspection.get(TYPE_ADAPTER), introspection.get(MESSAGE_RESOLVER));
373372

core/src/main/java/io/github/kaktushose/jdac/JDACommands.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import io.github.kaktushose.jdac.embeds.EmbedConfig;
1818
import io.github.kaktushose.jdac.embeds.EmbedDataSource;
1919
import io.github.kaktushose.jdac.embeds.internal.Embeds;
20+
import io.github.kaktushose.jdac.exceptions.internal.JDACException;
2021
import io.github.kaktushose.jdac.internal.JDAContext;
2122
import io.github.kaktushose.jdac.internal.logging.JDACLogger;
2223
import io.github.kaktushose.jdac.internal.register.CommandUpdater;
@@ -115,7 +116,7 @@ void start(Extensions extensions) {
115116
log.debug("Run Extension#onStart()");
116117
extensions.callOnStart(this);
117118

118-
log.info("Finished loading!");
119+
System.out.printf("\n%s\n\n", JDACException.errorMessage("starting-message"));
119120

120121
introspection.publish(new FrameworkStartEvent());
121122
});

core/src/main/java/io/github/kaktushose/jdac/definitions/interactions/command/OptionDataDefinition.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io.github.kaktushose.jdac.dispatching.events.Event;
1414
import io.github.kaktushose.jdac.dispatching.events.interactions.CommandEvent;
1515
import io.github.kaktushose.jdac.dispatching.events.interactions.ComponentEvent;
16+
import io.github.kaktushose.jdac.dispatching.events.interactions.ModalEvent;
1617
import io.github.kaktushose.jdac.dispatching.validation.Validator;
1718
import io.github.kaktushose.jdac.dispatching.validation.internal.Validators;
1819
import io.github.kaktushose.jdac.exceptions.ConfigurationException;
@@ -128,10 +129,13 @@ public static OptionDataDefinition build(ParameterDescription parameter,
128129
if (Event.class.isAssignableFrom(resolvedType)) {
129130
String guessedType = "";
130131
if (resolvedType.equals(ComponentEvent.class)) {
131-
guessedType = "CommandEvent";
132+
guessedType = "Perhaps you wanted to write CommandEvent?";
132133
}
133134
if (resolvedType.equals(CommandEvent.class)) {
134-
guessedType = "ComponentEvent";
135+
guessedType = "Perhaps you wanted to write ComponentEvent?";
136+
}
137+
if (resolvedType.equals(ModalEvent.class)) {
138+
guessedType = "Perhaps you wanted to write CommandEvent or ComponentEvent?";
135139
}
136140
throw new InvalidDeclarationException(
137141
"invalid-option-data",

core/src/main/java/io/github/kaktushose/jdac/dispatching/events/Event.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.List;
2828
import java.util.Locale;
2929
import java.util.Map;
30+
import java.util.Objects;
3031

3132
import static io.github.kaktushose.jdac.introspection.internal.IntrospectionAccess.*;
3233

@@ -114,6 +115,16 @@ public String resolve(String message, Entry... placeholders) {
114115
return messageResolver().resolve(message, jdaEvent().getUserLocale(), placeholders);
115116
}
116117

118+
/// Resolved the given message with help of the underlying [MessageResolver] instance,
119+
/// thus performing localization and emoji resolution.
120+
///
121+
/// Automatically resolves the [Locale] using [GenericInteractionCreateEvent#getUserLocale()].
122+
/// Use [MessageResolver#resolve(String, Locale, Map)] (obtained via [#messageResolver()]) if you want to use a different locale.
123+
///
124+
/// @return the resolved message
125+
public String resolve(String message, Map<String, @Nullable Object> placeholders) {
126+
return messageResolver().resolve(message, jdaEvent().getUserLocale(), placeholders);
127+
}
117128

118129
@Override
119130
public int getTypeRaw() {

core/src/main/java/io/github/kaktushose/jdac/dispatching/events/ModalReplyableEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,6 @@ private void reply(@Nullable Class<?> origin, String modal, Collection<ModalTopL
101101
);
102102

103103
log.debug("Replying to interaction \"{}\" with Modal: \"{}\". [Runtime={}]", definition.displayName(), modalDefinition.displayName(), runtimeId());
104-
callback.replyModal(modalDefinition.toJDAEntity(new CustomId(runtimeId(), definitionId))).queue();
104+
callback.replyModal(modalDefinition.toJDAEntity(new CustomId(runtimeId(), definitionId))).complete();
105105
}
106106
}

core/src/main/java/io/github/kaktushose/jdac/dispatching/events/interactions/AutoCompleteEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public final class AutoCompleteEvent extends Event<CommandAutoCompleteInteractio
3333
* </ul>
3434
*/
3535
public void replyChoices(Collection<Command.Choice> choices) {
36-
jdaEvent().replyChoices(choices).queue();
36+
jdaEvent().replyChoices(choices).complete();
3737
}
3838

3939
/**

core/src/main/java/io/github/kaktushose/jdac/dispatching/handling/EventHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private void invoke(InvocationContext<T> invocation, Runtime runtime, Introspect
148148
if (invocation.event() instanceof GenericComponentInteractionCreateEvent componentEvent && !edit) {
149149
Message message = componentEvent.getMessage();
150150
if (Helpers.isValidWithoutComponents(message)) {
151-
message.editMessageComponents().queue();
151+
message.editMessageComponents().complete();
152152
} else {
153153
edit = true;
154154
}

core/src/main/java/io/github/kaktushose/jdac/dispatching/handling/command/SlashCommandHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ protected PreparationResult prepare(SlashCommandInteractionEvent event, Runtime
105105
.setEphemeral(replyConfig.ephemeral())
106106
.setSuppressedNotifications(replyConfig.silent())
107107
.setAllowedMentions(replyConfig.allowedMentions())
108-
.queue();
108+
.complete();
109109
return Optional.empty();
110110
}
111111
case NO_PATH_FOUND, NO_LOSSLESS_CONVERSION -> throw new InternalException(

core/src/main/java/io/github/kaktushose/jdac/dispatching/middleware/Priority.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// !! order matters, because enums are compared by ordinal number (java.lang.Comparable)
77
public enum Priority {
88
/// Middlewares with priority PERMISSIONS will always be executed first
9-
PERMISSIONS,
9+
HIGHEST,
1010
/// Highest priority for custom implementation, will be executed right after internal middlewares.
1111
HIGH,
1212
/// Default priority.

core/src/main/java/io/github/kaktushose/jdac/dispatching/middleware/internal/Middlewares.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ public class Middlewares {
1717

1818
public Middlewares(Collection<Map.Entry<Priority, Middleware>> userDefined, ErrorMessageFactory errorMessageFactory, PermissionsProvider permissionsProvider) {
1919
SortedMap<Priority, Set<Middleware>> middlewareMap = new TreeMap<>(Map.of(
20-
Priority.PERMISSIONS, new HashSet<>(List.of(new PermissionsMiddleware(permissionsProvider, errorMessageFactory))),
20+
Priority.HIGHEST, new HashSet<>(List.of(new PermissionsMiddleware(permissionsProvider, errorMessageFactory))),
2121
Priority.NORMAL, new HashSet<>(List.of(new ConstraintMiddleware(errorMessageFactory))),
2222
Priority.HIGH, new HashSet<>(),
2323
Priority.LOW, new HashSet<>()
2424
));
2525

2626
userDefined.forEach(entry -> middlewareMap.get(entry.getKey()).add(entry.getValue()));
2727

28-
middlewareMap.computeIfPresent(Priority.PERMISSIONS, (_, set) -> Collections.unmodifiableSet(set));
28+
middlewareMap.computeIfPresent(Priority.HIGHEST, (_, set) -> Collections.unmodifiableSet(set));
2929
middlewareMap.computeIfPresent(Priority.HIGH, (_, set) -> Collections.unmodifiableSet(set));
3030
middlewareMap.computeIfPresent(Priority.NORMAL, (_, set) -> Collections.unmodifiableSet(set));
3131
middlewareMap.computeIfPresent(Priority.LOW, (_, set) -> Collections.unmodifiableSet(set));

0 commit comments

Comments
 (0)