22
22
import com .javadiscord .jdi .core .api .builders .command .CommandOptionType ;
23
23
import com .javadiscord .jdi .core .interaction .InteractionEventHandler ;
24
24
import com .javadiscord .jdi .core .models .ready .ReadyEvent ;
25
- import com .javadiscord .jdi .internal .ReflectiveComponentLoader ;
26
- import com .javadiscord .jdi .internal .ReflectiveLoader ;
27
- import com .javadiscord .jdi .internal .ReflectiveSlashCommandClassMethod ;
25
+ import com .javadiscord .jdi .internal .*;
28
26
import com .javadiscord .jdi .internal .api .DiscordRequest ;
29
27
import com .javadiscord .jdi .internal .api .DiscordRequestDispatcher ;
30
28
import com .javadiscord .jdi .internal .api .DiscordResponseFuture ;
@@ -112,13 +110,7 @@ public Discord(String botToken, IdentifyRequest identifyRequest) {
112
110
}
113
111
114
112
public Discord (String botToken , IdentifyRequest identifyRequest , Cache cache ) {
115
- System .err .println ("""
116
- _ ____ ___
117
- | | _ \\ _ _| https://github.com/javadiscord/java-discord-api
118
- _ | | | | | | Open-Source Discord Framework
119
- | |_| | |_| | | GPL-3.0 license
120
- \\ ___/|____/___| Version 1.0
121
- """ );
113
+ System .err .println (Constants .LAUNCH_HEADER );
122
114
123
115
this .botToken = botToken ;
124
116
this .discordRequestDispatcher = new DiscordRequestDispatcher (botToken );
@@ -150,7 +142,7 @@ private void registerLoadedAnnotationsWithDiscord() {
150
142
for (Annotation annotation : annotations ) {
151
143
if (
152
144
annotation .annotationType ().getName ()
153
- .equals ("com.javadiscord.jdi.core.annotations.SlashCommand" )
145
+ .equals (Constants . SLASH_COMMAND_ANNOTATION )
154
146
) {
155
147
CommandBuilder builder = buildCommand (annotation );
156
148
createInteractionRequests .add (builder );
@@ -183,22 +175,18 @@ private CommandBuilder buildCommand(Annotation annotation) throws ReflectiveOper
183
175
private void addCommandOption (
184
176
CommandBuilder builder ,
185
177
Object option
186
- ) throws ReflectiveOperationException {
187
- Method optionNameMethod = option .getClass ().getMethod ("name" );
188
- String optionName = (String ) optionNameMethod .invoke (option );
189
-
190
- Method optionDescriptionMethod = option .getClass ().getMethod ("description" );
191
- String optionDescription = (String ) optionDescriptionMethod .invoke (option );
178
+ ) {
192
179
193
- Method optionTypeMethod = option .getClass ().getMethod ("type" );
194
- Enum <?> optionType = (Enum <?>) optionTypeMethod .invoke (option );
195
- String optionTypeValue = optionType .name ();
180
+ ReflectiveCommandOption reflectiveCommandOption =
181
+ ReflectiveLoader .proxy (option , ReflectiveCommandOption .class );
196
182
197
- Method optionRequiredMethod = option .getClass ().getMethod ("required" );
198
- boolean optionRequired = (boolean ) optionRequiredMethod .invoke (option );
183
+ String optionName = reflectiveCommandOption .name ();
184
+ String optionDescription = reflectiveCommandOption .description ();
185
+ String optionTypeValue = reflectiveCommandOption .type ().name ();
186
+ boolean optionRequired = reflectiveCommandOption .required ();
199
187
200
188
List <CommandOptionChoice > choices = new ArrayList <>();
201
- Object [] choicesArray = ( Object []) option . getClass (). getMethod ( " choices" ). invoke ( option );
189
+ Object [] choicesArray = reflectiveCommandOption . choices ( );
202
190
for (Object choice : choicesArray ) {
203
191
addCommandOptionChoice (choices , choice );
204
192
}
@@ -209,24 +197,21 @@ private void addCommandOption(
209
197
optionDescription ,
210
198
CommandOptionType .fromName (optionTypeValue ),
211
199
optionRequired
212
- ).addChoice (choices )
200
+ )
201
+ .addChoice (choices )
213
202
);
214
203
}
215
204
216
- private void addCommandOptionChoice (
217
- List <CommandOptionChoice > choices ,
218
- Object choice
219
- ) throws ReflectiveOperationException {
220
- Annotation annotation1 = (Annotation ) choice ;
205
+ private void addCommandOptionChoice (List <CommandOptionChoice > choices , Object choice ) {
206
+ Annotation annotation = (Annotation ) choice ;
221
207
if (
222
- annotation1 .annotationType ().getName ()
223
- .equals (Constants .COMMAND_OPTION_CHOICE_ANNOTATION )
208
+ annotation .annotationType ().getName ().equals (Constants .COMMAND_OPTION_CHOICE_ANNOTATION )
224
209
) {
225
- Method nameMethod1 = annotation1 . annotationType (). getMethod ( "name" );
226
- Method valueMethod1 = annotation1 . annotationType (). getMethod ( "value" );
227
- String name1 = ( String ) nameMethod1 . invoke ( annotation1 );
228
- String value1 = ( String ) valueMethod1 . invoke ( annotation1 );
229
- choices . add ( new CommandOptionChoice ( value1 , name1 ) );
210
+ ReflectiveCommandOptionChoice commandOptionChoice =
211
+ ReflectiveLoader . proxy ( annotation , ReflectiveCommandOptionChoice . class );
212
+ choices . add (
213
+ new CommandOptionChoice ( commandOptionChoice . value (), commandOptionChoice . name ())
214
+ );
230
215
}
231
216
}
232
217
@@ -307,7 +292,6 @@ private void loadSlashCommands() {
307
292
308
293
public void start () {
309
294
started = true ;
310
-
311
295
webSocketManager = new WebSocketManager (gatewaySetting , identifyRequest , cache );
312
296
WebSocketManagerProxy webSocketManagerProxy = new WebSocketManagerProxy (webSocketManager );
313
297
ConnectionDetails connectionDetails =
0 commit comments