use of ml.duncte123.skybot.audio.GuildMusicManager in project SkyBot by duncte123.
the class BotListener method channelCheckThing.
/**
* This handles the guild leave/ join events to deferments if the channel is empty
*
* @param g the guild
* @param vc the voice channel
*/
private void channelCheckThing(Guild g, VoiceChannel vc) {
if (vc.getMembers().stream().filter(m -> !m.getUser().isBot()).count() < 1) {
GuildMusicManager manager = AudioUtils.ins.getMusicManager(g);
manager.player.stopTrack();
manager.player.setPaused(false);
manager.scheduler.queue.clear();
MusicCommand.cooldowns.put(g.getIdLong(), 12600);
if (g.getAudioManager().getConnectionListener() != null)
g.getAudioManager().setConnectionListener(null);
MessageUtils.sendMsg(manager.latestChannel, "Leaving voice channel because all the members have left it.");
if (LavalinkManager.ins.isConnected(g)) {
LavalinkManager.ins.closeConnection(g);
AudioUtils.ins.getMusicManagers().remove(g.getId());
}
}
}
use of ml.duncte123.skybot.audio.GuildMusicManager in project SkyBot by duncte123.
the class AudioUtils method loadAndPlay.
/**
* Loads a track and plays it if the bot isn't playing
*
* @param mng The {@link GuildMusicManager MusicManager} for the guild
* @param channel The {@link net.dv8tion.jda.core.entities.MessageChannel channel} that the bot needs to send the messages to
* @param trackUrlRaw The url from the track to play
* @param addPlayList If the url is a playlist
*/
public void loadAndPlay(GuildMusicManager mng, final TextChannel channel, final String trackUrlRaw, final boolean addPlayList) {
final String trackUrl;
// Strip <>'s that prevent discord from embedding link resources
if (trackUrlRaw.startsWith("<") && trackUrlRaw.endsWith(">")) {
trackUrl = trackUrlRaw.substring(1, trackUrlRaw.length() - 1);
} else {
trackUrl = trackUrlRaw;
}
playerManager.loadItemOrdered(mng, trackUrl, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
String title = track.getInfo().title;
if (track.getInfo().isStream) {
Optional<RadioStream> stream = ((RadioCommand) AirUtils.COMMAND_MANAGER.getCommand("radio")).getRadioStreams().stream().filter(s -> s.getUrl().equals(track.getInfo().uri)).findFirst();
if (stream.isPresent())
title = stream.get().getName();
}
String msg = "Adding to queue: " + title;
if (mng.player.getPlayingTrack() == null) {
msg += "\nand the Player has started playing;";
}
mng.scheduler.queue(track);
MessageUtils.sendEmbed(channel, EmbedUtils.embedField(embedTitle, msg));
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
AudioTrack firstTrack = playlist.getSelectedTrack();
List<AudioTrack> tracks = playlist.getTracks();
if (tracks.size() == 0) {
MessageUtils.sendEmbed(channel, EmbedUtils.embedField(embedTitle, "Error: This playlist is empty."));
return;
} else if (firstTrack == null) {
firstTrack = playlist.getTracks().get(0);
}
String msg;
if (addPlayList) {
msg = "Adding **" + playlist.getTracks().size() + "** tracks to queue from playlist: " + playlist.getName();
if (mng.player.getPlayingTrack() == null) {
msg += "\nand the Player has started playing;";
}
tracks.forEach(mng.scheduler::queue);
} else {
msg = "Adding to queue " + firstTrack.getInfo().title + " (first track of playlist " + playlist.getName() + ")";
if (mng.player.getPlayingTrack() == null) {
msg += "\nand the Player has started playing;";
}
mng.scheduler.queue(firstTrack);
}
MessageUtils.sendEmbed(channel, EmbedUtils.embedField(embedTitle, msg));
}
@Override
public void noMatches() {
MessageUtils.sendEmbed(channel, EmbedUtils.embedField(embedTitle, "Nothing found by _" + trackUrl + "_"));
}
@Override
public void loadFailed(FriendlyException exception) {
MessageUtils.sendEmbed(channel, EmbedUtils.embedField(embedTitle, "Could not play: " + exception.getMessage() + "\nIf this happens often try another link or join our [support guild](https://discord.gg/NKM9Xtk) for more!"));
}
});
}
use of ml.duncte123.skybot.audio.GuildMusicManager in project SkyBot by duncte123.
the class AudioUtils method getMusicManager.
/**
* This will get the music manager for the guild or register it if we don't have it yet
*
* @param guild The guild that we need the manager for
* @return The music manager for that guild
*/
public GuildMusicManager getMusicManager(Guild guild) {
String guildId = guild.getId();
GuildMusicManager mng = musicManagers.get(guildId);
if (mng == null) {
synchronized (musicManagers) {
mng = musicManagers.get(guildId);
if (mng == null) {
mng = new GuildMusicManager(guild);
mng.player.setVolume(DEFAULT_VOLUME);
musicManagers.put(guildId, mng);
}
}
}
guild.getAudioManager().setSendingHandler(mng.getSendHandler());
return mng;
}
Aggregations