public GuildVoiceJoinEvent(JDA api, long responseNumber, Member member) { super(api, responseNumber, member); this.channelJoined = member.getVoiceState().getChannel(); }
public GuildVoiceMoveEvent(JDA api, long responseNumber, Member member, VoiceChannel channelLeft) { super(api, responseNumber, member, channelLeft); this.channelJoined = member.getVoiceState().getChannel(); }
client.updateAudioConnection0(guild.getIdLong(), voiceState.getChannel());
throw new IllegalArgumentException("Attempted to start audio connection with Guild that doesn't exist!"); getJDA().getClient().updateAudioConnection(guildId, guild.getSelfMember().getVoiceState().getChannel());
throw new IllegalStateException("You cannot move a Member who isn't in a VoiceChannel!"); if (!PermissionUtil.checkPermission(vState.getChannel(), getGuild().getSelfMember(), Permission.VOICE_MOVE_OTHERS)) throw new InsufficientPermissionException(Permission.VOICE_MOVE_OTHERS, "This account does not have Permission to MOVE_OTHERS out of the channel that the Member is currently in.");
/** * Gets the connected voice channel for the given guild. * * @param guild The guild that the connected voice channel should be fetched for. * @return Possibly-null, The VoiceChannel that the bot is connected to. */ @Nullable public VoiceChannel getConnectedChannel(@Nonnull Guild guild) { return guild.getSelfMember().getVoiceState().getChannel(); }
private boolean canVoteSkip(CommandMessage message) { GuildVoiceState voiceState = message.getMember().getVoiceState(); GuildVoiceState selfVoteState = message.getGuild().getSelfMember().getVoiceState(); return voiceState.getChannel() != null && selfVoteState.getChannel() != null && voiceState.getChannel().getId().equals(selfVoteState.getChannel().getId()); } }
@SuppressWarnings("SimplifiableIfStatement") public boolean canPreformSpecialAction(@Nonnull Command command, @Nonnull CommandMessage context, @Nonnull String action) { if (context.getMember().hasPermission(Permission.ADMINISTRATOR)) { return true; } VoiceChannel channel = context.getMember().getVoiceState().getChannel(); if (channel == null) { return command.sendErrorMessage(context, "errors.mustBeConnectedToVoice"); } VoiceChannel selfChannel = context.getGuild().getSelfMember().getVoiceState().getChannel(); if (selfChannel == null || selfChannel.getIdLong() != channel.getIdLong()) { return command.sendErrorMessage(context, "errors.mustBeConnectedToSameChannel", action); } return true; }
private boolean isInVoiceWith(Guild guild, User author) { VoiceChannel channel = guild.getMember(author).getVoiceState().getChannel(); if (channel == null) { return false; } for (Member user : channel.getMembers()) { if (user.getUser().getId().equals(guild.getJDA().getSelfUser().getId())) { return true; } } return false; }
public boolean isInVoiceWith(Guild guild, User author) { VoiceChannel channel = guild.getMember(author).getVoiceState().getChannel(); if (channel == null) { return false; } for (Member user : channel.getMembers()) { if (user.getUser().getId().equals(guild.getJDA().getSelfUser().getId())) { return true; } } return false; }
private void cleanup(Guild guild, Player player, long id) { if (guild != null && guild.getSelfMember().getVoiceState() != null && guild.getSelfMember().getVoiceState().getChannel() != null && guild.getAudioManager().isConnected() && guild.getAudioManager().getConnectionStatus() == ConnectionStatus.CONNECTED && closedConnections.get() < WEBSOCKET_THRESHOLD) { // Cut off at threshold in-case we send too many guild.getAudioManager().closeAudioConnection(); closedConnections.incrementAndGet(); } FlareBot.instance().getMusicManager().deletePlayer(player); VC_LAST_USED.remove(id); }
/** * Check if a user meets the requirements to use the music commands * * @return bool */ public boolean canUseVoiceCommands(User user, SimpleRank rank) { Guild guild = user.getJDA().getGuildById(guildId); if (PermissionUtil.checkPermission(guild.getMember(user), Permission.ADMINISTRATOR)) { return true; } if (!GuildSettings.get(guild).canUseMusicCommands(user, rank)) { return false; } GuildVoiceState voiceStatus = guild.getMember(user).getVoiceState(); if (voiceStatus == null) { return false; } VoiceChannel userVoice = voiceStatus.getChannel(); if (userVoice == null) { return false; } if (guild.getAudioManager().getConnectedChannel() != null) { return guild.getAudioManager().getConnectedChannel().equals(userVoice); } return true; }
int listeners = (int)event.getSelfMember().getVoiceState().getChannel().getMembers().stream() .filter(m -> !m.getUser().isBot() && !m.getVoiceState().isDeafened()).count(); String msg; handler.getVotes().add(event.getAuthor().getId()); int skippers = (int)event.getSelfMember().getVoiceState().getChannel().getMembers().stream() .filter(m -> handler.getVotes().contains(m.getUser().getId())).count(); int required = (int)Math.ceil(listeners * .55);
@Override public void onGuildVoiceJoin(GuildVoiceJoinEvent event) { if (event.getMember().getUser().equals(event.getJDA().getSelfUser()) && flareBot.getMusicManager() .hasPlayer(event.getGuild().getId())) { flareBot.getMusicManager().getPlayer(event.getGuild().getId()).setPaused(false); } if (event.getMember().getUser().equals(event.getJDA().getSelfUser())) return; if (event.getGuild().getSelfMember().getVoiceState().getChannel() == null) return; if (VoteUtil.contains(SkipCommand.getSkipUUID(), event.getGuild()) && event.getGuild().getSelfMember().getVoiceState().inVoiceChannel() && event.getChannelJoined().getIdLong() == event.getGuild().getSelfMember().getVoiceState().getChannel().getIdLong()) { VoteUtil.getVoteGroup(SkipCommand.getSkipUUID(), event.getGuild()).addAllowedUser(event.getMember().getUser()); } }
@Override public String execute(DiscordBot bot, String[] args, MessageChannel channel, User author, Message inputMessage) { Guild guild = ((TextChannel) channel).getGuild(); SimpleRank userRank = bot.security.getSimpleRank(author, channel); if (!GuildSettings.get(guild).canUseMusicCommands(author, userRank)) { return Templates.music.required_role_not_found.formatGuild(channel, guild.getRoleById(GuildSettings.getFor(channel, GSetting.MUSIC_ROLE_REQUIREMENT))); } MusicPlayerHandler player = MusicPlayerHandler.getFor(guild, bot); if (!player.canTogglePause()) { return Templates.music.state_not_started.formatGuild(channel); } VoiceChannel userVoice = guild.getMember(author).getVoiceState().getChannel(); if (userVoice == null || !player.isConnectedTo(userVoice)) { return Templates.music.not_same_voicechannel.formatGuild(channel); } if (player.togglePause()) { return Templates.music.state_paused.formatGuild(channel); } return Templates.music.state_resumed.formatGuild(channel); } }
private boolean kickUser(CommandMessage context, Member user, String[] args) { String reason = generateMessage(args); String originalVoiceChannelName = user.getVoiceState().getChannel().getName(); String originalVoiceChannelId = user.getVoiceState().getChannel().getId(); context.getGuild().getController().createVoiceChannel("kick-" + user.getUser().getId()).queue(channel -> context.getGuild().getController().moveVoiceMember(user, (VoiceChannel) channel) .queue(empty -> channel.delete().queue((Consumer<Void>) aVoid -> { Modlog.log(avaire, context, new ModlogAction( ModlogType.VOICE_KICK, context.getAuthor(), user.getUser(), originalVoiceChannelName + " (ID: " + originalVoiceChannelId + ")\n" + reason ) ); context.makeSuccess(context.i18n("message")) .set("target", user.getUser().getName() + "#" + user.getUser().getDiscriminator()) .set("voiceChannel", originalVoiceChannelName) .set("reason", reason) .queue(ignoreMessage -> context.delete().queue(null, RestActionUtil.ignore)); }, RestActionUtil.ignore) ) ); return true; }
@Override public void run(Context context) { GuildAudioController musicManager = this.bot.getGuildsManager().getOrCreate(context.getEvent().getGuild(), context.getEvent().getTextChannel(), playerManager); if (context.getArgs().length == 0) { context.reply("Usage: {{prefix}}a decode <base64 string>"); return; } VoiceChannel channel = context.getEvent().getMember().getVoiceState().getChannel(); if (channel == null) { context.reply("Must be in a voice channel!"); return; } String base64 = context.getArgs()[0]; AudioTrack track; try { track = Utils.decode(playerManager, base64); } catch (IOException e) { logger.error("error performing decode command", e); context.reply("An error occurred!"); return; } if (!musicManager.getState().isConnectionOpen()) { musicManager.getConnector().openConnection(channel, context.getEvent().getAuthor()); } musicManager.getPlayer().playTrack(track); } }
@Override public void onGuildVoiceLeave(GuildVoiceLeaveEvent event) { if (event.getMember().getUser().getIdLong() == event.getJDA().getSelfUser().getIdLong()) { if (flareBot.getMusicManager().hasPlayer(event.getGuild().getId())) { flareBot.getMusicManager().getPlayer(event.getGuild().getId()).setPaused(true); } if (Getters.getActiveVoiceChannels() == 0 && FlareBot.NOVOICE_UPDATING.get()) { Constants.getImportantLogChannel() .sendMessage("I am now updating, there are no voice channels active!").queue(); UpdateCommand.update(true, null); } } else { handleVoiceConnectivity(event.getChannelLeft()); } if (event.getMember().getUser().equals(event.getJDA().getSelfUser())) return; if (VoteUtil.contains(SkipCommand.getSkipUUID(), event.getGuild()) && event.getChannelLeft().getIdLong() == event.getGuild().getSelfMember().getVoiceState().getChannel().getIdLong()) { VoteUtil.getVoteGroup(SkipCommand.getSkipUUID(), event.getGuild()).remoreAllowedUser(event.getMember().getUser()); } }
AudioTrack track = audioPlayer.getPlayingTrack(); MessageBuilder mb = new MessageBuilder(); mb.append(FormatUtil.filter(manager.getBot().getConfig().getSuccess()+" **Now Playing in "+guild.getSelfMember().getVoiceState().getChannel().getName()+"...**")); EmbedBuilder eb = new EmbedBuilder(); eb.setColor(guild.getSelfMember().getColor());
VoiceChannel channel = context.getMember().getVoiceState().getChannel(); if (channel == null) { return sendErrorMessage(context, "errors.mustBeConnectedToVoice");