-
-
Notifications
You must be signed in to change notification settings - Fork 718
/
CommandCreateActionImpl.java
201 lines (177 loc) · 5.49 KB
/
CommandCreateActionImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.dv8tion.jda.internal.requests.restaction;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData;
import net.dv8tion.jda.api.requests.Request;
import net.dv8tion.jda.api.requests.Response;
import net.dv8tion.jda.api.requests.restaction.CommandCreateAction;
import net.dv8tion.jda.api.utils.data.DataObject;
import net.dv8tion.jda.internal.JDAImpl;
import net.dv8tion.jda.internal.interactions.CommandDataImpl;
import net.dv8tion.jda.internal.interactions.command.CommandImpl;
import net.dv8tion.jda.internal.requests.RestActionImpl;
import net.dv8tion.jda.internal.requests.Route;
import net.dv8tion.jda.internal.utils.Checks;
import okhttp3.RequestBody;
import javax.annotation.Nonnull;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.BooleanSupplier;
public class CommandCreateActionImpl extends RestActionImpl<Command> implements CommandCreateAction
{
private final Guild guild;
private CommandDataImpl data;
public CommandCreateActionImpl(JDAImpl api, CommandData command)
{
super(api, Route.Interactions.CREATE_COMMAND.compile(api.getSelfUser().getApplicationId()));
this.guild = null;
this.data = (CommandDataImpl) command;
}
public CommandCreateActionImpl(Guild guild, CommandData command)
{
super(guild.getJDA(), Route.Interactions.CREATE_GUILD_COMMAND.compile(guild.getJDA().getSelfUser().getApplicationId(), guild.getId()));
this.guild = guild;
this.data = (CommandDataImpl) command;
}
@Nonnull
@Override
public CommandCreateAction addCheck(@Nonnull BooleanSupplier checks)
{
return (CommandCreateAction) super.addCheck(checks);
}
@Nonnull
@Override
public CommandCreateAction setCheck(BooleanSupplier checks)
{
return (CommandCreateAction) super.setCheck(checks);
}
@Nonnull
@Override
public CommandCreateAction deadline(long timestamp)
{
return (CommandCreateAction) super.deadline(timestamp);
}
@Nonnull
@Override
public CommandCreateAction setDefaultEnabled(boolean enabled)
{
data.setDefaultEnabled(enabled);
return this;
}
@Nonnull
@Override
public String getName()
{
return data.getName();
}
@Override
public boolean isDefaultEnabled()
{
return data.isDefaultEnabled();
}
@Nonnull
@Override
public Command.Type getType()
{
return data.getType();
}
@Nonnull
@Override
public CommandCreateAction timeout(long timeout, @Nonnull TimeUnit unit)
{
return (CommandCreateAction) super.timeout(timeout, unit);
}
@Nonnull
@Override
public CommandCreateAction setName(@Nonnull String name)
{
Checks.notEmpty(name, "Name");
Checks.notLonger(name, 32, "Name");
Checks.matches(name, Checks.ALPHANUMERIC_WITH_DASH, "Name");
data.setName(name);
return this;
}
@Nonnull
@Override
public CommandCreateAction setDescription(@Nonnull String description)
{
Checks.notEmpty(description, "Description");
Checks.notLonger(description, 100, "Description");
data.setDescription(description);
return this;
}
@Nonnull
@Override
public String getDescription()
{
return data.getDescription();
}
@Nonnull
@Override
public List<SubcommandData> getSubcommands()
{
return data.getSubcommands();
}
@Nonnull
@Override
public List<SubcommandGroupData> getSubcommandGroups()
{
return data.getSubcommandGroups();
}
@Nonnull
@Override
public CommandCreateAction addOptions(@Nonnull OptionData... options)
{
data.addOptions(options);
return this;
}
@Nonnull
@Override
public CommandCreateAction addSubcommands(@Nonnull SubcommandData... subcommand)
{
data.addSubcommands(subcommand);
return this;
}
@Nonnull
@Override
public CommandCreateAction addSubcommandGroups(@Nonnull SubcommandGroupData... group)
{
data.addSubcommandGroups(group);
return this;
}
@Override
public RequestBody finalizeData()
{
return getRequestBody(data.toData());
}
@Override
protected void handleSuccess(Response response, Request<Command> request)
{
DataObject json = response.getObject();
request.onSuccess(new CommandImpl(api, guild, json));
}
@Nonnull
@Override
public DataObject toData()
{
return data.toData();
}
}