Search in sources :

Example 21 with VoiceChannel

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);
}
Also used : VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel)

Example 22 with VoiceChannel

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);
}
Also used : VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) NEWLINE_PATTERN(net.kodehawa.mantarobot.utils.data.SimpleFileDataManager.NEWLINE_PATTERN) Utils(net.kodehawa.mantarobot.utils.Utils) AudioManager(net.dv8tion.jda.core.managers.AudioManager) GuildMusicManager(net.kodehawa.mantarobot.commands.music.GuildMusicManager) DiscordUtils(net.kodehawa.mantarobot.utils.DiscordUtils) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) java.awt(java.awt) Guild(net.dv8tion.jda.core.entities.Guild) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Permission(net.dv8tion.jda.core.Permission) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) Guild(net.dv8tion.jda.core.entities.Guild)

Example 23 with VoiceChannel

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;
}
Also used : AudioManager(net.dv8tion.jda.core.managers.AudioManager) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel)

Example 24 with VoiceChannel

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);
}
Also used : PostLoadEvent(net.kodehawa.mantarobot.core.listeners.events.PostLoadEvent) ShardWatcher(net.kodehawa.mantarobot.core.shard.watcher.ShardWatcher) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) MantaroBot(net.kodehawa.mantarobot.MantaroBot) PostingException(com.github.natanbc.discordbotsapi.PostingException)

Example 25 with VoiceChannel

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) {
    }
}
Also used : GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) TextChannel(net.dv8tion.jda.core.entities.TextChannel) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Aggregations

VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)38 TextChannel (net.dv8tion.jda.core.entities.TextChannel)13 Guild (net.dv8tion.jda.core.entities.Guild)8 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)7 Message (net.dv8tion.jda.core.entities.Message)7 AudioManager (net.dv8tion.jda.core.managers.AudioManager)6 GuildPlayer (fredboat.audio.player.GuildPlayer)5 ArrayList (java.util.ArrayList)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Collectors (java.util.stream.Collectors)3 Member (net.dv8tion.jda.core.entities.Member)3 Player (com.arsenarsen.lavaplayerbridge.player.Player)2 Track (com.arsenarsen.lavaplayerbridge.player.Track)2 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)2 AudioTrackContext (fredboat.audio.queue.AudioTrackContext)2 SplitAudioTrackContext (fredboat.audio.queue.SplitAudioTrackContext)2 Consumer (java.util.function.Consumer)2 Nullable (javax.annotation.Nullable)2 User (net.dv8tion.jda.core.entities.User)2 JDAImpl (net.dv8tion.jda.core.entities.impl.JDAImpl)2