use of me.shadorc.shadbot.listener.music.AudioLoadResultListener in project Shadbot by Shadorc.
the class PlayCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
if (!context.hasArg()) {
throw new MissingArgumentException();
}
IVoiceChannel botVoiceChannel = context.getClient().getOurUser().getVoiceStateForGuild(context.getGuild()).getChannel();
IVoiceChannel userVoiceChannel = context.getAuthor().getVoiceStateForGuild(context.getGuild()).getChannel();
if (botVoiceChannel != null && !botVoiceChannel.equals(userVoiceChannel)) {
throw new IllegalCmdArgumentException(String.format("I'm currently playing music in voice channel %s" + ", join me before using this command.", botVoiceChannel.mention()));
}
if (userVoiceChannel == null) {
throw new IllegalCmdArgumentException("Join a voice channel before using this command.");
}
if (botVoiceChannel == null && !BotUtils.hasPermissions(userVoiceChannel, Permissions.VOICE_CONNECT, Permissions.VOICE_SPEAK)) {
BotUtils.sendMessage(TextUtils.missingPerm(Permissions.VOICE_CONNECT, Permissions.VOICE_SPEAK), context.getChannel());
LogUtils.infof("{Guild ID: %d} Shadbot wasn't allowed to connect/speak in a voice channel.", context.getGuild().getLongID());
return;
}
String identifier;
if (context.getArg().startsWith("soundcloud ")) {
identifier = AudioLoadResultListener.SC_SEARCH + StringUtils.remove(context.getArg(), "soundcloud ");
} else if (NetUtils.isValidURL(context.getArg())) {
identifier = context.getArg();
} else {
identifier = AudioLoadResultListener.YT_SEARCH + context.getArg();
}
GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(context.getGuild().getLongID());
if (guildMusic != null && guildMusic.isWaiting()) {
if (guildMusic.getDj().equals(context.getAuthor())) {
throw new IllegalCmdArgumentException(String.format("(**%s**) You're already selecting a music. " + "Enter a number or use `%scancel` to cancel the selection.", context.getAuthorName(), context.getPrefix()));
}
if (identifier.startsWith(AudioLoadResultListener.SC_SEARCH) || identifier.startsWith(AudioLoadResultListener.YT_SEARCH)) {
BotUtils.sendMessage(String.format(Emoji.HOURGLASS + " **%s** is already selecting a music, please wait for him to finish.", guildMusic.getDj().getName()), context.getChannel());
return;
}
}
if (guildMusic == null) {
guildMusic = GuildMusicManager.createGuildMusic(context.getGuild());
}
if (guildMusic.getScheduler().getPlaylist().size() >= Config.MAX_PLAYLIST_SIZE - 1 && !PremiumManager.isPremium(context.getGuild(), context.getAuthor())) {
BotUtils.sendMessage(TextUtils.PLAYLIST_LIMIT_REACHED, context.getChannel());
return;
}
guildMusic.setChannel(context.getChannel());
AudioLoadResultListener resultListener = new AudioLoadResultListener(guildMusic, context.getAuthor(), userVoiceChannel, identifier, context.getCommandName().endsWith("first"));
GuildMusicManager.PLAYER_MANAGER.loadItemOrdered(guildMusic, identifier, resultListener);
}
Aggregations