6
6
import net .dv8tion .jda .api .interactions .commands .Command ;
7
7
import net .dv8tion .jda .api .interactions .commands .build .CommandData ;
8
8
import org .jetbrains .annotations .Contract ;
9
- import org .togetherjava .tjbot .commands .componentids .ComponentId ;
10
9
import org .togetherjava .tjbot .commands .componentids .ComponentIdGenerator ;
10
+ import org .togetherjava .tjbot .commands .componentids .ComponentIdInteractor ;
11
11
import org .togetherjava .tjbot .commands .componentids .Lifespan ;
12
12
13
- import java .util .Arrays ;
14
13
import java .util .List ;
15
14
import java .util .Objects ;
16
15
38
37
* Registration of commands can be done in {@link Features}.
39
38
*/
40
39
public abstract class BotCommandAdapter implements BotCommand {
41
- private final String name ;
42
40
private final Command .Type type ;
43
41
private final CommandVisibility visibility ;
44
42
private final CommandData data ;
45
- private ComponentIdGenerator componentIdGenerator ;
43
+ private final ComponentIdInteractor componentIdInteractor ;
46
44
47
45
/**
48
46
* Creates a new adapter with the given data.
@@ -54,17 +52,17 @@ protected BotCommandAdapter(CommandData data, CommandVisibility visibility) {
54
52
this .data = Objects .requireNonNull (data , "The data shouldn't be null" );
55
53
this .visibility = Objects .requireNonNull (visibility , "The visibility shouldn't be null" );
56
54
57
- this . name = data .getName ();
58
- this . type = data .getType ( );
55
+ type = data .getType ();
56
+ componentIdInteractor = new ComponentIdInteractor ( data .getName () );
59
57
}
60
58
61
59
@ Override
62
60
public final String getName () {
63
- return name ;
61
+ return componentIdInteractor . getName () ;
64
62
}
65
63
66
64
@ Override
67
- public Command .Type getType () {
65
+ public final Command .Type getType () {
68
66
return type ;
69
67
}
70
68
@@ -81,8 +79,7 @@ public CommandData getData() {
81
79
@ Override
82
80
@ Contract (mutates = "this" )
83
81
public final void acceptComponentIdGenerator (ComponentIdGenerator generator ) {
84
- componentIdGenerator =
85
- Objects .requireNonNull (generator , "The given generator cannot be null" );
82
+ componentIdInteractor .acceptComponentIdGenerator (generator );
86
83
}
87
84
88
85
@ SuppressWarnings ("NoopMethodInAbstractClass" )
@@ -113,7 +110,7 @@ public void onSelectionMenu(SelectMenuInteractionEvent event, List<String> args)
113
110
*/
114
111
@ SuppressWarnings ("OverloadedVarargsMethod" )
115
112
protected final String generateComponentId (String ... args ) {
116
- return generateComponentId (Lifespan . REGULAR , args );
113
+ return componentIdInteractor . generateComponentId (args );
117
114
}
118
115
119
116
/**
@@ -130,7 +127,6 @@ protected final String generateComponentId(String... args) {
130
127
*/
131
128
@ SuppressWarnings ({"OverloadedVarargsMethod" , "WeakerAccess" })
132
129
protected final String generateComponentId (Lifespan lifespan , String ... args ) {
133
- return componentIdGenerator .generate (new ComponentId (getName (), Arrays .asList (args )),
134
- lifespan );
130
+ return componentIdInteractor .generateComponentId (lifespan , args );
135
131
}
136
132
}
0 commit comments