use of com.arsenarsen.lavaplayerbridge.PlayerManager in project FlareBot by FlareBot.
the class GuildUtils method joinChannel.
/**
* Joins the bot to a {@link TextChannel}.
*
* @param channel The chanel to send an error message to in case this fails.
* @param member The member requesting the join. This is also how we determine what channel to join.
*/
public static void joinChannel(TextChannel channel, Member member) {
if (channel.getGuild().getSelfMember().hasPermission(member.getVoiceState().getChannel(), Permission.VOICE_CONNECT) && channel.getGuild().getSelfMember().hasPermission(member.getVoiceState().getChannel(), Permission.VOICE_SPEAK)) {
if (member.getVoiceState().getChannel().getUserLimit() > 0 && member.getVoiceState().getChannel().getMembers().size() >= member.getVoiceState().getChannel().getUserLimit() && !member.getGuild().getSelfMember().hasPermission(member.getVoiceState().getChannel(), Permission.MANAGE_CHANNEL)) {
MessageUtils.sendErrorMessage("We can't join :(\n\nThe channel user limit has been reached and we don't have the 'Manage Channel' permission to " + "bypass it!", channel);
return;
}
PlayerManager musicManager = FlareBot.instance().getMusicManager();
channel.getGuild().getAudioManager().openAudioConnection(member.getVoiceState().getChannel());
musicManager.getPlayer(channel.getGuild().getId()).play();
if (musicManager.getPlayer(channel.getGuild().getId()).getPaused()) {
MessageUtils.sendWarningMessage("The music is currently paused do `{%}resume`", channel);
}
} else {
MessageUtils.sendErrorMessage("I do not have permission to " + (!channel.getGuild().getSelfMember().hasPermission(member.getVoiceState().getChannel(), Permission.VOICE_CONNECT) ? "connect" : "speak") + " in your voice channel!", channel);
}
}
use of com.arsenarsen.lavaplayerbridge.PlayerManager in project FlareBot by FlareBot.
the class QueueCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
PlayerManager manager = FlareBot.instance().getMusicManager();
if (message.getContentRaw().substring(1).startsWith("playlist")) {
MessageUtils.sendWarningMessage("This command is deprecated! Please use `{%}queue` instead!", channel);
}
if (args.length < 1 || args.length > 2) {
send(channel, member);
} else {
if (args.length == 1) {
if (args[0].equalsIgnoreCase("clear")) {
if (!this.getPermissions(channel).hasPermission(member, Permission.QUEUE_CLEAR)) {
MessageUtils.sendErrorMessage("You need the `" + Permission.QUEUE_CLEAR + "` permission to do this!", channel, sender);
return;
}
manager.getPlayer(channel.getGuild().getId()).getPlaylist().clear();
channel.sendMessage("Cleared the current playlist!").queue();
} else if (args[0].equalsIgnoreCase("remove")) {
MessageUtils.sendUsage(this, channel, sender, args);
} else if (args[0].equalsIgnoreCase("here")) {
send(channel, member);
} else {
MessageUtils.sendUsage(this, channel, sender, args);
}
} else {
if (args[0].equalsIgnoreCase("remove")) {
int number;
try {
number = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
MessageUtils.sendErrorMessage("That is an invalid number!", channel);
return;
}
Queue<Track> queue = manager.getPlayer(channel.getGuild().getId()).getPlaylist();
if (number < 1 || number > queue.size()) {
MessageUtils.sendErrorMessage("There is no song with that index. Make sure your number is at least 1 and either " + queue.size() + " or below!", channel);
return;
}
List<Track> playlist = new ArrayList<>(queue);
playlist.remove(number - 1);
queue.clear();
queue.addAll(playlist);
channel.sendMessage(MessageUtils.getEmbed(sender).setDescription("Removed number " + number + " from the playlist!").build()).queue();
}
}
}
}
use of com.arsenarsen.lavaplayerbridge.PlayerManager in project FlareBot by FlareBot.
the class SkipCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
boolean songMessage = message.getAuthor().getIdLong() == Getters.getSelfUser().getIdLong();
PlayerManager musicManager = FlareBot.instance().getMusicManager();
if (!channel.getGuild().getAudioManager().isConnected() || musicManager.getPlayer(channel.getGuild().getId()).getPlayingTrack() == null) {
channel.sendMessage("I am not playing anything!").queue();
return;
}
if (member.getVoiceState().inVoiceChannel() && !channel.getGuild().getSelfMember().getVoiceState().getChannel().getId().equals(member.getVoiceState().getChannel().getId()) && !getPermissions(channel).hasPermission(member, Permission.SKIP_FORCE)) {
channel.sendMessage("You must be in the channel in order to skip songs!").queue();
return;
}
Track currentTrack = musicManager.getPlayer(guild.getGuildId()).getPlayingTrack();
if (args.length == 0 && currentTrack.getMeta().get("requester").equals(sender.getId())) {
channel.sendMessage("Skipped your own song!").queue();
musicManager.getPlayer(guild.getGuildId()).skip();
if (songMessage)
SongCommand.updateSongMessage(sender, message, channel);
return;
}
if (args.length != 1) {
if (!channel.getGuild().getMember(sender).getVoiceState().inVoiceChannel() || channel.getGuild().getMember(sender).getVoiceState().getChannel().getIdLong() != channel.getGuild().getSelfMember().getVoiceState().getChannel().getIdLong()) {
MessageUtils.sendErrorMessage("You cannot skip if you aren't listening to it!", channel);
return;
}
if (VoteUtil.contains(skipUUID, guild.getGuild()))
MessageUtils.sendWarningMessage("There is already a vote to skip current song! Vote with `{%}skip yes | no`", channel, sender);
else {
VoteGroup group = new VoteGroup("Skip current song", skipUUID);
List<User> users = new ArrayList<>();
for (Member inChannelMember : channel.getGuild().getSelfMember().getVoiceState().getChannel().getMembers()) {
if (channel.getGuild().getSelfMember().getUser().getIdLong() != inChannelMember.getUser().getIdLong()) {
users.add(inChannelMember.getUser());
}
}
group.limitUsers(users);
VoteUtil.sendVoteMessage(skipUUID, (vote) -> {
if (vote.equals(VoteGroup.Vote.NONE) || vote.equals(VoteGroup.Vote.NO)) {
MessageUtils.sendMessage("Results are in: Keep!", channel);
} else {
MessageUtils.sendMessage("Skipping!", channel);
if (songMessage)
SongCommand.updateSongMessage(sender, message, channel);
musicManager.getPlayer(guild.getGuildId()).skip();
}
}, group, TimeUnit.MINUTES.toMillis(1), channel, sender, ButtonGroupConstants.VOTE_SKIP, new ButtonGroup.Button("\u23ED", (owner, user, message1) -> {
if (getPermissions(channel).hasPermission(channel.getGuild().getMember(user), Permission.SKIP_FORCE)) {
musicManager.getPlayer(channel.getGuild().getId()).skip();
if (songMessage) {
SongCommand.updateSongMessage(user, message1, channel);
}
musicManager.getPlayer(guild.getGuildId()).skip();
VoteUtil.remove(skipUUID, guild.getGuild());
} else {
channel.sendMessage("You are missing the permission `" + Permission.SKIP_FORCE + "` which is required for use of this button!").queue();
}
}));
}
} else {
if (args[0].equalsIgnoreCase("force")) {
if (getPermissions(channel).hasPermission(member, Permission.SKIP_FORCE)) {
if (songMessage)
SongCommand.updateSongMessage(sender, message, channel);
VoteUtil.remove(skipUUID, guild.getGuild());
musicManager.getPlayer(guild.getGuildId()).skip();
} else {
channel.sendMessage("You are missing the permission `" + Permission.SKIP_FORCE + "` which is required for use of this command!").queue();
}
return;
} else if (args[0].equalsIgnoreCase("cancel")) {
if (getPermissions(channel).hasPermission(member, Permission.SKIP_CANCEL)) {
VoteUtil.remove(skipUUID, channel.getGuild());
} else
channel.sendMessage("You are missing the permission `" + Permission.SKIP_CANCEL + "` which is required for use of this command!").queue();
return;
}
if (!channel.getGuild().getMember(sender).getVoiceState().inVoiceChannel() || channel.getGuild().getMember(sender).getVoiceState().getChannel().getIdLong() != channel.getGuild().getSelfMember().getVoiceState().getChannel().getIdLong()) {
MessageUtils.sendWarningMessage("You cannot vote to skip if you aren't listening to it!", channel);
return;
}
VoteGroup.Vote vote = VoteGroup.Vote.parseVote(args[0]);
if (vote != null) {
if (!VoteUtil.contains(skipUUID, guild.getGuild()))
MessageUtils.sendWarningMessage("Their is no vote currently running!", channel, sender);
else
VoteUtil.getVoteGroup(skipUUID, guild.getGuild()).addVote(vote, sender);
} else
MessageUtils.sendUsage(this, channel, sender, args);
}
}
use of com.arsenarsen.lavaplayerbridge.PlayerManager in project FlareBot by FlareBot.
the class SongCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
PlayerManager manager = FlareBot.instance().getMusicManager();
if (manager.getPlayer(channel.getGuild().getId()).getPlayingTrack() != null) {
Track track = manager.getPlayer(channel.getGuild().getId()).getPlayingTrack();
EmbedBuilder eb = MessageUtils.getEmbed(sender).addField("Current Song", getLink(track), false).setThumbnail("https://img.youtube.com/vi/" + track.getTrack().getIdentifier() + "/hqdefault.jpg");
if (track.getTrack().getInfo().isStream)
eb.addField("Amount Played", "Issa livestream ;)", false);
else
eb.addField("Amount Played", GeneralUtils.getProgressBar(track), true).addField("Time", String.format("%s / %s", FormatUtils.formatDuration(track.getTrack().getPosition()), FormatUtils.formatDuration(track.getTrack().getDuration())), false);
ButtonGroup buttonGroup = new ButtonGroup(sender.getIdLong(), ButtonGroupConstants.SONG);
buttonGroup.addButton(new ButtonGroup.Button("\u23EF", (owner, user, message1) -> {
if (manager.hasPlayer(guild.getGuildId())) {
if (manager.getPlayer(guild.getGuild().getId()).getPaused()) {
if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.RESUME_COMMAND)) {
manager.getPlayer(guild.getGuild().getId()).play();
}
} else {
if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.PAUSE_COMMAND)) {
manager.getPlayer(guild.getGuild().getId()).setPaused(true);
}
}
}
}));
buttonGroup.addButton(new ButtonGroup.Button("\u23F9", (owner, user, message1) -> {
if (manager.hasPlayer(guild.getGuildId()) && getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.STOP_COMMAND)) {
manager.getPlayer(guild.getGuildId()).stop();
}
}));
buttonGroup.addButton(new ButtonGroup.Button("\u23ED", (owner, user, message1) -> {
if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.SKIP_COMMAND)) {
Command cmd = FlareBot.getCommandManager().getCommand("skip", user);
if (cmd != null)
cmd.onCommand(user, guild, channel, message1, new String[0], guild.getGuild().getMember(user));
}
}));
buttonGroup.addButton(new ButtonGroup.Button("\uD83D\uDD01", (ownerID, user, message1) -> {
updateSongMessage(user, message1, message1.getTextChannel());
}));
ButtonUtil.sendButtonedMessage(channel, eb.build(), buttonGroup);
} else {
channel.sendMessage(MessageUtils.getEmbed(sender).addField("Current song", "**No song playing right now!**", false).build()).queue();
}
}
use of com.arsenarsen.lavaplayerbridge.PlayerManager in project FlareBot by FlareBot.
the class QueueCommand method send.
private void send(TextChannel channel, Member sender) {
PlayerManager manager = FlareBot.instance().getMusicManager();
Track currentTrack = manager.getPlayer(channel.getGuild().getId()).getPlayingTrack();
if (!manager.getPlayer(channel.getGuild().getId()).getPlaylist().isEmpty() || currentTrack != null) {
List<String> songs = new ArrayList<>();
songs.add("Current Song: " + String.format("[`%s`](%s) | Requested by <@!%s>\n", currentTrack.getTrack().getInfo().title, YouTubeExtractor.WATCH_URL + currentTrack.getTrack().getIdentifier(), currentTrack.getMeta().get("requester")));
AtomicInteger i = new AtomicInteger(1);
manager.getPlayer(channel.getGuild().getId()).getPlaylist().forEach(track -> songs.add(String.format("%s. [`%s`](%s) | Requested by <@!%s>\n", i.getAndIncrement(), track.getTrack().getInfo().title, YouTubeExtractor.WATCH_URL + track.getTrack().getIdentifier(), track.getMeta().get("requester"))));
PagedEmbedBuilder pe = new PagedEmbedBuilder<>(PaginationUtil.splitStringToList(songs.stream().collect(Collectors.joining("\n")) + "\n", PaginationUtil.SplitMethod.NEW_LINES, 21)).setTitle("Queued Songs");
PaginationUtil.sendEmbedPagedMessage(pe.build(), 0, channel, sender.getUser(), ButtonGroupConstants.QUEUE);
} else {
MessageUtils.sendErrorMessage(MessageUtils.getEmbed().setDescription("No songs in the playlist!"), channel);
}
}
Aggregations