net.dv8tion.jda.api.entities.GuildVoiceState Java Examples

The following examples show how to use net.dv8tion.jda.api.entities.GuildVoiceState. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VoiceActivityListener.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
private void updateFreeze(Member member, GuildVoiceState state) {
    GuildVoiceActivityTracker tracker = trackers.getIfPresent(member.getGuild().getIdLong());
    if (tracker == null) {
        return;
    }
    tracker.freeze(member, isFrozen(state));
}
 
Example #2
Source File: VoiceChannelListener.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
private void onGuildVoiceMute(GuildVoiceMuteEvent event) {
    if (event.getMember().getUser().getIdLong() != event.getJDA().getSelfUser().getIdLong())
        return;

    GuildVoiceState vs = event.getVoiceState();
    if (validate(vs))
        return;

    GuildMusicManager gmm = MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild());
    if(gmm == null)
        return;

    if (event.isMuted()) {
        TrackScheduler scheduler = gmm.getTrackScheduler();
        if (scheduler.getCurrentTrack() != null && scheduler.getRequestedTextChannel() != null) {
            TextChannel tc = scheduler.getRequestedTextChannel();
            //Didn't ratelimit this one because mute can only be done by admins and such? Don't think it'll get abused.
            if (tc.canTalk()) {
                tc.sendMessageFormat(
                        scheduler.getLanguage().get("commands.music_general.listener.paused"), EmoteReference.SAD
                ).queue();
            }
            gmm.getLavaLink().getPlayer().setPaused(true);
        }
    } else {
        if (!isAlone(vs.getChannel()) && gmm.getTrackScheduler().getCurrentTrack() != null) {
            gmm.getLavaLink().getPlayer().setPaused(false);
        }
    }

}
 
Example #3
Source File: VoiceChannelListener.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
private void onJoin(VoiceChannel vc) {
    GuildVoiceState vs = vc.getGuild().getSelfMember().getVoiceState();
    if (validate(vs))
        return;

    if (!isAlone(vc)) {
        GuildMusicManager gmm = MantaroBot.getInstance().getAudioManager().getMusicManager(vc.getGuild());
        if(gmm == null)
            return;

        TrackScheduler scheduler = gmm.getTrackScheduler();
        if (scheduler.getCurrentTrack() != null) {
            if (gmm.isAwaitingDeath()) {
                TextChannel tc = scheduler.getRequestedTextChannel();
                if (tc.canTalk() && vcRatelimiter.process(vc.getGuild().getId())) {
                    tc.sendMessageFormat(
                            scheduler.getLanguage().get("commands.music_general.listener.resumed"), EmoteReference.POPPER
                    ).queue();
                }
            }
        }

        gmm.cancelLeave();
        gmm.setAwaitingDeath(false);
        gmm.getLavaLink().getPlayer().setPaused(false);
    }
}
 
Example #4
Source File: VoiceChannelListener.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
private void onLeave(VoiceChannel vc) {
    GuildVoiceState vs = vc.getGuild().getSelfMember().getVoiceState();
    if (validate(vs))
        return;

    if (isAlone(vc)) {
        GuildMusicManager gmm = MantaroBot.getInstance().getAudioManager().getMusicManager(vc.getGuild());
        if(gmm == null)
            return;

        TrackScheduler scheduler = gmm.getTrackScheduler();
        if (scheduler != null && scheduler.getCurrentTrack() != null && scheduler.getRequestedTextChannel() != null) {
            TextChannel tc = scheduler.getRequestedTextChannel();
            if (tc.canTalk() && vcRatelimiter.process(vc.getGuild().getId())) {
                tc.sendMessageFormat(scheduler.getLanguage().get(
                        "commands.music_general.listener.left_alone"), EmoteReference.THINKING, vc.getName()
                ).queue(m -> m.delete()
                        .queueAfter(30, TimeUnit.SECONDS)
                );
            }
        }

        gmm.setAwaitingDeath(true);
        gmm.scheduleLeave();
        gmm.getLavaLink().getPlayer().setPaused(true);
    }
}
 
Example #5
Source File: GuildVoiceStateImpl.java    From JDA with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj)
{
    if (obj == this)
        return true;
    if (!(obj instanceof GuildVoiceState))
        return false;
    GuildVoiceState oStatus = (GuildVoiceState) obj;
    return this.getMember().equals(oStatus.getMember());
}
 
Example #6
Source File: WebSocketSendingThread.java    From JDA with Apache License 2.0 5 votes vote down vote up
private void handleAudioRequest(ConnectionRequest audioRequest)
{
    long channelId = audioRequest.getChannelId();
    long guildId = audioRequest.getGuildIdLong();
    Guild guild = api.getGuildById(guildId);
    if (guild == null)
    {
        LOG.debug("Discarding voice request due to null guild {}", guildId);
        // race condition on guild delete, avoid NPE on DISCONNECT requests
        queuedAudioConnections.remove(guildId);
        return;
    }
    ConnectionStage stage = audioRequest.getStage();
    AudioManager audioManager = guild.getAudioManager();
    DataObject packet;
    switch (stage)
    {
        case RECONNECT:
        case DISCONNECT:
            packet = newVoiceClose(guildId);
            break;
        default:
        case CONNECT:
            packet = newVoiceOpen(audioManager, channelId, guild.getIdLong());
    }
    LOG.debug("Sending voice request {}", packet);
    if (send(packet.toString()))
    {
        //If we didn't get RateLimited, Next request attempt will be 2 seconds from now
        // we remove it in VoiceStateUpdateHandler once we hear that it has updated our status
        // in 2 seconds we will attempt again in case we did not receive an update
        audioRequest.setNextAttemptEpoch(System.currentTimeMillis() + 2000);
        //If we are already in the correct state according to voice state
        // we will not receive a VOICE_STATE_UPDATE that would remove it
        // thus we update it here
        final GuildVoiceState voiceState = guild.getSelfMember().getVoiceState();
        client.updateAudioConnection0(guild.getIdLong(), voiceState.getChannel());
    }
}
 
Example #7
Source File: VoiceActivityListener.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
private static boolean isFrozen(GuildVoiceState voiceState) {
    return voiceState == null || !voiceState.inVoiceChannel() || voiceState.isMuted() || voiceState.isSuppressed();
}
 
Example #8
Source File: VoiceChannelListener.java    From MantaroBot with GNU General Public License v3.0 4 votes vote down vote up
private static boolean validate(GuildVoiceState state) {
    return state == null || !state.inVoiceChannel();
}
 
Example #9
Source File: VoiceDispatchInterceptor.java    From JDA with Apache License 2.0 4 votes vote down vote up
public VoiceStateUpdate(VoiceChannel channel, GuildVoiceState voiceState, DataObject json)
{
    this.channel = channel;
    this.voiceState = voiceState;
    this.json = json;
}
 
Example #10
Source File: VoiceDispatchInterceptor.java    From JDA with Apache License 2.0 4 votes vote down vote up
/**
 * The voice state for the guild
 *
 * @return The voice state
 */
@Nonnull
public GuildVoiceState getVoiceState()
{
    return voiceState;
}
 
Example #11
Source File: GenericGuildVoiceEvent.java    From JDA with Apache License 2.0 2 votes vote down vote up
/**
 * The {@link net.dv8tion.jda.api.entities.GuildVoiceState GuildVoiceState} of the member
 * <br>Shortcut for {@code getMember().getVoiceState()}
 *
 * @return The {@link net.dv8tion.jda.api.entities.GuildVoiceState GuildVoiceState} of the member
 */
@Nonnull
public GuildVoiceState getVoiceState()
{
    return member.getVoiceState();
}