use of stream.flarebot.flarebot.util.votes.VoteGroup 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);
}
}
Aggregations