Java源码示例:net.dv8tion.jda.api.entities.GuildVoiceState

示例1
private void updateFreeze(Member member, GuildVoiceState state) {
    GuildVoiceActivityTracker tracker = trackers.getIfPresent(member.getGuild().getIdLong());
    if (tracker == null) {
        return;
    }
    tracker.freeze(member, isFrozen(state));
}
 
示例2
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);
        }
    }

}
 
示例3
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);
    }
}
 
示例4
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);
    }
}
 
示例5
@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());
}
 
示例6
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());
    }
}
 
示例7
private static boolean isFrozen(GuildVoiceState voiceState) {
    return voiceState == null || !voiceState.inVoiceChannel() || voiceState.isMuted() || voiceState.isSuppressed();
}
 
示例8
private static boolean validate(GuildVoiceState state) {
    return state == null || !state.inVoiceChannel();
}
 
示例9
public VoiceStateUpdate(VoiceChannel channel, GuildVoiceState voiceState, DataObject json)
{
    this.channel = channel;
    this.voiceState = voiceState;
    this.json = json;
}
 
示例10
/**
 * The voice state for the guild
 *
 * @return The voice state
 */
@Nonnull
public GuildVoiceState getVoiceState()
{
    return voiceState;
}
 
示例11
/**
 * 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();
}