use of net.dv8tion.jda.core.entities.VoiceChannel in project TheLighterBot by PhotonBursted.
the class UnpermanentChannelCommand method execute.
@Override
protected void execute() {
if (!ev.getMember().getVoiceState().inVoiceChannel()) {
handleError(MessageContent.NOT_IN_VOICE_CHANNEL);
}
VoiceChannel vc = ev.getMember().getVoiceState().getChannel();
if (!l.getChannelController().isPermanent(vc)) {
handleError(MessageContent.CHANNEL_NOT_PERMANENT);
}
l.getChannelController().getPermChannels().removeByValueStoring(vc);
LoggerUtils.logAndDelete(log, String.format("%s has been made temporary.", vc.getName()));
l.getDiscordController().sendMessage(ev, String.format("Successfully made **%s** temporary!%s", vc.getName(), l.getChannelController().isLinked(vc) ? "\n__Be aware that leaving the channel empty will now delete the channel!__" : ""), DiscordController.AUTOMATIC_REMOVAL_INTERVAL);
l.getFileController().applyPermDeletion(ev.getChannel(), vc);
}
use of net.dv8tion.jda.core.entities.VoiceChannel in project MantaroBot by Mantaro.
the class AudioCmdUtils method embedForQueue.
public static void embedForQueue(int page, GuildMessageReceivedEvent event, GuildMusicManager musicManager) {
String toSend = AudioUtils.getQueueList(musicManager.getTrackScheduler().getQueue());
Guild guild = event.getGuild();
String nowPlaying = musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack() != null ? "**[" + musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().title + "](" + musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().uri + ")** (" + Utils.getDurationMinutes(musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().length) + ")" : "Nothing or title/duration not found";
if (toSend.isEmpty()) {
event.getChannel().sendMessage(new EmbedBuilder().setAuthor("Queue for server " + guild.getName(), null, guild.getIconUrl()).setColor(Color.CYAN).setDescription("Nothing here, just dust. Why don't you queue some songs?\n" + "If you think there are songs here but they don't appear, try using `~>queue 1`.\n\n" + "**If there is a song playing and you didn't add more songs, then there is actually just dust here. You can queue more songs as you desire!**").addField("Currently playing", nowPlaying, false).setThumbnail("http://www.clipartbest.com/cliparts/jix/6zx/jix6zx4dT.png").build()).queue();
return;
}
String[] lines = NEWLINE_PATTERN.split(toSend);
if (!guild.getSelfMember().hasPermission(event.getChannel(), Permission.MESSAGE_ADD_REACTION)) {
String line = null;
StringBuilder sb = new StringBuilder();
int total;
{
int t = 0;
int c = 0;
for (String s : lines) {
if (s.length() + c + 1 > MessageEmbed.TEXT_MAX_LENGTH) {
t++;
c = 0;
}
c += s.length() + 1;
}
if (c > 0)
t++;
total = t;
}
int current = 0;
for (String s : lines) {
int l = s.length() + 1;
if (l > MessageEmbed.TEXT_MAX_LENGTH)
throw new IllegalArgumentException("Length for one of the pages is greater than the maximum");
if (sb.length() + l > MessageEmbed.TEXT_MAX_LENGTH) {
current++;
if (current == page) {
line = sb.toString();
break;
}
sb = new StringBuilder();
}
sb.append(s).append('\n');
}
if (sb.length() > 0 && current + 1 == page) {
line = sb.toString();
}
if (line == null || page > total) {
event.getChannel().sendMessage(new EmbedBuilder().setAuthor("Queue for server " + guild.getName(), null, guild.getIconUrl()).setColor(Color.CYAN).setDescription("Nothing here, just dust. Why don't you go back some pages?\n" + "If you think there are songs here but they don't appear, try using `~>queue 1`.").addField("Currently playing", nowPlaying, false).setThumbnail("http://www.clipartbest.com/cliparts/jix/6zx/jix6zx4dT.png").build()).queue();
} else {
long length = musicManager.getTrackScheduler().getQueue().stream().mapToLong(value -> value.getInfo().length).sum();
EmbedBuilder builder = new EmbedBuilder().setAuthor("Queue for server " + guild.getName(), null, guild.getIconUrl()).setColor(Color.CYAN);
VoiceChannel vch = guild.getSelfMember().getVoiceState().getChannel();
builder.addField("Currently playing", nowPlaying, false).setThumbnail("http://www.clipartbest.com/cliparts/jix/6zx/jix6zx4dT.png").addField("Total queue time", "`" + Utils.getReadableTime(length) + "`", true).addField("Total queue size", "`" + musicManager.getTrackScheduler().getQueue().size() + " songs`", true).addField("Repeat / Pause", "`" + (musicManager.getTrackScheduler().getRepeatMode() == null ? "false" : musicManager.getTrackScheduler().getRepeatMode()) + " / " + String.valueOf(musicManager.getTrackScheduler().getAudioPlayer().isPaused()) + "`", true).addField("Playing in", vch == null ? "No channel :<" : "`" + vch.getName() + "`", true).setFooter("Total pages: " + total + (total == 1 ? "" : " -> Use ~>queue <page> to change pages") + ". Currently in page " + page, guild.getIconUrl());
event.getChannel().sendMessage(builder.setDescription(line).build()).queue();
}
return;
}
DiscordUtils.list(event, 30, false, (p, total) -> {
long length = musicManager.getTrackScheduler().getQueue().stream().mapToLong(value -> value.getInfo().length).sum();
EmbedBuilder builder = new EmbedBuilder().setAuthor("Queue for server " + guild.getName(), null, guild.getIconUrl()).setColor(Color.CYAN);
VoiceChannel vch = guild.getSelfMember().getVoiceState().getChannel();
builder.addField("Currently playing", nowPlaying, false).setThumbnail("http://www.clipartbest.com/cliparts/jix/6zx/jix6zx4dT.png").addField("Total queue time", "`" + Utils.getReadableTime(length) + "`", true).addField("Total queue size", "`" + musicManager.getTrackScheduler().getQueue().size() + " songs`", true).addField("Repeat / Pause", "`" + (musicManager.getTrackScheduler().getRepeatMode() == null ? "false" : musicManager.getTrackScheduler().getRepeatMode()) + " / " + String.valueOf(musicManager.getTrackScheduler().getAudioPlayer().isPaused()) + "`", true).addField("Playing in", vch == null ? "No channel :<" : "`" + vch.getName() + "`", true).setFooter("Total pages: " + total + (total == 1 ? "" : " -> React to change pages") + ". Currently in page " + p, guild.getIconUrl());
return builder;
}, lines);
}
use of net.dv8tion.jda.core.entities.VoiceChannel in project MantaroBot by Mantaro.
the class AudioCmdUtils method connectToVoiceChannel.
public static boolean connectToVoiceChannel(GuildMessageReceivedEvent event) {
VoiceChannel userChannel = event.getMember().getVoiceState().getChannel();
if (userChannel == null) {
event.getChannel().sendMessage("\u274C **Please join a voice channel!**").queue();
return false;
}
if (!event.getGuild().getSelfMember().hasPermission(userChannel, Permission.VOICE_CONNECT)) {
event.getChannel().sendMessage(":heavy_multiplication_x: I cannot connect to this channel due to the lack of permission.").queue();
return false;
}
if (!event.getGuild().getSelfMember().hasPermission(userChannel, Permission.VOICE_SPEAK)) {
event.getChannel().sendMessage(":heavy_multiplication_x: I cannot speak in this channel due to the lack of permission.").queue();
return false;
}
VoiceChannel guildMusicChannel = null;
if (MantaroData.db().getGuild(event.getGuild()).getData().getMusicChannel() != null) {
guildMusicChannel = event.getGuild().getVoiceChannelById(MantaroData.db().getGuild(event.getGuild()).getData().getMusicChannel());
}
AudioManager audioManager = event.getGuild().getAudioManager();
if (guildMusicChannel != null) {
if (!userChannel.equals(guildMusicChannel)) {
event.getChannel().sendMessage(EmoteReference.ERROR + "I can only play music on channel **" + guildMusicChannel.getName() + "**!").queue();
return false;
}
if (!audioManager.isConnected() && !audioManager.isAttemptingToConnect()) {
audioManager.openAudioConnection(userChannel);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Connected to channel **" + userChannel.getName() + "**!").queue();
}
return true;
}
if (audioManager.isConnected() && !audioManager.getConnectedChannel().equals(userChannel)) {
event.getChannel().sendMessage(String.format(EmoteReference.WARNING + "I'm already connected on channel **%s**! (Use the `move` command to move me to another channel)", audioManager.getConnectedChannel().getName())).queue();
return false;
}
if (audioManager.isAttemptingToConnect() && !audioManager.getQueuedAudioConnection().equals(userChannel)) {
event.getChannel().sendMessage(String.format(EmoteReference.ERROR + "I'm already trying to connect to channel **%s**! (Use the `move` command to move me to another channel)", audioManager.getQueuedAudioConnection().getName())).queue();
return false;
}
if (!audioManager.isConnected() && !audioManager.isAttemptingToConnect()) {
openAudioConnection(event, audioManager, userChannel);
}
return true;
}
use of net.dv8tion.jda.core.entities.VoiceChannel in project MantaroBot by Mantaro.
the class ShardedMantaro method startPostLoadProcedure.
private void startPostLoadProcedure(long start) {
long end = System.currentTimeMillis();
MantaroBot bot = MantaroBot.getInstance();
// Start the reconnect queue.
bot.getCore().markAsReady();
System.out.println("[-=-=-=-=-=- MANTARO STARTED -=-=-=-=-=-]");
LogUtils.shard(String.format("Loaded all %d shards in %d seconds.", totalShards, (end - start) / 1000));
log.info("Loaded all shards successfully... Starting ShardWatcher! Status: {}", MantaroCore.getLoadState());
Async.thread("ShardWatcherThread", new ShardWatcher());
bot.getCore().getShardEventBus().post(new PostLoadEvent());
startUpdaters();
bot.startCheckingBirthdays();
Async.task(() -> {
try {
SnowflakeCacheView<VoiceChannel> vc = MantaroBot.getInstance().getVoiceChannelCache();
MantaroBot.getInstance().getStatsClient().gauge("music_players", vc.stream().filter(voiceChannel -> voiceChannel.getMembers().contains(voiceChannel.getGuild().getSelfMember())).count());
}// Avoid the scheduled task to unexpectedly end on exception (probably ConcurrentModificationException but let's just catch all errors)
catch (Exception ignored) {
}
}, 20, TimeUnit.SECONDS);
}
use of net.dv8tion.jda.core.entities.VoiceChannel in project MantaroBot by Mantaro.
the class TrackScheduler method announce.
private void announce() {
try {
DBGuild dbGuild = MantaroData.db().getGuild(guildId);
GuildData guildData = dbGuild.getData();
if (guildData.isMusicAnnounce()) {
AudioTrackContext atc = getCurrentTrack();
if (atc == null)
return;
TextChannel req = atc.getRequestedChannel();
if (req == null)
return;
VoiceChannel vc = req.getGuild().getSelfMember().getVoiceState().getChannel();
AudioTrackInfo trackInfo = getCurrentTrack().getInfo();
String title = trackInfo.title;
long trackLength = trackInfo.length;
if (req.canTalk()) {
getCurrentTrack().getRequestedChannel().sendMessage(String.format("📣 Now playing in **%s**: %s (%s)%s", vc.getName(), title, AudioUtils.getLength(trackLength), getCurrentTrack().getDJ() != null ? " requested by **" + getCurrentTrack().getDJ().getName() + "**" : "")).queue(message -> message.delete().queueAfter(90, TimeUnit.SECONDS));
}
}
} catch (Exception ignored) {
}
}
Aggregations