/
StageInstanceActionImpl.java
106 lines (94 loc) · 3.54 KB
/
StageInstanceActionImpl.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
/*
* 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.StageInstance;
import net.dv8tion.jda.api.entities.channel.concrete.StageChannel;
import net.dv8tion.jda.api.requests.Request;
import net.dv8tion.jda.api.requests.Response;
import net.dv8tion.jda.api.requests.Route;
import net.dv8tion.jda.api.requests.restaction.StageInstanceAction;
import net.dv8tion.jda.api.utils.data.DataObject;
import net.dv8tion.jda.internal.entities.GuildImpl;
import net.dv8tion.jda.internal.requests.RestActionImpl;
import net.dv8tion.jda.internal.utils.Checks;
import okhttp3.RequestBody;
import javax.annotation.Nonnull;
import java.util.concurrent.TimeUnit;
import java.util.function.BooleanSupplier;
public class StageInstanceActionImpl extends RestActionImpl<StageInstance> implements StageInstanceAction
{
private final StageChannel channel;
private String topic;
private StageInstance.PrivacyLevel level = StageInstance.PrivacyLevel.GUILD_ONLY;
public StageInstanceActionImpl(StageChannel channel)
{
super(channel.getJDA(), Route.StageInstances.CREATE_INSTANCE.compile());
this.channel = channel;
}
@Nonnull
@Override
public StageInstanceAction setCheck(BooleanSupplier checks)
{
return (StageInstanceAction) super.setCheck(checks);
}
@Nonnull
@Override
public StageInstanceAction timeout(long timeout, @Nonnull TimeUnit unit)
{
return (StageInstanceAction) super.timeout(timeout, unit);
}
@Nonnull
@Override
public StageInstanceAction deadline(long timestamp)
{
return (StageInstanceAction) super.deadline(timestamp);
}
@Nonnull
@Override
public StageInstanceAction setTopic(@Nonnull String topic)
{
Checks.notBlank(topic, "Topic");
Checks.notLonger(topic, 120, "Topic");
this.topic = topic;
return this;
}
@Nonnull
@Override
@SuppressWarnings("deprecation")
public StageInstanceAction setPrivacyLevel(@Nonnull StageInstance.PrivacyLevel level)
{
Checks.notNull(level, "PrivacyLevel");
Checks.check(level != StageInstance.PrivacyLevel.UNKNOWN, "The PrivacyLevel must not be UNKNOWN!");
Checks.check(level != StageInstance.PrivacyLevel.PUBLIC, "Cannot create PUBLIC stage instances anymore.");
this.level = level;
return this;
}
@Override
protected RequestBody finalizeData()
{
DataObject body = DataObject.empty();
body.put("channel_id", channel.getId());
body.put("topic", topic);
body.put("privacy_level", level.getKey());
return getRequestBody(body);
}
@Override
protected void handleSuccess(Response response, Request<StageInstance> request)
{
StageInstance instance = api.getEntityBuilder().createStageInstance((GuildImpl) channel.getGuild(), response.getObject());
request.onSuccess(instance);
}
}