/
StageChannel.java
166 lines (154 loc) · 6.65 KB
/
StageChannel.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
/*
* 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.api.entities.channel.concrete;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.GuildVoiceState;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.StageInstance;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildChannel;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.managers.channel.concrete.StageChannelManager;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.requests.restaction.ChannelAction;
import net.dv8tion.jda.api.requests.restaction.StageInstanceAction;
import net.dv8tion.jda.internal.requests.restaction.StageInstanceActionImpl;
import net.dv8tion.jda.internal.utils.Checks;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.EnumSet;
/**
* Represents a Stage Channel.
*
* <p>This is a specialized AudioChannel that can be used to host events with speakers and listeners.
*/
public interface StageChannel extends GuildChannel, AudioChannel, StandardGuildChannel
{
/**
* {@link StageInstance} attached to this stage channel.
*
* <p>This indicates whether a stage channel is currently "live".
*
* @return The {@link StageInstance} or {@code null} if this stage is not live
*/
@Nullable
StageInstance getStageInstance();
/**
* Create a new {@link StageInstance} for this stage channel.
*
* <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} include:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#STAGE_ALREADY_OPEN STAGE_ALREADY_OPEN}
* <br>If there already is an active {@link StageInstance} for this channel</li>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL}
* <br>If the channel was deleted</li>
* </ul>
*
* @param topic
* The topic of this stage instance, must be 1-120 characters long
*
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If the self member is not a stage moderator. (See {@link #isModerator(Member)})
* @throws IllegalArgumentException
* If the topic is null, empty, or longer than 120 characters
*
* @return {@link StageInstanceAction}
*/
@Nonnull
@CheckReturnValue
default StageInstanceAction createStageInstance(@Nonnull String topic)
{
EnumSet<Permission> permissions = getGuild().getSelfMember().getPermissions(this);
EnumSet<Permission> required = EnumSet.of(Permission.MANAGE_CHANNEL, Permission.VOICE_MUTE_OTHERS, Permission.VOICE_MOVE_OTHERS);
for (Permission perm : required)
{
if (!permissions.contains(perm))
throw new InsufficientPermissionException(this, perm, "You must be a stage moderator to create a stage instance! Missing Permission: " + perm);
}
return new StageInstanceActionImpl(this).setTopic(topic);
}
/**
* Whether this member is considered a moderator for this stage channel.
* <br>Moderators can modify the {@link #getStageInstance() Stage Instance} and promote speakers.
* To promote a speaker you can use {@link GuildVoiceState#inviteSpeaker()} or {@link GuildVoiceState#approveSpeaker()} if they have already raised their hand (indicated by {@link GuildVoiceState#getRequestToSpeakTimestamp()}).
* A stage moderator can move between speaker and audience without raising their hand. This can be done with {@link Guild#requestToSpeak()} and {@link Guild#cancelRequestToSpeak()} respectively.
*
* <p>A member is considered a stage moderator if they have these permissions in the stage channel:
* <ul>
* <li>{@link Permission#MANAGE_CHANNEL}</li>
* <li>{@link Permission#VOICE_MUTE_OTHERS}</li>
* <li>{@link Permission#VOICE_MOVE_OTHERS}</li>
* </ul>
*
* @param member
* The member to check
*
* @throws IllegalArgumentException
* If the provided member is null or not from this guild
*
* @return True, if the provided member is a stage moderator
*/
default boolean isModerator(@Nonnull Member member)
{
Checks.notNull(member, "Member");
return member.hasPermission(this, Permission.MANAGE_CHANNEL, Permission.VOICE_MUTE_OTHERS, Permission.VOICE_MOVE_OTHERS);
}
@Nonnull
@Override
ChannelAction<StageChannel> createCopy(@Nonnull Guild guild);
@Nonnull
@Override
default ChannelAction<StageChannel> createCopy()
{
return createCopy(getGuild());
}
@Nonnull
@Override
StageChannelManager getManager();
/**
* Sends a {@link GuildVoiceState#getRequestToSpeakTimestamp() request-to-speak} indicator to the stage instance moderators.
* <p>If the self member has {@link Permission#VOICE_MUTE_OTHERS} this will immediately promote them to speaker.
*
* @throws IllegalStateException
* If the self member is not currently connected to the channel
*
* @return {@link RestAction}
*
* @see #cancelRequestToSpeak()
*/
@Nonnull
@CheckReturnValue
RestAction<Void> requestToSpeak();
/**
* Cancels the {@link #requestToSpeak() Request-to-Speak}.
* <br>This can also be used to move back to the audience if you are currently a speaker.
*
* <p>If there is no request to speak or the member is not currently connected to an active {@link StageInstance}, this does nothing.
*
* @throws IllegalStateException
* If the self member is not currently connected to the channel
*
* @return {@link RestAction}
*
* @see #requestToSpeak()
*/
@Nonnull
@CheckReturnValue
RestAction<Void> cancelRequestToSpeak();
}