Skip to content

Commit cce19d5

Browse files
committed
fix breaking Discord API change
1 parent b5c9859 commit cce19d5

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/main/java/net/javadiscord/javabot/data/config/ReflectionUtils.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static Optional<Pair<Field, Object>> resolveField(@NotNull String propert
5454
public static @Nullable Pair<Field, Object> resolveField(@NotNull String[] fieldNames, @NotNull Object parent) throws UnknownPropertyException {
5555
if (fieldNames.length == 0) return null;
5656
try {
57-
Field field = parent.getClass().getDeclaredField(fieldNames[0]);
57+
Field field = findDeclaredField(parent.getClass(), fieldNames[0]);
5858
// Transient fields should not exist in the context of property resolution, treat them as unknown.
5959
if (Modifier.isTransient(field.getModifiers())) {
6060
throw new UnknownPropertyException(fieldNames[0], parent.getClass());
@@ -77,6 +77,19 @@ public static Optional<Pair<Field, Object>> resolveField(@NotNull String propert
7777
}
7878
}
7979

80+
private static Field findDeclaredField(Class<?> cl, String name) throws NoSuchFieldException {
81+
try {
82+
return cl.getDeclaredField(name);
83+
} catch (NoSuchFieldException e) {
84+
for (Field field : cl.getDeclaredFields()) {
85+
if(field.getName().equalsIgnoreCase(name)) {
86+
return field;
87+
}
88+
}
89+
throw e;
90+
}
91+
}
92+
8093
/**
8194
* Gets a mapping of properties and their type, recursively for the given
8295
* type.

src/main/java/net/javadiscord/javabot/systems/configuration/ConfigCommand.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ public class ConfigCommand extends SlashCommand implements CommandModerationPerm
1717
* @param getConfigSubcommand /config get
1818
* @param setConfigSubcommand /config set
1919
*/
20-
public ConfigCommand(BotConfig botConfig, ExportConfigSubcommand exportConfigSubcommand, GetConfigSubcommand getConfigSubcommand, ConfigSubcommand setConfigSubcommand) {
20+
public ConfigCommand(BotConfig botConfig, ExportConfigSubcommand exportConfigSubcommand, GetConfigSubcommand getConfigSubcommand, SetConfigSubcommand setConfigSubcommand) {
2121
setModerationSlashCommandData(Commands.slash("config", "Administrative Commands for managing the bot's configuration."));
2222
addSubcommands(exportConfigSubcommand, getConfigSubcommand, setConfigSubcommand);
23-
setRequiredUsers(botConfig.getSystems().getAdminConfig().getAdminUsers());
2423
}
2524
}
2625

0 commit comments

Comments
 (0)