-
-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a360d5
commit 706e27c
Showing
13 changed files
with
251 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/net/dv8tion/jda/api/entities/channel/attribute/IVoiceStatusChannel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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.attribute; | ||
|
||
import net.dv8tion.jda.api.Permission; | ||
import net.dv8tion.jda.api.entities.channel.Channel; | ||
import net.dv8tion.jda.api.requests.restaction.AuditableRestAction; | ||
|
||
import javax.annotation.CheckReturnValue; | ||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Channel with a modifiable voice status. | ||
* <br>This can be used to indicate what is going on to people outside the channel. | ||
*/ | ||
public interface IVoiceStatusChannel extends Channel | ||
{ | ||
/** The maximum length of a voice status {@value} */ | ||
int MAX_STATUS_LENGTH = 500; | ||
|
||
/** | ||
* The current voice channel status. | ||
* <br>This can be configured by users who are connected | ||
* and have the {@link net.dv8tion.jda.api.Permission#VOICE_SET_STATUS set voice channel status} permission. | ||
* | ||
* @return The current voice channel status, or empty string if unset | ||
*/ | ||
@Nonnull | ||
String getStatus(); | ||
|
||
/** | ||
* Change the current voice channel status. | ||
* <br>This can be configured by users who are connected | ||
* and have the {@link net.dv8tion.jda.api.Permission#VOICE_SET_STATUS set voice channel status} permission. | ||
* | ||
* @param status | ||
* The new status, or empty to unset | ||
* | ||
* @throws IllegalArgumentException | ||
* If the status is null or longer than {@value #MAX_STATUS_LENGTH} characters | ||
* @throws net.dv8tion.jda.api.exceptions.MissingAccessException | ||
* If the currently logged in account does not have {@link Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} in this channel | ||
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException | ||
* <ul> | ||
* <li>If the currently logged in account is <b>not connected</b> and does not have the {@link Permission#MANAGE_CHANNEL MANAGE_CHANNEL} permission.</li> | ||
* <li>If the currently logged in account is <b>connected</b> and does not have the {@link Permission#VOICE_SET_STATUS VOICE_SET_STATUS} permission.</li> | ||
* </ul> | ||
* | ||
* @return {@link AuditableRestAction} | ||
*/ | ||
@Nonnull | ||
@CheckReturnValue | ||
AuditableRestAction<Void> modifyStatus(@Nonnull String status); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/net/dv8tion/jda/api/events/channel/update/ChannelUpdateVoiceStatusEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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.events.channel.update; | ||
|
||
import net.dv8tion.jda.api.JDA; | ||
import net.dv8tion.jda.api.entities.channel.Channel; | ||
import net.dv8tion.jda.api.entities.channel.ChannelField; | ||
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Indicates that a {@link Channel Channel's} voice channel status has been updated. | ||
* | ||
* <p>Can be used to retrieve the old status and the new one. | ||
* | ||
* <p>Limited to {@link VoiceChannel VoiceChannels}. | ||
* | ||
* @see VoiceChannel#getStatus() | ||
*/ | ||
public class ChannelUpdateVoiceStatusEvent extends GenericChannelUpdateEvent<String> | ||
{ | ||
public static final ChannelField FIELD = ChannelField.VOICE_STATUS; | ||
public static final String IDENTIFIER = FIELD.getFieldName(); | ||
|
||
public ChannelUpdateVoiceStatusEvent(@Nonnull JDA api, long responseNumber, Channel channel, String oldValue, String newValue) | ||
{ | ||
super(api, responseNumber, channel, FIELD, oldValue, newValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/net/dv8tion/jda/internal/handle/VoiceChannelStatusUpdateHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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.handle; | ||
|
||
import net.dv8tion.jda.api.events.channel.update.ChannelUpdateVoiceStatusEvent; | ||
import net.dv8tion.jda.api.utils.data.DataObject; | ||
import net.dv8tion.jda.internal.JDAImpl; | ||
import net.dv8tion.jda.internal.entities.channel.concrete.VoiceChannelImpl; | ||
|
||
public class VoiceChannelStatusUpdateHandler extends SocketHandler | ||
{ | ||
public VoiceChannelStatusUpdateHandler(JDAImpl api) | ||
{ | ||
super(api); | ||
} | ||
|
||
@Override | ||
protected Long handleInternally(DataObject content) | ||
{ | ||
long guildId = content.getUnsignedLong("guild_id"); | ||
if (getJDA().getGuildSetupController().isLocked(guildId)) | ||
return guildId; | ||
|
||
long id = content.getUnsignedLong("id"); | ||
VoiceChannelImpl channel = (VoiceChannelImpl) getJDA().getVoiceChannelsView().getElementById(id); | ||
|
||
if (channel == null) | ||
{ | ||
EventCache.LOG.debug("Caching VOICE_CHANNEL_STATUS_UPDATE for uncached channel. ID: {}", id); | ||
getJDA().getEventCache().cache(EventCache.Type.CHANNEL, id, responseNumber, allContent, this::handle); | ||
return null; | ||
} | ||
|
||
String newStatus = content.getString("status", ""); | ||
if (!newStatus.equals(channel.getStatus())) | ||
{ | ||
String oldStatus = channel.getStatus(); | ||
channel.setStatus(newStatus); | ||
api.handleEvent( | ||
new ChannelUpdateVoiceStatusEvent( | ||
api, responseNumber, | ||
channel, oldStatus, newStatus)); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters