use of me.shadorc.shadbot.music.GuildMusic in project Shadbot by Shadorc.
the class NameCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException {
GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(context.getGuild().getLongID());
if (guildMusic == null || guildMusic.getScheduler().isStopped()) {
BotUtils.sendMessage(TextUtils.NO_PLAYING_MUSIC, context.getChannel());
return;
}
BotUtils.sendMessage(String.format(Emoji.MUSICAL_NOTE + " Currently playing: **%s**", FormatUtils.formatTrackName(guildMusic.getScheduler().getAudioPlayer().getPlayingTrack().getInfo())), context.getChannel());
}
use of me.shadorc.shadbot.music.GuildMusic 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);
}
use of me.shadorc.shadbot.music.GuildMusic in project Shadbot by Shadorc.
the class RepeatCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException {
GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(context.getGuild().getLongID());
if (guildMusic == null || guildMusic.getScheduler().isStopped()) {
BotUtils.sendMessage(TextUtils.NO_PLAYING_MUSIC, context.getChannel());
return;
}
RepeatMode mode = Utils.getValueOrNull(RepeatMode.class, context.getArg());
if (context.hasArg() && !RepeatMode.PLAYLIST.equals(mode)) {
throw new MissingArgumentException();
}
// By default, modification are made on song repeat mode
if (mode == null) {
mode = RepeatMode.SONG;
}
TrackScheduler scheduler = guildMusic.getScheduler();
scheduler.setRepeatMode(scheduler.getRepeatMode().equals(mode) ? RepeatMode.NONE : mode);
BotUtils.sendMessage(String.format("%s %sRepetition %s", scheduler.getRepeatMode().equals(RepeatMode.NONE) ? Emoji.PLAY : Emoji.REPEAT, RepeatMode.PLAYLIST.equals(mode) ? "Playlist " : "", scheduler.getRepeatMode().equals(RepeatMode.NONE) ? "disabled" : "enabled"), context.getChannel());
}
use of me.shadorc.shadbot.music.GuildMusic in project Shadbot by Shadorc.
the class ShuffleCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException {
GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(context.getGuild().getLongID());
if (guildMusic == null || guildMusic.getScheduler().isStopped()) {
BotUtils.sendMessage(TextUtils.NO_PLAYING_MUSIC, context.getChannel());
return;
}
guildMusic.getScheduler().shufflePlaylist();
BotUtils.sendMessage(Emoji.CHECK_MARK + " Playlist shuffled.", context.getChannel());
}
use of me.shadorc.shadbot.music.GuildMusic in project Shadbot by Shadorc.
the class SkipCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(context.getGuild().getLongID());
if (guildMusic == null || guildMusic.getScheduler().isStopped()) {
BotUtils.sendMessage(TextUtils.NO_PLAYING_MUSIC, context.getChannel());
return;
}
if (context.hasArg()) {
Integer num = CastUtils.asIntBetween(context.getArg(), 1, guildMusic.getScheduler().getPlaylist().size());
if (num == null) {
throw new IllegalCmdArgumentException(String.format("Number must be between 1 and %d.", guildMusic.getScheduler().getPlaylist().size()));
}
guildMusic.getScheduler().skipTo(num);
return;
}
if (guildMusic.getScheduler().nextTrack()) {
// If the music has been started correctly, we resume it in case the previous music was on pause
guildMusic.getScheduler().getAudioPlayer().setPaused(false);
} else {
guildMusic.end();
}
}
Aggregations