Java 类net.dv8tion.jda.core.entities.GuildVoiceState 实例源码

项目:Tazbot    文件:OrderCommand.java   
@Override
public void onCommand(MessageReceivedEvent e, String[] args) {
    if (e.getGuild() == null) {
        SendMessage.sendMessage(e, "Error: Can only be used in a guild.");
    }

    GuildVoiceState state = e.getMember().getVoiceState();

    if (!state.inVoiceChannel()) {
        SendMessage.sendMessage(e, "Error: You must be in a voice channel.");
    }

    List<Member> members = new ArrayList<Member>(e.getMember().getVoiceState().getChannel().getMembers());
    Collections.shuffle(members);

    StringBuilder sb = new StringBuilder();
    sb.append("Order is:\n");
    for (int i = 0; i < members.size(); i++) {
        String num = "[" + i + "]";
        sb.append(String.format("%-10s%s\n", num, members.get(i).getEffectiveName()));
    }

    SendMessage.sendMessage(e, sb.toString());
}
项目:GabrielBot    文件:MusicListener.java   
public void onGuildVoiceMute(GuildVoiceMuteEvent event) {
    if(event.getMember().getUser().getIdLong() != event.getJDA().getSelfUser().getIdLong()) return;
    GuildVoiceState vs = event.getVoiceState();
    if(validate(vs)) return;
    GuildMusicPlayer gmp = GabrielBot.getInstance().getPlayer(event.getGuild().getIdLong());
    if(gmp != null) {
        if(event.isMuted()) {
            gmp.scheduleLeave(GuildMusicPlayer.LeaveReason.MUTED);
        } else {
            if(!isAlone(vs.getChannel())) {
                gmp.cancelLeave();
            }
        }
    }
}
项目:GabrielBot    文件:MusicListener.java   
private void onJoin(VoiceChannel vc) {
    GuildVoiceState vs = vc.getGuild().getSelfMember().getVoiceState();
    if(validate(vs)) return;
    if(!isAlone(vc)) {
        GuildMusicPlayer gmp = GabrielBot.getInstance().getPlayer(vc.getGuild().getIdLong());
        if(gmp != null) {
            gmp.cancelLeave();
        }
    }
}
项目:GabrielBot    文件:MusicListener.java   
private void onLeave(VoiceChannel vc) {
    GuildVoiceState vs = vc.getGuild().getSelfMember().getVoiceState();
    if(validate(vs)) return;
    if(isAlone(vc)) {
        GuildMusicPlayer gmp = GabrielBot.getInstance().getPlayer(vc.getGuild().getIdLong());
        if(gmp != null) {
            gmp.scheduleLeave(GuildMusicPlayer.LeaveReason.ALONE);
        }
    }
}
项目:Tazbot    文件:AtChannelCommand.java   
@Override
public void onCommand(MessageReceivedEvent e, String[] args) {
    GuildVoiceState state = e.getMember().getVoiceState();
    if (!state.inVoiceChannel()) {
        return;
    }


    List<Member> members = state.getChannel().getMembers();
    if (members.size() <= 1) {
        return;
    }

    MessageBuilder mb = new MessageBuilder();

    String channelName = state.getChannel().getName();
    int maxNameLength = 25;
    if (channelName.length() > maxNameLength) {
        channelName = channelName.substring(0, maxNameLength) + "...";
    }

    mb.append(e.getAuthor()).append(" *@" + channelName + "*: ");

    members.forEach(m -> {
        if (m.getUser().getId() != e.getAuthor().getId()) {
            mb.append(m).append(" ");
        }
    });

    if (args.length > 1) {
        mb.append(StringUtils.join(args, " ", 1, args.length));
    }

    SendMessage.sendMessage(e, mb.build());
}
项目:avaire    文件:VoteSkipCommand.java   
private boolean canVoteSkip(Message message) {
    GuildVoiceState voiceState = message.getMember().getVoiceState();
    GuildVoiceState selfVoteState = message.getGuild().getSelfMember().getVoiceState();

    return voiceState.getChannel() != null && voiceState.getChannel().getId().equals(selfVoteState.getChannel().getId());
}
项目:GabrielBot    文件:MusicListener.java   
private static boolean validate(GuildVoiceState state) {
    return state == null || !state.inVoiceChannel();
}
项目:MusicBot    文件:MusicCommand.java   
@Override
protected void execute(CommandEvent event) {
    Settings settings = bot.getSettings(event.getGuild());
    TextChannel tchannel = event.getGuild().getTextChannelById(settings.getTextId());
    if(tchannel!=null && !event.getTextChannel().equals(tchannel))
    {
        try {
            event.getMessage().delete().queue();
        } catch(PermissionException e){}
        event.replyInDM(event.getClient().getError()+" You can only use that command in <#"+settings.getTextId()+">!");
        return;
    }
    if(bePlaying
            && (event.getGuild().getAudioManager().getSendingHandler()==null
            || !((AudioHandler)event.getGuild().getAudioManager().getSendingHandler()).isMusicPlaying()))
    {
        event.reply(event.getClient().getError()+" There must be music playing to use that!");
        return;
    }
    if(beListening)
    {
        VoiceChannel current = event.getGuild().getSelfMember().getVoiceState().getChannel();
        if(current==null)
            current = event.getGuild().getVoiceChannelById(settings.getVoiceId());
        GuildVoiceState userState = event.getMember().getVoiceState();
        if(!userState.inVoiceChannel() || userState.isDeafened() || (current!=null && !userState.getChannel().equals(current)))
        {
            event.reply(event.getClient().getError()
                    +" You must be listening in "+(current==null ? "a voice channel" : "**"+current.getName()+"**")
                    +" to use that!");
            return;
        }
        if(!event.getGuild().getSelfMember().getVoiceState().inVoiceChannel())
            try {
                event.getGuild().getAudioManager().openAudioConnection(userState.getChannel());
            }catch(PermissionException ex) {
                event.reply(event.getClient().getError()+" I am unable to connect to **"+userState.getChannel().getName()+"**!");
                return;
            }
    }
    doCommand(event);
}
项目:JDA    文件:GenericGuildVoiceEvent.java   
public GuildVoiceState getVoiceState()
{
    return member.getVoiceState();
}